Skip to content

Commit 1242530

Browse files
test: color-no-hex ramp (MetaMask#27030)
## **Description** This PR is the Ramp-only split of the `color-no-hex` batch work, extracted from the original umbrella PR MetaMask#26651. Scope: - Ramp files only (`app/components/UI/Ramp/**`) - temporary eslint rollout override for `app/components/UI/Ramp/**/*.{js,jsx,ts,tsx}` - includes replacing straightforward mock color suppressions in `DepositProgressBar` test with `mockTheme` Reference PR: MetaMask#26651 ## **Changelog** CHANGELOG entry: null ## **Related issues** Fixes: ## **Manual testing steps** ```gherkin Feature: color-no-hex ramp batch Scenario: validate ramp lint and tests Given this branch is checked out When running eslint for Ramp scope Then there are no lint errors When running jest for Ramp scope with snapshot updates Then tests pass ``` ## **Screenshots/Recordings** ### **Before** N/A (test/lint/config updates only) ### **After** N/A (test/lint/config updates only) ## **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/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] 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** > Low risk: changes are limited to ESLint override scope and test-only theme mocks/assertions, with no production logic changes aside from a local lint-disable comment on an SVG component. > > **Overview** > **Enables `@metamask/design-tokens/color-no-hex` enforcement for `app/components/UI/Ramp/**`** via an ESLint override, as part of the incremental rollout. > > Updates multiple Ramp tests to stop using hardcoded hex colors by reusing `util/theme`'s `mockTheme` (including `DepositProgressBar`, `DepositTextField`, `generateThemeParameters`, `PaymentMethodSelector`, `BankDetails`, and `useTransakRouting`), and adds a targeted file-level lint disable in `ShapesBackgroundAnimation` where the SVG uses fixed brand colors without token equivalents. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit ff93cb5. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 84edad3 commit 1242530

8 files changed

Lines changed: 65 additions & 48 deletions

File tree

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ module.exports = {
121121
'app/components/UI/Card/**/*.{js,jsx,ts,tsx}',
122122
'app/components/Snaps/**/*.{js,jsx,ts,tsx}',
123123
'app/components/UI/Predict/**/*.{js,jsx,ts,tsx}',
124+
'app/components/UI/Ramp/**/*.{js,jsx,ts,tsx}',
124125
'app/components/UI/Rewards/**/*.{js,jsx,ts,tsx}',
125126
'app/components/UI/Perps/**/*.{js,jsx,ts,tsx}',
126127
],

app/components/UI/Ramp/Aggregator/components/PaymentMethodSelector.test.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@ const defaultState = {
1111
},
1212
};
1313

14-
jest.mock('../../../../../util/theme', () => ({
15-
useTheme: jest.fn().mockReturnValue({
16-
colors: {
17-
icon: { default: '#000' },
18-
border: { muted: '#ccc' },
19-
},
20-
}),
21-
}));
14+
jest.mock('../../../../../util/theme', () => {
15+
const { mockTheme } = jest.requireActual('../../../../../util/theme');
16+
return {
17+
useTheme: jest.fn().mockReturnValue(mockTheme),
18+
};
19+
});
2220

2321
const mockProps = {
2422
name: 'Debit or Credit',

app/components/UI/Ramp/Aggregator/components/ShapesBackgroundAnimation/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @metamask/design-tokens/color-no-hex -- SVG illustration uses hardcoded brand colors without design token equivalents */
12
import React, { useEffect } from 'react';
23
import { Animated, Easing, StyleSheet } from 'react-native';
34
import Svg, { Path, LinearGradient, Stop, Defs } from 'react-native-svg';

app/components/UI/Ramp/Deposit/components/DepositProgressBar/DepositProgessBar.test.tsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
import React from 'react';
22
import { render } from '@testing-library/react-native';
33
import DepositProgressBar from './DepositProgressBar';
4+
import { mockTheme } from '../../../../../../util/theme';
45

5-
const COMPLETED_COLOR = '#007BFF';
6-
const CURRENT_COLOR = '#28A745';
7-
const TODO_COLOR = '#E5E5E5';
6+
const mockCompletedColor = mockTheme.colors.primary.default;
7+
const mockCurrentColor = mockTheme.colors.success.default;
8+
const mockTodoColor = mockTheme.colors.border.muted;
89

910
jest.mock('../../../../../../component-library/hooks', () => ({
1011
useStyles: jest.fn(() => ({
1112
styles: {
1213
container: { flexDirection: 'row', paddingVertical: 12 },
1314
step: { height: 5, flex: 1, borderRadius: 10 },
14-
completedStep: { backgroundColor: COMPLETED_COLOR },
15-
currentStep: { backgroundColor: CURRENT_COLOR },
16-
todoStep: { backgroundColor: TODO_COLOR },
15+
completedStep: { backgroundColor: mockCompletedColor },
16+
currentStep: { backgroundColor: mockCurrentColor },
17+
todoStep: { backgroundColor: mockTodoColor },
1718
stepGap: { marginRight: 10 },
1819
},
1920
})),
@@ -41,19 +42,19 @@ describe('DepositProgressBar', () => {
4142
const step4 = getByTestId('deposit-progress-step-4');
4243

4344
expect(JSON.stringify(step0.props.style)).toContain(
44-
`"backgroundColor":"${COMPLETED_COLOR}"`,
45+
`"backgroundColor":"${mockCompletedColor}"`,
4546
);
4647
expect(JSON.stringify(step1.props.style)).toContain(
47-
`"backgroundColor":"${COMPLETED_COLOR}"`,
48+
`"backgroundColor":"${mockCompletedColor}"`,
4849
);
4950
expect(JSON.stringify(step2.props.style)).toContain(
50-
`"backgroundColor":"${CURRENT_COLOR}"`,
51+
`"backgroundColor":"${mockCurrentColor}"`,
5152
);
5253
expect(JSON.stringify(step3.props.style)).toContain(
53-
`"backgroundColor":"${TODO_COLOR}"`,
54+
`"backgroundColor":"${mockTodoColor}"`,
5455
);
5556
expect(JSON.stringify(step4.props.style)).toContain(
56-
`"backgroundColor":"${TODO_COLOR}"`,
57+
`"backgroundColor":"${mockTodoColor}"`,
5758
);
5859
});
5960

app/components/UI/Ramp/Deposit/components/DepositTextField/DepositTextField.test.tsx

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,12 @@ import Text, {
77
TextVariant,
88
} from '../../../../../../component-library/components/Texts/Text';
99
import TextField from '../../../../../../component-library/components/Form/TextField';
10+
import { mockTheme } from '../../../../../../util/theme';
11+
import { AppThemeKey, Theme } from '../../../../../../util/theme/models';
1012

1113
const DEPOSIT_FIELD_TEST_ID = 'deposit-field-test-id';
1214

13-
const mockTheme = {
14-
colors: {
15-
text: { muted: '#888888' },
16-
error: { default: '#FF0000' },
17-
},
18-
themeAppearance: 'light',
19-
};
15+
let mockCurrentTheme: Theme = mockTheme;
2016

2117
const defaultProps = {
2218
label: 'Test Label',
@@ -30,11 +26,15 @@ jest.mock('../../../../../hooks/useStyles', () => ({
3026
label: {},
3127
error: {},
3228
},
33-
theme: mockTheme,
29+
theme: mockCurrentTheme,
3430
}),
3531
}));
3632

3733
describe('DepositTextField', () => {
34+
beforeEach(() => {
35+
mockCurrentTheme = mockTheme;
36+
});
37+
3838
it('should render default settings correctly', () => {
3939
const wrapper = shallow(<DepositTextField {...defaultProps} />);
4040
expect(wrapper).toMatchSnapshot();
@@ -57,6 +57,20 @@ describe('DepositTextField', () => {
5757
);
5858
});
5959

60+
it('should use dark keyboard appearance in dark theme', () => {
61+
mockCurrentTheme = {
62+
...mockTheme,
63+
themeAppearance: AppThemeKey.dark,
64+
};
65+
66+
const wrapper = shallow(<DepositTextField {...defaultProps} />);
67+
const textFieldComponent = wrapper.find(TextField);
68+
69+
expect(textFieldComponent.prop('keyboardAppearance')).toBe(
70+
AppThemeKey.dark,
71+
);
72+
});
73+
6074
it('should render error text when error prop is provided', () => {
6175
const errorMessage = 'This is an error message';
6276
const wrapper = shallow(

app/components/UI/Ramp/Deposit/utils/utils.test.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
} from '../../../../../constants/on-ramp';
1212
import { DepositOrder, DepositOrderType } from '@consensys/native-ramps-sdk';
1313
import { strings } from '../../../../../../locales/i18n';
14-
import { darkTheme, lightTheme } from '@metamask/design-tokens';
14+
import { darkTheme } from '@metamask/design-tokens';
15+
import { mockTheme } from '../../../../../util/theme';
1516
import { AppThemeKey } from '../../../../../util/theme/models';
1617
import { MOCK_ETH_TOKEN } from '../testUtils/constants';
1718

@@ -212,9 +213,15 @@ describe('hasDepositOrderField', () => {
212213
});
213214

214215
describe('generateThemeParameters', () => {
216+
const mockDarkTheme = {
217+
...mockTheme,
218+
colors: darkTheme.colors,
219+
themeAppearance: AppThemeKey.dark,
220+
};
221+
215222
it('should generate correct theme parameters for light mode', () => {
216223
const themeAppearance = AppThemeKey.light;
217-
const colors = lightTheme.colors;
224+
const colors = mockTheme.colors;
218225
const result = generateThemeParameters(themeAppearance, colors);
219226
expect(result).toEqual({
220227
themeColor: colors.primary.default,
@@ -242,7 +249,7 @@ describe('generateThemeParameters', () => {
242249

243250
it('should generate correct theme parameters for dark mode', () => {
244251
const themeAppearance = AppThemeKey.dark;
245-
const colors = darkTheme.colors;
252+
const colors = mockDarkTheme.colors;
246253
const result = generateThemeParameters(themeAppearance, colors);
247254
expect(result).toEqual({
248255
themeColor: colors.primary.default,

app/components/UI/Ramp/Views/NativeFlow/BankDetails.test.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,13 @@ jest.mock('../../../../../util/navigation/navUtils', () => ({
4949
}),
5050
}));
5151

52-
jest.mock('../../../../../util/theme', () => ({
53-
...jest.requireActual('../../../../../util/theme'),
54-
useTheme: () => ({
55-
colors: {
56-
primary: { default: '#0376C9' },
57-
icon: { default: '#6A737D' },
58-
},
59-
}),
60-
}));
52+
jest.mock('../../../../../util/theme', () => {
53+
const { mockTheme } = jest.requireActual('../../../../../util/theme');
54+
return {
55+
...jest.requireActual('../../../../../util/theme'),
56+
useTheme: () => mockTheme,
57+
};
58+
});
6159

6260
const mockGetOrder = jest.fn();
6361
const mockConfirmPayment = jest.fn();

app/components/UI/Ramp/hooks/useTransakRouting.test.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,12 @@ jest.mock('./useRampAccountAddress', () => ({
2525
default: () => MOCK_WALLET_ADDRESS,
2626
}));
2727

28-
jest.mock('../../../../util/theme', () => ({
29-
useTheme: () => ({
30-
themeAppearance: 'light',
31-
colors: {
32-
primary: { default: '#0376C9' },
33-
background: { default: '#FFFFFF' },
34-
},
35-
}),
36-
}));
28+
jest.mock('../../../../util/theme', () => {
29+
const { mockTheme } = jest.requireActual('../../../../util/theme');
30+
return {
31+
useTheme: () => mockTheme,
32+
};
33+
});
3734

3835
jest.mock('../../../../../locales/i18n', () => ({
3936
strings: (key: string, params?: Record<string, unknown>) => {

0 commit comments

Comments
 (0)