Skip to content

Commit

Permalink
Add custom message when a cell is not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
csouchet committed Oct 1, 2020
1 parent a6df58e commit 58f70c7
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 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 cell with id '${cellId}' NOT to be defined`,
pass: true,
};
} else {
return {
message: () => `Expected cell with id '${cellId}' to be defined`,
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 Down Expand Up @@ -113,10 +139,8 @@ describe('mxGraph model', () => {
}

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

0 comments on commit 58f70c7

Please sign in to comment.