fix(modeler): 侧板评审收口——会签保真读回/切换节点回归测试/meta可见性+清除确认
I-1 会签保真:isSequential/elementVariable/completionCondition 原值读进 CosignState、 写回用读到的值(真实库 isSequential=true×2 / elementVariable=assign|loop_assign / 完成条件 >0.6×7 原强写会静默改坏派任);完成条件 body 不匹配预设→「自定义(保留)」态,仅主动选预设才 改写;elementVariable 缺省态与原本无 completionCondition 写回时省略,不凭空写空。parseCompletion 改精确匹配预设串(修 >0.55 误判过半的子串 bug)。新增串行开关+循环变量输入。 I-2 双节点回归:A(meta X)→B(meta Y)→编辑 B→写回 meta===Y≠X,防串台。 I-3 meta 可见性:顶部只读徽标显示非空业务 meta(如任务后置服务 PM_XXX);删光 items 且含非空 业务 meta 时 window.confirm 确认才写 undefined(取消则本地态与引擎均不变)。 顺手:扩展属性强制 activiti:/flowable: 前缀 + 拉黑有专用控件的键(candidateUsers/formKey/ collection/elementVariable);非标准办理人表达式(parse→null)显示「编辑将覆盖」警示;订阅 commandStack.changed,非自身写入时对当前选中重灌本地态(undo/redo 脱同步防线)。 测试 Eip4Panel 21→33;全量 vitest 186 绿 / tsc -b 干净 / npm run build 成功。仅动自己文件。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||
import { render, screen, fireEvent, act, waitFor } from '@testing-library/react';
|
||||
import { SYNTHETIC_BPMN } from './moddle/fixtures/synthetic-full-surface.bpmn';
|
||||
import { parseCandidateExpression } from './candidateExpression';
|
||||
import {
|
||||
parseCandidateExpression,
|
||||
buildCandidateExpression,
|
||||
type UserPropertyItem,
|
||||
} from './candidateExpression';
|
||||
|
||||
// formKey 下拉数据源:mock,其中一个 id 对齐 fixture 的 formKey 值。
|
||||
vi.mock('../api/processModeler', () => ({
|
||||
@@ -28,7 +32,8 @@ const REAL_CANDIDATE = extractAttr('activiti:candidateUsers'); // type=position
|
||||
|
||||
// ── 假 modeler / element(vi.fn 捕获 updateProperties 载荷) ────────────────────
|
||||
function makeModeler() {
|
||||
let handler: ((e: unknown) => void) | null = null;
|
||||
let selHandler: ((e: unknown) => void) | null = null;
|
||||
let cmdHandler: (() => void) | null = null;
|
||||
const updateProperties = vi.fn();
|
||||
const created: Array<Record<string, unknown>> = [];
|
||||
const moddle = {
|
||||
@@ -40,7 +45,8 @@ function makeModeler() {
|
||||
};
|
||||
const modeling = { updateProperties };
|
||||
const on = vi.fn((ev: string, cb: (e: unknown) => void) => {
|
||||
if (ev === 'selection.changed') handler = cb;
|
||||
if (ev === 'selection.changed') selHandler = cb;
|
||||
if (ev === 'commandStack.changed') cmdHandler = cb as () => void;
|
||||
});
|
||||
const off = vi.fn();
|
||||
const get = (svc: string) => (svc === 'modeling' ? modeling : svc === 'moddle' ? moddle : {});
|
||||
@@ -49,11 +55,38 @@ function makeModeler() {
|
||||
// 避免「update not wrapped in act」告警。
|
||||
const select = (element: unknown) =>
|
||||
act(async () => {
|
||||
handler?.({ newSelection: element ? [element] : [] });
|
||||
selHandler?.({ newSelection: element ? [element] : [] });
|
||||
await Promise.resolve();
|
||||
await Promise.resolve();
|
||||
});
|
||||
return { modeler, updateProperties, moddle, created, select };
|
||||
// 模拟外部 undo/redo:commandStack.changed。
|
||||
const fireCommandStack = () =>
|
||||
act(async () => {
|
||||
cmdHandler?.();
|
||||
await Promise.resolve();
|
||||
});
|
||||
return { modeler, updateProperties, moddle, created, select, fireCommandStack };
|
||||
}
|
||||
|
||||
/** 全项目 window.confirm 默认放行(具体测试可再 spy 覆盖);afterEach 复原。 */
|
||||
let confirmSpy: ReturnType<typeof vi.spyOn>;
|
||||
beforeEach(() => {
|
||||
confirmSpy = vi.spyOn(window, 'confirm').mockReturnValue(true);
|
||||
});
|
||||
afterEach(() => {
|
||||
confirmSpy.mockRestore();
|
||||
});
|
||||
|
||||
/** 一个内容非空、meta 为空的合法办理人表达式(清空时不触发 confirm)。 */
|
||||
function candidateNoMeta(content = 'u1'): string {
|
||||
const item: UserPropertyItem = {
|
||||
type: 'user',
|
||||
content,
|
||||
isCandidate: true,
|
||||
isSendMail: false,
|
||||
isSendPhone: false,
|
||||
};
|
||||
return buildCandidateExpression([item], 'candidate', {});
|
||||
}
|
||||
|
||||
/** 造一个 userTask element:map=businessObject.get(name) 源,$attrs=原始扩展属性袋。 */
|
||||
@@ -138,13 +171,51 @@ describe('Eip4Panel — 办理人(candidateUsers)', () => {
|
||||
expect(parsed.items[0].content).toBe('changed');
|
||||
});
|
||||
|
||||
it('清空最后一行:写回 undefined(清除属性)', async () => {
|
||||
it('清空最后一行(meta 为空):无 confirm,直接写回 undefined', async () => {
|
||||
const { modeler, updateProperties, select } = makeModeler();
|
||||
render(<Eip4Panel modeler={modeler} />);
|
||||
await select(userTask({ 'activiti:candidateUsers': candidateNoMeta() }));
|
||||
fireEvent.click(screen.getByTestId('eip4-candidate-remove-0'));
|
||||
expect(confirmSpy).not.toHaveBeenCalled();
|
||||
expect(lastPayload(updateProperties)['activiti:candidateUsers']).toBeUndefined();
|
||||
expect('activiti:candidateUsers' in lastPayload(updateProperties)).toBe(true);
|
||||
});
|
||||
|
||||
it('I-3 清空含非空业务 meta:confirm=确认 → 写回 undefined', async () => {
|
||||
const { modeler, updateProperties, select } = makeModeler();
|
||||
confirmSpy.mockReturnValue(true);
|
||||
render(<Eip4Panel modeler={modeler} />);
|
||||
await select(userTask({ 'activiti:candidateUsers': REAL_CANDIDATE }));
|
||||
fireEvent.click(screen.getByTestId('eip4-candidate-remove-0'));
|
||||
expect(confirmSpy).toHaveBeenCalledTimes(1);
|
||||
expect(String(confirmSpy.mock.calls[0][0])).toContain('PM_CONTRACTUALREGISTER_UPDATEPROJECTSTATUS');
|
||||
expect(lastPayload(updateProperties)['activiti:candidateUsers']).toBeUndefined();
|
||||
expect('activiti:candidateUsers' in lastPayload(updateProperties)).toBe(true);
|
||||
});
|
||||
|
||||
it('I-3 清空含非空业务 meta:confirm=取消 → 不写回、行仍在', async () => {
|
||||
const { modeler, updateProperties, select } = makeModeler();
|
||||
confirmSpy.mockReturnValue(false);
|
||||
render(<Eip4Panel modeler={modeler} />);
|
||||
await select(userTask({ 'activiti:candidateUsers': REAL_CANDIDATE }));
|
||||
fireEvent.click(screen.getByTestId('eip4-candidate-remove-0'));
|
||||
expect(confirmSpy).toHaveBeenCalledTimes(1);
|
||||
expect(updateProperties).not.toHaveBeenCalled(); // 引擎未变
|
||||
expect(screen.getByTestId('eip4-candidate-content-0')).toBeInTheDocument(); // 行未删
|
||||
});
|
||||
|
||||
it('I-3 非空业务 meta 顶部只读徽标显示任务后置服务', async () => {
|
||||
const { modeler, select } = makeModeler();
|
||||
render(<Eip4Panel modeler={modeler} />);
|
||||
await select(userTask({ 'activiti:candidateUsers': REAL_CANDIDATE }));
|
||||
const badge = screen.getByTestId('eip4-candidate-meta-badge');
|
||||
expect(badge.textContent).toContain('PM_CONTRACTUALREGISTER_UPDATEPROJECTSTATUS');
|
||||
});
|
||||
|
||||
it('顺手:非标准办理人表达式显示「编辑将覆盖」警示', async () => {
|
||||
const { modeler, select } = makeModeler();
|
||||
render(<Eip4Panel modeler={modeler} />);
|
||||
await select(userTask({ 'activiti:candidateUsers': '${someOtherExpr(execution)}' }));
|
||||
expect(screen.getByTestId('eip4-candidate-nonstandard')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('增行:改 type 下拉写回对应 type', async () => {
|
||||
@@ -243,6 +314,69 @@ describe('Eip4Panel — 会签(multiInstance)', () => {
|
||||
'${nrOfCompletedInstances/nrOfInstances>0.5}',
|
||||
);
|
||||
});
|
||||
|
||||
// ── I-1 会签保真:读回并原样保留 isSequential / elementVariable / 非预设完成条件 ──────
|
||||
// 真实库存在 isSequential=true、elementVariable=assign、完成条件 >0.6 等形态;强写会静默改坏。
|
||||
function cosignLoop() {
|
||||
return moddleEl('bpmn:MultiInstanceLoopCharacteristics', {
|
||||
isSequential: true,
|
||||
'activiti:collection': extractAttr('activiti:collection'),
|
||||
'activiti:elementVariable': 'assign',
|
||||
completionCondition: { body: '${nrOfCompletedInstances/nrOfInstances>0.6}' },
|
||||
});
|
||||
}
|
||||
|
||||
it('I-1 串行会签往返保 isSequential=true(不被强写 false)', async () => {
|
||||
const { modeler, updateProperties, select } = makeModeler();
|
||||
render(<Eip4Panel modeler={modeler} />);
|
||||
await select(userTask({ loopCharacteristics: cosignLoop() }));
|
||||
expect((screen.getByTestId('eip4-cosign-sequential') as HTMLInputElement).checked).toBe(true);
|
||||
// 触发一次写(编辑会签人员 content),断言 isSequential 保留 true
|
||||
fireEvent.change(screen.getByTestId('eip4-cosign-content-0'), { target: { value: 'x' } });
|
||||
const loop = lastPayload(updateProperties).loopCharacteristics as Record<string, unknown>;
|
||||
expect(loop.isSequential).toBe(true);
|
||||
});
|
||||
|
||||
it('I-1 elementVariable=assign 往返保 assign(不被强写 assignee)', async () => {
|
||||
const { modeler, updateProperties, select } = makeModeler();
|
||||
render(<Eip4Panel modeler={modeler} />);
|
||||
await select(userTask({ loopCharacteristics: cosignLoop() }));
|
||||
expect((screen.getByTestId('eip4-cosign-element-variable') as HTMLInputElement).value).toBe('assign');
|
||||
fireEvent.change(screen.getByTestId('eip4-cosign-content-0'), { target: { value: 'x' } });
|
||||
const loop = lastPayload(updateProperties).loopCharacteristics as Record<string, unknown>;
|
||||
expect(loop['activiti:elementVariable']).toBe('assign');
|
||||
});
|
||||
|
||||
it('I-1 非预设完成条件 >0.6 不被归一为全票(自定义态保留原 body)', async () => {
|
||||
const { modeler, updateProperties, select } = makeModeler();
|
||||
render(<Eip4Panel modeler={modeler} />);
|
||||
await select(userTask({ loopCharacteristics: cosignLoop() }));
|
||||
// 下拉显「自定义(保留)」+ 原 body 展示
|
||||
expect(screen.getByText(/自定义(保留)/)).toBeInTheDocument();
|
||||
expect(screen.getByTestId('eip4-cosign-completion-custom').textContent).toContain(
|
||||
'${nrOfCompletedInstances/nrOfInstances>0.6}',
|
||||
);
|
||||
fireEvent.change(screen.getByTestId('eip4-cosign-content-0'), { target: { value: 'x' } });
|
||||
const loop = lastPayload(updateProperties).loopCharacteristics as Record<string, unknown>;
|
||||
expect((loop.completionCondition as { body: string }).body).toBe(
|
||||
'${nrOfCompletedInstances/nrOfInstances>0.6}',
|
||||
);
|
||||
});
|
||||
|
||||
it('I-1 缺 elementVariable 的会签:写回省略该属性(不凭空写空)', async () => {
|
||||
const { modeler, updateProperties, select } = makeModeler();
|
||||
const loop = moddleEl('bpmn:MultiInstanceLoopCharacteristics', {
|
||||
isSequential: false,
|
||||
'activiti:collection': extractAttr('activiti:collection'),
|
||||
// 无 activiti:elementVariable、无 completionCondition
|
||||
});
|
||||
render(<Eip4Panel modeler={modeler} />);
|
||||
await select(userTask({ loopCharacteristics: loop }));
|
||||
fireEvent.change(screen.getByTestId('eip4-cosign-content-0'), { target: { value: 'x' } });
|
||||
const written = lastPayload(updateProperties).loopCharacteristics as Record<string, unknown>;
|
||||
expect('activiti:elementVariable' in written).toBe(false); // 缺省态不写
|
||||
expect('completionCondition' in written).toBe(false); // 原本无完成条件不发出
|
||||
});
|
||||
});
|
||||
|
||||
describe('Eip4Panel — formKey', () => {
|
||||
@@ -300,6 +434,28 @@ describe('Eip4Panel — 扩展属性(长尾 $attrs)', () => {
|
||||
expect(screen.getByTestId('eip4-extattr-key-0')).toHaveValue('activiti:custom');
|
||||
expect(screen.queryByTestId('eip4-extattr-key-1')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('顺手:无 activiti:/flowable: 前缀的新键被拒(不写回)', async () => {
|
||||
const { modeler, updateProperties, select } = makeModeler();
|
||||
render(<Eip4Panel modeler={modeler} />);
|
||||
await select(userTask());
|
||||
fireEvent.change(screen.getByTestId('eip4-extattr-new-key'), { target: { value: 'foo' } });
|
||||
fireEvent.change(screen.getByTestId('eip4-extattr-new-value'), { target: { value: 'v' } });
|
||||
fireEvent.click(screen.getByTestId('eip4-extattr-add'));
|
||||
expect(updateProperties).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('顺手:拉黑有专用控件的键(activiti:formKey)不允许从扩展属性写', async () => {
|
||||
const { modeler, updateProperties, select } = makeModeler();
|
||||
render(<Eip4Panel modeler={modeler} />);
|
||||
await select(userTask());
|
||||
fireEvent.change(screen.getByTestId('eip4-extattr-new-key'), {
|
||||
target: { value: 'activiti:formKey' },
|
||||
});
|
||||
fireEvent.change(screen.getByTestId('eip4-extattr-new-value'), { target: { value: 'x' } });
|
||||
fireEvent.click(screen.getByTestId('eip4-extattr-add'));
|
||||
expect(updateProperties).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Eip4Panel — 任务监听器(taskListener)', () => {
|
||||
@@ -366,3 +522,56 @@ describe('Eip4Panel — 任务监听器(taskListener)', () => {
|
||||
expect('class' in listener).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Eip4Panel — 切换节点 / undo-redo 重灌(评审 I-2 + 顺手)', () => {
|
||||
it('I-2 A(meta X)→B(meta Y)→编辑 B→写回 meta===Y 且 ≠X', async () => {
|
||||
const { modeler, updateProperties, select } = makeModeler();
|
||||
const item = (c: string): UserPropertyItem => ({
|
||||
type: 'user',
|
||||
content: c,
|
||||
isCandidate: true,
|
||||
isSendMail: false,
|
||||
isSendPhone: false,
|
||||
isSendMessage: false,
|
||||
});
|
||||
const exprA = buildCandidateExpression([item('a')], 'candidate', { taskSuccessService: 'SVC_X' });
|
||||
const exprB = buildCandidateExpression([item('b')], 'candidate', { taskSuccessService: 'SVC_Y' });
|
||||
render(<Eip4Panel modeler={modeler} />);
|
||||
await select(userTask({ __id: 'A', 'activiti:candidateUsers': exprA }));
|
||||
await select(userTask({ __id: 'B', 'activiti:candidateUsers': exprB }));
|
||||
// 编辑 B 的 content
|
||||
fireEvent.change(screen.getByTestId('eip4-candidate-content-0'), { target: { value: 'b2' } });
|
||||
const written = lastPayload(updateProperties)['activiti:candidateUsers'] as string;
|
||||
const meta = parseCandidateExpression(written)!.meta;
|
||||
expect(meta.taskSuccessService).toBe('SVC_Y'); // 用 B 的 meta
|
||||
expect(meta.taskSuccessService).not.toBe('SVC_X'); // 不串到 A 的 meta
|
||||
});
|
||||
|
||||
it('顺手:commandStack.changed(外部 undo)对当前选中重灌本地态', async () => {
|
||||
const { modeler, select, fireCommandStack } = makeModeler();
|
||||
const item = (c: string): UserPropertyItem => ({
|
||||
type: 'user',
|
||||
content: c,
|
||||
isCandidate: true,
|
||||
isSendMail: false,
|
||||
isSendPhone: false,
|
||||
isSendMessage: false,
|
||||
});
|
||||
// 可变 map:模拟外部 undo 改写 businessObject。
|
||||
const map: Record<string, unknown> = {
|
||||
'activiti:candidateUsers': buildCandidateExpression([item('X')], 'candidate', {}),
|
||||
};
|
||||
const el = {
|
||||
id: 't1',
|
||||
type: 'bpmn:UserTask',
|
||||
businessObject: { $type: 'bpmn:UserTask', get: (n: string) => map[n] },
|
||||
};
|
||||
render(<Eip4Panel modeler={modeler} />);
|
||||
await select(el);
|
||||
expect((screen.getByTestId('eip4-candidate-content-0') as HTMLInputElement).value).toBe('X');
|
||||
// 外部 undo 改了 businessObject → commandStack.changed → 重灌
|
||||
map['activiti:candidateUsers'] = buildCandidateExpression([item('Y')], 'candidate', {});
|
||||
await fireCommandStack();
|
||||
expect((screen.getByTestId('eip4-candidate-content-0') as HTMLInputElement).value).toBe('Y');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user