mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Fix rest of the tests
This commit is contained in:
parent
40ff1b08ae
commit
7744284254
7 changed files with 47 additions and 47 deletions
|
@ -9,7 +9,7 @@ const EPSILON_DIGITS = 3;
|
||||||
// below tests. In Jest this wasn't needed as global override was possible
|
// below tests. In Jest this wasn't needed as global override was possible
|
||||||
// but vite doesn't allow that hence we need to mock
|
// but vite doesn't allow that hence we need to mock
|
||||||
vi.mock(
|
vi.mock(
|
||||||
"../constants.ts",
|
"@excalidraw/common",
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
async (importOriginal) => {
|
async (importOriginal) => {
|
||||||
const module: any = await importOriginal();
|
const module: any = await importOriginal();
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import throttle from "lodash.throttle";
|
import throttle from "lodash.throttle";
|
||||||
import { nanoid } from "nanoid";
|
|
||||||
import React, { useContext } from "react";
|
import React, { useContext } from "react";
|
||||||
import { flushSync } from "react-dom";
|
import { flushSync } from "react-dom";
|
||||||
import rough from "roughjs/bin/rough";
|
import rough from "roughjs/bin/rough";
|
||||||
|
import { nanoid } from "nanoid";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
clamp,
|
clamp,
|
||||||
|
@ -73,6 +73,31 @@ import {
|
||||||
toValidURL,
|
toValidURL,
|
||||||
getGridPoint,
|
getGridPoint,
|
||||||
getLineHeight,
|
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,
|
type EXPORT_IMAGE_TYPES,
|
||||||
} from "@excalidraw/common";
|
} from "@excalidraw/common";
|
||||||
|
|
||||||
|
@ -157,34 +182,6 @@ import {
|
||||||
isPathALoop,
|
isPathALoop,
|
||||||
} from "@excalidraw/element/shapes";
|
} 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 {
|
import {
|
||||||
createSrcDoc,
|
createSrcDoc,
|
||||||
embeddableURLValidator,
|
embeddableURLValidator,
|
||||||
|
|
|
@ -9,9 +9,8 @@ import {
|
||||||
|
|
||||||
import { clearElementsForExport } from "@excalidraw/element";
|
import { clearElementsForExport } from "@excalidraw/element";
|
||||||
|
|
||||||
import type { ExcalidrawElement, FileId } from "@excalidraw/element/types";
|
|
||||||
|
|
||||||
import type { ValueOf } from "@excalidraw/common/utility-types";
|
import type { ValueOf } from "@excalidraw/common/utility-types";
|
||||||
|
import type { ExcalidrawElement, FileId } from "@excalidraw/element/types";
|
||||||
|
|
||||||
import { cleanAppStateForExport } from "../appState";
|
import { cleanAppStateForExport } from "../appState";
|
||||||
|
|
||||||
|
@ -24,9 +23,9 @@ import { nativeFileSystemSupported } from "./filesystem";
|
||||||
import { isValidExcalidrawData, isValidLibrary } from "./json";
|
import { isValidExcalidrawData, isValidLibrary } from "./json";
|
||||||
import { restore, restoreLibraryItems } from "./restore";
|
import { restore, restoreLibraryItems } from "./restore";
|
||||||
|
|
||||||
import type { FileSystemHandle } from "./filesystem";
|
|
||||||
|
|
||||||
import type { AppState, DataURL, LibraryItem } from "../types";
|
import type { AppState, DataURL, LibraryItem } from "../types";
|
||||||
|
|
||||||
|
import type { FileSystemHandle } from "./filesystem";
|
||||||
import type { ImportedLibraryData } from "./types";
|
import type { ImportedLibraryData } from "./types";
|
||||||
|
|
||||||
const parseFileContents = async (blob: Blob | File): Promise<string> => {
|
const parseFileContents = async (blob: Blob | File): Promise<string> => {
|
||||||
|
|
|
@ -27,7 +27,7 @@ const { h } = window;
|
||||||
|
|
||||||
const mouse = new Pointer("mouse");
|
const mouse = new Pointer("mouse");
|
||||||
|
|
||||||
vi.mock("../keys.ts", async (importOriginal) => {
|
vi.mock("@excalidraw/common", async (importOriginal) => {
|
||||||
const module: any = await importOriginal();
|
const module: any = await importOriginal();
|
||||||
return {
|
return {
|
||||||
__esmodule: true,
|
__esmodule: true,
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
import { pointFrom, type Radians } from "@excalidraw/math";
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { vi } from "vitest";
|
import { vi } from "vitest";
|
||||||
|
|
||||||
import { ROUNDNESS, KEYS, arrayToMap, cloneJSON } from "@excalidraw/common";
|
import { ROUNDNESS, KEYS, arrayToMap, cloneJSON } from "@excalidraw/common";
|
||||||
|
|
||||||
|
import { pointFrom, type Radians } from "@excalidraw/math";
|
||||||
|
|
||||||
import { getBoundTextElementPosition } from "@excalidraw/element/textElement";
|
import { getBoundTextElementPosition } from "@excalidraw/element/textElement";
|
||||||
import { getElementAbsoluteCoords } from "@excalidraw/element/bounds";
|
import { getElementAbsoluteCoords } from "@excalidraw/element/bounds";
|
||||||
import { newLinearElement } from "@excalidraw/element/newElement";
|
import { newLinearElement } from "@excalidraw/element/newElement";
|
||||||
|
@ -21,6 +23,9 @@ import { actionFlipHorizontal, actionFlipVertical } from "../actions";
|
||||||
import { createPasteEvent } from "../clipboard";
|
import { createPasteEvent } from "../clipboard";
|
||||||
import { Excalidraw } from "../index";
|
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 { API } from "./helpers/api";
|
||||||
import { UI, Pointer, Keyboard } from "./helpers/ui";
|
import { UI, Pointer, Keyboard } from "./helpers/ui";
|
||||||
import {
|
import {
|
||||||
|
@ -37,13 +42,12 @@ import type { NormalizedZoomValue } from "../types";
|
||||||
const { h } = window;
|
const { h } = window;
|
||||||
const mouse = new Pointer("mouse");
|
const mouse = new Pointer("mouse");
|
||||||
|
|
||||||
vi.mock("../data/blob", async (actual) => {
|
beforeEach(() => {
|
||||||
const orig: Object = await actual();
|
const generateIdSpy = vi.spyOn(blobModule, "generateIdFromFile");
|
||||||
return {
|
const resizeFileSpy = vi.spyOn(blobModule, "resizeImageFile");
|
||||||
...orig,
|
|
||||||
resizeImageFile: (imageFile: File) => imageFile,
|
generateIdSpy.mockImplementation(() => Promise.resolve("fileId" as FileId));
|
||||||
generateIdFromFile: () => "fileId" as FileId,
|
resizeFileSpy.mockImplementation((file: File) => Promise.resolve(file));
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import util from "util";
|
||||||
|
|
||||||
import { pointFrom, type LocalPoint, type Radians } from "@excalidraw/math";
|
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 { mutateElement } from "@excalidraw/element/mutateElement";
|
||||||
import {
|
import {
|
||||||
|
@ -19,11 +19,9 @@ import {
|
||||||
newMagicFrameElement,
|
newMagicFrameElement,
|
||||||
newTextElement,
|
newTextElement,
|
||||||
} from "@excalidraw/element/newElement";
|
} from "@excalidraw/element/newElement";
|
||||||
|
|
||||||
import { isLinearElementType } from "@excalidraw/element/typeChecks";
|
import { isLinearElementType } from "@excalidraw/element/typeChecks";
|
||||||
|
|
||||||
import { getSelectedElements } from "@excalidraw/element/selection";
|
import { getSelectedElements } from "@excalidraw/element/selection";
|
||||||
import { assertNever } from "@excalidraw/common";
|
|
||||||
|
|
||||||
import { selectGroupsForSelectedElements } from "@excalidraw/element/groups";
|
import { selectGroupsForSelectedElements } from "@excalidraw/element/groups";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
|
|
|
@ -17,6 +17,8 @@ import { Excalidraw } from "../index";
|
||||||
import * as InteractiveCanvas from "../renderer/interactiveScene";
|
import * as InteractiveCanvas from "../renderer/interactiveScene";
|
||||||
import * as StaticScene from "../renderer/staticScene";
|
import * as StaticScene from "../renderer/staticScene";
|
||||||
|
|
||||||
|
import "../../utils/test-utils";
|
||||||
|
|
||||||
import { UI, Pointer, Keyboard } from "./helpers/ui";
|
import { UI, Pointer, Keyboard } from "./helpers/ui";
|
||||||
import { render, fireEvent, act, unmountComponent } from "./test-utils";
|
import { render, fireEvent, act, unmountComponent } from "./test-utils";
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue