Skip to content

Commit

Permalink
[TEST] Convert 'expectModelContainsMessageFlow' in Jest extension 'to…
Browse files Browse the repository at this point in the history
…BeMessageFlow' (#744)
  • Loading branch information
csouchet authored Oct 14, 2020
1 parent 5091204 commit ce3f62d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
8 changes: 3 additions & 5 deletions test/e2e/ExpectModelUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { FlowKind } from '../../src/model/bpmn/internal/edge/FlowKind';
import { MessageVisibleKind } from '../../src/model/bpmn/internal/edge/MessageVisibleKind';
import { SequenceFlowKind } from '../../src/model/bpmn/internal/edge/SequenceFlowKind';
import BpmnVisualization from '../../src/component/BpmnVisualization';
import { toBeCell, withGeometry, withFont, toBeEdge, toBeSequenceFlow } from './matchers';
import { toBeCell, withGeometry, withFont, toBeEdge, toBeSequenceFlow, toBeMessageFlow } from './matchers';

declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
Expand All @@ -29,6 +29,7 @@ declare global {
withFont(font: ExpectedFont): R;
toBeEdge(modelElement: ExpectedEdgeModelElement): R;
toBeSequenceFlow(modelElement: ExpectedSequenceFlowModelElement): R;
toBeMessageFlow(modelElement: ExpectedEdgeModelElement): R;
}
}
}
Expand All @@ -39,6 +40,7 @@ expect.extend({
withFont,
toBeEdge,
toBeSequenceFlow,
toBeMessageFlow,
});

export interface ExpectedFont {
Expand Down Expand Up @@ -131,10 +133,6 @@ export function expectModelContainsShape(cellId: string, modelElement: ExpectedS
return cell;
}

export function expectModelContainsMessageFlow(cellId: string, modelElement: ExpectedEdgeModelElement): void {
expect(cellId).toBeEdge({ ...modelElement, kind: FlowKind.MESSAGE_FLOW, startArrow: mxConstants.ARROW_OVAL, endArrow: 'blockThin' });
}

export function expectModelContainsAssociationFlow(cellId: string, modelElement: ExpectedEdgeModelElement): void {
expect(cellId).toBeEdge({ ...modelElement, kind: FlowKind.ASSOCIATION_FLOW });
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/matchers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export { toBeEdge, toBeSequenceFlow } from './toBeEdge';
export { toBeEdge, toBeSequenceFlow, toBeMessageFlow } from './toBeEdge';
export { toBeCell } from './toBeCell';
export { withGeometry } from './withGeometry';
export { withFont } from './withFont';
6 changes: 5 additions & 1 deletion test/e2e/matchers/toBeEdge/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ExpectedEdgeModelElement, ExpectedSequenceFlowModelElement } from '../../ExpectModelUtils';
import { buildExpectedCell, buildReceivedCell, getCell, EXPECTED_LABEL, RECEIVED_LABEL } from '../matcherUtils';
import MatcherContext = jest.MatcherContext;
import CustomMatcherResult = jest.CustomMatcherResult;
import { FlowKind } from '../../../../src/model/bpmn/internal/edge/FlowKind';
import { ExpectedEdgeModelElement, ExpectedSequenceFlowModelElement } from '../../ExpectModelUtils';

function buildEdgeMatcher(matcherName: string, matcherContext: MatcherContext, received: string, expected: ExpectedEdgeModelElement): CustomMatcherResult {
const options = {
Expand Down Expand Up @@ -65,3 +65,7 @@ export function toBeEdge(this: MatcherContext, received: string, expected: Expec
export function toBeSequenceFlow(this: MatcherContext, received: string, expected: ExpectedSequenceFlowModelElement): CustomMatcherResult {
return buildEdgeMatcher('toBeSequenceFlow', this, received, { ...expected, kind: FlowKind.SEQUENCE_FLOW, endArrow: 'blockThin' });
}

export function toBeMessageFlow(this: MatcherContext, received: string, expected: ExpectedEdgeModelElement): CustomMatcherResult {
return buildEdgeMatcher('toBeMessageFlow', this, received, { ...expected, kind: FlowKind.MESSAGE_FLOW, startArrow: mxConstants.ARROW_OVAL, endArrow: 'blockThin' });
}
7 changes: 3 additions & 4 deletions test/e2e/mxGraph.model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
expectModelContainsPool,
expectModelContainsShape,
expectModelContainsSubProcess,
expectModelContainsMessageFlow,
expectModelNotContainCell,
expectModelContainsCellWithGeometry,
getDefaultParentId,
Expand Down Expand Up @@ -816,17 +815,17 @@ describe('mxGraph model', () => {
});

// message flow
expectModelContainsMessageFlow('message_flow_initiating_message_id', {
expect('message_flow_initiating_message_id').toBeMessageFlow({
label: 'Message Flow with initiating message',
messageVisibleKind: MessageVisibleKind.INITIATING,
verticalAlign: 'bottom',
});
expectModelContainsMessageFlow('message_flow_non_initiating_message_id', {
expect('message_flow_non_initiating_message_id').toBeMessageFlow({
label: 'Message Flow with non-initiating message',
messageVisibleKind: MessageVisibleKind.NON_INITIATING,
verticalAlign: 'bottom',
});
expectModelContainsMessageFlow('message_flow_no_visible_id', { label: 'Message Flow without message', messageVisibleKind: MessageVisibleKind.NONE, verticalAlign: 'bottom' });
expect('message_flow_no_visible_id').toBeMessageFlow({ label: 'Message Flow without message', messageVisibleKind: MessageVisibleKind.NONE, verticalAlign: 'bottom' });

// association
expectModelContainsAssociationFlow('association_id', { kind: FlowKind.ASSOCIATION_FLOW, parentId: 'participant_1_id', verticalAlign: 'bottom' });
Expand Down

0 comments on commit ce3f62d

Please sign in to comment.