1
11import { describe, it, expect } from "vitest";
12import { displayStoredValue } from "@/lib/ai-database";
13
14describe("displayStoredValue", () => {
15 it("renders primitives and null/undefined", () => {
16 expect(displayStoredValue("hello")).toBe("hello");
17 expect(displayStoredValue(42)).toBe("42");
18 expect(displayStoredValue(true)).toBe("true");
19 expect(displayStoredValue(null)).toBe("—");
20 expect(displayStoredValue(undefined)).toBe("—");
21 });
22
23 it("unwraps the per-type stored shapes", () => {
24 expect(displayStoredValue({ text: "a note" })).toBe("a note");
25 expect(displayStoredValue({ value: 7 })).toBe("7");
26 expect(displayStoredValue({ value: false })).toBe("false");
27 expect(displayStoredValue({ start: "2026-01-01" })).toBe("2026-01-01");
28 });
29
30 it("resolves select optionId to the option name via the options list", () => {
31 const options = [
32 { id: "opt-to-do", name: "To Do" },
33 { id: "opt-done", name: "Done" }
34 ];
35 expect(displayStoredValue({ optionId: "opt-done" }, options)).toBe("Done");
36
37 expect(displayStoredValue({ optionId: "opt-missing" }, options)).toBe("opt-missing");
38
39 expect(displayStoredValue({ optionId: "opt-to-do" })).toBe("opt-to-do");
40 });
41
42 it("falls back to JSON for unknown shapes", () => {
43 expect(displayStoredValue({ weird: [1, 2] })).toBe('{"weird":[1,2]}');
44 });
45});
46