diff --git a/e2e/five-ring.spec.ts b/e2e/five-ring.spec.ts new file mode 100644 index 0000000..fe5d2b7 --- /dev/null +++ b/e2e/five-ring.spec.ts @@ -0,0 +1,121 @@ +/** + * 人走五环建新功能 · 浏览器全程点穿 e2e(实施计划 Section 6 / Task 24 的 UI 补全) + * + * 用真实浏览器走完整链路(curl e2e 之外补「UI 点穿」这一环): + * 登录 → 设计中心「+ 新建功能」→ 编排壳 → [+新建实体] 弹窗(建模器:标量字段 + 引用列 OWNER→SYS_USER) + * → 选 recipe + 填标题 → 生成页面(compile 拿 templateId) → 发布(五流+菜单+部署包) + * → 经后端 API 断言:发布后 /api/menu 树含该 templateId 节点。 + * + * 后端走 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()}`; + +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 { + const r = await apiJson('POST', '/api/auth/login', undefined, { account: 'admin', password: '111111' }); + return r.json.token as string; +} + +test.afterAll(async () => { + // 清理:删测试实体(drops 表 + 元数据)。页/菜单/流残留由跑后 psql 清(无运行时删除端点)。 + try { + const tok = await adminToken(); + await apiJson('DELETE', `/api/meta/entity/${TABLE}`, tok); + } catch { /* 清理尽力而为 */ } +}); + +test('人走五环 · 浏览器全程点穿(建实体含引用列 → compile → 发布 → 菜单可见)', 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(); + + // ── ②③环·建模器:新建实体(标量字段 NAME + 引用列 OWNER→SYS_USER)── + await page.getByTestId('nf-new-entity').click(); + await page.getByTestId('nf-create-tablename').fill(TABLE); + + // 标量字段 NAME + await page.getByTestId('field-add').click(); + await page.getByTestId('field-column').fill('NAME'); + await page.getByTestId('field-display').fill('名称'); + await page.getByTestId('field-submit').click(); + + // 引用列 OWNER → SYS_USER(DECISION-1 的 ReferencePicker) + await page.getByTestId('field-add').click(); + await page.getByTestId('field-column').fill('OWNER'); + await page.getByTestId('field-display').fill('负责人'); + await page.getByTestId('field-type').selectOption('引用'); + await page.getByTestId('ref-target').selectOption('SYS_USER'); + await page.getByTestId('field-submit').click(); + + await expect(page.getByTestId('field-row')).toHaveCount(2); + + // 建表并使用 → 进 recipe 步 + await page.getByTestId('nf-create-submit').click(); + await expect(page.getByTestId('nf-title')).toBeVisible({ timeout: 15_000 }); + + // ── ③环·选 recipe + 生成页面 ── + await page.getByTestId('nf-title').fill('PW五环演示'); + await page.getByTestId('nf-compile').click(); + await expect(page.getByTestId('nf-template-id')).toBeVisible({ timeout: 20_000 }); + const tid = (await page.getByTestId('nf-template-id').textContent())?.trim() ?? ''; + expect(tid).toContain('design-'); + + // ── ④环·发布(五流 + 菜单 + 部署包)── + await page.getByTestId('nf-publish').click(); + + // 后端断言:发布后 /api/menu 树应含该 templateId 节点(强端到端证据) + 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 || '') === tid) hit.push(n.name); + walk(n.children); + }); + walk(r.json?.roots || []); + return hit.length; + }, { timeout: 15_000, message: '发布后菜单树应出现新节点' }).toBeGreaterThan(0); +}); diff --git a/playwright.fivering.config.ts b/playwright.fivering.config.ts new file mode 100644 index 0000000..f444431 --- /dev/null +++ b/playwright.fivering.config.ts @@ -0,0 +1,26 @@ +import { defineConfig, devices } from '@playwright/test'; + +// 人走五环 UI 点穿 e2e 专用配置:webServer 反代到 8094(含本特性新代码), +// 与默认 playwright.config.ts(反代 8093 dev)隔离,不影响你正在跑的 8093。 +// 先单独启动 8094 后端,再 `npx playwright test -c playwright.fivering.config.ts`。 +export default defineConfig({ + testDir: './e2e', + testMatch: 'five-ring.spec.ts', + fullyParallel: false, + workers: 1, + timeout: 120_000, + reporter: [['list']], + use: { + baseURL: 'http://localhost:5174', + trace: 'off', + screenshot: 'only-on-failure', + }, + projects: [{ name: 'chromium', use: { ...devices['Desktop Chrome'] } }], + webServer: { + command: + 'NODE_OPTIONS=--max-http-header-size=65536 VITE_BACKEND_TARGET=http://localhost:8094 npx vite --port 5174 --strictPort', + url: 'http://localhost:5174', + reuseExistingServer: false, + timeout: 120_000, + }, +});