feat: enhance Tauri charts with deduped gridline labels and add tests for bar and line charts
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { TauriBarChart, TauriLineChart, type ChartPoint } from './TauriCharts';
|
||||
|
||||
const zero: ChartPoint[] = Array.from({ length: 7 }, (_, i) => ({ label: `روز ${i}`, value: 0 }));
|
||||
const real: ChartPoint[] = [
|
||||
{ label: '۷ خرداد', value: 15 },
|
||||
{ label: '۸ خرداد', value: 40 },
|
||||
{ label: '۹ خرداد', value: 48 },
|
||||
];
|
||||
|
||||
const EMPTY = 'دادهای برای نمایش نیست';
|
||||
|
||||
describe('TauriBarChart', () => {
|
||||
it('shows the empty state when every value is zero', () => {
|
||||
render(<TauriBarChart data={zero} />);
|
||||
expect(screen.getByText(EMPTY)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows the empty state when there is no data', () => {
|
||||
render(<TauriBarChart data={[]} />);
|
||||
expect(screen.getByText(EMPTY)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders the chart (x labels, no empty state) with real data', () => {
|
||||
render(<TauriBarChart data={real} />);
|
||||
expect(screen.queryByText(EMPTY)).not.toBeInTheDocument();
|
||||
expect(screen.getByText('۸ خرداد')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('TauriLineChart', () => {
|
||||
it('shows the empty state when every value is zero', () => {
|
||||
render(<TauriLineChart data={zero} />);
|
||||
expect(screen.getByText(EMPTY)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows the empty state with fewer than two points', () => {
|
||||
render(<TauriLineChart data={[{ label: 'x', value: 5 }]} />);
|
||||
expect(screen.getByText(EMPTY)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders the chart with real data', () => {
|
||||
const { container } = render(<TauriLineChart data={real} />);
|
||||
expect(screen.queryByText(EMPTY)).not.toBeInTheDocument();
|
||||
expect(container.querySelector('svg path')).toBeTruthy();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user