Skip to content

Commit bf75d55

Browse files
authored
test(leaderboard): add theme contrast coverage (JhaSourav07#3244)
## Description Fixes JhaSourav07#2755 Added theme contrast test coverage for the Leaderboard component. ### Changes Made * Created `components/Leaderboard.theme-contrast.test.tsx` * Added tests to verify leaderboard renders correctly across themes * Added checks for dark mode background styling * Added checks for dark mode text contrast classes * Added checks for dark mode border contrast classes * Added checks for hover contrast styling across light and dark themes ## Pillar * [ ] 🎨 Pillar 1 — New Theme Design * [ ] 📐 Pillar 2 — Geometric SVG Improvement * [ ] 🕐 Pillar 3 — Timezone Logic Optimization * [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview N/A (Test coverage only) ## Checklist before requesting a review: * [x] I have read the `CONTRIBUTING.md` file. * [x] I have tested these changes locally (`localhost:3000/api/streak?user=YOUR_USERNAME`). * [x] I have run `npm run format` and `npm run lint` locally and resolved all errors (CI will fail otherwise). * [x] My commits follow the Conventional Commits format (e.g., `feat(themes): ...`, `fix(calculate): ...`). * [ ] I have updated `README.md` if I added a new theme or URL parameter. * [x] I have started the repo. * [x] I have made sure that I have only one commit to merge in this PR. * [x] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts). * [ ] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents e97f565 + f8e87bb commit bf75d55

1 file changed

Lines changed: 83 additions & 0 deletions

File tree

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { render } from '@testing-library/react';
2+
import { describe, expect, it, vi } from 'vitest';
3+
import type { HTMLAttributes, ReactNode } from 'react';
4+
5+
import Leaderboard from './Leaderboard';
6+
7+
vi.mock('next/image', () => ({
8+
default: () => null,
9+
}));
10+
11+
vi.mock('framer-motion', () => ({
12+
motion: {
13+
div: ({
14+
children,
15+
...props
16+
}: HTMLAttributes<HTMLDivElement> & {
17+
children?: ReactNode;
18+
}) => <div {...props}>{children}</div>,
19+
},
20+
}));
21+
22+
describe('Leaderboard theme contrast behavior', () => {
23+
const contributors = [
24+
{
25+
id: 1,
26+
login: 'alice',
27+
avatar_url: 'https://example.com/alice.png',
28+
contributions: 100,
29+
html_url: 'https://github.com/alice',
30+
},
31+
{
32+
id: 2,
33+
login: 'bob',
34+
avatar_url: 'https://example.com/bob.png',
35+
contributions: 90,
36+
html_url: 'https://github.com/bob',
37+
},
38+
{
39+
id: 3,
40+
login: 'charlie',
41+
avatar_url: 'https://example.com/charlie.png',
42+
contributions: 80,
43+
html_url: 'https://github.com/charlie',
44+
},
45+
{
46+
id: 4,
47+
login: 'david',
48+
avatar_url: 'https://example.com/david.png',
49+
contributions: 70,
50+
html_url: 'https://github.com/david',
51+
},
52+
];
53+
54+
it('renders leaderboard container', () => {
55+
const { container } = render(<Leaderboard contributors={contributors} />);
56+
57+
expect(container.firstChild).toBeTruthy();
58+
});
59+
60+
it('includes dark mode background classes', () => {
61+
const { container } = render(<Leaderboard contributors={contributors} />);
62+
63+
expect(container.innerHTML).toContain('dark:bg');
64+
});
65+
66+
it('includes dark mode text classes', () => {
67+
const { container } = render(<Leaderboard contributors={contributors} />);
68+
69+
expect(container.innerHTML).toContain('dark:text-white');
70+
});
71+
72+
it('includes dark mode border classes', () => {
73+
const { container } = render(<Leaderboard contributors={contributors} />);
74+
75+
expect(container.innerHTML).toContain('dark:border');
76+
});
77+
78+
it('includes hover contrast styling for both themes', () => {
79+
const { container } = render(<Leaderboard contributors={contributors} />);
80+
81+
expect(container.innerHTML).toContain('dark:hover');
82+
});
83+
});

0 commit comments

Comments
 (0)