mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
test: add tests for deselecting when pressing escape
This commit is contained in:
parent
898036d202
commit
db9aca37b6
1 changed files with 98 additions and 0 deletions
|
@ -104,6 +104,104 @@ describe("box-selection", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("deselect when pressing escape", () => {
|
||||
beforeEach(async () => {
|
||||
await render(<Excalidraw handleKeyboardGlobally={true} />);
|
||||
});
|
||||
|
||||
it("deselects elements", async () => {
|
||||
const rect1 = API.createElement({
|
||||
type: "rectangle",
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 50,
|
||||
height: 50,
|
||||
});
|
||||
const rect2 = API.createElement({
|
||||
type: "rectangle",
|
||||
x: 100,
|
||||
y: 0,
|
||||
width: 50,
|
||||
height: 50,
|
||||
});
|
||||
|
||||
h.elements = [rect1, rect2];
|
||||
|
||||
mouse.clickAt(0, 0);
|
||||
|
||||
assertSelectedElements([rect1.id]);
|
||||
|
||||
Keyboard.keyDown(KEYS.ESCAPE);
|
||||
|
||||
assertSelectedElements([]);
|
||||
|
||||
mouse.downAt(-10, -10);
|
||||
mouse.moveTo(160, 60);
|
||||
mouse.up();
|
||||
|
||||
assertSelectedElements([rect1.id, rect2.id]);
|
||||
|
||||
Keyboard.keyDown(KEYS.ESCAPE);
|
||||
|
||||
assertSelectedElements([]);
|
||||
});
|
||||
|
||||
it("deselects groups", async () => {
|
||||
const rect1 = API.createElement({
|
||||
type: "rectangle",
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 50,
|
||||
height: 50,
|
||||
});
|
||||
const rect2 = API.createElement({
|
||||
type: "rectangle",
|
||||
x: 100,
|
||||
y: 0,
|
||||
width: 50,
|
||||
height: 50,
|
||||
});
|
||||
const rect3 = API.createElement({
|
||||
type: "rectangle",
|
||||
x: 200,
|
||||
y: 0,
|
||||
width: 50,
|
||||
height: 50,
|
||||
});
|
||||
|
||||
h.elements = [rect1, rect2, rect3];
|
||||
|
||||
mouse.downAt(-10, -10);
|
||||
mouse.moveTo(160, 60);
|
||||
mouse.up();
|
||||
|
||||
Keyboard.withModifierKeys({ ctrl: true }, () => {
|
||||
Keyboard.keyDown(KEYS.G);
|
||||
});
|
||||
|
||||
expect(Object.keys(h.state.selectedGroupIds).length).toBe(1);
|
||||
assertSelectedElements([rect1.id, rect2.id]);
|
||||
|
||||
Keyboard.keyDown(KEYS.ESCAPE);
|
||||
|
||||
expect(Object.keys(h.state.selectedGroupIds).length).toBe(0);
|
||||
assertSelectedElements([]);
|
||||
|
||||
mouse.clickAt(100, 0);
|
||||
Keyboard.withModifierKeys({ shift: true }, () => {
|
||||
mouse.clickAt(200, 0);
|
||||
});
|
||||
|
||||
expect(Object.keys(h.state.selectedGroupIds).length).toBe(1);
|
||||
assertSelectedElements([rect1.id, rect2.id, rect3.id]);
|
||||
|
||||
Keyboard.keyDown(KEYS.ESCAPE);
|
||||
|
||||
expect(Object.keys(h.state.selectedGroupIds).length).toBe(0);
|
||||
assertSelectedElements([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("inner box-selection", () => {
|
||||
beforeEach(async () => {
|
||||
await render(<Excalidraw />);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue