import { describe, expect, it } from "vitest"; import { removeHopFromNode } from "@/lib/npc-dialogue/dialogue"; import type { DialogueNode } from "@/lib/npc-dialogue/dialogue"; const node = (type: DialogueNode["type"], data: DialogueNode["data"]): DialogueNode => ({ id: `${type}-1`, type, position: { x: 0, y: 0 }, data, }); describe("removeHopFromNode (edge deletion scrubs the derived hop)", () => { it("removes a single choice row by its handle", () => { const n = node("choice", { choices: [{ label: "a", target: "x" }, { label: "b", target: "y" }] }); const next = removeHopFromNode(n, "c0"); expect(next.data.choices).toEqual([{ label: "b", target: "y" }]); // the other row is untouched expect(n.data.choices).toEqual([ { label: "a", target: "x" }, { label: "b", target: "y" }, ]); }); it("removes a condition branch by name", () => { const yes = node("condition", { condition: { kind: "flag", key: "k", op: "is_true" }, trueTarget: "t", falseTarget: "f" }); expect(removeHopFromNode(yes, "true").data.trueTarget).toBeUndefined(); expect(removeHopFromNode(yes, "true").data.falseTarget).toBe("f"); const no = node("condition", { condition: { kind: "flag", key: "k", op: "is_true" }, trueTarget: "t", falseTarget: "f" }); const falseRemoved = removeHopFromNode(no, "false"); expect(falseRemoved.data.falseTarget).toBeUndefined(); expect(falseRemoved.data.trueTarget).toBe("t"); }); it("clears the single continuation on a plain node", () => { const n = node("dialogue", { body: "hi", next: { label: "next", target: "t" } }); expect(removeHopFromNode(n).data.next).toBeUndefined(); }); it("leaves a choice node unchanged when the handle is not a numbered row", () => { const n = node("choice", { choices: [{ label: "a", target: "x" }] }); expect(removeHopFromNode(n, undefined)).toEqual(n); }); });