History

test(web): focus command palette tests on search behavior (#10302)

Julius Marminge committed 2 months ago

Commit a9fc4dc1 parent f93aafc2 files · +26 −36Browse files

Unified · Split

2 files
  1. apps/web/src/components/CommandPalette.logic.test.ts +26 −34
  2. apps/web/src/components/CommandPalette.logic.ts +0 −2
apps/web/src/components/CommandPalette.logic.test.ts+26−34
@@ -2,46 +2,15 @@ import { describe, expect, it, vi } from "vite-plus/test"; · 1 unmodified line
22 import { EnvironmentId, ProjectId, ProviderInstanceId, ThreadId } from "@t3tools/contracts";
33 import type { Thread } from "../types";
44 import {
5− browseInputEndPaddingClass,
65 buildBrowseGroups,
76 buildThreadActionItems,
87 enumerateCommandPaletteItems,
98 filterPinnedBrowseEntries,
109 filterCommandPaletteGroups,
11− normalizeSearchText,
1210 reduceCommandPaletteUiState,
1311 type CommandPaletteGroup,
1412 } from "./CommandPalette.logic";
1513
16−describe("browseInputEndPaddingClass", () => {
17− it("reserves the widest space for the create action", () => {
18− expect(
19− browseInputEndPaddingClass({
20− willCreateProjectPath: true,
21− hasHighlightedBrowseItem: false,
22− }),
23− ).toContain("pe-38");
24− });
25−
26− it("reserves space for the wider highlighted-item shortcut", () => {
27− expect(
28− browseInputEndPaddingClass({
29− willCreateProjectPath: false,
30− hasHighlightedBrowseItem: true,
31− }),
32− ).toContain("pe-30");
33− });
34−
35− it("keeps the compact reserve for the normal add action", () => {
36− expect(
37− browseInputEndPaddingClass({
38− willCreateProjectPath: false,
39− hasHighlightedBrowseItem: false,
40− }),
41− ).toContain("pe-24");
42− });
43−});
44−
4514 describe("reduceCommandPaletteUiState", () => {
4615 const closedState = { open: false, mode: "command", openIntent: null } as const;
4716
@@ -333,10 +302,33 @@ describe("buildThreadActionItems", () => { · 285 unmodified lines
333302 });
334303
335304 it("normalizes case independently of the host locale", () => {
336− const localeLowerCase = vi.spyOn(String.prototype, "toLocaleLowerCase").mockReturnValue("gıt");
305+ const toLocaleLowerCase = String.prototype.toLocaleLowerCase;
306+ const localeLowerCase = vi
307+ .spyOn(String.prototype, "toLocaleLowerCase")
308+ .mockImplementation(function (this: string) {
309+ return toLocaleLowerCase.call(this, "tr");
310+ });
337311 try {
338− expect(normalizeSearchText("GIT")).toBe("git");
339− expect(localeLowerCase).not.toHaveBeenCalled();
312+ const groups = filterCommandPaletteGroups({
313+ activeGroups: [],
314+ query: "GIT",
315+ isInSubmenu: false,
316+ projectSearchItems: [],
317+ threadSearchItems: [],
318+ settingsSearchItems: [
319+ {
320+ kind: "action",
321+ value: "setting:version-control",
322+ title: "Version control",
323+ searchTerms: ["git"],
324+ icon: null,
325+ run: async () => undefined,
326+ },
327+ ],
328+ });
329+ expect(groups.flatMap((group) => group.items.map((item) => item.value))).toEqual([
330+ "setting:version-control",
331+ ]);
340332 } finally {
341333 localeLowerCase.mockRestore();
342334 }
apps/web/src/components/CommandPalette.logic.ts+0−2
@@ -13,8 +13,6 @@ import { normalizeSearchText } from "../lib/utils"; · 12 unmodified lines
1313 import { formatRelativeTimeLabel } from "../timestampFormat";
1414 import { type Project, type SidebarThreadSummary, type Thread } from "../types";
1515
16−export { normalizeSearchText } from "../lib/utils";
17−
1816 export const RECENT_THREAD_LIMIT = 12;
1917 export const ITEM_ICON_CLASS = "size-4 text-icon-muted";
2018 export const ADDON_ICON_CLASS = "size-4";