Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import {
4 searchableSetting,
5 searchSettings,
6 SETTINGS_SEARCH_ITEMS,
7 type SettingsSearchItem,
8} from "./settingsSearch";
9
10const ITEMS: ReadonlyArray<SettingsSearchItem> = [
11 {
12 id: "word-wrap",
13 title: "Word wrap",
14 to: "/settings/general",
15 },
16 {
17 id: "network-access",
18 title: "Network access",
19 to: "/settings/connections",
20 },
21 {
22 id: "providers",
23 title: "Providers",
24 to: "/settings/providers",
25 },
26 {
27 id: "provider-updates",
28 title: "Update checks",
29 to: "/settings/general",
30 },
31 {
32 id: "automatic-updates",
33 title: "Automatic updates",
34 to: "/settings/general",
35 },
36];
37
38describe("searchSettings", () => {
39 it("matches only setting titles", () => {
40 expect(searchSettings("word", ITEMS).map((item) => item.id)).toEqual(["word-wrap"]);
41 expect(searchSettings("network", ITEMS).map((item) => item.id)).toEqual(["network-access"]);
42 expect(searchSettings("connections", ITEMS)).toEqual([]);
43 expect(searchSettings("claude", ITEMS)).toEqual([]);
44 });
45
46 it("matches normalized title substrings", () => {
47 expect(searchSettings(" WORD WRAP ", ITEMS).map((item) => item.id)).toEqual(["word-wrap"]);
48 expect(searchSettings("glass").map((item) => item.id)).toEqual(["setting-glass-opacity"]);
49 expect(searchSettings("xyzzy")).toEqual([]);
50 });
51
52 it("keeps catalog order for multiple title matches", () => {
53 expect(searchSettings("update", ITEMS).map((item) => item.id)).toEqual([
54 "provider-updates",
55 "automatic-updates",
56 ]);
57 });
58
59 it("returns no results for an empty query", () => {
60 expect(searchSettings(" ", ITEMS)).toEqual([]);
61 });
62
63 it("hides desktop-only settings from browser search", () => {
64 expect(SETTINGS_SEARCH_ITEMS.some((item) => item.id === "quit-confirmation")).toBe(true);
65 expect(SETTINGS_SEARCH_ITEMS.some((item) => item.id === "prevent-automatic-sleep")).toBe(true);
66 expect(searchSettings("quit confirmation")).toEqual([]);
67 expect(searchSettings("prevent automatic sleep")).toEqual([]);
68 });
69
70 it("keeps catalog result ids unique", () => {
71 const ids = SETTINGS_SEARCH_ITEMS.map((item) => item.id);
72 expect(new Set(ids).size).toBe(ids.length);
73 });
74
75 it("serves anchor props to panels from the catalog", () => {
76 expect(searchableSetting("word-wrap")).toEqual({ id: "word-wrap", title: "Word wrap" });
77 expect(searchableSetting("archive")).toEqual({ id: "archive", title: "Archived threads" });
78 expect(searchableSetting("prevent-automatic-sleep")).toEqual({
79 id: "prevent-automatic-sleep",
80 title: "Prevent automatic sleep",
81 });
82 });
83
84 it("routes appearance settings to their current section", () => {
85 expect(searchSettings("theme")[0]).toMatchObject({
86 id: "theme",
87 to: "/settings/appearance",
88 });
89 expect(searchSettings("word wrap")[0]).toMatchObject({
90 id: "word-wrap",
91 to: "/settings/appearance",
92 });
93 expect(searchSettings("environment identification")[0]).toMatchObject({
94 id: "environment-identification",
95 to: "/settings/appearance",
96 targetId: "appearance",
97 });
98 });
99});