Skip to content

test(perps): remove redundant MMDS BottomSheet mocks#33288

Merged
georgewrmarshall merged 1 commit into
mainfrom
remove-bottom-sheet-mocks
Jul 14, 2026
Merged

test(perps): remove redundant MMDS BottomSheet mocks#33288
georgewrmarshall merged 1 commit into
mainfrom
remove-bottom-sheet-mocks

Conversation

@georgewrmarshall

Copy link
Copy Markdown
Contributor

Description

Perps unit tests were duplicating the global MMDS BottomSheet mock from app/util/test/testSetup.js with local jest.mock('@metamask/design-system-react-native') overrides. Those local mocks were unnecessary and made assertions depend on mock-specific testIDs like bottom-sheet-header and close-button.

This PR removes the redundant per-test BottomSheet mocks from six Perps bottom sheet component test files and relies on the shared global mock instead. Components now expose stable, per-feature testIDs for bottom sheet containers and close buttons, and tests assert against those selectors.

Changelog

CHANGELOG entry: null

Related issues

Fixes:

Manual testing steps

N/A — test-only changes. Verified with:

yarn jest app/components/UI/Perps --no-coverage

All 279 Perps test suites pass (6332 tests).

Screenshots/Recordings

N/A

Before

After

Pre-merge author checklist

Performance checks (if applicable)

  • I've tested on Android
  • I've tested with a power user scenario
  • I've instrumented key operations with Sentry traces for production performance metrics

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.

Made with Cursor

Perps unit tests were overriding the global testSetup BottomSheet mock with
local copies. Rely on the shared mock instead and assert via component-specific
testIDs for bottom sheet containers and close actions.

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions

Copy link
Copy Markdown
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamask-ci metamask-ci Bot added the team-design-system All issues relating to design system in Mobile label Jul 14, 2026
@metamask-ci

metamask-ci Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

PR template — items to address before "Ready for review"

Warnings — informational, address before merging:

  • Related issues section is empty. Add Fixes: #123 / Closes: <URL> / Refs: <Jira key>, or write a short rationale after the colon.
  • Pre-merge author checklist has unchecked items (e.g. "I've documented my code using JSDoc format if applicable"). Every box must be consciously checked — see docs/readme/ready-for-review.md.

See docs/readme/ready-for-review.md for the full Definition of Ready for Review.

@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokePerps, SmokeWalletPlatform
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: low
  • AI Confidence: 90%
click to see 🤖 AI reasoning details

E2E Test Selection:
All 10 changed files are within the Perps UI component directory (app/components/UI/Perps/). The changes are:

  1. Perps.testIds.ts: Added new test ID constants (BOTTOM_SHEET for PerpsSlippageConfigSelectorsIDs, PerpsCandlePeriodBottomSheetSelectorsIDs.CLOSE_BUTTON, CONTAINER/CLOSE_BUTTON for PerpsOrderTypeBottomSheetSelectorsIDs). These are purely additive testability improvements.

  2. PerpsCandlePeriodBottomSheet.tsx: Updated close button testID from hardcoded 'close-button' to the new constant. No functional logic change.

  3. PerpsOrderTypeBottomSheet.tsx: Added testID to BottomSheet container and closeButtonProps.testID to BottomSheetHeader. No functional logic change.

  4. PerpsSlippageBottomSheet.tsx: Added testID to BottomSheet container. No functional logic change.

  5. Unit test files (6 files): Removed manual mocks of @metamask/design-system-react-native components (BottomSheet, BottomSheetHeader, etc.) and updated test assertions to use the new test ID constants. These are unit test improvements only.

The changes are low-risk testability improvements to Perps bottom sheet components. SmokePerps is selected because these components are part of the Perps trading flow. SmokeWalletPlatform is selected per the SmokePerps tag description (Perps is a section inside the Trending tab). SmokeConfirmations is NOT selected because no transaction confirmation flows are modified - only bottom sheet testIDs are updated.

Performance Test Selection:
No performance-sensitive code paths are modified. The changes are purely additive testID attributes on Perps bottom sheet components and unit test mock cleanup. These changes have no impact on rendering performance, load times, or any measured performance scenarios.

View GitHub Actions results

// ========================================

export const PerpsOrderTypeBottomSheetSelectorsIDs = {
CONTAINER: 'perps-order-type-bottom-sheet',

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These selectors replace mock-only IDs like bottom-sheet-header and close-button. Tests now target stable per-component testIDs that work with the shared MMDS BottomSheet mock in app/util/test/testSetup.js rather than per-file jest overrides.

BottomSheetHeader,
};
});
jest.mock('../../hooks/usePerpsEventTracking', () => ({

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The local @metamask/design-system-react-native BottomSheet mock was removed here. testSetup.js already provides a global BottomSheet stub that renders children synchronously and wires onOpenBottomSheet/onCloseBottomSheet, so duplicating it in each Perps test added maintenance cost without extra coverage.

return (
<BottomSheet
ref={sheetRef}
testID={PerpsOrderTypeBottomSheetSelectorsIDs.CONTAINER}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CONTAINER and CLOSE_BUTTON are wired into the real component so close/header interactions can be asserted without a custom BottomSheetHeader mock. closeButtonProps forwards the testID to MMDS ButtonIcon, which is the supported way to target the header close control in unit tests.


expect(mockOnOpenBottomSheet).toHaveBeenCalledTimes(2);
expect(screen.getByTestId('bottom-sheet')).toBeOnTheScreen();
expect(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-open behavior is now validated by user-visible state (BOTTOM_SHEET and EDIT_CHIP present) instead of counting onOpenBottomSheet calls on a local ref mock. That better matches what users see when the custom slippage sub-sheet dismisses and the preset sheet remounts.

'desc',
);
expect(mockOnClose).toHaveBeenCalledTimes(1);
expect(mockOnClose).toHaveBeenCalled();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the global BottomSheet mock, onClose fires from both the BottomSheet onClose prop and the callback passed to onCloseBottomSheet inside handleOptionPress. The test now checks that onClose was invoked rather than an exact call count, which reflects the real close path under testSetup.js.

};
});

jest.mock('../../../../../../locales/i18n', () => ({

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file previously mocked ListItemSelect, Box, Text, and Icon in addition to BottomSheet. Removing the whole design-system override lets the real MMDS list items render under the global BottomSheet stub, which is closer to production markup and still passes all nine tests.

onClose={handleClose}
closeButtonProps={{ testID: 'close-button' }}
closeButtonProps={{
testID: PerpsCandlePeriodBottomSheetSelectorsIDs.CLOSE_BUTTON,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generic close-button testID is replaced with a Perps-scoped selector so the close control stays discoverable when multiple bottom sheets render in the same test tree. This pairs with removing the custom BottomSheetHeader mock in the test file.

<BottomSheet ref={bottomSheetRef} onClose={onClose}>
<BottomSheet
ref={bottomSheetRef}
onClose={onClose}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All 279 Perps unit test suites were run after this change. PerpsOrderBookView.test.tsx still keeps a local BottomSheet override for the unavailable-ref edge case and was intentionally left out of this pass.

};
});

jest.mock('../../../../../../locales/i18n', () => ({

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PerpsModifyActionSheet and PerpsAdjustMarginActionSheet tests follow the same pattern: only themeUtils and i18n stay mocked. PerpsActionSheet already passes testID through to BottomSheet, so SHEET-level assertions continue to work via the global mock without a local BottomSheetHeader stub.

@georgewrmarshall georgewrmarshall self-assigned this Jul 14, 2026
@sonarqubecloud

Copy link
Copy Markdown

@georgewrmarshall georgewrmarshall marked this pull request as ready for review July 14, 2026 21:45
@georgewrmarshall georgewrmarshall requested a review from a team as a code owner July 14, 2026 21:45
@github-actions github-actions Bot added the risk:low AI analysis: low risk label Jul 14, 2026
@georgewrmarshall georgewrmarshall added this pull request to the merge queue Jul 14, 2026
Merged via the queue into main with commit 285a54b Jul 14, 2026
223 of 224 checks passed
@georgewrmarshall georgewrmarshall deleted the remove-bottom-sheet-mocks branch July 14, 2026 23:51
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 14, 2026
@metamask-ci metamask-ci Bot added the release-8.4.0 Issue or pull request that will be included in release 8.4.0 label Jul 14, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-8.4.0 Issue or pull request that will be included in release 8.4.0 risk:low AI analysis: low risk size-M team-design-system All issues relating to design system in Mobile

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants