-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathutils.test.ts
More file actions
129 lines (114 loc) · 5.17 KB
/
utils.test.ts
File metadata and controls
129 lines (114 loc) · 5.17 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
Copyright 2020 Bonitasoft S.A.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import { FlowKind, ShapeBpmnElementKind, ShapeUtil } from '@lib/model/bpmn/internal';
describe('ShapeUtil', () => {
it('top level bpmn event kinds', () => {
const events = ShapeUtil.eventKinds();
expect(events).toContain(ShapeBpmnElementKind.EVENT_END);
expect(events).toContain(ShapeBpmnElementKind.EVENT_START);
});
it('task kinds', () => {
const tasks = ShapeUtil.taskKinds();
expect(tasks).toContain(ShapeBpmnElementKind.TASK);
expect(tasks).toContain(ShapeBpmnElementKind.TASK_USER);
});
it('flow node kinds', () => {
const flowNodeKinds = ShapeUtil.flowNodeKinds();
expect(flowNodeKinds).toContain(ShapeBpmnElementKind.TASK);
expect(flowNodeKinds).toContain(ShapeBpmnElementKind.EVENT_INTERMEDIATE_CATCH);
expect(flowNodeKinds).toContain(ShapeBpmnElementKind.GROUP); // artifact should not be included
expect(flowNodeKinds).not.toContain(ShapeBpmnElementKind.POOL);
});
it('artifact kinds', () => {
const artifacts = ShapeUtil.artifactKinds();
expect(artifacts).toContain(ShapeBpmnElementKind.GROUP);
expect(artifacts).toContain(ShapeBpmnElementKind.TEXT_ANNOTATION);
});
describe('Is pool or lane?', () => {
it.each([
[ShapeBpmnElementKind.CALL_ACTIVITY],
[ShapeBpmnElementKind.SUB_PROCESS],
[ShapeBpmnElementKind.TASK],
[ShapeBpmnElementKind.TASK_SERVICE],
[ShapeBpmnElementKind.EVENT_START],
[ShapeBpmnElementKind.EVENT_BOUNDARY],
[ShapeBpmnElementKind.GATEWAY_PARALLEL],
[ShapeBpmnElementKind.GATEWAY_EVENT_BASED],
[ShapeBpmnElementKind.GROUP],
[ShapeBpmnElementKind.TEXT_ANNOTATION],
])('%s', (bpmnKind: ShapeBpmnElementKind) => {
expect(ShapeUtil.isPoolOrLane(bpmnKind)).toBeFalsy();
});
});
describe('isArtifact', () => {
test.each`
kind | expected
${ShapeBpmnElementKind.EVENT_END} | ${false}
${ShapeBpmnElementKind.GATEWAY_PARALLEL} | ${false}
${ShapeBpmnElementKind.TASK} | ${false}
${ShapeBpmnElementKind.SUB_PROCESS} | ${false}
${ShapeBpmnElementKind.CALL_ACTIVITY} | ${false}
${ShapeBpmnElementKind.POOL} | ${false}
${ShapeBpmnElementKind.LANE} | ${false}
${ShapeBpmnElementKind.GROUP} | ${true}
${ShapeBpmnElementKind.TEXT_ANNOTATION} | ${true}
${FlowKind.MESSAGE_FLOW} | ${false}
${'unknown'} | ${false}
${'receiveTask'} | ${false}
`('$kind isArtifact? $expected', ({ kind, expected }: Record<string, unknown>) => {
expect(ShapeUtil.isArtifact(kind as string)).toBe(expected);
});
});
describe('isFlowNode', () => {
test.each`
kind | expected
${ShapeBpmnElementKind.EVENT_END} | ${true}
${ShapeBpmnElementKind.GATEWAY_PARALLEL} | ${true}
${ShapeBpmnElementKind.TASK} | ${true}
${ShapeBpmnElementKind.SUB_PROCESS} | ${true}
${ShapeBpmnElementKind.CALL_ACTIVITY} | ${true}
${ShapeBpmnElementKind.POOL} | ${false}
${ShapeBpmnElementKind.LANE} | ${false}
${ShapeBpmnElementKind.GROUP} | ${true}
${ShapeBpmnElementKind.TEXT_ANNOTATION} | ${true}
${FlowKind.MESSAGE_FLOW} | ${false}
${'unknown'} | ${false}
${'receiveTask'} | ${true}
`('$kind isFlowNode? $expected', ({ kind, expected }: Record<string, unknown>) => {
expect(ShapeUtil.isFlowNode(kind as string)).toBe(expected);
});
});
describe('Reference kinds cannot be modified', () => {
it.each`
kind | kindsFunction
${'activities'} | ${() => ShapeUtil.activityKinds()}
${'artifacts'} | ${() => ShapeUtil.artifactKinds()}
${'events'} | ${() => ShapeUtil.eventKinds()}
${'flow nodes'} | ${() => ShapeUtil.flowNodeKinds()}
${'gateways'} | ${() => ShapeUtil.gatewayKinds()}
${'tasks'} | ${() => ShapeUtil.taskKinds()}
`('$kind', ({ kindsFunction }: { kindsFunction: () => string[] }) => {
const kinds = kindsFunction();
const initialKinds = [...kinds];
expect(kinds).toEqual(initialKinds);
expect(kinds).not.toBe(initialKinds);
// ensure the reference kinds is modified
const initialLength = kinds.length;
expect(kinds.push(null)).toEqual(initialLength + 1);
expect(kinds).not.toEqual(initialKinds);
const newKinds = kindsFunction();
expect(newKinds).not.toBe(kinds);
expect(newKinds).toEqual(initialKinds);
});
});
});