import { describe, expect, it, vi } from "vite-plus/test";import { ProviderDriverKind } from "@t3tools/contracts"; vi.mock("../../state/queries", () => ({ useComposerPathSearch: () => ({ entries: [], isPending: false }),}));vi.mock("../../state/server", () => ({ serverEnvironment: { refreshProviders: Symbol("refreshProviders") },}));vi.mock("../../state/use-atom-command", () => ({ useAtomCommand: () => vi.fn(),})); import { buildComposerSlashCommandItems, resolveComposerCommandSelection,} from "./use-composer-command-menu"; describe("mobile slash commands", () => { const antigravity = { driver: ProviderDriverKind.make("antigravity"), showInteractionModeToggle: false, slashCommands: [{ name: "plan", description: "Plan with Antigravity" }], }; it.each([false, true])( "keeps native /plan with legacy mode enabled=%s", (allowInteractionMode) => { const items = buildComposerSlashCommandItems({ query: "pl", atMessageStart: true, hasThread: true, allowInteractionMode, selectedProviderStatus: antigravity, }); expect(items).toHaveLength(1); expect(items[0]?.type).toBe("provider-slash-command"); const item = items[0]; if (!item) throw new Error("Expected the native plan command"); expect( resolveComposerCommandSelection({ draftMessage: "/pl", trigger: { rangeStart: 0, rangeEnd: 3 }, item, allowInteractionMode, }), ).toEqual({ text: "/plan ", cursor: 6, interactionMode: null }); }, ); it("does not offer a native command inside the message", () => { expect( buildComposerSlashCommandItems({ query: "plan", atMessageStart: false, hasThread: false, allowInteractionMode: true, selectedProviderStatus: antigravity, }), ).toEqual([]); }); it("still applies the T3 plan command for supported providers", () => { const items = buildComposerSlashCommandItems({ query: "plan", atMessageStart: true, hasThread: true, allowInteractionMode: true, selectedProviderStatus: { driver: ProviderDriverKind.make("codex"), slashCommands: [], }, }); const item = items[0]; if (!item) throw new Error("Expected the T3 plan command"); expect( resolveComposerCommandSelection({ draftMessage: "/plan", trigger: { rangeStart: 0, rangeEnd: 5 }, item, allowInteractionMode: true, }), ).toEqual({ text: "", cursor: 0, interactionMode: "plan" }); // A provider switch can invalidate an open menu before a tap arrives. expect( resolveComposerCommandSelection({ draftMessage: "/plan", trigger: { rangeStart: 0, rangeEnd: 5 }, item, allowInteractionMode: false, }), ).toEqual({ text: "/plan ", cursor: 6, interactionMode: null }); });});
import { describe, expect, it, vi } from "vite-plus/test";
import { ProviderDriverKind } from "@t3tools/contracts";
vi.mock("../../state/queries", () => ({
useComposerPathSearch: () => ({ entries: [], isPending: false }),
}));
vi.mock("../../state/server", () => ({
serverEnvironment: { refreshProviders: Symbol("refreshProviders") },
}));
vi.mock("../../state/use-atom-command", () => ({
useAtomCommand: () => vi.fn(),
}));
import {
buildComposerSlashCommandItems,
resolveComposerCommandSelection,
} from "./use-composer-command-menu";
describe("mobile slash commands", () => {
const antigravity = {
driver: ProviderDriverKind.make("antigravity"),
showInteractionModeToggle: false,
slashCommands: [{ name: "plan", description: "Plan with Antigravity" }],
};
it.each([false, true])(
"keeps native /plan with legacy mode enabled=%s",
(allowInteractionMode) => {
const items = buildComposerSlashCommandItems({
query: "pl",
atMessageStart: true,
hasThread: true,
allowInteractionMode,
selectedProviderStatus: antigravity,
});
expect(items).toHaveLength(1);
expect(items[0]?.type).toBe("provider-slash-command");
const item = items[0];
if (!item) throw new Error("Expected the native plan command");
expect(
resolveComposerCommandSelection({
draftMessage: "/pl",
trigger: { rangeStart: 0, rangeEnd: 3 },
item,
allowInteractionMode,
}),
).toEqual({ text: "/plan ", cursor: 6, interactionMode: null });
},
);
it("does not offer a native command inside the message", () => {
expect(
buildComposerSlashCommandItems({
query: "plan",
atMessageStart: false,
hasThread: false,
allowInteractionMode: true,
selectedProviderStatus: antigravity,
}),
).toEqual([]);
});
it("still applies the T3 plan command for supported providers", () => {
const items = buildComposerSlashCommandItems({
query: "plan",
atMessageStart: true,
hasThread: true,
allowInteractionMode: true,
selectedProviderStatus: {
driver: ProviderDriverKind.make("codex"),
slashCommands: [],
},
});
const item = items[0];
if (!item) throw new Error("Expected the T3 plan command");
expect(
resolveComposerCommandSelection({
draftMessage: "/plan",
trigger: { rangeStart: 0, rangeEnd: 5 },
item,
allowInteractionMode: true,
}),
).toEqual({ text: "", cursor: 0, interactionMode: "plan" });
// A provider switch can invalidate an open menu before a tap arrives.
expect(
resolveComposerCommandSelection({
draftMessage: "/plan",
trigger: { rangeStart: 0, rangeEnd: 5 },
item,
allowInteractionMode: false,
}),
).toEqual({ text: "/plan ", cursor: 6, interactionMode: null });
});
});