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

settings-search.test.ts

74 lines2.4 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { filterSettingsSections } from "./settings-search";
4​
5const SECTIONS = [
6 { rows: [{ id: "usage", label: "Usage" }] },
7 {
8 title: "Connections",
9 rows: [
10 { id: "account", label: "T3 Account" },
11 { id: "SettingsEnvironments", label: "Environments" },
12 ],
13 },
14 {
15 title: "Interface",
16 rows: [
17 { id: "SettingsAppearance", label: "Appearance" },
18 { id: "SettingsKeyboard", label: "Keyboard" },
19 { id: "SettingsVoice", label: "Voice" },
20 ],
21 },
22 { title: "Code", rows: [{ id: "SettingsProjectOverview", label: "Projects" }] },
23 {
24 title: "Server settings",
25 rows: [
26 { id: "SettingsProviderAccounts", label: "Provider accounts" },
27 { id: "SettingsEnvironmentSourceControl", label: "Source control & issues" },
28 ],
29 },
30];
31​
32function visible(query: string) {
33 return filterSettingsSections(SECTIONS, query).map((section) => [
34 section.title ?? null,
35 section.rows.map((row) => row.label),
36 ]);
38​
39describe("filterSettingsSections", () => {
40 it.each([
41 {
42 query: "",
43 expected: SECTIONS.map((section) => [
44 section.title ?? null,
45 section.rows.map((row) => row.label),
46 ]),
47 },
48 { query: " ", expected: visible("") },
49 { query: "appear", expected: [["Interface", ["Appearance"]]] },
50 { query: "KEYBOARD", expected: [["Interface", ["Keyboard"]]] },
51 { query: "dark mode", expected: [["Interface", ["Appearance"]]] },
52 { query: "microphone", expected: [["Interface", ["Voice"]]] },
53 { query: "agent credits", expected: [["Server settings", ["Source control & issues"]]] },
54 {
55 query: "server settings",
56 expected: [["Server settings", ["Provider accounts", "Source control & issues"]]],
57 },
58 {
59 query: "accounts",
60 expected: [["Server settings", ["Provider accounts"]]],
61 },
62 { query: "usage", expected: [[null, ["Usage"]]] },
63 { query: "pin", expected: [["Code", ["Projects"]]] },
64 { query: "pin project", expected: [["Code", ["Projects"]]] },
65 { query: "pinned projects", expected: [["Code", ["Projects"]]] },
66 { query: "zzzz", expected: [] },
67 ])("$query", ({ query, expected }) => {
68 expect(visible(query)).toEqual(expected);
69 });
70​
71 it("drops sections that start empty", () => {
72 expect(filterSettingsSections([{ rows: [] }, ...SECTIONS], "").length).toBe(SECTIONS.length);
73 });
74});