oh-my-muse/muse-studio/e2e/agent-create.spec.ts

46 lines
2.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { expect, test, type Page } from '@playwright/test';
/**
* 智能体创建 e2e(真实后端,MSW off)。
*
* 只覆盖“新建智能体 → 真实 POST → 列表回显”,刻意不点击“运行试用”,避免把 New-API 外部依赖带入本切片。
*/
const TOKEN = 'test1';
async function seedToken(page: Page): Promise<void> {
await page.addInitScript((t) => {
window.localStorage.setItem('accessToken', t);
window.localStorage.setItem('tenantId', '1');
}, TOKEN);
}
test('用户可在真实后端创建自建智能体并在列表回显', async ({ page }) => {
await seedToken(page);
const uniqueName = `活体智能体-e2e-${Date.now()}`;
await page.goto('/agents');
await expect(page.getByRole('heading', { name: '智能体工作台' })).toBeVisible({ timeout: 15_000 });
await page.getByRole('button', { name: '新建智能体' }).click();
await page.getByPlaceholder('例如:角色口吻校对员').fill(uniqueName);
await page.getByPlaceholder('说明智能体适合的写作场景').fill('Playwright 活体验收创建的自建智能体');
await page.getByPlaceholder('写下能力目标、输入要求、输出格式和禁止越权范围')
.fill('只做结构化润色建议,不写入作品事实。');
const createResponsePromise = page.waitForResponse((response) =>
response.url().includes('/app-api/muse/agents') &&
response.request().method() === 'POST' &&
response.status() === 201
);
await page.getByRole('button', { name: '创建智能体' }).click();
const createResponse = await createResponsePromise;
const createBody = await createResponse.json();
expect(createBody.code).toBe(0);
expect(createBody.data?.agentId).toBeTruthy();
await expect(page.getByRole('button', { name: '关闭创建' })).toBeHidden({ timeout: 15_000 });
await expect(page.getByRole('button', { name: new RegExp(`${uniqueName} v1`) })).toBeVisible({ timeout: 15_000 });
await expect(page.getByText('我创建的').first()).toBeVisible();
});