diff --git a/src/canvas/__tests__/eventData.test.ts b/src/canvas/__tests__/eventData.test.ts index d30fb70b7a0..39249a57d96 100644 --- a/src/canvas/__tests__/eventData.test.ts +++ b/src/canvas/__tests__/eventData.test.ts @@ -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()];