Skip to content

Commit 341cbba

Browse files
test: use mockTheme instead of hardcoded hex values in test assertions (#26657)
## **Description** This PR updates test files to use design token references instead of hardcoded hex values, unblocking the design tokens upgrade to v8.2.1 (#26639). **What this PR does:** - Replaces hardcoded color hex values with `mockTheme.colors.*` references in test assertions - Uses `brandColor.*` for static, non-theme-dependent colors (camera overlay) - Updates snapshots to reflect new design token values - Fixes template interpolation in inline snapshots **Why this is an improvement:** - Makes tests resilient to design token value changes - Ensures tests validate correct token usage rather than specific hex values - Aligns with design system best practices ## **Changelog** CHANGELOG entry: null ## **Related issues** Dependency of: #26639 Related: #26651 ## **Manual testing steps** ```gherkin Scenario: Verify all updated tests pass Given the repository with design tokens v8.2.1 When I run the following test files: | Test File | | app/components/Snaps/SnapUIRenderer/components/input.test.ts | | app/components/UI/Bridge/components/TransactionDetails/BridgeStepDescription.test.tsx | | app/components/UI/Card/components/Onboarding/VerifyIdentity.test.tsx | | app/components/UI/Earn/Views/EarnLendingWithdrawalConfirmationView/EarnLendingWithdrawalConfirmationView.test.tsx | | app/components/UI/Rewards/hooks/useRewardsToast.test.tsx | | app/components/Views/confirmations/components/UI/info-row-divider/info-row-divider.test.tsx | Then all tests should pass And snapshots should match expected values ``` ## **Screenshots/Recordings** N/A - Test-only changes ## **Pre-merge author checklist** - [x] 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/GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I've included tests if applicable - [x] I've documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] 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. - [x] I've properly set the pull request status: - [x] In case it's not yet "ready for review", I've set it to "draft". - [x] In case it's "ready for review", I've changed it from "draft" to "non-draft". ## **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 update assertions to reference theme tokens, reducing brittleness during design-token updates. Low risk aside from potential snapshot/assertion adjustments if token mappings differ. > > **Overview** > Updates several UI/unit tests to assert against theme design tokens (via `mockTheme.colors.*`) instead of hardcoded hex values, including Snap UI input borders, Bridge step text colors, Earn navbar background, and Rewards toast icon colors. > > Adjusts tests that relied on inline snapshots/mocked theme shapes by switching to token-backed assertions (and using `brandColors` for static camera overlay colors in Veriff branding) to keep tests resilient to design-token value changes. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 04dc67e. 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>
1 parent 0f16851 commit 341cbba

6 files changed

Lines changed: 65 additions & 49 deletions

File tree

app/components/Snaps/SnapUIRenderer/components/input.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { renderInterface } from '../testUtils';
22
import { Input, Box, Form } from '@metamask/snaps-sdk/jsx';
33
import { fireEvent } from '@testing-library/react-native';
44
import { TEXTFIELD_TEST_ID } from '../../../../component-library/components/Form/TextField/TextField.constants';
5+
import { mockTheme } from '../../../../util/theme';
56

67
jest.mock('../../../../core/Engine/Engine', () => ({
78
controllerMessenger: {
@@ -15,8 +16,8 @@ jest.mock('../../../../core/Engine/Engine', () => ({
1516
}));
1617

1718
describe('SnapUIInput', () => {
18-
const clearBorderColor = '#b7bbc866';
19-
const focusedBorderColor = '#b7bbc8';
19+
const clearBorderColor = mockTheme.colors.border.muted;
20+
const focusedBorderColor = mockTheme.colors.border.default;
2021

2122
beforeEach(() => {
2223
jest.resetAllMocks();

app/components/UI/Bridge/components/TransactionDetails/BridgeStepDescription.test.tsx

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
CHAIN_IDS,
1414
} from '@metamask/transaction-controller';
1515
import { fontStyles } from '../../../../../styles/common';
16+
import { mockTheme } from '../../../../../util/theme';
1617

1718
describe('BridgeStepDescription', () => {
1819
const mockStep = {
@@ -142,7 +143,10 @@ describe('BridgeStepDescription', () => {
142143
);
143144

144145
const textElement = getByText(/ETH/);
145-
expect(textElement.props.style).toHaveProperty('color', '#686e7d');
146+
expect(textElement.props.style).toHaveProperty(
147+
'color',
148+
mockTheme.colors.text.alternative,
149+
);
146150
});
147151

148152
it('should render bridge action with COMPLETE status text', () => {
@@ -155,7 +159,10 @@ describe('BridgeStepDescription', () => {
155159

156160
expect(getByText(/ETH/)).toBeTruthy();
157161
const textElement = getByText(/ETH/);
158-
expect(textElement.props.style).toHaveProperty('color', '#121314');
162+
expect(textElement.props.style).toHaveProperty(
163+
'color',
164+
mockTheme.colors.text.default,
165+
);
159166
expect(textElement.props.style).toHaveProperty(
160167
'fontFamily',
161168
fontStyles.normal.fontFamily,
@@ -173,7 +180,10 @@ describe('BridgeStepDescription', () => {
173180
expect(getByText(/ETH/)).toBeTruthy();
174181
expect(getByText(/USDC/)).toBeTruthy();
175182
const textElement = getByText(/ETH/);
176-
expect(textElement.props.style).toHaveProperty('color', '#121314');
183+
expect(textElement.props.style).toHaveProperty(
184+
'color',
185+
mockTheme.colors.text.default,
186+
);
177187
expect(textElement.props.style).toHaveProperty(
178188
'fontFamily',
179189
fontStyles.normal.fontFamily,
@@ -192,7 +202,10 @@ describe('BridgeStepDescription', () => {
192202
expect(getByText(/10:00 AM/)).toBeTruthy();
193203
expect(getByText(/ETH/)).toBeTruthy();
194204
const textElement = getByText(/ETH/);
195-
expect(textElement.props.style).toHaveProperty('color', '#121314');
205+
expect(textElement.props.style).toHaveProperty(
206+
'color',
207+
mockTheme.colors.text.default,
208+
);
196209
expect(textElement.props.style).toHaveProperty(
197210
'fontFamily',
198211
fontStyles.normal.fontFamily,
@@ -213,7 +226,10 @@ describe('BridgeStepDescription', () => {
213226
);
214227

215228
const textElement = getByText(/ETH/);
216-
expect(textElement.props.style).toHaveProperty('color', '#121314');
229+
expect(textElement.props.style).toHaveProperty(
230+
'color',
231+
mockTheme.colors.text.default,
232+
);
217233
expect(textElement.props.style).toHaveProperty(
218234
'fontFamily',
219235
fontStyles.medium.fontFamily,
@@ -234,7 +250,10 @@ describe('BridgeStepDescription', () => {
234250
);
235251

236252
const textElement = getByText(/ETH/);
237-
expect(textElement.props.style).toHaveProperty('color', '#121314');
253+
expect(textElement.props.style).toHaveProperty(
254+
'color',
255+
mockTheme.colors.text.default,
256+
);
238257
expect(textElement.props.style).toHaveProperty(
239258
'fontFamily',
240259
fontStyles.medium.fontFamily,
@@ -283,7 +302,10 @@ describe('BridgeStepDescription', () => {
283302
expect(getByText(/ETH/)).toBeTruthy();
284303
expect(getByText(/USDC/)).toBeTruthy();
285304
const textElement = getByText(/ETH/);
286-
expect(textElement.props.style).toHaveProperty('color', '#686e7d');
305+
expect(textElement.props.style).toHaveProperty(
306+
'color',
307+
mockTheme.colors.text.alternative,
308+
);
287309
expect(textElement.props.style).toHaveProperty(
288310
'fontFamily',
289311
fontStyles.normal.fontFamily,
@@ -297,7 +319,10 @@ describe('BridgeStepDescription', () => {
297319

298320
expect(getByText(/ETH/)).toBeTruthy();
299321
const textElement = getByText(/ETH/);
300-
expect(textElement.props.style).toHaveProperty('color', '#686e7d');
322+
expect(textElement.props.style).toHaveProperty(
323+
'color',
324+
mockTheme.colors.text.alternative,
325+
);
301326
expect(textElement.props.style).toHaveProperty(
302327
'fontFamily',
303328
fontStyles.normal.fontFamily,

app/components/UI/Card/components/Onboarding/VerifyIdentity.test.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Provider } from 'react-redux';
55
import { configureStore } from '@reduxjs/toolkit';
66
import { useNavigation, StackActions } from '@react-navigation/native';
77
import VeriffSdk from '@veriff/react-native-sdk';
8+
import { mockTheme } from '../../../../../util/theme';
89
import VerifyIdentity from './VerifyIdentity';
910
import Routes from '../../../../../constants/navigation/Routes';
1011
import useStartVerification from '../../hooks/useStartVerification';
@@ -463,8 +464,8 @@ describe('VerifyIdentity Component', () => {
463464
success: expect.any(String),
464465
buttonRadius: 12,
465466
// Camera overlay colors are static — always dark + white text
466-
cameraOverlay: '#121314',
467-
onCameraOverlay: '#ffffff',
467+
cameraOverlay: mockTheme.brandColors.grey900,
468+
onCameraOverlay: mockTheme.brandColors.grey000,
468469
}),
469470
});
470471
});

app/components/UI/Earn/Views/EarnLendingWithdrawalConfirmationView/EarnLendingWithdrawalConfirmationView.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { LendingMarketWithPosition } from '@metamask/earn-controller';
2+
import { mockTheme } from '../../../../../util/theme';
23
import { useRoute } from '@react-navigation/native';
34
import { act, fireEvent } from '@testing-library/react-native';
45
import React from 'react';
@@ -234,7 +235,7 @@ describe('EarnLendingWithdrawalConfirmationView', () => {
234235
expect.any(Object), // theme.colors
235236
{
236237
hasCancelButton: false,
237-
backgroundColor: '#f3f5f9',
238+
backgroundColor: mockTheme.colors.background.alternative,
238239
},
239240
{
240241
backButtonEvent: {

app/components/UI/Rewards/hooks/useRewardsToast.test.tsx

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { renderHook, act } from '@testing-library/react-hooks';
22
import { useContext } from 'react';
33
import { notificationAsync, NotificationFeedbackType } from 'expo-haptics';
4+
import { mockTheme } from '../../../../util/theme';
45
import useRewardsToast, { RewardsToastOptions } from './useRewardsToast';
56
import {
67
ToastVariants,
@@ -32,25 +33,13 @@ jest.mock('../../../../../locales/i18n', () => ({
3233
}),
3334
}));
3435

35-
jest.mock('../../../../util/theme', () => ({
36-
useAppThemeFromContext: () => ({
37-
colors: {
38-
primary: {
39-
default: '#4459ff',
40-
muted: '#4459ff1a',
41-
},
42-
background: {
43-
muted: '#3c4d9d0f',
44-
},
45-
success: {
46-
default: '#457a39',
47-
},
48-
error: {
49-
default: '#ca3542',
50-
},
51-
},
52-
}),
53-
}));
36+
jest.mock('../../../../util/theme', () => {
37+
const actualTheme = jest.requireActual('../../../../util/theme');
38+
return {
39+
...actualTheme,
40+
useAppThemeFromContext: () => actualTheme.mockTheme,
41+
};
42+
});
5443

5544
describe('useRewardsToast', () => {
5645
let mockShowToast: jest.Mock;
@@ -107,7 +96,7 @@ describe('useRewardsToast', () => {
10796
expect(config).toMatchObject({
10897
variant: ToastVariants.Icon,
10998
iconName: IconName.Confirmation,
110-
iconColor: '#457a39',
99+
iconColor: mockTheme.colors.success.default,
111100
backgroundColor: 'transparent',
112101
hapticsType: NotificationFeedbackType.Success,
113102
hasNoTimeout: false,
@@ -131,7 +120,7 @@ describe('useRewardsToast', () => {
131120
expect(config).toMatchObject({
132121
variant: ToastVariants.Icon,
133122
iconName: IconName.Confirmation,
134-
iconColor: '#457a39',
123+
iconColor: mockTheme.colors.success.default,
135124
backgroundColor: 'transparent',
136125
hapticsType: NotificationFeedbackType.Success,
137126
hasNoTimeout: false,
@@ -154,7 +143,7 @@ describe('useRewardsToast', () => {
154143
expect(config).toMatchObject({
155144
variant: ToastVariants.Icon,
156145
iconName: IconName.Danger,
157-
iconColor: '#ca3542',
146+
iconColor: mockTheme.colors.error.default,
158147
backgroundColor: 'transparent',
159148
hapticsType: NotificationFeedbackType.Error,
160149
hasNoTimeout: false,
@@ -178,7 +167,7 @@ describe('useRewardsToast', () => {
178167
expect(config).toMatchObject({
179168
variant: ToastVariants.Icon,
180169
iconName: IconName.Danger,
181-
iconColor: '#ca3542',
170+
iconColor: mockTheme.colors.error.default,
182171
backgroundColor: 'transparent',
183172
hapticsType: NotificationFeedbackType.Error,
184173
hasNoTimeout: false,
Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import { mockTheme } from '../../../../../../util/theme';
23
import { stakingDepositConfirmationState } from '../../../../../../util/test/confirm-data-helpers';
34
import renderWithProvider from '../../../../../../util/test/renderWithProvider';
45
import InfoRowDivider from './info-row-divider';
@@ -9,18 +10,16 @@ describe('InfoRowDivider', () => {
910
state: stakingDepositConfirmationState,
1011
});
1112

12-
expect(toJSON()).toMatchInlineSnapshot(`
13-
<View
14-
style={
15-
{
16-
"backgroundColor": "#b7bbc866",
17-
"height": 1,
18-
"marginLeft": -8,
19-
"marginRight": -8,
20-
"marginVertical": 8,
21-
}
22-
}
23-
/>
24-
`);
13+
const result = toJSON();
14+
expect(result).toBeTruthy();
15+
if (result && !Array.isArray(result)) {
16+
expect(result.props.style).toEqual({
17+
backgroundColor: mockTheme.colors.border.muted,
18+
height: 1,
19+
marginLeft: -8,
20+
marginRight: -8,
21+
marginVertical: 8,
22+
});
23+
}
2524
});
2625
});

0 commit comments

Comments
 (0)