Skip to content

Commit 57308b4

Browse files
test: color-no-hex mobile-core-ux batch (MetaMask#27152)
<!-- 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** <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> Split from MetaMask#26651 to reduce CODEOWNERS fanout. Batch: mobile-core-ux Source branch: `origin/remove-static-hex-from-tests` This batch removes brittle hardcoded hex theme values from mobile-core-ux-owned tests and replaces them with `mockTheme` so the tests follow the same token values as the components under test. It also expands the `color-no-hex` ESLint rollout in `.eslintrc.js` to the mobile-core-ux component and view folders from `CODEOWNERS`, so future violations are caught at the team ownership boundary instead of only in the few files touched by this PR. The concrete updates are: - `TransactionsFooter.test.tsx` and `AccountsMenu.test.tsx` now mock `useTheme` from `jest.requireActual(...).mockTheme` instead of hand-rolled hex values. - `Transactions/index.test.tsx` now uses `mockTheme.colors` and `mockTheme.typography` for the direct render-context tests, including the remaining `CancelSpeedupModal` case. - `.eslintrc.js` now enables `@metamask/design-tokens/color-no-hex` for the relevant mobile-core-ux component/view CODEOWNERS folders such as `Transactions`, `AccountsMenu`, and related mobile-core-ux UI surfaces. ## **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: null ## **Related issues** Fixes: ## **Manual testing steps** ```gherkin Feature: color-no-hex lint compliance for mobile-core-ux tests Scenario: developer validates the mobile-core-ux batch Given the mobile-core-ux test files use theme-backed values instead of hardcoded hex literals When the developer runs the targeted lint and unit test commands Then no color-no-hex violations are reported for the updated scope And the updated Transactions and AccountsMenu test suites pass ``` ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** N/A ### **After** N/A ## **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 - [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. ## **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. <!-- Generated with the help of the pr-description AI skill --> <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Low risk: changes are limited to ESLint override scope and test-only theme mocking, with no production logic changes. Main risk is unexpected new lint failures in the newly enforced folders. > > **Overview** > Expands the `.eslintrc.js` rollout of `@metamask/design-tokens/color-no-hex` by enabling it (as `error`) for additional mobile-core-ux-owned UI/view directories, so new static hex colors are caught at lint time. > > Updates `TransactionsFooter.test.tsx`, `Transactions/index.test.tsx`, and `AccountsMenu.test.tsx` to stop hardcoding hex theme values and instead source colors/typography from `mockTheme` (and mock `useTheme` accordingly), making tests consistent with design token values. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit bb033cb. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 9564fd6 commit 57308b4

4 files changed

Lines changed: 53 additions & 69 deletions

File tree

.eslintrc.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,20 +181,22 @@ module.exports = {
181181
},
182182
{
183183
files: [
184-
'app/components/hooks/useIsOriginalNativeTokenSymbol/**/*.{js,jsx,ts,tsx}',
185-
'app/components/hooks/useTokenBalancesController/**/*.{js,jsx,ts,tsx}',
186-
'app/components/hooks/useTokenBalance.tsx',
187-
'app/components/hooks/useTokensData/**/*.{js,jsx,ts,tsx}',
188-
'app/components/hooks/useSafeChains.ts',
184+
// @MetaMask/card
189185
'app/components/UI/Card/**/*.{js,jsx,ts,tsx}',
186+
// @MetaMask/core-platform
190187
'app/components/Snaps/**/*.{js,jsx,ts,tsx}',
188+
// @MetaMask/predict
191189
'app/components/UI/Predict/**/*.{js,jsx,ts,tsx}',
190+
// @MetaMask/ramp
192191
'app/components/UI/Ramp/**/*.{js,jsx,ts,tsx}',
192+
// @MetaMask/rewards
193193
'app/components/UI/Rewards/**/*.{js,jsx,ts,tsx}',
194+
// @MetaMask/perps
194195
'app/components/UI/Perps/**/*.{js,jsx,ts,tsx}',
196+
// @MetaMask/metamask-earn
195197
'app/components/UI/Earn/**/*.{js,jsx,ts,tsx}',
196198
'app/components/UI/Stake/**/*.{js,jsx,ts,tsx}',
197-
// Assets team has a large number of folder ownership areas,
199+
// @MetaMask/metamask-assets
198200
'app/components/UI/Assets/**/*.{js,jsx,ts,tsx}',
199201
'app/components/UI/Tokens/**/*.{js,jsx,ts,tsx}',
200202
'app/components/UI/AssetOverview/**/*.{js,jsx,ts,tsx}',
@@ -220,6 +222,26 @@ module.exports = {
220222
'app/components/Views/DetectedTokens/**/*.{js,jsx,ts,tsx}',
221223
'app/components/Views/NFTAutoDetectionModal/**/*.{js,jsx,ts,tsx}',
222224
'app/components/Views/NftDetails/**/*.{js,jsx,ts,tsx}',
225+
// @MetaMask/mobile-core-ux
226+
'app/components/Views/AccountActions/**/*.{js,jsx,ts,tsx}',
227+
'app/components/Views/AccountSelector/**/*.{js,jsx,ts,tsx}',
228+
'app/components/Views/AccountsMenu/**/*.{js,jsx,ts,tsx}',
229+
'app/components/Views/AddressQRCode/**/*.{js,jsx,ts,tsx}',
230+
'app/components/Views/EditAccountName/**/*.{js,jsx,ts,tsx}',
231+
'app/components/Views/LockScreen/**/*.{js,jsx,ts,tsx}',
232+
'app/components/Views/Login/**/*.{js,jsx,ts,tsx}',
233+
'app/components/Views/MultichainTransactionsView/**/*.{js,jsx,ts,tsx}',
234+
'app/components/Views/NetworkConnect/**/*.{js,jsx,ts,tsx}',
235+
'app/components/Views/NetworkSelector/**/*.{js,jsx,ts,tsx}',
236+
'app/components/Views/QRAccountDisplay/**/*.{js,jsx,ts,tsx}',
237+
'app/components/Views/QRScanner/**/*.{js,jsx,ts,tsx}',
238+
'app/components/Views/Settings/**/*.{js,jsx,ts,tsx}',
239+
'app/components/Views/TermsAndConditions/**/*.{js,jsx,ts,tsx}',
240+
'app/components/Views/UnifiedTransactionsView/**/*.{js,jsx,ts,tsx}',
241+
'app/components/UI/MultichainTransactionListItem/**/*.{js,jsx,ts,tsx}',
242+
'app/components/UI/TransactionActionModal/**/*.{js,jsx,ts,tsx}',
243+
'app/components/UI/TransactionElement/**/*.{js,jsx,ts,tsx}',
244+
'app/components/UI/Transactions/**/*.{js,jsx,ts,tsx}',
223245
],
224246
rules: {
225247
'@metamask/design-tokens/color-no-hex': 'error',

app/components/UI/Transactions/TransactionsFooter.test.tsx

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,12 @@ import TransactionsFooter from './TransactionsFooter';
44
import { strings } from '../../../../locales/i18n';
55
import { NO_RPC_BLOCK_EXPLORER } from '../../../constants/network';
66

7-
jest.mock('../../../util/theme', () => ({
8-
useTheme: () => ({
9-
colors: {
10-
text: {
11-
default: '#24272a',
12-
},
13-
},
14-
typography: {
15-
sBodySM: {
16-
fontSize: 14,
17-
lineHeight: 20,
18-
},
19-
},
20-
}),
21-
}));
7+
jest.mock('../../../util/theme', () => {
8+
const { mockTheme } = jest.requireActual('../../../util/theme');
9+
return {
10+
useTheme: () => mockTheme,
11+
};
12+
});
2213

2314
jest.mock('../../../util/networks', () => ({
2415
getBlockExplorerName: jest.fn(),

app/components/UI/Transactions/index.test.tsx

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { updateIncomingTransactions } from '../../../util/transaction-controller
2020
import Engine from '../../../core/Engine';
2121
import Logger from '../../../util/Logger';
2222
import { CancelSpeedupModal } from '../../../components/Views/confirmations/components/modals/cancel-speedup-modal';
23+
import { mockTheme } from '../../../util/theme';
2324

2425
// Mock the navigation and other dependencies
2526
const mockNavigationPush = jest.fn();
@@ -1954,11 +1955,8 @@ describe('UnconnectedTransactions Component Direct Method Testing', () => {
19541955

19551956
it('should test renderLoader method directly', () => {
19561957
instance.context = {
1957-
colors: {
1958-
background: { default: '#fff' },
1959-
text: { muted: '#999' },
1960-
},
1961-
typography: {},
1958+
colors: mockTheme.colors,
1959+
typography: mockTheme.typography,
19621960
};
19631961

19641962
const result = instance.renderLoader();
@@ -1967,11 +1965,8 @@ describe('UnconnectedTransactions Component Direct Method Testing', () => {
19671965

19681966
it('should test renderEmpty method directly', () => {
19691967
instance.context = {
1970-
colors: {
1971-
background: { default: '#fff' },
1972-
text: { muted: '#999' },
1973-
},
1974-
typography: {},
1968+
colors: mockTheme.colors,
1969+
typography: mockTheme.typography,
19751970
};
19761971
instance.props = {
19771972
...defaultTestProps,
@@ -2002,13 +1997,8 @@ describe('UnconnectedTransactions Component Direct Method Testing', () => {
20021997

20031998
it('should test renderList method directly', () => {
20041999
instance.context = {
2005-
colors: {
2006-
background: { default: '#fff' },
2007-
text: { muted: '#999' },
2008-
primary: { default: '#037dd6' },
2009-
icon: { default: '#24272a' },
2010-
},
2011-
typography: {},
2000+
colors: mockTheme.colors,
2001+
typography: mockTheme.typography,
20122002
};
20132003
instance.flatList = React.createRef();
20142004
instance.state = { refreshing: false };
@@ -2033,13 +2023,8 @@ describe('UnconnectedTransactions Component Direct Method Testing', () => {
20332023

20342024
it('renders single CancelSpeedupModal with correct props when speed up or cancel is open', () => {
20352025
instance.context = {
2036-
colors: {
2037-
background: { default: '#fff' },
2038-
text: { muted: '#999' },
2039-
primary: { default: '#037dd6' },
2040-
icon: { default: '#24272a' },
2041-
},
2042-
typography: {},
2026+
colors: mockTheme.colors,
2027+
typography: mockTheme.typography,
20432028
};
20442029
instance.state = {
20452030
refreshing: false,
@@ -2083,11 +2068,8 @@ describe('UnconnectedTransactions Component Direct Method Testing', () => {
20832068

20842069
it('should test render method directly', () => {
20852070
instance.context = {
2086-
colors: {
2087-
background: { default: '#fff' },
2088-
text: { muted: '#999' },
2089-
},
2090-
typography: {},
2071+
colors: mockTheme.colors,
2072+
typography: mockTheme.typography,
20912073
};
20922074
instance.state = {
20932075
ready: true,
@@ -2209,11 +2191,8 @@ describe('UnconnectedTransactions Component Direct Method Testing', () => {
22092191

22102192
it('should test renderEmpty with switch network scenarios', () => {
22112193
instance.context = {
2212-
colors: {
2213-
background: { default: '#fff' },
2214-
text: { muted: '#999' },
2215-
},
2216-
typography: {},
2194+
colors: mockTheme.colors,
2195+
typography: mockTheme.typography,
22172196
};
22182197

22192198
// Test when tokenChainId is different from chainId

app/components/Views/AccountsMenu/AccountsMenu.test.tsx

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,12 @@ jest.mock('react-redux', () => ({
3030
useSelector: jest.fn(),
3131
}));
3232

33-
jest.mock('../../../util/theme', () => ({
34-
useTheme: () => ({
35-
colors: {
36-
background: {
37-
default: '#FFFFFF',
38-
alternative: '#F2F4F6',
39-
},
40-
text: {
41-
default: '#24272A',
42-
alternative: '#6A737D',
43-
},
44-
},
45-
}),
46-
}));
33+
jest.mock('../../../util/theme', () => {
34+
const { mockTheme } = jest.requireActual('../../../util/theme');
35+
return {
36+
useTheme: () => mockTheme,
37+
};
38+
});
4739

4840
const mockTrackEvent = jest.fn();
4941
const mockCreateEventBuilder = jest.fn(() => ({

0 commit comments

Comments
 (0)