Skip to content

Commit 2aefb3d

Browse files
committed
Cover settings panel entry wrappers
(cherry picked from commit 7afbc2f)
1 parent 47bbd3a commit 2aefb3d

File tree

1 file changed

+155
-1
lines changed

1 file changed

+155
-1
lines changed

test/settings-panels.test.ts

Lines changed: 155 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
import { describe, expect, it } from "vitest";
1+
import { describe, expect, it, vi } from "vitest";
22
import {
33
formatAutoReturnDelayLabel,
4+
promptBehaviorSettingsPanelEntry,
5+
promptDashboardDisplaySettingsPanelEntry,
6+
promptStatuslineSettingsPanelEntry,
7+
promptThemeSettingsPanelEntry,
48
reorderStatuslineField,
59
} from "../lib/codex-manager/settings-panels.js";
10+
import { DEFAULT_DASHBOARD_DISPLAY_SETTINGS } from "../lib/dashboard-settings.js";
611

712
describe("settings panel helpers", () => {
813
it("reorders statusline fields safely", () => {
@@ -18,4 +23,153 @@ describe("settings panel helpers", () => {
1823
expect(formatAutoReturnDelayLabel(0)).toBe("Instant return");
1924
expect(formatAutoReturnDelayLabel(4000)).toBe("4s auto-return");
2025
});
26+
27+
it("passes dashboard display panel dependencies through and falls back to defaults", async () => {
28+
const initial = { ...DEFAULT_DASHBOARD_DISPLAY_SETTINGS };
29+
const cloneDashboardSettings = vi.fn((value) => ({ ...value }));
30+
const buildAccountListPreview = vi.fn(() => "preview");
31+
const formatDashboardSettingState = vi.fn(() => "state");
32+
const formatMenuSortMode = vi.fn(() => "sort");
33+
const resolveMenuLayoutMode = vi.fn((settings?: { menuLayoutMode?: string }) =>
34+
settings?.menuLayoutMode === "expanded-rows"
35+
? "expanded-rows"
36+
: "compact-details",
37+
);
38+
const formatMenuLayoutMode = vi.fn(() => "layout");
39+
const applyDashboardDefaultsForKeys = vi.fn(() => initial);
40+
const promptDashboardDisplayPanel = vi.fn(async (_value, deps) => {
41+
expect(_value).toEqual(initial);
42+
expect(deps.cloneDashboardSettings).toBe(cloneDashboardSettings);
43+
expect(deps.buildAccountListPreview).toBe(buildAccountListPreview);
44+
expect(deps.formatDashboardSettingState).toBe(formatDashboardSettingState);
45+
expect(deps.formatMenuSortMode).toBe(formatMenuSortMode);
46+
expect(deps.formatMenuLayoutMode).toBe(formatMenuLayoutMode);
47+
expect(deps.applyDashboardDefaultsForKeys).toBe(applyDashboardDefaultsForKeys);
48+
expect(deps.resolveMenuLayoutMode(undefined)).toBe("compact-details");
49+
expect(
50+
deps.resolveMenuLayoutMode({ menuLayoutMode: "expanded-rows" } as never),
51+
).toBe("expanded-rows");
52+
return initial;
53+
});
54+
55+
const result = await promptDashboardDisplaySettingsPanelEntry({
56+
initial,
57+
promptDashboardDisplayPanel,
58+
cloneDashboardSettings,
59+
buildAccountListPreview,
60+
formatDashboardSettingState,
61+
formatMenuSortMode,
62+
resolveMenuLayoutMode,
63+
formatMenuLayoutMode,
64+
applyDashboardDefaultsForKeys,
65+
DASHBOARD_DISPLAY_OPTIONS: [] as never,
66+
ACCOUNT_LIST_PANEL_KEYS: [] as never,
67+
UI_COPY: {} as never,
68+
});
69+
70+
expect(promptDashboardDisplayPanel).toHaveBeenCalledOnce();
71+
expect(resolveMenuLayoutMode).toHaveBeenCalledWith(
72+
DEFAULT_DASHBOARD_DISPLAY_SETTINGS,
73+
);
74+
expect(result).toEqual(initial);
75+
});
76+
77+
it("passes statusline panel dependencies through", async () => {
78+
const initial = { ...DEFAULT_DASHBOARD_DISPLAY_SETTINGS };
79+
const cloneDashboardSettings = vi.fn((value) => ({ ...value }));
80+
const buildAccountListPreview = vi.fn(() => "preview");
81+
const normalizeStatuslineFields = vi.fn((fields) => fields);
82+
const formatDashboardSettingState = vi.fn(() => "state");
83+
const applyDashboardDefaultsForKeys = vi.fn(() => initial);
84+
const promptStatuslineSettingsPanel = vi.fn(async (_value, deps) => {
85+
expect(_value).toEqual(initial);
86+
expect(deps.cloneDashboardSettings).toBe(cloneDashboardSettings);
87+
expect(deps.buildAccountListPreview).toBe(buildAccountListPreview);
88+
expect(deps.normalizeStatuslineFields).toBe(normalizeStatuslineFields);
89+
expect(deps.formatDashboardSettingState).toBe(formatDashboardSettingState);
90+
expect(deps.applyDashboardDefaultsForKeys).toBe(applyDashboardDefaultsForKeys);
91+
expect(deps.reorderField(["last-used", "limits"], "limits", -1)).toEqual([
92+
"limits",
93+
"last-used",
94+
]);
95+
return null;
96+
});
97+
98+
const result = await promptStatuslineSettingsPanelEntry({
99+
initial,
100+
promptStatuslineSettingsPanel,
101+
cloneDashboardSettings,
102+
buildAccountListPreview,
103+
normalizeStatuslineFields,
104+
formatDashboardSettingState,
105+
applyDashboardDefaultsForKeys,
106+
STATUSLINE_FIELD_OPTIONS: [] as never,
107+
STATUSLINE_PANEL_KEYS: [] as never,
108+
UI_COPY: {} as never,
109+
});
110+
111+
expect(promptStatuslineSettingsPanel).toHaveBeenCalledOnce();
112+
expect(result).toBeNull();
113+
});
114+
115+
it("passes behavior panel dependencies through", async () => {
116+
const initial = { ...DEFAULT_DASHBOARD_DISPLAY_SETTINGS };
117+
const cloneDashboardSettings = vi.fn((value) => ({ ...value }));
118+
const applyDashboardDefaultsForKeys = vi.fn(() => initial);
119+
const formatMenuQuotaTtl = vi.fn(() => "ttl");
120+
const promptBehaviorSettingsPanel = vi.fn(async (_value, deps) => {
121+
expect(_value).toEqual(initial);
122+
expect(deps.cloneDashboardSettings).toBe(cloneDashboardSettings);
123+
expect(deps.applyDashboardDefaultsForKeys).toBe(applyDashboardDefaultsForKeys);
124+
expect(deps.formatMenuQuotaTtl).toBe(formatMenuQuotaTtl);
125+
expect(deps.formatDelayLabel(4000)).toBe("4s auto-return");
126+
return initial;
127+
});
128+
129+
const result = await promptBehaviorSettingsPanelEntry({
130+
initial,
131+
promptBehaviorSettingsPanel,
132+
cloneDashboardSettings,
133+
applyDashboardDefaultsForKeys,
134+
formatMenuQuotaTtl,
135+
AUTO_RETURN_OPTIONS_MS: [] as never,
136+
MENU_QUOTA_TTL_OPTIONS_MS: [] as never,
137+
BEHAVIOR_PANEL_KEYS: [] as never,
138+
UI_COPY: {} as never,
139+
});
140+
141+
expect(promptBehaviorSettingsPanel).toHaveBeenCalledOnce();
142+
expect(result).toEqual(initial);
143+
});
144+
145+
it("passes theme panel dependencies through", async () => {
146+
const initial = { ...DEFAULT_DASHBOARD_DISPLAY_SETTINGS };
147+
const cloneDashboardSettings = vi.fn((value) => ({ ...value }));
148+
const applyDashboardDefaultsForKeys = vi.fn(() => initial);
149+
const applyUiThemeFromDashboardSettings = vi.fn();
150+
const promptThemeSettingsPanel = vi.fn(async (_value, deps) => {
151+
expect(_value).toEqual(initial);
152+
expect(deps.cloneDashboardSettings).toBe(cloneDashboardSettings);
153+
expect(deps.applyDashboardDefaultsForKeys).toBe(applyDashboardDefaultsForKeys);
154+
expect(deps.applyUiThemeFromDashboardSettings).toBe(
155+
applyUiThemeFromDashboardSettings,
156+
);
157+
return null;
158+
});
159+
160+
const result = await promptThemeSettingsPanelEntry({
161+
initial,
162+
promptThemeSettingsPanel,
163+
cloneDashboardSettings,
164+
applyDashboardDefaultsForKeys,
165+
applyUiThemeFromDashboardSettings,
166+
THEME_PRESET_OPTIONS: [] as never,
167+
ACCENT_COLOR_OPTIONS: [] as never,
168+
THEME_PANEL_KEYS: [] as never,
169+
UI_COPY: {} as never,
170+
});
171+
172+
expect(promptThemeSettingsPanel).toHaveBeenCalledOnce();
173+
expect(result).toBeNull();
174+
});
21175
});

0 commit comments

Comments
 (0)