Skip to content

Commit b47a932

Browse files
authored
test(dashboard): add vitest suite for commit clock component (JhaSourav07#834)
## Description Fixes JhaSourav07#678 Added a comprehensive Vitest test suite for the `CommitClock` dashboard component (`components/dashboard/CommitClock.test.tsx`). **Changes made:** - Mocked `framer-motion` to ensure clean, error-free DOM rendering during tests. - Implemented all 5 test cases outlined in the issue's Definition of Done: - Verifies the 'Commit Clock' heading renders. - Verifies the 'Weekly activity cycle' subtitle renders. - Verifies all 7 day labels render correctly. - Verifies the SVG element renders. - Verifies the component does not crash when passed an all-zero data array. ## 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 - This PR only adds test files, no visual UI changes were made.* ## 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): ...`). - [x] 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). - [x] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents 6cac500 + 7d08675 commit b47a932

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { render, screen } from '@testing-library/react';
2+
import { describe, it, expect, vi } from 'vitest';
3+
import type { ReactNode } from 'react';
4+
import CommitClock from './CommitClock';
5+
import type { CommitClockData } from '@/types/dashboard';
6+
7+
// 1. Mock framer-motion to prevent animation errors during DOM testing
8+
vi.mock('framer-motion', () => ({
9+
motion: {
10+
div: ({ children, className }: { children: ReactNode; className?: string }) => (
11+
<div className={className}>{children}</div>
12+
),
13+
g: ({ children }: { children: ReactNode }) => <g>{children}</g>,
14+
},
15+
}));
16+
17+
describe('CommitClock', () => {
18+
// Helper to generate properly typed mock data
19+
const generateMockData = (commits: number): CommitClockData[] => [
20+
{ day: 'Sun', commits },
21+
{ day: 'Mon', commits },
22+
{ day: 'Tue', commits },
23+
{ day: 'Wed', commits },
24+
{ day: 'Thu', commits },
25+
{ day: 'Fri', commits },
26+
{ day: 'Sat', commits },
27+
];
28+
29+
it("renders 'Commit Clock' heading", () => {
30+
render(<CommitClock data={generateMockData(5)} />);
31+
expect(screen.getByRole('heading', { name: /commit clock/i })).toBeDefined();
32+
});
33+
34+
it("renders 'Weekly activity cycle' subtitle", () => {
35+
render(<CommitClock data={generateMockData(5)} />);
36+
expect(screen.getByText(/weekly activity cycle/i)).toBeDefined();
37+
});
38+
39+
it('renders all 7 day labels', () => {
40+
render(<CommitClock data={generateMockData(5)} />);
41+
const days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
42+
days.forEach((day) => {
43+
expect(screen.getByText(day)).toBeDefined();
44+
});
45+
});
46+
47+
it('renders an SVG element', () => {
48+
const { container } = render(<CommitClock data={generateMockData(5)} />);
49+
expect(container.querySelector('svg')).not.toBeNull();
50+
});
51+
52+
it('renders with all-zero commit data without crashing', () => {
53+
expect(() => render(<CommitClock data={generateMockData(0)} />)).not.toThrow();
54+
});
55+
});

0 commit comments

Comments
 (0)