1
0

refactor: 迁移 UI 组件库从 Ant Design 至 TDesign

- 替换 antd 为 tdesign-react 作为主要 UI 组件库
- 引入 Recharts 替代 @ant-design/charts 实现图表功能
- 移除主题系统相关代码(ThemeContext、themes 目录)
- 更新所有组件以适配 TDesign 组件 API
- 更新测试用例以匹配新的组件实现
- 新增 TDesign 和 Recharts 集成规范文档
This commit is contained in:
2026-04-17 18:22:13 +08:00
parent 6eeb38c15e
commit 2b1c5e96c3
55 changed files with 1622 additions and 2541 deletions

View File

@@ -1,12 +1,8 @@
import { render, screen } from '@testing-library/react';
import { describe, it, expect, vi } from 'vitest';
import { describe, it, expect } from 'vitest';
import { BrowserRouter } from 'react-router';
import { AppLayout } from '@/components/AppLayout';
vi.mock('@/contexts/ThemeContext', () => ({
useTheme: vi.fn(() => ({ effectiveThemeId: 'default', themeId: 'default', followSystem: false, systemIsDark: false, setThemeId: vi.fn(), setFollowSystem: vi.fn() })),
}));
const renderWithRouter = (component: React.ReactNode) => {
return render(<BrowserRouter>{component}</BrowserRouter>);
};
@@ -32,76 +28,25 @@ describe('AppLayout', () => {
expect(screen.getByText('设置')).toBeInTheDocument();
});
it('does not render theme toggle button', () => {
renderWithRouter(<AppLayout />);
expect(screen.queryByRole('button', { name: 'moon' })).not.toBeInTheDocument();
expect(screen.queryByRole('button', { name: 'sun' })).not.toBeInTheDocument();
});
it('renders content outlet', () => {
const { container } = renderWithRouter(<AppLayout />);
expect(container.querySelector('.ant-layout-content')).toBeInTheDocument();
// TDesign Layout content
expect(container.querySelector('.t-layout__content')).toBeInTheDocument();
});
it('renders sidebar', () => {
const { container } = renderWithRouter(<AppLayout />);
expect(container.querySelector('.ant-layout-sider')).toBeInTheDocument();
// TDesign Layout.Aside might render with different class names
// Check for Menu component which is in the sidebar
expect(container.querySelector('.t-menu')).toBeInTheDocument();
});
it('renders header with page title', () => {
const { container } = renderWithRouter(<AppLayout />);
expect(container.querySelector('.ant-layout-header')).toBeInTheDocument();
});
it('uses effectiveThemeId for header background in dark mode', async () => {
const { useTheme } = await import('@/contexts/ThemeContext');
vi.mocked(useTheme).mockReturnValue({
effectiveThemeId: 'dark',
themeId: 'dark',
followSystem: false,
systemIsDark: false,
setThemeId: vi.fn(),
setFollowSystem: vi.fn(),
});
const { container } = renderWithRouter(<AppLayout />);
const header = container.querySelector('.ant-layout-header') as HTMLElement;
expect(header.style.borderBottom).toContain('1px solid');
});
it('uses light menu theme in default mode', async () => {
const { useTheme } = await import('@/contexts/ThemeContext');
vi.mocked(useTheme).mockReturnValue({
effectiveThemeId: 'default',
themeId: 'default',
followSystem: false,
systemIsDark: false,
setThemeId: vi.fn(),
setFollowSystem: vi.fn(),
});
const { container } = renderWithRouter(<AppLayout />);
expect(container.querySelector('.ant-menu-light')).toBeInTheDocument();
expect(container.querySelector('.ant-menu-dark')).not.toBeInTheDocument();
});
it('uses dark menu theme in dark mode', async () => {
const { useTheme } = await import('@/contexts/ThemeContext');
vi.mocked(useTheme).mockReturnValue({
effectiveThemeId: 'dark',
themeId: 'dark',
followSystem: false,
systemIsDark: false,
setThemeId: vi.fn(),
setFollowSystem: vi.fn(),
});
const { container } = renderWithRouter(<AppLayout />);
expect(container.querySelector('.ant-menu-dark')).toBeInTheDocument();
expect(container.querySelector('.ant-menu-light')).not.toBeInTheDocument();
// TDesign Layout header
expect(container.querySelector('.t-layout__header')).toBeInTheDocument();
});
});