Skip to content

Commit

Permalink
[TEST] Convert 'expectModelContainsPool' in Jest extension 'toBePool' (
Browse files Browse the repository at this point in the history
  • Loading branch information
csouchet authored Oct 16, 2020
1 parent 06c6cf2 commit 872ee0f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
10 changes: 3 additions & 7 deletions test/e2e/ExpectModelUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
toBeIntermediateCatchEvent,
toBeBoundaryEvent,
toBeSubProcess,
toBePool,
} from './matchers';

declare global {
Expand Down Expand Up @@ -67,6 +68,7 @@ declare global {
toBeIntermediateCatchEvent(modelElement: ExpectedEventModelElement): R;
toBeBoundaryEvent(modelElement: ExpectedBoundaryEventModelElement): R;
toBeSubProcess(modelElement: ExpectedSubProcessModelElement): R;
toBePool(modelElement: ExpectedShapeModelElement): R;
}
}
}
Expand All @@ -93,6 +95,7 @@ expect.extend({
toBeIntermediateCatchEvent,
toBeBoundaryEvent,
toBeSubProcess,
toBePool,
});

export interface ExpectedCellWithGeometry {
Expand Down Expand Up @@ -161,13 +164,6 @@ export function getDefaultParentId(): string {
return bpmnVisualization.graph.getDefaultParent().id;
}

export function expectModelContainsPool(cellId: string, modelElement: ExpectedShapeModelElement): void {
expect(cellId).toBeShape({ ...modelElement, kind: ShapeBpmnElementKind.POOL, styleShape: mxConstants.SHAPE_SWIMLANE, verticalAlign: 'middle' });

const mxCell = bpmnVisualization.graph.model.getCell(cellId);
expect(mxCell.style).toContain(`${mxConstants.STYLE_HORIZONTAL}=${modelElement.isHorizontal ? '0' : '1'}`);
}

export function expectModelContainsLane(cellId: string, modelElement: ExpectedShapeModelElement): void {
expect(cellId).toBeShape({ ...modelElement, kind: ShapeBpmnElementKind.LANE, styleShape: mxConstants.SHAPE_SWIMLANE, verticalAlign: 'middle' });

Expand Down
1 change: 1 addition & 0 deletions test/e2e/matchers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ export {
toBeIntermediateCatchEvent,
toBeBoundaryEvent,
toBeSubProcess,
toBePool,
} from './toBeShape';
export { toBeCell, toBeCellWithParentAndGeometry } from './toBeCell';
2 changes: 2 additions & 0 deletions test/e2e/matchers/matcherUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface ExpectedStateStyle extends StyleMap {
endArrow?: string;
endSize?: number;
shape?: string;
horizontal?: number;
}

export interface ExpectedCell {
Expand Down Expand Up @@ -142,6 +143,7 @@ function buildReceivedStateStyle(cell: mxCell): ExpectedStateStyle {
expectedStateStyle.endSize = stateStyle.endSize;
} else {
expectedStateStyle.shape = stateStyle.shape;
expectedStateStyle.horizontal = stateStyle.horizontal;
}
return expectedStateStyle;
}
Expand Down
9 changes: 9 additions & 0 deletions test/e2e/matchers/toBeShape/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ function buildExpectedStateStyle(expectedModel: ExpectedShapeModelElement): Expe
expectedStateStyle.align = expectedModel.align ? expectedModel.align : 'center';
expectedStateStyle.strokeWidth = undefined;

if ('isHorizontal' in expectedModel) {
expectedStateStyle.horizontal = expectedModel.isHorizontal ? 0 : 1;
}

return expectedStateStyle;
}

Expand Down Expand Up @@ -83,6 +87,11 @@ export function toBeShape(this: MatcherContext, received: string, expected: Expe
return buildShapeMatcher('toBeShape', this, received, expected);
}

export function toBePool(this: MatcherContext, received: string, expected: ExpectedShapeModelElement): CustomMatcherResult {
const isHorizontal = 'isHorizontal' in expected ? expected.isHorizontal : true;
return buildShapeMatcher('toBePool', this, received, { ...expected, kind: ShapeBpmnElementKind.POOL, styleShape: mxConstants.SHAPE_SWIMLANE, isHorizontal });
}

export function toBeCallActivity(this: MatcherContext, received: string, expected: ExpectedShapeModelElement): CustomMatcherResult {
return buildCellMatcher(
'toBeCallActivity',
Expand Down
12 changes: 6 additions & 6 deletions test/e2e/mxGraph.model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { SequenceFlowKind } from '../../src/model/bpmn/internal/edge/SequenceFlo
import { MarkerIdentifier } from '../../src/bpmn-visualization';
import { MessageVisibleKind } from '../../src/model/bpmn/internal/edge/MessageVisibleKind';
import { readFileSync } from '../helpers/file-helper';
import { bpmnVisualization, ExpectedShapeModelElement, expectModelContainsLane, expectModelContainsPool } from './ExpectModelUtils';
import { bpmnVisualization, ExpectedShapeModelElement, expectModelContainsLane } from './ExpectModelUtils';

describe('mxGraph model', () => {
it('bpmn elements should be available in the mxGraph model', async () => {
Expand All @@ -37,10 +37,10 @@ describe('mxGraph model', () => {

// pool
const minimalPoolModelElement: ExpectedShapeModelElement = { kind: null, isHorizontal: true };
expectModelContainsPool('participant_1_id', { ...minimalPoolModelElement, label: 'Pool 1' });
expectModelContainsPool('participant_2_id', minimalPoolModelElement);
expectModelContainsPool('participant_3_id', { ...minimalPoolModelElement, label: 'Black Box Process' });
expectModelContainsPool('participant_4_id', { ...minimalPoolModelElement, label: 'Pool containing sublanes' });
expect('participant_1_id').toBePool({ ...minimalPoolModelElement, label: 'Pool 1' });
expect('participant_2_id').toBePool(minimalPoolModelElement);
expect('participant_3_id').toBePool({ ...minimalPoolModelElement, label: 'Black Box Process' });
expect('participant_4_id').toBePool({ ...minimalPoolModelElement, label: 'Pool containing sublanes' });

// lane
expectModelContainsLane('lane_4_1_id', { ...minimalPoolModelElement, label: 'Lane with child lanes', parentId: 'participant_4_id' });
Expand Down Expand Up @@ -1046,7 +1046,7 @@ describe('mxGraph model', () => {

// pool
const minimalPoolModelElement: ExpectedShapeModelElement = { kind: null, isHorizontal: false };
expectModelContainsPool('Participant_Vertical_With_Lanes', { ...minimalPoolModelElement, label: 'Vertical Pool With Lanes' });
expect('Participant_Vertical_With_Lanes').toBePool({ ...minimalPoolModelElement, label: 'Vertical Pool With Lanes' });

// lane
expectModelContainsLane('Lane_Vertical_3', { ...minimalPoolModelElement, parentId: 'Participant_Vertical_With_Lanes' });
Expand Down

0 comments on commit 872ee0f

Please sign in to comment.