feat: 实现大模型模型列表与供应商管理,并接入 Playwright 测试

补齐 LLM 子菜单路由,落地模型列表与供应商管理页面交互,同时引入功能与视觉回归用例以便后续页面持续验证。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-26 02:01:40 +08:00
parent a09dcef3f1
commit c4872891f8
23 changed files with 1117 additions and 7 deletions

View File

@@ -0,0 +1,9 @@
import { expect, test } from '../fixtures/auth';
test('登录态可直接访问总览', async ({ page }) => {
await page.goto('/dashboard');
await expect(page.getByText('近7日对话趋势')).toBeVisible();
await expect(page.getByText('模型调用占比')).toBeVisible();
await expect(page.getByText('异常告警')).toBeVisible();
});

View File

@@ -0,0 +1,48 @@
import { expect, test } from '../fixtures/auth';
test.describe('大模型 / 模型列表', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/llm/models');
await page.getByRole('table').waitFor();
});
test('展示列表及主要操作', async ({ page }) => {
await expect(page.getByRole('button', { name: '新增模型' })).toBeVisible();
await expect(page.getByRole('table')).toBeVisible();
await expect(page.getByText('GPT-4o', { exact: true })).toBeVisible();
});
test('可新增模型', async ({ page }) => {
await page.getByRole('button', { name: '新增模型' }).click();
const dialog = page.getByRole('dialog', { name: '新增模型' });
await expect(dialog).toBeVisible();
await dialog.getByLabel('模型名称').fill('测试模型');
await dialog.getByLabel('模型 ID').fill('test-model');
await dialog.getByRole('button', { name: '保 存' }).click();
await expect(page.getByText('测试模型', { exact: true })).toBeVisible();
});
test('可切换模型状态并查看用量', async ({ page }) => {
const statusSwitch = page.getByRole('switch', { name: 'GPT-4o状态' });
await expect(statusSwitch).toBeChecked();
await statusSwitch.click();
await expect(statusSwitch).not.toBeChecked();
const row = page.getByRole('row').filter({ hasText: 'GPT-4o' });
await row.getByRole('button', { name: '用量' }).click();
await expect(page.getByText('GPT-4o 用量详情')).toBeVisible();
await expect(page.getByText('近 7 日用量趋势')).toBeVisible();
});
test('可调整排序并删除模型', async ({ page }) => {
await page.getByRole('spinbutton', { name: 'GPT-4o排序' }).fill('2');
await expect(page.locator('.ant-table-tbody .ant-table-row').first()).toContainText('Claude-3.5-Sonnet');
const row = page.getByRole('row').filter({ hasText: 'GPT-4o' });
await row.getByRole('button', { name: '删除' }).click();
await page.getByRole('button', { name: '确 定' }).click();
await expect(page.getByText('GPT-4o', { exact: true })).toHaveCount(0);
});
});

View File

@@ -0,0 +1,54 @@
import { expect, test } from '../fixtures/auth';
test.describe('大模型 / 供应商管理', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/llm/providers');
await page.getByRole('table').waitFor();
});
test('展示列表及主要操作', async ({ page }) => {
await expect(page.getByRole('button', { name: '新增供应商' })).toBeVisible();
await expect(page.getByRole('table')).toBeVisible();
await expect(page.getByText('OpenAI', { exact: true })).toBeVisible();
await expect(page.getByText('https://api.openai.com/v1')).toBeVisible();
});
test('可搜索供应商', async ({ page }) => {
await page.getByPlaceholder('搜索供应商名称').fill('DeepSeek');
await expect(page.getByText('DeepSeek', { exact: true })).toBeVisible();
await expect(page.getByText('OpenAI', { exact: true })).toHaveCount(0);
});
test('可新增供应商', async ({ page }) => {
await page.getByRole('button', { name: '新增供应商' }).click();
const dialog = page.getByRole('dialog', { name: '新增供应商' });
await expect(dialog).toBeVisible();
await dialog.getByLabel('供应商名称').fill('测试供应商');
await dialog.getByLabel('Base URL').fill('https://api.test.com/v1');
await dialog.getByRole('button', { name: '保 存' }).click();
await expect(page.getByText('测试供应商', { exact: true })).toBeVisible();
});
test('可切换供应商状态并测试连通', async ({ page }) => {
const statusSwitch = page.getByRole('switch', { name: 'OpenAI状态' });
await expect(statusSwitch).toBeChecked();
await statusSwitch.click();
await expect(statusSwitch).not.toBeChecked();
const row = page.getByRole('row').filter({ hasText: 'OpenAI' });
await row.getByRole('button', { name: '测试连通' }).click();
await expect(page.getByText('OpenAI 连通正常')).toBeVisible();
});
test('可编辑凭证', async ({ page }) => {
const row = page.getByRole('row').filter({ hasText: 'DeepSeek' });
await row.getByRole('button', { name: '编辑凭证' }).click();
const dialog = page.getByRole('dialog', { name: '编辑供应商' });
await expect(dialog).toBeVisible();
await dialog.getByLabel('API Key').fill('sk-test-key');
await dialog.getByRole('button', { name: '保 存' }).click();
await expect(page.getByText('供应商已更新')).toBeVisible();
});
});

12
e2e/pages/login.spec.ts Normal file
View File

@@ -0,0 +1,12 @@
import { expect, test } from '@playwright/test';
test('账号密码可登录并进入总览', async ({ page }) => {
await page.goto('/login');
await page.getByPlaceholder('用户名: admin or user').fill('admin');
await page.getByPlaceholder('密码: 123456').fill('123456');
await page.getByRole('button', { name: '登 录' }).click();
await expect(page).toHaveURL(/\/dashboard$/);
await expect(page.getByText('近7日对话趋势')).toBeVisible();
});