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

settingsSearch.test.ts

188 lines6.4 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("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("quit confirmation")).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 });
138​
139 const gatedIds = new Set<string>([
140 "follow-change-request-templates",
141 "git-fetch-interval",
142 "network-access",
143 "publish-agent-activity",
144 "provider-health-check-interval",
145 "source-control-writer-model",
146 "source-control-writing-style",
147 "t3-connect",
148 "tailscale-https",
149 "wsl-backend",
150 ]);
151 expect(available.map((item) => item.id).filter((id) => gatedIds.has(id))).toEqual([]);
152 });
153​
154 it("keeps catalog result ids unique", () => {
155 const ids = SETTINGS_SEARCH_ITEMS.map((item) => item.id);
156 expect(new Set(ids).size).toBe(ids.length);
157 });
158​
159 it("serves anchor props to panels from the catalog", () => {
160 expect(searchableSetting("word-wrap")).toEqual({ id: "word-wrap", title: "Word wrap" });
161 expect(searchableSetting("archive")).toEqual({ id: "archive", title: "Archived threads" });
162 });
163​
164 it("routes appearance settings to their current section", () => {
165 expect(searchSettings("theme")[0]).toMatchObject({
166 id: "theme",
167 to: "/settings/appearance",
168 });
169 expect(searchSettings("word wrap")[0]).toMatchObject({
170 id: "word-wrap",
171 to: "/settings/appearance",
172 });
173 expect(searchSettings("environment identification")[0]).toMatchObject({
174 id: "environment-identification",
175 to: "/settings/appearance",
176 targetId: "appearance",
177 });
178 });
179​
180 it("routes browser recording quality to integrations", () => {
181 const result = searchSettings("recording frame rate")[0];
182 expect(result).toMatchObject({
183 id: "browser-recording-frame-rate",
184 to: "/settings/integrations",
185 });
186 expect(result).not.toHaveProperty("targetId");
187 });
188});