@@ -287,5 +287,51 @@ describe("EventTile", () => {
287287 "mx_EventTile_e2eIcon_warning" ,
288288 ) ;
289289 } ) ;
290+
291+ it ( "should update the warning when the event is replaced with an unencrypted one" , async ( ) => {
292+ jest . spyOn ( client , "isRoomEncrypted" ) . mockReturnValue ( true ) ;
293+
294+ // we start out with an event from the trusted device
295+ mxEvent = await mkEncryptedEvent ( {
296+ plainContent : { msgtype : "m.text" , body : "msg1" } ,
297+ plainType : "m.room.message" ,
298+ user : "@alice:example.org" ,
299+ room : room . roomId ,
300+ } ) ;
301+ eventToEncryptionInfoMap . set ( mxEvent . getId ( ) ! , {
302+ authenticated : true ,
303+ sender : TRUSTED_DEVICE ,
304+ } as IEncryptedEventInfo ) ;
305+
306+ const { container } = getComponent ( ) ;
307+
308+ const eventTiles = container . getElementsByClassName ( "mx_EventTile" ) ;
309+ expect ( eventTiles ) . toHaveLength ( 1 ) ;
310+ const eventTile = eventTiles [ 0 ] ;
311+
312+ expect ( eventTile . classList ) . toContain ( "mx_EventTile_verified" ) ;
313+
314+ // there should be no warning
315+ expect ( container . getElementsByClassName ( "mx_EventTile_e2eIcon" ) ) . toHaveLength ( 0 ) ;
316+
317+ // then we replace the event with an unencrypted one
318+ const replacementEvent = await mkMessage ( {
319+ msg : "msg2" ,
320+ user : "@alice:example.org" ,
321+ room : room . roomId ,
322+ event : true ,
323+ } ) ;
324+
325+ act ( ( ) => {
326+ mxEvent . makeReplaced ( replacementEvent ) ;
327+ } ) ;
328+
329+ // check it was updated
330+ expect ( eventTile . classList ) . not . toContain ( "mx_EventTile_verified" ) ;
331+ expect ( container . getElementsByClassName ( "mx_EventTile_e2eIcon" ) ) . toHaveLength ( 1 ) ;
332+ expect ( container . getElementsByClassName ( "mx_EventTile_e2eIcon" ) [ 0 ] . classList ) . toContain (
333+ "mx_EventTile_e2eIcon_warning" ,
334+ ) ;
335+ } ) ;
290336 } ) ;
291337} ) ;
0 commit comments