The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { filterCommandPaletteItems, type CommandPaletteItem } from "./commandPaletteItems"; |
| 4 | |
| 5 | const NOW = Date.UTC(2026, 9, 23); |
| 6 | |
| 7 | function item( |
| 8 | key: string, |
| 9 | title: string, |
| 10 | kind: CommandPaletteItem["kind"], |
| 11 | searchTerms: string[] = [], |
| 12 | ): CommandPaletteItem { |
| 13 | return { |
| 14 | key, |
| 15 | title, |
| 16 | kind, |
| 17 | searchTerms, |
| 18 | ...(kind === "thread" ? { threadSearch: { title, activityAt: NOW } } : {}), |
| 19 | run: () => {}, |
| 20 | }; |
| 21 | } |
| 22 | |
| 23 | const items = [ |
| 24 | item("new", "New thread in…", "action", ["project", "create"]), |
| 25 | item("settings", "Open settings", "action", ["preferences"]), |
| 26 | item("project", "Mobile app", "project", ["/workspaces/mobile", "new thread"]), |
| 27 | item("siva:one", "Keyboard shortcuts", "thread"), |
| 28 | item("mac:one", "Mobile app layout", "thread"), |
| 29 | ]; |
| 30 | const keys = (results: ReadonlyArray<{ readonly key: string }>) => |
| 31 | results.map((entry) => entry.key); |
| 32 | |
| 33 | describe("filterCommandPaletteItems", () => { |
| 34 | it("ranks like the web palette, whole words first, with every token required", () => { |
| 35 | // A thread active today outranks a project that matches as well, but not |
| 36 | // one whose whole name was typed. |
| 37 | expect(keys(filterCommandPaletteItems(items, "mobile", [], NOW))).toEqual([ |
| 38 | "mac:one", |
| 39 | "project", |
| 40 | ]); |
| 41 | expect(keys(filterCommandPaletteItems(items, " MOBILE app ", [], NOW))).toEqual([ |
| 42 | "project", |
| 43 | "mac:one", |
| 44 | ]); |
| 45 | expect(keys(filterCommandPaletteItems(items, "keyboard short", [], NOW))).toEqual(["siva:one"]); |
| 46 | }); |
| 47 | |
| 48 | it("lists message matches after the other results, once, except in actions-only mode", () => { |
| 49 | const results = filterCommandPaletteItems(items, "layout", ["siva:one", "mac:one"], NOW); |
| 50 | expect(results.map((entry) => [entry.key, entry.fromMessages ?? false])).toEqual([ |
| 51 | ["mac:one", false], |
| 52 | ["siva:one", true], |
| 53 | ]); |
| 54 | expect(filterCommandPaletteItems(items, "> layout", ["siva:one"], NOW)).toEqual([]); |
| 55 | }); |
| 56 | }); |