Skip to content

Commit

Permalink
simplify the initialization of the json to set as parameter of the Js…
Browse files Browse the repository at this point in the history
…onParser in the unit tests
  • Loading branch information
csouchet committed Aug 22, 2023
1 parent b0ad5fa commit cd83406
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 69 deletions.
76 changes: 23 additions & 53 deletions test/unit/component/parser/json/BpmnJsonParser.flowNode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand Down Expand Up @@ -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: {
Expand All @@ -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);

Expand Down Expand Up @@ -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: {
Expand All @@ -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);

Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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',
Expand All @@ -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);

Expand All @@ -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: {
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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',
Expand All @@ -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);

Expand Down
4 changes: 1 addition & 3 deletions test/unit/component/parser/json/BpmnJsonParser.label.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand All @@ -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',
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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',
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down Expand Up @@ -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',
Expand All @@ -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);

Expand Down

0 comments on commit cd83406

Please sign in to comment.