Skip to content

Commit

Permalink
Fix withFont extension
Browse files Browse the repository at this point in the history
  • Loading branch information
csouchet committed Oct 7, 2020
1 parent 1587a56 commit 756f1c2
Showing 1 changed file with 33 additions and 41 deletions.
74 changes: 33 additions & 41 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 { StyleIdentifier } from '../../src/bpmn-visualization';
import { StyleDefault, StyleIdentifier } from '../../src/bpmn-visualization';
import MatcherContext = jest.MatcherContext;
import CustomMatcherResult = jest.CustomMatcherResult;

Expand All @@ -28,6 +28,7 @@ declare global {
interface Matchers<R> {
toBeCell(): R;
withGeometry(geometry: mxGeometry): R;
withFont(font: ExpectedFont): R;
}
}
}
Expand Down Expand Up @@ -134,40 +135,42 @@ function withGeometry(this: MatcherContext, received: mxCell, expected: mxGeomet
}

function withFont(this: MatcherContext, received: mxCell, expected: ExpectedFont): CustomMatcherResult {
if (expected) {
const style = bpmnVisualization.graph.getView().getState(received).style;
const style = bpmnVisualization.graph.getView().getState(received).style;
const receivedFont = { fontStyle: style[mxConstants.STYLE_FONTSTYLE], fontFamily: style[mxConstants.STYLE_FONTFAMILY], fontSize: style[mxConstants.STYLE_FONTSIZE] };

const receivedFont = { fontStyle: style[mxConstants.STYLE_FONTSTYLE], fontFamily: style[mxConstants.STYLE_FONTFAMILY], fontSize: style[mxConstants.STYLE_FONTSIZE] };
const expectedFont = { fontStyle: getFontStyleValue(expected), fontFamily: expected.name, fontSize: expected.size };

const pass = receivedFont === expectedFont;
let expectedFont: any;
if (expected) {
expectedFont = { fontStyle: getFontStyleValue(expected), fontFamily: expected.name, fontSize: expected.size };
} else {
expectedFont = { fontStyle: undefined, fontFamily: StyleDefault.DEFAULT_FONT_FAMILY, fontSize: StyleDefault.DEFAULT_FONT_SIZE };
}

return {
message: pass
? () =>
this.utils.matcherHint('.not.withFont') +
const pass = JSON.stringify(receivedFont) === JSON.stringify(expectedFont);
return {
message: pass
? () =>
this.utils.matcherHint('.not.withFont') +
'\n\n' +
`Expected font of the cell with id '${received.id}' not to be equals to:\n` +
` ${this.utils.printExpected(expectedFont)}\n` +
`Received:\n` +
` ${this.utils.printReceived(receivedFont)}`
: () => {
const diffString = this.utils.diff(expectedFont, receivedFont, {
expand: this.expand,
});
return (
this.utils.matcherHint('.withFont') +
'\n\n' +
`Expected font of the cell with id '${received.cell.id}' not to be equals to:\n` +
`Expected font of the cell with id '${received.id}' to be equals to:\n` +
` ${this.utils.printExpected(expectedFont)}\n` +
`Received:\n` +
` ${this.utils.printReceived(receivedFont)}`
: () => {
const diffString = this.utils.diff(expectedFont, receivedFont, {
expand: this.expand,
});
return (
this.utils.matcherHint('.withFont') +
'\n\n' +
`Expected font of the cell with id '${received.cell.id}' to be equals to:\n` +
` ${this.utils.printExpected(expectedFont)}\n` +
`Received:\n` +
` ${this.utils.printReceived(receivedFont)}` +
(diffString ? `\n\nDifference:\n\n${diffString}` : '')
);
},
pass,
};
}
` ${this.utils.printReceived(receivedFont)}` +
(diffString ? `\n\nDifference:\n\n${diffString}` : '')
);
},
pass,
};
}

function getFontStyleValue(expectedFont: ExpectedFont): number {
Expand All @@ -187,17 +190,6 @@ function getFontStyleValue(expectedFont: ExpectedFont): number {
return value;
}

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

expect.extend({
toBeCell,
withGeometry,
Expand Down

0 comments on commit 756f1c2

Please sign in to comment.