refactor: 迁移 UI 组件库从 Ant Design 至 TDesign
- 替换 antd 为 tdesign-react 作为主要 UI 组件库 - 引入 Recharts 替代 @ant-design/charts 实现图表功能 - 移除主题系统相关代码(ThemeContext、themes 目录) - 更新所有组件以适配 TDesign 组件 API - 更新测试用例以匹配新的组件实现 - 新增 TDesign 和 Recharts 集成规范文档
This commit is contained in:
@@ -3,8 +3,15 @@ import { describe, it, expect, vi } from 'vitest';
|
||||
import { UsageChart } from '@/pages/Stats/UsageChart';
|
||||
import type { UsageStats } from '@/types';
|
||||
|
||||
vi.mock('@ant-design/charts', () => ({
|
||||
Line: vi.fn(() => <div data-testid="mock-line-chart" />),
|
||||
// Mock Recharts components
|
||||
vi.mock('recharts', () => ({
|
||||
ResponsiveContainer: vi.fn(({ children }) => <div data-testid="mock-chart-container">{children}</div>),
|
||||
LineChart: vi.fn(() => <div data-testid="mock-line-chart" />),
|
||||
Line: vi.fn(() => null),
|
||||
XAxis: vi.fn(() => null),
|
||||
YAxis: vi.fn(() => null),
|
||||
CartesianGrid: vi.fn(() => null),
|
||||
Tooltip: vi.fn(() => null),
|
||||
}));
|
||||
|
||||
const mockStats: UsageStats[] = [
|
||||
@@ -41,8 +48,10 @@ describe('UsageChart', () => {
|
||||
it('renders with data', () => {
|
||||
const { container } = render(<UsageChart stats={mockStats} />);
|
||||
|
||||
expect(container.querySelector('.ant-card')).toBeInTheDocument();
|
||||
expect(screen.getByTestId('mock-line-chart')).toBeInTheDocument();
|
||||
// TDesign Card component
|
||||
expect(container.querySelector('.t-card')).toBeInTheDocument();
|
||||
// Mocked chart container
|
||||
expect(screen.getByTestId('mock-chart-container')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders empty state when no data', () => {
|
||||
@@ -54,6 +63,9 @@ describe('UsageChart', () => {
|
||||
it('aggregates data by date correctly', () => {
|
||||
const { container } = render(<UsageChart stats={mockStats} />);
|
||||
|
||||
expect(container.querySelector('.ant-card')).toBeInTheDocument();
|
||||
// TDesign Card component
|
||||
expect(container.querySelector('.t-card')).toBeInTheDocument();
|
||||
// Mocked chart should render
|
||||
expect(screen.getByTestId('mock-chart-container')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user