authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-09-05 22:31:33-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2026-09-05 22:31:33-07:00
loga9fc4dc2b010db7979dee9d11c94580fee62b44d
treec19434e8655bed4beee647dfa69ee21153edfd5a
parentf93aafcc2c166128070b32259e827f15bc2a1d82
signature Signed by PGP key B5690EEEBB952194

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


2 files changed, 26 insertions(+), 36 deletions(-)

apps/web/src/components/CommandPalette.logic.test.ts+26-34
...@@ -2,46 +2,15 @@ import { describe, expect, it, vi } from "vite-plus/test";...@@ -2,46 +2,15 @@ import { describe, expect, it, vi } from "vite-plus/test";
2import { EnvironmentId, ProjectId, ProviderInstanceId, ThreadId } from "@t3tools/contracts";2import { EnvironmentId, ProjectId, ProviderInstanceId, ThreadId } from "@t3tools/contracts";
3import type { Thread } from "../types";3import type { Thread } from "../types";
4import {4import {
5 browseInputEndPaddingClass,
6 buildBrowseGroups,5 buildBrowseGroups,
7 buildThreadActionItems,6 buildThreadActionItems,
8 enumerateCommandPaletteItems,7 enumerateCommandPaletteItems,
9 filterPinnedBrowseEntries,8 filterPinnedBrowseEntries,
10 filterCommandPaletteGroups,9 filterCommandPaletteGroups,
11 normalizeSearchText,
12 reduceCommandPaletteUiState,10 reduceCommandPaletteUiState,
13 type CommandPaletteGroup,11 type CommandPaletteGroup,
14} from "./CommandPalette.logic";12} from "./CommandPalette.logic";
1513
16describe("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
45describe("reduceCommandPaletteUiState", () => {14describe("reduceCommandPaletteUiState", () => {
46 const closedState = { open: false, mode: "command", openIntent: null } as const;15 const closedState = { open: false, mode: "command", openIntent: null } as const;
4716
...@@ -333,10 +302,33 @@ describe("buildThreadActionItems", () => {...@@ -333,10 +302,33 @@ describe("buildThreadActionItems", () => {
333 });302 });
334303
335 it("normalizes case independently of the host locale", () => {304 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 });
337 try {311 try {
338 expect(normalizeSearchText("GIT")).toBe("git");312 const groups = filterCommandPaletteGroups({
339 expect(localeLowerCase).not.toHaveBeenCalled();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 ]);
340 } finally {332 } finally {
341 localeLowerCase.mockRestore();333 localeLowerCase.mockRestore();
342 }334 }
apps/web/src/components/CommandPalette.logic.ts-2
...@@ -13,8 +13,6 @@ import { normalizeSearchText } from "../lib/utils";...@@ -13,8 +13,6 @@ import { normalizeSearchText } from "../lib/utils";
13import { formatRelativeTimeLabel } from "../timestampFormat";13import { formatRelativeTimeLabel } from "../timestampFormat";
14import { type Project, type SidebarThreadSummary, type Thread } from "../types";14import { type Project, type SidebarThreadSummary, type Thread } from "../types";
1515
16export { normalizeSearchText } from "../lib/utils";
17
18export const RECENT_THREAD_LIMIT = 12;16export const RECENT_THREAD_LIMIT = 12;
19export const ITEM_ICON_CLASS = "size-4 text-icon-muted";17export const ITEM_ICON_CLASS = "size-4 text-icon-muted";
20export const ADDON_ICON_CLASS = "size-4";18export const ADDON_ICON_CLASS = "size-4";