Open History to see the last commit
1import { type ProviderModelOptions, ThreadId } from "@t3tools/contracts";
2import "../../index.css";
3
4import { page } from "vitest/browser";
5import { afterEach, describe, expect, it, vi } from "vitest";
6import { render } from "vitest-browser-react";
7
8import { CompactComposerControlsMenu } from "./CompactComposerControlsMenu";
9import { ClaudeTraitsMenuContent } from "./ClaudeTraitsPicker";
10import { CodexTraitsMenuContent } from "./CodexTraitsPicker";
11import { useComposerDraftStore } from "../../composerDraftStore";
12
13async function mountMenu(props?: {
14 model?: string;
15 prompt?: string;
16 provider?: "codex" | "claudeAgent";
17 modelOptions?: ProviderModelOptions | null;
18}) {
19 const threadId = ThreadId.makeUnsafe("thread-compact-menu");
20 const provider = props?.provider ?? "claudeAgent";
21 const draftsByThreadId = {} as ReturnType<
22 typeof useComposerDraftStore.getState
23 >["draftsByThreadId"];
24 draftsByThreadId[threadId] = {
25 prompt: props?.prompt ?? "",
26 images: [],
27 nonPersistedImageIds: [],
28 persistedAttachments: [],
29 terminalContexts: [],
30 provider,
31 model: props?.model ?? "claude-opus-4-6",
32 modelOptions: props?.modelOptions ?? null,
33 runtimeMode: null,
34 interactionMode: null,
35 };
36 useComposerDraftStore.setState({
37 draftsByThreadId,
38 draftThreadsByThreadId: {},
39 projectDraftThreadIdByProjectId: {},
40 });
41 const host = document.createElement("div");
42 document.body.append(host);
43 const onPromptChange = vi.fn();
44 const screen = await render(
45 <CompactComposerControlsMenu
46 activePlan={false}
47 interactionMode="default"
48 planSidebarOpen={false}
49 runtimeMode="approval-required"
50 traitsMenuContent={
51 provider === "codex" ? (
52 <CodexTraitsMenuContent threadId={threadId} />
53 ) : (
54 <ClaudeTraitsMenuContent
55 threadId={threadId}
56 model={props?.model ?? "claude-opus-4-6"}
57 onPromptChange={onPromptChange}
58 />
59 )
60 }
61 onToggleInteractionMode={vi.fn()}
62 onTogglePlanSidebar={vi.fn()}
63 onToggleRuntimeMode={vi.fn()}
64 />,
65 { container: host },
66 );
67
68 return {
69 cleanup: async () => {
70 await screen.unmount();
71 host.remove();
72 },
73 };
74}
75
76describe("CompactComposerControlsMenu", () => {
77 afterEach(() => {
78 document.body.innerHTML = "";
79 useComposerDraftStore.setState({
80 draftsByThreadId: {},
81 draftThreadsByThreadId: {},
82 projectDraftThreadIdByProjectId: {},
83 });
84 });
85
86 it("shows fast mode controls for Opus", async () => {
87 const mounted = await mountMenu();
88
89 try {
90 await page.getByLabelText("More composer controls").click();
91
92 await vi.waitFor(() => {
93 const text = document.body.textContent ?? "";
94 expect(text).toContain("Fast Mode");
95 expect(text).toContain("off");
96 expect(text).toContain("on");
97 });
98 } finally {
99 await mounted.cleanup();
100 }
101 });
102
103 it("hides fast mode controls for non-Opus Claude models", async () => {
104 const mounted = await mountMenu({ model: "claude-sonnet-4-6" });
105
106 try {
107 await page.getByLabelText("More composer controls").click();
108
109 await vi.waitFor(() => {
110 expect(document.body.textContent ?? "").not.toContain("Fast Mode");
111 });
112 } finally {
113 await mounted.cleanup();
114 }
115 });
116
117 it("shows only the provided effort options", async () => {
118 const mounted = await mountMenu({
119 model: "claude-sonnet-4-6",
120 });
121
122 try {
123 await page.getByLabelText("More composer controls").click();
124
125 await vi.waitFor(() => {
126 const text = document.body.textContent ?? "";
127 expect(text).toContain("Low");
128 expect(text).toContain("Medium");
129 expect(text).toContain("High");
130 expect(text).not.toContain("Max");
131 expect(text).toContain("Ultrathink");
132 });
133 } finally {
134 await mounted.cleanup();
135 }
136 });
137
138 it("shows a Claude thinking on/off section for Haiku", async () => {
139 const mounted = await mountMenu({
140 model: "claude-haiku-4-5",
141 modelOptions: {
142 claudeAgent: {
143 thinking: true,
144 },
145 },
146 });
147
148 try {
149 await page.getByLabelText("More composer controls").click();
150
151 await vi.waitFor(() => {
152 const text = document.body.textContent ?? "";
153 expect(text).toContain("Thinking");
154 expect(text).toContain("On (default)");
155 expect(text).toContain("Off");
156 });
157 } finally {
158 await mounted.cleanup();
159 }
160 });
161
162 it("shows prompt-controlled Ultrathink messaging with disabled effort controls", async () => {
163 const mounted = await mountMenu({
164 model: "claude-opus-4-6",
165 prompt: "Ultrathink:\nInvestigate this",
166 modelOptions: {
167 claudeAgent: {
168 effort: "high",
169 },
170 },
171 });
172
173 try {
174 await page.getByLabelText("More composer controls").click();
175
176 await vi.waitFor(() => {
177 const text = document.body.textContent ?? "";
178 expect(text).toContain("Effort");
179 expect(text).toContain("Remove Ultrathink from the prompt to change effort.");
180 expect(text).not.toContain("Fallback Effort");
181 });
182 } finally {
183 await mounted.cleanup();
184 }
185 });
186});