forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeAnalysis.test.tsx
More file actions
54 lines (47 loc) · 1.88 KB
/
Copy pathTimeAnalysis.test.tsx
File metadata and controls
54 lines (47 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { render, screen, fireEvent } from '@testing-library/react';
import { describe, it, expect, vi } from 'vitest';
import { TimeAnalysis } from './TimeAnalysis';
import type { TimeDistribution } from '../../types/analytics';
vi.mock('recharts', async () => {
const actual = await vi.importActual('recharts');
return {
...actual,
ResponsiveContainer: ({ children }: { children: React.ReactNode }) => (
<div data-testid="responsive-container" style={{ width: 500, height: 280 }}>
{children}
</div>
),
};
});
const mockData: TimeDistribution[] = [
{ label: 'Mon', count: 12, amount: 340 },
{ label: 'Tue', count: 8, amount: 210 },
{ label: 'Wed', count: 15, amount: 480 },
];
describe('TimeAnalysis', () => {
it('renders the chart title', () => {
render(<TimeAnalysis data={mockData} />);
expect(screen.getByText('Time Analysis')).toBeDefined();
});
it('renders view toggle buttons', () => {
render(<TimeAnalysis data={mockData} />);
expect(screen.getByText('Day of Week')).toBeDefined();
expect(screen.getByText('By Amount')).toBeDefined();
});
it('shows peak day info', () => {
render(<TimeAnalysis data={mockData} />);
// Wed has the highest count (15)
expect(screen.getByText('Wed')).toBeDefined();
});
it('toggles between views', () => {
render(<TimeAnalysis data={mockData} />);
const amountBtn = screen.getByText('By Amount');
fireEvent.click(amountBtn);
// After clicking, the button should have active styling (white bg)
expect(amountBtn.className).toContain('bg-white');
});
it('has the correct id for export', () => {
const { container } = render(<TimeAnalysis data={mockData} />);
expect(container.querySelector('#time-analysis')).not.toBeNull();
});
});