Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

use-composer-command-menu.test.ts

143 lines4.3 KB

1import { describe, expect, it, vi } from "vite-plus/test";
2import { ProviderDriverKind } from "@t3tools/contracts";
3vi.mock("react-native", () => ({ Alert: { alert: vi.fn() } }));
4​
5vi.mock("../../state/queries", () => ({
6 useComposerPathSearch: () => ({ entries: [], isPending: false }),
7 useComposerPullRequestSearch: () => ({ entries: [], isPending: false, error: null }),
8}));
9vi.mock("../../state/use-composer-drafts", () => ({
10 getComposerDraftSnapshot: vi.fn(),
11 setComposerDraftContext: vi.fn(),
12}));
13vi.mock("../../lib/uuid", () => ({ uuidv4: () => "context-id" }));
14vi.mock("../../state/server", () => ({
15 serverEnvironment: { refreshProviders: Symbol("refreshProviders") },
16}));
17vi.mock("../../state/use-atom-command", () => ({
18 useAtomCommand: () => vi.fn(),
19}));
20​
21import {
22 buildComposerSlashCommandItems,
23 resolveComposerCommandSelection,
24} from "./use-composer-command-menu";
25​
26describe("mobile slash commands", () => {
27 const antigravity = {
28 driver: ProviderDriverKind.make("antigravity"),
29 showInteractionModeToggle: false,
30 slashCommands: [{ name: "plan", description: "Plan with Antigravity" }],
31 };
32​
33 it.each([false, true])(
34 "keeps native /plan with legacy mode enabled=%s",
35 (allowInteractionMode) => {
36 const items = buildComposerSlashCommandItems({
37 query: "pl",
38 atMessageStart: true,
39 hasThread: true,
40 hasSession: true,
41 allowInteractionMode,
42 selectedProviderStatus: antigravity,
43 });
44​
45 expect(items).toHaveLength(1);
46 expect(items[0]?.type).toBe("provider-slash-command");
47 const item = items[0];
48 if (!item) throw new Error("Expected the native plan command");
49 expect(
50 resolveComposerCommandSelection({
51 draftMessage: "/pl",
52 trigger: { rangeStart: 0, rangeEnd: 3 },
53 item,
54 allowInteractionMode,
55 }),
56 ).toEqual({ text: "/plan ", cursor: 6, interactionMode: null });
57 },
58 );
59​
60 it("does not offer a native command inside the message", () => {
61 expect(
62 buildComposerSlashCommandItems({
63 query: "plan",
64 atMessageStart: false,
65 hasThread: false,
66 hasSession: false,
67 allowInteractionMode: true,
68 selectedProviderStatus: antigravity,
69 }),
70 ).toEqual([]);
71 });
72​
73 it("still applies the T3 plan command for supported providers", () => {
74 const items = buildComposerSlashCommandItems({
75 query: "plan",
76 atMessageStart: true,
77 hasThread: true,
78 hasSession: true,
79 allowInteractionMode: true,
80 selectedProviderStatus: {
81 driver: ProviderDriverKind.make("codex"),
82 slashCommands: [],
83 },
84 });
85 const item = items[0];
86 if (!item) throw new Error("Expected the T3 plan command");
87 expect(
88 resolveComposerCommandSelection({
89 draftMessage: "/plan",
90 trigger: { rangeStart: 0, rangeEnd: 5 },
91 item,
92 allowInteractionMode: true,
93 }),
94 ).toEqual({ text: "", cursor: 0, interactionMode: "plan" });
95​
96 // A provider switch can invalidate an open menu before a tap arrives.
97 expect(
98 resolveComposerCommandSelection({
99 draftMessage: "/plan",
100 trigger: { rangeStart: 0, rangeEnd: 5 },
101 item,
102 allowInteractionMode: false,
103 }),
104 ).toEqual({ text: "/plan ", cursor: 6, interactionMode: null });
105 });
106​
107 it("offers MCP reconnect only for threads with a session", () => {
108 const claude = {
109 driver: ProviderDriverKind.make("claudeAgent"),
110 slashCommands: [],
111 };
112 expect(
113 buildComposerSlashCommandItems({
114 query: "reconnect",
115 atMessageStart: true,
116 hasThread: true,
117 hasSession: true,
118 allowInteractionMode: false,
119 selectedProviderStatus: claude,
120 }).map((item) => item.id),
121 ).toEqual(["cmd:reconnect-mcp"]);
122 expect(
123 buildComposerSlashCommandItems({
124 query: "reconnect",
125 atMessageStart: true,
126 hasThread: true,
127 hasSession: false,
128 allowInteractionMode: false,
129 selectedProviderStatus: claude,
130 }),
131 ).toEqual([]);
132 expect(
133 buildComposerSlashCommandItems({
134 query: "reconnect",
135 atMessageStart: true,
136 hasThread: false,
137 hasSession: false,
138 allowInteractionMode: false,
139 selectedProviderStatus: claude,
140 }),
141 ).toEqual([]);
142 });
143});