Spaces:
Running
Running
File size: 1,603 Bytes
b456468 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
import ArrowLine from '@/extension/arrowLine';
describe('ArrowLine', () => {
let ctx, arrowLine, linePath;
function assertPointsToMatchSnapshots() {
const [firstPoint] = ctx.moveTo.mock.calls;
const [secondPoint] = ctx.lineTo.mock.calls;
const [, lastPoint] = ctx.lineTo.mock.calls;
expect(firstPoint).toMatchSnapshot();
expect(secondPoint).toMatchSnapshot();
expect(lastPoint).toMatchSnapshot();
}
beforeEach(() => {
ctx = {
lineWidth: 1,
beginPath: jest.fn(),
moveTo: jest.fn(),
lineTo: jest.fn(),
closePath: jest.fn(),
};
arrowLine = new ArrowLine();
arrowLine.ctx = ctx;
linePath = {
fromX: 1,
fromY: 1,
toX: 10,
toY: 10,
};
});
it('should draw the "v" calculated according to the angle around the "tail" of the line when attaching the "chevron" type to the end point', () => {
arrowLine.arrowType = { tail: 'chevron' };
arrowLine._drawDecoratorPath(linePath);
assertPointsToMatchSnapshots();
});
it('should draw the "v" calculated according to the angle around the "head" of the line when attaching the "chevron" type to the start point', () => {
arrowLine.arrowType = { head: 'chevron' };
arrowLine._drawDecoratorPath(linePath);
assertPointsToMatchSnapshots();
});
it('should be a triangular shape that closes the path with closePath after drawing', () => {
arrowLine.arrowType = { head: 'triangle' };
arrowLine._drawDecoratorPath(linePath);
assertPointsToMatchSnapshots();
expect(ctx.closePath).toBeCalledTimes(1);
});
});
|