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

settings-search.test.ts

68 lines2.0 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 ],
20 },
21 {
22 title: "Server settings",
23 rows: [
24 { id: "SettingsProviderAccounts", label: "Provider accounts" },
25 { id: "SettingsEnvironmentSourceControl", label: "Source control" },
26 ],
27 },
28];
29​
30function visible(query: string) {
31 return filterSettingsSections(SECTIONS, query).map((section) => [
32 section.title ?? null,
33 section.rows.map((row) => row.label),
34 ]);
36​
37describe("filterSettingsSections", () => {
38 it.each([
39 {
40 query: "",
41 expected: SECTIONS.map((section) => [
42 section.title ?? null,
43 section.rows.map((row) => row.label),
44 ]),
45 },
46 { query: " ", expected: visible("") },
47 { query: "appear", expected: [["Interface", ["Appearance"]]] },
48 { query: "KEYBOARD", expected: [["Interface", ["Keyboard"]]] },
49 { query: "dark mode", expected: [["Interface", ["Appearance"]]] },
50 { query: "agent credits", expected: [["Server settings", ["Source control"]]] },
51 {
52 query: "server settings",
53 expected: [["Server settings", ["Provider accounts", "Source control"]]],
54 },
55 {
56 query: "accounts",
57 expected: [["Server settings", ["Provider accounts"]]],
58 },
59 { query: "usage", expected: [[null, ["Usage"]]] },
60 { query: "zzzz", expected: [] },
61 ])("$query", ({ query, expected }) => {
62 expect(visible(query)).toEqual(expected);
63 });
64​
65 it("drops sections that start empty", () => {
66 expect(filterSettingsSections([{ rows: [] }, ...SECTIONS], "").length).toBe(SECTIONS.length);
67 });
68});