P4-5: 前端改写后脚本指令 onEvent 重放胶水
AmisRenderer embed 前注册自定义 amis 动作 replayScriptCommands: scriptCommands.translateCommands 把后端 facade 返回的 29 UI 动词指令 翻译成 amis 动作(show/hidden/static/setValue/setOptions/addOption/ toast/reload/...),逐条经 amis-core runActions 重放;带 componentId 者走组件级路由,componentId=大写列名与字段 name 天然对齐。 e2e(playwright,后端 8086 + dev):2 真实 FULL_AUTO facade-only 模板 - 福利保险结算单 inited → setFieldVisible 隐藏 BEGINDATE(截图留档) - 办公用品领用申请 change → bindField(getFieldValue) 回填 OLD_STORE_ID (服务端 getFieldValue 从 item 求值闭环,截图留档),2 passed。 测试:vitest scriptCommands 12 + registerReplayAction 4;tsc+build 全绿。 工具链:devDeps 加 vitest/jsdom/testing-library/playwright + test script。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
BIN
e2e/__screenshots__/office-collar-setvalue.png
Normal file
BIN
e2e/__screenshots__/office-collar-setvalue.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 27 KiB |
BIN
e2e/__screenshots__/welfare-hidden.png
Normal file
BIN
e2e/__screenshots__/welfare-hidden.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 22 KiB |
56
e2e/script-replay.spec.ts
Normal file
56
e2e/script-replay.spec.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { expect, test, type Page } from '@playwright/test';
|
||||
|
||||
// ============================================================================
|
||||
// P4-5 端到端:改写后脚本挂回 amis 页面 schema 的 onEvent 重放
|
||||
// ----------------------------------------------------------------------------
|
||||
// 链路:页面渲染(mock schema 带 onEvent)→ 触发 inited/change → ajax 调
|
||||
// /api/script/execute-template(vite proxy → 后端 8086,取改写后脚本经 facade 执行)
|
||||
// → 返回 amis 指令数组 → 前端 replayScriptCommands 自定义动作逐条 doAction。
|
||||
// 口径:schema 取自前端 mock(public/schemas/*.json,onEvent 形态 = 转换器 attachScriptOnEvent
|
||||
// 产出,已单测固定);脚本与指令来自后端真实改写产物 + 真实保真层引擎(非桩)。
|
||||
// amis 渲染需登录态:种入任意非空令牌过 RequireAuth(schema 走 mock 源,免后端鉴权;
|
||||
// 仅 /api/script/execute-template 走后端,POC 默认链不拦截)。
|
||||
// ============================================================================
|
||||
|
||||
// 种入登录态(RequireAuth 仅校验令牌非空;schema 为 mock 源不发后端 schema 请求)
|
||||
async function seedAuth(page: Page) {
|
||||
await page.addInitScript(() => {
|
||||
localStorage.setItem('eip4_token', 'e2e-fake-token');
|
||||
localStorage.setItem(
|
||||
'eip4_profile',
|
||||
JSON.stringify({ userId: 'e2e', account: 'e2e', name: 'e2e', roles: ['ADMIN'] }),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
test('inited 重放:福利保险结算单脚本隐藏 BEGINDATE 字段', async ({ page }) => {
|
||||
await seedAuth(page);
|
||||
await page.goto('/page/welfare-settlement');
|
||||
|
||||
// amis 渲染出表单(起始年字段先在)
|
||||
await expect(page.getByText('起始年')).toBeVisible({ timeout: 20_000 });
|
||||
|
||||
// inited 触发 → ajax 取脚本 setFieldVisible("BEGINDATE", false) → 重放 hidden
|
||||
// 断言 BEGINDATE 字段(起始日期 label)被隐藏
|
||||
await expect(page.getByText('起始日期')).toBeHidden({ timeout: 15_000 });
|
||||
|
||||
await page.screenshot({ path: 'e2e/__screenshots__/welfare-hidden.png', fullPage: true });
|
||||
});
|
||||
|
||||
test('change 重放 + 服务端 getFieldValue 闭环:办公用品领用申请回填 OLD_STORE_ID', async ({ page }) => {
|
||||
await seedAuth(page);
|
||||
await page.goto('/page/office-collar');
|
||||
|
||||
await expect(page.getByText('仓库', { exact: true })).toBeVisible({ timeout: 20_000 });
|
||||
|
||||
// 改 STORE_ID → change 触发 → ajax 传 item(含 STORE_ID)→ 脚本
|
||||
// bindField("OLD_STORE_ID", getFieldValue("STORE_ID")) → 重放 setValue OLD_STORE_ID
|
||||
const storeInput = page.locator('input[name="STORE_ID"]');
|
||||
await storeInput.fill('WH-7788');
|
||||
await storeInput.blur();
|
||||
|
||||
// 断言 OLD_STORE_ID 被脚本回填为 STORE_ID 的值(服务端 getFieldValue 从 item 求值闭环)
|
||||
await expect(page.locator('input[name="OLD_STORE_ID"]')).toHaveValue('WH-7788', { timeout: 15_000 });
|
||||
|
||||
await page.screenshot({ path: 'e2e/__screenshots__/office-collar-setvalue.png', fullPage: true });
|
||||
});
|
||||
Reference in New Issue
Block a user