@@ -3877,6 +3877,90 @@ describe("chat voice controls", () => {
38773877 } ) ;
38783878} ) ;
38793879
3880+ describe ( "chat composer render invalidation" , ( ) => {
3881+ it ( "keeps steady ordinary edits and direction changes local" , ( ) => {
3882+ const container = document . createElement ( "div" ) ;
3883+ let draft = "a" ;
3884+ const onDraftChange = vi . fn ( ( next : string ) => {
3885+ draft = next ;
3886+ } ) ;
3887+ let props = createChatProps ( {
3888+ draft,
3889+ getDraft : ( ) => draft ,
3890+ onDraftChange,
3891+ } ) ;
3892+ const onRequestUpdate = vi . fn ( ( ) => {
3893+ props = { ...props , draft, getDraft : ( ) => draft } ;
3894+ render ( renderChat ( props ) , container ) ;
3895+ } ) ;
3896+ props = { ...props , onRequestUpdate } ;
3897+ render ( renderChat ( props ) , container ) ;
3898+
3899+ const textarea = getComposerTextarea ( container ) ;
3900+ onRequestUpdate . mockClear ( ) ;
3901+ vi . mocked ( chatThread . buildCachedChatItems ) . mockClear ( ) ;
3902+
3903+ textarea . value = "ab" ;
3904+ textarea . dispatchEvent ( new InputEvent ( "input" , { bubbles : true , inputType : "insertText" } ) ) ;
3905+ textarea . value = "abc" ;
3906+ textarea . dispatchEvent ( new InputEvent ( "input" , { bubbles : true , inputType : "insertText" } ) ) ;
3907+
3908+ expect ( draft ) . toBe ( "abc" ) ;
3909+ expect ( onRequestUpdate ) . not . toHaveBeenCalled ( ) ;
3910+ expect ( chatThread . buildCachedChatItems ) . not . toHaveBeenCalled ( ) ;
3911+
3912+ textarea . value = "مرحبا" ;
3913+ textarea . dispatchEvent ( new InputEvent ( "input" , { bubbles : true , inputType : "insertText" } ) ) ;
3914+
3915+ expect ( onRequestUpdate ) . not . toHaveBeenCalled ( ) ;
3916+ expect ( chatThread . buildCachedChatItems ) . not . toHaveBeenCalled ( ) ;
3917+ expect ( textarea . dir ) . toBe ( "rtl" ) ;
3918+
3919+ render ( renderChat ( props ) , container ) ;
3920+ expect ( getComposerTextarea ( container ) . dir ) . toBe ( "rtl" ) ;
3921+ } ) ;
3922+
3923+ it ( "invalidates when offline slash eligibility changes" , ( ) => {
3924+ const container = document . createElement ( "div" ) ;
3925+ let draft = "queue this offline" ;
3926+ const onDraftChange = vi . fn ( ( next : string ) => {
3927+ draft = next ;
3928+ } ) ;
3929+ let props = createChatProps ( {
3930+ connected : false ,
3931+ draft,
3932+ getDraft : ( ) => draft ,
3933+ onDraftChange,
3934+ } ) ;
3935+ const onRequestUpdate = vi . fn ( ( ) => {
3936+ props = { ...props , draft, getDraft : ( ) => draft } ;
3937+ render ( renderChat ( props ) , container ) ;
3938+ } ) ;
3939+ props = { ...props , onRequestUpdate } ;
3940+ render ( renderChat ( props ) , container ) ;
3941+
3942+ const sendButton = ( ) =>
3943+ container . querySelector < HTMLButtonElement > ( 'button[aria-label="Send message"]' ) ;
3944+ expect ( sendButton ( ) ?. disabled ) . toBe ( false ) ;
3945+ onRequestUpdate . mockClear ( ) ;
3946+
3947+ let textarea = getComposerTextarea ( container ) ;
3948+ textarea . value = "/status" ;
3949+ textarea . dispatchEvent ( new InputEvent ( "input" , { bubbles : true , inputType : "insertText" } ) ) ;
3950+
3951+ expect ( onRequestUpdate ) . toHaveBeenCalled ( ) ;
3952+ expect ( sendButton ( ) ?. disabled ) . toBe ( true ) ;
3953+ onRequestUpdate . mockClear ( ) ;
3954+
3955+ textarea = getComposerTextarea ( container ) ;
3956+ textarea . value = "queue this instead" ;
3957+ textarea . dispatchEvent ( new InputEvent ( "input" , { bubbles : true , inputType : "insertText" } ) ) ;
3958+
3959+ expect ( onRequestUpdate ) . toHaveBeenCalled ( ) ;
3960+ expect ( sendButton ( ) ?. disabled ) . toBe ( false ) ;
3961+ } ) ;
3962+ } ) ;
3963+
38803964describe ( "chat composer IME composition" , ( ) => {
38813965 it ( "switches to send on the first composing character without committing the draft" , ( ) => {
38823966 const onDraftChange = vi . fn ( ) ;
0 commit comments