Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

settingsSearch.test.ts

218 lines7.5 KB

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