From c6b27f22a2d55b629039b065edbe2b6f7db0203c Mon Sep 17 00:00:00 2001 From: Shikhaar Tiwari Date: Sun, 31 May 2026 10:48:41 +0530 Subject: [PATCH] test(ActivityLandscape): add component tests --- .../dashboard/ActivityLandscape.test.tsx | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 components/dashboard/ActivityLandscape.test.tsx diff --git a/components/dashboard/ActivityLandscape.test.tsx b/components/dashboard/ActivityLandscape.test.tsx new file mode 100644 index 00000000..0e606ed9 --- /dev/null +++ b/components/dashboard/ActivityLandscape.test.tsx @@ -0,0 +1,62 @@ +import { it, expect, vi } from 'vitest'; +import { render, screen, fireEvent } from '@testing-library/react'; +import ActivityLandscape from './ActivityLandscape'; + +vi.mock('framer-motion', async () => { + const actual = await vi.importActual('framer-motion'); + + return { + ...actual, + motion: { + ...actual.motion, + div: ({ children, ...props }: React.ComponentProps<'div'>) => ( +
{children}
+ ), + }, + }; +}); +const mockData = Array.from({ length: 100 }, (_, i) => ({ + date: `2024-01-${String(i + 1).padStart(2, '0')}`, + count: i + 1, + intensity: (i % 5) as 0 | 1 | 2 | 3 | 4, +})); +it('renders Activity Landscape heading', () => { + render(); + + expect(screen.getByText('Activity Landscape')).toBeTruthy(); +}); +it('renders all tab buttons', () => { + render(); + + expect(screen.getByText('1W')).toBeTruthy(); + expect(screen.getByText('1M')).toBeTruthy(); + expect(screen.getByText('3M')).toBeTruthy(); + expect(screen.getByText('1Y')).toBeTruthy(); +}); +it('has 3M active by default', () => { + render(); + + const tab = screen.getByText('3M'); + + expect(tab.className).toContain('bg-black'); +}); +it('activates 1W tab when clicked', () => { + render(); + + const tab = screen.getByText('1W'); + + fireEvent.click(tab); + + expect(tab.className).toContain('bg-black'); +}); +it('renders activity chart', () => { + render(); + + expect(screen.getByText('Activity Landscape')).toBeTruthy(); + expect(screen.getByText('Commit frequency over time')).toBeTruthy(); +}); +it('renders with empty data without crashing', () => { + render(); + + expect(screen.getByText('Activity Landscape')).toBeTruthy(); +});