-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Canvas): invalidate
_objectsToRender
on stack change (#9387)
- Loading branch information
Showing
3 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { FabricObject } from '../../shapes/Object/FabricObject'; | ||
import { Canvas } from '../Canvas'; | ||
|
||
describe('Canvas', () => { | ||
describe('invalidating `_objectsToRender`', () => { | ||
test('initial state', () => { | ||
const canvas = new Canvas(); | ||
expect(canvas._objectsToRender).toBeUndefined(); | ||
}); | ||
|
||
test('mousedown', () => { | ||
const canvas = new Canvas(); | ||
canvas.add(new FabricObject({ width: 10, height: 10 })); | ||
canvas._objectsToRender = []; | ||
canvas | ||
.getSelectionElement() | ||
.dispatchEvent(new MouseEvent('mousedown', { clientX: 5, clientY: 5 })); | ||
expect(canvas._objectsToRender).toBeUndefined(); | ||
}); | ||
|
||
test('object added/removed', () => { | ||
const canvas = new Canvas(); | ||
canvas._objectsToRender = []; | ||
const object = new FabricObject({ width: 10, height: 10 }); | ||
canvas.add(object); | ||
expect(canvas._objectsToRender).toBeUndefined(); | ||
canvas._objectsToRender = []; | ||
canvas.remove(object); | ||
expect(canvas._objectsToRender).toBeUndefined(); | ||
}); | ||
|
||
test('stack change', () => { | ||
const canvas = new Canvas(); | ||
const object = new FabricObject({ width: 10, height: 10 }); | ||
const object2 = new FabricObject({ | ||
left: 5, | ||
top: 5, | ||
width: 10, | ||
height: 10, | ||
}); | ||
canvas.add(object, object2); | ||
|
||
canvas._objectsToRender = []; | ||
canvas.sendObjectBackwards(object2); | ||
expect(canvas._objectsToRender).toBeUndefined(); | ||
|
||
canvas._objectsToRender = []; | ||
canvas.bringObjectForward(object2); | ||
expect(canvas._objectsToRender).toBeUndefined(); | ||
|
||
canvas._objectsToRender = []; | ||
canvas.bringObjectToFront(object); | ||
expect(canvas._objectsToRender).toBeUndefined(); | ||
|
||
canvas._objectsToRender = []; | ||
canvas.sendObjectToBack(object); | ||
expect(canvas._objectsToRender).toBeUndefined(); | ||
}); | ||
}); | ||
}); |