feat(f7.1): flowchart node/edge diff + styling emission (#22)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -35,3 +35,50 @@ describe("parseFlowchart", () => {
|
||||
expect(g.edges).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
import { diffFlowchart } from "../src/mermaidFlowchartDiff";
|
||||
|
||||
describe("diffFlowchart", () => {
|
||||
it("colors an added node with the cwAdded class", () => {
|
||||
const before = "flowchart LR\n A-->B";
|
||||
const current = "flowchart LR\n A-->B\n B-->C";
|
||||
const out = diffFlowchart(before, current);
|
||||
expect(out).toContain("classDef cwAdded");
|
||||
expect(out).toMatch(/class\s+C\s+cwAdded/);
|
||||
});
|
||||
|
||||
it("colors a changed node (same id, new label) with cwChanged", () => {
|
||||
const before = "flowchart LR\n A[Old]-->B";
|
||||
const current = "flowchart LR\n A[New]-->B";
|
||||
const out = diffFlowchart(before, current);
|
||||
expect(out).toMatch(/class\s+A\s+cwChanged/);
|
||||
});
|
||||
|
||||
it("styles an added edge via linkStyle on its current index", () => {
|
||||
const before = "flowchart LR\n A-->B";
|
||||
const current = "flowchart LR\n A-->B\n A-->C";
|
||||
const out = diffFlowchart(before, current);
|
||||
// edge index 1 (A-->C) is the added one
|
||||
expect(out).toMatch(/linkStyle\s+1\s+stroke:#2ea043/);
|
||||
});
|
||||
|
||||
it("ghosts a removed node in place with cwRemoved (re-injected decl)", () => {
|
||||
const before = "flowchart LR\n A-->B\n B-->C[Gone]";
|
||||
const current = "flowchart LR\n A-->B";
|
||||
const out = diffFlowchart(before, current);
|
||||
expect(out).toContain("C[Gone]"); // re-injected
|
||||
expect(out).toMatch(/class\s+C\s+cwRemoved/);
|
||||
});
|
||||
|
||||
it("is deterministic (same inputs → identical output)", () => {
|
||||
const before = "flowchart LR\n A-->B";
|
||||
const current = "flowchart LR\n A-->B\n B-->C\n A-->D";
|
||||
expect(diffFlowchart(before, current)).toBe(diffFlowchart(before, current));
|
||||
});
|
||||
|
||||
it("preserves the original current source as the prefix", () => {
|
||||
const current = "flowchart LR\n A-->B\n B-->C";
|
||||
const out = diffFlowchart("flowchart LR\n A-->B", current);
|
||||
expect(out.startsWith(current)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user