Skip to content

Commit 5ec6322

Browse files
authored
test(dashboard): add responsive ComparisonStatsCard coverag (JhaSourav07#1750)
## Description Added a focused test suite for ComparisonStatsCard that checks responsive layout structure, positive/negative growth indicators, winner badges, and the zero-value fallback, then verified it passes with Vitest. Fixes JhaSourav07#1540 ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview ## 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. - [ ] I have made sure that i have only one commit to merge in this PR. - [ ] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts). - [x] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents cd21f62 + 21da5f5 commit 5ec6322

1 file changed

Lines changed: 80 additions & 1 deletion

File tree

components/dashboard/ComparisonStatsCard.test.tsx

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ describe('ComparisonStatsCard', () => {
9090

9191
expect(screen.queryByText('Winner')).toBeNull();
9292
});
93+
9394
it('renders neutral fallback progress bar when both values are zero', () => {
9495
const { container } = render(
9596
<ComparisonStatsCard
@@ -103,7 +104,6 @@ describe('ComparisonStatsCard', () => {
103104
);
104105

105106
const fallbackBar = container.querySelector('.bg-gray-700\\/50');
106-
107107
expect(fallbackBar).toBeDefined();
108108
});
109109

@@ -225,3 +225,82 @@ describe('ComparisonStatsCard responsive rendering and growth trends (Variation
225225
expect(screen.getByText('Winner')).toBeDefined();
226226
});
227227
});
228+
229+
describe('ComparisonStatsCard responsive breakpoints', () => {
230+
it('renders expected card structure with correct HTML nodes', () => {
231+
const { container } = render(
232+
<ComparisonStatsCard
233+
title="Developer Score"
234+
valueA={85}
235+
valueB={72}
236+
labelA="User One"
237+
labelB="User Two"
238+
icon="Award"
239+
/>
240+
);
241+
242+
const card = container.firstElementChild;
243+
const header = container.querySelector('.flex.justify-between.items-center.mb-6');
244+
const comparisonGrid = container.querySelector(
245+
'.grid.grid-cols-2.gap-4.items-center.mb-6.relative'
246+
);
247+
const progressBar = container.querySelector('.w-full.h-2.bg-gray-100');
248+
const divider = container.querySelector('.hidden.md\\:block');
249+
250+
expect(card?.tagName).toBe('DIV');
251+
expect(header?.tagName).toBe('DIV');
252+
expect(comparisonGrid?.tagName).toBe('DIV');
253+
expect(progressBar?.tagName).toBe('DIV');
254+
expect(divider?.tagName).toBe('DIV');
255+
256+
expect(screen.getByText('Winner')).toBeDefined();
257+
expect(screen.getByText('85')).toBeDefined();
258+
expect(screen.getByText('72')).toBeDefined();
259+
});
260+
261+
it('renders responsive divider and preserves winner badge for higher value', () => {
262+
const { container } = render(
263+
<ComparisonStatsCard
264+
title="Streak"
265+
valueA={20}
266+
valueB={80}
267+
labelA="Alice"
268+
labelB="Bob"
269+
icon="Flame"
270+
/>
271+
);
272+
273+
const divider = container.querySelector('.hidden.md\\:block');
274+
expect(divider?.tagName).toBe('DIV');
275+
276+
const winnerBadges = screen.getAllByText('Winner');
277+
expect(winnerBadges.length).toBe(1);
278+
expect(screen.getByText('80').parentElement?.textContent).toContain('Winner');
279+
280+
expect(screen.getByText('20').className).not.toMatch(/emerald/);
281+
282+
expect(screen.getByTitle('Alice')).toBeDefined();
283+
expect(screen.getByTitle('Bob')).toBeDefined();
284+
});
285+
286+
it('renders neutral fallback progress bar and no winner badge when both values are zero', () => {
287+
const { container } = render(
288+
<ComparisonStatsCard
289+
title="Commits"
290+
valueA={0}
291+
valueB={0}
292+
labelA="Alice"
293+
labelB="Bob"
294+
icon="GitCommit"
295+
/>
296+
);
297+
298+
const progressBar = container.querySelector('.w-full.h-2.bg-gray-100');
299+
expect(progressBar?.tagName).toBe('DIV');
300+
301+
const fallbackBar = container.querySelector('.bg-gray-700\\/50');
302+
expect(fallbackBar).toBeDefined();
303+
304+
expect(screen.queryByText('Winner')).toBeNull();
305+
});
306+
});

0 commit comments

Comments
 (0)