Skip to content

Commit a99399c

Browse files
authored
test: remove toMatchSnapshot and removed snapshot files in confirmations tests (#29287)
<!-- 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** > Refactors confirmations-related unit tests to stop using toMatchSnapshot and instead assert on specific UI elements via @testing-library/react-native (e.g., presence of buttons, text, and testIDs) across Tooltip, BottomModal, CopyButton, Network, BlockaidBanner, AddressElement/List, approval templates/results, and transaction header. > > Deletes the associated Jest snapshot files and adds a testID (blockaid-banner-loader) to the BlockaidBanner ActivityIndicator so the loader state can be asserted without snapshots. ## **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: changes are confined to test expectations and snapshot removals, with only a minor UI change adding a `testID` to the Blockaid loader for testability. > > **Overview** > Refactors confirmations-related unit tests to **stop using `toMatchSnapshot`** and instead assert on specific UI elements via `@testing-library/react-native` (e.g., presence of buttons, text, and testIDs) across Tooltip, BottomModal, CopyButton, Network, BlockaidBanner, AddressElement/List, approval templates/results, and transaction header. > > Deletes the associated Jest snapshot files and adds a `testID` (`blockaid-banner-loader`) to the BlockaidBanner `ActivityIndicator` so the loader state can be asserted without snapshots. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 0d0a988. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent c2be0e3 commit a99399c

29 files changed

Lines changed: 100 additions & 3136 deletions

File tree

app/components/Views/confirmations/components/UI/Tooltip/Tooltip.test.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@ import { fireEvent, render } from '@testing-library/react-native';
55
import Tooltip from './Tooltip';
66

77
describe('Tooltip', () => {
8-
it('should match snapshot', async () => {
9-
const container = render(
8+
it('renders the open button', () => {
9+
const { getByTestId } = render(
1010
<Tooltip
1111
title="Tooltip title"
1212
content={
1313
<View>
1414
<Text>Tooltip content to be displayed here!</Text>
1515
</View>
1616
}
17+
tooltipTestId="tooltipTestId"
1718
/>,
1819
);
19-
expect(container).toMatchSnapshot();
20+
expect(getByTestId('tooltipTestId-open-btn')).toBeOnTheScreen();
2021
});
2122

2223
it('should display content when info icon is clicked', async () => {
@@ -34,7 +35,9 @@ describe('Tooltip', () => {
3435
/>,
3536
);
3637
fireEvent.press(getByTestId('tooltipTestId-open-btn'));
37-
expect(getByText('Tooltip content to be displayed here!')).toBeDefined();
38+
expect(
39+
getByText('Tooltip content to be displayed here!'),
40+
).toBeOnTheScreen();
3841
expect(mockOnPress).toHaveBeenCalled();
3942
});
4043
});

app/components/Views/confirmations/components/UI/Tooltip/__snapshots__/Tooltip.test.tsx.snap

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

app/components/Views/confirmations/components/UI/bottom-modal/__snapshots__/bottom-modal.test.tsx.snap

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

app/components/Views/confirmations/components/UI/bottom-modal/bottom-modal.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import renderWithProvider from '../../../../../../util/test/renderWithProvider';
55
import BottomModal from '.';
66

77
describe('BottomModal', () => {
8-
it('should match snapshot', async () => {
9-
const container = renderWithProvider(
8+
it('renders children', () => {
9+
const { getByText } = renderWithProvider(
1010
<BottomModal>
1111
<View>
1212
<Text>DUMMY</Text>
1313
</View>
1414
</BottomModal>,
1515
{ state: {} },
1616
);
17-
expect(container).toMatchSnapshot();
17+
expect(getByText('DUMMY')).toBeOnTheScreen();
1818
});
1919
});

app/components/Views/confirmations/components/UI/copy-button/__snapshots__/copy-button.test.tsx.snap

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

app/components/Views/confirmations/components/UI/copy-button/copy-button.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ jest.mock('../../../../../../core/ClipboardManager', () => ({
99
}));
1010

1111
describe('CopyButton', () => {
12-
it('should match snapshot', async () => {
13-
const container = render(<CopyButton copyText={'DUMMY'} />);
14-
expect(container).toMatchSnapshot();
12+
it('renders the copy button', () => {
13+
const { getByTestId } = render(<CopyButton copyText={'DUMMY'} />);
14+
expect(getByTestId('copyButtonTestId')).toBeOnTheScreen();
1515
});
1616

1717
it('should copy text to clipboard when pressed', async () => {

app/components/Views/confirmations/components/UI/info-row/info-value/network/__snapshots__/network.test.tsx.snap

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

app/components/Views/confirmations/components/UI/info-row/info-value/network/network.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ const mockInitialState = {
2323
};
2424

2525
describe('Network', () => {
26-
it('should match snapshot', async () => {
27-
const container = renderWithProvider(
26+
it('renders the network avatar', () => {
27+
const { getByTestId } = renderWithProvider(
2828
<Network chainId={CHAIN_IDS.MAINNET} />,
2929
{ state: mockInitialState },
3030
);
31-
expect(container).toMatchSnapshot();
31+
expect(getByTestId('network-avatar-image')).toBeOnTheScreen();
3232
});
3333
});

0 commit comments

Comments
 (0)