import { describe, expect, it } from "vitest"; import { normalizeTypewriterPreference, resolveTypewriter } from "@/lib/npc-dialogue/presentation"; describe("typewriter preference resolution", () => { it("follows the unit default unless the player chose otherwise", () => { for (const preference of [undefined, null, "default", "nonsense"]) { expect(resolveTypewriter(preference, true)).toBe(true); expect(resolveTypewriter(preference, false)).toBe(false); } }); it("lets the player override the unit default in both directions", () => { // Someone who dislikes the animation can turn it off even when it is on by // default, and someone who wants it keeps it when the unit turns it off. expect(resolveTypewriter("off", true)).toBe(false); expect(resolveTypewriter("on", false)).toBe(true); expect(resolveTypewriter("on", true)).toBe(true); expect(resolveTypewriter("off", false)).toBe(false); }); it("coerces stored values to a known preference", () => { expect(normalizeTypewriterPreference("on")).toBe("on"); expect(normalizeTypewriterPreference("off")).toBe("off"); expect(normalizeTypewriterPreference("default")).toBe("default"); expect(normalizeTypewriterPreference(undefined)).toBe("default"); expect(normalizeTypewriterPreference("yes")).toBe("default"); }); });