Skip to content

test: color-no-hex assets batch#27150

Merged
georgewrmarshall merged 2 commits intomainfrom
chore/color-no-hex-assets-batch
Mar 23, 2026
Merged

test: color-no-hex assets batch#27150
georgewrmarshall merged 2 commits intomainfrom
chore/color-no-hex-assets-batch

Conversation

@georgewrmarshall
Copy link
Copy Markdown
Contributor

@georgewrmarshall georgewrmarshall commented Mar 6, 2026

Description

Split from #26651 to reduce CODEOWNERS fanout.

Batch: assets
Source branch: `origin/remove-static-hex-from-tests`

When `@metamask/design-tokens` upgrades change color values, tests that hardcode hex literals (e.g. `'#ffffff'`, `'#457a39'`) break because the component renders the new token value while the test still asserts the old one — even though nothing is actually wrong. This PR fixes that brittleness across the assets scope.

Two strategies are applied:

  1. Replace hardcoded hex theme mocks with `mockTheme` — test mocks that hand-rolled partial theme objects (e.g. `{ colors: { primary: { default: '#0376C9' } } }`) are replaced with `jest.requireActual` to pull the real `mockTheme`. Test assertions that checked against hex literals (e.g. `expect(color).toBe('#457a39')`) now reference `mockTheme.colors.success.default`, so both the component and the test always resolve the same value regardless of token package version.

  2. Add targeted `eslint-disable` comments — strings like `'Fix Browser Injection for both platforms #113'` or `'docs: add JSDoc to deprecate Alert in favor of BannerAlert #6904'` are NFT token IDs, not CSS colors. The `color-no-hex` rule can't distinguish them, so inline suppressions are added to allow these legitimate domain strings without weakening the rule elsewhere.

Together these changes make the `@metamask/design-tokens/color-no-hex` lint rule enforceable across this scope, so future hex literals won't accidentally creep back in and cause brittle tests.

Changelog

CHANGELOG entry: null

Related issues

Fixes:

Manual testing steps

```gherkin
Feature: color-no-hex lint compliance (assets batch)

Scenario: user runs lint and tests
Given the asset test files have been updated
When user runs lint and test checks
Then no color-no-hex violations are reported
And all tests pass
```

Screenshots/Recordings

Before

After

Pre-merge author checklist

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.

Note

Low Risk
Low risk: changes are confined to ESLint configuration and test mocks/assertions to avoid hardcoded hex values, with no runtime logic impact.

Overview
Enables @metamask/design-tokens/color-no-hex enforcement for the Assets-owned UI/hooks surface by expanding the ESLint override to treat hex literals as errors in those directories.

Updates multiple Assets-related tests to remove hardcoded hex color mocks and assertions by sourcing colors from the real mockTheme via jest.requireActual, and adds targeted inline disables where strings like #113/#6904 are NFT identifiers (not color literals).

Written by Cursor Bugbot for commit 02aaba1. This will update automatically on new commits. Configure here.

@georgewrmarshall georgewrmarshall requested a review from a team as a code owner March 6, 2026 20:20
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 6, 2026

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot metamaskbot added the team-design-system All issues relating to design system in Mobile label Mar 6, 2026
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Imported mockTheme is undefined due to circular mock
    • Updated the theme mock to use jest.requireActual and spread real exports, re-mocking only useTheme to return actual.mockTheme, eliminating the circular mock and undefined import.

Create PR

Or push these changes by commenting:

@cursor push 9be41cd528
Preview (9be41cd528)
diff --git a/app/components/UI/AssetOverview/TronEnergyBandwidthDetail/ResourceRing.test.tsx b/app/components/UI/AssetOverview/TronEnergyBandwidthDetail/ResourceRing.test.tsx
--- a/app/components/UI/AssetOverview/TronEnergyBandwidthDetail/ResourceRing.test.tsx
+++ b/app/components/UI/AssetOverview/TronEnergyBandwidthDetail/ResourceRing.test.tsx
@@ -11,9 +11,13 @@
   },
 }));
 
-jest.mock('../../../../util/theme', () => ({
-  useTheme: () => mockTheme,
-}));
+jest.mock('../../../../util/theme', () => {
+  const actual = jest.requireActual('../../../../util/theme');
+  return {
+    ...actual,
+    useTheme: () => actual.mockTheme,
+  };
+});
 
 describe('ResourceRing', () => {
   it('renders the ring icon', () => {

@github-actions github-actions bot added the size-M label Mar 6, 2026
@georgewrmarshall georgewrmarshall marked this pull request as draft March 6, 2026 21:10
@georgewrmarshall georgewrmarshall force-pushed the chore/color-no-hex-assets-batch branch from dbd952e to 5dd7d0f Compare March 17, 2026 17:29
@github-actions github-actions bot added the risk-low Low testing needed · Low bug introduction risk label Mar 17, 2026
@georgewrmarshall
Copy link
Copy Markdown
Contributor Author

@cursor fix /home/runner/work/metamask-mobile/metamask-mobile/app/components/UI/Tokens/TokenList/ScamWarningModal/ScamWarningModal.test.tsx
Error: 19:30 error '#fff' Hex color values are not allowed. Consider using design tokens instead. For support reach out to the design system team #metamask-design-system on Slack @metamask/design-tokens/color-no-hex
Error: 20:24 error '#ccc' Hex color values are not allowed. Consider using design tokens instead. For support reach out to the design system team #metamask-design-system on Slack @metamask/design-tokens/color-no-hex

@cursor
Copy link
Copy Markdown

cursor bot commented Mar 19, 2026

I inspected the failing test and removed the hardcoded hex colors by switching the theme mock to reuse the real mockTheme.

  • Edited app/components/UI/Tokens/TokenList/ScamWarningModal/ScamWarningModal.test.tsx to replace the inline hex literals with jest.requireActual('../../../../../util/theme') and return useTheme: () => actual.mockTheme.
  • Proactively fixed a related issue in app/components/UI/AssetOverview/TronEnergyBandwidthDetail/ResourceRing.test.tsx where mockTheme was imported alongside a jest.mock of the same module (hoisting caused mockTheme to be undefined). Reworked the mock to jest.requireActual and return useTheme: () => actual.mockTheme.

I committed both edits and pushed to chore/color-no-hex-assets-batch, then updated the existing PR.

Open in Web Open in Cursor 

@georgewrmarshall georgewrmarshall self-assigned this Mar 19, 2026
@georgewrmarshall
Copy link
Copy Markdown
Contributor Author

@cursor push 9be41cd

@cursor
Copy link
Copy Markdown

cursor bot commented Mar 19, 2026

Could not push Autofix changes. The PR branch may have changed since the Autofix ran, or the Autofix commit may no longer exist.

@georgewrmarshall georgewrmarshall force-pushed the chore/color-no-hex-assets-batch branch from 380102d to b65687b Compare March 23, 2026 16:29
@github-actions github-actions bot added size-XL and removed size-M labels Mar 23, 2026
@georgewrmarshall georgewrmarshall force-pushed the chore/color-no-hex-assets-batch branch from b65687b to 84ff85e Compare March 23, 2026 17:48
@github-actions github-actions bot added size-M and removed size-XL labels Mar 23, 2026
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Missed hex literal will fail new lint rule
    • Replaced the remaining '#457a39' test assertion with mockTheme.colors.success.default to comply with the new color-no-hex rule.

Create PR

Or push these changes by commenting:

@cursor push 940bf55d55
Preview (940bf55d55)
diff --git a/app/components/UI/Tokens/TokenList/TokenListItem/TokenListItem.test.tsx b/app/components/UI/Tokens/TokenList/TokenListItem/TokenListItem.test.tsx
--- a/app/components/UI/Tokens/TokenList/TokenListItem/TokenListItem.test.tsx
+++ b/app/components/UI/Tokens/TokenList/TokenListItem/TokenListItem.test.tsx
@@ -611,7 +611,9 @@
       const percentageText = getByTestId(SECONDARY_BALANCE_TEST_ID);
       expect(percentageText.props.children).toBe('-3.45%');
       // Negative percentage should NOT have success color
-      expect(percentageText.props.style.color).not.toBe('#457a39');
+      expect(percentageText.props.style.color).not.toBe(
+        mockTheme.colors.success.default,
+      );
     });
 
     it('hides percentage change on testnet', () => {

@github-actions
Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

⏭️ Smart E2E selection skipped - draft PR

All E2E tests pre-selected.

View GitHub Actions results

expect(percentageText.props.children).toBe('-3.45%');
// Negative percentage should NOT have success color
expect(percentageText.props.style.color).not.toBe('#457a39');
expect(percentageText.props.style.color).toBe(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assertion is tied to the semantic error token rather than the old literal hex value. That keeps the test validating the negative-state contract while staying stable across design-token updates.

'app/components/UI/Perps/**/*.{js,jsx,ts,tsx}',
'app/components/UI/Earn/**/*.{js,jsx,ts,tsx}',
'app/components/UI/Stake/**/*.{js,jsx,ts,tsx}',
// Assets team has a large number of folder ownership areas,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This override now follows the assets team codeowner boundaries instead of a handful of component-specific paths. That keeps future color-no-hex rollout work aligned with the review surface and avoids having lint coverage drift from ownership.

state: mockInitialState,
});

// eslint-disable-next-line @metamask/design-tokens/color-no-hex -- false positive: '#6904' is the NFT token ID text, not a color literal
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suppression stays inline on purpose because this string is part of the NFT token ID shown to the user, not a color literal. Keeping the reason next to the matcher makes it clear why the waiver is safe and narrowly scoped.

createEventBuilder: AnalyticsEventBuilder.createEventBuilder,
}),
);
mockUseAnalytics.mockReturnValue({
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test now stubs the full hook contract instead of relying on the helper so it stays compatible if useAnalytics grows additional methods. The assertions still exercise the real event builder, which keeps the analytics payload checks meaningful without reintroducing brittle theme or helper coupling.

@georgewrmarshall georgewrmarshall marked this pull request as ready for review March 23, 2026 18:11
@sonarqubecloud
Copy link
Copy Markdown

@georgewrmarshall georgewrmarshall requested review from a team and removed request for a team March 23, 2026 18:46
@georgewrmarshall georgewrmarshall added this pull request to the merge queue Mar 23, 2026
@github-actions
Copy link
Copy Markdown
Contributor

E2E Fixture Validation — Schema is up to date
17 value mismatches detected (expected — fixture represents an existing user).
View details

Merged via the queue into main with commit 88e375e Mar 23, 2026
216 of 219 checks passed
@georgewrmarshall georgewrmarshall deleted the chore/color-no-hex-assets-batch branch March 23, 2026 19:15
@github-actions github-actions bot locked and limited conversation to collaborators Mar 23, 2026
@metamaskbot metamaskbot added the release-7.72.0 Issue or pull request that will be included in release 7.72.0 label Mar 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.72.0 Issue or pull request that will be included in release 7.72.0 risk-low Low testing needed · Low bug introduction risk size-M team-design-system All issues relating to design system in Mobile

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants