import { describe, it, expect } from "vitest"; import { detectDiagramType, diffMermaid } from "../src/mermaidDiff"; describe("detectDiagramType", () => { it("detects flowchart from `flowchart` / `graph` headers", () => { expect(detectDiagramType("flowchart LR\n a-->b")).toBe("flowchart"); expect(detectDiagramType("graph TD\n a-->b")).toBe("flowchart"); expect(detectDiagramType(" \n%% c\ngraph TD")).toBe("flowchart"); }); it("detects sequence from `sequenceDiagram`", () => { expect(detectDiagramType("sequenceDiagram\n A->>B: hi")).toBe("sequence"); }); it("returns `other` for unsupported types", () => { expect(detectDiagramType("classDiagram\n class A")).toBe("other"); expect(detectDiagramType("stateDiagram-v2\n s1 --> s2")).toBe("other"); expect(detectDiagramType("")).toBe("other"); }); }); describe("diffMermaid", () => { it("falls back for an unsupported diagram type", () => { expect(diffMermaid("classDiagram\n class A", "classDiagram\n class B")).toEqual({ kind: "fallback" }); }); it("falls back (never throws) when the differ throws", () => { // A deliberately malformed flowchart still degrades gracefully. const r = diffMermaid("flowchart LR", "flowchart LR\n a -->"); expect(["augmented", "fallback"]).toContain(r.kind); }); });