From 7b9cf43fead029e4f37d0dcf92ba66dbc2b76471 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Souchet=20C=C3=A9line?= <4921914+csouchet@users.noreply.github.com> Date: Thu, 23 Jul 2020 17:54:12 +0200 Subject: [PATCH] [REFACTOR] Unit json test: Replace some tests by test templates (#439) * Merge all Json tests for sub-process in a same file * Fix label tests * Fix association tests * Refactor Text association tests * Merge gateways, tasks & call activity tests in same file * Fix messageFlow test * Change test names --- .../json/BpmnJsonParser.association.test.ts | 21 +- .../json/BpmnJsonParser.call.activity.test.ts | 165 --------------- ...est.ts => BpmnJsonParser.flowNode.test.ts} | 55 ++--- .../json/BpmnJsonParser.gateway.test.ts | 130 ------------ .../json/BpmnJsonParser.label.bounds.test.ts | 113 ++++++----- .../json/BpmnJsonParser.label.font.test.ts | 84 ++++---- .../parser/json/BpmnJsonParser.label.test.ts | 15 +- .../json/BpmnJsonParser.messageFlow.test.ts | 8 +- ...sonParser.sequenceFlow.conditional.test.ts | 4 +- ...pmnJsonParser.sequenceFlow.default.test.ts | 73 +------ ...BpmnJsonParser.sequenceFlow.normal.test.ts | 71 ++----- ...pmnJsonParser.sub.process.embedded.test.ts | 177 ---------------- .../BpmnJsonParser.sub.process.event.test.ts | 178 ---------------- .../json/BpmnJsonParser.sub.process.test.ts | 190 ++++++++++++++++++ .../BpmnJsonParser.text.annotation.test.ts | 90 ++------- 15 files changed, 378 insertions(+), 996 deletions(-) delete mode 100644 test/unit/component/parser/json/BpmnJsonParser.call.activity.test.ts rename test/unit/component/parser/json/{BpmnJsonParser.task.test.ts => BpmnJsonParser.flowNode.test.ts} (80%) delete mode 100644 test/unit/component/parser/json/BpmnJsonParser.gateway.test.ts delete mode 100644 test/unit/component/parser/json/BpmnJsonParser.sub.process.embedded.test.ts delete mode 100644 test/unit/component/parser/json/BpmnJsonParser.sub.process.event.test.ts create mode 100644 test/unit/component/parser/json/BpmnJsonParser.sub.process.test.ts diff --git a/test/unit/component/parser/json/BpmnJsonParser.association.test.ts b/test/unit/component/parser/json/BpmnJsonParser.association.test.ts index 7cd8ff8f11..3dc8edc2fd 100644 --- a/test/unit/component/parser/json/BpmnJsonParser.association.test.ts +++ b/test/unit/component/parser/json/BpmnJsonParser.association.test.ts @@ -14,7 +14,6 @@ * limitations under the License. */ import { parseJsonAndExpectOnlyEdges, verifyEdge } from './JsonTestUtils'; -import { defaultBpmnJsonParser } from '../../../../../src/component/parser/json/BpmnJsonParser'; import Waypoint from '../../../../../src/model/bpmn/edge/Waypoint'; import { TProcess } from '../../../../../src/component/parser/xml/bpmn-json-model/baseElement/rootElement/rootElement'; @@ -31,7 +30,7 @@ describe('parse bpmn as json for association', () => { it.each([ ['object', processJsonAsObjectWithAssociationJsonAsObject], ['array', [processJsonAsObjectWithAssociationJsonAsObject]], - ])(`should convert as Edge, when a association is an attribute (as object) of 'process' (as %s)`, (title: string, processJson: TProcess | TProcess[]) => { + ])(`should convert as Edge, when an association is an attribute (as object) of 'process' (as %s)`, (title: string, processJson: TProcess | TProcess[]) => { const json = { definitions: { targetNamespace: '', @@ -61,7 +60,7 @@ describe('parse bpmn as json for association', () => { }); }); - it('json containing one process with an array of associations with/without name', () => { + it(`should convert as Edge, when an association (with/without name) is an attribute (as array) of 'process'`, () => { const json = { definitions: { targetNamespace: '', @@ -101,13 +100,7 @@ describe('parse bpmn as json for association', () => { }, }; - //const model = parseJsonAndExpectOnlyEdges(json, 2); - - const model = defaultBpmnJsonParser().parse(json); - expect(model.lanes).toHaveLength(0); - expect(model.pools).toHaveLength(0); - expect(model.flowNodes).toHaveLength(0); - expect(model.edges).toHaveLength(2); + const model = parseJsonAndExpectOnlyEdges(json, 2); verifyEdge(model.edges[0], { edgeId: 'edge_association_id_0', @@ -148,13 +141,7 @@ describe('parse bpmn as json for association', () => { }, }; - //const model = parseJsonAndExpectOnlyEdges(json, 1); - - const model = defaultBpmnJsonParser().parse(json); - expect(model.lanes).toHaveLength(0); - expect(model.pools).toHaveLength(0); - expect(model.flowNodes).toHaveLength(0); - expect(model.edges).toHaveLength(1); + const model = parseJsonAndExpectOnlyEdges(json, 1); verifyEdge(model.edges[0], { edgeId: `edge_association_id_0`, diff --git a/test/unit/component/parser/json/BpmnJsonParser.call.activity.test.ts b/test/unit/component/parser/json/BpmnJsonParser.call.activity.test.ts deleted file mode 100644 index e5351364e9..0000000000 --- a/test/unit/component/parser/json/BpmnJsonParser.call.activity.test.ts +++ /dev/null @@ -1,165 +0,0 @@ -/** - * 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 { ShapeBpmnElementKind } from '../../../../../src/model/bpmn/shape/ShapeBpmnElementKind'; -import { parseJsonAndExpectOnlyFlowNodes, verifyShape } from './JsonTestUtils'; -import { TProcess } from '../../../../../src/component/parser/xml/bpmn-json-model/baseElement/rootElement/rootElement'; - -describe('parse bpmn as json for call activity', () => { - const processJsonAsObjectWithCallActivityJsonAsObject = { - callActivity: { - id: 'callActivity_id_0', - name: 'callActivity name', - }, - }; - - it.each([ - ['object', processJsonAsObjectWithCallActivityJsonAsObject], - ['array', [processJsonAsObjectWithCallActivityJsonAsObject]], - ])(`should convert as Shape, when a callActivity is an attribute (as object) of 'process' (as %s)`, (title: string, processJson: TProcess | TProcess[]) => { - const json = { - definitions: { - targetNamespace: '', - process: processJson, - BPMNDiagram: { - name: 'process 0', - BPMNPlane: { - BPMNShape: { - id: 'shape_callActivity_id_0', - bpmnElement: 'callActivity_id_0', - Bounds: { x: 362, y: 232, width: 36, height: 45 }, - }, - }, - }, - }, - }; - - const model = parseJsonAndExpectOnlyFlowNodes(json, 1); - - verifyShape(model.flowNodes[0], { - shapeId: `shape_callActivity_id_0`, - bpmnElementId: `callActivity_id_0`, - bpmnElementName: `callActivity name`, - bpmnElementKind: ShapeBpmnElementKind.CALL_ACTIVITY, - bounds: { - x: 362, - y: 232, - width: 36, - height: 45, - }, - }); - }); - - it('json containing one process with an array of call activities with/without name', () => { - const json = { - definitions: { - targetNamespace: '', - process: { - callActivity: [ - { - id: 'callActivity_id_0', - name: 'callActivity name', - }, - { - id: 'callActivity_id_1', - instantiate: true, - }, - ], - }, - BPMNDiagram: { - name: 'process 0', - BPMNPlane: { - BPMNShape: [ - { - id: 'shape_callActivity_id_0', - bpmnElement: 'callActivity_id_0', - Bounds: { x: 362, y: 232, width: 36, height: 45 }, - }, - { - id: 'shape_callActivity_id_1', - bpmnElement: 'callActivity_id_1', - Bounds: { x: 365, y: 235, width: 35, height: 46 }, - }, - ], - }, - }, - }, - }; - - const model = parseJsonAndExpectOnlyFlowNodes(json, 2); - - verifyShape(model.flowNodes[0], { - shapeId: 'shape_callActivity_id_0', - bpmnElementId: 'callActivity_id_0', - bpmnElementName: 'callActivity name', - bpmnElementKind: ShapeBpmnElementKind.CALL_ACTIVITY, - bounds: { - x: 362, - y: 232, - width: 36, - height: 45, - }, - }); - - verifyShape(model.flowNodes[1], { - shapeId: 'shape_callActivity_id_1', - bpmnElementId: 'callActivity_id_1', - bpmnElementName: undefined, - bpmnElementKind: ShapeBpmnElementKind.CALL_ACTIVITY, - bounds: { - x: 365, - y: 235, - width: 35, - height: 46, - }, - }); - }); - - it('should convert as Shape, when BPMNDiagram is an array', () => { - const json = { - definitions: { - targetNamespace: '', - process: processJsonAsObjectWithCallActivityJsonAsObject, - BPMNDiagram: [ - { - name: 'process 0', - BPMNPlane: { - BPMNShape: { - id: 'shape_callActivity_id_0', - bpmnElement: 'callActivity_id_0', - Bounds: { x: 362, y: 232, width: 36, height: 45 }, - }, - }, - }, - ], - }, - }; - - const model = parseJsonAndExpectOnlyFlowNodes(json, 1); - - verifyShape(model.flowNodes[0], { - shapeId: `shape_callActivity_id_0`, - bpmnElementId: `callActivity_id_0`, - bpmnElementName: `callActivity name`, - bpmnElementKind: ShapeBpmnElementKind.CALL_ACTIVITY, - bounds: { - x: 362, - y: 232, - width: 36, - height: 45, - }, - }); - }); -}); diff --git a/test/unit/component/parser/json/BpmnJsonParser.task.test.ts b/test/unit/component/parser/json/BpmnJsonParser.flowNode.test.ts similarity index 80% rename from test/unit/component/parser/json/BpmnJsonParser.task.test.ts rename to test/unit/component/parser/json/BpmnJsonParser.flowNode.test.ts index 4b65f0ded3..de18d64063 100644 --- a/test/unit/component/parser/json/BpmnJsonParser.task.test.ts +++ b/test/unit/component/parser/json/BpmnJsonParser.flowNode.test.ts @@ -18,20 +18,24 @@ import { parseJsonAndExpectOnlyFlowNodes, verifyShape } from './JsonTestUtils'; import { TProcess } from '../../../../../src/component/parser/xml/bpmn-json-model/baseElement/rootElement/rootElement'; describe.each([ + ['callActivity', ShapeBpmnElementKind.CALL_ACTIVITY], ['task', ShapeBpmnElementKind.TASK], ['serviceTask', ShapeBpmnElementKind.TASK_SERVICE], ['userTask', ShapeBpmnElementKind.TASK_USER], ['receiveTask', ShapeBpmnElementKind.TASK_RECEIVE], + ['exclusiveGateway', ShapeBpmnElementKind.GATEWAY_EXCLUSIVE], + ['inclusiveGateway', ShapeBpmnElementKind.GATEWAY_INCLUSIVE], + ['parallelGateway', ShapeBpmnElementKind.GATEWAY_PARALLEL], ])('parse bpmn as json for %s', (bpmnKind: string, expectedShapeBpmnElementKind: ShapeBpmnElementKind) => { - const processJsonAsObjectWithTaskJsonAsObject = {} as TProcess; - processJsonAsObjectWithTaskJsonAsObject[`${bpmnKind}`] = { + const processWithFlowNodeAsObject = {} as TProcess; + processWithFlowNodeAsObject[`${bpmnKind}`] = { id: `${bpmnKind}_id_0`, name: `${bpmnKind} name`, }; it.each([ - ['object', processJsonAsObjectWithTaskJsonAsObject], - ['array', [processJsonAsObjectWithTaskJsonAsObject]], + ['object', processWithFlowNodeAsObject], + ['array', [processWithFlowNodeAsObject]], ])(`should convert as Shape, when a ${bpmnKind} is an attribute (as object) of 'process' (as %s)`, (title: string, processJson: TProcess) => { const json = { definitions: { @@ -128,34 +132,24 @@ describe.each([ }); }); - if (expectedShapeBpmnElementKind === ShapeBpmnElementKind.TASK_RECEIVE) { + if (expectedShapeBpmnElementKind === ShapeBpmnElementKind.TASK_RECEIVE || expectedShapeBpmnElementKind === ShapeBpmnElementKind.CALL_ACTIVITY) { it(`should convert as Shape, when a ${bpmnKind} (with/without instantiate) is an attribute (as array) of 'process'`, () => { const json = { definitions: { targetNamespace: '', - process: { - receiveTask: [ - { - id: 'receiveTask_id_0', - }, - { - id: 'receiveTask_id_1', - instantiate: true, - }, - ], - }, + process: {}, BPMNDiagram: { name: 'process 0', BPMNPlane: { BPMNShape: [ { - id: 'shape_receiveTask_id_0', - bpmnElement: 'receiveTask_id_0', + id: `shape_${bpmnKind}_id_0`, + bpmnElement: `${bpmnKind}_id_0`, Bounds: { x: 362, y: 232, width: 36, height: 45 }, }, { - id: 'shape_receiveTask_id_1', - bpmnElement: 'receiveTask_id_1', + id: `shape_${bpmnKind}_id_1`, + bpmnElement: `${bpmnKind}_id_1`, Bounds: { x: 365, y: 235, width: 35, height: 46 }, }, ], @@ -163,14 +157,23 @@ describe.each([ }, }, }; + (json.definitions.process as TProcess)[`${bpmnKind}`] = [ + { + id: `${bpmnKind}_id_0`, + }, + { + id: `${bpmnKind}_id_1`, + instantiate: true, + }, + ]; const model = parseJsonAndExpectOnlyFlowNodes(json, 2); verifyShape(model.flowNodes[0], { - shapeId: 'shape_receiveTask_id_0', - bpmnElementId: 'receiveTask_id_0', + shapeId: `shape_${bpmnKind}_id_0`, + bpmnElementId: `${bpmnKind}_id_0`, bpmnElementName: undefined, - bpmnElementKind: ShapeBpmnElementKind.TASK_RECEIVE, + bpmnElementKind: expectedShapeBpmnElementKind, bounds: { x: 362, y: 232, @@ -181,10 +184,10 @@ describe.each([ expect(model.flowNodes[0].bpmnElement.instantiate).toBeFalsy(); verifyShape(model.flowNodes[1], { - shapeId: 'shape_receiveTask_id_1', - bpmnElementId: 'receiveTask_id_1', + shapeId: `shape_${bpmnKind}_id_1`, + bpmnElementId: `${bpmnKind}_id_1`, bpmnElementName: undefined, - bpmnElementKind: ShapeBpmnElementKind.TASK_RECEIVE, + bpmnElementKind: expectedShapeBpmnElementKind, bounds: { x: 365, y: 235, diff --git a/test/unit/component/parser/json/BpmnJsonParser.gateway.test.ts b/test/unit/component/parser/json/BpmnJsonParser.gateway.test.ts deleted file mode 100644 index cb359471d3..0000000000 --- a/test/unit/component/parser/json/BpmnJsonParser.gateway.test.ts +++ /dev/null @@ -1,130 +0,0 @@ -/** - * 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 { ShapeBpmnElementKind } from '../../../../../src/model/bpmn/shape/ShapeBpmnElementKind'; -import { parseJsonAndExpectOnlyFlowNodes, verifyShape } from './JsonTestUtils'; -import { TProcess } from '../../../../../src/component/parser/xml/bpmn-json-model/baseElement/rootElement/rootElement'; -import { BpmnJsonModel } from '../../../../../src/component/parser/xml/bpmn-json-model/BPMN20'; - -describe.each([ - ['exclusive', ShapeBpmnElementKind.GATEWAY_EXCLUSIVE], - ['inclusive', ShapeBpmnElementKind.GATEWAY_INCLUSIVE], - ['parallel', ShapeBpmnElementKind.GATEWAY_PARALLEL], -])('parse bpmn as json for %s gateway', (bpmnKind: string, expectedShapeBpmnElementKind: ShapeBpmnElementKind) => { - const processJsonAsObjectWithGatewayJsonAsObject = {} as TProcess; - processJsonAsObjectWithGatewayJsonAsObject[`${bpmnKind}Gateway`] = { - id: `${bpmnKind}Gateway_id_0`, - name: `${bpmnKind}Gateway name`, - }; - - it.each([ - ['object', processJsonAsObjectWithGatewayJsonAsObject], - ['array', [processJsonAsObjectWithGatewayJsonAsObject]], - ])(`should convert as Shape, when a ${bpmnKind} gateway is an attribute (as object) of 'process' (as %s)`, (title: string, processJson: TProcess | TProcess[]) => { - const json = { - definitions: { - targetNamespace: '', - process: processJson, - BPMNDiagram: { - name: 'process 0', - BPMNPlane: { - BPMNShape: { - id: `shape_${bpmnKind}Gateway_id_0`, - bpmnElement: `${bpmnKind}Gateway_id_0`, - Bounds: { x: 362, y: 232, width: 36, height: 45 }, - }, - }, - }, - }, - }; - - const model = parseJsonAndExpectOnlyFlowNodes(json, 1); - - verifyShape(model.flowNodes[0], { - shapeId: `shape_${bpmnKind}Gateway_id_0`, - bpmnElementId: `${bpmnKind}Gateway_id_0`, - bpmnElementName: `${bpmnKind}Gateway name`, - bpmnElementKind: expectedShapeBpmnElementKind, - bounds: { - x: 362, - y: 232, - width: 36, - height: 45, - }, - }); - }); - - it(`should convert as Shape, when a ${bpmnKind} gateway (with/without name) is an attribute (as array) of 'process'`, () => { - const json: BpmnJsonModel = { - definitions: { - targetNamespace: '', - process: {}, - BPMNDiagram: { - name: 'process 0', - BPMNPlane: { - BPMNShape: [ - { - id: `shape_${bpmnKind}Gateway_id_0`, - bpmnElement: `${bpmnKind}Gateway_id_0`, - Bounds: { x: 362, y: 232, width: 36, height: 45 }, - }, - { - id: `shape_${bpmnKind}Gateway_id_1`, - bpmnElement: `${bpmnKind}Gateway_id_1`, - Bounds: { x: 365, y: 235, width: 35, height: 46 }, - }, - ], - }, - }, - }, - }; - (json.definitions.process as TProcess)[`${bpmnKind}Gateway`] = [ - { - id: `${bpmnKind}Gateway_id_0`, - name: `${bpmnKind}Gateway name`, - }, - { - id: `${bpmnKind}Gateway_id_1`, - }, - ]; - - const model = parseJsonAndExpectOnlyFlowNodes(json, 2); - - verifyShape(model.flowNodes[0], { - shapeId: `shape_${bpmnKind}Gateway_id_0`, - bpmnElementId: `${bpmnKind}Gateway_id_0`, - bpmnElementName: `${bpmnKind}Gateway name`, - bpmnElementKind: expectedShapeBpmnElementKind, - bounds: { - x: 362, - y: 232, - width: 36, - height: 45, - }, - }); - verifyShape(model.flowNodes[1], { - shapeId: `shape_${bpmnKind}Gateway_id_1`, - bpmnElementId: `${bpmnKind}Gateway_id_1`, - bpmnElementName: undefined, - bpmnElementKind: expectedShapeBpmnElementKind, - bounds: { - x: 365, - y: 235, - width: 35, - height: 46, - }, - }); - }); -}); diff --git a/test/unit/component/parser/json/BpmnJsonParser.label.bounds.test.ts b/test/unit/component/parser/json/BpmnJsonParser.label.bounds.test.ts index 6d871dd2a8..792dc93792 100644 --- a/test/unit/component/parser/json/BpmnJsonParser.label.bounds.test.ts +++ b/test/unit/component/parser/json/BpmnJsonParser.label.bounds.test.ts @@ -21,11 +21,12 @@ describe('parse bpmn as json for label bounds', () => { each([ ['exclusiveGateway'], ['inclusiveGateway'], + ['parallelGateway'], ['task'], ['userTask'], ['serviceTask'], - ['callActivity'], ['receiveTask'], + ['callActivity'], ['subProcess'], ['textAnnotation'], // TODO: To uncomment when we support complex gateway @@ -38,38 +39,68 @@ describe('parse bpmn as json for label bounds', () => { //['sendTask'], // TODO: To uncomment when we support businessRuleTask //['businessRuleTask'], - ]).it('json containing a BPMNShape which has a label with bounds with all attributes in a %s', sourceKind => { - const json = { - definitions: { - targetNamespace: '', - process: { - id: 'Process_1', + ]).describe('parse bpmn as json for label bounds on %s', sourceKind => { + it(`should convert as Shape, when a BPMNShape (attached to ${sourceKind} & with bounds with all attributes) is an attribute (as object) of 'BPMNPlane' (as object)`, () => { + const json = { + definitions: { + targetNamespace: '', + process: { + id: 'Process_1', + }, + BPMNDiagram: { + id: 'BpmnDiagram_1', + BPMNPlane: { + id: 'BpmnPlane_1', + BPMNShape: { + id: 'shape_source_id_0', + bpmnElement: 'source_id_0', + Bounds: { x: 362, y: 232, width: 36, height: 45 }, + BPMNLabel: { + id: 'label_id', + Bounds: { x: 25, y: 26, width: 27, height: 28 }, + }, + }, + }, + }, }, - BPMNDiagram: { - id: 'BpmnDiagram_1', - BPMNPlane: { - id: 'BpmnPlane_1', - BPMNShape: { - id: 'shape_source_id_0', - bpmnElement: 'source_id_0', - Bounds: { x: 362, y: 232, width: 36, height: 45 }, - BPMNLabel: { - id: 'label_id', - Bounds: { x: 25, y: 26, width: 27, height: 28 }, + }; + (json.definitions.process as TProcess)[`${sourceKind}`] = { id: 'source_id_0', name: `${sourceKind}_id_0` }; + + const model = parseJsonAndExpectOnlyFlowNodes(json, 1); + + verifyLabelBounds(model.flowNodes[0].label, { x: 25, y: 26, width: 27, height: 28 }); + }); + + it(`should convert as Shape, when a BPMNShape (attached to ${sourceKind} & without bounds) is an attribute (as object) of 'BPMNPlane' (as object)`, () => { + const json = { + definitions: { + targetNamespace: '', + process: {}, + BPMNDiagram: { + id: 'BpmnDiagram_1', + BPMNPlane: { + id: 'BpmnPlane_1', + BPMNShape: { + id: 'BPMNShape_id_0', + bpmnElement: 'source_id_0', + Bounds: { x: 362, y: 232, width: 36, height: 45 }, + BPMNLabel: { + id: 'label_id', + }, }, }, }, }, - }, - }; - (json.definitions.process as TProcess)[`${sourceKind}`] = { id: 'source_id_0', name: `${sourceKind}_id_0` }; + }; + (json.definitions.process as TProcess)[`${sourceKind}`] = { id: 'source_id_0', name: `${sourceKind}_id_0` }; - const model = parseJsonAndExpectOnlyFlowNodes(json, 1); + const model = parseJsonAndExpectOnlyFlowNodes(json, 1); - verifyLabelBounds(model.flowNodes[0].label, { x: 25, y: 26, width: 27, height: 28 }); + expect(model.flowNodes[0].label).toBeUndefined(); + }); }); - it('json containing a BPMNEdge which has a label with bounds with all attributes', () => { + it(`should convert as Edge, when a BPMNEdge (with bounds with all attributes) is an attribute (as object) of 'BPMNPlane' (as object)`, () => { const json = { definitions: { targetNamespace: '', @@ -96,39 +127,7 @@ describe('parse bpmn as json for label bounds', () => { verifyLabelBounds(model.edges[0].label, { x: 25, y: 26, width: 27, height: 28 }); }); - it('json containing a BPMNShape which has a label without bounds', () => { - const json = { - definitions: { - targetNamespace: '', - process: { - task: { - id: 'task_id_0', - name: 'task name', - }, - }, - BPMNDiagram: { - id: 'BpmnDiagram_1', - BPMNPlane: { - id: 'BpmnPlane_1', - BPMNShape: { - id: 'BPMNShape_id_0', - bpmnElement: 'task_id_0', - Bounds: { x: 362, y: 232, width: 36, height: 45 }, - BPMNLabel: { - id: 'label_id', - }, - }, - }, - }, - }, - }; - - const model = parseJsonAndExpectOnlyFlowNodes(json, 1); - - expect(model.flowNodes[0].label).toBeUndefined(); - }); - - it('json containing a BPMNEdge which has a label without bounds', () => { + it(`should convert as Edge, when a BPMNEdge (without bounds) is an attribute (as object) of 'BPMNPlane' (as object)`, () => { const json = { definitions: { targetNamespace: '', diff --git a/test/unit/component/parser/json/BpmnJsonParser.label.font.test.ts b/test/unit/component/parser/json/BpmnJsonParser.label.font.test.ts index 1e3abe0531..6542b40868 100644 --- a/test/unit/component/parser/json/BpmnJsonParser.label.font.test.ts +++ b/test/unit/component/parser/json/BpmnJsonParser.label.font.test.ts @@ -27,11 +27,12 @@ describe('parse bpmn as json for label font', () => { each([ ['exclusiveGateway'], ['inclusiveGateway'], + ['parallelGateway'], ['task'], ['userTask'], ['serviceTask'], - ['callActivity'], ['receiveTask'], + ['callActivity'], ['subProcess'], ['textAnnotation'], // TODO: To uncomment when we support complex gateway @@ -44,45 +45,48 @@ describe('parse bpmn as json for label font', () => { //['sendTask'], // TODO: To uncomment when we support businessRuleTask //['businessRuleTask'], - ]).it('json containing a BPMNShape who references a label style with font in a %s', sourceKind => { - const json = { - definitions: { - targetNamespace: '', - process: { - id: 'Process_1', - }, - BPMNDiagram: { - id: 'BpmnDiagram_1', - BPMNPlane: { - id: 'BpmnPlane_1', - BPMNShape: { - id: 'shape_source_id_0', - bpmnElement: 'source_id_0', - Bounds: { x: 362, y: 232, width: 36, height: 45 }, - BPMNLabel: { - id: 'label_id', - labelStyle: 'style_id', + ]).it( + "should convert as Shape with Font, when a BPMNShape (attached to %s & who references a BPMNLabelStyle with font) is an attribute (as object) of 'BPMNPlane' (as object)", + sourceKind => { + const json = { + definitions: { + targetNamespace: '', + process: { + id: 'Process_1', + }, + BPMNDiagram: { + id: 'BpmnDiagram_1', + BPMNPlane: { + id: 'BpmnPlane_1', + BPMNShape: { + id: 'shape_source_id_0', + bpmnElement: 'source_id_0', + Bounds: { x: 362, y: 232, width: 36, height: 45 }, + BPMNLabel: { + id: 'label_id', + labelStyle: 'style_id', + }, }, }, - }, - BPMNLabelStyle: { - id: 'style_id', - Font: { - name: 'Arial', - size: 11.0, + BPMNLabelStyle: { + id: 'style_id', + Font: { + name: 'Arial', + size: 11.0, + }, }, }, }, - }, - }; - (json.definitions.process as TProcess)[`${sourceKind}`] = { id: 'source_id_0', name: `${sourceKind}_id_0` }; + }; + (json.definitions.process as TProcess)[`${sourceKind}`] = { id: 'source_id_0', name: `${sourceKind}_id_0` }; - const model = parseJsonAndExpectOnlyFlowNodes(json, 1); + const model = parseJsonAndExpectOnlyFlowNodes(json, 1); - verifyLabelFont(model.flowNodes[0].label, { name: 'Arial', size: 11.0 }); - }); + verifyLabelFont(model.flowNodes[0].label, { name: 'Arial', size: 11.0 }); + }, + ); - it('json containing a BPMNEdge who references a label style with font', () => { + it("should convert as Edge with Font, when a BPMNEdge (who references a BPMNLabelStyle with font) is an attribute (as object) of 'BPMNPlane' (as object)", () => { const json = { definitions: { targetNamespace: '', @@ -116,7 +120,7 @@ describe('parse bpmn as json for label font', () => { verifyLabelFont(model.edges[0].label, { name: 'Arial', size: 11.0 }); }); - it('json containing several BPMNShapes who reference the same label style', () => { + it("should convert as Shape[] with Font, when several BPMNShapes (who reference the same BPMNLabelStyle) are an attribute (as array) of 'BPMNPlane' (as object)", () => { const json = { definitions: { targetNamespace: '', @@ -170,7 +174,7 @@ describe('parse bpmn as json for label font', () => { verifyLabelFont(model.flowNodes[1].label, { name: 'Arial', size: 11.0 }); }); - it('json containing several BPMNEdges who reference the same label style', () => { + it("should convert as Edge[] with Font, when several BPMNEdges (who reference the same BPMNLabelStyle) are an attribute (as array) of 'BPMNPlane' (as object)", () => { const json = { definitions: { targetNamespace: '', @@ -213,7 +217,7 @@ describe('parse bpmn as json for label font', () => { verifyLabelFont(model.edges[1].label, { name: 'Arial', size: 11.0 }); }); - it('json containing an array of label styles and BPMNShapes who reference a label style with font with/without all attributes', () => { + it("should convert as Shape[] without Font, when BPMNShapes (who reference a BPMNLabelStyle) are an attribute (as array) of 'BPMNPlane' (as object) & BPMNLabelStyle (with font with/without all attributes) is an attribute (as array) of 'BPMNDiagram' (as object)", () => { const json = { definitions: { targetNamespace: '', @@ -280,7 +284,7 @@ describe('parse bpmn as json for label font', () => { expect(model.flowNodes[1].label).toBeUndefined(); }); - it('json containing an array of label styles and BPMNEdges who reference a label style with font with/without all attributes', () => { + it("should convert as Edge[] without Font, when BPMNEdges (who reference a BPMNLabelStyle) are an attribute (as array) of 'BPMNPlane' (as object) & BPMNLabelStyle (with font with/without all attributes) is an attribute (as array) of 'BPMNDiagram' (as object)", () => { const json = { definitions: { targetNamespace: '', @@ -336,7 +340,7 @@ describe('parse bpmn as json for label font', () => { expect(model.edges[1].label).toBeUndefined(); }); - it('json containing a BPMNShape who references a label style without font', () => { + it("should convert as Shape without Font, when a BPMNShape (who references a BPMNLabelStyle without font) is an attribute (as object) of 'BPMNPlane' (as object)", () => { const json = { definitions: { targetNamespace: '', @@ -372,7 +376,7 @@ describe('parse bpmn as json for label font', () => { expect(model.flowNodes[0].label).toBeUndefined(); }); - it('json containing a BPMNEdge who references a label style without font', () => { + it("should convert as Edge without Font, when a BPMNEdge (who references a BPMNLabelStyle without font) is an attribute (as object) of 'BPMNPlane' (as object)", () => { const json = { definitions: { targetNamespace: '', @@ -402,7 +406,7 @@ describe('parse bpmn as json for label font', () => { expect(model.edges[0].label).toBeUndefined(); }); - it('json containing a BPMNShape who references a non-existing label style', () => { + it("should convert as Shape without Font, when a BPMNShape (who references a non-existing BPMNLabelStyle) is an attribute (as object) of 'BPMNPlane' (as object)", () => { console.warn = jest.fn(); const json = { definitions: { @@ -437,7 +441,7 @@ describe('parse bpmn as json for label font', () => { expect(console.warn).toHaveBeenCalledWith('Unable to assign font from style %s to shape/edge %s', 'non-existing_style_id', 'BPMNShape_id_0'); }); - it('json containing a BPMNEdge who references a non-existing label style', () => { + it("should convert as Edge without Font, when a BPMNEdge (who references a non-existing BPMNLabelStyle) is an attribute (as object) of 'BPMNPlane' (as object)", () => { console.warn = jest.fn(); const json = { definitions: { diff --git a/test/unit/component/parser/json/BpmnJsonParser.label.test.ts b/test/unit/component/parser/json/BpmnJsonParser.label.test.ts index 3b0d835602..8d0ba2afef 100644 --- a/test/unit/component/parser/json/BpmnJsonParser.label.test.ts +++ b/test/unit/component/parser/json/BpmnJsonParser.label.test.ts @@ -21,11 +21,12 @@ describe('parse bpmn as json for label font', () => { each([ ['exclusiveGateway'], ['inclusiveGateway'], + ['parallelGateway'], ['task'], ['userTask'], ['serviceTask'], - ['callActivity'], ['receiveTask'], + ['callActivity'], ['subProcess'], ['textAnnotation'], // TODO: To uncomment when we support complex gateway @@ -38,7 +39,7 @@ describe('parse bpmn as json for label font', () => { //['sendTask'], // TODO: To uncomment when we support businessRuleTask //['businessRuleTask'], - ]).it('json containing a BPMNShape with empty label in a %s', sourceKind => { + ]).it("should convert as Shape without Label, when a BPMNShape (attached to %s & with empty BPMNLabel) is an attribute (as object) of 'BPMNPlane' (as object)", sourceKind => { const json = { definitions: { targetNamespace: '', @@ -66,7 +67,7 @@ describe('parse bpmn as json for label font', () => { expect(model.flowNodes[0].label).toBeUndefined(); }); - it('json containing a BPMNEdge with empty label', () => { + it("should convert as Edge without Label, when a BPMNEdge (with empty BPMNLabel) is an attribute (as object) of 'BPMNPlane' (as object)", () => { const json = { definitions: { targetNamespace: '', @@ -90,7 +91,7 @@ describe('parse bpmn as json for label font', () => { expect(model.edges[0].label).toBeUndefined(); }); - it('json containing a BPMNShape with label with just id', () => { + it("should convert as Shape without Label, when a BPMNShape (with BPMNLabel with just id) is an attribute (as object) of 'BPMNPlane' (as object)", () => { const json = { definitions: { targetNamespace: '', @@ -122,7 +123,7 @@ describe('parse bpmn as json for label font', () => { expect(model.flowNodes[0].label).toBeUndefined(); }); - it('json containing a BPMNEdge with empty label with just id', () => { + it("should convert as Edge without Label, when a BPMNEdge (with BPMNLabel with just id) is an attribute (as object) of 'BPMNPlane' (as object)", () => { const json = { definitions: { targetNamespace: '', @@ -148,7 +149,7 @@ describe('parse bpmn as json for label font', () => { expect(model.edges[0].label).toBeUndefined(); }); - it('json containing a BPMNShape without label', () => { + it("should convert as Shape without Label, when a BPMNShape (without BPMNLabel) is an attribute (as object) of 'BPMNPlane' (as object)", () => { const json = { definitions: { targetNamespace: '', @@ -177,7 +178,7 @@ describe('parse bpmn as json for label font', () => { expect(model.flowNodes[0].label).toBeUndefined(); }); - it('json containing a BPMNEdge without label', () => { + it("should convert as Edge without Label, when a BPMNEdge (without BPMNLabel) is an attribute (as object) of 'BPMNPlane' (as object)", () => { const json = { definitions: { targetNamespace: '', diff --git a/test/unit/component/parser/json/BpmnJsonParser.messageFlow.test.ts b/test/unit/component/parser/json/BpmnJsonParser.messageFlow.test.ts index c406b1ee88..1cb388163b 100644 --- a/test/unit/component/parser/json/BpmnJsonParser.messageFlow.test.ts +++ b/test/unit/component/parser/json/BpmnJsonParser.messageFlow.test.ts @@ -19,7 +19,7 @@ import { MessageVisibleKind } from '../../../../../src/model/bpmn/edge/MessageVi import * as bpmndi from '../../../../../src/component/parser/xml/bpmn-json-model/BPMNDI'; describe('parse bpmn as json for message flow', () => { - it('json containing a collaboration with a single message flow without waypoint', () => { + it(`should convert as Edge, when an message flow is an attribute (as object) of 'collaboration' (as object)`, () => { const json = { definitions: { targetNamespace: '', @@ -59,7 +59,7 @@ describe('parse bpmn as json for message flow', () => { }); }); - it('json containing a collaboration with an array of message flows with name & without name', () => { + it(`should convert as Edge, when an message flow (with/without name) is an attribute (as array) of 'collaboration'`, () => { const json = { definitions: { targetNamespace: '', @@ -121,7 +121,7 @@ describe('parse bpmn as json for message flow', () => { }); }); - it('json containing a collaboration with an array of message flows with one & several waypoints', () => { + it(`should convert as Edge, when an message flow (with one & several waypoints) is an attribute (as array) of 'collaboration'`, () => { const json = { definitions: { targetNamespace: '', @@ -196,7 +196,7 @@ describe('parse bpmn as json for message flow', () => { }); }); - it('json containing a collaboration with none/initiating/non-initiating message flows', () => { + it(`should convert as Edge, when none/initiating/non-initiating message flows are an attribute (as array) of 'collaboration'`, () => { const json = { definitions: { targetNamespace: '', diff --git a/test/unit/component/parser/json/BpmnJsonParser.sequenceFlow.conditional.test.ts b/test/unit/component/parser/json/BpmnJsonParser.sequenceFlow.conditional.test.ts index b4ccc7d9ee..ee4c320915 100644 --- a/test/unit/component/parser/json/BpmnJsonParser.sequenceFlow.conditional.test.ts +++ b/test/unit/component/parser/json/BpmnJsonParser.sequenceFlow.conditional.test.ts @@ -40,7 +40,7 @@ describe('parse bpmn as json for conditional sequence flow', () => { //['sendTask', SequenceFlowKind.CONDITIONAL_FROM_ACTIVITY], // TODO: To uncomment when we support businessRuleTask //['businessRuleTask', SequenceFlowKind.CONDITIONAL_FROM_ACTIVITY], - ]).it('json containing one process with a sequence flow defined as conditional in a %s', (sourceKind, expectedSequenceFlowKind) => { + ]).it(`should convert as Edge, when an sequence flow (defined as conditional) is an attribute (as object) of 'process' (as object)`, (sourceKind, expectedSequenceFlowKind) => { const json = { definitions: { targetNamespace: '', @@ -90,7 +90,7 @@ describe('parse bpmn as json for conditional sequence flow', () => { }); }); - it('json containing one process with a flow node who define a sequence flow as conditional, but not possible in BPMN Semantic', () => { + it(`should NOT convert, when an sequence flow (defined as conditional) is an attribute of 'process' and attached to a flow node where is NOT possible in BPMN Semantic`, () => { const json = { definitions: { targetNamespace: '', diff --git a/test/unit/component/parser/json/BpmnJsonParser.sequenceFlow.default.test.ts b/test/unit/component/parser/json/BpmnJsonParser.sequenceFlow.default.test.ts index 3e19af3450..6a26de0ae6 100644 --- a/test/unit/component/parser/json/BpmnJsonParser.sequenceFlow.default.test.ts +++ b/test/unit/component/parser/json/BpmnJsonParser.sequenceFlow.default.test.ts @@ -20,75 +20,6 @@ import Waypoint from '../../../../../src/model/bpmn/edge/Waypoint'; import { TProcess } from '../../../../../src/component/parser/xml/bpmn-json-model/baseElement/rootElement/rootElement'; describe('parse bpmn as json for default sequence flow', () => { - it('json containing one process with a default sequence flow & a sequence flow', () => { - const json = { - definitions: { - targetNamespace: '', - process: { - id: 'Process_1', - task: { id: 'task_id_0', default: 'sequenceFlow_id_0' }, - sequenceFlow: [ - { - id: 'sequenceFlow_id_0', - name: 'label 1', - sourceRef: 'task_id_0', - targetRef: 'targetRef_RLk', - }, - { - id: 'sequenceFlow_id_1', - sourceRef: 'task_id_0', - targetRef: 'targetRef_2', - }, - ], - }, - BPMNDiagram: { - id: 'BpmnDiagram_1', - BPMNPlane: { - id: 'BpmnPlane_1', - BPMNShape: { - id: 'shape_task_id_0', - bpmnElement: 'task_id_0', - Bounds: { x: 362, y: 232, width: 36, height: 45 }, - }, - BPMNEdge: [ - { - id: 'edge_sequenceFlow_id_0', - bpmnElement: 'sequenceFlow_id_0', - waypoint: [{ x: 10, y: 10 }], - }, - { - id: 'edge_sequenceFlow_id_1', - bpmnElement: 'sequenceFlow_id_1', - waypoint: [{ x: 10, y: 10 }], - }, - ], - }, - }, - }, - }; - - const model = parseJsonAndExpectOnlyEdgesAndFlowNodes(json, 2, 1); - - verifyEdge(model.edges[0], { - edgeId: 'edge_sequenceFlow_id_0', - bpmnElementId: 'sequenceFlow_id_0', - bpmnElementName: 'label 1', - bpmnElementSourceRefId: 'task_id_0', - bpmnElementTargetRefId: 'targetRef_RLk', - bpmnElementSequenceFlowKind: SequenceFlowKind.DEFAULT, - waypoints: [new Waypoint(10, 10)], - }); - verifyEdge(model.edges[1], { - edgeId: 'edge_sequenceFlow_id_1', - bpmnElementId: 'sequenceFlow_id_1', - bpmnElementName: undefined, - bpmnElementSourceRefId: 'task_id_0', - bpmnElementTargetRefId: 'targetRef_2', - bpmnElementSequenceFlowKind: SequenceFlowKind.NORMAL, - waypoints: [new Waypoint(10, 10)], - }); - }); - each([ ['exclusiveGateway'], ['inclusiveGateway'], @@ -108,7 +39,7 @@ describe('parse bpmn as json for default sequence flow', () => { //['sendTask'], // TODO: To uncomment when we support businessRuleTask //['businessRuleTask'], - ]).it('json containing one process with a sequence flow defined as default in a %s', sourceKind => { + ]).it(`should convert as Edge, when an sequence flow (defined as default) is an attribute (as object) of 'process' (as object)`, sourceKind => { const json = { definitions: { targetNamespace: '', @@ -153,7 +84,7 @@ describe('parse bpmn as json for default sequence flow', () => { }); }); - it('json containing one process with a flow node who define a sequence flow as default, but not possible in BPMN Semantic', () => { + it(`should NOT convert, when an sequence flow (defined as default) is an attribute of 'process' and attached to a flow node where is NOT possible in BPMN Semantic`, () => { const json = { definitions: { targetNamespace: '', diff --git a/test/unit/component/parser/json/BpmnJsonParser.sequenceFlow.normal.test.ts b/test/unit/component/parser/json/BpmnJsonParser.sequenceFlow.normal.test.ts index 62a581c84a..abce76e5f1 100644 --- a/test/unit/component/parser/json/BpmnJsonParser.sequenceFlow.normal.test.ts +++ b/test/unit/component/parser/json/BpmnJsonParser.sequenceFlow.normal.test.ts @@ -15,66 +15,29 @@ */ import { parseJsonAndExpectOnlyEdges, verifyEdge } from './JsonTestUtils'; import Waypoint from '../../../../../src/model/bpmn/edge/Waypoint'; +import { TProcess } from '../../../../../src/component/parser/xml/bpmn-json-model/baseElement/rootElement/rootElement'; describe('parse bpmn as json for sequence flow', () => { - it('json containing one process with a single sequence flow without waypoint', () => { - const json = { - definitions: { - targetNamespace: '', - process: { - id: 'Process_1', - sequenceFlow: { - id: 'sequenceFlow_id_0', - name: 'label 1', - sourceRef: 'sourceRef_id_xsdas', - targetRef: 'targetRef_RLk', - }, - }, - BPMNDiagram: { - id: 'BpmnDiagram_1', - BPMNPlane: { - id: 'BpmnPlane_1', - BPMNEdge: { - id: 'edge_sequenceFlow_id_0', - bpmnElement: 'sequenceFlow_id_0', - waypoint: [{ x: 10, y: 10 }], - }, - }, - }, - }, - }; + const processWithSequenceFlowAsObject = { + sequenceFlow: { + id: 'sequenceFlow_id_0', + name: 'label 1', + sourceRef: 'sourceRef_id_xsdas', + targetRef: 'targetRef_RLk', + }, + } as TProcess; - const model = parseJsonAndExpectOnlyEdges(json, 1); - - verifyEdge(model.edges[0], { - edgeId: 'edge_sequenceFlow_id_0', - bpmnElementId: 'sequenceFlow_id_0', - bpmnElementName: 'label 1', - bpmnElementSourceRefId: 'sourceRef_id_xsdas', - bpmnElementTargetRefId: 'targetRef_RLk', - waypoints: [new Waypoint(10, 10)], - }); - }); - - it('json containing one process declared as array with a single sequence flow', () => { + it.each([ + ['object', processWithSequenceFlowAsObject], + ['array', [processWithSequenceFlowAsObject]], + ])(`should convert as Edge, when a sequence flow is an attribute (as object) of 'process' (as %s)`, (title: string, processJson: TProcess) => { const json = { definitions: { targetNamespace: '', - process: [ - { - id: 'Process_1', - sequenceFlow: { - id: 'sequenceFlow_id_0', - name: 'label 1', - sourceRef: 'sourceRef_id_xsdas', - targetRef: 'targetRef_RLk', - }, - }, - ], + process: processJson, BPMNDiagram: { - id: 'BpmnDiagram_1', + name: 'process 0', BPMNPlane: { - id: 'BpmnPlane_1', BPMNEdge: { id: 'edge_sequenceFlow_id_0', bpmnElement: 'sequenceFlow_id_0', @@ -97,7 +60,7 @@ describe('parse bpmn as json for sequence flow', () => { }); }); - it('json containing one process with an array of sequence flows with name & without name', () => { + it(`should convert as Edge, when a sequence flow (with/without name) is an attribute (as array) of 'process'`, () => { const json = { definitions: { targetNamespace: '', @@ -158,7 +121,7 @@ describe('parse bpmn as json for sequence flow', () => { }); }); - it('json containing one process with an array of sequence flows with 2 & several waypoints', () => { + it(`should convert as Edge, when a sequence flow (with 2 & several waypoints) is an attribute (as array) of 'process'`, () => { const json = { definitions: { targetNamespace: '', diff --git a/test/unit/component/parser/json/BpmnJsonParser.sub.process.embedded.test.ts b/test/unit/component/parser/json/BpmnJsonParser.sub.process.embedded.test.ts deleted file mode 100644 index 3620bd09e9..0000000000 --- a/test/unit/component/parser/json/BpmnJsonParser.sub.process.embedded.test.ts +++ /dev/null @@ -1,177 +0,0 @@ -/** - * 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 { ShapeBpmnElementKind } from '../../../../../src/model/bpmn/shape/ShapeBpmnElementKind'; -import { parseJsonAndExpectOnlySubProcess, verifyShape } from './JsonTestUtils'; -import each from 'jest-each'; -import { ShapeBpmnSubProcessKind } from '../../../../../src/model/bpmn/shape/ShapeBpmnSubProcessKind'; - -describe('parse bpmn as json for embedded sub-process', () => { - each([ - ['expanded', true], - ['collapsed', false], - ]).it('json containing one process with a single %s embedded sub-process', (testName, isExpanded: boolean) => { - const json = { - definitions: { - targetNamespace: '', - process: { - subProcess: { - id: 'sub-process_id_0', - name: 'sub-process name', - triggeredByEvent: false, - }, - }, - BPMNDiagram: { - name: 'process 0', - BPMNPlane: { - BPMNShape: { - id: 'shape_sub-process_id_0', - bpmnElement: 'sub-process_id_0', - Bounds: { x: 362, y: 232, width: 36, height: 45 }, - isExpanded: isExpanded, - }, - }, - }, - }, - }; - - const model = parseJsonAndExpectOnlySubProcess(json, ShapeBpmnSubProcessKind.EMBEDDED, 1); - - verifyShape(model.flowNodes[0], { - shapeId: 'shape_sub-process_id_0', - bpmnElementId: 'sub-process_id_0', - bpmnElementName: 'sub-process name', - bpmnElementKind: ShapeBpmnElementKind.SUB_PROCESS, - bounds: { - x: 362, - y: 232, - width: 36, - height: 45, - }, - isExpanded: isExpanded, - }); - }); - - it('json containing one process declared as array with a single embedded sub-process', () => { - const json = { - definitions: { - targetNamespace: '', - process: [ - { - subProcess: { - id: 'sub-process_id_1', - name: 'sub-process name', - triggeredByEvent: false, - }, - }, - ], - BPMNDiagram: { - name: 'process 0', - BPMNPlane: { - BPMNShape: { - id: 'shape_sub-process_id_1', - bpmnElement: 'sub-process_id_1', - Bounds: { x: 362, y: 232, width: 36, height: 45 }, - isExpanded: false, - }, - }, - }, - }, - }; - - const model = parseJsonAndExpectOnlySubProcess(json, ShapeBpmnSubProcessKind.EMBEDDED, 1); - - verifyShape(model.flowNodes[0], { - shapeId: 'shape_sub-process_id_1', - bpmnElementId: 'sub-process_id_1', - bpmnElementName: 'sub-process name', - bpmnElementKind: ShapeBpmnElementKind.SUB_PROCESS, - bounds: { - x: 362, - y: 232, - width: 36, - height: 45, - }, - isExpanded: false, - }); - }); - - it('json containing one process with an array of embedded sub-processes with/without name, triggeredByEvent & isExpanded', () => { - const json = { - definitions: { - targetNamespace: '', - process: { - subProcess: [ - { - id: 'sub-process_id_0', - name: 'sub-process name', - triggeredByEvent: false, - }, - { - id: 'sub-process_id_1', - }, - ], - }, - BPMNDiagram: { - name: 'process 0', - BPMNPlane: { - BPMNShape: [ - { - id: 'shape_sub-process_id_0', - bpmnElement: 'sub-process_id_0', - Bounds: { x: 362, y: 232, width: 36, height: 45 }, - isExpanded: false, - }, - { - id: 'shape_sub-process_id_1', - bpmnElement: 'sub-process_id_1', - Bounds: { x: 365, y: 235, width: 35, height: 46 }, - }, - ], - }, - }, - }, - }; - - const model = parseJsonAndExpectOnlySubProcess(json, ShapeBpmnSubProcessKind.EMBEDDED, 2); - - verifyShape(model.flowNodes[0], { - shapeId: 'shape_sub-process_id_0', - bpmnElementId: 'sub-process_id_0', - bpmnElementName: 'sub-process name', - bpmnElementKind: ShapeBpmnElementKind.SUB_PROCESS, - bounds: { - x: 362, - y: 232, - width: 36, - height: 45, - }, - isExpanded: false, - }); - verifyShape(model.flowNodes[1], { - shapeId: 'shape_sub-process_id_1', - bpmnElementId: 'sub-process_id_1', - bpmnElementName: undefined, - bpmnElementKind: ShapeBpmnElementKind.SUB_PROCESS, - bounds: { - x: 365, - y: 235, - width: 35, - height: 46, - }, - isExpanded: false, - }); - }); -}); diff --git a/test/unit/component/parser/json/BpmnJsonParser.sub.process.event.test.ts b/test/unit/component/parser/json/BpmnJsonParser.sub.process.event.test.ts deleted file mode 100644 index f0afae7399..0000000000 --- a/test/unit/component/parser/json/BpmnJsonParser.sub.process.event.test.ts +++ /dev/null @@ -1,178 +0,0 @@ -/** - * 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 { ShapeBpmnElementKind } from '../../../../../src/model/bpmn/shape/ShapeBpmnElementKind'; -import { parseJsonAndExpectOnlySubProcess, verifyShape } from './JsonTestUtils'; -import each from 'jest-each'; -import { ShapeBpmnSubProcessKind } from '../../../../../src/model/bpmn/shape/ShapeBpmnSubProcessKind'; - -describe('parse bpmn as json for event sub-process', () => { - each([ - ['expanded', true], - ['collapsed', false], - ]).it('json containing one process with a single %s event sub-process', (testName, isExpanded: boolean) => { - const json = { - definitions: { - targetNamespace: '', - process: { - subProcess: { - id: 'sub-process_id_0', - name: 'sub-process name', - triggeredByEvent: true, - }, - }, - BPMNDiagram: { - name: 'process 0', - BPMNPlane: { - BPMNShape: { - id: 'shape_sub-process_id_0', - bpmnElement: 'sub-process_id_0', - Bounds: { x: 362, y: 232, width: 36, height: 45 }, - isExpanded: isExpanded, - }, - }, - }, - }, - }; - - const model = parseJsonAndExpectOnlySubProcess(json, ShapeBpmnSubProcessKind.EVENT, 1); - - verifyShape(model.flowNodes[0], { - shapeId: 'shape_sub-process_id_0', - bpmnElementId: 'sub-process_id_0', - bpmnElementName: 'sub-process name', - bpmnElementKind: ShapeBpmnElementKind.SUB_PROCESS, - bounds: { - x: 362, - y: 232, - width: 36, - height: 45, - }, - isExpanded: isExpanded, - }); - }); - - it('json containing one process declared as array with a single event sub-process', () => { - const json = { - definitions: { - targetNamespace: '', - process: [ - { - subProcess: { - id: 'sub-process_id_1', - name: 'sub-process name', - triggeredByEvent: true, - }, - }, - ], - BPMNDiagram: { - name: 'process 0', - BPMNPlane: { - BPMNShape: { - id: 'shape_sub-process_id_1', - bpmnElement: 'sub-process_id_1', - Bounds: { x: 362, y: 232, width: 36, height: 45 }, - isExpanded: false, - }, - }, - }, - }, - }; - - const model = parseJsonAndExpectOnlySubProcess(json, ShapeBpmnSubProcessKind.EVENT, 1); - - verifyShape(model.flowNodes[0], { - shapeId: 'shape_sub-process_id_1', - bpmnElementId: 'sub-process_id_1', - bpmnElementName: 'sub-process name', - bpmnElementKind: ShapeBpmnElementKind.SUB_PROCESS, - bounds: { - x: 362, - y: 232, - width: 36, - height: 45, - }, - isExpanded: false, - }); - }); - - it('json containing one process with an array of event sub-processes with/without name & isExpanded', () => { - const json = { - definitions: { - targetNamespace: '', - process: { - subProcess: [ - { - id: 'sub-process_id_0', - name: 'sub-process name', - triggeredByEvent: true, - }, - { - id: 'sub-process_id_1', - triggeredByEvent: true, - }, - ], - }, - BPMNDiagram: { - name: 'process 0', - BPMNPlane: { - BPMNShape: [ - { - id: 'shape_sub-process_id_0', - bpmnElement: 'sub-process_id_0', - Bounds: { x: 362, y: 232, width: 36, height: 45 }, - isExpanded: false, - }, - { - id: 'shape_sub-process_id_1', - bpmnElement: 'sub-process_id_1', - Bounds: { x: 365, y: 235, width: 35, height: 46 }, - }, - ], - }, - }, - }, - }; - - const model = parseJsonAndExpectOnlySubProcess(json, ShapeBpmnSubProcessKind.EVENT, 2); - - verifyShape(model.flowNodes[0], { - shapeId: 'shape_sub-process_id_0', - bpmnElementId: 'sub-process_id_0', - bpmnElementName: 'sub-process name', - bpmnElementKind: ShapeBpmnElementKind.SUB_PROCESS, - bounds: { - x: 362, - y: 232, - width: 36, - height: 45, - }, - isExpanded: false, - }); - verifyShape(model.flowNodes[1], { - shapeId: 'shape_sub-process_id_1', - bpmnElementId: 'sub-process_id_1', - bpmnElementName: undefined, - bpmnElementKind: ShapeBpmnElementKind.SUB_PROCESS, - bounds: { - x: 365, - y: 235, - width: 35, - height: 46, - }, - isExpanded: false, - }); - }); -}); diff --git a/test/unit/component/parser/json/BpmnJsonParser.sub.process.test.ts b/test/unit/component/parser/json/BpmnJsonParser.sub.process.test.ts new file mode 100644 index 0000000000..0266e30395 --- /dev/null +++ b/test/unit/component/parser/json/BpmnJsonParser.sub.process.test.ts @@ -0,0 +1,190 @@ +/** + * 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 { ShapeBpmnElementKind } from '../../../../../src/model/bpmn/shape/ShapeBpmnElementKind'; +import { parseJsonAndExpectOnlySubProcess, verifyShape } from './JsonTestUtils'; +import each from 'jest-each'; +import { ShapeBpmnSubProcessKind } from '../../../../../src/model/bpmn/shape/ShapeBpmnSubProcessKind'; +import { TProcess } from '../../../../../src/component/parser/xml/bpmn-json-model/baseElement/rootElement/rootElement'; + +describe('parse bpmn as json for sub-process', () => { + each([ + ['embedded', false, ShapeBpmnSubProcessKind.EMBEDDED], + ['event', true, ShapeBpmnSubProcessKind.EVENT], + ]).describe('parse bpmn as json for %s sub-process', (bpmnSubProcessKind: string, triggeredByEvent: boolean, expectedShapeBpmnSubProcessKind: ShapeBpmnSubProcessKind) => { + each([ + ['expanded', true], + ['collapsed', false], + ]).describe(`parse bpmn as json for %s ${bpmnSubProcessKind} sub-process`, (expandedKind: string, isExpanded: boolean) => { + const processWithSubProcessAsObject = {} as TProcess; + processWithSubProcessAsObject['subProcess'] = { + id: `sub-process_id_0`, + name: `sub-process name`, + triggeredByEvent: triggeredByEvent, + }; + + it.each([ + ['object', processWithSubProcessAsObject], + ['array', [processWithSubProcessAsObject]], + ])( + `should convert as Shape, when a ${expandedKind} ${bpmnSubProcessKind} sub-process is an attribute (as object) of 'process' (as %s)`, + (title: string, processJson: TProcess) => { + const json = { + definitions: { + targetNamespace: '', + process: processJson, + BPMNDiagram: { + name: 'process 0', + BPMNPlane: { + BPMNShape: { + id: `shape_sub-process_id_0`, + bpmnElement: `sub-process_id_0`, + Bounds: { x: 362, y: 232, width: 36, height: 45 }, + isExpanded: isExpanded, + }, + }, + }, + }, + }; + + const model = parseJsonAndExpectOnlySubProcess(json, expectedShapeBpmnSubProcessKind, 1); + + verifyShape(model.flowNodes[0], { + shapeId: 'shape_sub-process_id_0', + bpmnElementId: 'sub-process_id_0', + bpmnElementName: 'sub-process name', + bpmnElementKind: ShapeBpmnElementKind.SUB_PROCESS, + bounds: { + x: 362, + y: 232, + width: 36, + height: 45, + }, + isExpanded: isExpanded, + }); + }, + ); + }); + + it(`should convert as Shape, when a ${bpmnSubProcessKind} sub-process (with/without name & isExpanded) is an attribute (as array) of 'process'`, () => { + const json = { + definitions: { + targetNamespace: '', + process: { + subProcess: [ + { + id: 'sub-process_id_0', + name: 'sub-process name', + triggeredByEvent: triggeredByEvent, + }, + { + id: 'sub-process_id_1', + triggeredByEvent: triggeredByEvent, + }, + ], + }, + BPMNDiagram: { + name: 'process 0', + BPMNPlane: { + BPMNShape: [ + { + id: 'shape_sub-process_id_0', + bpmnElement: 'sub-process_id_0', + Bounds: { x: 362, y: 232, width: 36, height: 45 }, + isExpanded: false, + }, + { + id: 'shape_sub-process_id_1', + bpmnElement: 'sub-process_id_1', + Bounds: { x: 365, y: 235, width: 35, height: 46 }, + }, + ], + }, + }, + }, + }; + + const model = parseJsonAndExpectOnlySubProcess(json, expectedShapeBpmnSubProcessKind, 2); + + verifyShape(model.flowNodes[0], { + shapeId: 'shape_sub-process_id_0', + bpmnElementId: 'sub-process_id_0', + bpmnElementName: 'sub-process name', + bpmnElementKind: ShapeBpmnElementKind.SUB_PROCESS, + bounds: { + x: 362, + y: 232, + width: 36, + height: 45, + }, + isExpanded: false, + }); + verifyShape(model.flowNodes[1], { + shapeId: 'shape_sub-process_id_1', + bpmnElementId: 'sub-process_id_1', + bpmnElementName: undefined, + bpmnElementKind: ShapeBpmnElementKind.SUB_PROCESS, + bounds: { + x: 365, + y: 235, + width: 35, + height: 46, + }, + isExpanded: false, + }); + }); + + if (expectedShapeBpmnSubProcessKind === ShapeBpmnSubProcessKind.EMBEDDED) { + it(`should convert as Shape, when a embedded sub-process (with/without triggeredByEvent) is an attribute (as object) of 'process'`, () => { + const json = { + definitions: { + targetNamespace: '', + process: { + subProcess: { + id: 'sub-process_id_1', + }, + }, + BPMNDiagram: { + name: 'process 0', + BPMNPlane: { + BPMNShape: { + id: 'shape_sub-process_id_1', + bpmnElement: 'sub-process_id_1', + Bounds: { x: 365, y: 235, width: 35, height: 46 }, + }, + }, + }, + }, + }; + + const model = parseJsonAndExpectOnlySubProcess(json, expectedShapeBpmnSubProcessKind, 1); + + verifyShape(model.flowNodes[0], { + shapeId: 'shape_sub-process_id_1', + bpmnElementId: 'sub-process_id_1', + bpmnElementName: undefined, + bpmnElementKind: ShapeBpmnElementKind.SUB_PROCESS, + bounds: { + x: 365, + y: 235, + width: 35, + height: 46, + }, + isExpanded: false, + }); + }); + } + }); +}); diff --git a/test/unit/component/parser/json/BpmnJsonParser.text.annotation.test.ts b/test/unit/component/parser/json/BpmnJsonParser.text.annotation.test.ts index c1c1ec04be..32828d6f92 100644 --- a/test/unit/component/parser/json/BpmnJsonParser.text.annotation.test.ts +++ b/test/unit/component/parser/json/BpmnJsonParser.text.annotation.test.ts @@ -15,76 +15,30 @@ */ import { ShapeBpmnElementKind } from '../../../../../src/model/bpmn/shape/ShapeBpmnElementKind'; import { parseJsonAndExpectOnlyFlowNodes, verifyShape } from './JsonTestUtils'; +import { TProcess } from '../../../../../src/component/parser/xml/bpmn-json-model/baseElement/rootElement/rootElement'; describe('parse bpmn as json for text annotation', () => { - it('json containing one process with a text annotation', () => { - const json = { - definitions: { - targetNamespace: '', - process: { - textAnnotation: { - id: 'TextAnnotation_01', - text: 'Task Annotation', - }, - }, - BPMNDiagram: { - name: 'process 0', - BPMNPlane: { - BPMNShape: { - id: 'TextAnnotation_01_di', - bpmnElement: 'TextAnnotation_01', - Bounds: { - x: 430, - y: 160, - width: 100, - height: 30, - }, - }, - }, - }, - }, - }; - - const model = parseJsonAndExpectOnlyFlowNodes(json, 1); - - verifyShape(model.flowNodes[0], { - shapeId: 'TextAnnotation_01_di', - bpmnElementId: 'TextAnnotation_01', - bpmnElementName: 'Task Annotation', - bpmnElementKind: ShapeBpmnElementKind.TEXT_ANNOTATION, - bounds: { - x: 430, - y: 160, - width: 100, - height: 30, - }, - }); - }); + const processWithArtifactAsObject = {} as TProcess; + processWithArtifactAsObject['textAnnotation'] = { + id: `textAnnotation_id_0`, + text: `textAnnotation name`, + }; - it('json containing one process declared as array with a single text annotation', () => { + it.each([ + ['object', processWithArtifactAsObject], + ['array', [processWithArtifactAsObject]], + ])(`should convert as Shape, when a text annotation is an attribute (as object) of 'process' (as %s)`, (title: string, processJson: TProcess) => { const json = { definitions: { targetNamespace: '', - process: [ - { - textAnnotation: { - id: 'TextAnnotation_01', - text: 'Task Annotation', - }, - }, - ], + process: processJson, BPMNDiagram: { name: 'process 0', BPMNPlane: { BPMNShape: { - id: 'TextAnnotation_01_di', - bpmnElement: 'TextAnnotation_01', - Bounds: { - x: 430, - y: 160, - width: 100, - height: 30, - }, + id: `shape_textAnnotation_id_0`, + bpmnElement: `textAnnotation_id_0`, + Bounds: { x: 362, y: 232, width: 36, height: 45 }, }, }, }, @@ -94,20 +48,20 @@ describe('parse bpmn as json for text annotation', () => { const model = parseJsonAndExpectOnlyFlowNodes(json, 1); verifyShape(model.flowNodes[0], { - shapeId: 'TextAnnotation_01_di', - bpmnElementId: 'TextAnnotation_01', - bpmnElementName: 'Task Annotation', + shapeId: `shape_textAnnotation_id_0`, + bpmnElementId: `textAnnotation_id_0`, + bpmnElementName: `textAnnotation name`, bpmnElementKind: ShapeBpmnElementKind.TEXT_ANNOTATION, bounds: { - x: 430, - y: 160, - width: 100, - height: 30, + x: 362, + y: 232, + width: 36, + height: 45, }, }); }); - it('json containing one process with an array of text annotations with text & without text', () => { + it(`should convert as Shape, when a text annotation (with/without text) is an attribute (as array) of 'process'`, () => { const json = { definitions: { targetNamespace: '',