@@ -15,15 +15,10 @@ vi.mock(import("../ChatMarkdown"), async (importOriginal) => ({
1515 default : ( ( { text } : { text : string } ) => < p > { text } </ p > ) as never ,
1616} ) ) ;
1717
18- const toasts = vi . hoisted ( ( ) => ( { add : vi . fn ( ) } ) ) ;
19- vi . mock ( import ( "../ui/toast" ) , async ( importOriginal ) => {
20- const actual = await importOriginal ( ) ;
21- return { ...actual , toastManager : { ...actual . toastManager , add : toasts . add } as never } ;
22- } ) ;
23-
2418import { act , fakeTimers , render } from "../../../test/render" ;
2519import { useComposerDraftStore } from "../../composerDraftStore" ;
2620import { makeThreadProjectionFixture } from "../../test-fixtures" ;
21+ import { toastManager } from "../ui/toast" ;
2722import { usePendingThreadRequests } from "./usePendingThreadRequests" ;
2823
2924const threadRef = { environmentId : EnvironmentId . make ( "env" ) , threadId : ThreadId . make ( "thread" ) } ;
@@ -151,7 +146,7 @@ it("tells the user when an option click moves their typed answer into the hidden
151146 const environmentId = EnvironmentId . make ( "displaced-environment" ) ;
152147 const draftTarget = { environmentId, threadId : threadRef . threadId } ;
153148 const draftPrompt = ( ) => useComposerDraftStore . getState ( ) . getComposerDraft ( draftTarget ) ?. prompt ;
154- toasts . add . mockClear ( ) ;
149+ using toast = vi . spyOn ( toastManager , "add" ) ;
155150 await using _screen = await render (
156151 < PendingRequestsProbe
157152 environmentId = { environmentId }
@@ -160,23 +155,27 @@ it("tells the user when an option click moves their typed answer into the hidden
160155 ) ;
161156
162157 await act ( ( ) => requests . onSelectActivePendingUserInputOption ( "question-0" , "Incremental" ) ) ;
163- expect ( toasts . add ) . not . toHaveBeenCalled ( ) ;
158+ expect ( toast ) . not . toHaveBeenCalled ( ) ;
164159
165160 await act ( ( ) => requests . onChangeActivePendingUserInputCustomAnswer ( "question-0" , "first try" ) ) ;
166161 await act ( ( ) => requests . onSelectActivePendingUserInputOption ( "question-0" , "Incremental" ) ) ;
167162 expect ( draftPrompt ( ) ) . toBe ( "first try" ) ;
168- expect ( toasts . add ) . toHaveBeenCalledTimes ( 1 ) ;
169- expect ( toasts . add ) . toHaveBeenCalledWith (
170- expect . objectContaining ( { data : { threadRef : draftTarget } } ) ,
163+ expect ( toast ) . toHaveBeenCalledTimes ( 1 ) ;
164+ expect ( toast ) . toHaveBeenCalledWith (
165+ expect . objectContaining ( {
166+ type : "info" ,
167+ title : "Your typed text was set aside" ,
168+ description : "It will be back in the composer once the question is answered." ,
169+ data : { threadRef : draftTarget } ,
170+ } ) ,
171171 ) ;
172172
173- // Typing again replaces the option as the answer; the moved text stays put and is not announced twice.
174173 await act ( ( ) => requests . onChangeActivePendingUserInputCustomAnswer ( "question-0" , "second try" ) ) ;
175174 expect ( draftPrompt ( ) ) . toBe ( "first try" ) ;
176175 expect ( requests . activePendingDraftAnswers [ "question-0" ] ) . toMatchObject ( {
177176 customAnswer : "second try" ,
178177 } ) ;
179- expect ( toasts . add ) . toHaveBeenCalledTimes ( 1 ) ;
178+ expect ( toast ) . toHaveBeenCalledTimes ( 1 ) ;
180179} ) ;
181180
182181it ( "isolates drafts by environment, thread and request and discards only resolved requests" , async ( ) => {
0 commit comments