Commit 1a0ed51
authored
test: enhance DeFiSection tests with error handling and retry logic (#26773)
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->
## **Description**
The DeFi homepage section was returning null (hiding entirely) when the
API responded with an error (e.g. 501). This matched the behavior for
the empty-data case, but the acceptance criteria requires showing a
retry UI on API failure — consistent with how the Predictions and Tokens
sections handle errors.
**This PR:**
- Separates error and empty handling in DeFiSection: errors now render
the shared ErrorState component with a retry button, while empty data
(200 with 0 positions) still hides the section.
- Replaces the no-op refresh function with a real one that calls
DeFiPositionsController._executePoll(), so both the retry button and
pull-to-refresh actually re-fetch.
- Updates tests to assert the new error UI behavior and verify retry
triggers _executePoll.
## **Changelog**
<!--
If this PR is not End-User-Facing and should not show up in the
CHANGELOG, you can choose to either:
1. Write `CHANGELOG entry: null`
2. Label with `no-changelog`
If this PR is End-User-Facing, please write a short User-Facing
description in the past tense like:
`CHANGELOG entry: Added a new tab for users to see their NFTs`
`CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker`
(This helps the Release Engineer do their job more quickly and
accurately)
-->
CHANGELOG entry: Fixed DeFi homepage section to show retry UI when API
request fails instead of hiding the section
## **Related issues**
Fixes: https://consensyssoftware.atlassian.net/browse/TMCU-496
## **Manual testing steps**
```gherkin
Feature: DeFi section error handling on homepage
Scenario: user sees retry UI when DeFi API fails
Given the DeFi positions API returns a 501 error
And the user navigates to the homepage
When the homepage loads
Then the DeFi section displays with a "Unable to load" message and a "Retry" button
Scenario: user retries after API failure
Given the DeFi section is showing the error/retry UI
When user taps the "Retry" button
Then the DeFi positions are re-fetched from the API
Scenario: DeFi section hidden when no positions exist
Given the DeFi positions API returns 200 with no positions
When the homepage loads
Then the DeFi section is not displayed
```
## **Screenshots/Recordings**
<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->
### **Before**
<!-- [screenshots/recordings] -->
### **After**
<img width="377" height="613" alt="Screenshot 2026-03-02 at 13 21 18"
src="https://github.com/user-attachments/assets/55d6b7e4-2187-4824-87c9-fa1161439e70"
/>
<!-- [screenshots/recordings] -->
## **Pre-merge author checklist**
- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I've included tests if applicable
- [x] I've documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I've applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
## **Pre-merge reviewer checklist**
- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Changes homepage DeFi rendering and refresh behavior to call
`DeFiPositionsController._executePoll()`, which could affect polling
frequency and error-handling paths. Uses a controller internal method,
so regressions are possible if controller APIs change.
>
> **Overview**
> DeFi homepage section no longer disappears on API errors: when
`hasError` (and not loading) it now renders the shared `ErrorState` with
a Retry button while still hiding the section for the *empty data* case.
>
> The section’s `refresh` handler (used by pull-to-refresh and Retry) is
wired to `Engine.context.DeFiPositionsController._executePoll()` to
actively re-fetch positions.
>
> Tests were updated to validate the new error UI and to assert that
both Retry and the exposed `ref.refresh()` call `_executePoll()`.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
296c330. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent be2b91c commit 1a0ed51
2 files changed
Lines changed: 53 additions & 8 deletions
Lines changed: 32 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
17 | 26 | | |
18 | 27 | | |
19 | 28 | | |
| |||
120 | 129 | | |
121 | 130 | | |
122 | 131 | | |
123 | | - | |
| 132 | + | |
124 | 133 | | |
125 | 134 | | |
126 | 135 | | |
127 | 136 | | |
128 | 137 | | |
129 | 138 | | |
130 | 139 | | |
131 | | - | |
| 140 | + | |
132 | 141 | | |
133 | | - | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
134 | 162 | | |
135 | 163 | | |
136 | 164 | | |
| |||
195 | 223 | | |
196 | 224 | | |
197 | 225 | | |
198 | | - | |
| 226 | + | |
199 | 227 | | |
200 | 228 | | |
Lines changed: 21 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| 19 | + | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
| |||
71 | 73 | | |
72 | 74 | | |
73 | 75 | | |
74 | | - | |
75 | 76 | | |
76 | | - | |
| 77 | + | |
| 78 | + | |
77 | 79 | | |
78 | 80 | | |
79 | 81 | | |
| |||
83 | 85 | | |
84 | 86 | | |
85 | 87 | | |
86 | | - | |
87 | | - | |
| 88 | + | |
| 89 | + | |
88 | 90 | | |
89 | 91 | | |
90 | 92 | | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
91 | 108 | | |
92 | 109 | | |
93 | 110 | | |
| |||
0 commit comments