Commit ffc7e29
test(perps): expand component view coverage for market details, list,… (#26083)
Added component view tests for Perps section on increase coverage
<!--
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**
## Summary
Improves Perps component-view flow tests: less duplication, faster runs,
and more components covered.
## Changes
### 1. i18n strings as variables (no hardcoded keys)
- **PerpsOrderLifecycleFlow**: `ORDER_TYPE_TITLE`, `ORDER_TYPE_MARKET`,
`ORDER_TYPE_LIMIT`, `QUOTE_NETWORK_FEE`, `QUOTE_ESTIMATED_TIME`,
`QUOTE_RATE`, `DONE_BUTTON`, `LIQUIDATION_PRICE` in `beforeAll`.
- **PerpsPortfolioFlow**: `SEE_ALL_PERPS`, `POSITIONS`,
`ACCOUNT_SUMMARY_TITLE`, `EMPTY_TITLE`, `FIRST_TIME_DESCRIPTION`,
`ADD_MARGIN`, `REDUCE_MARGIN`.
- **PerpsActiveTraderFlow**: `MARKET_ORDERS`, `LEVERAGE_MODAL_TITLE`,
`LIMIT_PRICE_MODAL_TITLE`, `LIMIT_PRICE_MID`, `LIMIT_PRICE_BID`,
`CLOSE_ALL_TITLE`, `CANCEL_ALL_TITLE`, `ADJUST_MARGIN_TITLE`,
`ADD_MARGIN`, `REDUCE_MARGIN`.
- **PerpsErrorsAndInfoFlow**: `CONNECTION_FAILED_TITLE`,
`CONNECTION_FAILED_RETRY`, `CONNECTION_FAILED_GO_BACK`, `GOT_IT_BUTTON`.
- **PerpsMarketAndRiskFlow**: `NOTIFICATIONS_TITLE`, `SORT_SORT_BY`,
`SORT_APPLY`.
All of these are set once in `beforeAll` and reused in the tests instead
of repeating `strings('perps....')`.
### 2. Test execution speed
- **PerpsOrderLifecycleFlow**: `TIMEOUT_MS = 3000`; all `findBy*` use it
instead of 10s/5s so failures are detected sooner.
- **PerpsPortfolioFlow**: One `findBy*` per phase (with `TIMEOUT_MS`),
then `getBy*` for the rest to avoid extra async waits.
### 3. New coverage in existing flow tests
**PerpsOrderLifecycleFlow**
- **Phase 13 – PerpsTransactionsView**: Renders Activity, asserts
Trades/Orders/Funding/Deposits tabs and tab switching.
- **Phase 14 – PerpsSelectOrderTypeView**: Renders order type view
(route + params), asserts title, Market/Limit options, and Limit press.
**PerpsMarketAndRiskFlow**
- **Phase 8 – PerpsMarketSortFieldBottomSheet**: Renders sort sheet,
asserts "Sort by" and "Apply", selects Volume and Apply, asserts
`onOptionSelect`.
- **Phase 9 – PerpsTransactionItem**: Renders item with sample
transaction, asserts testID, title/subtitle, and `onPress` with
transaction.
- **Phase 10 – TradingViewChart**: Renders chart with `candleData:
null`, asserts container testID.
- **Phase 11 – PerpsNotificationTooltip**: Renders with
`orderSuccess={false}`, asserts notification sheet title is not shown.
### 4. Components covered by these flows
- **OrderLifecycleFlow**: PerpsClosePositionView, PerpsOrderBookView,
PerpsOrderDetailsView, PerpsHeroCardView, PerpsWithdrawView,
PerpsSelectProviderView, PerpsOrderTypeBottomSheet,
PerpsQuoteDetailsCard, PerpsQuoteExpiredModal, PerpsAdjustMarginView,
**PerpsTransactionsView**, **PerpsSelectOrderTypeView**.
- **MarketAndRiskFlow**: PerpsLoader, LivePriceDisplay,
PerpsMarketRowItem, PerpsMarketTradesList, PerpsStopLossPromptBanner,
PerpsNotificationBottomSheet, PerpsTransactionDetailAssetHero,
**PerpsMarketSortFieldBottomSheet**, **PerpsTransactionItem**,
**TradingViewChart**, **PerpsNotificationTooltip**.
## Testing
- Run flow tests:
`yarn jest PerpsOrderLifecycleFlow.view.test
PerpsMarketAndRiskFlow.view.test PerpsPortfolioFlow.view.test
PerpsActiveTraderFlow.view.test PerpsErrorsAndInfoFlow.view.test
--no-coverage`
<!--
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:
## **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]
> **Medium Risk**
> Mostly adds/updates view tests, but it also changes shared Jest
view-test setup and core Engine/controller mocks, which could affect
many tests and introduce CI flakiness.
>
> **Overview**
> Adds several new Perps *E2E-like* component-view flow tests covering
trading (tabs/orders/modify/flip/leverage/limit/cross-margin),
errors+info (connection recovery, tooltips, badges, fill tags),
market+risk (loaders, market rows, stop-loss prompts, notifications,
sorting, transactions, chart), order lifecycle (provider switching,
order type, quotes, adjust margin, activity tabs), portfolio
(tab/home/positions/geo-block/empty states), plus new standalone tests
for `PerpsTPSLView` and `PerpsTransactionsView`.
>
> Expands the Perps view-test harness (`perpsViewRenderer`) with many
new render helpers, default fixtures, order stream overrides, and a
`topOfBook` channel shim; updates shared test setup/mocks
(`testSetupView.js`, component-view `mocks.ts`, `perpsStatePreset`) to
stub additional React Native propTypes, Engine controller methods/state,
and missing Redux slices; removes older narrower view tests now covered
by the flow suites and tweaks a single onboarding perf timer threshold.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
94bd6ef. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: javiergarciavera <javiergarciavera@users.noreply.github.com>1 parent 9840ef0 commit ffc7e29
16 files changed
Lines changed: 2977 additions & 96 deletions
File tree
- app
- components/UI/Perps/Views
- PerpsMarketDetailsView
- PerpsMarketListView
- PerpsSelectModifyActionView
- PerpsTPSLView
- PerpsTabView
- PerpsTransactionsView
- util/test
- tests
- component-view
- presets
- renderers
- performance/onboarding
Lines changed: 497 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 295 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 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 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
0 commit comments