Skip to content

Commit

Permalink
Convert 'expectModelContainsLane' in Jest extension 'toBeLane'
Browse files Browse the repository at this point in the history
  • Loading branch information
csouchet committed Oct 16, 2020
1 parent 872ee0f commit 3e1fe5a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
10 changes: 3 additions & 7 deletions test/e2e/ExpectModelUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
toBeBoundaryEvent,
toBeSubProcess,
toBePool,
toBeLane,
} from './matchers';

declare global {
Expand Down Expand Up @@ -69,6 +70,7 @@ declare global {
toBeBoundaryEvent(modelElement: ExpectedBoundaryEventModelElement): R;
toBeSubProcess(modelElement: ExpectedSubProcessModelElement): R;
toBePool(modelElement: ExpectedShapeModelElement): R;
toBeLane(modelElement: ExpectedShapeModelElement): R;
}
}
}
Expand Down Expand Up @@ -96,6 +98,7 @@ expect.extend({
toBeBoundaryEvent,
toBeSubProcess,
toBePool,
toBeLane,
});

export interface ExpectedCellWithGeometry {
Expand Down Expand Up @@ -163,10 +166,3 @@ export const bpmnVisualization = new BpmnVisualization(null);
export function getDefaultParentId(): string {
return bpmnVisualization.graph.getDefaultParent().id;
}

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

const mxCell = bpmnVisualization.graph.model.getCell(cellId);
expect(mxCell.style).toContain(`${mxConstants.STYLE_HORIZONTAL}=${modelElement.isHorizontal ? '0' : '1'}`);
}
1 change: 1 addition & 0 deletions test/e2e/matchers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ export {
toBeBoundaryEvent,
toBeSubProcess,
toBePool,
toBeLane,
} from './toBeShape';
export { toBeCell, toBeCellWithParentAndGeometry } from './toBeCell';
5 changes: 5 additions & 0 deletions test/e2e/matchers/toBeShape/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ export function toBePool(this: MatcherContext, received: string, expected: Expec
return buildShapeMatcher('toBePool', this, received, { ...expected, kind: ShapeBpmnElementKind.POOL, styleShape: mxConstants.SHAPE_SWIMLANE, isHorizontal });
}

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

export function toBeCallActivity(this: MatcherContext, received: string, expected: ExpectedShapeModelElement): CustomMatcherResult {
return buildCellMatcher(
'toBeCallActivity',
Expand Down
20 changes: 10 additions & 10 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 } from './ExpectModelUtils';
import { bpmnVisualization, ExpectedShapeModelElement } from './ExpectModelUtils';

describe('mxGraph model', () => {
it('bpmn elements should be available in the mxGraph model', async () => {
Expand All @@ -43,10 +43,10 @@ describe('mxGraph model', () => {
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' });
expectModelContainsLane('lane_4_1_1_id', { ...minimalPoolModelElement, label: 'Child Lane 1', parentId: 'lane_4_1_id' });
expectModelContainsLane('lane_4_1_2_id', { ...minimalPoolModelElement, label: 'Child Lane 2', parentId: 'lane_4_1_id' });
expectModelContainsLane('lane_4_2_id', { ...minimalPoolModelElement, label: 'Solo Lane', parentId: 'participant_4_id' });
expect('lane_4_1_id').toBeLane({ ...minimalPoolModelElement, label: 'Lane with child lanes', parentId: 'participant_4_id' });
expect('lane_4_1_1_id').toBeLane({ ...minimalPoolModelElement, label: 'Child Lane 1', parentId: 'lane_4_1_id' });
expect('lane_4_1_2_id').toBeLane({ ...minimalPoolModelElement, label: 'Child Lane 2', parentId: 'lane_4_1_id' });
expect('lane_4_2_id').toBeLane({ ...minimalPoolModelElement, label: 'Solo Lane', parentId: 'participant_4_id' });

// start event
expect('start_event_none_id').toBeStartEvent({
Expand Down Expand Up @@ -1049,10 +1049,10 @@ describe('mxGraph model', () => {
expect('Participant_Vertical_With_Lanes').toBePool({ ...minimalPoolModelElement, label: 'Vertical Pool With Lanes' });

// lane
expectModelContainsLane('Lane_Vertical_3', { ...minimalPoolModelElement, parentId: 'Participant_Vertical_With_Lanes' });
expectModelContainsLane('Lane_Vertical_1', { ...minimalPoolModelElement, label: 'Lane', parentId: 'Participant_Vertical_With_Lanes' });
expectModelContainsLane('Lane_Vertical_With_Sub_Lane', { ...minimalPoolModelElement, label: 'Lane with Sub-Lanes', parentId: 'Participant_Vertical_With_Lanes' });
expectModelContainsLane('SubLane_Vertical_1', { ...minimalPoolModelElement, label: 'Sub-Lane 1', parentId: 'Lane_Vertical_With_Sub_Lane' });
expectModelContainsLane('SubLane_Vertical_2', { ...minimalPoolModelElement, label: 'Sub-Lane 2', parentId: 'Lane_Vertical_With_Sub_Lane' });
expect('Lane_Vertical_3').toBeLane({ ...minimalPoolModelElement, parentId: 'Participant_Vertical_With_Lanes' });
expect('Lane_Vertical_1').toBeLane({ ...minimalPoolModelElement, label: 'Lane', parentId: 'Participant_Vertical_With_Lanes' });
expect('Lane_Vertical_With_Sub_Lane').toBeLane({ ...minimalPoolModelElement, label: 'Lane with Sub-Lanes', parentId: 'Participant_Vertical_With_Lanes' });
expect('SubLane_Vertical_1').toBeLane({ ...minimalPoolModelElement, label: 'Sub-Lane 1', parentId: 'Lane_Vertical_With_Sub_Lane' });
expect('SubLane_Vertical_2').toBeLane({ ...minimalPoolModelElement, label: 'Sub-Lane 2', parentId: 'Lane_Vertical_With_Sub_Lane' });
});
});

0 comments on commit 3e1fe5a

Please sign in to comment.