Skip to content

Commit

Permalink
add more important tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaMan123 committed Sep 15, 2023
1 parent 360665d commit c1448b0
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/canvas/__tests__/eventData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,57 @@ describe('Event targets', () => {
expect(canvas.targets).toEqual([]);
});

test('searchPossibleTargets with selection and subTargetCheck', () => {
const subTarget = new FabricObject();
const target = new Group([subTarget], {
subTargetCheck: true,
});
const other = new FabricObject();
const activeSelection = new ActiveSelection([], {
subTargetCheck: true,
});
registerTestObjects({ subTarget, target, other, activeSelection });

const canvas = new Canvas(null, { activeSelection });
canvas.add(other, target);
activeSelection.add(target, other);
canvas.setActiveObject(activeSelection);

jest.spyOn(canvas, '_checkTarget').mockReturnValue(true);
const foundTargets = canvas['findTargetsTraversal'](
[activeSelection],
new Point(),
{ searchStrategy: 'search-all' }
);
const found = canvas.searchPossibleTargets(
[activeSelection],
new Point()
);
expect(foundTargets).toEqual([other, subTarget, target, activeSelection]);
expect(found).toBe(activeSelection);
expect(canvas.targets).toEqual([other]);
});

test.failing('searchPossibleTargets with active objects', () => {
const subTarget = new FabricObject();
const target = new Group([subTarget], {
subTargetCheck: true,
});
const other = new FabricObject();
const activeSelection = new ActiveSelection();
registerTestObjects({ subTarget, target, other, activeSelection });

const canvas = new Canvas(null, { activeSelection });
canvas.add(other, target);
activeSelection.add(target, other);
canvas.setActiveObject(activeSelection);

jest.spyOn(canvas, '_checkTarget').mockReturnValue(true);
const found = canvas.searchPossibleTargets([target, other], new Point());
expect(found).toBe(other);
expect(canvas.targets).toEqual([subTarget, target, other]);
});

test('findTarget clears prev targets', () => {
const canvas = new Canvas();
canvas.targets = [new FabricObject()];
Expand Down

0 comments on commit c1448b0

Please sign in to comment.