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("thè\u{1ab0}mes")[0]?.id).toBe("theme");
55 const localeLowerCase = vi.spyOn(String.prototype, "toLocaleLowerCase").mockReturnValue("gıt");
56 try {
57 expect(searchSettings("GIT")[0]?.id).toBe("git-fetch-interval");
58 expect(localeLowerCase).not.toHaveBeenCalled();
59 } finally {
60 localeLowerCase.mockRestore();
61 }
62 expect(searchSettings("xyzzy")).toEqual([]);
63 });
64
65 it("keeps catalog order for multiple title matches", () => {
66 expect(searchSettings("update", ITEMS).map((item) => item.id)).toEqual([
67 "provider-updates",
68 "automatic-updates",
69 ]);
70 });
71
72 it("matches query words across fields and ranks the strongest result first", () => {
73 expect(searchSettings("pairing remote", ITEMS).map((item) => item.id)).toEqual([
74 "network-access",
75 ]);
76 expect(
77 searchSettings("remote pairing")
78 .slice(0, 2)
79 .map((item) => item.id),
80 ).toEqual(["network-access", "connections-environment"]);
81 });
82
83 it("finds settings that used to be reachable only through their section", () => {
84 expect(searchSettings("pull request template")[0]?.id).toBe("follow-change-request-templates");
85 expect(searchSettings("git security keys")[0]?.id).toBe("git-fetch-interval");
86 expect(searchSettings("push notifications")[0]?.id).toBe("publish-agent-activity");
87 expect(searchSettings("battery saver")[0]?.id).toBe("background-activity");
88 expect(searchSettings("binary path")[0]?.id).toBe("providers");
89 expect(searchSettings("authorized clients")[0]?.id).toBe("connections-environment");
90 expect(searchSettings("administrative access")[0]?.id).toBe("connections-environment");
91 });
92
93 it("lists thread confirmations in panel order", () => {
94 expect(searchSettings("confirmation").map((item) => item.id)).toEqual([
95 "unpin-confirmation",
96 "archive-confirmation",
97 "delete-confirmation",
98 ]);
99 });
100
101 it("returns no results for an empty query", () => {
102 expect(searchSettings(" ", ITEMS)).toEqual([]);
103 });
104
105 it("hides desktop-only settings from browser search", () => {
106 expect(SETTINGS_SEARCH_ITEMS.some((item) => item.id === "quit-confirmation")).toBe(true);
107 expect(searchSettings("hold to quit")).toEqual([]);
108 expect(searchSettings("wsl")).toEqual([]);
109 });
110
111 it("hides macOS-only settings on other platforms", () => {
112 vi.stubGlobal("navigator", { platform: "Win32" });
113 try {
114 expect(searchSettings("font smoothing")).toEqual([]);
115 } finally {
116 vi.unstubAllGlobals();
117 }
118 });
119
120 it("registers the WSL backend as a desktop-only setting", () => {
121 expect(SETTINGS_SEARCH_ITEMS.find((item) => item.id === "wsl-backend")).toMatchObject({
122 id: "wsl-backend",
123 title: "WSL backend",
124 to: "/settings/connections",
125 desktopOnly: true,
126 windowsOnly: true,
127 });
128 });
129
130 it("hides settings whose controls are unavailable", () => {
131 const available = filterAvailableSettingsSearchItems({
132 hasCloudPublicConfig: false,
133 hasPrimaryEnvironment: false,
134 hasProviderSettingsEnvironment: false,
135 canManageLocalBackend: false,
136 isWslSettingsRowVisible: false,
137 hasThreadAutoSettlement: false,
138 });
139
140 const gatedIds = new Set<string>([
141 "follow-change-request-templates",
142 "git-fetch-interval",
143 "network-access",
144 "publish-agent-activity",
145 "provider-health-check-interval",
146 "source-control-writer-model",
147 "source-control-writing-style",
148 "t3-connect",
149 "tailscale-https",
150 "wsl-backend",
151 "auto-settle-inactive-threads",
152 "auto-settle-merged-threads",
153 "days-before-auto-settle",
154 ]);
155 expect(available.map((item) => item.id).filter((id) => gatedIds.has(id))).toEqual([]);
156 });
157
158 it("shows automatic settlement settings when the server supports them", () => {
159 const available = filterAvailableSettingsSearchItems({
160 hasCloudPublicConfig: false,
161 hasPrimaryEnvironment: false,
162 hasProviderSettingsEnvironment: false,
163 canManageLocalBackend: false,
164 isWslSettingsRowVisible: false,
165 hasThreadAutoSettlement: true,
166 });
167
168 expect(searchSettings("auto-settle", available).map((item) => item.id)).toEqual([
169 "auto-settle-inactive-threads",
170 "auto-settle-merged-threads",
171 "days-before-auto-settle",
172 ]);
173 });
174
175 it("keeps catalog result ids unique", () => {
176 const ids = SETTINGS_SEARCH_ITEMS.map((item) => item.id);
177 expect(new Set(ids).size).toBe(ids.length);
178 });
179
180 it("serves anchor props to panels from the catalog", () => {
181 expect(searchableSetting("word-wrap")).toEqual({ id: "word-wrap", title: "Word wrap" });
182 expect(searchableSetting("archive")).toEqual({ id: "archive", title: "Archived threads" });
183 });
184
185 it("routes appearance settings to their current section", () => {
186 expect(searchSettings("theme")[0]).toMatchObject({
187 id: "theme",
188 to: "/settings/appearance",
189 });
190 expect(searchSettings("word wrap")[0]).toMatchObject({
191 id: "word-wrap",
192 to: "/settings/appearance",
193 });
194 expect(searchSettings("environment identification")[0]).toMatchObject({
195 id: "environment-identification",
196 to: "/settings/appearance",
197 targetId: "appearance",
198 });
199 });
200
201 it("routes browser recording quality to integrations", () => {
202 const result = searchSettings("recording frame rate")[0];
203 expect(result).toMatchObject({
204 id: "browser-recording-frame-rate",
205 to: "/settings/integrations",
206 });
207 expect(result).not.toHaveProperty("targetId");
208 });
209});