diff --git a/packages/excalidraw/tests/selection.test.tsx b/packages/excalidraw/tests/selection.test.tsx
index 6d55cc373..e40251fea 100644
--- a/packages/excalidraw/tests/selection.test.tsx
+++ b/packages/excalidraw/tests/selection.test.tsx
@@ -104,6 +104,104 @@ describe("box-selection", () => {
});
});
+describe("deselect when pressing escape", () => {
+ beforeEach(async () => {
+ await render();
+ });
+
+ 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();