Browse Source

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

* fix: duplication tests pointer state leaking between tests

* fix snapshots
pull/9071/merge
David Luzar 8 months ago committed by GitHub
parent
commit
b5d60973b7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      packages/element/tests/duplicate.test.tsx
  2. 28
      packages/excalidraw/tests/__snapshots__/history.test.tsx.snap
  3. 1
      packages/excalidraw/tests/helpers/api.ts
  4. 9
      packages/excalidraw/tests/helpers/ui.ts
  5. 6
      packages/excalidraw/tests/test-utils.ts
  6. 5
      setupTests.ts

3
packages/element/tests/duplicate.test.tsx

@ -1,4 +1,3 @@ @@ -1,4 +1,3 @@
import React from "react";
import { pointFrom } from "@excalidraw/math";
import {
@ -472,7 +471,7 @@ describe("group-related duplication", () => { @@ -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,

28
packages/excalidraw/tests/__snapshots__/history.test.tsx.snap

@ -7348,8 +7348,8 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh @@ -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 { @@ -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 @@ -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 @@ -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 @@ -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 { @@ -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 { @@ -12387,8 +12387,8 @@ History {
"strokeWidth": 2,
"type": "freedraw",
"width": 50,
"x": 150,
"y": -10,
"x": 130,
"y": -30,
},
"inserted": {
"isDeleted": true,

1
packages/excalidraw/tests/helpers/api.ts

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

9
packages/excalidraw/tests/helpers/ui.ts

@ -180,10 +180,17 @@ export class Pointer { @@ -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;

6
packages/excalidraw/tests/test-utils.ts

@ -19,7 +19,7 @@ import type { AllPossibleKeys } from "@excalidraw/common/utility-types"; @@ -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 = ( @@ -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;

5
setupTests.ts

@ -94,11 +94,6 @@ vi.mock( @@ -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");

Loading…
Cancel
Save