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

settingsSearch.test.ts

101 lines3.0 KB

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("lists thread confirmations in panel order", () => {
60 expect(searchSettings("confirmation").map((item) => item.id)).toEqual([
61 "unpin-confirmation",
62 "archive-confirmation",
63 "delete-confirmation",
64 ]);
65 });
66​
67 it("returns no results for an empty query", () => {
68 expect(searchSettings(" ", ITEMS)).toEqual([]);
69 });
70​
71 it("hides desktop-only settings from browser search", () => {
72 expect(SETTINGS_SEARCH_ITEMS.some((item) => item.id === "quit-confirmation")).toBe(true);
73 expect(searchSettings("quit confirmation")).toEqual([]);
74 });
75​
76 it("keeps catalog result ids unique", () => {
77 const ids = SETTINGS_SEARCH_ITEMS.map((item) => item.id);
78 expect(new Set(ids).size).toBe(ids.length);
79 });
80​
81 it("serves anchor props to panels from the catalog", () => {
82 expect(searchableSetting("word-wrap")).toEqual({ id: "word-wrap", title: "Word wrap" });
83 expect(searchableSetting("archive")).toEqual({ id: "archive", title: "Archived threads" });
84 });
85​
86 it("routes appearance settings to their current section", () => {
87 expect(searchSettings("theme")[0]).toMatchObject({
88 id: "theme",
89 to: "/settings/appearance",
90 });
91 expect(searchSettings("word wrap")[0]).toMatchObject({
92 id: "word-wrap",
93 to: "/settings/appearance",
94 });
95 expect(searchSettings("environment identification")[0]).toMatchObject({
96 id: "environment-identification",
97 to: "/settings/appearance",
98 targetId: "appearance",
99 });
100 });
101});