|
@@ -13,6 +13,7 @@ import type { NormalizedZoomValue } from "../types";
|
|
|
import { API } from "./helpers/api";
|
|
|
import { createPasteEvent, serializeAsClipboardJSON } from "../clipboard";
|
|
|
import { arrayToMap } from "../utils";
|
|
|
+import { mockMermaidToExcalidraw } from "./helpers/mocks";
|
|
|
|
|
|
const { h } = window;
|
|
|
|
|
@@ -435,3 +436,83 @@ describe("pasting & frames", () => {
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
+
|
|
|
+describe("clipboard - pasting mermaid definition", () => {
|
|
|
+ beforeAll(() => {
|
|
|
+ mockMermaidToExcalidraw({
|
|
|
+ parseMermaidToExcalidraw: async (definition) => {
|
|
|
+ const lines = definition.split("\n");
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ if (lines.some((line) => line === "flowchart TD")) {
|
|
|
+ resolve({
|
|
|
+ elements: [
|
|
|
+ {
|
|
|
+ id: "rect1",
|
|
|
+ type: "rectangle",
|
|
|
+ groupIds: [],
|
|
|
+ x: 0,
|
|
|
+ y: 0,
|
|
|
+ width: 69.703125,
|
|
|
+ height: 44,
|
|
|
+ strokeWidth: 2,
|
|
|
+ label: {
|
|
|
+ groupIds: [],
|
|
|
+ text: "A",
|
|
|
+ fontSize: 20,
|
|
|
+ },
|
|
|
+ link: null,
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ reject(new Error("ERROR"));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ it("should detect and paste as mermaid", async () => {
|
|
|
+ const text = "flowchart TD\nA";
|
|
|
+
|
|
|
+ pasteWithCtrlCmdV(text);
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(h.elements.length).toEqual(2);
|
|
|
+ expect(h.elements).toEqual(
|
|
|
+ expect.arrayContaining([
|
|
|
+ expect.objectContaining({ type: "rectangle" }),
|
|
|
+ expect.objectContaining({ type: "text", text: "A" }),
|
|
|
+ ]),
|
|
|
+ );
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ it("should support directives", async () => {
|
|
|
+ const text = "%%{init: { **config** } }%%\nflowchart TD\nA";
|
|
|
+
|
|
|
+ pasteWithCtrlCmdV(text);
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(h.elements.length).toEqual(2);
|
|
|
+ expect(h.elements).toEqual(
|
|
|
+ expect.arrayContaining([
|
|
|
+ expect.objectContaining({ type: "rectangle" }),
|
|
|
+ expect.objectContaining({ type: "text", text: "A" }),
|
|
|
+ ]),
|
|
|
+ );
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ it("should paste as normal text if invalid mermaid", async () => {
|
|
|
+ const text = "flowchart TD xx\nA";
|
|
|
+ pasteWithCtrlCmdV(text);
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(h.elements.length).toEqual(2);
|
|
|
+ expect(h.elements).toEqual(
|
|
|
+ expect.arrayContaining([
|
|
|
+ expect.objectContaining({ type: "text", text: "flowchart TD xx" }),
|
|
|
+ expect.objectContaining({ type: "text", text: "A" }),
|
|
|
+ ]),
|
|
|
+ );
|
|
|
+ });
|
|
|
+ });
|
|
|
+});
|