@@ -475,6 +475,31 @@ function mount(
475475 } ;
476476}
477477
478+ it ( "retires reply controls immediately and preserves the draft when replying again" , ( ) => {
479+ const h = mount ( {
480+ replyContext : < button type = "button" > Cancel reply to Honey</ button > ,
481+ } ) ;
482+ fireEvent . change ( h . input ( ) , { target : { value : "Draft in progress" } } ) ;
483+ const previous = screen . getByRole ( "button" , {
484+ name : "Cancel reply to Honey" ,
485+ } ) ;
486+
487+ h . retarget ( { replyContext : undefined } ) ;
488+ expect ( previous . closest ( "[inert]" ) ) . not . toBeNull ( ) ;
489+ expect (
490+ screen . queryByRole ( "button" , { name : "Cancel reply to Honey" } ) ,
491+ ) . toBeNull ( ) ;
492+ expect ( h . input ( ) ) . toHaveValue ( "Draft in progress" ) ;
493+
494+ h . retarget ( {
495+ replyContext : < button type = "button" > Cancel reply to Wes</ button > ,
496+ } ) ;
497+ const current = screen . getByRole ( "button" , { name : "Cancel reply to Wes" } ) ;
498+ expect ( current . closest ( "[inert]" ) ) . toBeNull ( ) ;
499+ expect ( screen . queryByText ( "Cancel reply to Honey" ) ) . toBeNull ( ) ;
500+ expect ( h . input ( ) ) . toHaveValue ( "Draft in progress" ) ;
501+ } ) ;
502+
478503it ( "shows a local draft in the cached composer without completion, typing or transport reads" , async ( ) => {
479504 const viewer = keypair ( ) ,
480505 relay = keypair ( ) ;
@@ -1455,7 +1480,9 @@ it.each(["never", "before the failure", "after the failure"])(
14551480 if ( remounted === "after the failure" ) remount ( ) ;
14561481 const input = ( ) => within ( container ) . getByRole ( "textbox" ) ;
14571482 await waitFor ( ( ) => expect ( input ( ) ) . toHaveValue ( "think hard@Honey " ) ) ;
1458- expect ( within ( container ) . getByText ( "tuned.txt" ) ) . toBeVisible ( ) ;
1483+ await waitFor ( ( ) =>
1484+ expect ( within ( container ) . getByText ( "tuned.txt" ) ) . toBeVisible ( ) ,
1485+ ) ;
14591486 // The restored draft brings its pick back with it, not the default run.
14601487 const button = await picker ( ) ;
14611488 expect ( button ) . toHaveAttribute ( "data-selected" ) ;
@@ -1536,7 +1563,9 @@ it.each(["cleanup", "restore"] as const)(
15361563 await waitFor ( ( ) =>
15371564 expect ( h . input ( ) ) . toHaveValue ( "recover this caption" ) ,
15381565 ) ;
1539- expect ( within ( h . form ( ) ) . getByText ( "retained.txt" ) ) . toBeVisible ( ) ;
1566+ await waitFor ( ( ) =>
1567+ expect ( within ( h . form ( ) ) . getByText ( "retained.txt" ) ) . toBeVisible ( ) ,
1568+ ) ;
15401569 expect (
15411570 screen . queryByRole ( "button" , { name : "Retry draft cleanup" } ) ,
15421571 ) . toBeNull ( ) ;
@@ -1607,7 +1636,9 @@ it("does not overwrite a later local edit when a background upload fails", async
16071636 await userEvent . clear ( h . input ( ) ) ;
16081637 await userEvent . click ( retry ) ;
16091638 await waitFor ( ( ) => expect ( h . input ( ) ) . toHaveValue ( "original caption" ) ) ;
1610- expect ( within ( h . form ( ) ) . getByText ( "original.txt" ) ) . toBeVisible ( ) ;
1639+ await waitFor ( ( ) =>
1640+ expect ( within ( h . form ( ) ) . getByText ( "original.txt" ) ) . toBeVisible ( ) ,
1641+ ) ;
16111642 expect (
16121643 screen . queryByRole ( "button" , { name : "Retry failed send recovery" } ) ,
16131644 ) . toBeNull ( ) ;
@@ -1636,7 +1667,9 @@ it("restores a failed upload after the composer remounts in the same session", a
16361667 "remount caption" ,
16371668 ) ,
16381669 ) ;
1639- expect ( within ( again . container ) . getByText ( "remount.txt" ) ) . toBeVisible ( ) ;
1670+ await waitFor ( ( ) =>
1671+ expect ( within ( again . container ) . getByText ( "remount.txt" ) ) . toBeVisible ( ) ,
1672+ ) ;
16401673} ) ;
16411674
16421675it ( "reconciles failed-cleanup recovery after remount before stale cleanup can overwrite the caption" , async ( ) => {
@@ -1676,7 +1709,9 @@ it("reconciles failed-cleanup recovery after remount before stale cleanup can ov
16761709 expect ( replacement ) . toHaveValue ( "recover this caption" ) ,
16771710 ) ;
16781711 expect ( replacement ) . toHaveAttribute ( "contenteditable" , "true" ) ;
1679- expect ( within ( again . container ) . getByText ( "retained.txt" ) ) . toBeVisible ( ) ;
1712+ await waitFor ( ( ) =>
1713+ expect ( within ( again . container ) . getByText ( "retained.txt" ) ) . toBeVisible ( ) ,
1714+ ) ;
16801715 expect (
16811716 within ( again . container ) . queryByRole ( "button" , {
16821717 name : "Retry draft cleanup" ,
@@ -1724,7 +1759,9 @@ it("retains a remounted later edit conflict until clearing it and explicitly ret
17241759 await userEvent . click ( retry ) ;
17251760 await waitFor ( ( ) => expect ( replacement ) . toHaveValue ( "original caption" ) ) ;
17261761 expect ( replacement ) . toHaveAttribute ( "contenteditable" , "true" ) ;
1727- expect ( within ( again . container ) . getByText ( "original.txt" ) ) . toBeVisible ( ) ;
1762+ await waitFor ( ( ) =>
1763+ expect ( within ( again . container ) . getByText ( "original.txt" ) ) . toBeVisible ( ) ,
1764+ ) ;
17281765 expect (
17291766 screen . queryByRole ( "button" , { name : "Retry failed send recovery" } ) ,
17301767 ) . toBeNull ( ) ;
@@ -1765,7 +1802,9 @@ it("does not replace an active message edit when a remounted upload recovers", a
17651802 within ( again . container ) . getByRole ( "button" , { name : "Cancel edit" } ) ,
17661803 ) ;
17671804 await waitFor ( ( ) => expect ( replacement ) . toHaveValue ( "original caption" ) ) ;
1768- expect ( within ( again . container ) . getByText ( "original.txt" ) ) . toBeVisible ( ) ;
1805+ await waitFor ( ( ) =>
1806+ expect ( within ( again . container ) . getByText ( "original.txt" ) ) . toBeVisible ( ) ,
1807+ ) ;
17691808 expect ( h . publish ) . not . toHaveBeenCalled ( ) ;
17701809} ) ;
17711810
@@ -1807,7 +1846,9 @@ it("defers a failed upload recovery until an empty active message edit ends", as
18071846 within ( h . form ( ) ) . getByRole ( "button" , { name : "Cancel edit" } ) ,
18081847 ) ;
18091848 await waitFor ( ( ) => expect ( editor ) . toHaveValue ( "original caption" ) ) ;
1810- expect ( within ( h . form ( ) ) . getByText ( "original.txt" ) ) . toBeVisible ( ) ;
1849+ await waitFor ( ( ) =>
1850+ expect ( within ( h . form ( ) ) . getByText ( "original.txt" ) ) . toBeVisible ( ) ,
1851+ ) ;
18111852} ) ;
18121853
18131854it ( "retains preparation retry when recovery is deferred by an edit then unmounted" , async ( ) => {
@@ -1860,7 +1901,9 @@ it("retains preparation retry when recovery is deferred by an edit then unmounte
18601901 ) ;
18611902 const composer = within ( returned . container ) ;
18621903 expect ( composer . getByRole ( "textbox" ) ) . toHaveValue ( "caption :party:" ) ;
1863- expect ( composer . getByText ( "edit-remount.txt" ) ) . toBeVisible ( ) ;
1904+ await waitFor ( ( ) =>
1905+ expect ( composer . getByText ( "edit-remount.txt" ) ) . toBeVisible ( ) ,
1906+ ) ;
18641907 expect ( composer . getByRole ( "alert" ) ) . toHaveTextContent (
18651908 "Community emoji unavailable" ,
18661909 ) ;
@@ -1901,7 +1944,9 @@ it("offers message preparation retry after a failed attachment send remounts", a
19011944 await waitFor ( ( ) =>
19021945 expect ( composer . getByRole ( "textbox" ) ) . toHaveValue ( "caption :party:" ) ,
19031946 ) ;
1904- expect ( composer . getByText ( "emoji-remount.txt" ) ) . toBeVisible ( ) ;
1947+ await waitFor ( ( ) =>
1948+ expect ( composer . getByText ( "emoji-remount.txt" ) ) . toBeVisible ( ) ,
1949+ ) ;
19051950 expect ( composer . getByRole ( "alert" ) ) . toHaveTextContent (
19061951 "Community emoji unavailable" ,
19071952 ) ;
@@ -1913,7 +1958,9 @@ it("offers message preparation retry after a failed attachment send remounts", a
19131958 expect ( h . owner . session . emoji . snapshot ( ) . status ) . toBe ( "ready" ) ,
19141959 ) ;
19151960 expect ( composer . getByRole ( "textbox" ) ) . toHaveValue ( "caption :party:" ) ;
1916- expect ( composer . getByText ( "emoji-remount.txt" ) ) . toBeVisible ( ) ;
1961+ await waitFor ( ( ) =>
1962+ expect ( composer . getByText ( "emoji-remount.txt" ) ) . toBeVisible ( ) ,
1963+ ) ;
19171964 expect ( h . publish ) . not . toHaveBeenCalled ( ) ;
19181965 again . unmount ( ) ;
19191966 const returned = render (
@@ -7227,9 +7274,11 @@ it("keeps snapshot paste from taking the attachment slot reserved for a recordin
72277274 screen . queryByRole ( "button" , { name : "Remove helper.agent.png" } ) ,
72287275 ) . toBeNull ( ) ;
72297276 fireEvent . click ( finish ) ;
7230- expect (
7231- await screen . findByRole ( "button" , { name : "Remove voice-note.wav" } ) ,
7232- ) . toBeVisible ( ) ;
7277+ await waitFor ( ( ) =>
7278+ expect (
7279+ screen . getByRole ( "button" , { name : "Remove voice-note.wav" } ) ,
7280+ ) . toBeVisible ( ) ,
7281+ ) ;
72337282 await waitFor ( ( ) => expect ( h . uploadCalls ) . toHaveLength ( 1 ) ) ;
72347283 expect ( h . uploadCalls [ 0 ] ?. file . name ) . toBe ( "draft-0.txt" ) ;
72357284 expect ( h . publish ) . not . toHaveBeenCalled ( ) ;
@@ -7305,7 +7354,9 @@ it("drops the attachments mark while a row-requested edit holds pending items",
73057354 ) ;
73067355 expect ( form ) . not . toHaveAttribute ( "data-editing" ) ;
73077356 expect ( form ) . toHaveAttribute ( "data-attachments" ) ;
7308- expect ( within ( view . container ) . getByText ( "pending.txt" ) ) . toBeVisible ( ) ;
7357+ await waitFor ( ( ) =>
7358+ expect ( within ( view . container ) . getByText ( "pending.txt" ) ) . toBeVisible ( ) ,
7359+ ) ;
73097360} ) ;
73107361
73117362it ( "stages session cards above an ordinary caption editor, persists them, and sends both" , async ( ) => {
0 commit comments