mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-04-14 16:40:58 -04:00
* Remove width/height from the ".excalidraw" container so it will sized automatically. * updated all ref calculation to ".excalidraw" instead of parent since now ".excalidraw" will get resized * Remove props width/height as its not needed anymore. * Resize handler is also not needed anymore. * Position absolute canvas due to #3379 (comment) * move css to style and remove one extra rerendering * factor out mock logic for test * set height, width so as to avoid unnecessary updates of regression snap * better mock * better type checking and omit width,height from getDefaultAppState and also restore * revert * default to window dimensions in constructor * update docs * update * update * tweaks
54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
import React from "react";
|
|
import {
|
|
mockBoundingClientRect,
|
|
render,
|
|
restoreOriginalGetBoundingClientRect,
|
|
waitFor,
|
|
} from "./test-utils";
|
|
import Excalidraw from "../packages/excalidraw/index";
|
|
import { API } from "./helpers/api";
|
|
|
|
const { h } = window;
|
|
|
|
describe("appState", () => {
|
|
it("scroll-to-content on init works with non-zero offsets", async () => {
|
|
const WIDTH = 200;
|
|
const HEIGHT = 100;
|
|
const OFFSET_LEFT = 20;
|
|
const OFFSET_TOP = 10;
|
|
|
|
const ELEM_WIDTH = 100;
|
|
const ELEM_HEIGHT = 60;
|
|
|
|
mockBoundingClientRect();
|
|
|
|
await render(
|
|
<div>
|
|
<Excalidraw
|
|
initialData={{
|
|
elements: [
|
|
API.createElement({
|
|
type: "rectangle",
|
|
id: "A",
|
|
width: ELEM_WIDTH,
|
|
height: ELEM_HEIGHT,
|
|
}),
|
|
],
|
|
scrollToContent: true,
|
|
}}
|
|
/>
|
|
</div>,
|
|
);
|
|
await waitFor(() => {
|
|
expect(h.state.width).toBe(200);
|
|
expect(h.state.height).toBe(100);
|
|
expect(h.state.offsetLeft).toBe(OFFSET_LEFT);
|
|
expect(h.state.offsetTop).toBe(OFFSET_TOP);
|
|
|
|
// assert scroll is in center
|
|
expect(h.state.scrollX).toBe(WIDTH / 2 - ELEM_WIDTH / 2);
|
|
expect(h.state.scrollY).toBe(HEIGHT / 2 - ELEM_HEIGHT / 2);
|
|
});
|
|
restoreOriginalGetBoundingClientRect();
|
|
});
|
|
});
|