Fix rest of the tests

This commit is contained in:
Marcel Mraz 2025-03-20 23:35:46 +01:00
parent 40ff1b08ae
commit 7744284254
No known key found for this signature in database
GPG key ID: 4EBD6E62DC830CD2
7 changed files with 47 additions and 47 deletions

View file

@ -9,7 +9,7 @@ const EPSILON_DIGITS = 3;
// below tests. In Jest this wasn't needed as global override was possible
// but vite doesn't allow that hence we need to mock
vi.mock(
"../constants.ts",
"@excalidraw/common",
//@ts-ignore
async (importOriginal) => {
const module: any = await importOriginal();

View file

@ -1,9 +1,9 @@
import clsx from "clsx";
import throttle from "lodash.throttle";
import { nanoid } from "nanoid";
import React, { useContext } from "react";
import { flushSync } from "react-dom";
import rough from "roughjs/bin/rough";
import { nanoid } from "nanoid";
import {
clamp,
@ -73,6 +73,31 @@ import {
toValidURL,
getGridPoint,
getLineHeight,
debounce,
distance,
getFontString,
getNearestScrollableContainer,
isInputLike,
isToolIcon,
isWritableElement,
sceneCoordsToViewportCoords,
tupleToCoors,
viewportCoordsToSceneCoords,
wrapEvent,
updateObject,
updateActiveTool,
getShortcutKey,
isTransparent,
easeToValuesRAF,
muteFSAbortError,
isTestEnv,
easeOut,
updateStable,
addEventListener,
normalizeEOL,
getDateTime,
isShallowEqual,
arrayToMap,
type EXPORT_IMAGE_TYPES,
} from "@excalidraw/common";
@ -157,34 +182,6 @@ import {
isPathALoop,
} from "@excalidraw/element/shapes";
import {
debounce,
distance,
getFontString,
getNearestScrollableContainer,
isInputLike,
isToolIcon,
isWritableElement,
sceneCoordsToViewportCoords,
tupleToCoors,
viewportCoordsToSceneCoords,
wrapEvent,
updateObject,
updateActiveTool,
getShortcutKey,
isTransparent,
easeToValuesRAF,
muteFSAbortError,
isTestEnv,
easeOut,
updateStable,
addEventListener,
normalizeEOL,
getDateTime,
isShallowEqual,
arrayToMap,
} from "@excalidraw/common";
import {
createSrcDoc,
embeddableURLValidator,

View file

@ -9,9 +9,8 @@ import {
import { clearElementsForExport } from "@excalidraw/element";
import type { ExcalidrawElement, FileId } from "@excalidraw/element/types";
import type { ValueOf } from "@excalidraw/common/utility-types";
import type { ExcalidrawElement, FileId } from "@excalidraw/element/types";
import { cleanAppStateForExport } from "../appState";
@ -24,9 +23,9 @@ import { nativeFileSystemSupported } from "./filesystem";
import { isValidExcalidrawData, isValidLibrary } from "./json";
import { restore, restoreLibraryItems } from "./restore";
import type { FileSystemHandle } from "./filesystem";
import type { AppState, DataURL, LibraryItem } from "../types";
import type { FileSystemHandle } from "./filesystem";
import type { ImportedLibraryData } from "./types";
const parseFileContents = async (blob: Blob | File): Promise<string> => {

View file

@ -27,7 +27,7 @@ const { h } = window;
const mouse = new Pointer("mouse");
vi.mock("../keys.ts", async (importOriginal) => {
vi.mock("@excalidraw/common", async (importOriginal) => {
const module: any = await importOriginal();
return {
__esmodule: true,

View file

@ -1,8 +1,10 @@
import { pointFrom, type Radians } from "@excalidraw/math";
import React from "react";
import { vi } from "vitest";
import { ROUNDNESS, KEYS, arrayToMap, cloneJSON } from "@excalidraw/common";
import { pointFrom, type Radians } from "@excalidraw/math";
import { getBoundTextElementPosition } from "@excalidraw/element/textElement";
import { getElementAbsoluteCoords } from "@excalidraw/element/bounds";
import { newLinearElement } from "@excalidraw/element/newElement";
@ -21,6 +23,9 @@ import { actionFlipHorizontal, actionFlipVertical } from "../actions";
import { createPasteEvent } from "../clipboard";
import { Excalidraw } from "../index";
// Importing to spy on it and mock the implementation (mocking does not work with simple vi.mock for some reason)
import * as blobModule from "../data/blob";
import { API } from "./helpers/api";
import { UI, Pointer, Keyboard } from "./helpers/ui";
import {
@ -37,13 +42,12 @@ import type { NormalizedZoomValue } from "../types";
const { h } = window;
const mouse = new Pointer("mouse");
vi.mock("../data/blob", async (actual) => {
const orig: Object = await actual();
return {
...orig,
resizeImageFile: (imageFile: File) => imageFile,
generateIdFromFile: () => "fileId" as FileId,
};
beforeEach(() => {
const generateIdSpy = vi.spyOn(blobModule, "generateIdFromFile");
const resizeFileSpy = vi.spyOn(blobModule, "resizeImageFile");
generateIdSpy.mockImplementation(() => Promise.resolve("fileId" as FileId));
resizeFileSpy.mockImplementation((file: File) => Promise.resolve(file));
});
beforeEach(async () => {

View file

@ -4,7 +4,7 @@ import util from "util";
import { pointFrom, type LocalPoint, type Radians } from "@excalidraw/math";
import { DEFAULT_VERTICAL_ALIGN, ROUNDNESS } from "@excalidraw/common";
import { DEFAULT_VERTICAL_ALIGN, ROUNDNESS, assertNever } from "@excalidraw/common";
import { mutateElement } from "@excalidraw/element/mutateElement";
import {
@ -19,11 +19,9 @@ import {
newMagicFrameElement,
newTextElement,
} from "@excalidraw/element/newElement";
import { isLinearElementType } from "@excalidraw/element/typeChecks";
import { getSelectedElements } from "@excalidraw/element/selection";
import { assertNever } from "@excalidraw/common";
import { selectGroupsForSelectedElements } from "@excalidraw/element/groups";
import type {

View file

@ -17,6 +17,8 @@ import { Excalidraw } from "../index";
import * as InteractiveCanvas from "../renderer/interactiveScene";
import * as StaticScene from "../renderer/staticScene";
import "../../utils/test-utils";
import { UI, Pointer, Keyboard } from "./helpers/ui";
import { render, fireEvent, act, unmountComponent } from "./test-utils";