// @vitest-environment node import { describe, expect, it } from "vitest"; import type { DialogueNode } from "@/lib/npc-dialogue/dialogue"; import { waitsForContinue } from "@/lib/npc-dialogue/dialogue"; /** * The Continue gate is off unless an author turns it on, and it only means * something where a successor exists. Both facts are one function so the * runtime and the editor's draft preview cannot disagree. */ function node(data: Record, type: DialogueNode["type"] = "dialogue"): DialogueNode { return { id: "n1", type, position: { x: 0, y: 0 }, data } as DialogueNode; } describe("continue gate", () => { it("is off by default", () => { expect(waitsForContinue(node({ body: "Hello." }))).toBe(false); expect(waitsForContinue(node({ body: "Hello.", next: { target: "n2" } }))).toBe(false); }); it("holds a line that has somewhere to go", () => { expect( waitsForContinue(node({ body: "Hello.", requireContinue: true, next: { target: "n2" } })), ).toBe(true); }); it("ignores the flag on a dead end, where there is nothing to continue to", () => { expect(waitsForContinue(node({ body: "Hello.", requireContinue: true }))).toBe(false); expect( waitsForContinue(node({ body: "Hello.", requireContinue: true, next: { target: "" } })), ).toBe(false); }); it("applies to any node type that carries a continuation", () => { expect( waitsForContinue( node({ body: "A scene.", requireContinue: true, next: { target: "n2" } }, "event"), ), ).toBe(true); }); });