forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpendingChart.test.tsx
More file actions
47 lines (41 loc) · 1.72 KB
/
Copy pathSpendingChart.test.tsx
File metadata and controls
47 lines (41 loc) · 1.72 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
import { render, screen } from '@testing-library/react';
import { describe, it, expect, vi } from 'vitest';
import { SpendingChart } from './SpendingChart';
import type { SpendingTrend } from '../../types/analytics';
// Mock recharts ResponsiveContainer since it needs DOM measurements
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: 300 }}>
{children}
</div>
),
};
});
const mockData: SpendingTrend[] = [
{ period: '2026-01-01', totalSpent: 490, transactionCount: 10, avgTransactionAmount: 49 },
{ period: '2026-02-01', totalSpent: 620, transactionCount: 11, avgTransactionAmount: 56.36 },
];
describe('SpendingChart', () => {
it('renders the chart title', () => {
render(<SpendingChart data={mockData} />);
expect(screen.getByText('Spending Trends')).toBeDefined();
});
it('renders summary stats', () => {
render(<SpendingChart data={mockData} />);
expect(screen.getByText('Total')).toBeDefined();
expect(screen.getByText('Transactions')).toBeDefined();
expect(screen.getByText('Avg / Tx')).toBeDefined();
});
it('calculates total correctly', () => {
render(<SpendingChart data={mockData} />);
// 490 + 620 = 1,110
expect(screen.getByText('$1,110')).toBeDefined();
});
it('has the correct id for export', () => {
const { container } = render(<SpendingChart data={mockData} />);
expect(container.querySelector('#spending-chart')).not.toBeNull();
});
});