Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions components/dashboard/ActivityLandscape.test.tsx
Original file line number Diff line number Diff line change
@@ -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<typeof import('framer-motion')>('framer-motion');

return {
...actual,
motion: {
...actual.motion,
div: ({ children, ...props }: React.ComponentProps<'div'>) => (
<div {...props}>{children}</div>
),
},
};
});
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(<ActivityLandscape data={mockData} />);

expect(screen.getByText('Activity Landscape')).toBeTruthy();
});
it('renders all tab buttons', () => {
render(<ActivityLandscape data={mockData} />);

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(<ActivityLandscape data={mockData} />);

const tab = screen.getByText('3M');

expect(tab.className).toContain('bg-black');
});
it('activates 1W tab when clicked', () => {
render(<ActivityLandscape data={mockData} />);

const tab = screen.getByText('1W');

fireEvent.click(tab);

expect(tab.className).toContain('bg-black');
});
it('renders activity chart', () => {
render(<ActivityLandscape data={mockData} />);

expect(screen.getByText('Activity Landscape')).toBeTruthy();
expect(screen.getByText('Commit frequency over time')).toBeTruthy();
});
it('renders with empty data without crashing', () => {
render(<ActivityLandscape data={[]} />);

expect(screen.getByText('Activity Landscape')).toBeTruthy();
});
Loading