1
0
Fork 0
polaris-task-force/tests/int/npc-dialogue-remove-hop.int.spec.ts
Z8MB1E a96eddf32c feat(npc-dialogue): bigger flow handles + delete edges via Delete
- Enlarge flow-editor wire handles from size-2 (8px) to size-3 (12px) so
  they are easier to click and grab.
- Select an edge by clicking it, then remove it with the Delete key.
  Selection is tracked in state and the highlight renders through BaseEdge
  stroke props so the chosen line stands out.
- Edges are a derived projection, so deletion scrubs the hop from the
  source node data via a new pure removeHopFromNode() helper in dialogue.ts
  (choice row, condition branch, or single continuation).
- Add tests/int/npc-dialogue-remove-hop.int.spec.ts (4 tests).
2026-10-07 14:25:14 -04:00

45 lines
1.9 KiB
TypeScript

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);
});
});