Files
eip4-web/e2e/five-ring.spec.ts
zhengwr 71535929f7 refactor(design-center): 编排壳/AI入口改用 amis 渲染(替手搓原生表单)
用户反馈手搓 input/select/嵌套弹窗又丑又不一致。改:
- NewFeatureShell → amis wizard(建实体 combo字段含引用列 → 选recipe → 发布),三步 api 直打后端、数据自动透传
- AiFeatureForm → amis form(api adaptor 包裹非标响应 + ARRAYFILTER 取草稿 targetId)
- 组件测试改为守 admin/容器(amis 内部交 Playwright);five-ring.spec 改驱动 amis wizard
与全站业务页同一套 AmisRenderer,外观一致。wizard e2e 1 passed / 72 vitest / build 绿。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-20 14:39:00 +08:00

110 lines
5.2 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.
/**
* 人走五环建新功能 · 浏览器全程点穿 e2e(实施计划 Section 6 / Task 24 的 UI 补全)
*
* NewFeatureShell 现为 amis wizard。本 spec 用真实浏览器走完整链路:
* 登录 → 设计中心「+ 新建功能」→ amis wizard:①建实体(combo 字段) → ②生成页(recipe+标题) → ③发布
* → 经后端 API 断言:发布后 /api/menu 树出现该实体的 design-<table> 模板节点。
*
* 后端走 8094(含本特性新代码,不碰 dev 默认 8093)。运行:
* 先 java -jar platform-app...jar --spring.profiles.active=dev --server.port=8094
* 再 npx playwright test -c playwright.fivering.config.ts
* 数据纪律:afterAll DELETE 测试实体(EIP4 前缀门);net-new 页/菜单/流无运行时删除端点(§F),由跑后 psql 清。
*/
import { expect, test } from '@playwright/test';
import http from 'node:http';
const BACKEND_PORT = 8094;
const TABLE = `EIP4PT_PW${Date.now()}`;
const TPL_PREFIX = `design-${TABLE.toLowerCase().replace(/_/g, '-')}`;
function apiJson(method: string, path: string, token?: string, body?: unknown): Promise<{ status: number; json: any }> {
return new Promise((resolve, reject) => {
const data = body ? JSON.stringify(body) : undefined;
const req = http.request(
{
hostname: 'localhost', port: BACKEND_PORT, path, method,
headers: {
'Content-Type': 'application/json',
...(token ? { Authorization: `Bearer ${token}` } : {}),
...(data ? { 'Content-Length': Buffer.byteLength(data) } : {}),
},
},
(res) => {
let buf = '';
res.on('data', (c) => (buf += c));
res.on('end', () => {
try { resolve({ status: res.statusCode ?? 0, json: buf ? JSON.parse(buf) : null }); }
catch { resolve({ status: res.statusCode ?? 0, json: buf }); }
});
},
);
req.on('error', reject);
if (data) req.write(data);
req.end();
});
}
async function adminToken(): Promise<string> {
const r = await apiJson('POST', '/api/auth/login', undefined, { account: 'admin', password: '111111' });
return r.json.token as string;
}
test.afterAll(async () => {
try {
const tok = await adminToken();
await apiJson('DELETE', `/api/meta/entity/${TABLE}`, tok);
} catch { /* 清理尽力而为 */ }
});
test('人走五环 · 浏览器全程点穿(amis wizard:建实体 → 生成页 → 发布 → 菜单可见)', async ({ page }) => {
test.setTimeout(120_000);
// ── 登录(真实 React 表单)──
await page.goto('/login');
await page.getByRole('textbox').first().fill('admin');
await page.locator('input[type="password"]').fill('111111');
await page.getByRole('button', { name: '登录' }).click();
await page.waitForURL((u) => !u.pathname.endsWith('/login'), { timeout: 15_000 });
// ── 设计中心 → + 新建功能 ──
await page.goto('/design-center');
await page.getByTestId('dc-new-feature').click();
await expect(page.getByTestId('new-feature-shell')).toBeVisible();
// ── 环①②·amis wizard 步1 建实体(combo minLength=1 自带一行字段)──
await expect(page.getByPlaceholder('OA_DEMO')).toBeVisible({ timeout: 15_000 });
await page.getByPlaceholder('OA_DEMO').fill(TABLE);
// combo 默认不带行(显示「<空>」),先点「加字段」再填
await page.getByRole('button', { name: '加字段' }).click();
await expect(page.getByPlaceholder('TITLE').first()).toBeVisible({ timeout: 10_000 });
await page.getByPlaceholder('TITLE').first().fill('NAME'); // combo 行·列名
await page.getByPlaceholder('标题').first().fill('名称'); // combo 行·显示名
await page.getByRole('button', { name: '保存并下一步' }).click();
// ── 环③·步2 选 recipe + 标题 → compile ──
await expect(page.getByPlaceholder('如:客户等级维护')).toBeVisible({ timeout: 20_000 });
await page.getByPlaceholder('如:客户等级维护').fill('PW五环演示');
await page.getByRole('button', { name: '保存并下一步' }).click();
// ── 环④·步3 发布(菜单名已由 ${title} 预填)──
await page.getByRole('button', { name: '完成' }).click();
// ── 后端断言:发布后 /api/menu 树出现该实体的 design-<table> 模板节点 ──
const tok = await adminToken();
await expect.poll(async () => {
const r = await apiJson('GET', '/api/menu', tok);
const hit: string[] = [];
const walk = (ns: any[]) => (ns || []).forEach((n) => {
if ((n.templateId || '').startsWith(TPL_PREFIX)) hit.push(n.name);
walk(n.children);
});
walk(r.json?.roots || []);
return hit.length;
}, { timeout: 20_000, message: '发布后菜单树应出现 design-<table> 节点' }).toBeGreaterThan(0);
});
// 注:AI ①面 amis form 的渲染已人工 live 验证(截图 + 提交按钮),其 READY_FOR_HUMAN_REVIEW
// 后端链路由 curl e2e 证(status=READY + PAGE_SCHEMA.targetId,见 scripts/five-ring-acceptance.sh)。
// 不在此自动化 AI 全程:auto-develop 的 localApply/smoke 以 baseUrl 回调,dev 经 5174→8094 代理回跳时
// SPA 路由会干扰 smoke(生产同源无此问题),属测试环境工件,故不纳入 Playwright 断言。