/** * TASK-0124 — the database-AI client's pure display helper renders a * stored per-type record value for the mapping/preview/sample tables * (text/number/checkbox/select/date/unknown). The SSE streamers need a * fetch + auth store (covered by the integration + e2e suites); this file * covers the pure part. * * @vitest-environment node (no DOM needed; the config default is jsdom, * which is not installed — every web test opts into node explicitly). */ import { describe, it, expect } from "vitest"; import { displayStoredValue } from "@/lib/ai-database"; describe("displayStoredValue", () => { it("renders primitives and null/undefined", () => { expect(displayStoredValue("hello")).toBe("hello"); expect(displayStoredValue(42)).toBe("42"); expect(displayStoredValue(true)).toBe("true"); expect(displayStoredValue(null)).toBe("—"); expect(displayStoredValue(undefined)).toBe("—"); }); it("unwraps the per-type stored shapes", () => { expect(displayStoredValue({ text: "a note" })).toBe("a note"); expect(displayStoredValue({ value: 7 })).toBe("7"); expect(displayStoredValue({ value: false })).toBe("false"); expect(displayStoredValue({ start: "2026-01-01" })).toBe("2026-01-01"); }); it("resolves select optionId to the option name via the options list", () => { const options = [ { id: "opt-to-do", name: "To Do" }, { id: "opt-done", name: "Done" } ]; expect(displayStoredValue({ optionId: "opt-done" }, options)).toBe("Done"); // unknown id → the raw id (no crash) expect(displayStoredValue({ optionId: "opt-missing" }, options)).toBe("opt-missing"); // no options provided → the raw id expect(displayStoredValue({ optionId: "opt-to-do" })).toBe("opt-to-do"); }); it("falls back to JSON for unknown shapes", () => { expect(displayStoredValue({ weird: [1, 2] })).toBe('{"weird":[1,2]}'); }); });