-
Notifications
You must be signed in to change notification settings - Fork 233
[CustomCatalogCard] Adapt MetricsDiv text color to active theme mode #1808
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MAYANKSHARMA01010
wants to merge
4
commits into
layer5io:master
Choose a base branch
from
MAYANKSHARMA01010:fix-1647-customcatalogcard-metrics-darkmode
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+105
−9
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
aa7d78a
fix(CustomCatalog): adapt MetricsDiv text color to active theme mode
MAYANKSHARMA01010 aaf34de
fix(CatalogCard): adapt MetricsDiv text color to active theme mode
MAYANKSHARMA01010 ca737c6
test(CustomCatalog): add theme regression tests for catalog metrics
MAYANKSHARMA01010 f923666
refactor(CatalogCard): align MetricsCount with theme tokens and refin…
MAYANKSHARMA01010 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import React from 'react'; | ||
| import CustomCatalogCard, { Pattern } from '../custom/CustomCatalog/CustomCard'; | ||
| import { darkModePalette, SistentThemeProvider } from '../theme'; | ||
|
|
||
| jest.mock('react-markdown', () => ({ | ||
| __esModule: true, | ||
| default: ({ children }: { children: React.ReactNode }) => <div>{children}</div> | ||
| })); | ||
|
|
||
| jest.mock('remark-gfm', () => ({ | ||
| __esModule: true, | ||
| default: () => {} | ||
| })); | ||
|
|
||
| jest.mock('rehype-raw', () => ({ | ||
| __esModule: true, | ||
| default: () => {} | ||
| })); | ||
|
|
||
| jest.mock('../custom/CustomCatalog/Helper', () => ({ | ||
| ...jest.requireActual('../custom/CustomCatalog/Helper'), | ||
| handleImage: jest.fn() | ||
| })); | ||
|
|
||
| const hexToRgb = (hex?: string) => { | ||
| if (!hex) return ''; | ||
| const cleanHex = hex.replace('#', ''); | ||
| const r = parseInt(cleanHex.substring(0, 2), 16); | ||
| const g = parseInt(cleanHex.substring(2, 4), 16); | ||
| const b = parseInt(cleanHex.substring(4, 6), 16); | ||
| return `rgb(${r}, ${g}, ${b})`; | ||
| }; | ||
|
|
||
| const renderWithTheme = (ui: React.ReactElement, mode: 'light' | 'dark' = 'light') => { | ||
| return render(<SistentThemeProvider initialMode={mode}>{ui}</SistentThemeProvider>); | ||
| }; | ||
|
|
||
| const mockPattern: Pattern = { | ||
| id: 'test-pattern-1', | ||
| userId: 'user-1', | ||
| patternFile: 'test-pattern-file', | ||
| user: { | ||
| firstName: 'Test', | ||
| lastName: 'User' | ||
| }, | ||
| avatarUrl: 'https://example.com/avatar.png', | ||
| name: 'Istio Service Mesh', | ||
| type: 'design', | ||
| downloadCount: 1200, | ||
| cloneCount: 450, | ||
| viewCount: 300, | ||
| deploymentCount: 100, | ||
| shareCount: 50, | ||
| updated_at: '2026-01-01', | ||
| created_at: '2026-01-01', | ||
| visibility: 'public' | ||
| }; | ||
|
|
||
| describe('CustomCatalogCard', () => { | ||
| it('renders all metrics counts correctly', () => { | ||
| renderWithTheme( | ||
| <CustomCatalogCard | ||
| pattern={mockPattern} | ||
| patternType="design" | ||
| isDetailed={true} | ||
| cardTechnologies={false} | ||
| /> | ||
| ); | ||
|
|
||
| expect(screen.getByText('1200')).not.toBeNull(); | ||
| expect(screen.getByText('450')).not.toBeNull(); | ||
| expect(screen.getByText('300')).not.toBeNull(); | ||
| expect(screen.getByText('100')).not.toBeNull(); | ||
| expect(screen.getByText('50')).not.toBeNull(); | ||
| }); | ||
|
|
||
| it('renders metrics with theme-aware text color in dark mode', () => { | ||
| renderWithTheme( | ||
| <CustomCatalogCard | ||
| pattern={mockPattern} | ||
| patternType="design" | ||
| isDetailed={true} | ||
| cardTechnologies={false} | ||
| />, | ||
| 'dark' | ||
| ); | ||
|
|
||
| const countElement = screen.getByText('1200'); | ||
| expect(countElement).not.toBeNull(); | ||
|
|
||
| const computedStyle = window.getComputedStyle(countElement); | ||
| expect(computedStyle.color).toBe(hexToRgb(darkModePalette.text.default)); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.