Skip to content

Commit

Permalink
[TEST] Introduce 'toBeCallActivity' Jest extension (#754)
Browse files Browse the repository at this point in the history
  • Loading branch information
csouchet authored Oct 14, 2020
1 parent 1e4c0fb commit 8a35e75
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 37 deletions.
6 changes: 4 additions & 2 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, toBeSequenceFlow, toBeMessageFlow, toBeAssociationFlow, toBeShape } from './matchers';
import { toBeCell, withGeometry, withFont, toBeSequenceFlow, toBeMessageFlow, toBeAssociationFlow, toBeShape, toBeCallActivity } from './matchers';

declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
Expand All @@ -31,6 +31,7 @@ declare global {
toBeMessageFlow(modelElement: ExpectedEdgeModelElement): R;
toBeAssociationFlow(modelElement: ExpectedEdgeModelElement): R;
toBeShape(modelElement: ExpectedShapeModelElement): R;
toBeCallActivity(modelElement: ExpectedShapeModelElement): R;
}
}
}
Expand All @@ -43,6 +44,7 @@ expect.extend({
toBeMessageFlow,
toBeAssociationFlow,
toBeShape,
toBeCallActivity,
});

export interface ExpectedFont {
Expand All @@ -56,7 +58,7 @@ export interface ExpectedFont {

export interface ExpectedShapeModelElement {
label?: string;
kind: ShapeBpmnElementKind;
kind?: ShapeBpmnElementKind;
font?: ExpectedFont;
parentId?: string;
/** Only needed when the BPMN shape doesn't exist yet (use an arbitrary shape until the final render is implemented) */
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 @@ -14,7 +14,7 @@
* limitations under the License.
*/
export { toBeSequenceFlow, toBeMessageFlow, toBeAssociationFlow } from './toBeEdge';
export { toBeShape } from './toBeShape';
export { toBeShape, toBeCallActivity } from './toBeShape';
export { toBeCell } from './toBeCell';
export { withGeometry } from './withGeometry';
export { withFont } from './withFont';
33 changes: 15 additions & 18 deletions test/e2e/matchers/toBeCell/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,23 @@ export function buildCellMatcher<R>(

const cell = getCell(received);
if (!cell) {
const pass = !matcherContext.isNot;
const message =
utils.matcherHint(matcherName, undefined, undefined, options) + '\n\n' + pass
? () => `${EXPECTED_LABEL}: ${cellKind} with id '${received}' not to be found`
: () => utils.printDiffOrStringify(expectedCell, undefined, `${EXPECTED_LABEL}: ${cellKind} with id '${expectedCell.id}'`, `${RECEIVED_LABEL}`, expand);
return { message, pass };
const message = (): string =>
utils.matcherHint(matcherName, undefined, undefined, options) +
'\n\n' +
utils.printDiffOrStringify(expectedCell, undefined, `${EXPECTED_LABEL}: ${cellKind} with id '${expectedCell.id}'`, `${RECEIVED_LABEL}`, expand);
return { message, pass: false };
}

const receivedCell: ExpectedCell = buildReceivedCell(cell);
const pass = matcherContext.equals(receivedCell, expectedCell, [utils.iterableEquality, utils.subsetEquality]);
const message =
utils.matcherHint(matcherName, undefined, undefined, options) + '\n\n' + pass
? () => `${EXPECTED_LABEL}: ${cellKind} with id '${received}' not to be found with the configuration:\n` + `${utils.printExpected(expectedCell)}`
: () =>
utils.printDiffOrStringify(
expectedCell,
receivedCell,
`${EXPECTED_LABEL}: ${cellKind} with id '${expectedCell.id}'`,
`${RECEIVED_LABEL}: ${cellKind} with id '${received}'`,
expand,
);
return { message, pass };
const messageEnd = pass
? `${EXPECTED_LABEL}: ${cellKind} with id '${received}' not to be found with the configuration:\n` + `${utils.printExpected(expectedCell)}`
: utils.printDiffOrStringify(
expectedCell,
receivedCell,
`${EXPECTED_LABEL}: ${cellKind} with id '${expectedCell.id}'`,
`${RECEIVED_LABEL}: ${cellKind} with id '${received}'`,
expand,
);
return { message: () => utils.matcherHint(matcherName, undefined, undefined, options) + '\n\n' + messageEnd, pass };
}
5 changes: 5 additions & 0 deletions test/e2e/matchers/toBeShape/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import MatcherContext = jest.MatcherContext;
import CustomMatcherResult = jest.CustomMatcherResult;
import { ExpectedShapeModelElement, getDefaultParentId } from '../../ExpectModelUtils';
import { buildCellMatcher } from '../toBeCell';
import { ShapeBpmnElementKind } from '../../../../src/model/bpmn/internal/shape';

function buildExpectedStateStyle(expectedModel: ExpectedShapeModelElement): ExpectedStateStyle {
const expectedStateStyle = buildCommonExpectedStateStyle(expectedModel);
Expand Down Expand Up @@ -60,3 +61,7 @@ function buildExpectedCell(id: string, expectedModel: ExpectedShapeModelElement)
export function toBeShape(this: MatcherContext, received: string, expected: ExpectedShapeModelElement): CustomMatcherResult {
return buildCellMatcher('toBeShape', this, received, expected, 'Shape', buildExpectedCell);
}

export function toBeCallActivity(this: MatcherContext, received: string, expected: ExpectedShapeModelElement): CustomMatcherResult {
return buildCellMatcher('toBeCallActivity', this, received, { ...expected, kind: ShapeBpmnElementKind.CALL_ACTIVITY }, 'Shape', buildExpectedCell);
}
24 changes: 8 additions & 16 deletions test/e2e/mxGraph.model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -682,55 +682,47 @@ describe('mxGraph model', () => {

// Call Activity calling process
// Expanded
expect('expanded_call_activity_id').toBeShape({
kind: ShapeBpmnElementKind.CALL_ACTIVITY,
expect('expanded_call_activity_id').toBeCallActivity({
label: 'Expanded Call Activity',
parentId: 'participant_1_id',
verticalAlign: 'top',
});
expect('expanded_call_activity_with_loop_id').toBeShape({
kind: ShapeBpmnElementKind.CALL_ACTIVITY,
expect('expanded_call_activity_with_loop_id').toBeCallActivity({
label: 'Expanded Call Activity With Loop',
markers: [ShapeBpmnMarkerKind.LOOP],
parentId: 'participant_1_id',
verticalAlign: 'top',
});
expect('expanded_call_activity_with_sequential_multi_instance_id').toBeShape({
kind: ShapeBpmnElementKind.CALL_ACTIVITY,
expect('expanded_call_activity_with_sequential_multi_instance_id').toBeCallActivity({
label: 'Expanded Call Activity With Sequential Multi-instance',
markers: [ShapeBpmnMarkerKind.MULTI_INSTANCE_SEQUENTIAL],
parentId: 'participant_1_id',
verticalAlign: 'top',
});
expect('expanded_call_activity_with_parallel_multi_instance_id').toBeShape({
kind: ShapeBpmnElementKind.CALL_ACTIVITY,
expect('expanded_call_activity_with_parallel_multi_instance_id').toBeCallActivity({
label: 'Expanded Call Activity With Parallel Multi-instance',
markers: [ShapeBpmnMarkerKind.MULTI_INSTANCE_PARALLEL],
parentId: 'participant_1_id',
verticalAlign: 'top',
});

// Collapsed
expect('collapsed_call_activity_id').toBeShape({
kind: ShapeBpmnElementKind.CALL_ACTIVITY,
expect('collapsed_call_activity_id').toBeCallActivity({
label: 'Collapsed Call Activity',
parentId: 'participant_1_id',
verticalAlign: 'top',
});
expect('collapsed_call_activity_with_loop_id').toBeShape({
kind: ShapeBpmnElementKind.CALL_ACTIVITY,
expect('collapsed_call_activity_with_loop_id').toBeCallActivity({
label: 'Collapsed Call Activity With Loop',
markers: [ShapeBpmnMarkerKind.LOOP, ShapeBpmnMarkerKind.EXPAND],
parentId: 'participant_1_id',
});
expect('collapsed_call_activity_with_sequential_multi_instance_id').toBeShape({
kind: ShapeBpmnElementKind.CALL_ACTIVITY,
expect('collapsed_call_activity_with_sequential_multi_instance_id').toBeCallActivity({
label: 'Collapsed Call Activity With Sequential Multi-instance',
markers: [ShapeBpmnMarkerKind.MULTI_INSTANCE_SEQUENTIAL, ShapeBpmnMarkerKind.EXPAND],
parentId: 'participant_1_id',
});
expect('collapsed_call_activity_with_parallel_multi_instance_id').toBeShape({
kind: ShapeBpmnElementKind.CALL_ACTIVITY,
expect('collapsed_call_activity_with_parallel_multi_instance_id').toBeCallActivity({
label: 'Collapsed Call Activity With Parallel Multi-instance',
markers: [ShapeBpmnMarkerKind.MULTI_INSTANCE_PARALLEL, ShapeBpmnMarkerKind.EXPAND],
parentId: 'participant_1_id',
Expand Down

0 comments on commit 8a35e75

Please sign in to comment.