feat: 前端集成 Prettier 代码格式化
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { UsageChart } from '@/pages/Stats/UsageChart';
|
||||
import type { UsageStats } from '@/types';
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
import { UsageChart } from '@/pages/Stats/UsageChart'
|
||||
import type { UsageStats } from '@/types'
|
||||
|
||||
// Mock Recharts components
|
||||
vi.mock('recharts', () => ({
|
||||
ResponsiveContainer: vi.fn(({ children }) => <div data-testid="mock-chart-container">{children}</div>),
|
||||
AreaChart: vi.fn(() => <div data-testid="mock-area-chart" />),
|
||||
ResponsiveContainer: vi.fn(({ children }) => <div data-testid='mock-chart-container'>{children}</div>),
|
||||
AreaChart: vi.fn(() => <div data-testid='mock-area-chart' />),
|
||||
Area: vi.fn(() => null),
|
||||
XAxis: vi.fn(() => null),
|
||||
YAxis: vi.fn(() => null),
|
||||
CartesianGrid: vi.fn(() => null),
|
||||
Tooltip: vi.fn(() => null),
|
||||
}));
|
||||
}))
|
||||
|
||||
const mockStats: UsageStats[] = [
|
||||
{
|
||||
@@ -36,36 +36,36 @@ const mockStats: UsageStats[] = [
|
||||
requestCount: 150,
|
||||
date: '2024-01-02',
|
||||
},
|
||||
];
|
||||
]
|
||||
|
||||
describe('UsageChart', () => {
|
||||
it('renders chart title', () => {
|
||||
render(<UsageChart stats={mockStats} />);
|
||||
render(<UsageChart stats={mockStats} />)
|
||||
|
||||
expect(screen.getByText('请求趋势')).toBeInTheDocument();
|
||||
});
|
||||
expect(screen.getByText('请求趋势')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders with data', () => {
|
||||
const { container } = render(<UsageChart stats={mockStats} />);
|
||||
const { container } = render(<UsageChart stats={mockStats} />)
|
||||
|
||||
// TDesign Card component
|
||||
expect(container.querySelector('.t-card')).toBeInTheDocument();
|
||||
expect(container.querySelector('.t-card')).toBeInTheDocument()
|
||||
// Mocked chart container
|
||||
expect(screen.getByTestId('mock-chart-container')).toBeInTheDocument();
|
||||
});
|
||||
expect(screen.getByTestId('mock-chart-container')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders empty state when no data', () => {
|
||||
render(<UsageChart stats={[]} />);
|
||||
render(<UsageChart stats={[]} />)
|
||||
|
||||
expect(screen.getByText('暂无数据')).toBeInTheDocument();
|
||||
});
|
||||
expect(screen.getByText('暂无数据')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('aggregates data by date correctly', () => {
|
||||
const { container } = render(<UsageChart stats={mockStats} />);
|
||||
const { container } = render(<UsageChart stats={mockStats} />)
|
||||
|
||||
// TDesign Card component
|
||||
expect(container.querySelector('.t-card')).toBeInTheDocument();
|
||||
expect(container.querySelector('.t-card')).toBeInTheDocument()
|
||||
// Mocked chart should render
|
||||
expect(screen.getByTestId('mock-chart-container')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
expect(screen.getByTestId('mock-chart-container')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user