|
| 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