Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { filterCommandPaletteItems, type CommandPaletteItem } from "./commandPaletteItems";
4
5function item(
6 key: string,
7 title: string,
8 kind: CommandPaletteItem["kind"],
9 searchTerms: string[] = [],
10): CommandPaletteItem {
11 return { key, title, kind, searchTerms, run: () => {} };
12}
13
14const items = [
15 item("new", "New thread in…", "action", ["project", "create"]),
16 item("settings", "Open settings", "action", ["preferences"]),
17 item("project", "Mobile app", "project", ["/workspaces/mobile", "new thread"]),
18 item("siva:one", "Keyboard shortcuts", "thread", ["Mobile app", "Siva"]),
19 item("mac:one", "Mobile app", "thread", ["Mac"]),
20];
21const emptyMatches = new Set<string>();
22
23describe("filterCommandPaletteItems", () => {
24 it("matches query tokens across titles and metadata and ranks exact titles first", () => {
25 expect(
26 filterCommandPaletteItems(items, " MOBILE app ", emptyMatches).map((item) => item.key),
27 ).toEqual(["project", "mac:one", "siva:one"]);
28 expect(
29 filterCommandPaletteItems(items, "siva keyboard", emptyMatches).map((item) => item.key),
30 ).toEqual(["siva:one"]);
31 });
32
33 it("includes server content matches scoped to the correct environment, except in actions-only mode", () => {
34 const matches = new Set(["siva:one", "project"]);
35 expect(
36 filterCommandPaletteItems(items, "message content", matches).map((item) => item.key),
37 ).toEqual(["siva:one"]);
38 expect(filterCommandPaletteItems(items, "> message content", matches)).toEqual([]);
39 });
40});