@@ -15,14 +15,16 @@ limitations under the License.
1515*/
1616
1717import * as React from "react" ;
18+ import { render , waitFor , screen , act , fireEvent } from "@testing-library/react" ;
19+ import { mocked } from "jest-mock" ;
1820import { EventType } from "matrix-js-sdk/src/@types/event" ;
1921import { MatrixClient , PendingEventOrdering } from "matrix-js-sdk/src/client" ;
22+ import { TweakName } from "matrix-js-sdk/src/matrix" ;
2023import { MatrixEvent } from "matrix-js-sdk/src/models/event" ;
2124import { NotificationCountType , Room } from "matrix-js-sdk/src/models/room" ;
2225import { DeviceTrustLevel , UserTrustLevel } from "matrix-js-sdk/src/crypto/CrossSigning" ;
2326import { DeviceInfo } from "matrix-js-sdk/src/crypto/deviceinfo" ;
2427import { IEncryptedEventInfo } from "matrix-js-sdk/src/crypto/api" ;
25- import { render , waitFor , screen , act , fireEvent } from "@testing-library/react" ;
2628
2729import EventTile , { EventTileProps } from "../../../../src/components/views/rooms/EventTile" ;
2830import MatrixClientContext from "../../../../src/contexts/MatrixClientContext" ;
@@ -73,7 +75,7 @@ describe("EventTile", () => {
7375 stubClient ( ) ;
7476 client = MatrixClientPeg . get ( ) ;
7577
76- room = new Room ( ROOM_ID , client , client . getUserId ( ) ! , {
78+ room = new Room ( ROOM_ID , client , client . getSafeUserId ( ) , {
7779 pendingEventOrdering : PendingEventOrdering . Detached ,
7880 } ) ;
7981
@@ -373,4 +375,102 @@ describe("EventTile", () => {
373375 ) ;
374376 } ) ;
375377 } ) ;
378+
379+ describe ( "event highlighting" , ( ) => {
380+ const isHighlighted = ( container : HTMLElement ) : boolean =>
381+ ! ! container . getElementsByClassName ( "mx_EventTile_highlight" ) . length ;
382+
383+ beforeEach ( ( ) => {
384+ mocked ( client . getPushActionsForEvent ) . mockReturnValue ( null ) ;
385+ } ) ;
386+
387+ it ( "does not highlight message where message matches no push actions" , ( ) => {
388+ const { container } = getComponent ( ) ;
389+
390+ expect ( client . getPushActionsForEvent ) . toHaveBeenCalledWith ( mxEvent ) ;
391+ expect ( isHighlighted ( container ) ) . toBeFalsy ( ) ;
392+ } ) ;
393+
394+ it ( `does not highlight when message's push actions does not have a highlight tweak` , ( ) => {
395+ mocked ( client . getPushActionsForEvent ) . mockReturnValue ( { notify : true , tweaks : { } } ) ;
396+ const { container } = getComponent ( ) ;
397+
398+ expect ( isHighlighted ( container ) ) . toBeFalsy ( ) ;
399+ } ) ;
400+
401+ it ( `highlights when message's push actions have a highlight tweak` , ( ) => {
402+ mocked ( client . getPushActionsForEvent ) . mockReturnValue ( {
403+ notify : true ,
404+ tweaks : { [ TweakName . Highlight ] : true } ,
405+ } ) ;
406+ const { container } = getComponent ( ) ;
407+
408+ expect ( isHighlighted ( container ) ) . toBeTruthy ( ) ;
409+ } ) ;
410+
411+ describe ( "when a message has been edited" , ( ) => {
412+ let editingEvent : MatrixEvent ;
413+
414+ beforeEach ( ( ) => {
415+ editingEvent = new MatrixEvent ( {
416+ type : "m.room.message" ,
417+ room_id : ROOM_ID ,
418+ sender : "@alice:example.org" ,
419+ content : {
420+ "msgtype" : "m.text" ,
421+ "body" : "* edited body" ,
422+ "m.new_content" : {
423+ msgtype : "m.text" ,
424+ body : "edited body" ,
425+ } ,
426+ "m.relates_to" : {
427+ rel_type : "m.replace" ,
428+ event_id : mxEvent . getId ( ) ,
429+ } ,
430+ } ,
431+ } ) ;
432+ mxEvent . makeReplaced ( editingEvent ) ;
433+ } ) ;
434+
435+ it ( "does not highlight message where no version of message matches any push actions" , ( ) => {
436+ const { container } = getComponent ( ) ;
437+
438+ // get push actions for both events
439+ expect ( client . getPushActionsForEvent ) . toHaveBeenCalledWith ( mxEvent ) ;
440+ expect ( client . getPushActionsForEvent ) . toHaveBeenCalledWith ( editingEvent ) ;
441+ expect ( isHighlighted ( container ) ) . toBeFalsy ( ) ;
442+ } ) ;
443+
444+ it ( `does not highlight when no version of message's push actions have a highlight tweak` , ( ) => {
445+ mocked ( client . getPushActionsForEvent ) . mockReturnValue ( { notify : true , tweaks : { } } ) ;
446+ const { container } = getComponent ( ) ;
447+
448+ expect ( isHighlighted ( container ) ) . toBeFalsy ( ) ;
449+ } ) ;
450+
451+ it ( `highlights when previous version of message's push actions have a highlight tweak` , ( ) => {
452+ mocked ( client . getPushActionsForEvent ) . mockImplementation ( ( event : MatrixEvent ) => {
453+ if ( event === mxEvent ) {
454+ return { notify : true , tweaks : { [ TweakName . Highlight ] : true } } ;
455+ }
456+ return { notify : false , tweaks : { } } ;
457+ } ) ;
458+ const { container } = getComponent ( ) ;
459+
460+ expect ( isHighlighted ( container ) ) . toBeTruthy ( ) ;
461+ } ) ;
462+
463+ it ( `highlights when new version of message's push actions have a highlight tweak` , ( ) => {
464+ mocked ( client . getPushActionsForEvent ) . mockImplementation ( ( event : MatrixEvent ) => {
465+ if ( event === editingEvent ) {
466+ return { notify : true , tweaks : { [ TweakName . Highlight ] : true } } ;
467+ }
468+ return { notify : false , tweaks : { } } ;
469+ } ) ;
470+ const { container } = getComponent ( ) ;
471+
472+ expect ( isHighlighted ( container ) ) . toBeTruthy ( ) ;
473+ } ) ;
474+ } ) ;
475+ } ) ;
376476} ) ;
0 commit comments