From 5f1a8939ec6f77363fdc888b1506c7a1c28e2ac3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Souchet=20C=C3=A9line?= Date: Mon, 21 Aug 2023 15:46:35 +0200 Subject: [PATCH] simplify the initialization of the json to set as parameter of the JsonParser in the unit tests --- .../json/BpmnJsonParser.flowNode.test.ts | 76 ++++++------------- .../json/BpmnJsonParser.label.bounds.test.ts | 8 +- .../json/BpmnJsonParser.label.font.test.ts | 3 +- .../parser/json/BpmnJsonParser.label.test.ts | 4 +- ...sonParser.sequenceFlow.conditional.test.ts | 7 +- ...pmnJsonParser.sequenceFlow.default.test.ts | 3 +- 6 files changed, 32 insertions(+), 69 deletions(-) diff --git a/test/unit/component/parser/json/BpmnJsonParser.flowNode.test.ts b/test/unit/component/parser/json/BpmnJsonParser.flowNode.test.ts index 811974aabf..ad97390414 100644 --- a/test/unit/component/parser/json/BpmnJsonParser.flowNode.test.ts +++ b/test/unit/component/parser/json/BpmnJsonParser.flowNode.test.ts @@ -39,16 +39,17 @@ describe.each([ ['eventBasedGateway', ShapeBpmnElementKind.GATEWAY_EVENT_BASED], ['complexGateway', ShapeBpmnElementKind.GATEWAY_COMPLEX], ])('parse bpmn as json for %s', (bpmnKind: string, expectedShapeBpmnElementKind: ShapeBpmnElementKind) => { - const processWithFlowNodeAsObject = {} as TProcess; - processWithFlowNodeAsObject[`${bpmnKind}`] = { - id: `${bpmnKind}_id_0`, - name: `${bpmnKind} name`, + const processWithFlowNodeAsObject: TProcess = { + [bpmnKind]: { + id: `${bpmnKind}_id_0`, + name: `${bpmnKind} name`, + }, }; it.each([ ['object', processWithFlowNodeAsObject], ['array', [processWithFlowNodeAsObject]], - ])(`should convert as Shape, when a ${bpmnKind} is an attribute (as object) of 'process' (as %s)`, (title: string, processJson: TProcess) => { + ])(`should convert as Shape, when a ${bpmnKind} is an attribute (as object) of 'process' (as %s)`, (title: string, processJson: TProcess | TProcess[]) => { const json: BpmnJsonModel = { definitions: { targetNamespace: '', @@ -81,7 +82,9 @@ describe.each([ const json: BpmnJsonModel = { definitions: { targetNamespace: '', - process: {}, + process: { + [bpmnKind]: [{ id: `${bpmnKind}_id_0`, name: `${bpmnKind} name` }, { id: `${bpmnKind}_id_1` }], + }, BPMNDiagram: { name: 'process 0', BPMNPlane: { @@ -101,15 +104,6 @@ describe.each([ }, }, }; - (json.definitions.process as TProcess)[`${bpmnKind}`] = [ - { - id: `${bpmnKind}_id_0`, - name: `${bpmnKind} name`, - }, - { - id: `${bpmnKind}_id_1`, - }, - ]; const model = parseJsonAndExpectOnlyFlowNodes(json, 2); @@ -144,7 +138,9 @@ describe.each([ const json: BpmnJsonModel = { definitions: { targetNamespace: '', - process: {}, + process: { + [bpmnKind]: [{ id: `${bpmnKind}_id_0` }, { id: `${bpmnKind}_id_1`, instantiate: true }], + }, BPMNDiagram: { name: 'process 0', BPMNPlane: { @@ -164,15 +160,6 @@ describe.each([ }, }, }; - (json.definitions.process as TProcess)[`${bpmnKind}`] = [ - { - id: `${bpmnKind}_id_0`, - }, - { - id: `${bpmnKind}_id_1`, - instantiate: true, - }, - ]; const model = parseJsonAndExpectOnlyFlowNodes(json, 2); @@ -211,7 +198,17 @@ describe.each([ const json: BpmnJsonModel = { definitions: { targetNamespace: '', - process: {}, + process: { + [bpmnKind]: [ + { id: `${bpmnKind}_id_1` }, + { id: `${bpmnKind}_id_2`, eventGatewayType: 'Exclusive' }, + // forbidden by the BPMN spec, only valid when 'instantiate: true' + { id: `${bpmnKind}_id_3`, eventGatewayType: 'Parallel' }, + { id: `${bpmnKind}_id_11`, instantiate: true }, + { id: `${bpmnKind}_id_12`, instantiate: true, eventGatewayType: 'Exclusive' }, + { id: `${bpmnKind}_id_13`, instantiate: true, eventGatewayType: 'Parallel' }, + ], + }, BPMNDiagram: { name: 'process 0', BPMNPlane: { @@ -251,33 +248,6 @@ describe.each([ }, }, }; - (json.definitions.process as TProcess)[`${bpmnKind}`] = [ - { - id: `${bpmnKind}_id_1`, - }, - { - id: `${bpmnKind}_id_2`, - eventGatewayType: 'Exclusive', - }, - { - id: `${bpmnKind}_id_3`, - eventGatewayType: 'Parallel', // forbidden by the BPMN spec, only valid when 'instantiate: true' - }, - { - id: `${bpmnKind}_id_11`, - instantiate: true, - }, - { - id: `${bpmnKind}_id_12`, - instantiate: true, - eventGatewayType: 'Exclusive', - }, - { - id: `${bpmnKind}_id_13`, - instantiate: true, - eventGatewayType: 'Parallel', - }, - ]; const model = parseJsonAndExpectOnlyFlowNodes(json, 6); 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 15e84ce6f6..2344c5f00d 100644 --- a/test/unit/component/parser/json/BpmnJsonParser.label.bounds.test.ts +++ b/test/unit/component/parser/json/BpmnJsonParser.label.bounds.test.ts @@ -17,7 +17,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -import type { TProcess } from '@lib/model/bpmn/json/baseElement/rootElement/rootElement'; import type { BpmnJsonModel } from '@lib/model/bpmn/json/BPMN20'; import { parseJsonAndExpectOnlyEdges, parseJsonAndExpectOnlyFlowNodes, verifyLabelBounds } from '../../../helpers/JsonTestUtils'; import { shapeBpmnElementKindForLabelTests } from '../../../helpers/TestUtils'; @@ -30,6 +29,7 @@ describe('parse bpmn as json for label bounds', () => { targetNamespace: '', process: { id: 'Process_1', + [sourceKind]: { id: 'source_id_0', name: `${sourceKind}_id_0` }, }, BPMNDiagram: { id: 'BpmnDiagram_1', @@ -48,7 +48,6 @@ describe('parse bpmn as json for label bounds', () => { }, }, }; - (json.definitions.process as TProcess)[`${sourceKind}`] = { id: 'source_id_0', name: `${sourceKind}_id_0` }; const model = parseJsonAndExpectOnlyFlowNodes(json, 1); @@ -59,7 +58,9 @@ describe('parse bpmn as json for label bounds', () => { const json: BpmnJsonModel = { definitions: { targetNamespace: '', - process: {}, + process: { + [sourceKind]: { id: 'source_id_0', name: `${sourceKind}_id_0` }, + }, BPMNDiagram: { id: 'BpmnDiagram_1', BPMNPlane: { @@ -76,7 +77,6 @@ describe('parse bpmn as json for label bounds', () => { }, }, }; - (json.definitions.process as TProcess)[`${sourceKind}`] = { id: 'source_id_0', name: `${sourceKind}_id_0` }; const model = parseJsonAndExpectOnlyFlowNodes(json, 1); 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 f6a7783245..4115c01823 100644 --- a/test/unit/component/parser/json/BpmnJsonParser.label.font.test.ts +++ b/test/unit/component/parser/json/BpmnJsonParser.label.font.test.ts @@ -21,7 +21,6 @@ import type { BpmnJsonModel } from '@lib/model/bpmn/json/BPMN20'; import { expectAsWarning, parseJsonAndExpectOnlyEdges, parseJsonAndExpectOnlyFlowNodes, parsingMessageCollector, verifyLabelFont } from '../../../helpers/JsonTestUtils'; import { shapeBpmnElementKindForLabelTests } from '../../../helpers/TestUtils'; -import type { TProcess } from '@lib/model/bpmn/json/baseElement/rootElement/rootElement'; import { LabelStyleMissingFontWarning } from '@lib/component/parser/json/warnings'; function expectMissingFontWarning(shapeOrEdgeId: string, labelStyleId: string): void { @@ -39,6 +38,7 @@ describe('parse bpmn as json for label font', () => { targetNamespace: '', process: { id: 'Process_1', + [sourceKind]: { id: 'source_id_0', name: `${sourceKind}_id_0` }, }, BPMNDiagram: { id: 'BpmnDiagram_1', @@ -64,7 +64,6 @@ describe('parse bpmn as json for label font', () => { }, }, }; - (json.definitions.process as TProcess)[`${sourceKind}`] = { id: 'source_id_0', name: `${sourceKind}_id_0` }; const model = parseJsonAndExpectOnlyFlowNodes(json, 1); diff --git a/test/unit/component/parser/json/BpmnJsonParser.label.test.ts b/test/unit/component/parser/json/BpmnJsonParser.label.test.ts index 77ec329b51..b1cbcf408f 100644 --- a/test/unit/component/parser/json/BpmnJsonParser.label.test.ts +++ b/test/unit/component/parser/json/BpmnJsonParser.label.test.ts @@ -21,8 +21,6 @@ import type { BpmnJsonModel } from '@lib/model/bpmn/json/BPMN20'; import { parseJsonAndExpectOnlyEdges, parseJsonAndExpectOnlyFlowNodes } from '../../../helpers/JsonTestUtils'; import { shapeBpmnElementKindForLabelTests } from '../../../helpers/TestUtils'; -import type { TProcess } from '@lib/model/bpmn/json/baseElement/rootElement/rootElement'; - describe('parse bpmn as json for label', () => { it.each(shapeBpmnElementKindForLabelTests)( "should convert as Shape without Label, when a BPMNShape (attached to %s & with empty BPMNLabel) is an attribute (as object) of 'BPMNPlane' (as object)", @@ -32,6 +30,7 @@ describe('parse bpmn as json for label', () => { targetNamespace: '', process: { id: 'Process_1', + [sourceKind]: { id: 'source_id_0', name: `${sourceKind}_id_0` }, }, BPMNDiagram: { id: 'BpmnDiagram_1', @@ -47,7 +46,6 @@ describe('parse bpmn as json for label', () => { }, }, }; - (json.definitions.process as TProcess)[`${sourceKind}`] = { id: 'source_id_0', name: `${sourceKind}_id_0` }; const model = parseJsonAndExpectOnlyFlowNodes(json, 1); 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 6e046bd338..4a1c254a85 100644 --- a/test/unit/component/parser/json/BpmnJsonParser.sequenceFlow.conditional.test.ts +++ b/test/unit/component/parser/json/BpmnJsonParser.sequenceFlow.conditional.test.ts @@ -19,8 +19,6 @@ import { parseJsonAndExpectOnlyEdgesAndFlowNodes } from '../../../helpers/JsonTe import { verifyEdge } from '../../../helpers/bpmn-model-expect'; import { SequenceFlowKind } from '@lib/model/bpmn/internal'; -import type { TProcess } from '@lib/model/bpmn/json/baseElement/rootElement/rootElement'; -import type { TSequenceFlow } from '@lib/model/bpmn/json/baseElement/flowElement'; import { Waypoint } from '@lib/model/bpmn/internal/edge/edge'; describe('parse bpmn as json for conditional sequence flow', () => { @@ -52,8 +50,10 @@ describe('parse bpmn as json for conditional sequence flow', () => { targetRef: 'targetRef_RLk', conditionExpression: { evaluatesToTypeRef: 'java:java.lang.Boolean', + '#text': '"Contract to be written".equals(loanRequested.status)', }, }, + [sourceKind]: { id: 'source_id_0' }, }, BPMNDiagram: { id: 'BpmnDiagram_1', @@ -73,9 +73,6 @@ describe('parse bpmn as json for conditional sequence flow', () => { }, }, }; - const process = json.definitions.process as TProcess; - process[`${sourceKind}`] = { id: 'source_id_0' }; - (process.sequenceFlow as TSequenceFlow).conditionExpression['#text'] = '"Contract to be written".equals(loanRequested.status)'; const model = parseJsonAndExpectOnlyEdgesAndFlowNodes(json, 1, 1); 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 c1d6793d90..c29e927046 100644 --- a/test/unit/component/parser/json/BpmnJsonParser.sequenceFlow.default.test.ts +++ b/test/unit/component/parser/json/BpmnJsonParser.sequenceFlow.default.test.ts @@ -20,7 +20,6 @@ import { verifyEdge } from '../../../helpers/bpmn-model-expect'; import { SequenceFlowKind } from '@lib/model/bpmn/internal'; import { Waypoint } from '@lib/model/bpmn/internal/edge/edge'; -import type { TProcess } from '@lib/model/bpmn/json/baseElement/rootElement/rootElement'; describe('parse bpmn as json for default sequence flow', () => { it.each([ @@ -48,6 +47,7 @@ describe('parse bpmn as json for default sequence flow', () => { sourceRef: 'source_id_0', targetRef: 'targetRef_RLk', }, + [sourceKind]: { id: 'source_id_0', default: 'sequenceFlow_id_0' }, }, BPMNDiagram: { id: 'BpmnDiagram_1', @@ -67,7 +67,6 @@ describe('parse bpmn as json for default sequence flow', () => { }, }, }; - (json.definitions.process as TProcess)[`${sourceKind}`] = { id: 'source_id_0', default: 'sequenceFlow_id_0' }; const model = parseJsonAndExpectOnlyEdgesAndFlowNodes(json, 1, 1);