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("work")).toEqual([]);
49 });
50
51 it("keeps catalog order for multiple title matches", () => {
52 expect(searchSettings("update", ITEMS).map((item) => item.id)).toEqual([
53 "provider-updates",
54 "automatic-updates",
55 ]);
56 });
57
58 it("returns no results for an empty query", () => {
59 expect(searchSettings(" ", ITEMS)).toEqual([]);
60 });
61
62 it("keeps catalog result ids unique", () => {
63 const ids = SETTINGS_SEARCH_ITEMS.map((item) => item.id);
64 expect(new Set(ids).size).toBe(ids.length);
65 });
66
67 it("serves anchor props to panels from the catalog", () => {
68 expect(searchableSetting("word-wrap")).toEqual({ id: "word-wrap", title: "Word wrap" });
69 expect(searchableSetting("archive")).toEqual({ id: "archive", title: "Archived threads" });
70 });
71
72 it("routes appearance settings to their current section", () => {
73 expect(searchSettings("theme")[0]).toMatchObject({
74 id: "theme",
75 to: "/settings/appearance",
76 });
77 expect(searchSettings("word wrap")[0]).toMatchObject({
78 id: "word-wrap",
79 to: "/settings/appearance",
80 });
81 expect(searchSettings("environment identification")[0]).toMatchObject({
82 id: "environment-identification",
83 to: "/settings/appearance",
84 targetId: "appearance",
85 });
86 });
87});