@@ -19,7 +19,7 @@ const commands = vi.hoisted(() => ({
1919} ) ) ;
2020const router = vi . hoisted ( ( ) => ( {
2121 navigate : vi . fn ( async ( ) => { } ) ,
22- state : { matches : [ { params : { } as Record < string , string > } ] } ,
22+ state : { location : { href : "/" } , matches : [ { params : { } as Record < string , string > } ] } ,
2323} ) ) ;
2424vi . mock ( "../state/use-atom-query-runner" , ( ) => ( { useAtomQueryRunner : ( ) => vi . fn ( ) } ) ) ;
2525vi . mock ( "../state/session" , async ( original ) => ( {
@@ -34,7 +34,11 @@ vi.mock("react", async (original) => ({
3434} ) ) ;
3535vi . mock ( "@tanstack/react-router" , ( ) => ( { useRouter : ( ) => router } ) ) ;
3636vi . mock ( "./useSettings" , ( ) => ( { useClientSettings : ( ) => false } ) ) ;
37- vi . mock ( "./useHandleNewThread" , ( ) => ( { useNewThreadHandler : ( ) => vi . fn ( ) } ) ) ;
37+ vi . mock ( "./useHandleNewThread" , ( ) => ( {
38+ useNewThreadHandler : ( ) => async ( ) => {
39+ router . state . location . href = "/draft/project" ;
40+ } ,
41+ } ) ) ;
3842vi . mock ( "../composerDraftStore" , ( ) => ( { useComposerDraftStore : ( ) => vi . fn ( ) } ) ) ;
3943vi . mock ( "../terminalUiStateStore" , ( ) => ( { useTerminalUiStateStore : ( ) => vi . fn ( ) } ) ) ;
4044vi . mock ( "../uiStateStore" , ( ) => ( { useUiStateStore : ( ) => vi . fn ( ) } ) ) ;
@@ -94,6 +98,7 @@ beforeEach(() => {
9498 command . mockReset ( ) . mockResolvedValue ( { _tag : "Success" , value : undefined } ) ;
9599 }
96100 router . navigate . mockClear ( ) ;
101+ router . state . location . href = "/" ;
97102 router . state . matches [ 0 ] ! . params = { } ;
98103 threadShell . pinnedAt = null ;
99104 threadShell . snoozedUntil = null ;
@@ -201,6 +206,32 @@ describe("archive Undo", () => {
201206 } ) ;
202207} ) ;
203208
209+ describe ( "archive navigation" , ( ) => {
210+ it . each ( [
211+ { destination : "/undo-env/thread" , expected : "/draft/project" } ,
212+ { destination : "/undo-env/other-thread" , expected : "/undo-env/other-thread" } ,
213+ { destination : "/settings" , expected : "/settings" } ,
214+ ] ) ( "ends at $expected after opening $destination while archiving" , async ( route ) => {
215+ router . state . location . href = "/undo-env/thread" ;
216+ router . state . matches [ 0 ] ! . params = {
217+ environmentId : target . environmentId ,
218+ threadId : target . threadId ,
219+ } ;
220+ let finishArchive ! : ( ) => void ;
221+ commands . archive . mockReturnValue (
222+ new Promise ( ( resolve ) => {
223+ finishArchive = ( ) => resolve ( { _tag : "Success" , value : undefined } ) ;
224+ } ) ,
225+ ) ;
226+ const archived = useThreadActions ( ) . archiveThread ( target ) ;
227+ router . state . location . href = route . destination ;
228+ finishArchive ( ) ;
229+ expect ( ( await archived ) . _tag ) . toBe ( "Success" ) ;
230+ expect ( useThreadUndoNotice . getState ( ) . notice ) . toMatchObject ( { action : "Archived" } ) ;
231+ expect ( router . state . location . href ) . toBe ( route . expected ) ;
232+ } ) ;
233+ } ) ;
234+
204235describe ( "settle and snooze Undo" , ( ) => {
205236 it ( "un-settles from the notice and expires the Undo after a manual un-settle" , async ( ) => {
206237 const add = vi . spyOn ( toastManager , "add" ) . mockReturnValue ( "toast" ) ;
0 commit comments