mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
chore: bump @testing-library/react
12.1.5
-> 16.0.0
(#8322)
This commit is contained in:
parent
3cf14c73a3
commit
f19ce30dfe
52 changed files with 1035 additions and 978 deletions
|
@ -1,3 +1,4 @@
|
|||
import React from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import {
|
||||
fireEvent,
|
||||
|
@ -19,7 +20,6 @@ import type {
|
|||
} from "../element/types";
|
||||
import { newLinearElement } from "../element";
|
||||
import { Excalidraw } from "../index";
|
||||
import { mutateElement } from "../element/mutateElement";
|
||||
import type { NormalizedZoomValue } from "../types";
|
||||
import { ROUNDNESS } from "../constants";
|
||||
import { vi } from "vitest";
|
||||
|
@ -54,7 +54,7 @@ beforeEach(async () => {
|
|||
elementFromPoint: () => GlobalTestState.canvas,
|
||||
});
|
||||
await render(<Excalidraw autoFocus={true} handleKeyboardGlobally={true} />);
|
||||
h.setState({
|
||||
API.setAppState({
|
||||
zoom: {
|
||||
value: 1 as NormalizedZoomValue,
|
||||
},
|
||||
|
@ -204,14 +204,14 @@ const checkElementsBoundingBox = async (
|
|||
|
||||
const checkHorizontalFlip = async (toleranceInPx: number = 0.00001) => {
|
||||
const originalElement = cloneJSON(h.elements[0]);
|
||||
h.app.actionManager.executeAction(actionFlipHorizontal);
|
||||
API.executeAction(actionFlipHorizontal);
|
||||
const newElement = h.elements[0];
|
||||
await checkElementsBoundingBox(originalElement, newElement, toleranceInPx);
|
||||
};
|
||||
|
||||
const checkTwoPointsLineHorizontalFlip = async () => {
|
||||
const originalElement = cloneJSON(h.elements[0]) as ExcalidrawLinearElement;
|
||||
h.app.actionManager.executeAction(actionFlipHorizontal);
|
||||
API.executeAction(actionFlipHorizontal);
|
||||
const newElement = h.elements[0] as ExcalidrawLinearElement;
|
||||
await waitFor(() => {
|
||||
expect(originalElement.points[0][0]).toBeCloseTo(
|
||||
|
@ -235,7 +235,7 @@ const checkTwoPointsLineHorizontalFlip = async () => {
|
|||
|
||||
const checkTwoPointsLineVerticalFlip = async () => {
|
||||
const originalElement = cloneJSON(h.elements[0]) as ExcalidrawLinearElement;
|
||||
h.app.actionManager.executeAction(actionFlipVertical);
|
||||
API.executeAction(actionFlipVertical);
|
||||
const newElement = h.elements[0] as ExcalidrawLinearElement;
|
||||
await waitFor(() => {
|
||||
expect(originalElement.points[0][0]).toBeCloseTo(
|
||||
|
@ -262,7 +262,7 @@ const checkRotatedHorizontalFlip = async (
|
|||
toleranceInPx: number = 0.00001,
|
||||
) => {
|
||||
const originalElement = cloneJSON(h.elements[0]);
|
||||
h.app.actionManager.executeAction(actionFlipHorizontal);
|
||||
API.executeAction(actionFlipHorizontal);
|
||||
const newElement = h.elements[0];
|
||||
await waitFor(() => {
|
||||
expect(newElement.angle).toBeCloseTo(expectedAngle);
|
||||
|
@ -275,7 +275,7 @@ const checkRotatedVerticalFlip = async (
|
|||
toleranceInPx: number = 0.00001,
|
||||
) => {
|
||||
const originalElement = cloneJSON(h.elements[0]);
|
||||
h.app.actionManager.executeAction(actionFlipVertical);
|
||||
API.executeAction(actionFlipVertical);
|
||||
const newElement = h.elements[0];
|
||||
await waitFor(() => {
|
||||
expect(newElement.angle).toBeCloseTo(expectedAngle);
|
||||
|
@ -286,7 +286,7 @@ const checkRotatedVerticalFlip = async (
|
|||
const checkVerticalFlip = async (toleranceInPx: number = 0.00001) => {
|
||||
const originalElement = cloneJSON(h.elements[0]);
|
||||
|
||||
h.app.actionManager.executeAction(actionFlipVertical);
|
||||
API.executeAction(actionFlipVertical);
|
||||
|
||||
const newElement = h.elements[0];
|
||||
await checkElementsBoundingBox(originalElement, newElement, toleranceInPx);
|
||||
|
@ -295,8 +295,8 @@ const checkVerticalFlip = async (toleranceInPx: number = 0.00001) => {
|
|||
const checkVerticalHorizontalFlip = async (toleranceInPx: number = 0.00001) => {
|
||||
const originalElement = cloneJSON(h.elements[0]);
|
||||
|
||||
h.app.actionManager.executeAction(actionFlipHorizontal);
|
||||
h.app.actionManager.executeAction(actionFlipVertical);
|
||||
API.executeAction(actionFlipHorizontal);
|
||||
API.executeAction(actionFlipVertical);
|
||||
|
||||
const newElement = h.elements[0];
|
||||
await checkElementsBoundingBox(originalElement, newElement, toleranceInPx);
|
||||
|
@ -309,7 +309,6 @@ const MULTIPOINT_LINEAR_ELEMENT_FLIP_TOLERANCE_IN_PIXELS = 20;
|
|||
describe("rectangle", () => {
|
||||
it("flips an unrotated rectangle horizontally correctly", async () => {
|
||||
createAndSelectOneRectangle();
|
||||
|
||||
await checkHorizontalFlip();
|
||||
});
|
||||
|
||||
|
@ -408,8 +407,8 @@ describe("ellipse", () => {
|
|||
describe("arrow", () => {
|
||||
it("flips an unrotated arrow horizontally with line inside min/max points bounds", async () => {
|
||||
const arrow = createLinearElementWithCurveInsideMinMaxPoints("arrow");
|
||||
h.elements = [arrow];
|
||||
h.app.setState({ selectedElementIds: { [arrow.id]: true } });
|
||||
API.setElements([arrow]);
|
||||
API.setAppState({ selectedElementIds: { [arrow.id]: true } });
|
||||
await checkHorizontalFlip(
|
||||
MULTIPOINT_LINEAR_ELEMENT_FLIP_TOLERANCE_IN_PIXELS,
|
||||
);
|
||||
|
@ -417,8 +416,8 @@ describe("arrow", () => {
|
|||
|
||||
it("flips an unrotated arrow vertically with line inside min/max points bounds", async () => {
|
||||
const arrow = createLinearElementWithCurveInsideMinMaxPoints("arrow");
|
||||
h.elements = [arrow];
|
||||
h.app.setState({ selectedElementIds: { [arrow.id]: true } });
|
||||
API.setElements([arrow]);
|
||||
API.setAppState({ selectedElementIds: { [arrow.id]: true } });
|
||||
|
||||
await checkVerticalFlip(50);
|
||||
});
|
||||
|
@ -427,12 +426,14 @@ describe("arrow", () => {
|
|||
const originalAngle = Math.PI / 4;
|
||||
const expectedAngle = (7 * Math.PI) / 4;
|
||||
const line = createLinearElementWithCurveInsideMinMaxPoints("arrow");
|
||||
h.elements = [line];
|
||||
h.state.selectedElementIds = {
|
||||
...h.state.selectedElementIds,
|
||||
[line.id]: true,
|
||||
};
|
||||
mutateElement(line, {
|
||||
API.setElements([line]);
|
||||
API.setAppState({
|
||||
selectedElementIds: {
|
||||
...h.state.selectedElementIds,
|
||||
[line.id]: true,
|
||||
},
|
||||
});
|
||||
API.updateElement(line, {
|
||||
angle: originalAngle,
|
||||
});
|
||||
|
||||
|
@ -446,12 +447,14 @@ describe("arrow", () => {
|
|||
const originalAngle = Math.PI / 4;
|
||||
const expectedAngle = (7 * Math.PI) / 4;
|
||||
const line = createLinearElementWithCurveInsideMinMaxPoints("arrow");
|
||||
h.elements = [line];
|
||||
h.state.selectedElementIds = {
|
||||
...h.state.selectedElementIds,
|
||||
[line.id]: true,
|
||||
};
|
||||
mutateElement(line, {
|
||||
API.setElements([line]);
|
||||
API.setAppState({
|
||||
selectedElementIds: {
|
||||
...h.state.selectedElementIds,
|
||||
[line.id]: true,
|
||||
},
|
||||
});
|
||||
API.updateElement(line, {
|
||||
angle: originalAngle,
|
||||
});
|
||||
|
||||
|
@ -464,8 +467,8 @@ describe("arrow", () => {
|
|||
//TODO: elements with curve outside minMax points have a wrong bounding box!!!
|
||||
it.skip("flips an unrotated arrow horizontally with line outside min/max points bounds", async () => {
|
||||
const arrow = createLinearElementsWithCurveOutsideMinMaxPoints("arrow");
|
||||
h.elements = [arrow];
|
||||
h.app.setState({ selectedElementIds: { [arrow.id]: true } });
|
||||
API.setElements([arrow]);
|
||||
API.setAppState({ selectedElementIds: { [arrow.id]: true } });
|
||||
|
||||
await checkHorizontalFlip(
|
||||
MULTIPOINT_LINEAR_ELEMENT_FLIP_TOLERANCE_IN_PIXELS,
|
||||
|
@ -477,9 +480,9 @@ describe("arrow", () => {
|
|||
const originalAngle = Math.PI / 4;
|
||||
const expectedAngle = (7 * Math.PI) / 4;
|
||||
const line = createLinearElementsWithCurveOutsideMinMaxPoints("arrow");
|
||||
mutateElement(line, { angle: originalAngle });
|
||||
h.elements = [line];
|
||||
h.app.setState({ selectedElementIds: { [line.id]: true } });
|
||||
API.updateElement(line, { angle: originalAngle });
|
||||
API.setElements([line]);
|
||||
API.setAppState({ selectedElementIds: { [line.id]: true } });
|
||||
|
||||
await checkRotatedVerticalFlip(
|
||||
expectedAngle,
|
||||
|
@ -490,8 +493,8 @@ describe("arrow", () => {
|
|||
//TODO: elements with curve outside minMax points have a wrong bounding box!!!
|
||||
it.skip("flips an unrotated arrow vertically with line outside min/max points bounds", async () => {
|
||||
const arrow = createLinearElementsWithCurveOutsideMinMaxPoints("arrow");
|
||||
h.elements = [arrow];
|
||||
h.app.setState({ selectedElementIds: { [arrow.id]: true } });
|
||||
API.setElements([arrow]);
|
||||
API.setAppState({ selectedElementIds: { [arrow.id]: true } });
|
||||
|
||||
await checkVerticalFlip(MULTIPOINT_LINEAR_ELEMENT_FLIP_TOLERANCE_IN_PIXELS);
|
||||
});
|
||||
|
@ -501,9 +504,9 @@ describe("arrow", () => {
|
|||
const originalAngle = Math.PI / 4;
|
||||
const expectedAngle = (7 * Math.PI) / 4;
|
||||
const line = createLinearElementsWithCurveOutsideMinMaxPoints("arrow");
|
||||
mutateElement(line, { angle: originalAngle });
|
||||
h.elements = [line];
|
||||
h.app.setState({ selectedElementIds: { [line.id]: true } });
|
||||
API.updateElement(line, { angle: originalAngle });
|
||||
API.setElements([line]);
|
||||
API.setAppState({ selectedElementIds: { [line.id]: true } });
|
||||
|
||||
await checkRotatedVerticalFlip(
|
||||
expectedAngle,
|
||||
|
@ -538,8 +541,8 @@ describe("arrow", () => {
|
|||
describe("line", () => {
|
||||
it("flips an unrotated line horizontally with line inside min/max points bounds", async () => {
|
||||
const line = createLinearElementWithCurveInsideMinMaxPoints("line");
|
||||
h.elements = [line];
|
||||
h.app.setState({ selectedElementIds: { [line.id]: true } });
|
||||
API.setElements([line]);
|
||||
API.setAppState({ selectedElementIds: { [line.id]: true } });
|
||||
|
||||
await checkHorizontalFlip(
|
||||
MULTIPOINT_LINEAR_ELEMENT_FLIP_TOLERANCE_IN_PIXELS,
|
||||
|
@ -548,8 +551,8 @@ describe("line", () => {
|
|||
|
||||
it("flips an unrotated line vertically with line inside min/max points bounds", async () => {
|
||||
const line = createLinearElementWithCurveInsideMinMaxPoints("line");
|
||||
h.elements = [line];
|
||||
h.app.setState({ selectedElementIds: { [line.id]: true } });
|
||||
API.setElements([line]);
|
||||
API.setAppState({ selectedElementIds: { [line.id]: true } });
|
||||
|
||||
await checkVerticalFlip(MULTIPOINT_LINEAR_ELEMENT_FLIP_TOLERANCE_IN_PIXELS);
|
||||
});
|
||||
|
@ -563,8 +566,8 @@ describe("line", () => {
|
|||
//TODO: elements with curve outside minMax points have a wrong bounding box
|
||||
it.skip("flips an unrotated line horizontally with line outside min/max points bounds", async () => {
|
||||
const line = createLinearElementsWithCurveOutsideMinMaxPoints("line");
|
||||
h.elements = [line];
|
||||
h.app.setState({ selectedElementIds: { [line.id]: true } });
|
||||
API.setElements([line]);
|
||||
API.setAppState({ selectedElementIds: { [line.id]: true } });
|
||||
|
||||
await checkHorizontalFlip(
|
||||
MULTIPOINT_LINEAR_ELEMENT_FLIP_TOLERANCE_IN_PIXELS,
|
||||
|
@ -574,8 +577,8 @@ describe("line", () => {
|
|||
//TODO: elements with curve outside minMax points have a wrong bounding box
|
||||
it.skip("flips an unrotated line vertically with line outside min/max points bounds", async () => {
|
||||
const line = createLinearElementsWithCurveOutsideMinMaxPoints("line");
|
||||
h.elements = [line];
|
||||
h.app.setState({ selectedElementIds: { [line.id]: true } });
|
||||
API.setElements([line]);
|
||||
API.setAppState({ selectedElementIds: { [line.id]: true } });
|
||||
|
||||
await checkVerticalFlip(MULTIPOINT_LINEAR_ELEMENT_FLIP_TOLERANCE_IN_PIXELS);
|
||||
});
|
||||
|
@ -585,9 +588,9 @@ describe("line", () => {
|
|||
const originalAngle = Math.PI / 4;
|
||||
const expectedAngle = (7 * Math.PI) / 4;
|
||||
const line = createLinearElementsWithCurveOutsideMinMaxPoints("line");
|
||||
mutateElement(line, { angle: originalAngle });
|
||||
h.elements = [line];
|
||||
h.app.setState({ selectedElementIds: { [line.id]: true } });
|
||||
API.updateElement(line, { angle: originalAngle });
|
||||
API.setElements([line]);
|
||||
API.setAppState({ selectedElementIds: { [line.id]: true } });
|
||||
|
||||
await checkRotatedHorizontalFlip(
|
||||
expectedAngle,
|
||||
|
@ -600,9 +603,9 @@ describe("line", () => {
|
|||
const originalAngle = Math.PI / 4;
|
||||
const expectedAngle = (7 * Math.PI) / 4;
|
||||
const line = createLinearElementsWithCurveOutsideMinMaxPoints("line");
|
||||
mutateElement(line, { angle: originalAngle });
|
||||
h.elements = [line];
|
||||
h.app.setState({ selectedElementIds: { [line.id]: true } });
|
||||
API.updateElement(line, { angle: originalAngle });
|
||||
API.setElements([line]);
|
||||
API.setAppState({ selectedElementIds: { [line.id]: true } });
|
||||
|
||||
await checkRotatedVerticalFlip(
|
||||
expectedAngle,
|
||||
|
@ -619,12 +622,14 @@ describe("line", () => {
|
|||
const originalAngle = Math.PI / 4;
|
||||
const expectedAngle = (7 * Math.PI) / 4;
|
||||
const line = createLinearElementWithCurveInsideMinMaxPoints("line");
|
||||
h.elements = [line];
|
||||
h.state.selectedElementIds = {
|
||||
...h.state.selectedElementIds,
|
||||
[line.id]: true,
|
||||
};
|
||||
mutateElement(line, {
|
||||
API.setElements([line]);
|
||||
API.setAppState({
|
||||
selectedElementIds: {
|
||||
...h.state.selectedElementIds,
|
||||
[line.id]: true,
|
||||
},
|
||||
});
|
||||
API.updateElement(line, {
|
||||
angle: originalAngle,
|
||||
});
|
||||
|
||||
|
@ -638,12 +643,14 @@ describe("line", () => {
|
|||
const originalAngle = Math.PI / 4;
|
||||
const expectedAngle = (7 * Math.PI) / 4;
|
||||
const line = createLinearElementWithCurveInsideMinMaxPoints("line");
|
||||
h.elements = [line];
|
||||
h.state.selectedElementIds = {
|
||||
...h.state.selectedElementIds,
|
||||
[line.id]: true,
|
||||
};
|
||||
mutateElement(line, {
|
||||
API.setElements([line]);
|
||||
API.setAppState({
|
||||
selectedElementIds: {
|
||||
...h.state.selectedElementIds,
|
||||
[line.id]: true,
|
||||
},
|
||||
});
|
||||
API.updateElement(line, {
|
||||
angle: originalAngle,
|
||||
});
|
||||
|
||||
|
@ -669,20 +676,24 @@ describe("freedraw", () => {
|
|||
it("flips an unrotated drawing horizontally correctly", async () => {
|
||||
const draw = createAndReturnOneDraw();
|
||||
// select draw, since not done automatically
|
||||
h.state.selectedElementIds = {
|
||||
...h.state.selectedElementIds,
|
||||
[draw.id]: true,
|
||||
};
|
||||
API.setAppState({
|
||||
selectedElementIds: {
|
||||
...h.state.selectedElementIds,
|
||||
[draw.id]: true,
|
||||
},
|
||||
});
|
||||
await checkHorizontalFlip();
|
||||
});
|
||||
|
||||
it("flips an unrotated drawing vertically correctly", async () => {
|
||||
const draw = createAndReturnOneDraw();
|
||||
// select draw, since not done automatically
|
||||
h.state.selectedElementIds = {
|
||||
...h.state.selectedElementIds,
|
||||
[draw.id]: true,
|
||||
};
|
||||
API.setAppState({
|
||||
selectedElementIds: {
|
||||
...h.state.selectedElementIds,
|
||||
[draw.id]: true,
|
||||
},
|
||||
});
|
||||
await checkVerticalFlip();
|
||||
});
|
||||
|
||||
|
@ -692,10 +703,12 @@ describe("freedraw", () => {
|
|||
|
||||
const draw = createAndReturnOneDraw(originalAngle);
|
||||
// select draw, since not done automatically
|
||||
h.state.selectedElementIds = {
|
||||
...h.state.selectedElementIds,
|
||||
[draw.id]: true,
|
||||
};
|
||||
API.setAppState({
|
||||
selectedElementIds: {
|
||||
...h.state.selectedElementIds,
|
||||
[draw.id]: true,
|
||||
},
|
||||
});
|
||||
|
||||
await checkRotatedHorizontalFlip(expectedAngle);
|
||||
});
|
||||
|
@ -706,10 +719,12 @@ describe("freedraw", () => {
|
|||
|
||||
const draw = createAndReturnOneDraw(originalAngle);
|
||||
// select draw, since not done automatically
|
||||
h.state.selectedElementIds = {
|
||||
...h.state.selectedElementIds,
|
||||
[draw.id]: true,
|
||||
};
|
||||
API.setAppState({
|
||||
selectedElementIds: {
|
||||
...h.state.selectedElementIds,
|
||||
[draw.id]: true,
|
||||
},
|
||||
});
|
||||
|
||||
await checkRotatedVerticalFlip(expectedAngle);
|
||||
});
|
||||
|
@ -767,7 +782,7 @@ describe("image", () => {
|
|||
expect(API.getSelectedElements()[0].type).toEqual("image");
|
||||
expect(h.app.files.fileId).toBeDefined();
|
||||
});
|
||||
mutateElement(h.elements[0], {
|
||||
API.updateElement(h.elements[0], {
|
||||
angle: originalAngle,
|
||||
});
|
||||
await checkRotatedHorizontalFlip(expectedAngle);
|
||||
|
@ -786,7 +801,7 @@ describe("image", () => {
|
|||
expect(API.getSelectedElements()[0].type).toEqual("image");
|
||||
expect(h.app.files.fileId).toBeDefined();
|
||||
});
|
||||
mutateElement(h.elements[0], {
|
||||
API.updateElement(h.elements[0], {
|
||||
angle: originalAngle,
|
||||
});
|
||||
|
||||
|
@ -827,8 +842,7 @@ describe("mutliple elements", () => {
|
|||
".excalidraw-textEditorContainer > textarea",
|
||||
)!;
|
||||
fireEvent.input(editor, { target: { value: "arrow" } });
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
Keyboard.keyPress(KEYS.ESCAPE);
|
||||
Keyboard.exitTextEditor(editor);
|
||||
|
||||
const rectangle = UI.createElement("rectangle", {
|
||||
x: 0,
|
||||
|
@ -842,12 +856,11 @@ describe("mutliple elements", () => {
|
|||
".excalidraw-textEditorContainer > textarea",
|
||||
)!;
|
||||
fireEvent.input(editor, { target: { value: "rect\ntext" } });
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
Keyboard.keyPress(KEYS.ESCAPE);
|
||||
Keyboard.exitTextEditor(editor);
|
||||
|
||||
mouse.select([arrow, rectangle]);
|
||||
h.app.actionManager.executeAction(actionFlipHorizontal);
|
||||
h.app.actionManager.executeAction(actionFlipVertical);
|
||||
API.executeAction(actionFlipHorizontal);
|
||||
API.executeAction(actionFlipVertical);
|
||||
|
||||
const arrowText = h.elements[1] as ExcalidrawTextElementWithContainer;
|
||||
const arrowTextPos = getBoundTextElementPosition(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue