Open History to see the last commit
1import { describe, expect, it, vi } from "vite-plus/test";
2import { ProviderDriverKind } from "@t3tools/contracts";
3
4vi.mock("react-native", () => ({ Alert: { alert: vi.fn() } }));
5
6vi.mock("../../state/queries", () => ({
7 useComposerPathSearch: () => ({ entries: [], isPending: false }),
8 useComposerPullRequestSearch: () => ({ entries: [], isPending: false, error: null }),
9}));
10vi.mock("../../state/use-composer-drafts", () => ({
11 getComposerDraftSnapshot: vi.fn(),
12 setComposerDraftContext: vi.fn(),
13 useComposerDraftSelection: vi.fn(),
14}));
15vi.mock("../../lib/uuid", () => ({ uuidv4: () => "context-id" }));
16vi.mock("../../state/server", () => ({
17 serverEnvironment: {
18 providersValueAtom: vi.fn(),
19 refreshProviders: Symbol("refreshProviders"),
20 },
21}));
22
23import {
24 buildComposerSlashCommandItems,
25 resolveComposerCommandSelection,
26 resolveComposerMenuSelection,
27} from "./use-composer-command-menu";
28
29describe("resolveComposerMenuSelection", () => {
30 it("prefers the caret an insertion placed in the current draft text", () => {
31 expect(
32 resolveComposerMenuSelection({
33 draftMessage: "hello @chip ",
34 ownerKey: "draft-a",
35 inserted: { start: 12, end: 12 },
36 local: { ownerKey: "draft-a", start: 2, end: 2 },
37 }),
38 ).toEqual({ start: 12, end: 12 });
39 });
40
41 it("clamps the composer's own caret when the draft shrinks", () => {
42 expect(
43 resolveComposerMenuSelection({
44 draftMessage: "hi",
45 ownerKey: "draft-a",
46 inserted: null,
47 local: { ownerKey: "draft-a", start: 5, end: 9 },
48 }),
49 ).toEqual({ start: 2, end: 2 });
50 });
51
52 it("starts at the end of the draft after switching owners", () => {
53 expect(
54 resolveComposerMenuSelection({
55 draftMessage: "other draft",
56 ownerKey: "draft-b",
57 inserted: null,
58 local: { ownerKey: "draft-a", start: 1, end: 1 },
59 }),
60 ).toEqual({ start: 11, end: 11 });
61 });
62});
63
64describe("mobile slash commands", () => {
65 const antigravity = {
66 driver: ProviderDriverKind.make("antigravity"),
67 showInteractionModeToggle: false,
68 slashCommands: [{ name: "plan", description: "Plan with Antigravity" }],
69 };
70
71 it.each([false, true])(
72 "keeps native /plan with legacy mode enabled=%s",
73 (allowInteractionMode) => {
74 const items = buildComposerSlashCommandItems({
75 query: "pl",
76 atMessageStart: true,
77 hasThread: true,
78 allowInteractionMode,
79 selectedProviderStatus: antigravity,
80 });
81
82 expect(items).toHaveLength(1);
83 expect(items[0]?.type).toBe("provider-slash-command");
84 const item = items[0];
85 if (!item) throw new Error("Expected the native plan command");
86 expect(
87 resolveComposerCommandSelection({
88 draftMessage: "/pl",
89 trigger: { rangeStart: 0, rangeEnd: 3 },
90 item,
91 allowInteractionMode,
92 }),
93 ).toEqual({ text: "/plan ", cursor: 6, interactionMode: null });
94 },
95 );
96
97 it("offers T3's /clear in place of the provider's, only at the message start", () => {
98 const claude = {
99 driver: ProviderDriverKind.make("claudeAgent"),
100 slashCommands: [{ name: "clear", description: "Clear conversation history" }],
101 };
102 const build = (offersFreshSession: boolean, atMessageStart = true) =>
103 buildComposerSlashCommandItems({
104 query: "cle",
105 atMessageStart,
106 hasThread: true,
107 allowInteractionMode: true,
108 offersFreshSession,
109 selectedProviderStatus: claude,
110 }).map((item) => item.id);
111 expect(build(true)).toEqual(["cmd:clear"]);
112 expect(build(false)).toEqual(["pcmd:clear"]);
113 expect(build(true, false)).toEqual([]);
114 });
115
116 it("still applies the T3 plan command for supported providers", () => {
117 const items = buildComposerSlashCommandItems({
118 query: "plan",
119 atMessageStart: true,
120 hasThread: true,
121 allowInteractionMode: true,
122 selectedProviderStatus: {
123 driver: ProviderDriverKind.make("codex"),
124 slashCommands: [],
125 },
126 });
127 const item = items[0];
128 if (!item) throw new Error("Expected the T3 plan command");
129 expect(
130 resolveComposerCommandSelection({
131 draftMessage: "/plan",
132 trigger: { rangeStart: 0, rangeEnd: 5 },
133 item,
134 allowInteractionMode: true,
135 }),
136 ).toEqual({ text: "", cursor: 0, interactionMode: "plan" });
137
138 expect(
139 resolveComposerCommandSelection({
140 draftMessage: "/plan",
141 trigger: { rangeStart: 0, rangeEnd: 5 },
142 item,
143 allowInteractionMode: false,
144 }),
145 ).toEqual({ text: "/plan ", cursor: 6, interactionMode: null });
146 });
147});