Files
eip4-web/e2e/five-ring.spec.ts
zhengwr 2b261e319f feat(modeler): 建实体向导加「所属分类」选择器(source /api/meta/entity-types)
wizard 步①新增 amis select「所属分类」(必填,221 分类可搜),提交时随 attributes 一并 POST。
e2e 补选分类交互。修用户反馈的「实体所属分类缺失」。

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

113 lines
5.4 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);
// 所属分类(amis select,必填):点开下拉 → 选第一个分类
await page.locator('.cxd-Select').first().click();
await page.locator('.cxd-Select-option').first().click();
// 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 断言。