feat(f7.1): sequence participant/message diff + rect emission (#22)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -22,3 +22,44 @@ describe("parseSequence", () => {
|
||||
expect(d.statements).toEqual(["A->>B: hi"]);
|
||||
});
|
||||
});
|
||||
|
||||
import { diffSequence } from "../src/mermaidSequenceDiff";
|
||||
|
||||
const rectCount = (s: string, rgb: string) => s.split(`rect rgb(${rgb})`).length - 1;
|
||||
|
||||
describe("diffSequence", () => {
|
||||
it("wraps an added message in a green rect", () => {
|
||||
const before = "sequenceDiagram\n A->>B: hi";
|
||||
const current = "sequenceDiagram\n A->>B: hi\n B->>C: on";
|
||||
const out = diffSequence(before, current);
|
||||
expect(rectCount(out, "46, 160, 67")).toBe(1); // CW_COLORS.added as rgb
|
||||
expect(out).toContain("B->>C: on");
|
||||
});
|
||||
|
||||
it("ghosts a removed message back in a grey rect", () => {
|
||||
const before = "sequenceDiagram\n A->>B: hi\n B->>C: gone";
|
||||
const current = "sequenceDiagram\n A->>B: hi";
|
||||
const out = diffSequence(before, current);
|
||||
expect(out).toContain("B->>C: gone");
|
||||
expect(rectCount(out, "128, 128, 128")).toBe(1);
|
||||
});
|
||||
|
||||
it("re-declares a removed participant so it still appears", () => {
|
||||
const before = "sequenceDiagram\n participant A\n participant B\n participant C\n A->>C: x";
|
||||
const current = "sequenceDiagram\n participant A\n participant B\n A->>B: y";
|
||||
const out = diffSequence(before, current);
|
||||
expect(out).toMatch(/participant C/);
|
||||
});
|
||||
|
||||
it("keeps an unchanged message outside any rect", () => {
|
||||
const doc = "sequenceDiagram\n A->>B: hi";
|
||||
const out = diffSequence(doc, doc);
|
||||
expect(out).not.toContain("rect rgb");
|
||||
});
|
||||
|
||||
it("is deterministic", () => {
|
||||
const before = "sequenceDiagram\n A->>B: hi";
|
||||
const current = "sequenceDiagram\n A->>B: hi\n B->>A: bye";
|
||||
expect(diffSequence(before, current)).toBe(diffSequence(before, current));
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user