Open History to see the last commit
1import { describe, expect, it, vi } from "vite-plus/test";
2import { ProviderDriverKind } from "@t3tools/contracts";
3
4const refreshProviders = vi.hoisted(() => vi.fn());
5vi.mock("react-native", () => ({ Alert: { alert: vi.fn() } }));
6
7vi.mock("../../state/queries", () => ({
8 useComposerPathSearch: () => ({ entries: [], isPending: false }),
9 useComposerPullRequestSearch: () => ({ entries: [], isPending: false, error: null }),
10}));
11vi.mock("../../state/use-composer-drafts", () => ({
12 getComposerDraftSnapshot: vi.fn(),
13 readComposerDraftSelection: vi.fn(),
14 setComposerDraftContext: vi.fn(),
15}));
16vi.mock("../../lib/uuid", () => ({ uuidv4: () => "context-id" }));
17vi.mock("../../state/server", () => ({
18 serverEnvironment: { refreshProviders: Symbol("refreshProviders") },
19}));
20vi.mock("../../state/use-atom-command", () => ({
21 useAtomCommand: () => refreshProviders,
22}));
23
24import {
25 buildComposerSlashCommandItems,
26 resolveComposerCommandSelection,
27} from "./use-composer-command-menu";
28
29describe("mobile slash commands", () => {
30 const antigravity = {
31 driver: ProviderDriverKind.make("antigravity"),
32 showInteractionModeToggle: false,
33 slashCommands: [{ name: "plan", description: "Plan with Antigravity" }],
34 };
35
36 it.each([false, true])(
37 "keeps native /plan with legacy mode enabled=%s",
38 (allowInteractionMode) => {
39 const items = buildComposerSlashCommandItems({
40 query: "pl",
41 atMessageStart: true,
42 hasThread: true,
43 allowInteractionMode,
44 selectedProviderStatus: antigravity,
45 });
46
47 expect(items).toHaveLength(1);
48 expect(items[0]?.type).toBe("provider-slash-command");
49 const item = items[0];
50 if (!item) throw new Error("Expected the native plan command");
51 expect(
52 resolveComposerCommandSelection({
53 draftMessage: "/pl",
54 trigger: { rangeStart: 0, rangeEnd: 3 },
55 item,
56 allowInteractionMode,
57 }),
58 ).toEqual({ text: "/plan ", cursor: 6, interactionMode: null });
59 },
60 );
61
62 it("still applies the T3 plan command for supported providers", () => {
63 const items = buildComposerSlashCommandItems({
64 query: "plan",
65 atMessageStart: true,
66 hasThread: true,
67 allowInteractionMode: true,
68 selectedProviderStatus: {
69 driver: ProviderDriverKind.make("codex"),
70 slashCommands: [],
71 },
72 });
73 const item = items[0];
74 if (!item) throw new Error("Expected the T3 plan command");
75 expect(
76 resolveComposerCommandSelection({
77 draftMessage: "/plan",
78 trigger: { rangeStart: 0, rangeEnd: 5 },
79 item,
80 allowInteractionMode: true,
81 }),
82 ).toEqual({ text: "", cursor: 0, interactionMode: "plan" });
83
84 expect(
85 resolveComposerCommandSelection({
86 draftMessage: "/plan",
87 trigger: { rangeStart: 0, rangeEnd: 5 },
88 item,
89 allowInteractionMode: false,
90 }),
91 ).toEqual({ text: "/plan ", cursor: 6, interactionMode: null });
92 });
93});