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

* fix: duplication tests pointer state leaking between tests

* fix snapshots
This commit is contained in:
David Luzar 2025-04-18 11:11:12 +02:00 committed by GitHub
parent a5d6939826
commit b5d60973b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 28 additions and 24 deletions

View file

@ -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,

View file

@ -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,

View file

@ -444,7 +444,6 @@ export class API {
const text = API.createElement({
type: "text",
id: "text2",
width: 50,
height: 20,
containerId: arrow.id,

View file

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

View file

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

View file

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