|
| 1 | +import { it, expect, vi } from 'vitest'; |
| 2 | +import { render, screen, fireEvent } from '@testing-library/react'; |
| 3 | +import ActivityLandscape from './ActivityLandscape'; |
| 4 | + |
| 5 | +vi.mock('framer-motion', async () => { |
| 6 | + const actual = await vi.importActual<typeof import('framer-motion')>('framer-motion'); |
| 7 | + |
| 8 | + return { |
| 9 | + ...actual, |
| 10 | + motion: { |
| 11 | + ...actual.motion, |
| 12 | + div: ({ children, ...props }: React.ComponentProps<'div'>) => ( |
| 13 | + <div {...props}>{children}</div> |
| 14 | + ), |
| 15 | + }, |
| 16 | + }; |
| 17 | +}); |
| 18 | +const mockData = Array.from({ length: 100 }, (_, i) => ({ |
| 19 | + date: `2024-01-${String(i + 1).padStart(2, '0')}`, |
| 20 | + count: i + 1, |
| 21 | + intensity: (i % 5) as 0 | 1 | 2 | 3 | 4, |
| 22 | +})); |
| 23 | +it('renders Activity Landscape heading', () => { |
| 24 | + render(<ActivityLandscape data={mockData} />); |
| 25 | + |
| 26 | + expect(screen.getByText('Activity Landscape')).toBeTruthy(); |
| 27 | +}); |
| 28 | +it('renders all tab buttons', () => { |
| 29 | + render(<ActivityLandscape data={mockData} />); |
| 30 | + |
| 31 | + expect(screen.getByText('1W')).toBeTruthy(); |
| 32 | + expect(screen.getByText('1M')).toBeTruthy(); |
| 33 | + expect(screen.getByText('3M')).toBeTruthy(); |
| 34 | + expect(screen.getByText('1Y')).toBeTruthy(); |
| 35 | +}); |
| 36 | +it('has 3M active by default', () => { |
| 37 | + render(<ActivityLandscape data={mockData} />); |
| 38 | + |
| 39 | + const tab = screen.getByText('3M'); |
| 40 | + |
| 41 | + expect(tab.className).toContain('bg-black'); |
| 42 | +}); |
| 43 | +it('activates 1W tab when clicked', () => { |
| 44 | + render(<ActivityLandscape data={mockData} />); |
| 45 | + |
| 46 | + const tab = screen.getByText('1W'); |
| 47 | + |
| 48 | + fireEvent.click(tab); |
| 49 | + |
| 50 | + expect(tab.className).toContain('bg-black'); |
| 51 | +}); |
| 52 | +it('renders activity chart', () => { |
| 53 | + render(<ActivityLandscape data={mockData} />); |
| 54 | + |
| 55 | + expect(screen.getByText('Activity Landscape')).toBeTruthy(); |
| 56 | + expect(screen.getByText('Commit frequency over time')).toBeTruthy(); |
| 57 | +}); |
| 58 | +it('renders with empty data without crashing', () => { |
| 59 | + render(<ActivityLandscape data={[]} />); |
| 60 | + |
| 61 | + expect(screen.getByText('Activity Landscape')).toBeTruthy(); |
| 62 | +}); |
0 commit comments