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:
@@ -1,11 +1,12 @@
|
||||
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 { vi, describe, it, expect } from 'vitest';
|
||||
|
||||
// NewFeatureShell 现以 amis wizard 渲染(<AmisRenderer>)。amis SDK(amisRequire) 是 index.html 注入的
|
||||
// 全局 UMD,jsdom 下不存在 → wizard 内部不在单测渲染;其端到端行为由 Playwright(e2e/five-ring.spec) 覆盖。
|
||||
// 单测仅守:① admin 守卫;② admin 下渲染壳容器 + 返回设计中心入口 + amis 挂载点。
|
||||
// NewFeatureShell 现以「先选页面类型卡 → 进 amis wizard」两段渲染(c735f24 合并入口)。amis SDK(amisRequire)
|
||||
// 是 index.html 注入的全局 UMD,jsdom 下不存在 → wizard 内部不在单测渲染;其端到端行为由 Playwright
|
||||
// (e2e/five-ring.spec、master-detail.spec) 覆盖。单测仅守:① admin 守卫;② admin 下先渲染页面类型选择卡;
|
||||
// ③ 选一种类型后渲染 amis 挂载点(wizard 壳)。
|
||||
let mockProfile: { userId: string; account: string; name: string; roles: string[] } | null = null;
|
||||
vi.mock('../auth/token', () => ({ getProfile: () => mockProfile }));
|
||||
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();
|
||||
});
|
||||
|
||||
it('管理员:渲染壳容器 + 返回设计中心 + amis 挂载点', () => {
|
||||
it('管理员:先渲染壳容器 + 返回设计中心 + 页面类型选择卡(含主子表)', () => {
|
||||
mockProfile = { userId: 'ADMIN', account: 'admin', name: 'x', roles: [] };
|
||||
renderShell();
|
||||
expect(screen.getByTestId('new-feature-shell')).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.getByText('← 重选页面类型')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -161,6 +161,30 @@ function buildWizardSchema(recipe: string): Record<string, unknown> {
|
||||
{ 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> = {
|
||||
@@ -169,7 +193,7 @@ function buildWizardSchema(recipe: string): Record<string, unknown> {
|
||||
if (isMD) {
|
||||
Object.assign(compileData, {
|
||||
childTable: '${childTablename}', linkColumn: 'MASTERID', listColumn: 'DETAILS', listLabel: '${childName}',
|
||||
childDerived: '${childDerived}', childRollup: '${childRollup}',
|
||||
childDerived: '${childDerived}', childRollup: '${childRollup}', childLinkage: '${childLinkage}',
|
||||
});
|
||||
} else {
|
||||
compileData.pageSize = '${pageSize}';
|
||||
@@ -210,7 +234,7 @@ function buildWizardSchema(recipe: string): Record<string, unknown> {
|
||||
return {
|
||||
type: 'page',
|
||||
className: 'h-full',
|
||||
data: { childDerived: [], childRollup: [] },
|
||||
data: { childDerived: [], childRollup: [], childLinkage: [] },
|
||||
body: {
|
||||
type: 'wizard',
|
||||
mode: 'horizontal',
|
||||
|
||||
Reference in New Issue
Block a user