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(searchSettings("quit confirmation")).toEqual([]);
66 });
67
68 it("keeps catalog result ids unique", () => {
69 const ids = SETTINGS_SEARCH_ITEMS.map((item) => item.id);
70 expect(new Set(ids).size).toBe(ids.length);
71 });
72
73 it("serves anchor props to panels from the catalog", () => {
74 expect(searchableSetting("word-wrap")).toEqual({ id: "word-wrap", title: "Word wrap" });
75 expect(searchableSetting("archive")).toEqual({ id: "archive", title: "Archived threads" });
76 });
77
78 it("routes appearance settings to their current section", () => {
79 expect(searchSettings("theme")[0]).toMatchObject({
80 id: "theme",
81 to: "/settings/appearance",
82 });
83 expect(searchSettings("word wrap")[0]).toMatchObject({
84 id: "word-wrap",
85 to: "/settings/appearance",
86 });
87 expect(searchSettings("environment identification")[0]).toMatchObject({
88 id: "environment-identification",
89 to: "/settings/appearance",
90 targetId: "appearance",
91 });
92 });
93});