Skip to content

Virtual whiteboard for sketching hand-drawn like diagrams

fix: duplication tests pointer state leaking between tests (#9414)

David Luzarb5d60973b718
diff --git a/packages/element/tests/duplicate.test.tsx b/packages/element/tests/duplicate.test.tsx
index 409200b6e6..fd748757bb 100644
--- a/packages/element/tests/duplicate.test.tsx
+++ b/packages/element/tests/duplicate.test.tsx
@@ -1,4 +1,3 @@
-import React from "react";
import { pointFrom } from "@excalidraw/math";
import {
@@ -472,7 +471,7 @@ describe("group-related duplication", () => {
expect(h.state.editingGroupId).toBe("group1");
});
- it.skip("alt-duplicating within group away outside frame", () => {
+ it("alt-duplicating within group away outside frame", () => {
const frame = API.createElement({
type: "frame",
x: 0,
diff --git a/packages/excalidraw/tests/__snapshots__/history.test.tsx.snap b/packages/excalidraw/tests/__snapshots__/history.test.tsx.snap
index 9ffb97128a..7b249da278 100644
--- a/packages/excalidraw/tests/__snapshots__/history.test.tsx.snap
+++ b/packages/excalidraw/tests/__snapshots__/history.test.tsx.snap
@@ -7348,8 +7348,8 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh
"updated": 1,
"version": 7,
"width": 10,
- "x": -10,
- "y": -10,
+ "x": 0,
+ "y": 0,
}
`;
@@ -7422,8 +7422,8 @@ History {
"strokeWidth": 2,
"type": "arrow",
"width": 10,
- "x": -10,
- "y": -10,
+ "x": 0,
+ "y": 0,
},
"inserted": {
"isDeleted": true,
@@ -12138,8 +12138,8 @@ exports[`history > singleplayer undo/redo > should create entry when selecting f
"updated": 1,
"version": 3,
"width": 10,
- "x": 10,
- "y": 10,
+ "x": -10,
+ "y": -10,
}
`;
@@ -12192,8 +12192,8 @@ exports[`history > singleplayer undo/redo > should create entry when selecting f
"updated": 1,
"version": 5,
"width": 50,
- "x": 60,
- "y": 0,
+ "x": 40,
+ "y": -20,
}
`;
@@ -12246,8 +12246,8 @@ exports[`history > singleplayer undo/redo > should create entry when selecting f
"updated": 1,
"version": 4,
"width": 50,
- "x": 150,
- "y": -10,
+ "x": 130,
+ "y": -30,
}
`;
@@ -12301,8 +12301,8 @@ History {
"strokeWidth": 2,
"type": "rectangle",
"width": 10,
- "x": 10,
- "y": 10,
+ "x": -10,
+ "y": -10,
},
"inserted": {
"isDeleted": true,
@@ -12387,8 +12387,8 @@ History {
"strokeWidth": 2,
"type": "freedraw",
"width": 50,
- "x": 150,
- "y": -10,
+ "x": 130,
+ "y": -30,
},
"inserted": {
"isDeleted": true,
diff --git a/packages/excalidraw/tests/helpers/api.ts b/packages/excalidraw/tests/helpers/api.ts
index 09aa308a5d..3a83f27635 100644
--- a/packages/excalidraw/tests/helpers/api.ts
+++ b/packages/excalidraw/tests/helpers/api.ts
@@ -444,7 +444,6 @@ export class API {
const text = API.createElement({
type: "text",
- id: "text2",
width: 50,
height: 20,
containerId: arrow.id,
diff --git a/packages/excalidraw/tests/helpers/ui.ts b/packages/excalidraw/tests/helpers/ui.ts
index 32de489f15..38070d38bc 100644
--- a/packages/excalidraw/tests/helpers/ui.ts
+++ b/packages/excalidraw/tests/helpers/ui.ts
@@ -180,10 +180,17 @@ export class Pointer {
public clientX = 0;
public clientY = 0;
+ static activePointers: Pointer[] = [];
+ static resetAll() {
+ Pointer.activePointers.forEach((pointer) => pointer.reset());
+ }
+
constructor(
private readonly pointerType: "mouse" | "touch" | "pen",
private readonly pointerId = 1,
- ) {}
+ ) {
+ Pointer.activePointers.push(this);
+ }
reset() {
this.clientX = 0;
diff --git a/packages/excalidraw/tests/test-utils.ts b/packages/excalidraw/tests/test-utils.ts
index b2b8aff9c9..894d748dd8 100644
--- a/packages/excalidraw/tests/test-utils.ts
+++ b/packages/excalidraw/tests/test-utils.ts
@@ -19,7 +19,7 @@ import type { AllPossibleKeys } from "@excalidraw/common/utility-types";
import { STORAGE_KEYS } from "../../../excalidraw-app/app_constants";
-import { UI } from "./helpers/ui";
+import { Pointer, UI } from "./helpers/ui";
import * as toolQueries from "./queries/toolQueries";
import type { RenderResult, RenderOptions } from "@testing-library/react";
@@ -42,6 +42,10 @@ type TestRenderFn = (
) => Promise<RenderResult<typeof customQueries>>;
const renderApp: TestRenderFn = async (ui, options) => {
+ // when tests reuse Pointer instances let's reset the last
+ // pointer poisitions so there's no leak between tests
+ Pointer.resetAll();
+
if (options?.localStorageData) {
initLocalStorage(options.localStorageData);
delete options.localStorageData;
diff --git a/setupTests.ts b/setupTests.ts
index 2aec616b48..245c573267 100644
--- a/setupTests.ts
+++ b/setupTests.ts
@@ -94,11 +94,6 @@ vi.mock(
},
);
-vi.mock("nanoid", () => {
- return {
- nanoid: vi.fn(() => "test-id"),
- };
-});
// ReactDOM is located inside index.tsx file
// as a result, we need a place for it to render into
const element = document.createElement("div");