Skip to content

Commit

Permalink
[REFACTOR] Unit json test: Replace some tests by test templates (#439)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
csouchet authored Jul 23, 2020
1 parent 081e96e commit 7b9cf43
Show file tree
Hide file tree
Showing 15 changed files with 378 additions and 996 deletions.
21 changes: 4 additions & 17 deletions test/unit/component/parser/json/BpmnJsonParser.association.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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: '',
Expand Down Expand Up @@ -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: '',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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`,
Expand Down
165 changes: 0 additions & 165 deletions test/unit/component/parser/json/BpmnJsonParser.call.activity.test.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -128,49 +132,48 @@ 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 },
},
],
},
},
},
};
(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,
Expand All @@ -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,
Expand Down
Loading

0 comments on commit 7b9cf43

Please sign in to comment.