Skip to content

Commit a5ad540

Browse files
authored
feat: add flowNode and artifact methods in ShapeUtil (#3397)
Add - artifactKinds - isArtifact - isFlowNode
1 parent 4ade06b commit a5ad540

2 files changed

Lines changed: 79 additions & 1 deletion

File tree

src/model/bpmn/internal/shape/utils.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,30 @@ export class ShapeUtil {
107107
return Object.values(ShapeBpmnElementKind).filter(kind => !ShapeUtil.isPoolOrLane(kind));
108108
}
109109

110+
/**
111+
* @since 0.48.0
112+
*/
113+
static isFlowNode(kind: ShapeBpmnElementKind | string): boolean {
114+
return ShapeUtil.flowNodeKinds().includes(kind as ShapeBpmnElementKind);
115+
}
116+
110117
static isPoolOrLane(kind: ShapeBpmnElementKind | string): boolean {
111118
return kind == ShapeBpmnElementKind.POOL || kind == ShapeBpmnElementKind.LANE;
112119
}
120+
121+
/**
122+
* @since 0.48.0
123+
*/
124+
static artifactKinds(): ShapeBpmnElementKind[] {
125+
return [...ARTIFACT_KINDS];
126+
}
127+
128+
/**
129+
* @since 0.48.0
130+
*/
131+
static isArtifact(kind: ShapeBpmnElementKind | string): boolean {
132+
return ARTIFACT_KINDS.includes(kind as ShapeBpmnElementKind);
133+
}
113134
}
114135

115136
function filterKind(suffix: string, options?: FilterParameter): ShapeBpmnElementKind[] {
@@ -135,6 +156,8 @@ const FLOW_NODE_WITH_DEFAULT_SEQUENCE_FLOW_KINDS = new Set([
135156
ShapeBpmnElementKind.GATEWAY_COMPLEX,
136157
]);
137158

159+
const ARTIFACT_KINDS = [ShapeBpmnElementKind.GROUP, ShapeBpmnElementKind.TEXT_ANNOTATION];
160+
138161
/**
139162
* Elements that are effectively used in BPMN diagram as base for eventDefinition i.e all {@link ShapeBpmnEventDefinitionKind} elements except {@link ShapeBpmnEventDefinitionKind.NONE}
140163
* @internal

test/unit/model/bpmn/internal/shape/utils.test.ts

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import { ShapeBpmnElementKind, ShapeUtil } from '@lib/model/bpmn/internal';
17+
import { FlowKind, ShapeBpmnElementKind, ShapeUtil } from '@lib/model/bpmn/internal';
1818

1919
describe('ShapeUtil', () => {
2020
it('top level bpmn event kinds', () => {
@@ -29,6 +29,20 @@ describe('ShapeUtil', () => {
2929
expect(tasks).toContain(ShapeBpmnElementKind.TASK_USER);
3030
});
3131

32+
it('flow node kinds', () => {
33+
const flowNodeKinds = ShapeUtil.flowNodeKinds();
34+
expect(flowNodeKinds).toContain(ShapeBpmnElementKind.TASK);
35+
expect(flowNodeKinds).toContain(ShapeBpmnElementKind.EVENT_INTERMEDIATE_CATCH);
36+
expect(flowNodeKinds).toContain(ShapeBpmnElementKind.GROUP); // artifact should not be included
37+
expect(flowNodeKinds).not.toContain(ShapeBpmnElementKind.POOL);
38+
});
39+
40+
it('artifact kinds', () => {
41+
const artifacts = ShapeUtil.artifactKinds();
42+
expect(artifacts).toContain(ShapeBpmnElementKind.GROUP);
43+
expect(artifacts).toContain(ShapeBpmnElementKind.TEXT_ANNOTATION);
44+
});
45+
3246
describe('Is pool or lane?', () => {
3347
it.each([
3448
[ShapeBpmnElementKind.CALL_ACTIVITY],
@@ -46,10 +60,51 @@ describe('ShapeUtil', () => {
4660
});
4761
});
4862

63+
describe('isArtifact', () => {
64+
test.each`
65+
kind | expected
66+
${ShapeBpmnElementKind.EVENT_END} | ${false}
67+
${ShapeBpmnElementKind.GATEWAY_PARALLEL} | ${false}
68+
${ShapeBpmnElementKind.TASK} | ${false}
69+
${ShapeBpmnElementKind.SUB_PROCESS} | ${false}
70+
${ShapeBpmnElementKind.CALL_ACTIVITY} | ${false}
71+
${ShapeBpmnElementKind.POOL} | ${false}
72+
${ShapeBpmnElementKind.LANE} | ${false}
73+
${ShapeBpmnElementKind.GROUP} | ${true}
74+
${ShapeBpmnElementKind.TEXT_ANNOTATION} | ${true}
75+
${FlowKind.MESSAGE_FLOW} | ${false}
76+
${'unknown'} | ${false}
77+
${'receiveTask'} | ${false}
78+
`('$kind isArtifact? $expected', ({ kind, expected }: Record<string, unknown>) => {
79+
expect(ShapeUtil.isArtifact(kind as string)).toBe(expected);
80+
});
81+
});
82+
83+
describe('isFlowNode', () => {
84+
test.each`
85+
kind | expected
86+
${ShapeBpmnElementKind.EVENT_END} | ${true}
87+
${ShapeBpmnElementKind.GATEWAY_PARALLEL} | ${true}
88+
${ShapeBpmnElementKind.TASK} | ${true}
89+
${ShapeBpmnElementKind.SUB_PROCESS} | ${true}
90+
${ShapeBpmnElementKind.CALL_ACTIVITY} | ${true}
91+
${ShapeBpmnElementKind.POOL} | ${false}
92+
${ShapeBpmnElementKind.LANE} | ${false}
93+
${ShapeBpmnElementKind.GROUP} | ${true}
94+
${ShapeBpmnElementKind.TEXT_ANNOTATION} | ${true}
95+
${FlowKind.MESSAGE_FLOW} | ${false}
96+
${'unknown'} | ${false}
97+
${'receiveTask'} | ${true}
98+
`('$kind isFlowNode? $expected', ({ kind, expected }: Record<string, unknown>) => {
99+
expect(ShapeUtil.isFlowNode(kind as string)).toBe(expected);
100+
});
101+
});
102+
49103
describe('Reference kinds cannot be modified', () => {
50104
it.each`
51105
kind | kindsFunction
52106
${'activities'} | ${() => ShapeUtil.activityKinds()}
107+
${'artifacts'} | ${() => ShapeUtil.artifactKinds()}
53108
${'events'} | ${() => ShapeUtil.eventKinds()}
54109
${'flow nodes'} | ${() => ShapeUtil.flowNodeKinds()}
55110
${'gateways'} | ${() => ShapeUtil.gatewayKinds()}

0 commit comments

Comments
 (0)