test: add tests for deselecting when pressing escape

This commit is contained in:
Andrew Aquino 2024-03-16 21:44:09 -07:00
parent 898036d202
commit db9aca37b6

View file

@ -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 />);