feat(主子表): 引用驱动联动 向导映射 UI + 真事件 e2e
- NewFeatureShell: 主子表步③加「引用联动」combo(引用列 → 目标子列 ← 源实体列),
childLinkage 透传 compile;构建时分支(不依赖 amis 运行时 step 跳步),页面 data seed []
- e2e/master-detail: 引用驱动联动用例——真后端 schema(GET /api/page/schema) + 真 picker
数据 + 真 Playwright 事件填充 + 提交落库验证(选物料→带出单价/规格,用户未手填仍随
_ADD 级联落库;引用 FK 本身也落库)
- e2e/linkage-probe: amis input-table 行内联动机制隔离验证(钉死 selectedItems 是对象非
数组;远程 source 选项携整行列;多行 ${index} 按行隔离防串台)
- NewFeatureShell.test: 修过时断言(c735f24 类型选择卡后需先选类型才出 amis 挂载点)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
271
e2e/linkage-probe.spec.ts
Normal file
271
e2e/linkage-probe.spec.ts
Normal file
@@ -0,0 +1,271 @@
|
|||||||
|
/**
|
||||||
|
* 隔离验证 · amis input-table 行内联动机制(真 Playwright 事件)。
|
||||||
|
*
|
||||||
|
* 交接首要指令:上一会话「引用驱动联动」后端方案做了但手搓浏览器 fill 没验成功(疑 `.click()` 没触发
|
||||||
|
* React onEvent / `${index}` componentId 替换)→ 全部回退。本 probe 不碰后端,用 page.evaluate 直接
|
||||||
|
* amis.embed 注入「手写最小 schema」,再用真 Playwright 鼠标/键盘事件驱动,钉死正确 schema 形态:
|
||||||
|
* ① 对照组:input-number → setValue componentId=amount_${index}(amis 官方范式 input-table.md:2536)。
|
||||||
|
* ② select(物料带 PRICE/SPEC 整行)→ onEvent.change → setValue price_${index}/spec_${index}
|
||||||
|
* = ${event.data.selectedItems[0].PRICE/SPEC}。
|
||||||
|
* 验证兄弟列是否真被填充。结论决定后端编译器怎么发 schema(id 挂列上 vs quickEdit)。
|
||||||
|
*
|
||||||
|
* 纯前端:select 用 static options 不打后端,故任意 vite(默认 config 反代 8093 即可,不依赖 8094)。
|
||||||
|
*/
|
||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
|
||||||
|
test('amis input-table 行内联动:input-number 与 select 都应填充兄弟列', async ({ page }) => {
|
||||||
|
const consoleErrors: string[] = [];
|
||||||
|
page.on('console', (m) => { if (m.type() === 'error') consoleErrors.push(m.text()); });
|
||||||
|
|
||||||
|
await page.goto('/login');
|
||||||
|
await page.waitForFunction(() => typeof (window as Window & { amisRequire?: unknown }).amisRequire === 'function',
|
||||||
|
null, { timeout: 30_000 });
|
||||||
|
|
||||||
|
// 注入一个覆盖层 host(不抹掉 React root,避免 React reconciliation 报错),embed 手写 schema。
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const w = window as unknown as { amisRequire: (p: string) => any };
|
||||||
|
const host = document.createElement('div');
|
||||||
|
host.id = 'probe-host';
|
||||||
|
host.style.cssText =
|
||||||
|
'position:fixed;inset:0;z-index:99999;background:#fff;padding:24px;overflow:auto';
|
||||||
|
document.body.appendChild(host);
|
||||||
|
const amis = w.amisRequire('amis/embed');
|
||||||
|
const schema = {
|
||||||
|
type: 'page',
|
||||||
|
data: { rows: [{}] }, // 预置一行,免去点「新增」
|
||||||
|
body: {
|
||||||
|
type: 'form',
|
||||||
|
title: '行内联动验证',
|
||||||
|
wrapWithPanel: false,
|
||||||
|
body: [
|
||||||
|
{
|
||||||
|
type: 'input-table',
|
||||||
|
name: 'rows',
|
||||||
|
id: 'eg-rows',
|
||||||
|
addable: true,
|
||||||
|
removable: true,
|
||||||
|
needConfirm: false,
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
type: 'input-number',
|
||||||
|
name: 'qty',
|
||||||
|
label: '数量',
|
||||||
|
onEvent: {
|
||||||
|
change: {
|
||||||
|
actions: [
|
||||||
|
{ actionType: 'setValue', componentId: 'amount_${index}', args: { value: '${qty * 10}' } },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// 目标列带「真实 type」(经 quickEdit),且 id 挂在列上 —— 镜像后端编译器对普通子列的渲染形态,
|
||||||
|
// 验证 id-on-column + 显式 quickEdit type 仍能被 setValue componentId 命中。
|
||||||
|
{ name: 'amount', id: 'amount_${index}', label: '金额', quickEdit: { type: 'input-number', name: 'amount' } },
|
||||||
|
{
|
||||||
|
type: 'select',
|
||||||
|
name: 'material',
|
||||||
|
label: '物料',
|
||||||
|
// 整行 option(PRICE/SPEC 作为额外列),模拟 picker/list 的 items(responseData options:${items})
|
||||||
|
options: [
|
||||||
|
{ label: '水泥', value: 'C1', PRICE: '10', SPEC: '袋装' },
|
||||||
|
{ label: '钢筋', value: 'S1', PRICE: '20', SPEC: '12mm' },
|
||||||
|
],
|
||||||
|
onEvent: {
|
||||||
|
change: {
|
||||||
|
// 单选 select 的 change 事件 selectedItems = 被选 Option 对象本身(非数组),故 .PRICE 直取。
|
||||||
|
// (Select.tsx changeValue: dispatchEvent('change',{value,options,items,selectedItems:value}))
|
||||||
|
actions: [
|
||||||
|
{ actionType: 'setValue', componentId: 'price_${index}', args: { value: '${event.data.selectedItems.PRICE}' } },
|
||||||
|
{ actionType: 'setValue', componentId: 'spec_${index}', args: { value: '${event.data.selectedItems.SPEC}' } },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ name: 'price', id: 'price_${index}', label: '单价' },
|
||||||
|
{ name: 'spec', id: 'spec_${index}', label: '规格' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'tpl',
|
||||||
|
id: 'probe-out',
|
||||||
|
tpl: 'PROBEOUT amount=[${rows[0].amount}] price=[${rows[0].price}] spec=[${rows[0].spec}]',
|
||||||
|
className: 'probe-out-marker',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
amis.embed(host, schema, {}, {});
|
||||||
|
});
|
||||||
|
|
||||||
|
const host = page.locator('#probe-host');
|
||||||
|
await expect(host.locator('table')).toBeVisible({ timeout: 15_000 });
|
||||||
|
await expect(page.getByText(/PROBEOUT/)).toBeVisible({ timeout: 10_000 });
|
||||||
|
|
||||||
|
const probe = page.getByText(/PROBEOUT/);
|
||||||
|
|
||||||
|
// ---- ① 对照组:input-number qty → amount = qty*10 ----
|
||||||
|
// input-number 的输入框:取第一行第一列的数字输入。用 .cxd-Number 更稳。
|
||||||
|
const numberCell = host.locator('.cxd-Number input').first();
|
||||||
|
await numberCell.click();
|
||||||
|
await numberCell.fill('5');
|
||||||
|
await numberCell.press('Tab'); // 失焦触发 change
|
||||||
|
// tpl 重渲染有批处理延迟,用 toContainText 自动重试(非一次性读)。
|
||||||
|
await expect(probe, 'input-number 联动应把 amount 填成 50').toContainText('amount=[50]', { timeout: 8_000 });
|
||||||
|
console.log('[probe] after input-number qty=5 →', await probe.textContent());
|
||||||
|
|
||||||
|
// ---- ② select 物料 水泥 → price=10 spec=袋装 ----
|
||||||
|
const sel = host.locator('.cxd-Select').first();
|
||||||
|
await sel.click();
|
||||||
|
await page.waitForTimeout(300);
|
||||||
|
await page.getByText('水泥', { exact: true }).click();
|
||||||
|
await expect(probe, 'select 联动应把 price 填成 10').toContainText('price=[10]', { timeout: 8_000 });
|
||||||
|
await expect(probe, 'select 联动应把 spec 填成 袋装').toContainText('spec=[袋装]', { timeout: 8_000 });
|
||||||
|
console.log('[probe] after select 水泥 →', await probe.textContent());
|
||||||
|
|
||||||
|
console.log('[probe] console errors:', JSON.stringify(consoleErrors.slice(0, 20)));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('amis select source(远程 picker) 选项仍携带整行额外列 → 联动填充', async ({ page }) => {
|
||||||
|
// 真实后端场景:子表引用列 select 用 source=/api/picker/{ref}/list(responseData options:${items}),
|
||||||
|
// items 是整行(含 PRICE/SPEC + _id/_label)。验证远程 source 选项被选中后 selectedItems 仍带额外列。
|
||||||
|
await page.goto('/login');
|
||||||
|
await page.waitForFunction(() => typeof (window as Window & { amisRequire?: unknown }).amisRequire === 'function',
|
||||||
|
null, { timeout: 30_000 });
|
||||||
|
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const w = window as unknown as { amisRequire: (p: string) => any };
|
||||||
|
const host = document.createElement('div');
|
||||||
|
host.id = 'probe-host2';
|
||||||
|
host.style.cssText = 'position:fixed;inset:0;z-index:99999;background:#fff;padding:24px;overflow:auto';
|
||||||
|
document.body.appendChild(host);
|
||||||
|
const amis = w.amisRequire('amis/embed');
|
||||||
|
// mock fetcher:模拟 picker/list 返回整行 items(每行带 PRICE/SPEC/_id/_label/value/label)。
|
||||||
|
const fetcher = (opt: { url: string }) => {
|
||||||
|
if (opt.url.includes('/api/picker/')) {
|
||||||
|
const items = [
|
||||||
|
{ _id: 'C1', _label: '水泥', value: 'C1', label: '水泥', PRICE: '10', SPEC: '袋装' },
|
||||||
|
{ _id: 'S1', _label: '钢筋', value: 'S1', label: '钢筋', PRICE: '20', SPEC: '12mm' },
|
||||||
|
];
|
||||||
|
return Promise.resolve({ status: 200, headers: {}, data: { status: 0, msg: '', data: { items, options: items, total: 2 } } });
|
||||||
|
}
|
||||||
|
return Promise.resolve({ status: 200, headers: {}, data: { status: 0, msg: '', data: {} } });
|
||||||
|
};
|
||||||
|
const schema = {
|
||||||
|
type: 'page',
|
||||||
|
data: { rows: [{}] },
|
||||||
|
body: {
|
||||||
|
type: 'form',
|
||||||
|
title: '远程 source 联动验证',
|
||||||
|
wrapWithPanel: false,
|
||||||
|
body: [
|
||||||
|
{
|
||||||
|
type: 'input-table',
|
||||||
|
name: 'rows',
|
||||||
|
id: 'eg-rows2',
|
||||||
|
addable: true,
|
||||||
|
removable: true,
|
||||||
|
needConfirm: false,
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
type: 'select',
|
||||||
|
name: 'material',
|
||||||
|
label: '物料',
|
||||||
|
source: { method: 'get', url: '/api/picker/MATERIAL/list', responseData: { options: '${items}' } },
|
||||||
|
labelField: '_label',
|
||||||
|
valueField: '_id',
|
||||||
|
onEvent: {
|
||||||
|
change: {
|
||||||
|
actions: [
|
||||||
|
{ actionType: 'setValue', componentId: 'price_${index}', args: { value: '${event.data.selectedItems.PRICE}' } },
|
||||||
|
{ actionType: 'setValue', componentId: 'spec_${index}', args: { value: '${event.data.selectedItems.SPEC}' } },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ name: 'price', id: 'price_${index}', label: '单价' },
|
||||||
|
{ name: 'spec', id: 'spec_${index}', label: '规格' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{ type: 'tpl', id: 'probe-out2', tpl: 'PROBEOUT2 price=[${rows[0].price}] spec=[${rows[0].spec}]' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
amis.embed(host, schema, {}, { fetcher });
|
||||||
|
});
|
||||||
|
|
||||||
|
const host = page.locator('#probe-host2');
|
||||||
|
await expect(host.locator('table')).toBeVisible({ timeout: 15_000 });
|
||||||
|
const probe = page.getByText(/PROBEOUT2/);
|
||||||
|
|
||||||
|
const sel = host.locator('.cxd-Select').first();
|
||||||
|
await sel.click();
|
||||||
|
await page.waitForTimeout(400); // 等远程 options 加载
|
||||||
|
await page.getByText('水泥', { exact: true }).click();
|
||||||
|
await expect(probe, '远程 source 选项联动应填 price=10').toContainText('price=[10]', { timeout: 8_000 });
|
||||||
|
await expect(probe, '远程 source 选项联动应填 spec=袋装').toContainText('spec=[袋装]', { timeout: 8_000 });
|
||||||
|
console.log('[probe2] after remote select 水泥 →', await probe.textContent());
|
||||||
|
});
|
||||||
|
|
||||||
|
test('amis 多行 input-table:componentId=col_${index} 按行隔离填充(行0选水泥/行1选钢筋, 互不串台)', async ({ page }) => {
|
||||||
|
// ★ 关键回归(对抗评审 HIGH 揪出):联动靠 ${index} 让 componentId 逐行展开。单行测覆盖不到「选第 2 行
|
||||||
|
// 是否误填第 0 行」的串台风险(属红线「绝不写错值」)。本测 seed 两行,分别选不同物料,断言各行各填各的。
|
||||||
|
await page.goto('/login');
|
||||||
|
await page.waitForFunction(() => typeof (window as Window & { amisRequire?: unknown }).amisRequire === 'function',
|
||||||
|
null, { timeout: 30_000 });
|
||||||
|
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const w = window as unknown as { amisRequire: (p: string) => any };
|
||||||
|
const host = document.createElement('div');
|
||||||
|
host.id = 'probe-host3';
|
||||||
|
host.style.cssText = 'position:fixed;inset:0;z-index:99999;background:#fff;padding:24px;overflow:auto';
|
||||||
|
document.body.appendChild(host);
|
||||||
|
const amis = w.amisRequire('amis/embed');
|
||||||
|
const schema = {
|
||||||
|
type: 'page',
|
||||||
|
data: { rows: [{}, {}] }, // 两行
|
||||||
|
body: {
|
||||||
|
type: 'form', title: '多行联动隔离验证', wrapWithPanel: false,
|
||||||
|
body: [
|
||||||
|
{
|
||||||
|
type: 'input-table', name: 'rows', id: 'eg-rows3',
|
||||||
|
addable: true, removable: true, needConfirm: false,
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
type: 'select', name: 'material', label: '物料',
|
||||||
|
options: [
|
||||||
|
{ label: '水泥', value: 'C1', PRICE: '10' },
|
||||||
|
{ label: '钢筋', value: 'S1', PRICE: '20' },
|
||||||
|
],
|
||||||
|
onEvent: { change: { actions: [
|
||||||
|
{ actionType: 'setValue', componentId: 'price_${index}', args: { value: '${event.data.selectedItems.PRICE}' } },
|
||||||
|
] } },
|
||||||
|
},
|
||||||
|
{ name: 'price', id: 'price_${index}', label: '单价' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{ type: 'tpl', tpl: 'MULTI r0=[${rows[0].price}] r1=[${rows[1].price}]' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
amis.embed(host, schema, {}, {});
|
||||||
|
});
|
||||||
|
|
||||||
|
const host = page.locator('#probe-host3');
|
||||||
|
await expect(host.locator('table')).toBeVisible({ timeout: 15_000 });
|
||||||
|
const probe = page.getByText(/MULTI/);
|
||||||
|
|
||||||
|
// 行0 选水泥(10)
|
||||||
|
await host.locator('.cxd-Select').nth(0).click();
|
||||||
|
await page.waitForTimeout(200);
|
||||||
|
await page.getByText('水泥', { exact: true }).click();
|
||||||
|
await expect(probe, '行0选水泥应填 r0=10').toContainText('r0=[10]', { timeout: 8_000 });
|
||||||
|
|
||||||
|
// 行1 选钢筋(20):必须只填 r1,绝不串改 r0。
|
||||||
|
await host.locator('.cxd-Select').nth(1).click();
|
||||||
|
await page.waitForTimeout(200);
|
||||||
|
await page.getByText('钢筋', { exact: true }).click();
|
||||||
|
await expect(probe, '行1选钢筋应填 r1=20').toContainText('r1=[20]', { timeout: 8_000 });
|
||||||
|
// 串台守卫:r0 仍须是 10(行1的选择没污染行0)。
|
||||||
|
await expect(probe, '行0不应被行1串改').toContainText('r0=[10] r1=[20]', { timeout: 8_000 });
|
||||||
|
console.log('[probe3] multi-row →', await probe.textContent());
|
||||||
|
});
|
||||||
@@ -15,6 +15,10 @@ const CHILD = `EIP4PT_MDW${TS}C`;
|
|||||||
// 第二个用例(派生+汇总)专用表
|
// 第二个用例(派生+汇总)专用表
|
||||||
const MASTER2 = `EIP4PT_MDD${TS}M`;
|
const MASTER2 = `EIP4PT_MDD${TS}M`;
|
||||||
const CHILD2 = `EIP4PT_MDD${TS}C`;
|
const CHILD2 = `EIP4PT_MDD${TS}C`;
|
||||||
|
// 第三个用例(引用驱动联动)专用表:物料引用实体 + 主表 + 子表(含引用列)
|
||||||
|
const MAT = `EIP4PT_MTL${TS}`;
|
||||||
|
const MASTER3 = `EIP4PT_LKM${TS}`;
|
||||||
|
const CHILD3 = `EIP4PT_LKC${TS}`;
|
||||||
|
|
||||||
function api(method: string, path: string, token?: string, body?: unknown): Promise<{ status: number; json: any }> {
|
function api(method: string, path: string, token?: string, body?: unknown): Promise<{ status: number; json: any }> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@@ -71,9 +75,35 @@ test.afterAll(async () => {
|
|||||||
await api('DELETE', `/api/meta/entity/${MASTER}`, tok);
|
await api('DELETE', `/api/meta/entity/${MASTER}`, tok);
|
||||||
await api('DELETE', `/api/meta/entity/${CHILD2}`, tok);
|
await api('DELETE', `/api/meta/entity/${CHILD2}`, tok);
|
||||||
await api('DELETE', `/api/meta/entity/${MASTER2}`, tok);
|
await api('DELETE', `/api/meta/entity/${MASTER2}`, tok);
|
||||||
|
// 子表引用物料,先删子/主,再删物料引用实体。
|
||||||
|
await api('DELETE', `/api/meta/entity/${CHILD3}`, tok);
|
||||||
|
await api('DELETE', `/api/meta/entity/${MASTER3}`, tok);
|
||||||
|
await api('DELETE', `/api/meta/entity/${MAT}`, tok);
|
||||||
} catch { /* best effort */ }
|
} catch { /* best effort */ }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 建实体 → 取 entityId。attributes 见各列 {column,display,type,referenceTable?,mandatory?}。
|
||||||
|
async function createEntity(tok: string, table: string, name: string, etype: string,
|
||||||
|
attributes: Record<string, unknown>[], masterTable?: string): Promise<string> {
|
||||||
|
const body: Record<string, unknown> = { tablename: table, name, entitytype: etype, attributes };
|
||||||
|
if (masterTable) body.masterTable = masterTable;
|
||||||
|
const r = await api('POST', '/api/meta/entity', tok, body);
|
||||||
|
if (r.json?.status !== 0) throw new Error(`createEntity ${table} 失败: ${JSON.stringify(r.json)}`);
|
||||||
|
return r.json.data.entityId as string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 编译 maintenance-crud + 发布(建默认流),供物料实体可 _ADD 行(picker 读真实数据)。
|
||||||
|
// menuName 须 ≤ sys_menu.name varchar(20);本测不走菜单导航(直接 embed schema),故用短名即可。
|
||||||
|
async function compileAndPublish(tok: string, table: string, entityId: string, menuName: string): Promise<void> {
|
||||||
|
const c = await api('POST', '/api/design/recipe/compile', tok,
|
||||||
|
{ tableName: table, recipe: 'maintenance-crud-v1', title: `${table}页` });
|
||||||
|
const tid = c.json?.data?.templateId;
|
||||||
|
if (!tid) throw new Error(`compile ${table} 失败: ${JSON.stringify(c.json)}`);
|
||||||
|
const p = await api('POST', '/api/design/publish', tok,
|
||||||
|
{ entityId, tableName: table, templateId: tid, menuName, generateDeploymentPackage: false });
|
||||||
|
if (p.json?.status !== 0) throw new Error(`publish ${table} 失败: ${JSON.stringify(p.json)}`);
|
||||||
|
}
|
||||||
|
|
||||||
test('主子表 · 统一向导全程点穿(选主子表 → 建主+子 → 生成主子页 → 发布 → 级联保存子行)', async ({ page }) => {
|
test('主子表 · 统一向导全程点穿(选主子表 → 建主+子 → 生成主子页 → 发布 → 级联保存子行)', async ({ page }) => {
|
||||||
test.setTimeout(120_000);
|
test.setTimeout(120_000);
|
||||||
await openWizardAsMasterDetail(page);
|
await openWizardAsMasterDetail(page);
|
||||||
@@ -218,3 +248,138 @@ test('主子表派生字段+父级汇总 · 统一向导加派生/汇总 → 发
|
|||||||
expect(amts, '服务端派生 AMOUNT=数量×单价(3×10=30,2×12.5=25)').toEqual([25, 30]);
|
expect(amts, '服务端派生 AMOUNT=数量×单价(3×10=30,2×12.5=25)').toEqual([25, 30]);
|
||||||
expect(Number(loaded.json?.data?.result?.TOTAL), '服务端聚合 TOTAL=55').toBe(55);
|
expect(Number(loaded.json?.data?.result?.TOTAL), '服务端聚合 TOTAL=55').toBe(55);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('引用驱动联动 · 子表选物料(真 Playwright 事件)→带出单价/规格, 校验 schema + 真实填充 + 提交落库', async ({ page }) => {
|
||||||
|
test.setTimeout(120_000);
|
||||||
|
const tok = await adminToken();
|
||||||
|
|
||||||
|
// 取一个实体分类 id
|
||||||
|
const types = await api('GET', '/api/meta/entity-types', tok);
|
||||||
|
const etype = (types.json?.data ?? [])[0]?.id;
|
||||||
|
expect(etype, '应有可用实体分类').toBeTruthy();
|
||||||
|
|
||||||
|
// ── 设置(API):物料引用实体(含 PRICE/SPEC)+ 发布建流 + 2 行(picker 读真实数据)──
|
||||||
|
const matId = await createEntity(tok, MAT, '物料', etype, [
|
||||||
|
{ column: 'MATNAME', display: '物料名', type: 'string', mandatory: true },
|
||||||
|
{ column: 'PRICE', display: '单价', type: 'number' },
|
||||||
|
{ column: 'SPEC', display: '规格', type: 'string' },
|
||||||
|
]);
|
||||||
|
await compileAndPublish(tok, MAT, matId, '物料联动');
|
||||||
|
expect((await api('POST', `/api/flow/${MAT}_ADD`, tok,
|
||||||
|
{ MATNAME: '水泥', PRICE: 10, SPEC: '袋装' })).json?.status, '物料水泥 _ADD').toBe(0);
|
||||||
|
expect((await api('POST', `/api/flow/${MAT}_ADD`, tok,
|
||||||
|
{ MATNAME: '钢筋', PRICE: 20, SPEC: '12mm' })).json?.status, '物料钢筋 _ADD').toBe(0);
|
||||||
|
|
||||||
|
// ── 设置(API):主表 + 子表(子表含引用列 ITEMID→物料、被带出列 ITEMPRICE/ITEMSPEC)──
|
||||||
|
const masterId = await createEntity(tok, MASTER3, '采购联动', etype, [
|
||||||
|
{ column: 'TITLE', display: '标题', type: 'string', mandatory: true },
|
||||||
|
]);
|
||||||
|
await createEntity(tok, CHILD3, '采购联动明细', etype, [
|
||||||
|
{ column: 'ITEMNAME', display: '明细名', type: 'string' },
|
||||||
|
{ column: 'ITEMID', display: '物料', type: 'reference', referenceTable: MAT },
|
||||||
|
{ column: 'ITEMPRICE', display: '单价', type: 'number' },
|
||||||
|
{ column: 'ITEMSPEC', display: '规格', type: 'string' },
|
||||||
|
], MASTER3);
|
||||||
|
|
||||||
|
// ── 编译 master-detail + 引用驱动联动(ITEMID 选中→带出 ITEMPRICE←PRICE / ITEMSPEC←SPEC)──
|
||||||
|
const compileResp = await api('POST', '/api/design/recipe/compile', tok, {
|
||||||
|
tableName: MASTER3, recipe: 'master-detail-v1', title: '采购联动单',
|
||||||
|
childTable: CHILD3, linkColumn: 'MASTERID', listColumn: 'DETAILS', listLabel: '明细',
|
||||||
|
childLinkage: [{ refColumn: 'ITEMID', fills: [
|
||||||
|
{ target: 'ITEMPRICE', source: 'PRICE' }, { target: 'ITEMSPEC', source: 'SPEC' }] }],
|
||||||
|
});
|
||||||
|
const tid = compileResp.json?.data?.templateId;
|
||||||
|
expect(tid, 'master-detail compile 应返回 templateId').toBeTruthy();
|
||||||
|
await api('POST', '/api/design/publish', tok,
|
||||||
|
{ entityId: masterId, tableName: MASTER3, templateId: tid, menuName: '采购联动单', generateDeploymentPackage: false });
|
||||||
|
|
||||||
|
// ── 断言 1:生成的 schema 形态正确(select source=picker + onEvent setValue selectedItems.<src>,无 [0])──
|
||||||
|
const schema = (await api('GET', `/api/page/schema/${tid}`, tok)).json;
|
||||||
|
const sj = JSON.stringify(schema);
|
||||||
|
expect(sj, 'ITEMID 列应为 picker select 取物料').toContain(`/api/picker/${MAT}/list`);
|
||||||
|
expect(sj, '联动应发 setValue 带出 PRICE').toContain('${event.data.selectedItems.PRICE}');
|
||||||
|
expect(sj, '联动目标列 ITEMPRICE 应挂 id=ITEMPRICE_${index}').toContain('ITEMPRICE_${index}');
|
||||||
|
// 联动 onEvent 里单选 select 的 selectedItems 是对象非数组,绝不能写 event.data.selectedItems[0]
|
||||||
|
// (这是上一会话 fill 失败的真因)。注意 CRUD 编辑按钮的 ${selectedItems[0]}=选中主行(数组)是另一回事,合法。
|
||||||
|
expect(sj, '联动取值绝不能含 event.data.selectedItems[0]').not.toContain('event.data.selectedItems[0]');
|
||||||
|
|
||||||
|
// 取 picker 真实选项:找出「水泥」行的显示标签(_label 可能是显示名也可能是裸 id)与其 PRICE,
|
||||||
|
// UI 按真实 _label 文本点选(不假设显示名=MATNAME,规避新实体无显示列时 _label=裸 id 的情况)。
|
||||||
|
const picker = await api('GET', `/api/picker/${MAT}/list`, tok);
|
||||||
|
const pickerItems: any[] = picker.json?.data?.items ?? [];
|
||||||
|
const cement = pickerItems.find((i) => i.MATNAME === '水泥');
|
||||||
|
expect(cement, 'picker 应返回水泥行').toBeTruthy();
|
||||||
|
expect(String(cement.PRICE), 'picker items 应携带整行 PRICE 列(联动源)').toBe('10');
|
||||||
|
const cementLabel = String(cement._label).trim();
|
||||||
|
|
||||||
|
// ── 断言 2:真实渲染 + 真 Playwright 事件填充 ──
|
||||||
|
// 取真实 schema 的「新增」表单(含真实 input-table 引用列 select),seed 一行 + 探针 tpl,amis.embed
|
||||||
|
// 用「真后端 token fetcher」渲染(picker 打真实 8094)。不是手写 schema——是后端真产物。
|
||||||
|
await page.goto('/login');
|
||||||
|
await page.waitForFunction(() => typeof (window as Window & { amisRequire?: unknown }).amisRequire === 'function',
|
||||||
|
null, { timeout: 30_000 });
|
||||||
|
|
||||||
|
await page.evaluate(([realSchema, token, masterTable]) => {
|
||||||
|
const w = window as unknown as { amisRequire: (p: string) => any };
|
||||||
|
const host = document.createElement('div');
|
||||||
|
host.id = 'lk-host';
|
||||||
|
host.style.cssText = 'position:fixed;inset:0;z-index:99999;background:#fff;padding:24px;overflow:auto';
|
||||||
|
document.body.appendChild(host);
|
||||||
|
// 真后端 fetcher:复用 vite /api 代理到 8094,带 admin Bearer。
|
||||||
|
const fetcher = async (opt: { url: string; method?: string; data?: unknown }) => {
|
||||||
|
const method = (opt.method || 'get').toLowerCase();
|
||||||
|
const res = await fetch(opt.url, {
|
||||||
|
method,
|
||||||
|
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
|
||||||
|
body: method === 'get' ? undefined : JSON.stringify(opt.data || {}),
|
||||||
|
});
|
||||||
|
const json = await res.json().catch(() => ({}));
|
||||||
|
return { status: res.status, headers: {}, data: json };
|
||||||
|
};
|
||||||
|
// 从真实 schema 取「新增」按钮的对话框表单(含真 input-table)。
|
||||||
|
const hb = (realSchema as any).body.headerToolbar as any[];
|
||||||
|
const addBtn = hb.find((b) => b && b.id === '新增');
|
||||||
|
const form = addBtn.dialog.body;
|
||||||
|
// 探针 tpl 放进表单内(数据域含 DETAILS),实时反映联动填充结果。
|
||||||
|
form.body.push({ type: 'tpl',
|
||||||
|
tpl: 'PROBELK price=[${DETAILS[0].ITEMPRICE}] spec=[${DETAILS[0].ITEMSPEC}]' });
|
||||||
|
const pageSchema = { type: 'page',
|
||||||
|
data: { TITLE: '联动单A', DETAILS: [{}] }, // seed 一行免点「新增行」
|
||||||
|
body: [form] };
|
||||||
|
void masterTable;
|
||||||
|
w.amisRequire('amis/embed').embed(host, pageSchema, {}, { fetcher });
|
||||||
|
}, [schema, tok, MASTER3] as const);
|
||||||
|
|
||||||
|
const host = page.locator('#lk-host');
|
||||||
|
await expect(host.locator('table')).toBeVisible({ timeout: 15_000 });
|
||||||
|
const probe = page.getByText(/PROBELK/);
|
||||||
|
|
||||||
|
// 真事件:打开子表行内 ITEMID select → 选「水泥」。
|
||||||
|
const sel = host.locator('.cxd-Select').first();
|
||||||
|
await sel.click();
|
||||||
|
// 等真实 picker options 渲染(替固定 sleep),再在下拉里(scoped .cxd-Select-option)按 _label 点选——
|
||||||
|
// 避免 getByText 误命中全屏 host 上的其它同文本节点。
|
||||||
|
await page.locator('.cxd-Select-option').first().waitFor({ timeout: 8_000 });
|
||||||
|
await page.locator('.cxd-Select-option', { hasText: cementLabel }).first().click();
|
||||||
|
|
||||||
|
// ★ 联动填充:选物料→自动带出单价 10 / 规格 袋装(真后端 schema + 真事件,非手写)。
|
||||||
|
await expect(probe, '选水泥应带出 ITEMPRICE=10').toContainText('price=[10]', { timeout: 8_000 });
|
||||||
|
await expect(probe, '选水泥应带出 ITEMSPEC=袋装').toContainText('spec=[袋装]', { timeout: 8_000 });
|
||||||
|
|
||||||
|
// ── 断言 3:提交 → 落库(_LOAD 回读子行 ITEMPRICE=10,证明填充值真随主表 _ADD 级联落库)──
|
||||||
|
await host.getByRole('button', { name: '提交' }).click();
|
||||||
|
await expect.poll(async () => {
|
||||||
|
const s = await api('POST', `/api/flow/${MASTER3}_SEARCH`, tok, {});
|
||||||
|
return (s.json?.data?.items ?? []).find((r: any) => r.TITLE === '联动单A') ? 'ok' : 'wait';
|
||||||
|
}, { timeout: 20_000, message: '提交后主表应查到联动单A' }).toBe('ok');
|
||||||
|
const s = await api('POST', `/api/flow/${MASTER3}_SEARCH`, tok, {});
|
||||||
|
const rowA = (s.json?.data?.items ?? []).find((r: any) => r.TITLE === '联动单A');
|
||||||
|
const pk = `${MASTER3}_ID`;
|
||||||
|
const loaded = await api('POST', `/api/flow/${MASTER3}_LOAD`, tok, { [pk]: String(rowA[pk]).trim() });
|
||||||
|
const child = (loaded.json?.data?.result?.DETAILS ?? [])[0];
|
||||||
|
expect(child, '应级联落子行').toBeTruthy();
|
||||||
|
// 所选物料(引用列 FK=_id)本身应落库——证明 select valueField=_id 绑定生效(fill 之外的主契约)。
|
||||||
|
expect(String(child.ITEMID).trim(), '所选物料引用FK应落库').toBe(String(cement._id).trim());
|
||||||
|
expect(Number(child.ITEMPRICE), '联动带出的单价应随提交落库=10(用户未手填)').toBe(10);
|
||||||
|
expect(String(child.ITEMSPEC).trim(), '联动带出的规格应随提交落库=袋装').toBe('袋装');
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import '@testing-library/jest-dom';
|
import '@testing-library/jest-dom';
|
||||||
import { render, screen } from '@testing-library/react';
|
import { render, screen, fireEvent } from '@testing-library/react';
|
||||||
import { MemoryRouter } from 'react-router-dom';
|
import { MemoryRouter } from 'react-router-dom';
|
||||||
import { vi, describe, it, expect } from 'vitest';
|
import { vi, describe, it, expect } from 'vitest';
|
||||||
|
|
||||||
// NewFeatureShell 现以 amis wizard 渲染(<AmisRenderer>)。amis SDK(amisRequire) 是 index.html 注入的
|
// NewFeatureShell 现以「先选页面类型卡 → 进 amis wizard」两段渲染(c735f24 合并入口)。amis SDK(amisRequire)
|
||||||
// 全局 UMD,jsdom 下不存在 → wizard 内部不在单测渲染;其端到端行为由 Playwright(e2e/five-ring.spec) 覆盖。
|
// 是 index.html 注入的全局 UMD,jsdom 下不存在 → wizard 内部不在单测渲染;其端到端行为由 Playwright
|
||||||
// 单测仅守:① admin 守卫;② admin 下渲染壳容器 + 返回设计中心入口 + amis 挂载点。
|
// (e2e/five-ring.spec、master-detail.spec) 覆盖。单测仅守:① admin 守卫;② admin 下先渲染页面类型选择卡;
|
||||||
|
// ③ 选一种类型后渲染 amis 挂载点(wizard 壳)。
|
||||||
let mockProfile: { userId: string; account: string; name: string; roles: string[] } | null = null;
|
let mockProfile: { userId: string; account: string; name: string; roles: string[] } | null = null;
|
||||||
vi.mock('../auth/token', () => ({ getProfile: () => mockProfile }));
|
vi.mock('../auth/token', () => ({ getProfile: () => mockProfile }));
|
||||||
vi.mock('../components/AmisRenderer', () => ({ AmisRenderer: () => <div data-testid="amis-mount" /> }));
|
vi.mock('../components/AmisRenderer', () => ({ AmisRenderer: () => <div data-testid="amis-mount" /> }));
|
||||||
@@ -28,12 +29,25 @@ describe('NewFeatureShell(amis wizard 壳)', () => {
|
|||||||
expect(screen.queryByTestId('new-feature-shell')).toBeNull();
|
expect(screen.queryByTestId('new-feature-shell')).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('管理员:渲染壳容器 + 返回设计中心 + amis 挂载点', () => {
|
it('管理员:先渲染壳容器 + 返回设计中心 + 页面类型选择卡(含主子表)', () => {
|
||||||
mockProfile = { userId: 'ADMIN', account: 'admin', name: 'x', roles: [] };
|
mockProfile = { userId: 'ADMIN', account: 'admin', name: 'x', roles: [] };
|
||||||
renderShell();
|
renderShell();
|
||||||
expect(screen.getByTestId('new-feature-shell')).toBeInTheDocument();
|
expect(screen.getByTestId('new-feature-shell')).toBeInTheDocument();
|
||||||
expect(screen.getByText('新建功能 · 人走五环')).toBeInTheDocument();
|
expect(screen.getByText('新建功能 · 人走五环')).toBeInTheDocument();
|
||||||
expect(screen.getByText('← 返回设计中心')).toBeInTheDocument();
|
expect(screen.getByText('← 返回设计中心')).toBeInTheDocument();
|
||||||
|
// 先出页面类型选择卡(未选类型时不渲 wizard)。
|
||||||
|
expect(screen.getByTestId('recipe-chooser')).toBeInTheDocument();
|
||||||
|
expect(screen.getByTestId('dc-recipe-maintenance')).toBeInTheDocument();
|
||||||
|
expect(screen.getByTestId('dc-recipe-master-detail')).toBeInTheDocument();
|
||||||
|
expect(screen.queryByTestId('amis-mount')).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('管理员:选页面类型后渲染 amis wizard 挂载点', () => {
|
||||||
|
mockProfile = { userId: 'ADMIN', account: 'admin', name: 'x', roles: [] };
|
||||||
|
renderShell();
|
||||||
|
fireEvent.click(screen.getByTestId('dc-recipe-master-detail'));
|
||||||
expect(screen.getByTestId('amis-mount')).toBeInTheDocument();
|
expect(screen.getByTestId('amis-mount')).toBeInTheDocument();
|
||||||
|
// 选类型后头部按钮变为「重选页面类型」。
|
||||||
|
expect(screen.getByText('← 重选页面类型')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -161,6 +161,30 @@ function buildWizardSchema(recipe: string): Record<string, unknown> {
|
|||||||
{ label: '最大 MAX', value: 'MAX' }] },
|
{ label: '最大 MAX', value: 'MAX' }] },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
type: 'combo', name: 'childLinkage', label: '引用联动', multiple: true,
|
||||||
|
addable: true, removable: true, addButtonText: '加引用联动', minLength: 0,
|
||||||
|
description: '可选。子表「引用列」(类型=引用)选中某条记录时,自动带出该记录的其它列到同行子列。'
|
||||||
|
+ '如 选物料→带出单价/规格:引用列填 ITEMID(须为引用类型子列);带出映射 目标子列 ITEMPRICE ← 源列 PRICE。'
|
||||||
|
+ '选中时实时填充,提交保存所填值。',
|
||||||
|
items: [
|
||||||
|
{ type: 'input-text', name: 'refColumn', label: '引用列', required: true, placeholder: 'ITEMID',
|
||||||
|
columnClassName: 'w-sm', validations: { matchRegexp: '/^[A-Z][A-Z0-9_]{0,40}$/' },
|
||||||
|
validationErrors: { matchRegexp: '须为大写字母开头的引用类型子列' } },
|
||||||
|
{
|
||||||
|
type: 'combo', name: 'fills', label: '带出映射', multiple: true,
|
||||||
|
addable: true, removable: true, addButtonText: '加带出', minLength: 1,
|
||||||
|
items: [
|
||||||
|
{ type: 'input-text', name: 'target', label: '目标子列', required: true, placeholder: 'ITEMPRICE',
|
||||||
|
validations: { matchRegexp: '/^[A-Z][A-Z0-9_]{0,40}$/' },
|
||||||
|
validationErrors: { matchRegexp: '须为大写字母开头的子表真实列' } },
|
||||||
|
{ type: 'input-text', name: 'source', label: '源列(引用实体)', required: true, placeholder: 'PRICE',
|
||||||
|
validations: { matchRegexp: '/^[A-Z][A-Z0-9_]{0,40}$/' },
|
||||||
|
validationErrors: { matchRegexp: '须为大写字母开头的引用实体列' } },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const compileData: Record<string, unknown> = {
|
const compileData: Record<string, unknown> = {
|
||||||
@@ -169,7 +193,7 @@ function buildWizardSchema(recipe: string): Record<string, unknown> {
|
|||||||
if (isMD) {
|
if (isMD) {
|
||||||
Object.assign(compileData, {
|
Object.assign(compileData, {
|
||||||
childTable: '${childTablename}', linkColumn: 'MASTERID', listColumn: 'DETAILS', listLabel: '${childName}',
|
childTable: '${childTablename}', linkColumn: 'MASTERID', listColumn: 'DETAILS', listLabel: '${childName}',
|
||||||
childDerived: '${childDerived}', childRollup: '${childRollup}',
|
childDerived: '${childDerived}', childRollup: '${childRollup}', childLinkage: '${childLinkage}',
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
compileData.pageSize = '${pageSize}';
|
compileData.pageSize = '${pageSize}';
|
||||||
@@ -210,7 +234,7 @@ function buildWizardSchema(recipe: string): Record<string, unknown> {
|
|||||||
return {
|
return {
|
||||||
type: 'page',
|
type: 'page',
|
||||||
className: 'h-full',
|
className: 'h-full',
|
||||||
data: { childDerived: [], childRollup: [] },
|
data: { childDerived: [], childRollup: [], childLinkage: [] },
|
||||||
body: {
|
body: {
|
||||||
type: 'wizard',
|
type: 'wizard',
|
||||||
mode: 'horizontal',
|
mode: 'horizontal',
|
||||||
|
|||||||
Reference in New Issue
Block a user