@@ -917,6 +917,33 @@ describe('MessageOperations — optimistic lifecycle', () => {
917917 expect ( store . get ( 'm1' ) ?. text ) . toBe ( 'from a websocket event' ) ;
918918 } ) ;
919919
920+ // UIs render `i18n.<language>_text` in place of `text`, so a translation of the old text left on
921+ // the optimistic copy hides the edit until the server responds, or offline, until the replay.
922+ it ( 'drops the translations of the replaced text' , async ( ) => {
923+ const seed = makeLocalMessage ( {
924+ i18n : { en_text : 'before' , es_text : 'antes' , language : 'en' } ,
925+ id : 'm1' ,
926+ status : 'received' ,
927+ text : 'before' ,
928+ } ) ;
929+ const { ops, persisted } = harness ( { seed } ) ;
930+
931+ await ops . update ( { localMessage : { ...seed , text : 'after' } } ) ;
932+
933+ expect ( persisted [ 0 ] . text ) . toBe ( 'after' ) ;
934+ expect ( persisted [ 0 ] . i18n ) . toBeUndefined ( ) ;
935+ } ) ;
936+
937+ it ( 'keeps the translations when the edit leaves the text unchanged' , async ( ) => {
938+ const i18n = { en_text : 'same' , es_text : 'igual' , language : 'en' } ;
939+ const seed = makeLocalMessage ( { i18n, id : 'm1' , status : 'received' , text : 'same' } ) ;
940+ const { ops, persisted } = harness ( { seed } ) ;
941+
942+ await ops . update ( { localMessage : { ...seed , attachments : [ ] } } ) ;
943+
944+ expect ( persisted [ 0 ] . i18n ) . toEqual ( i18n ) ;
945+ } ) ;
946+
920947 it ( 'stamps message_text_updated_at so the "edited" indicator shows immediately' , async ( ) => {
921948 const seed = makeLocalMessage ( { id : 'm1' , status : 'received' } ) ;
922949 const { ops, persisted } = harness ( { seed } ) ;
0 commit comments