Skip to content

Commit 5f18700

Browse files
authored
test: remove toMatchSnapshot and removed snapshot files inaccounts tests (#28551)
<!-- 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** Refactors several React Native tests to stop using toMatchSnapshot and instead assert key UI elements are present via getByTestId/getByText and toBeOnTheScreen(). Deletes the corresponding Jest snapshot files for BackupAndSyncFeaturesToggles, BackupAndSyncToggle, ConfirmTurnOnBackupAndSyncModal, BackupAndSyncSettings, and MultichainAccountsConnectedList, and updates assertions to use stable IDs/translated strings (e.g., BACKUP_AND_SYNC_TOGGLE_TEST_IDS and strings(...)). ## **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] > **Low Risk** > Test-only changes that remove brittle `toMatchSnapshot` coverage in favor of targeted assertions; low risk aside from potentially missing some structural regression detection previously covered by snapshots. > > **Overview** > Refactors several React Native tests to **stop using `toMatchSnapshot`** and instead assert key UI elements are present via `getByTestId`/`getByText` and `toBeOnTheScreen()`. > > Deletes the corresponding Jest snapshot files for `BackupAndSyncFeaturesToggles`, `BackupAndSyncToggle`, `ConfirmTurnOnBackupAndSyncModal`, `BackupAndSyncSettings`, and `MultichainAccountsConnectedList`, and updates assertions to use stable IDs/translated strings (e.g., `BACKUP_AND_SYNC_TOGGLE_TEST_IDS` and `strings(...)`). > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 28a4755. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 3cc9298 commit 5f18700

10 files changed

Lines changed: 30 additions & 1686 deletions

File tree

app/components/UI/Identity/BackupAndSyncFeaturesToggles/BackupAndSyncFeaturesToggles.test.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,17 @@ describe('BackupAndSyncToggle', () => {
6767
);
6868
});
6969

70-
it('renders correctly', () => {
71-
const { toJSON } = renderWithProvider(<BackupAndSyncFeaturesToggles />, {
72-
state: MOCK_STORE_STATE,
70+
it('renders all feature toggle sections', () => {
71+
const { getByTestId } = renderWithProvider(
72+
<BackupAndSyncFeaturesToggles />,
73+
{
74+
state: MOCK_STORE_STATE,
75+
},
76+
);
77+
78+
backupAndSyncFeaturesTogglesSections.forEach((section) => {
79+
expect(getByTestId(section.testID)).toBeOnTheScreen();
7380
});
74-
expect(toJSON()).toMatchSnapshot();
7581
});
7682

7783
it('tracks toggle event when toggling the switch', async () => {

app/components/UI/Identity/BackupAndSyncFeaturesToggles/__snapshots__/BackupAndSyncFeaturesToggles.test.tsx.snap

Lines changed: 0 additions & 192 deletions
This file was deleted.

app/components/UI/Identity/BackupAndSyncToggle/BackupAndSyncToggle.test.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React from 'react';
33
import BackupAndSyncToggle from './BackupAndSyncToggle';
44
import renderWithProvider from '../../../../util/test/renderWithProvider';
55
import Routes from '../../../../constants/navigation/Routes';
6+
import { BACKUP_AND_SYNC_TOGGLE_TEST_IDS } from './BackupAndSyncToggle.testIds';
67
import { act, fireEvent, waitFor } from '@testing-library/react-native';
78
import { toggleBasicFunctionality } from '../../../../actions/settings';
89
import { BACKUPANDSYNC_FEATURES } from '@metamask/profile-sync-controller/user-storage';
@@ -92,16 +93,19 @@ describe('BackupAndSyncToggle', () => {
9293
);
9394
});
9495

95-
it('renders correctly', () => {
96-
const { toJSON } = renderWithProvider(
96+
it('renders the toggle switch', () => {
97+
const { getByTestId } = renderWithProvider(
9798
<BackupAndSyncToggle
9899
trackBackupAndSyncToggleEventOverride={mockTrackEventOverride}
99100
/>,
100101
{
101102
state: MOCK_STORE_STATE,
102103
},
103104
);
104-
expect(toJSON()).toMatchSnapshot();
105+
106+
expect(
107+
getByTestId(BACKUP_AND_SYNC_TOGGLE_TEST_IDS.TOGGLE),
108+
).toBeOnTheScreen();
105109
});
106110

107111
it('tracks the event when the toggle is changed', async () => {

app/components/UI/Identity/BackupAndSyncToggle/__snapshots__/BackupAndSyncToggle.test.tsx.snap

Lines changed: 0 additions & 89 deletions
This file was deleted.

app/components/UI/Identity/ConfirmTurnOnBackupAndSyncModal/ConfirmTurnOnBackupAndSyncModal.test.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import renderWithProvider from '../../../../util/test/renderWithProvider';
77
import { useNavigation } from '@react-navigation/native';
88
import { fireEvent, waitFor } from '@testing-library/react-native';
99
import { toggleBasicFunctionality } from '../../../../actions/settings';
10+
import { strings } from '../../../../../locales/i18n';
1011

1112
jest.mock('../../../../actions/settings', () => ({
1213
...jest.requireActual('../../../../actions/settings'),
@@ -69,13 +70,17 @@ jest.mock('@react-navigation/native', () => {
6970
});
7071

7172
describe('ConfirmTurnOnBackupAndSyncModal', () => {
72-
it('renders correctly', () => {
73-
const { toJSON } = renderWithProvider(
73+
it('renders the title and confirm button', () => {
74+
const { getByText } = renderWithProvider(
7475
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
7576
//@ts-ignore
7677
<ConfirmTurnOnBackupAndSyncModal navigation={useNavigation()} />,
7778
);
78-
expect(toJSON()).toMatchSnapshot();
79+
80+
expect(getByText(strings('backupAndSync.enable.title'))).toBeOnTheScreen();
81+
expect(
82+
getByText(strings('default_settings.sheet.buttons.turn_on')),
83+
).toBeOnTheScreen();
7984
});
8085

8186
it('enables basic functionality, then backup and sync', async () => {

0 commit comments

Comments
 (0)