@@ -17,7 +17,9 @@ vi.mock(import("../ChatMarkdown"), async (importOriginal) => ({
1717} ) ) ;
1818
1919import { act , fakeTimers , render } from "../../../test/render" ;
20+ import { useComposerDraftStore } from "../../composerDraftStore" ;
2021import { makeThreadProjectionFixture } from "../../test-fixtures" ;
22+ import { toastManager } from "../ui/toast" ;
2123import { usePendingThreadRequests } from "./usePendingThreadRequests" ;
2224
2325const threadRef = { environmentId : EnvironmentId . make ( "env" ) , threadId : ThreadId . make ( "thread" ) } ;
@@ -89,7 +91,8 @@ function useProbeRequests({ environmentId, projection, loading = false }: ProbeP
8991 serverProjection : loading ? null : projection ,
9092 supportsQuestionAttachments : false ,
9193 composerDraftTarget : { environmentId, threadId : projection . thread . id } ,
92- setComposerDraftPrompt : ( ) => { } ,
94+ setComposerDraftPrompt : ( target , prompt ) =>
95+ useComposerDraftStore . getState ( ) . setPrompt ( target , prompt ) ,
9396 promptRef,
9497 composerRef,
9598 setThreadError : ( ) => { } ,
@@ -141,6 +144,43 @@ it("retains answers, selections and question position after leaving chat, includ
141144 expect ( requests ) . toMatchObject ( expected ) ;
142145} ) ;
143146
147+ it ( "tells the user when an option click moves their typed answer into the hidden composer draft" , async ( ) => {
148+ using _timers = fakeTimers ( ) ;
149+ const environmentId = EnvironmentId . make ( "displaced-environment" ) ;
150+ const draftTarget = { environmentId, threadId : threadRef . threadId } ;
151+ const draftPrompt = ( ) => useComposerDraftStore . getState ( ) . getComposerDraft ( draftTarget ) ?. prompt ;
152+ using toast = vi . spyOn ( toastManager , "add" ) ;
153+ await using _screen = await render (
154+ < PendingRequestsProbe
155+ environmentId = { environmentId }
156+ projection = { questionProjection ( threadRef . threadId ) }
157+ /> ,
158+ ) ;
159+
160+ await act ( ( ) => requests . onSelectActivePendingUserInputOption ( "question-0" , "Incremental" ) ) ;
161+ expect ( toast ) . not . toHaveBeenCalled ( ) ;
162+
163+ await act ( ( ) => requests . onChangeActivePendingUserInputCustomAnswer ( "question-0" , "first try" ) ) ;
164+ await act ( ( ) => requests . onSelectActivePendingUserInputOption ( "question-0" , "Incremental" ) ) ;
165+ expect ( draftPrompt ( ) ) . toBe ( "first try" ) ;
166+ expect ( toast ) . toHaveBeenCalledTimes ( 1 ) ;
167+ expect ( toast ) . toHaveBeenCalledWith (
168+ expect . objectContaining ( {
169+ type : "info" ,
170+ title : "Your typed text was set aside" ,
171+ description : "It will be back in the composer once the question is answered." ,
172+ data : { threadRef : draftTarget } ,
173+ } ) ,
174+ ) ;
175+
176+ await act ( ( ) => requests . onChangeActivePendingUserInputCustomAnswer ( "question-0" , "second try" ) ) ;
177+ expect ( draftPrompt ( ) ) . toBe ( "first try" ) ;
178+ expect ( requests . activePendingDraftAnswers [ "question-0" ] ) . toMatchObject ( {
179+ customAnswer : "second try" ,
180+ } ) ;
181+ expect ( toast ) . toHaveBeenCalledTimes ( 1 ) ;
182+ } ) ;
183+
144184function QuestionPositionProbe ( props : ProbeProps ) {
145185 const state = useProbeRequests ( props ) ;
146186 return (
0 commit comments