Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaMan123 committed May 4, 2024
1 parent af83ec3 commit 06f831c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/canvas/SelectableCanvas.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { FabricObject } from '../shapes/Object/FabricObject';
import { Point } from '../Point';
import { Canvas } from './Canvas';
import { Group } from '../shapes/Group';
import { createTranslateMatrix } from '../util';
import type { TPointerEventInfo } from '../EventTypeDefs';

describe('Selectable Canvas', () => {
describe('_pointIsInObjectSelectionArea', () => {
Expand Down Expand Up @@ -480,5 +482,29 @@ describe('Selectable Canvas', () => {
expect(canvas._currentTransform).toHaveProperty('corner', controlKey);
expect(spy).toHaveBeenCalledTimes(1);
});

test('caching event pointers is a mistake', () => {
const canvas = new Canvas();
const spy = jest
.fn()
.mockImplementation(({ e, scenePoint }: TPointerEventInfo) => {
const before = canvas.getScenePoint(e);
canvas.setViewportTransform(createTranslateMatrix(50, 50));
// canvas._resetTransformEventData();
return { event: scenePoint, before, after: canvas.getScenePoint(e) };
});
canvas.once('mouse:down', spy);
canvas.getSelectionElement().dispatchEvent(
new MouseEvent('mousedown', {
clientX: 50,
clientY: 50,
})
);
expect(spy).toHaveReturnedWith({
event: new Point(50, 50),
before: new Point(50, 50),
after: new Point(),
});
});
});
});

0 comments on commit 06f831c

Please sign in to comment.