From a952c38be7022ce488f7a6b19ab981d6cd9dbb86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9line=20Souchet?= Date: Wed, 14 Oct 2020 10:20:57 +0200 Subject: [PATCH] Convert 'expectModelContainsLane' in Jest extension 'toBeLane' --- test/e2e/ExpectModelUtils.ts | 10 +++------- test/e2e/matchers/index.ts | 1 + test/e2e/matchers/toBeShape/index.ts | 5 +++++ test/e2e/mxGraph.model.test.ts | 20 ++++++++++---------- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/test/e2e/ExpectModelUtils.ts b/test/e2e/ExpectModelUtils.ts index 20e7cc5b3e..bda3f80a5f 100644 --- a/test/e2e/ExpectModelUtils.ts +++ b/test/e2e/ExpectModelUtils.ts @@ -41,6 +41,7 @@ import { toBeBoundaryEvent, toBeSubProcess, toBePool, + toBeLane, } from './matchers'; declare global { @@ -69,6 +70,7 @@ declare global { toBeBoundaryEvent(modelElement: ExpectedBoundaryEventModelElement): R; toBeSubProcess(modelElement: ExpectedSubProcessModelElement): R; toBePool(modelElement: ExpectedShapeModelElement): R; + toBeLane(modelElement: ExpectedShapeModelElement): R; } } } @@ -96,6 +98,7 @@ expect.extend({ toBeBoundaryEvent, toBeSubProcess, toBePool, + toBeLane, }); export interface ExpectedCellWithGeometry { @@ -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'}`); -} diff --git a/test/e2e/matchers/index.ts b/test/e2e/matchers/index.ts index a0e0df9913..aef47e5f5e 100644 --- a/test/e2e/matchers/index.ts +++ b/test/e2e/matchers/index.ts @@ -32,5 +32,6 @@ export { toBeBoundaryEvent, toBeSubProcess, toBePool, + toBeLane, } from './toBeShape'; export { toBeCell, toBeCellWithParentAndGeometry } from './toBeCell'; diff --git a/test/e2e/matchers/toBeShape/index.ts b/test/e2e/matchers/toBeShape/index.ts index c11bb2b677..a74c4915a5 100644 --- a/test/e2e/matchers/toBeShape/index.ts +++ b/test/e2e/matchers/toBeShape/index.ts @@ -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', diff --git a/test/e2e/mxGraph.model.test.ts b/test/e2e/mxGraph.model.test.ts index ffcdb80ed0..227de4531d 100644 --- a/test/e2e/mxGraph.model.test.ts +++ b/test/e2e/mxGraph.model.test.ts @@ -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 () => { @@ -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({ @@ -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' }); }); });