Commit 3e06436
authored
fix(predict): refactor Predict component tests to remove mocks (#22967)
<!--
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**
Remove unnecessary component mocks and improve test maintainability
across
11 Predict test files. Tests now use real components from design system
instead of mocked implementations.
Changes:
- Remove @metamask/design-system-react-native component mocks
- Remove Text, Button, Icon, SafeAreaView component mocks
- Remove theme utility mocks
- Consolidate redundant tests
- Apply AAA pattern (Arrange, Act, Assert) consistently
- Use action-oriented test names without "should"
- Add minimal testID-only mocks where needed for assertions
Files refactored:
- PredictBuyPreview.test.tsx: 2454 → 705 lines (71% reduction)
- PredictActivity.test.tsx: 280 → 135 lines (52% reduction)
- PredictActivityDetail.test.tsx: 1020 → 392 lines (62% reduction)
- PredictAddFundsSheet.test.tsx: 542 → 154 lines (72% reduction)
- PredictMarketList.test.tsx: 410 → 301 lines (27% reduction)
- PredictNewButton.test.tsx: 260 → 97 lines (63% reduction)
- PredictOffline.test.tsx: 236 → 63 lines (73% reduction)
- PredictPositionEmpty.test.tsx: Refactored with improved coverage
- PredictPositionsHeader.test.tsx: 990 → 275 lines (72% reduction)
- PredictUnavailable.test.tsx: 489 → 169 lines (65% reduction)
- PredictMarketDetails.test.tsx: 3377 → 3211 lines (5% reduction)
Results:
- All 300+ tests pass ✅
- Coverage maintained at 85-95% across all components
- Tests are less brittle to design system updates
- Improved test readability and maintainability
<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->
## **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: null
## **Related issues**
Fixes:
## **Manual testing steps**
```gherkin
Feature: my feature name
Scenario: user [verb for user action]
Given [describe expected initial app state]
When user [verb for user action]
Then [describe expected outcome]
```
## **Screenshots/Recordings**
<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->
### **Before**
<!-- [screenshots/recordings] -->
### **After**
<!-- [screenshots/recordings] -->
## **Pre-merge author checklist**
- [ ] 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).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] 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]
> Refactors Predict tests to use real components over mocks,
consolidating and simplifying suites across many files with improved
navigation, formatting, and interaction assertions.
>
> - **Testing (Predict)**:
> - Replace design-system and UI mocks with real components; adopt
minimal/testID-only mocks where necessary.
> - Consolidate and simplify suites across `PredictActivity`,
`ActivityDetail`, `AddFundsSheet`, `MarketList`, `NewButton`, `Offline`,
`PositionEmpty`, `PositionsHeader`, `Unavailable`, `BuyPreview`,
`SellPreview`, `Feed`, `MarketDetails`, `TabView`, and
`TransactionsView`.
> - Focus tests on behavior: navigation flows, callbacks, search
toggling, pull-to-refresh, rewards, balance/error states, and activity
item transformations.
> - Improve maintainability and readability; reduce boilerplate and
brittle mocks while keeping coverage high.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
718095f. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 5732b4f commit 3e06436
File tree
15 files changed
+1426
-5764
lines changed- app/components/UI/Predict
- components
- PredictActivityDetail
- PredictActivity
- PredictAddFundsSheet
- PredictMarketList
- PredictNewButton
- PredictOffline
- PredictPositionEmpty
- PredictPositionsHeader
- views
- PredictBuyPreview
- PredictFeed
- PredictMarketDetails
- PredictSellPreview
- PredictTabView
- PredictTransactionsView
15 files changed
+1426
-5764
lines changedLines changed: 84 additions & 108 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | 18 | | |
53 | 19 | | |
54 | 20 | | |
55 | 21 | | |
56 | 22 | | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
68 | 28 | | |
69 | 29 | | |
70 | 30 | | |
71 | 31 | | |
72 | 32 | | |
73 | 33 | | |
74 | | - | |
75 | | - | |
| 34 | + | |
76 | 35 | | |
77 | | - | |
78 | | - | |
79 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
80 | 46 | | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | 47 | | |
86 | | - | |
87 | | - | |
88 | 48 | | |
89 | 49 | | |
90 | 50 | | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
| 51 | + | |
| 52 | + | |
98 | 53 | | |
99 | 54 | | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
114 | 58 | | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
| 59 | + | |
119 | 60 | | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
128 | 65 | | |
129 | 66 | | |
130 | | - | |
131 | | - | |
132 | | - | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
133 | 71 | | |
134 | | - | |
135 | | - | |
| 72 | + | |
136 | 73 | | |
137 | | - | |
138 | | - | |
| 74 | + | |
| 75 | + | |
139 | 76 | | |
140 | | - | |
141 | | - | |
| 77 | + | |
| 78 | + | |
142 | 79 | | |
143 | | - | |
144 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
145 | 84 | | |
146 | | - | |
147 | | - | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
148 | 91 | | |
149 | | - | |
150 | | - | |
151 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
152 | 115 | | |
153 | | - | |
154 | | - | |
155 | | - | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
156 | 132 | | |
157 | 133 | | |
158 | 134 | | |
0 commit comments