Skip to content

Commit b1e7b2c

Browse files
committed
feat: add isFlowNode and isArtifact in ShapeUtil
1 parent cbeac7f commit b1e7b2c

2 files changed

Lines changed: 63 additions & 1 deletion

File tree

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,23 @@ 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 isArtifact(kind: ShapeBpmnElementKind | string): boolean {
125+
return kind === ShapeBpmnElementKind.GROUP || kind === ShapeBpmnElementKind.TEXT_ANNOTATION;
126+
}
113127
}
114128

115129
function filterKind(suffix: string, options?: FilterParameter): ShapeBpmnElementKind[] {

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

Lines changed: 49 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,14 @@ 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+
3240
describe('Is pool or lane?', () => {
3341
it.each([
3442
[ShapeBpmnElementKind.CALL_ACTIVITY],
@@ -46,6 +54,46 @@ describe('ShapeUtil', () => {
4654
});
4755
});
4856

57+
describe('isArtifact', () => {
58+
test.each`
59+
kind | expected
60+
${ShapeBpmnElementKind.EVENT_END} | ${false}
61+
${ShapeBpmnElementKind.GATEWAY_PARALLEL} | ${false}
62+
${ShapeBpmnElementKind.TASK} | ${false}
63+
${ShapeBpmnElementKind.SUB_PROCESS} | ${false}
64+
${ShapeBpmnElementKind.CALL_ACTIVITY} | ${false}
65+
${ShapeBpmnElementKind.POOL} | ${false}
66+
${ShapeBpmnElementKind.LANE} | ${false}
67+
${ShapeBpmnElementKind.GROUP} | ${true}
68+
${ShapeBpmnElementKind.TEXT_ANNOTATION} | ${true}
69+
${FlowKind.MESSAGE_FLOW} | ${false}
70+
${'unknown'} | ${false}
71+
${'receiveTask'} | ${false}
72+
`('$kind isArtifact? $expected', ({ kind, expected }: Record<string, unknown>) => {
73+
expect(ShapeUtil.isArtifact(kind as string)).toBe(expected);
74+
});
75+
});
76+
77+
describe('isFlowNode', () => {
78+
test.each`
79+
kind | expected
80+
${ShapeBpmnElementKind.EVENT_END} | ${true}
81+
${ShapeBpmnElementKind.GATEWAY_PARALLEL} | ${true}
82+
${ShapeBpmnElementKind.TASK} | ${true}
83+
${ShapeBpmnElementKind.SUB_PROCESS} | ${true}
84+
${ShapeBpmnElementKind.CALL_ACTIVITY} | ${true}
85+
${ShapeBpmnElementKind.POOL} | ${false}
86+
${ShapeBpmnElementKind.LANE} | ${false}
87+
${ShapeBpmnElementKind.GROUP} | ${true}
88+
${ShapeBpmnElementKind.TEXT_ANNOTATION} | ${true}
89+
${FlowKind.MESSAGE_FLOW} | ${false}
90+
${'unknown'} | ${false}
91+
${'receiveTask'} | ${true}
92+
`('$kind isFlowNode? $expected', ({ kind, expected }: Record<string, unknown>) => {
93+
expect(ShapeUtil.isFlowNode(kind as string)).toBe(expected);
94+
});
95+
});
96+
4997
describe('Reference kinds cannot be modified', () => {
5098
it.each`
5199
kind | kindsFunction

0 commit comments

Comments
 (0)