本仓 2026-08-12 从 ssw main (192.168.1.18:13300/ssw/ssw-mvp) 的 dacli/ subpath 抽取,作为独立仓托管到 gitea:3000/ssw/dacli.git。 - 工作树为 ssw main dacli subpath 最新版 (110 commit, 08-12) - 历史未带 ssw main 整体历史(避免大仓污染) - 此为新仓基线 commit,未来以本仓历史为主
74 lines
3.3 KiB
TypeScript
74 lines
3.3 KiB
TypeScript
/**
|
|
* tests/unit/workflow/parse_flowxml.test.ts
|
|
*
|
|
* 回归: v0.22+ SSW /build-workflow 输出无前缀 BPMN (默认命名空间),
|
|
* 旧 parseFlowXml 正则写死 <bpmn2: → 0 节点 → flowNodes 只剩 global (canvas 缺口)。
|
|
* 修复: 命名空间无关正则 (bpmn2:/bpmn:/无前缀 都解析)。
|
|
*/
|
|
import { describe, it, expect } from 'vitest'
|
|
import { parseFlowXml, buildFlowNodes } from '../../../src/commands/workflow/_webapi_helpers.ts'
|
|
|
|
// SSW /build-workflow 真实输出格式: 默认命名空间, 无前缀, 自闭合
|
|
const SSW_UNPREFIXED = `<?xml version="1.0" encoding="UTF-8"?>
|
|
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
|
|
xmlns:flowable="http://flowable.org/bpmn">
|
|
<process id="p06repairflow01" name="设备维修审批" isExecutable="true">
|
|
<startEvent id="startEvent_1" name="开始"/>
|
|
<userTask id="userTask_apply" name="报修人提交申请" flowable:assignee="\${initiator}"/>
|
|
<userTask id="userTask_deptApprove" name="部门主管审批" flowable:assignee="\${deptManager}"/>
|
|
<exclusiveGateway id="exclusiveGateway_fee" name="费用是否大于5000元"/>
|
|
<userTask id="userTask_dispatch" name="维修派工" flowable:assignee="\${dispatcher}"/>
|
|
<endEvent id="endEvent_1" name="结束"/>
|
|
<sequenceFlow id="flow_1" sourceRef="startEvent_1" targetRef="userTask_apply"/>
|
|
</process>
|
|
</definitions>`
|
|
|
|
// 旧 JNPF 后端格式: bpmn2: 前缀 + 跨行属性
|
|
const JNPF_BPMN2 = `<?xml version="1.0"?>
|
|
<bpmn2:definitions xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL">
|
|
<bpmn2:process id="leave" name="请假">
|
|
<bpmn2:startEvent id="Event_1"
|
|
name="流程发起"/>
|
|
<bpmn2:userTask id="Activity_1" name="经理审批"/>
|
|
<bpmn2:endEvent id="Event_2" name="结束"/>
|
|
</bpmn2:process>
|
|
</bpmn2:definitions>`
|
|
|
|
describe('parseFlowXml: 命名空间无关', () => {
|
|
it('无前缀 (SSW /build-workflow) → 解析全部节点', () => {
|
|
const nodes = parseFlowXml(SSW_UNPREFIXED)
|
|
const ids = Object.keys(nodes)
|
|
expect(ids).toContain('startEvent_1')
|
|
expect(ids).toContain('userTask_apply')
|
|
expect(ids).toContain('exclusiveGateway_fee')
|
|
expect(ids).toContain('endEvent_1')
|
|
expect(ids.length).toBe(6)
|
|
})
|
|
|
|
it('正确映射 type + nodeName', () => {
|
|
const nodes = parseFlowXml(SSW_UNPREFIXED)
|
|
expect(nodes['startEvent_1'].type).toBe('start')
|
|
expect(nodes['userTask_apply'].type).toBe('approver')
|
|
expect(nodes['userTask_apply'].nodeName).toBe('报修人提交申请')
|
|
expect(nodes['exclusiveGateway_fee'].type).toBe('exclusive')
|
|
expect(nodes['endEvent_1'].type).toBe('end')
|
|
})
|
|
|
|
it('bpmn2: 前缀 (旧 JNPF 后端) 仍解析 (向后兼容)', () => {
|
|
const nodes = parseFlowXml(JNPF_BPMN2)
|
|
expect(Object.keys(nodes).length).toBe(3)
|
|
expect(nodes['Event_1'].type).toBe('start')
|
|
expect(nodes['Activity_1'].type).toBe('approver')
|
|
expect(nodes['Activity_1'].nodeName).toBe('经理审批')
|
|
expect(nodes['Event_2'].type).toBe('end')
|
|
})
|
|
|
|
it('buildFlowNodes: 无前缀 XML → global + 全部业务节点 (回归修复)', () => {
|
|
const fn = buildFlowNodes(SSW_UNPREFIXED, { formId: 'form123' })
|
|
expect(fn.global).toBeDefined()
|
|
expect(Object.keys(fn).length).toBe(7) // global + 6
|
|
// start 节点绑 formId
|
|
expect(fn['startEvent_1'].formId).toBe('form123')
|
|
})
|
|
})
|