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

use-composer-command-menu.test.ts

92 lines2.8 KB

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 readComposerDraftSelection: vi.fn(),
13 setComposerDraftContext: 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} from "./use-composer-command-menu";
27​
28describe("mobile slash commands", () => {
29 const antigravity = {
30 driver: ProviderDriverKind.make("antigravity"),
31 showInteractionModeToggle: false,
32 slashCommands: [{ name: "plan", description: "Plan with Antigravity" }],
33 };
34​
35 it.each([false, true])(
36 "keeps native /plan with legacy mode enabled=%s",
37 (allowInteractionMode) => {
38 const items = buildComposerSlashCommandItems({
39 query: "pl",
40 atMessageStart: true,
41 hasThread: true,
42 allowInteractionMode,
43 selectedProviderStatus: antigravity,
44 });
45​
46 expect(items).toHaveLength(1);
47 expect(items[0]?.type).toBe("provider-slash-command");
48 const item = items[0];
49 if (!item) throw new Error("Expected the native plan command");
50 expect(
51 resolveComposerCommandSelection({
52 draftMessage: "/pl",
53 trigger: { rangeStart: 0, rangeEnd: 3 },
54 item,
55 allowInteractionMode,
56 }),
57 ).toEqual({ text: "/plan ", cursor: 6, interactionMode: null });
58 },
59 );
60​
61 it("still applies the T3 plan command for supported providers", () => {
62 const items = buildComposerSlashCommandItems({
63 query: "plan",
64 atMessageStart: true,
65 hasThread: true,
66 allowInteractionMode: true,
67 selectedProviderStatus: {
68 driver: ProviderDriverKind.make("codex"),
69 slashCommands: [],
70 },
71 });
72 const item = items[0];
73 if (!item) throw new Error("Expected the T3 plan command");
74 expect(
75 resolveComposerCommandSelection({
76 draftMessage: "/plan",
77 trigger: { rangeStart: 0, rangeEnd: 5 },
78 item,
79 allowInteractionMode: true,
80 }),
81 ).toEqual({ text: "", cursor: 0, interactionMode: "plan" });
82​
83 expect(
84 resolveComposerCommandSelection({
85 draftMessage: "/plan",
86 trigger: { rangeStart: 0, rangeEnd: 5 },
87 item,
88 allowInteractionMode: false,
89 }),
90 ).toEqual({ text: "/plan ", cursor: 6, interactionMode: null });
91 });
92});