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("returns no results for an empty query", () => {
105 expect(searchSettings(" ", ITEMS)).toEqual([]);
106 });
107
108 it("hides desktop-only settings from browser search", () => {
109 expect(SETTINGS_SEARCH_ITEMS.some((item) => item.id === "quit-confirmation")).toBe(true);
110 expect(searchSettings("hold to quit")).toEqual([]);
111 expect(searchSettings("wsl")).toEqual([]);
112 });
113
114 it("hides macOS-only settings on other platforms", () => {
115 vi.stubGlobal("navigator", { platform: "Win32" });
116 try {
117 expect(searchSettings("font smoothing")).toEqual([]);
118 } finally {
119 vi.unstubAllGlobals();
120 }
121 });
122
123 it("registers the WSL backend as a desktop-only setting", () => {
124 expect(SETTINGS_SEARCH_ITEMS.find((item) => item.id === "wsl-backend")).toMatchObject({
125 id: "wsl-backend",
126 title: "WSL backend",
127 to: "/settings/connections",
128 desktopOnly: true,
129 windowsOnly: true,
130 });
131 });
132
133 it("hides settings whose controls are unavailable", () => {
134 const available = filterAvailableSettingsSearchItems({
135 hasCloudPublicConfig: false,
136 hasPrimaryEnvironment: false,
137 hasProviderSettingsEnvironment: false,
138 canManageLocalBackend: false,
139 isWslSettingsRowVisible: false,
140 hasThreadAutoSettlement: false,
141 });
142
143 const gatedIds = new Set<string>([
144 "follow-change-request-templates",
145 "git-fetch-interval",
146 "network-access",
147 "publish-agent-activity",
148 "provider-health-check-interval",
149 "source-control-writer-model",
150 "source-control-writing-style",
151 "t3-connect",
152 "tailscale-https",
153 "wsl-backend",
154 "auto-settle-inactive-threads",
155 "auto-settle-merged-threads",
156 "days-before-auto-settle",
157 ]);
158 expect(available.map((item) => item.id).filter((id) => gatedIds.has(id))).toEqual([]);
159 });
160
161 it("shows automatic settlement settings when the server supports them", () => {
162 const available = filterAvailableSettingsSearchItems({
163 hasCloudPublicConfig: false,
164 hasPrimaryEnvironment: false,
165 hasProviderSettingsEnvironment: false,
166 canManageLocalBackend: false,
167 isWslSettingsRowVisible: false,
168 hasThreadAutoSettlement: true,
169 });
170
171 expect(searchSettings("auto-settle", available).map((item) => item.id)).toEqual([
172 "auto-settle-inactive-threads",
173 "auto-settle-merged-threads",
174 "days-before-auto-settle",
175 ]);
176 });
177
178 it("keeps catalog result ids unique", () => {
179 const ids = SETTINGS_SEARCH_ITEMS.map((item) => item.id);
180 expect(new Set(ids).size).toBe(ids.length);
181 });
182
183 it("serves anchor props to panels from the catalog", () => {
184 expect(searchableSetting("word-wrap")).toEqual({ id: "word-wrap", title: "Word wrap" });
185 expect(searchableSetting("archive")).toEqual({ id: "archive", title: "Archived threads" });
186 });
187
188 it("routes appearance settings to their current section", () => {
189 expect(searchSettings("theme")[0]).toMatchObject({
190 id: "theme",
191 to: "/settings/appearance",
192 });
193 expect(searchSettings("word wrap")[0]).toMatchObject({
194 id: "word-wrap",
195 to: "/settings/appearance",
196 });
197 expect(searchSettings("environment identification")[0]).toMatchObject({
198 id: "environment-identification",
199 to: "/settings/appearance",
200 targetId: "appearance",
201 });
202 });
203
204 it("routes browser recording quality to integrations", () => {
205 const result = searchSettings("recording frame rate")[0];
206 expect(result).toMatchObject({
207 id: "browser-recording-frame-rate",
208 to: "/settings/integrations",
209 });
210 expect(result).not.toHaveProperty("targetId");
211 });
212
213 it("routes where links open to integrations", () => {
214 expect(searchSettings("open links in")[0]).toMatchObject({
215 id: "browser-link-target",
216 to: "/settings/integrations",
217 });
218 expect(searchSettings("external links")[0]).toMatchObject({ id: "browser-link-target" });
219 });
220
221 it("finds the default browser profile action in the profiles list", () => {
222 expect(searchSettings("default profile")[0]).toMatchObject({
223 id: "browser-default-profile",
224 to: "/settings/integrations",
225 targetId: "browser-profiles",
226 });
227 });
228});