feat(主子表): 父级汇总定义 UI + e2e 扩展
- MasterDetailShell step③ 汇总字段 combo(主表列+子表列+函数 SUM/COUNT/AVG/MIN/MAX); page data seed childRollup:[] 防未触碰时占位串致 compile 400 - e2e 派生用例扩展为「派生+汇总」:向导加 TOTAL 主列+汇总字段,断言发布页 __rollup + 主表 TOTAL static SUM(ARRAYMAP) 预览,_ADD 后 _LOAD 主表 TOTAL=55(服务端先派生再聚合) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -123,7 +123,7 @@ test('主子表 · 浏览器全程点穿(建主+子 → 生成主子页 →
|
|||||||
expect(names, '子行水泥/钢筋应级联落库').toEqual(['水泥', '钢筋']);
|
expect(names, '子行水泥/钢筋应级联落库').toEqual(['水泥', '钢筋']);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('主子表派生字段 · 向导加派生字段 → 发布页含 tpl 预览+__derive → _ADD 服务端逐行落库 AMOUNT', async ({ page }) => {
|
test('主子表派生字段+父级汇总 · 向导加派生/汇总 → 发布页 tpl+SUM预览+__derive+__rollup → _ADD 服务端派生再聚合 AMOUNT/TOTAL', async ({ page }) => {
|
||||||
test.setTimeout(120_000);
|
test.setTimeout(120_000);
|
||||||
|
|
||||||
// 登录
|
// 登录
|
||||||
@@ -147,6 +147,11 @@ test('主子表派生字段 · 向导加派生字段 → 发布页含 tpl 预览
|
|||||||
await expect(page.getByPlaceholder('TITLE').first()).toBeVisible({ timeout: 10_000 });
|
await expect(page.getByPlaceholder('TITLE').first()).toBeVisible({ timeout: 10_000 });
|
||||||
await page.getByPlaceholder('TITLE').first().fill('TITLE');
|
await page.getByPlaceholder('TITLE').first().fill('TITLE');
|
||||||
await page.getByPlaceholder('标题').first().fill('标题');
|
await page.getByPlaceholder('标题').first().fill('标题');
|
||||||
|
// 主表第 2 列 TOTAL(父级汇总目标列)
|
||||||
|
await page.getByRole('button', { name: '加字段' }).click();
|
||||||
|
await expect(page.getByPlaceholder('TITLE').nth(1)).toBeVisible({ timeout: 10_000 });
|
||||||
|
await page.getByPlaceholder('TITLE').nth(1).fill('TOTAL');
|
||||||
|
await page.getByPlaceholder('标题').nth(1).fill('总额');
|
||||||
await page.getByRole('button', { name: '保存并下一步' }).click();
|
await page.getByRole('button', { name: '保存并下一步' }).click();
|
||||||
|
|
||||||
// 步② 建子表:4 列 ITEMNAME/ITEMQTY/ITEMPRICE/AMOUNT(默认 string,求值器会数字强转)
|
// 步② 建子表:4 列 ITEMNAME/ITEMQTY/ITEMPRICE/AMOUNT(默认 string,求值器会数字强转)
|
||||||
@@ -168,6 +173,11 @@ test('主子表派生字段 · 向导加派生字段 → 发布页含 tpl 预览
|
|||||||
await expect(page.getByPlaceholder('MONEY')).toBeVisible({ timeout: 10_000 });
|
await expect(page.getByPlaceholder('MONEY')).toBeVisible({ timeout: 10_000 });
|
||||||
await page.getByPlaceholder('MONEY').fill('AMOUNT');
|
await page.getByPlaceholder('MONEY').fill('AMOUNT');
|
||||||
await page.getByPlaceholder('QTY*PRICE').fill('ITEMQTY*ITEMPRICE');
|
await page.getByPlaceholder('QTY*PRICE').fill('ITEMQTY*ITEMPRICE');
|
||||||
|
// 汇总字段 TOTAL = SUM(AMOUNT)(agg 默认 SUM)
|
||||||
|
await page.getByRole('button', { name: '加汇总字段' }).click();
|
||||||
|
await expect(page.getByPlaceholder('TOTAL')).toBeVisible({ timeout: 10_000 });
|
||||||
|
await page.getByPlaceholder('TOTAL').fill('TOTAL');
|
||||||
|
await page.getByPlaceholder('AMOUNT').fill('AMOUNT');
|
||||||
|
|
||||||
// 捕获 compile 响应拿 templateId(验 UI→编译产物)
|
// 捕获 compile 响应拿 templateId(验 UI→编译产物)
|
||||||
const compileResp = page.waitForResponse(
|
const compileResp = page.waitForResponse(
|
||||||
@@ -192,15 +202,21 @@ test('主子表派生字段 · 向导加派生字段 → 发布页含 tpl 预览
|
|||||||
// 必须显式 quickEdit:false——否则 amis needConfirm:false 会强注可编辑框覆盖 tpl 只读预览。
|
// 必须显式 quickEdit:false——否则 amis needConfirm:false 会强注可编辑框覆盖 tpl 只读预览。
|
||||||
expect(amountCol.quickEdit, '派生列 quickEdit 必须显式 false 才保留只读 tpl 预览').toBe(false);
|
expect(amountCol.quickEdit, '派生列 quickEdit 必须显式 false 才保留只读 tpl 预览').toBe(false);
|
||||||
|
|
||||||
// ★ 断言2:_ADD 带 __derive,子行不带 AMOUNT,服务端逐行算 30/25 落库
|
// ★ 断言1b:主表 TOTAL 汇总列只读 static + SUM 实时预览 + 表单 api 透传 __rollup
|
||||||
|
expect(JSON.stringify(schema), '表单 api 应透传 __rollup').toContain('__rollup');
|
||||||
|
expect(JSON.stringify(schema), '主表 TOTAL 应为 SUM(ARRAYMAP) 实时预览')
|
||||||
|
.toContain('SUM(ARRAYMAP(DETAILS, item => item.ITEMQTY*item.ITEMPRICE))');
|
||||||
|
|
||||||
|
// ★ 断言2:_ADD 带 __derive+__rollup,子行不带 AMOUNT、主体不带 TOTAL,服务端逐行派生再聚合
|
||||||
await expect.poll(async () => {
|
await expect.poll(async () => {
|
||||||
const r = await api('POST',
|
const r = await api('POST',
|
||||||
`/api/flow/${MASTER2}_ADD?__derive=${encodeURIComponent('DETAILS|AMOUNT=ITEMQTY*ITEMPRICE')}`, tok,
|
`/api/flow/${MASTER2}_ADD?__derive=${encodeURIComponent('DETAILS|AMOUNT=ITEMQTY*ITEMPRICE')}`
|
||||||
|
+ `&__rollup=${encodeURIComponent('TOTAL=SUM:DETAILS:AMOUNT')}`, tok,
|
||||||
{ TITLE: '派生单A', DETAILS: [
|
{ TITLE: '派生单A', DETAILS: [
|
||||||
{ ITEMNAME: '水泥', ITEMQTY: 3, ITEMPRICE: 10 },
|
{ ITEMNAME: '水泥', ITEMQTY: 3, ITEMPRICE: 10 },
|
||||||
{ ITEMNAME: '钢筋', ITEMQTY: 2, ITEMPRICE: '12.5' }] });
|
{ ITEMNAME: '钢筋', ITEMQTY: 2, ITEMPRICE: '12.5' }] });
|
||||||
return r.json?.status;
|
return r.json?.status;
|
||||||
}, { timeout: 25_000, message: '派生 _ADD 应成功' }).toBe(0);
|
}, { timeout: 25_000, message: '派生+汇总 _ADD 应成功' }).toBe(0);
|
||||||
|
|
||||||
const s = await api('POST', `/api/flow/${MASTER2}_SEARCH`, tok, {});
|
const s = await api('POST', `/api/flow/${MASTER2}_SEARCH`, tok, {});
|
||||||
expect(s.json?.status).toBe(0);
|
expect(s.json?.status).toBe(0);
|
||||||
@@ -213,4 +229,6 @@ test('主子表派生字段 · 向导加派生字段 → 发布页含 tpl 预览
|
|||||||
const details: any[] = loaded.json?.data?.result?.DETAILS ?? [];
|
const details: any[] = loaded.json?.data?.result?.DETAILS ?? [];
|
||||||
const amts = details.map((d) => Number(d.AMOUNT)).sort((a, b) => a - b);
|
const amts = details.map((d) => Number(d.AMOUNT)).sort((a, b) => a - b);
|
||||||
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]);
|
||||||
|
// 父级汇总:主表 TOTAL = SUM(明细金额) = 55(服务端先逐行派生再聚合,主体未提交 TOTAL)。
|
||||||
|
expect(Number(loaded.json?.data?.result?.TOTAL), '服务端聚合 TOTAL=55').toBe(55);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -35,9 +35,9 @@ function attrCombo(name: string): Record<string, unknown> {
|
|||||||
function buildSchema(): Record<string, unknown> {
|
function buildSchema(): Record<string, unknown> {
|
||||||
return {
|
return {
|
||||||
type: 'page',
|
type: 'page',
|
||||||
// seed childDerived=[] 使 ${childDerived} 恒解析为数组:派生字段 combo 未触碰时也不会发出
|
// seed childDerived/childRollup=[] 使 ${...} 恒解析为数组:combo 未触碰时也不会发出未解析占位串
|
||||||
// 未解析占位串导致 compile 反序列化 400(后端已另做 Object 容错,此处双保险)。
|
// 导致 compile 反序列化 400(后端已另做 Object 容错,此处双保险)。
|
||||||
data: { childDerived: [] },
|
data: { childDerived: [], childRollup: [] },
|
||||||
body: {
|
body: {
|
||||||
type: 'wizard',
|
type: 'wizard',
|
||||||
mode: 'horizontal',
|
mode: 'horizontal',
|
||||||
@@ -92,7 +92,7 @@ function buildSchema(): Record<string, unknown> {
|
|||||||
tableName: '${masterTable}', recipe: 'master-detail-v1', title: '${title}',
|
tableName: '${masterTable}', recipe: 'master-detail-v1', title: '${title}',
|
||||||
displayField: '${displayField}', childTable: '${childTablename}',
|
displayField: '${displayField}', childTable: '${childTablename}',
|
||||||
linkColumn: 'MASTERID', listColumn: 'DETAILS', listLabel: '${childName}',
|
linkColumn: 'MASTERID', listColumn: 'DETAILS', listLabel: '${childName}',
|
||||||
childDerived: '${childDerived}',
|
childDerived: '${childDerived}', childRollup: '${childRollup}',
|
||||||
},
|
},
|
||||||
responseData: { templateId: '${templateId}' },
|
responseData: { templateId: '${templateId}' },
|
||||||
},
|
},
|
||||||
@@ -114,6 +114,24 @@ function buildSchema(): Record<string, unknown> {
|
|||||||
{ type: 'input-text', name: 'formula', label: '公式', required: true, placeholder: 'QTY*PRICE' },
|
{ type: 'input-text', name: 'formula', label: '公式', required: true, placeholder: 'QTY*PRICE' },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
type: 'combo', name: 'childRollup', label: '汇总字段', multiple: true,
|
||||||
|
addable: true, removable: true, addButtonText: '加汇总字段', minLength: 0,
|
||||||
|
description: '可选。如 申请总额=明细金额之和:主表列填 TOTAL、子表列填 AMOUNT、函数选 SUM。'
|
||||||
|
+ '主表列须为主实体真实列、子表列须为子表真实列;落库前服务端权威聚合,主表单只读实时预览。',
|
||||||
|
items: [
|
||||||
|
{ type: 'input-text', name: 'masterColumn', label: '主表列', required: true, placeholder: 'TOTAL',
|
||||||
|
validations: { matchRegexp: '/^[A-Z][A-Z0-9_]{0,40}$/' },
|
||||||
|
validationErrors: { matchRegexp: '须为大写字母开头的主表真实列' } },
|
||||||
|
{ type: 'input-text', name: 'childColumn', label: '子表列', required: true, placeholder: 'AMOUNT',
|
||||||
|
validations: { matchRegexp: '/^[A-Z][A-Z0-9_]{0,40}$/' },
|
||||||
|
validationErrors: { matchRegexp: '须为大写字母开头的子表真实列' } },
|
||||||
|
{ type: 'select', name: 'agg', label: '函数', value: 'SUM', options: [
|
||||||
|
{ label: '求和 SUM', value: 'SUM' }, { label: '计数 COUNT', value: 'COUNT' },
|
||||||
|
{ label: '平均 AVG', value: 'AVG' }, { label: '最小 MIN', value: 'MIN' },
|
||||||
|
{ label: '最大 MAX', value: 'MAX' }] },
|
||||||
|
],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user