g6-to-logicflow.spec.ts
2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { describe, expect, it } from 'vitest'
import {
normalizeGraphData,
toLogicFlowGraphData,
} from '../../packages/flow-editor/src/core/adapter/g6-to-logicflow'
import baseSingleNode from '../fixtures/graphs/base-single-node.json'
import branchingFlow from '../fixtures/graphs/branching-flow.json'
import linearApprovalFlow from '../fixtures/graphs/linear-approval-flow.json'
describe('g6-to-logicflow 适配器', () => {
it('应能把旧项目单节点数据归一化为兼容结构', () => {
const normalizedGraph = normalizeGraphData(baseSingleNode)
expect(normalizedGraph.nodes).toHaveLength(1)
expect(normalizedGraph.nodes[0]).toMatchObject({
id: 'start-node',
label: '开始节点',
type: 'start',
x: 160,
y: 180,
})
expect(normalizedGraph.edges).toHaveLength(0)
})
it('应兼容已经整理过的新结构图数据', () => {
const normalizedGraph = normalizeGraphData(linearApprovalFlow)
expect(normalizedGraph.nodes).toHaveLength(3)
expect(normalizedGraph.edges).toHaveLength(2)
expect(normalizedGraph.nodes[1]).toMatchObject({
id: 'approve',
label: '审批节点',
type: 'approval',
})
expect(normalizedGraph.edges[0]).toMatchObject({
sourceNodeId: 'start',
targetNodeId: 'approve',
label: '提交审批',
})
})
it('应能把旧项目分支流程映射为 LogicFlow 2.x 可消费结构', () => {
const logicFlowGraph = toLogicFlowGraphData(branchingFlow)
expect(logicFlowGraph.nodes).toHaveLength(5)
expect(logicFlowGraph.edges).toHaveLength(5)
expect(logicFlowGraph.nodes[0]).toMatchObject({
id: 'start-node',
type: 'circle',
text: '开始节点',
})
expect(logicFlowGraph.nodes[2]).toMatchObject({
id: 'approve-node',
type: 'rect',
text: '通过分支',
})
expect(logicFlowGraph.edges[0]).toMatchObject({
sourceNodeId: 'start-node',
targetNodeId: 'review-node',
type: 'polyline',
text: '提交审批',
})
expect(logicFlowGraph.edges[0].id).toContain('edge-start-node-review-node')
})
})