fix: duplication tests pointer state leaking between tests

This commit is contained in:
dwelle 2025-04-18 10:59:17 +02:00
parent a5d6939826
commit 2114a799af
5 changed files with 14 additions and 10 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

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