38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { parseDiagram, renderSvg } from "../../src/core/diagram";
|
|
describe("diagram grammar", () => {
|
|
it("parses and escapes flowcharts", () => {
|
|
const d = parseDiagram("flowchart LR\nA[<script>] -->|safe| B{Choice}");
|
|
expect(d.nodes).toHaveLength(2);
|
|
const svg = renderSvg(d);
|
|
expect(svg).toContain("<script>");
|
|
expect(svg).not.toContain("<script>");
|
|
});
|
|
it("supports sequence, class and state", () => {
|
|
const sequence = parseDiagram(
|
|
"sequenceDiagram\nparticipant A as Ada\nparticipant B\nA-->>B: hello",
|
|
);
|
|
expect(sequence.mode).toBe("sequence");
|
|
expect(sequence.nodes.map((node) => node.id)).toEqual(["A", "B"]);
|
|
expect(sequence.edges[0]).toMatchObject({
|
|
from: "A",
|
|
to: "B",
|
|
dashed: true,
|
|
});
|
|
expect(
|
|
parseDiagram("classDiagram\nclass A\nA : +field\nA <|-- B").nodes[0]
|
|
?.members,
|
|
).toEqual(["+field"]);
|
|
expect(parseDiagram("stateDiagram-v2\nIdle --> Ready : go").mode).toBe(
|
|
"state",
|
|
);
|
|
});
|
|
it("diagnoses directives without executing", () => {
|
|
const d = parseDiagram(
|
|
"flowchart LR\n%%{init: {}}%%\nclick A https://bad.test\nA-->B",
|
|
);
|
|
expect(d.diagnostics).toHaveLength(2);
|
|
expect(renderSvg(d)).not.toContain("bad.test");
|
|
});
|
|
});
|