Skip to content

Commit e85dcd5

Browse files
authored
test(ActivityLandscape): add component tests (JhaSourav07#1960)
## Description Fixes JhaSourav07#677 Added comprehensive tests for the `ActivityLandscape` component. ### Changes * Created `components/dashboard/ActivityLandscape.test.tsx` * Mocked `framer-motion` for stable test execution * Added test for rendering the **Activity Landscape** heading * Added test for rendering all time-range tabs (`1W`, `1M`, `3M`, `1Y`) * Added test to verify **3M** is active by default * Added test to verify tab switching functionality * Added test to verify activity bars are rendered correctly * Added test to ensure the component handles empty datasets without crashing ## Pillar * [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview N/A (Test-only change) ## Checklist before requesting a review: * [x] I have read the `CONTRIBUTING.md` file. * [x] I have run `npm run lint` and resolved all errors. * [x] My commit follows the Conventional Commits format. * [x] I have made sure that I have only one commit to merge in this PR. * [x] This PR only adds automated tests and does not modify component behavior.
2 parents 9ed3908 + c6b27f2 commit e85dcd5

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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

Comments
 (0)