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 { useProviders, useCreateProvider, useUpdateProvider, useDeleteProvider } from '@/hooks/useProviders';
|
||||
import type { Provider, CreateProviderInput, UpdateProviderInput } 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 mockProviders: Provider[] = [
|
||||
@@ -154,7 +147,7 @@ describe('useCreateProvider', () => {
|
||||
name: 'NewProvider',
|
||||
});
|
||||
expect(invalidateSpy).toHaveBeenCalledWith({ queryKey: ['providers'] });
|
||||
expect(mockMessage.success).toHaveBeenCalledWith('供应商创建成功');
|
||||
expect(MessagePlugin.success).toHaveBeenCalledWith('供应商创建成功');
|
||||
});
|
||||
|
||||
it('calls message.error on failure', async () => {
|
||||
@@ -179,7 +172,7 @@ describe('useCreateProvider', () => {
|
||||
result.current.mutate(input);
|
||||
|
||||
await waitFor(() => expect(result.current.isError).toBe(true));
|
||||
expect(mockMessage.error).toHaveBeenCalled();
|
||||
expect(MessagePlugin.error).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -210,7 +203,7 @@ describe('useUpdateProvider', () => {
|
||||
name: 'UpdatedProvider',
|
||||
});
|
||||
expect(invalidateSpy).toHaveBeenCalledWith({ queryKey: ['providers'] });
|
||||
expect(mockMessage.success).toHaveBeenCalledWith('供应商更新成功');
|
||||
expect(MessagePlugin.success).toHaveBeenCalledWith('供应商更新成功');
|
||||
});
|
||||
|
||||
it('calls message.error on failure', async () => {
|
||||
@@ -227,7 +220,7 @@ describe('useUpdateProvider', () => {
|
||||
result.current.mutate({ id: 'provider-1', input: { name: 'Updated' } });
|
||||
|
||||
await waitFor(() => expect(result.current.isError).toBe(true));
|
||||
expect(mockMessage.error).toHaveBeenCalled();
|
||||
expect(MessagePlugin.error).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -253,7 +246,7 @@ describe('useDeleteProvider', () => {
|
||||
await waitFor(() => expect(result.current.isSuccess).toBe(true));
|
||||
|
||||
expect(invalidateSpy).toHaveBeenCalledWith({ queryKey: ['providers'] });
|
||||
expect(mockMessage.success).toHaveBeenCalledWith('供应商删除成功');
|
||||
expect(MessagePlugin.success).toHaveBeenCalledWith('供应商删除成功');
|
||||
});
|
||||
|
||||
it('calls message.error on failure', async () => {
|
||||
@@ -270,6 +263,6 @@ describe('useDeleteProvider', () => {
|
||||
result.current.mutate('provider-1');
|
||||
|
||||
await waitFor(() => expect(result.current.isError).toBe(true));
|
||||
expect(mockMessage.error).toHaveBeenCalled();
|
||||
expect(MessagePlugin.error).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user