fix(modeler): 属性面板显式 attachTo 修挂载时序(live 实证)+canvas 分支错误提示
live 复验:画布/palette/选中/context pad 正常,但标准属性面板从不挂载
(document 中 .bio-properties-panel 为 0,容器 children=0)。
根因(本次修时 attachTo 测试逼出):属性面板宿主 <div data-testid=process-modeler-props>
**从未挂 ref={panelRef}** → 构造参数 propertiesPanel.parent 恒为 null,面板无处渲染。
- 补 ref={panelRef} 到 props 容器 div(真根因)。
- 构造后显式 (modeler.get('propertiesPanel')).attachTo(panelRef.current)——
bpmn-js-properties-panel 规范补救,放 importXML 前、alive 检查内、panelRef 存在时。
- 顺带修 T1.5 评审 M-2:canvasRef 为 null 分支改为 setError(原停 loading 无提示)。
测试:ProcessModelerPage.test.tsx +1(Modeler stub get('propertiesPanel')→{attachTo},
断言 attachTo 恰调一次且实参是 props 容器 DOM)。stub get 改按 service 分派
(propertiesPanel/canvas)。全量 vitest 22 文件 118 例绿;tsc -b 干净;npm run build 成功。
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,10 +4,15 @@ import { MemoryRouter } from 'react-router-dom';
|
|||||||
import { SYNTHETIC_BPMN } from '../modeler/moddle/fixtures/synthetic-full-surface.bpmn';
|
import { SYNTHETIC_BPMN } from '../modeler/moddle/fixtures/synthetic-full-surface.bpmn';
|
||||||
|
|
||||||
// bpmn-js Modeler:jsdom 跑不动真渲染,stub 成类(可断言 importXML/destroy 调用)。
|
// bpmn-js Modeler:jsdom 跑不动真渲染,stub 成类(可断言 importXML/destroy 调用)。
|
||||||
const { importXMLMock, destroyMock, getMock, onMock, ModelerCtor } = vi.hoisted(() => {
|
const { importXMLMock, destroyMock, getMock, onMock, attachToMock, ModelerCtor } = vi.hoisted(() => {
|
||||||
const importXMLMock = vi.fn();
|
const importXMLMock = vi.fn();
|
||||||
const destroyMock = vi.fn();
|
const destroyMock = vi.fn();
|
||||||
const getMock = vi.fn(() => ({}));
|
const attachToMock = vi.fn();
|
||||||
|
const getMock = vi.fn((service: string) => {
|
||||||
|
if (service === 'propertiesPanel') return { attachTo: attachToMock };
|
||||||
|
if (service === 'canvas') return { zoom: vi.fn() };
|
||||||
|
return {};
|
||||||
|
});
|
||||||
const onMock = vi.fn();
|
const onMock = vi.fn();
|
||||||
const ModelerCtor = vi.fn().mockImplementation(() => ({
|
const ModelerCtor = vi.fn().mockImplementation(() => ({
|
||||||
importXML: importXMLMock,
|
importXML: importXMLMock,
|
||||||
@@ -15,7 +20,7 @@ const { importXMLMock, destroyMock, getMock, onMock, ModelerCtor } = vi.hoisted(
|
|||||||
get: getMock,
|
get: getMock,
|
||||||
on: onMock,
|
on: onMock,
|
||||||
}));
|
}));
|
||||||
return { importXMLMock, destroyMock, getMock, onMock, ModelerCtor };
|
return { importXMLMock, destroyMock, getMock, onMock, attachToMock, ModelerCtor };
|
||||||
});
|
});
|
||||||
vi.mock('bpmn-js/lib/Modeler', () => ({ default: ModelerCtor }));
|
vi.mock('bpmn-js/lib/Modeler', () => ({ default: ModelerCtor }));
|
||||||
// 标准属性面板模块只作为 additionalModules 配置项传入被 mock 的 Modeler,永不真正执行。
|
// 标准属性面板模块只作为 additionalModules 配置项传入被 mock 的 Modeler,永不真正执行。
|
||||||
@@ -53,7 +58,8 @@ function renderPage(initialPath = '/process-modeler') {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
importXMLMock.mockReset().mockResolvedValue(undefined);
|
importXMLMock.mockReset().mockResolvedValue(undefined);
|
||||||
destroyMock.mockReset();
|
destroyMock.mockReset();
|
||||||
getMock.mockReset().mockReturnValue({});
|
attachToMock.mockReset();
|
||||||
|
getMock.mockClear();
|
||||||
onMock.mockReset();
|
onMock.mockReset();
|
||||||
ModelerCtor.mockClear();
|
ModelerCtor.mockClear();
|
||||||
mSource.mockReset().mockResolvedValue({ found: true, bpmnXml: SYNTHETIC_BPMN, idMap: { '总包合同交底': 'Proc_zbht' } });
|
mSource.mockReset().mockResolvedValue({ found: true, bpmnXml: SYNTHETIC_BPMN, idMap: { '总包合同交底': 'Proc_zbht' } });
|
||||||
@@ -83,6 +89,12 @@ describe('ProcessModelerPage', () => {
|
|||||||
expect(ModelerCtor).toHaveBeenCalledTimes(1);
|
expect(ModelerCtor).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('构造后显式 attachTo 属性面板容器一次(修 live 面板从不挂载)', async () => {
|
||||||
|
renderPage('/process-modeler?procDefId=PD-1');
|
||||||
|
await waitFor(() => expect(attachToMock).toHaveBeenCalledTimes(1));
|
||||||
|
expect(attachToMock).toHaveBeenCalledWith(screen.getByTestId('process-modeler-props'));
|
||||||
|
});
|
||||||
|
|
||||||
it('接口 found:false 时显示未找到文案且不 importXML', async () => {
|
it('接口 found:false 时显示未找到文案且不 importXML', async () => {
|
||||||
mSource.mockResolvedValue({ found: false });
|
mSource.mockResolvedValue({ found: false });
|
||||||
renderPage('/process-modeler?procDefId=PD-x');
|
renderPage('/process-modeler?procDefId=PD-x');
|
||||||
|
|||||||
@@ -85,7 +85,12 @@ export function ProcessModelerPage() {
|
|||||||
setLoadState('error');
|
setLoadState('error');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!canvasRef.current) return;
|
if (!canvasRef.current) {
|
||||||
|
// 画布容器缺失(异常时序):明确报错,别停在 loading 无提示(T1.5 评审 M-2)。
|
||||||
|
setLoadError('画布未就绪,请重试');
|
||||||
|
setLoadState('error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
modeler = new ModelerCtor({
|
modeler = new ModelerCtor({
|
||||||
container: canvasRef.current,
|
container: canvasRef.current,
|
||||||
propertiesPanel: { parent: panelRef.current },
|
propertiesPanel: { parent: panelRef.current },
|
||||||
@@ -97,6 +102,16 @@ export function ProcessModelerPage() {
|
|||||||
// 扩展属性冲突静默丢弃 userTask;单载 activiti 时 flowable 文档经 moddle lax 往返零丢失。
|
// 扩展属性冲突静默丢弃 userTask;单载 activiti 时 flowable 文档经 moddle lax 往返零丢失。
|
||||||
moddleExtensions: { activiti: activitiModdle },
|
moddleExtensions: { activiti: activitiModdle },
|
||||||
});
|
});
|
||||||
|
// ⚠️ 显式 attachTo:live 实证——只靠构造参数 propertiesPanel.parent,面板从不挂载
|
||||||
|
// (.bio-properties-panel 在 document 中为 0;构造时 ref 时序/传对象非 element 皆可致此)。
|
||||||
|
// attachTo 容器 DOM 是 bpmn-js-properties-panel 的规范补救。放在 importXML 前,alive 内。
|
||||||
|
if (panelRef.current) {
|
||||||
|
try {
|
||||||
|
(modeler.get('propertiesPanel') as { attachTo(el: HTMLElement): void }).attachTo(panelRef.current);
|
||||||
|
} catch {
|
||||||
|
/* 面板模块缺失 / stub 时忽略 */
|
||||||
|
}
|
||||||
|
}
|
||||||
idMapRef.current = src.idMap ?? {};
|
idMapRef.current = src.idMap ?? {};
|
||||||
await modeler.importXML(src.bpmnXml);
|
await modeler.importXML(src.bpmnXml);
|
||||||
if (!alive) return;
|
if (!alive) return;
|
||||||
@@ -255,8 +270,8 @@ export function ProcessModelerPage() {
|
|||||||
>
|
>
|
||||||
EIP4 定制控件(办理人 / 会签 / formKey)将在此叠加,下阶段接入。
|
EIP4 定制控件(办理人 / 会签 / formKey)将在此叠加,下阶段接入。
|
||||||
</div>
|
</div>
|
||||||
{/* 标准属性面板宿主(bpmn-js-properties-panel 渲染进此容器) */}
|
{/* 标准属性面板宿主(bpmn-js-properties-panel attachTo 进此容器) */}
|
||||||
<div data-testid="process-modeler-props" style={{ flex: 1, overflow: 'auto', minHeight: 0 }} />
|
<div ref={panelRef} data-testid="process-modeler-props" style={{ flex: 1, overflow: 'auto', minHeight: 0 }} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user