refactor: 迁移 UI 组件库从 Ant Design 至 TDesign
- 替换 antd 为 tdesign-react 作为主要 UI 组件库 - 引入 Recharts 替代 @ant-design/charts 实现图表功能 - 移除主题系统相关代码(ThemeContext、themes 目录) - 更新所有组件以适配 TDesign 组件 API - 更新测试用例以匹配新的组件实现 - 新增 TDesign 和 Recharts 集成规范文档
This commit is contained in:
@@ -1,16 +1,15 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
// 辅助:在对话框内定位输入框(Ant Design 6 的 Modal + Form)
|
||||
// 辅助:在对话框内定位输入框(TDesign Dialog + Form)
|
||||
function formInputs(page: import('@playwright/test').Page) {
|
||||
const dialog = page.getByRole('dialog');
|
||||
const dialog = page.locator('.t-dialog:visible');
|
||||
return {
|
||||
id: dialog.getByRole('textbox', { name: /ID/ }),
|
||||
name: dialog.getByRole('textbox', { name: /名称/ }),
|
||||
id: dialog.locator('input[placeholder="例如: openai"]'),
|
||||
name: dialog.locator('input[placeholder="例如: OpenAI"]'),
|
||||
apiKey: dialog.locator('input[type="password"]'),
|
||||
baseUrl: dialog.getByRole('textbox', { name: /Base URL/ }),
|
||||
// Ant Design 6 按钮文字带空格:"保 存"、"取 消"
|
||||
saveBtn: dialog.locator('.ant-modal-footer').getByRole('button').last(),
|
||||
cancelBtn: dialog.locator('.ant-modal-footer').getByRole('button').first(),
|
||||
baseUrl: dialog.locator('input[placeholder="例如: https://api.openai.com/v1"]'),
|
||||
saveBtn: dialog.locator('.t-dialog__footer').getByRole('button', { name: '保存' }),
|
||||
cancelBtn: dialog.locator('.t-dialog__footer').getByRole('button', { name: '取消' }),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -29,17 +28,17 @@ test.describe('供应商管理', () => {
|
||||
});
|
||||
|
||||
test('应通过侧边栏导航切换页面', async ({ page }) => {
|
||||
await page.locator('.ant-layout-sider').getByText('用量统计').click();
|
||||
await page.locator('aside').getByText('用量统计').click();
|
||||
await expect(page.getByRole('heading', { name: '用量统计' })).toBeVisible();
|
||||
|
||||
await page.locator('.ant-layout-sider').getByText('供应商管理').click();
|
||||
await page.locator('aside').getByText('供应商管理').click();
|
||||
await expect(page.getByRole('heading', { name: '供应商管理' })).toBeVisible();
|
||||
});
|
||||
|
||||
test('应能打开添加供应商对话框', async ({ page }) => {
|
||||
await page.getByRole('button', { name: '添加供应商' }).click();
|
||||
|
||||
const dialog = page.getByRole('dialog');
|
||||
const dialog = page.locator('.t-dialog');
|
||||
await expect(dialog).toBeVisible();
|
||||
await expect(dialog.getByText('添加供应商')).toBeVisible();
|
||||
await expect(formInputs(page).id).toBeVisible();
|
||||
@@ -50,7 +49,7 @@ test.describe('供应商管理', () => {
|
||||
|
||||
test('应验证供应商表单必填字段', async ({ page }) => {
|
||||
await page.getByRole('button', { name: '添加供应商' }).click();
|
||||
await expect(page.getByRole('dialog')).toBeVisible();
|
||||
await expect(page.locator('.t-dialog')).toBeVisible();
|
||||
|
||||
await formInputs(page).saveBtn.click();
|
||||
|
||||
@@ -62,7 +61,7 @@ test.describe('供应商管理', () => {
|
||||
|
||||
test('应验证URL格式', async ({ page }) => {
|
||||
await page.getByRole('button', { name: '添加供应商' }).click();
|
||||
await expect(page.getByRole('dialog')).toBeVisible();
|
||||
await expect(page.locator('.t-dialog')).toBeVisible();
|
||||
|
||||
const inputs = formInputs(page);
|
||||
await inputs.id.fill('test-provider');
|
||||
@@ -77,40 +76,40 @@ test.describe('供应商管理', () => {
|
||||
|
||||
test('应能取消添加供应商', async ({ page }) => {
|
||||
await page.getByRole('button', { name: '添加供应商' }).click();
|
||||
await expect(page.getByRole('dialog')).toBeVisible();
|
||||
await expect(page.locator('.t-dialog')).toBeVisible();
|
||||
|
||||
await formInputs(page).id.fill('test-provider');
|
||||
await formInputs(page).cancelBtn.click();
|
||||
|
||||
await expect(page.getByRole('dialog')).not.toBeVisible();
|
||||
await expect(page.locator('.t-dialog')).not.toBeVisible();
|
||||
});
|
||||
|
||||
test('应显示供应商列表中的信息', async ({ page }) => {
|
||||
await expect(page.locator('.ant-table')).toBeVisible();
|
||||
const tableHeaders = page.locator('.ant-table-thead th');
|
||||
await expect(page.locator('.t-table')).toBeVisible();
|
||||
const tableHeaders = page.locator('.t-table__header th');
|
||||
const count = await tableHeaders.count();
|
||||
expect(count).toBeGreaterThanOrEqual(3);
|
||||
});
|
||||
|
||||
test('应能展开供应商查看模型列表', async ({ page }) => {
|
||||
const expandBtns = page.locator('.ant-table-row-expand-icon');
|
||||
const expandBtns = page.locator('.t-table__expandable-icon');
|
||||
const count = await expandBtns.count();
|
||||
|
||||
if (count > 0) {
|
||||
await expandBtns.first().click();
|
||||
await expect(page.locator('.ant-table-expanded-row').first()).toBeVisible();
|
||||
await expect(page.locator('.t-table__expanded-row').first()).toBeVisible();
|
||||
} else {
|
||||
test.skip();
|
||||
}
|
||||
});
|
||||
|
||||
test('应能打开编辑供应商对话框', async ({ page }) => {
|
||||
const editBtns = page.locator('.ant-table-tbody button:has-text("编辑")');
|
||||
const editBtns = page.locator('.t-table__body button:has-text("编辑")');
|
||||
const count = await editBtns.count();
|
||||
|
||||
if (count > 0) {
|
||||
await editBtns.first().click();
|
||||
const dialog = page.getByRole('dialog');
|
||||
const dialog = page.locator('.t-dialog');
|
||||
await expect(dialog).toBeVisible();
|
||||
await expect(dialog.getByText('编辑供应商')).toBeVisible();
|
||||
await expect(formInputs(page).id).toBeDisabled();
|
||||
@@ -120,15 +119,15 @@ test.describe('供应商管理', () => {
|
||||
});
|
||||
|
||||
test('应显示删除确认对话框', async ({ page }) => {
|
||||
const deleteBtns = page.locator('.ant-table-tbody button:has-text("删除")');
|
||||
const deleteBtns = page.locator('.t-table__body button:has-text("删除")');
|
||||
const count = await deleteBtns.count();
|
||||
|
||||
if (count > 0) {
|
||||
await deleteBtns.first().click();
|
||||
await expect(page.getByText('确定要删除这个供应商吗?')).toBeVisible();
|
||||
|
||||
// Popconfirm 按钮也带空格:"确 定"、"取 消"
|
||||
await page.locator('.ant-popconfirm-buttons').getByRole('button').first().click();
|
||||
// TDesign Popconfirm 取消按钮
|
||||
await page.locator('.t-popconfirm').getByRole('button', { name: '取消' }).click();
|
||||
} else {
|
||||
test.skip();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user