import { beforeEach, describe, expect, it } from "vitest"; import { STORAGE_KEYS } from "@/lib/settings/constants"; import { DEFAULT_SETTINGS_MENU_MODE, isTreeSettingsMenuMode, readSettingsMenuExpandedKeys, readSettingsMenuMode, writeSettingsMenuExpandedKeys, writeSettingsMenuMode, } from "./settings-menu-mode"; const FLAT = "flat"; const ACCORDION = "accordion"; const AGENTS_ROW_KEY = "row:/settings/agents"; const AGENT_KEY = "agent:claude-code"; describe("settings menu mode storage", () => { beforeEach(() => { window.localStorage.clear(); }); // @covers AC-UI-SETTINGS-MENU-DEFAULT-001.1 it("defaults to the accordion menu when this device has never chosen", () => { expect(readSettingsMenuMode()).toBe(ACCORDION); expect(DEFAULT_SETTINGS_MENU_MODE).toBe(ACCORDION); }); it("round-trips a chosen mode", () => { writeSettingsMenuMode("persistent"); expect(readSettingsMenuMode()).toBe("persistent"); }); // @covers AC-UI-SETTINGS-MENU-DEFAULT-001.3 it("falls back rather than trusting a mode that no longer exists", () => { window.localStorage.setItem(STORAGE_KEYS.SETTINGS_MENU_MODE, JSON.stringify("outline")); expect(readSettingsMenuMode()).toBe(ACCORDION); }); it("survives an unparseable stored value", () => { window.localStorage.setItem(STORAGE_KEYS.SETTINGS_MENU_MODE, "{not json"); expect(readSettingsMenuMode()).toBe(ACCORDION); }); it("round-trips expanded branch keys", () => { writeSettingsMenuExpandedKeys([AGENTS_ROW_KEY, AGENT_KEY]); expect(readSettingsMenuExpandedKeys()).toEqual([AGENTS_ROW_KEY, AGENT_KEY]); }); it("drops non-string entries instead of feeding them to the menu", () => { window.localStorage.setItem( STORAGE_KEYS.SETTINGS_MENU_EXPANDED, JSON.stringify([AGENT_KEY, 7, null]), ); expect(readSettingsMenuExpandedKeys()).toEqual([AGENT_KEY]); }); it("treats a stored non-array as no open branches", () => { window.localStorage.setItem(STORAGE_KEYS.SETTINGS_MENU_EXPANDED, JSON.stringify({})); expect(readSettingsMenuExpandedKeys()).toEqual([]); }); it("knows which modes render branches", () => { expect(isTreeSettingsMenuMode(FLAT)).toBe(false); expect(isTreeSettingsMenuMode("accordion")).toBe(true); expect(isTreeSettingsMenuMode("persistent")).toBe(true); }); });