Open History to see the last commit
1import { describe, expect, it, vi } from "vite-plus/test";
2
3import {
4 filterAvailableSettingsSearchItems,
5 searchableSetting,
6 searchSettings,
7 SETTINGS_SEARCH_ITEMS,
8 type SettingsSearchItem,
9} from "./settingsSearch";
10
11const ITEMS: ReadonlyArray<SettingsSearchItem> = [
12 {
13 id: "word-wrap",
14 title: "Word wrap",
15 to: "/settings/general",
16 searchTerms: ["long lines in code previews"],
17 },
18 {
19 id: "network-access",
20 title: "Network access",
21 to: "/settings/connections",
22 searchTerms: ["remote pairing backend"],
23 },
24 {
25 id: "providers",
26 title: "Providers",
27 to: "/settings/providers",
28 searchTerms: ["claude codex agents"],
29 },
30 {
31 id: "provider-updates",
32 title: "Update checks",
33 to: "/settings/general",
34 },
35 {
36 id: "automatic-updates",
37 title: "Automatic updates",
38 to: "/settings/general",
39 },
40];
41
42describe("searchSettings", () => {
43 it("matches titles, sections, and remembered setting details", () => {
44 expect(searchSettings("word", ITEMS).map((item) => item.id)).toEqual(["word-wrap"]);
45 expect(searchSettings("network", ITEMS).map((item) => item.id)).toEqual(["network-access"]);
46 expect(searchSettings("connections", ITEMS).map((item) => item.id)).toEqual(["network-access"]);
47 expect(searchSettings("claude", ITEMS).map((item) => item.id)).toEqual(["providers"]);
48 expect(searchSettings("long lines", ITEMS).map((item) => item.id)).toEqual(["word-wrap"]);
49 });
50
51 it("matches normalized title substrings", () => {
52 expect(searchSettings(" WORD WRAP ", ITEMS).map((item) => item.id)).toEqual(["word-wrap"]);
53 expect(searchSettings("glass").map((item) => item.id)).toEqual(["setting-glass-opacity"]);
54 expect(searchSettings("panel animations").map((item) => item.id)).toEqual(["panel-animations"]);
55 expect(searchSettings("thè\u{1ab0}mes")[0]?.id).toBe("theme");
56 const localeLowerCase = vi.spyOn(String.prototype, "toLocaleLowerCase").mockReturnValue("gıt");
57 try {
58 expect(searchSettings("GIT")[0]?.id).toBe("git-fetch-interval");
59 expect(localeLowerCase).not.toHaveBeenCalled();
60 } finally {
61 localeLowerCase.mockRestore();
62 }
63 expect(searchSettings("xyzzy")).toEqual([]);
64 });
65
66 it("keeps catalog order for multiple title matches", () => {
67 expect(searchSettings("update", ITEMS).map((item) => item.id)).toEqual([
68 "provider-updates",
69 "automatic-updates",
70 ]);
71 });
72
73 it("matches query words across fields and ranks the strongest result first", () => {
74 expect(searchSettings("pairing remote", ITEMS).map((item) => item.id)).toEqual([
75 "network-access",
76 ]);
77 expect(
78 searchSettings("remote pairing")
79 .slice(0, 2)
80 .map((item) => item.id),
81 ).toEqual(["network-access", "connections-environment"]);
82 });
83
84 it("finds settings that used to be reachable only through their section", () => {
85 expect(searchSettings("pull request template")[0]?.id).toBe("follow-change-request-templates");
86 expect(searchSettings("git security keys")[0]?.id).toBe("git-fetch-interval");
87 expect(searchSettings("push notifications")[0]?.id).toBe("publish-agent-activity");
88 expect(searchSettings("battery saver")[0]?.id).toBe("background-activity");
89 expect(searchSettings("binary path")[0]?.id).toBe("providers");
90 expect(searchSettings("Antigravity")[0]?.id).toBe("providers");
91 expect(searchSettings("Google sign in")[0]?.id).toBe("providers");
92 expect(searchSettings("authorized clients")[0]?.id).toBe("connections-environment");
93 expect(searchSettings("administrative access")[0]?.id).toBe("connections-environment");
94 });
95
96 it("lists thread confirmations in panel order", () => {
97 expect(searchSettings("confirmation").map((item) => item.id)).toEqual([
98 "unpin-confirmation",
99 "archive-confirmation",
100 "delete-confirmation",
101 ]);
102 });
103
104 it.each(["usage providers", "CLIProxyAPI", "CLI proxy hub", "management key"])(
105 "finds usage-provider management by %s",
106 (query) => {
107 expect(searchSettings(query)[0]).toMatchObject({
108 id: "usage-providers",
109 to: "/settings/providers",
110 });
111 },
112 );
113
114 it("returns no results for an empty query", () => {
115 expect(searchSettings(" ", ITEMS)).toEqual([]);
116 });
117
118 it("hides desktop-only settings from browser search", () => {
119 expect(SETTINGS_SEARCH_ITEMS.some((item) => item.id === "quit-confirmation")).toBe(true);
120 expect(searchSettings("hold to quit")).toEqual([]);
121 expect(searchSettings("wsl")).toEqual([]);
122 });
123
124 it("hides macOS-only settings on other platforms", () => {
125 vi.stubGlobal("navigator", { platform: "Win32" });
126 try {
127 expect(searchSettings("font smoothing")).toEqual([]);
128 } finally {
129 vi.unstubAllGlobals();
130 }
131 });
132
133 it("registers the WSL backend as a desktop-only setting", () => {
134 expect(SETTINGS_SEARCH_ITEMS.find((item) => item.id === "wsl-backend")).toMatchObject({
135 id: "wsl-backend",
136 title: "WSL backend",
137 to: "/settings/connections",
138 desktopOnly: true,
139 windowsOnly: true,
140 });
141 });
142
143 it("hides settings whose controls are unavailable", () => {
144 const available = filterAvailableSettingsSearchItems({
145 hasCloudPublicConfig: false,
146 hasPrimaryEnvironment: false,
147 hasProviderSettingsEnvironment: false,
148 canManageLocalBackend: false,
149 isWslSettingsRowVisible: false,
150 hasThreadAutoSettlement: false,
151 });
152
153 const gatedIds = new Set<string>([
154 "follow-change-request-templates",
155 "git-fetch-interval",
156 "network-access",
157 "publish-agent-activity",
158 "provider-health-check-interval",
159 "source-control-writer-model",
160 "source-control-writing-style",
161 "t3-connect",
162 "tailscale-https",
163 "wsl-backend",
164 "auto-settle-inactive-threads",
165 "auto-settle-merged-threads",
166 "days-before-auto-settle",
167 ]);
168 expect(available.map((item) => item.id).filter((id) => gatedIds.has(id))).toEqual([]);
169 });
170
171 it("shows automatic settlement settings when the server supports them", () => {
172 const available = filterAvailableSettingsSearchItems({
173 hasCloudPublicConfig: false,
174 hasPrimaryEnvironment: false,
175 hasProviderSettingsEnvironment: false,
176 canManageLocalBackend: false,
177 isWslSettingsRowVisible: false,
178 hasThreadAutoSettlement: true,
179 });
180
181 expect(searchSettings("auto-settle", available).map((item) => item.id)).toEqual([
182 "auto-settle-inactive-threads",
183 "auto-settle-merged-threads",
184 "days-before-auto-settle",
185 ]);
186 });
187
188 it("keeps catalog result ids unique", () => {
189 const ids = SETTINGS_SEARCH_ITEMS.map((item) => item.id);
190 expect(new Set(ids).size).toBe(ids.length);
191 });
192
193 it("serves anchor props to panels from the catalog", () => {
194 expect(searchableSetting("word-wrap")).toEqual({ id: "word-wrap", title: "Word wrap" });
195 expect(searchableSetting("archive")).toEqual({ id: "archive", title: "Archived threads" });
196 });
197
198 it("routes appearance settings to their current section", () => {
199 expect(searchSettings("theme")[0]).toMatchObject({
200 id: "theme",
201 to: "/settings/appearance",
202 });
203 expect(searchSettings("word wrap")[0]).toMatchObject({
204 id: "word-wrap",
205 to: "/settings/appearance",
206 });
207 expect(searchSettings("environment identification")[0]).toMatchObject({
208 id: "environment-identification",
209 to: "/settings/appearance",
210 targetId: "appearance-interface",
211 });
212 });
213
214 it("routes browser recording quality to integrations", () => {
215 const result = searchSettings("recording frame rate")[0];
216 expect(result).toMatchObject({
217 id: "browser-recording-frame-rate",
218 to: "/settings/integrations",
219 });
220 expect(result).not.toHaveProperty("targetId");
221 });
222
223 it("routes where links open to integrations", () => {
224 expect(searchSettings("open links in")[0]).toMatchObject({
225 id: "browser-link-target",
226 to: "/settings/integrations",
227 });
228 expect(searchSettings("external links")[0]).toMatchObject({ id: "browser-link-target" });
229 });
230
231 it("finds the default browser profile action in the profiles list", () => {
232 expect(searchSettings("default profile")[0]).toMatchObject({
233 id: "browser-default-profile",
234 to: "/settings/integrations",
235 targetId: "browser-profiles",
236 });
237 });
238});