@@ -13,7 +13,7 @@ vi.mock("../SidebarStageBackdrop", () => ({
1313 useSidebarStageBackdropVariant : ( ) => null ,
1414} ) ) ;
1515
16- import { ComposerPrimaryActions } from "./ComposerPrimaryActions" ;
16+ import { CollapsedComposerStopAction , ComposerPrimaryActions } from "./ComposerPrimaryActions" ;
1717
1818function setup ( ) {
1919 return {
@@ -142,3 +142,33 @@ it("keeps a pending stop when the run id clears and resets it for a different ru
142142 await screen . rerender ( < ComposerPrimaryActions { ...props } runId = "second" /> ) ;
143143 expect ( screen . getByRole ( "button" , { name : "Stop generation" } ) . element ( ) ) . toBeEnabled ( ) ;
144144} ) ;
145+
146+ it ( "swaps the collapsed composer's send button for Stop while a turn can be stopped" , async ( ) => {
147+ const onInterrupt = vi . fn ( ) ;
148+ const collapsed = ( overrides : { canInterrupt ?: boolean ; hasSendableContent ?: boolean } = { } ) => (
149+ < CollapsedComposerStopAction
150+ canOperateThread
151+ canInterrupt = { overrides . canInterrupt ?? true }
152+ runId = "run"
153+ hasSendableContent = { overrides . hasSendableContent ?? false }
154+ isEditingQueuedMessage = { false }
155+ onInterrupt = { onInterrupt }
156+ >
157+ < button type = "button" > Send message</ button >
158+ </ CollapsedComposerStopAction >
159+ ) ;
160+ await using screen = await render ( collapsed ( { hasSendableContent : true } ) ) ;
161+ await expect . element ( screen . getByRole ( "button" , { name : "Send message" } ) ) . toBeVisible ( ) ;
162+ await screen . rerender ( collapsed ( ) ) ;
163+ await act ( ( ) =>
164+ (
165+ screen . getByRole ( "button" , { name : "Stop generation" } ) . element ( ) as HTMLButtonElement
166+ ) . click ( ) ,
167+ ) ;
168+ expect ( onInterrupt ) . toHaveBeenCalledTimes ( 1 ) ;
169+ await expect
170+ . element ( screen . getByRole ( "button" , { name : "Stopping" , exact : true } ) )
171+ . toBeDisabled ( ) ;
172+ await screen . rerender ( collapsed ( { canInterrupt : false } ) ) ;
173+ await expect . element ( screen . getByRole ( "button" , { name : "Send message" } ) ) . toBeVisible ( ) ;
174+ } ) ;
0 commit comments