summaryrefslogtreecommitdiffstats
path: root/packages/excalidraw/tests/appState.test.tsx
diff options
context:
space:
mode:
authorkj_sh6042026-03-15 16:19:35 -0400
committerkj_sh6042026-03-15 16:19:35 -0400
commit6ec259a0e71174651bae95d4628138bf6fd68742 (patch)
tree5e33c6a5ec091ecabfcb257fdc7b6a88ed8754ac /packages/excalidraw/tests/appState.test.tsx
parent16c8578b15c727f22921f8a80a56ee4d4e7f2272 (diff)
refactor: packages/
Diffstat (limited to 'packages/excalidraw/tests/appState.test.tsx')
-rw-r--r--packages/excalidraw/tests/appState.test.tsx81
1 files changed, 81 insertions, 0 deletions
diff --git a/packages/excalidraw/tests/appState.test.tsx b/packages/excalidraw/tests/appState.test.tsx
new file mode 100644
index 0000000..4a937cd
--- /dev/null
+++ b/packages/excalidraw/tests/appState.test.tsx
@@ -0,0 +1,81 @@
+import React from "react";
+import { fireEvent, queryByTestId, render, waitFor } from "./test-utils";
+import { Excalidraw } from "../index";
+import { API } from "./helpers/api";
+import { getDefaultAppState } from "../appState";
+import { EXPORT_DATA_TYPES, MIME_TYPES } from "../constants";
+import { Pointer, UI } from "./helpers/ui";
+import type { ExcalidrawTextElement } from "../element/types";
+
+const { h } = window;
+
+describe("appState", () => {
+ it("drag&drop file doesn't reset non-persisted appState", async () => {
+ const defaultAppState = getDefaultAppState();
+ const exportBackground = !defaultAppState.exportBackground;
+
+ await render(
+ <Excalidraw
+ initialData={{
+ appState: {
+ exportBackground,
+ viewBackgroundColor: "#F00",
+ },
+ }}
+ />,
+ {},
+ );
+
+ await waitFor(() => {
+ expect(h.state.exportBackground).toBe(exportBackground);
+ expect(h.state.viewBackgroundColor).toBe("#F00");
+ });
+
+ await API.drop(
+ new Blob(
+ [
+ JSON.stringify({
+ type: EXPORT_DATA_TYPES.excalidraw,
+ appState: {
+ viewBackgroundColor: "#000",
+ },
+ elements: [API.createElement({ type: "rectangle", id: "A" })],
+ }),
+ ],
+ { type: MIME_TYPES.json },
+ ),
+ );
+
+ await waitFor(() => {
+ expect(h.elements).toEqual([expect.objectContaining({ id: "A" })]);
+ // non-imported prop → retain
+ expect(h.state.exportBackground).toBe(exportBackground);
+ // imported prop → overwrite
+ expect(h.state.viewBackgroundColor).toBe("#000");
+ });
+ });
+
+ it("changing fontSize with text tool selected (no element created yet)", async () => {
+ const { container } = await render(
+ <Excalidraw
+ initialData={{
+ appState: {
+ currentItemFontSize: 30,
+ },
+ }}
+ />,
+ );
+
+ UI.clickTool("text");
+
+ expect(h.state.currentItemFontSize).toBe(30);
+ fireEvent.click(queryByTestId(container, "fontSize-small")!);
+ expect(h.state.currentItemFontSize).toBe(16);
+
+ const mouse = new Pointer("mouse");
+
+ mouse.clickAt(100, 100);
+
+ expect((h.elements[0] as ExcalidrawTextElement).fontSize).toBe(16);
+ });
+});