Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TEST] Update error message in e2e tests #689

Merged
merged 4 commits into from
Oct 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 32 additions & 9 deletions test/e2e/mxGraph.model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ import { FlowKind } from '../../src/model/bpmn/internal/edge/FlowKind';
import { MessageVisibleKind } from '../../src/model/bpmn/internal/edge/MessageVisibleKind';
import { readFileSync } from '../helpers/file-helper';

declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace jest {
interface Matchers<R> {
toBeCell(): R;
}
}
}

export interface ExpectedFont {
name?: string;
size?: number;
Expand Down Expand Up @@ -72,6 +81,25 @@ export interface ExpectedStartEventModelElement extends ExpectedEventModelElemen
isInterrupting?: boolean;
}

const bpmnVisualization = new BpmnVisualization(null);

expect.extend({
toBeCell(cellId) {
const cell = bpmnVisualization.graph.model.getCell(cellId);
if (cell) {
return {
message: () => `Expected the cell with id '${cellId}' not to be found in the mxGraph model`,
pass: true,
};
} else {
return {
message: () => `Expected the cell with id '${cellId}' to be found in the mxGraph model`,
pass: false,
};
}
},
});

function expectGeometry(cell: mxCell, geometry: mxGeometry): void {
const cellGeometry = cell.getGeometry();
expect(cellGeometry.x).toEqual(geometry.x);
Expand All @@ -82,8 +110,6 @@ function expectGeometry(cell: mxCell, geometry: mxGeometry): void {
}

describe('mxGraph model', () => {
const bpmnVisualization = new BpmnVisualization(null);

function expectFont(state: mxCellState, expectedFont: ExpectedFont): void {
if (expectedFont) {
if (expectedFont.isBold) {
Expand All @@ -109,14 +135,12 @@ describe('mxGraph model', () => {

function expectModelNotContainCell(cellId: string): void {
const cell = bpmnVisualization.graph.model.getCell(cellId);
expect(cell).toBeUndefined();
expect(cell).not.toBeCell();
}

function expectModelContainsCell(cellId: string): mxCell {
const cell = bpmnVisualization.graph.model.getCell(cellId);
expect(cell).not.toBeUndefined();
expect(cell).not.toBeNull();
return cell;
expect(cellId).toBeCell();
return bpmnVisualization.graph.model.getCell(cellId);
}

function expectModelContainsShape(cellId: string, modelElement: ExpectedShapeModelElement): mxCell {
Expand Down Expand Up @@ -944,8 +968,7 @@ describe('mxGraph model', () => {
});

function expectModelContainsCellWithGeometry(cellId: string, parentId: string, geometry: mxGeometry): void {
const cell = bpmnVisualization.graph.model.getCell(cellId);
expect(cell).not.toBeNull();
const cell = expectModelContainsCell(cellId);

if (parentId) {
expect(cell.parent.id).toEqual(parentId);
Expand Down