Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: refactor JsonParser unit tests and type handling enhancements #2801

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/component/parser/json/converter/ProcessConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,8 @@ export default class ProcessConverter {
shapeBpmnElement = new ShapeBpmnElement(bpmnElement.id, name, kind, parentId, bpmnElement.instantiate);
}

// eslint-disable-next-line @typescript-eslint/ban-ts-comment -- We know that the 'default' field is not on all types, but it's already tested
// @ts-ignore
const defaultFlow = bpmnElement.default;
if (ShapeUtil.isWithDefaultSequenceFlow(kind) && defaultFlow) {
this.defaultSequenceFlowIds.push(defaultFlow);
if ('default' in bpmnElement && ShapeUtil.isWithDefaultSequenceFlow(kind)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: Nice!

this.defaultSequenceFlowIds.push(bpmnElement.default);
}

if (shapeBpmnElement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type { BuildProcessParameter } from '../../../helpers/JsonBuilder';
import { parseJsonAndExpectOnlyEdges } from '../../../helpers/JsonTestUtils';
import { verifyEdge } from '../../../helpers/bpmn-model-expect';

import type { BpmnJsonModel } from '@lib/model/bpmn/json/BPMN20';
import { Waypoint } from '@lib/model/bpmn/internal/edge/edge';

describe('parse bpmn as json for association', () => {
Expand Down Expand Up @@ -88,7 +89,7 @@ describe('parse bpmn as json for association', () => {
});

it('should convert as Edge, when BPMNDiagram is an array', () => {
const json = {
const json: BpmnJsonModel = {
definitions: {
targetNamespace: '',
process: processJsonAsObjectWithAssociationJsonAsObject,
Expand Down
4 changes: 3 additions & 1 deletion test/unit/component/parser/json/BpmnJsonParser.edge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ limitations under the License.
*/

import { expectAsWarning, parseJsonAndExpectOnlyWarnings, parsingMessageCollector } from '../../../helpers/JsonTestUtils';

import type { BpmnJsonModel } from '@lib/model/bpmn/json/BPMN20';
import { EdgeUnknownBpmnElementWarning } from '@lib/component/parser/json/warnings';

describe('parse bpmn as json for edges', () => {
// this also covers unsupported bpmn element types that are then not retrieved during the parsing
it('should not convert as Edge without related BPMN element', () => {
const json = {
const json: BpmnJsonModel = {
definitions: {
targetNamespace: '',
process: '',
Expand Down
84 changes: 27 additions & 57 deletions test/unit/component/parser/json/BpmnJsonParser.flowNode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { parseJsonAndExpectOnlyEdgesAndFlowNodes, parseJsonAndExpectOnlyFlowNode
import type { ExpectedShape } from '../../../helpers/bpmn-model-expect';
import { verifyShape } from '../../../helpers/bpmn-model-expect';

import type { BpmnJsonModel } from '@lib/model/bpmn/json/BPMN20';
import type { TProcess } from '@lib/model/bpmn/json/baseElement/rootElement/rootElement';
import { ShapeBpmnElementKind, ShapeBpmnEventBasedGatewayKind, ShapeUtil } from '@lib/model/bpmn/internal';
import type { ShapeBpmnEventBasedGateway } from '@lib/model/bpmn/internal/shape/ShapeBpmnElement';
Expand All @@ -38,17 +39,18 @@ 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) => {
const json = {
])(`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: '',
process: processJson,
Expand Down Expand Up @@ -77,10 +79,12 @@ describe.each([
});

it(`should convert as Shape, when a ${bpmnKind} (with/without name) is an attribute (as array) of 'process'`, () => {
const json = {
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 @@ -100,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 @@ -140,10 +135,12 @@ describe.each([

if (expectedShapeBpmnElementKind === ShapeBpmnElementKind.TASK_RECEIVE) {
it(`should convert as Shape, when a ${bpmnKind} (with/without instantiate) is an attribute (as array) of 'process'`, () => {
const json = {
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 @@ -163,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 @@ -207,10 +195,19 @@ describe.each([

if (expectedShapeBpmnElementKind === ShapeBpmnElementKind.GATEWAY_EVENT_BASED) {
it(`should convert as Shape, when a ${bpmnKind} (with/without instantiate) is an attribute (as array) of 'process'`, () => {
const json = {
const json: BpmnJsonModel = {
definitions: {
targetNamespace: '',
process: {},
process: {
[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' },
],
},
BPMNDiagram: {
name: 'process 0',
BPMNPlane: {
Expand Down Expand Up @@ -250,33 +247,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
12 changes: 7 additions & 5 deletions test/unit/component/parser/json/BpmnJsonParser.group.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ import {
parsingMessageCollector,
} from '../../../helpers/JsonTestUtils';
import { verifyShape } from '../../../helpers/bpmn-model-expect';

import type { BpmnJsonModel } from '@lib/model/bpmn/json/BPMN20';
import { ShapeBpmnElementKind } from '@lib/model/bpmn/internal';
import { GroupUnknownCategoryValueWarning, ShapeUnknownBpmnElementWarning } from '@lib/component/parser/json/warnings';

describe('parse bpmn as json for group', () => {
it('Single Group with label in process', () => {
const json = {
const json: BpmnJsonModel = {
definitions: {
targetNamespace: '',
process: {
Expand Down Expand Up @@ -78,7 +80,7 @@ describe('parse bpmn as json for group', () => {
});

it('Several Groups with or without label in process', () => {
const json = {
const json: BpmnJsonModel = {
definitions: {
targetNamespace: '',
process: {
Expand Down Expand Up @@ -165,7 +167,7 @@ describe('parse bpmn as json for group', () => {
});

it('Single Group with label in collaboration', () => {
const json = {
const json: BpmnJsonModel = {
definitions: {
targetNamespace: '',
collaboration: {
Expand Down Expand Up @@ -241,7 +243,7 @@ describe('parse bpmn as json for group', () => {

describe('Robustness', () => {
it('Single Group in process without matching categoryValueRef', () => {
const json = {
const json: BpmnJsonModel = {
definitions: {
targetNamespace: '',
process: {
Expand Down Expand Up @@ -284,7 +286,7 @@ describe('parse bpmn as json for group', () => {
}

it('Single Group in collaboration without matching categoryValueRef', () => {
const json = {
const json: BpmnJsonModel = {
definitions: {
targetNamespace: '',
collaboration: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@ 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 { parseJsonAndExpectOnlyEdges, parseJsonAndExpectOnlyFlowNodes, verifyLabelBounds } from '../../../helpers/JsonTestUtils';
import { shapeBpmnElementKindForLabelTests } from '../../../helpers/TestUtils';

import type { BpmnJsonModel } from '@lib/model/bpmn/json/BPMN20';

describe('parse bpmn as json for label bounds', () => {
describe.each(shapeBpmnElementKindForLabelTests)('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 = {
const json: BpmnJsonModel = {
definitions: {
targetNamespace: '',
process: {
id: 'Process_1',
[sourceKind]: { id: 'source_id_0', name: `${sourceKind}_id_0` },
},
BPMNDiagram: {
id: 'BpmnDiagram_1',
Expand All @@ -47,18 +49,19 @@ 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);

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 = {
const json: BpmnJsonModel = {
definitions: {
targetNamespace: '',
process: {},
process: {
[sourceKind]: { id: 'source_id_0', name: `${sourceKind}_id_0` },
},
BPMNDiagram: {
id: 'BpmnDiagram_1',
BPMNPlane: {
Expand All @@ -75,7 +78,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 @@ -84,7 +86,7 @@ describe('parse bpmn as json for label bounds', () => {
});

it(`should convert as Edge, when a BPMNEdge (with bounds with all attributes) is an attribute (as object) of 'BPMNPlane' (as object)`, () => {
const json = {
const json: BpmnJsonModel = {
definitions: {
targetNamespace: '',
process: {
Expand Down Expand Up @@ -118,7 +120,7 @@ describe('parse bpmn as json for label bounds', () => {
});

it(`should convert as Edge, when a BPMNEdge (without bounds) is an attribute (as object) of 'BPMNPlane' (as object)`, () => {
const json = {
const json: BpmnJsonModel = {
definitions: {
targetNamespace: '',
process: {
Expand Down
Loading