refactor: 迁移 UI 组件库从 Ant Design 至 TDesign
- 替换 antd 为 tdesign-react 作为主要 UI 组件库 - 引入 Recharts 替代 @ant-design/charts 实现图表功能 - 移除主题系统相关代码(ThemeContext、themes 目录) - 更新所有组件以适配 TDesign 组件 API - 更新测试用例以匹配新的组件实现 - 新增 TDesign 和 Recharts 集成规范文档
This commit is contained in:
@@ -5,22 +5,15 @@ import { http, HttpResponse } from 'msw';
|
||||
import { setupServer } from 'msw/node';
|
||||
import { useModels, useCreateModel, useUpdateModel, useDeleteModel } from '@/hooks/useModels';
|
||||
import type { Model, CreateModelInput, UpdateModelInput } from '@/types';
|
||||
import { MessagePlugin } from 'tdesign-react';
|
||||
|
||||
const mockMessage = {
|
||||
success: vi.fn(),
|
||||
error: vi.fn(),
|
||||
};
|
||||
|
||||
vi.mock('antd', async (importOriginal) => {
|
||||
const original = await importOriginal<typeof import('antd')>();
|
||||
return {
|
||||
...original,
|
||||
App: {
|
||||
...original.App,
|
||||
useApp: () => ({ message: mockMessage }),
|
||||
},
|
||||
};
|
||||
});
|
||||
// Mock MessagePlugin
|
||||
vi.mock('tdesign-react', () => ({
|
||||
MessagePlugin: {
|
||||
success: vi.fn(),
|
||||
error: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
// Test data
|
||||
const mockModels: Model[] = [
|
||||
@@ -173,7 +166,7 @@ describe('useCreateModel', () => {
|
||||
modelName: 'gpt-4.1',
|
||||
});
|
||||
expect(invalidateSpy).toHaveBeenCalledWith({ queryKey: ['models'] });
|
||||
expect(mockMessage.success).toHaveBeenCalledWith('模型创建成功');
|
||||
expect(MessagePlugin.success).toHaveBeenCalledWith('模型创建成功');
|
||||
});
|
||||
|
||||
it('calls message.error on failure', async () => {
|
||||
@@ -197,7 +190,7 @@ describe('useCreateModel', () => {
|
||||
result.current.mutate(input);
|
||||
|
||||
await waitFor(() => expect(result.current.isError).toBe(true));
|
||||
expect(mockMessage.error).toHaveBeenCalled();
|
||||
expect(MessagePlugin.error).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -228,7 +221,7 @@ describe('useUpdateModel', () => {
|
||||
modelName: 'gpt-4o-updated',
|
||||
});
|
||||
expect(invalidateSpy).toHaveBeenCalledWith({ queryKey: ['models'] });
|
||||
expect(mockMessage.success).toHaveBeenCalledWith('模型更新成功');
|
||||
expect(MessagePlugin.success).toHaveBeenCalledWith('模型更新成功');
|
||||
});
|
||||
|
||||
it('calls message.error on failure', async () => {
|
||||
@@ -245,7 +238,7 @@ describe('useUpdateModel', () => {
|
||||
result.current.mutate({ id: 'model-1', input: { modelName: 'Updated' } });
|
||||
|
||||
await waitFor(() => expect(result.current.isError).toBe(true));
|
||||
expect(mockMessage.error).toHaveBeenCalled();
|
||||
expect(MessagePlugin.error).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -271,7 +264,7 @@ describe('useDeleteModel', () => {
|
||||
await waitFor(() => expect(result.current.isSuccess).toBe(true));
|
||||
|
||||
expect(invalidateSpy).toHaveBeenCalledWith({ queryKey: ['models'] });
|
||||
expect(mockMessage.success).toHaveBeenCalledWith('模型删除成功');
|
||||
expect(MessagePlugin.success).toHaveBeenCalledWith('模型删除成功');
|
||||
});
|
||||
|
||||
it('calls message.error on failure', async () => {
|
||||
@@ -288,6 +281,6 @@ describe('useDeleteModel', () => {
|
||||
result.current.mutate('model-1');
|
||||
|
||||
await waitFor(() => expect(result.current.isError).toBe(true));
|
||||
expect(mockMessage.error).toHaveBeenCalled();
|
||||
expect(MessagePlugin.error).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user