auto(14b5ea1b9bd9): session end @ 2026-07-30T19:19:11 (+1f)

This commit is contained in:
ssw committed 2026-07-30 19:19:14 +08:00
1 parent 44c1f31e86
commit 9af734e4ab
1 file changed
+112
@@ -0,0 +1,112 @@
/**
* workflow process id 归一化 (BS-新 7, tdd8 debug §2.5, 2026-07-30)
*
* 根因: web/packages/jnpf/plugins/jnpf-bpmn/lib/utils/nodeUtil.js 硬编码
* `xmlDoc.querySelector('#Process_1')` (autoCreateGateWay:25, autoDelGateWay:171)
* 若落库 flowXml 的 process id ≠ 'Process_1' (如 tdd8overtime 'overtimeApply'),
* preview 时 process=null → .append()/.getElementsByTagName() 抛
* `TypeError: null is not an object (evaluating 'u.getElementsByTagName')`
*
* 修法: dacli _autoLayout.normalizeProcessId 落库前归一化 (本测试)
*/
import { describe, expect, it } from 'vitest'
import { normalizeProcessId } from '../../src/commands/workflow/_autoLayout.ts'
const sampleWithOvertimeApply = `<?xml version="1.0" encoding="UTF-8"?>
<bpmn2:definitions xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:flowable="http://flowable.org/bpmn" targetNamespace="http://bpmn.io/schema/bpmn">
<bpmn2:process id="overtimeApply" name="员工加班申请流程" isExecutable="true">
<bpmn2:startEvent id="startEvent_1" name="开始" />
<bpmn2:userTask id="userTask_apply" name="员工提交加班申请" flowable:assignee="\${initiator}" />
<bpmn2:userTask id="userTask_approve" name="admin审批" flowable:assignee="\${approver}" />
<bpmn2:endEvent id="endEvent_1" name="结束" />
<bpmn2:sequenceFlow id="flow_1" sourceRef="startEvent_1" targetRef="userTask_apply" />
<bpmn2:sequenceFlow id="flow_2" sourceRef="userTask_apply" targetRef="userTask_approve" />
<bpmn2:sequenceFlow id="flow_3" sourceRef="userTask_approve" targetRef="endEvent_1" />
</bpmn2:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="overtimeApply">
<bpmndi:BPMNShape id="startEvent_1_di" bpmnElement="startEvent_1">
<dc:Bounds x="70" y="0" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="userTask_apply_di" bpmnElement="userTask_apply">
<dc:Bounds x="270" y="0" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="flow_1_di" bpmnElement="flow_1">
<di:waypoint x="106" y="18" />
<di:waypoint x="270" y="40" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn2:definitions>`
const sampleWithProcess1 = `<?xml version="1.0" encoding="UTF-8"?>
<bpmn2:definitions xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL">
<bpmn2:process id="Process_1" name="标准流程" isExecutable="true">
<bpmn2:startEvent id="startEvent_1" />
</bpmn2:process>
</bpmn2:definitions>`
const sampleNoProcess = `<?xml version="1.0" encoding="UTF-8"?>
<root><other /></root>`
describe('workflow normalize process id (BS-新 7, 2026-07-30)', () => {
it('process id=overtimeApply → 归一化为 Process_1 (tdd8 实战 case)', () => {
const out = normalizeProcessId(sampleWithOvertimeApply)
// process id 改了
expect(out).toMatch(/<bpmn2:process\b[^>]*\bid="Process_1"/)
expect(out).not.toMatch(/<bpmn2:process\b[^>]*\bid="overtimeApply"/)
// BPMNPlane bpmnElement 也同步改了 (DI 树不能断)
expect(out).toMatch(/<bpmndi:BPMNPlane\b[^>]*\bbpmnElement="Process_1"/)
expect(out).not.toMatch(/<bpmndi:BPMNPlane\b[^>]*\bbpmnElement="overtimeApply"/)
})
it('process id 已是 Process_1 → noop (幂等)', () => {
const out = normalizeProcessId(sampleWithProcess1)
expect(out).toBe(sampleWithProcess1)
})
it('无 process 元素 → 原样返回 (防御)', () => {
const out = normalizeProcessId(sampleNoProcess)
expect(out).toBe(sampleNoProcess)
})
it('其它非 Process_1 id (语义化如 reimbursementApply) → 归一化', () => {
const xml = sampleWithOvertimeApply.replace('overtimeApply', 'reimbursementApply')
const out = normalizeProcessId(xml)
expect(out).toMatch(/<bpmn2:process\b[^>]*\bid="Process_1"/)
expect(out).not.toMatch(/reimbursementApply/)
})
it('自定义 targetId 参数: Process_42 (跨项目兼容兜底)', () => {
const out = normalizeProcessId(sampleWithOvertimeApply, 'Process_42')
expect(out).toMatch(/<bpmn2:process\b[^>]*\bid="Process_42"/)
expect(out).toMatch(/<bpmndi:BPMNPlane\b[^>]*\bbpmnElement="Process_42"/)
})
it('正则防误匹配: 含 process 子串的其它元素 (processCategory) 不动', () => {
// 包含 bpmn2:processCategory 元素的 XML
const xml = `<?xml version="1.0"?>
<bpmn2:definitions xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL">
<bpmn2:process id="myFlow" isExecutable="true" processCategory="cat-1">
<bpmn2:startEvent id="startEvent_1" />
</bpmn2:process>
<bpmn2:processCategory id="cat-1" />
</bpmn2:definitions>`
const out = normalizeProcessId(xml)
// myFlow → Process_1
expect(out).toMatch(/<bpmn2:process\b[^>]*\bid="Process_1"/)
// processCategory id=cat-1 不动
expect(out).toMatch(/<bpmn2:processCategory\b[^>]*\bid="cat-1"/)
})
it('兼容 bpmn: 前缀 (moddle.toXML canonical 输出)', () => {
const xml = `<?xml version="1.0"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL">
<bpmn:process id="overtimeApply" isExecutable="true">
<bpmn:startEvent id="startEvent_1" />
</bpmn:process>
</bpmn:definitions>`
const out = normalizeProcessId(xml)
expect(out).toMatch(/<bpmn:process\b[^>]*\bid="Process_1"/)
})
})