Skip to content

Commit 082d3d1

Browse files
authored
fix: confirmations unit tests; pay-with-modal and usePendingAmountAlerts (#29481)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until this PR meets the canonical Definition of Ready For Review in `docs/readme/ready-for-review.md`. In short: the template must be materially complete (not just section titles present), all status checks must be currently passing, and the only expected follow-up commits must be reviewer-driven. --> ## **Description** <!-- 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** <!-- Every checklist item must be consciously assessed before marking this PR as "Ready for review". A checked box means you deliberately considered that responsibility, not that you literally performed every action listed. Unchecked boxes are ambiguous: they are not an implicit "N/A" and they are not a silent "skip". See `docs/readme/ready-for-review.md` for the full checklist semantics. --> - [ ] 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. #### Performance checks (if applicable) - [ ] I've tested on Android - Ideally on a mid-range device; emulator is acceptable - [ ] I've tested with a power user scenario - Use these [power-user SRPs](https://consensyssoftware.atlassian.net/wiki/spaces/TL1/pages/edit-v2/401401446401?draftShareId=9d77e1e1-4bdc-4be1-9ebb-ccd916988d93) to import wallets with many accounts and tokens - [ ] I've instrumented key operations with Sentry traces for production performance metrics - See [`trace()`](/app/util/trace.ts) for usage and [`addToken`](/app/components/Views/AddAsset/components/AddCustomToken/AddCustomToken.tsx#L274) for an example For performance guidelines and tooling, see the [Performance Guide](https://consensyssoftware.atlassian.net/wiki/spaces/TL1/pages/400085549067/Performance+Guide+for+Engineers). ## **Pre-merge reviewer checklist** <!-- Reviewer checklist items follow the same semantics as the author checklist: an unchecked box is ambiguous, a checked box means the reviewer consciously assessed that responsibility. See `docs/readme/ready-for-review.md`. --> - [ ] 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] > **Low Risk** > Low risk because changes are confined to unit tests and only adjust async queries/mocked alert composition, with no production logic modifications. > > **Overview** > Fixes flakiness in `PayWithModal` tests by switching token selection assertions to async `findByText` before firing presses (including withdraw/zero-balance cases). > > Updates `usePendingAmountAlerts` test coverage to mock `useInsufficientMoneyAccountBalanceAlert` returning an alert and asserts it appears in the combined alert list. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 5cee122. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent d957987 commit 082d3d1

2 files changed

Lines changed: 16 additions & 13 deletions

File tree

app/components/Views/confirmations/components/modals/pay-with-modal/pay-with-modal.test.tsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -294,18 +294,18 @@ describe('PayWithModal', () => {
294294
});
295295

296296
describe('on token select', () => {
297-
it('sets pay asset', () => {
298-
const { getByText } = render();
297+
it('sets pay asset', async () => {
298+
const { findByText } = render();
299299

300-
fireEvent.press(getByText('Test Token 1'));
300+
fireEvent.press(await findByText('Test Token 1'));
301301

302302
expect(setPayTokenMock).toHaveBeenCalledWith({
303303
address: TOKENS_MOCK[1].address,
304304
chainId: TOKENS_MOCK[1].chainId,
305305
});
306306
});
307307

308-
it('calls onPerpsPaymentTokenChange via close callback when type is perpsDepositAndOrder', () => {
308+
it('calls onPerpsPaymentTokenChange via close callback when type is perpsDepositAndOrder', async () => {
309309
useTransactionMetadataRequestMock.mockReturnValue({
310310
id: transactionIdMock,
311311
chainId: CHAIN_ID_1_MOCK,
@@ -316,9 +316,9 @@ describe('PayWithModal', () => {
316316
type: TransactionType.perpsDepositAndOrder,
317317
} as unknown as ReturnType<typeof useTransactionMetadataRequest>);
318318

319-
const { getByText } = render();
319+
const { findByText } = render();
320320

321-
fireEvent.press(getByText('Test Token 1'));
321+
fireEvent.press(await findByText('Test Token 1'));
322322

323323
expect(onPerpsPaymentTokenChangeMock).toHaveBeenCalledWith(
324324
expect.objectContaining({
@@ -465,9 +465,9 @@ describe('PayWithModal', () => {
465465
jest.fn(() => [zeroBalanceToken]),
466466
);
467467

468-
const { getByText } = render();
468+
const { findByText } = render();
469469

470-
fireEvent.press(getByText('Zero Token'));
470+
fireEvent.press(await findByText('Zero Token'));
471471

472472
await waitFor(() => {
473473
expect(setPayTokenMock).toHaveBeenCalled();
@@ -497,11 +497,9 @@ describe('PayWithModal', () => {
497497
jest.fn(() => [zeroBalanceToken]),
498498
);
499499

500-
const { getByText } = render();
500+
const { findByText } = render();
501501

502-
await waitFor(() => {
503-
fireEvent.press(getByText('Zero Token'));
504-
});
502+
fireEvent.press(await findByText('Zero Token'));
505503

506504
expect(mockAddTokens).toHaveBeenCalledWith(
507505
[

app/components/Views/confirmations/hooks/alerts/usePendingAmountAlerts.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ jest.mock('./useAccountNoFundsAlert', () => ({
4242
}));
4343

4444
jest.mock('./useInsufficientMoneyAccountBalanceAlert', () => ({
45-
useInsufficientMoneyAccountBalanceAlert: () => [],
45+
useInsufficientMoneyAccountBalanceAlert: () => [
46+
{
47+
id: 'alert-7',
48+
},
49+
],
4650
}));
4751

4852
describe('usePendingAmountAlerts', () => {
@@ -56,6 +60,7 @@ describe('usePendingAmountAlerts', () => {
5660
{ id: 'alert-3' },
5761
{ id: 'alert-4' },
5862
{ id: 'alert-5' },
63+
{ id: 'alert-7' },
5964
{ id: 'alert-6' },
6065
]);
6166
});

0 commit comments

Comments
 (0)