|
| 1 | +import { describe, it, expect, vi } from 'vitest'; |
| 2 | +import { render, screen } from '@testing-library/react'; |
| 3 | +import '@testing-library/jest-dom/vitest'; |
| 4 | + |
| 5 | +import HistoricalTrendView from './HistoricalTrendView'; |
| 6 | +import type { ActivityData } from '@/types/dashboard'; |
| 7 | +import type { DashboardPeriod } from '@/utils/dashboardPeriod'; |
| 8 | + |
| 9 | +vi.mock('next/navigation', () => ({ |
| 10 | + useRouter: () => ({ |
| 11 | + push: vi.fn(), |
| 12 | + }), |
| 13 | +})); |
| 14 | + |
| 15 | +vi.mock('./Heatmap', () => ({ |
| 16 | + default: () => <div data-testid="heatmap">Heatmap</div>, |
| 17 | +})); |
| 18 | + |
| 19 | +const period: DashboardPeriod = { |
| 20 | + kind: 'month', |
| 21 | + month: '2025-05', |
| 22 | + label: 'May 2025', |
| 23 | + from: '2025-05-01T00:00:00.000Z', |
| 24 | + to: '2025-05-31T23:59:59.999Z', |
| 25 | +}; |
| 26 | + |
| 27 | +const activity: ActivityData[] = [ |
| 28 | + { |
| 29 | + date: '2025-05-01', |
| 30 | + count: 5, |
| 31 | + intensity: 4, |
| 32 | + }, |
| 33 | + { |
| 34 | + date: '2025-05-02', |
| 35 | + count: 2, |
| 36 | + intensity: 2, |
| 37 | + }, |
| 38 | +]; |
| 39 | + |
| 40 | +describe('HistoricalTrendView theme contrast', () => { |
| 41 | + it('renders light mode background classes', () => { |
| 42 | + const { container } = render( |
| 43 | + <HistoricalTrendView username="tester" activity={activity} period={period} /> |
| 44 | + ); |
| 45 | + |
| 46 | + expect(container.innerHTML).toContain('bg-white'); |
| 47 | + expect(container.innerHTML).toContain('text-gray-900'); |
| 48 | + }); |
| 49 | + |
| 50 | + it('includes dark mode styling classes', () => { |
| 51 | + const { container } = render( |
| 52 | + <HistoricalTrendView username="tester" activity={activity} period={period} /> |
| 53 | + ); |
| 54 | + |
| 55 | + expect(container.innerHTML).toContain('dark:bg-[#0a0a0a]'); |
| 56 | + expect(container.innerHTML).toContain('dark:text-white'); |
| 57 | + }); |
| 58 | + |
| 59 | + it('renders text content with contrast-aware classes', () => { |
| 60 | + render(<HistoricalTrendView username="tester" activity={activity} period={period} />); |
| 61 | + |
| 62 | + expect(screen.getByText(/Explore long-term activity patterns/i)).toBeInTheDocument(); |
| 63 | + |
| 64 | + expect(screen.getByText(/Contributions/i)).toBeInTheDocument(); |
| 65 | + }); |
| 66 | + |
| 67 | + it('renders foreground content without clipping overlays', () => { |
| 68 | + render(<HistoricalTrendView username="tester" activity={activity} period={period} />); |
| 69 | + |
| 70 | + expect(screen.getByText(/Monthly Summary/i)).toBeInTheDocument(); |
| 71 | + expect(screen.getByText(/Yearly Summary/i)).toBeInTheDocument(); |
| 72 | + }); |
| 73 | + |
| 74 | + it('renders heatmap and statistics in both theme-capable layouts', () => { |
| 75 | + render(<HistoricalTrendView username="tester" activity={activity} period={period} />); |
| 76 | + |
| 77 | + expect(screen.getByTestId('heatmap')).toBeInTheDocument(); |
| 78 | + expect(screen.getByText(/Current Streak/i)).toBeInTheDocument(); |
| 79 | + }); |
| 80 | +}); |
0 commit comments