summaryrefslogtreecommitdiffstats
path: root/packages/excalidraw/tests/MermaidToExcalidraw.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/MermaidToExcalidraw.test.tsx
parent16c8578b15c727f22921f8a80a56ee4d4e7f2272 (diff)
refactor: packages/
Diffstat (limited to 'packages/excalidraw/tests/MermaidToExcalidraw.test.tsx')
-rw-r--r--packages/excalidraw/tests/MermaidToExcalidraw.test.tsx117
1 files changed, 117 insertions, 0 deletions
diff --git a/packages/excalidraw/tests/MermaidToExcalidraw.test.tsx b/packages/excalidraw/tests/MermaidToExcalidraw.test.tsx
new file mode 100644
index 0000000..05727a0
--- /dev/null
+++ b/packages/excalidraw/tests/MermaidToExcalidraw.test.tsx
@@ -0,0 +1,117 @@
+import React from "react";
+import { render, waitFor } from "./test-utils";
+import { Excalidraw } from "../index";
+import { expect } from "vitest";
+import { getTextEditor, updateTextEditor } from "./queries/dom";
+import { mockMermaidToExcalidraw } from "./helpers/mocks";
+
+mockMermaidToExcalidraw({
+ mockRef: true,
+ parseMermaidToExcalidraw: async (definition) => {
+ const firstLine = definition.split("\n")[0];
+ return new Promise((resolve, reject) => {
+ if (firstLine === "flowchart TD") {
+ resolve({
+ elements: [
+ {
+ id: "Start",
+ type: "rectangle",
+ groupIds: [],
+ x: 0,
+ y: 0,
+ width: 69.703125,
+ height: 44,
+ strokeWidth: 2,
+ label: {
+ groupIds: [],
+ text: "Start",
+ fontSize: 20,
+ },
+ link: null,
+ },
+ {
+ id: "Stop",
+ type: "rectangle",
+ groupIds: [],
+ x: 2.7109375,
+ y: 94,
+ width: 64.28125,
+ height: 44,
+ strokeWidth: 2,
+ label: {
+ groupIds: [],
+ text: "Stop",
+ fontSize: 20,
+ },
+ link: null,
+ },
+ {
+ id: "Start_Stop",
+ type: "arrow",
+ groupIds: [],
+ x: 34.852,
+ y: 44,
+ strokeWidth: 2,
+ points: [
+ [0, 0],
+ [0, 50],
+ ],
+ roundness: {
+ type: 2,
+ },
+ start: {
+ id: "Start",
+ },
+ end: {
+ id: "Stop",
+ },
+ },
+ ],
+ });
+ } else {
+ reject(new Error("ERROR"));
+ }
+ });
+ },
+});
+
+describe("Test <MermaidToExcalidraw/>", () => {
+ beforeEach(async () => {
+ await render(
+ <Excalidraw
+ initialData={{
+ appState: {
+ openDialog: { name: "ttd", tab: "mermaid" },
+ },
+ }}
+ />,
+ );
+ });
+
+ it("should open mermaid popup when active tool is mermaid", async () => {
+ const dialog = document.querySelector(".ttd-dialog")!;
+ await waitFor(() => expect(dialog.querySelector("canvas")).not.toBeNull());
+ expect(dialog.outerHTML).toMatchSnapshot();
+ });
+
+ it("should show error in preview when mermaid library throws error", async () => {
+ const dialog = document.querySelector(".ttd-dialog")!;
+
+ expect(dialog).not.toBeNull();
+
+ const selector = ".ttd-dialog-input";
+ let editor = await getTextEditor(selector, true);
+
+ expect(dialog.querySelector('[data-testid="mermaid-error"]')).toBeNull();
+
+ expect(editor.textContent).toMatchSnapshot();
+
+ updateTextEditor(editor, "flowchart TD1");
+ editor = await getTextEditor(selector, false);
+
+ expect(editor.textContent).toBe("flowchart TD1");
+ expect(
+ dialog.querySelector('[data-testid="mermaid-error"]'),
+ ).toMatchInlineSnapshot("null");
+ });
+});