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("still applies the T3 plan command for supported providers", () => {
98 const items = buildComposerSlashCommandItems({
99 query: "plan",
100 atMessageStart: true,
101 hasThread: true,
102 allowInteractionMode: true,
103 selectedProviderStatus: {
104 driver: ProviderDriverKind.make("codex"),
105 slashCommands: [],
106 },
107 });
108 const item = items[0];
109 if (!item) throw new Error("Expected the T3 plan command");
110 expect(
111 resolveComposerCommandSelection({
112 draftMessage: "/plan",
113 trigger: { rangeStart: 0, rangeEnd: 5 },
114 item,
115 allowInteractionMode: true,
116 }),
117 ).toEqual({ text: "", cursor: 0, interactionMode: "plan" });
118
119 expect(
120 resolveComposerCommandSelection({
121 draftMessage: "/plan",
122 trigger: { rangeStart: 0, rangeEnd: 5 },
123 item,
124 allowInteractionMode: false,
125 }),
126 ).toEqual({ text: "/plan ", cursor: 6, interactionMode: null });
127 });
128});