mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-09-21 16:29:58 +02:00
chore: bump @testing-library/react
12.1.5
-> 16.0.0
(#8322)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { render } from "./test-utils";
|
||||
import React from "react";
|
||||
import { act, render } from "./test-utils";
|
||||
import { API } from "./helpers/api";
|
||||
|
||||
import { Excalidraw } from "../index";
|
||||
@@ -6,6 +7,17 @@ import { vi } from "vitest";
|
||||
|
||||
const { h } = window;
|
||||
|
||||
const waitForNextAnimationFrame = () => {
|
||||
return act(
|
||||
() =>
|
||||
new Promise((resolve) => {
|
||||
requestAnimationFrame(() => {
|
||||
requestAnimationFrame(resolve);
|
||||
});
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
describe("fitToContent", () => {
|
||||
it("should zoom to fit the selected element", async () => {
|
||||
await render(<Excalidraw />);
|
||||
@@ -22,7 +34,9 @@ describe("fitToContent", () => {
|
||||
|
||||
expect(h.state.zoom.value).toBe(1);
|
||||
|
||||
h.app.scrollToContent(rectElement, { fitToContent: true });
|
||||
act(() => {
|
||||
h.app.scrollToContent(rectElement, { fitToContent: true });
|
||||
});
|
||||
|
||||
// element is 10x taller than the viewport size,
|
||||
// zoom should be at least 1/10
|
||||
@@ -51,8 +65,10 @@ describe("fitToContent", () => {
|
||||
|
||||
expect(h.state.zoom.value).toBe(1);
|
||||
|
||||
h.app.scrollToContent([topLeft, bottomRight], {
|
||||
fitToContent: true,
|
||||
act(() => {
|
||||
h.app.scrollToContent([topLeft, bottomRight], {
|
||||
fitToContent: true,
|
||||
});
|
||||
});
|
||||
|
||||
// elements take 100x100, which is 10x bigger than the viewport size,
|
||||
@@ -77,7 +93,9 @@ describe("fitToContent", () => {
|
||||
expect(h.state.scrollX).toBe(0);
|
||||
expect(h.state.scrollY).toBe(0);
|
||||
|
||||
h.app.scrollToContent(rectElement);
|
||||
act(() => {
|
||||
h.app.scrollToContent(rectElement);
|
||||
});
|
||||
|
||||
// zoom level should stay the same
|
||||
expect(h.state.zoom.value).toBe(1);
|
||||
@@ -88,14 +106,6 @@ describe("fitToContent", () => {
|
||||
});
|
||||
});
|
||||
|
||||
const waitForNextAnimationFrame = () => {
|
||||
return new Promise((resolve) => {
|
||||
requestAnimationFrame(() => {
|
||||
requestAnimationFrame(resolve);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
describe("fitToContent animated", () => {
|
||||
beforeEach(() => {
|
||||
vi.spyOn(window, "requestAnimationFrame");
|
||||
@@ -118,7 +128,9 @@ describe("fitToContent animated", () => {
|
||||
y: -100,
|
||||
});
|
||||
|
||||
h.app.scrollToContent(rectElement, { animate: true });
|
||||
act(() => {
|
||||
h.app.scrollToContent(rectElement, { animate: true });
|
||||
});
|
||||
|
||||
expect(window.requestAnimationFrame).toHaveBeenCalled();
|
||||
|
||||
@@ -157,7 +169,9 @@ describe("fitToContent animated", () => {
|
||||
expect(h.state.scrollX).toBe(0);
|
||||
expect(h.state.scrollY).toBe(0);
|
||||
|
||||
h.app.scrollToContent(rectElement, { animate: true, fitToContent: true });
|
||||
act(() => {
|
||||
h.app.scrollToContent(rectElement, { animate: true, fitToContent: true });
|
||||
});
|
||||
|
||||
expect(window.requestAnimationFrame).toHaveBeenCalled();
|
||||
|
||||
|
Reference in New Issue
Block a user