@@ -17,13 +17,14 @@ limitations under the License.
1717import React from "react" ;
1818import "jest-mock" ;
1919import { screen , act , render } from "@testing-library/react" ;
20- import { MatrixClient , PendingEventOrdering } from "matrix-js-sdk/src/client" ;
20+ import { MsgType , RelationType } from "matrix-js-sdk/src/matrix" ;
21+ import { PendingEventOrdering } from "matrix-js-sdk/src/client" ;
2122import { NotificationCountType , Room } from "matrix-js-sdk/src/models/room" ;
22- import { mocked } from "jest-mock" ;
2323import { EventStatus } from "matrix-js-sdk/src/models/event-status" ;
2424
25+ import { mkThread } from "../../../../test-utils/threads" ;
2526import { UnreadNotificationBadge } from "../../../../../src/components/views/rooms/NotificationBadge/UnreadNotificationBadge" ;
26- import { mkMessage , stubClient } from "../../../../test-utils/test-utils" ;
27+ import { mkEvent , mkMessage , stubClient } from "../../../../test-utils/test-utils" ;
2728import { MatrixClientPeg } from "../../../../../src/MatrixClientPeg" ;
2829import * as RoomNotifs from "../../../../../src/RoomNotifs" ;
2930
@@ -34,28 +35,38 @@ jest.mock("../../../../../src/RoomNotifs", () => ({
3435} ) ) ;
3536
3637const ROOM_ID = "!roomId:example.org" ;
37- let THREAD_ID ;
38+ let THREAD_ID : string ;
3839
3940describe ( "UnreadNotificationBadge" , ( ) => {
40- let mockClient : MatrixClient ;
41+ stubClient ( ) ;
42+ const client = MatrixClientPeg . get ( ) ;
4143 let room : Room ;
4244
4345 function getComponent ( threadId ?: string ) {
4446 return < UnreadNotificationBadge room = { room } threadId = { threadId } /> ;
4547 }
4648
49+ beforeAll ( ( ) => {
50+ client . supportsExperimentalThreads = ( ) => true ;
51+ } ) ;
52+
4753 beforeEach ( ( ) => {
4854 jest . clearAllMocks ( ) ;
4955
50- stubClient ( ) ;
51- mockClient = mocked ( MatrixClientPeg . get ( ) ) ;
52-
53- room = new Room ( ROOM_ID , mockClient , mockClient . getUserId ( ) ?? "" , {
56+ room = new Room ( ROOM_ID , client , client . getUserId ( ) ! , {
5457 pendingEventOrdering : PendingEventOrdering . Detached ,
5558 } ) ;
5659 room . setUnreadNotificationCount ( NotificationCountType . Total , 1 ) ;
5760 room . setUnreadNotificationCount ( NotificationCountType . Highlight , 0 ) ;
5861
62+ const { rootEvent } = mkThread ( {
63+ room,
64+ client,
65+ authorId : client . getUserId ( ) ! ,
66+ participantUserIds : [ client . getUserId ( ) ! ] ,
67+ } ) ;
68+ THREAD_ID = rootEvent . getId ( ) ! ;
69+
5970 room . setThreadUnreadNotificationCount ( THREAD_ID , NotificationCountType . Total , 1 ) ;
6071 room . setThreadUnreadNotificationCount ( THREAD_ID , NotificationCountType . Highlight , 0 ) ;
6172
@@ -125,4 +136,33 @@ describe("UnreadNotificationBadge", () => {
125136 const { container } = render ( getComponent ( ) ) ;
126137 expect ( container . querySelector ( ".mx_NotificationBadge" ) ) . toBeNull ( ) ;
127138 } ) ;
139+
140+ it ( "activity renders unread notification badge" , ( ) => {
141+ act ( ( ) => {
142+ room . setThreadUnreadNotificationCount ( THREAD_ID , NotificationCountType . Total , 0 ) ;
143+ room . setThreadUnreadNotificationCount ( THREAD_ID , NotificationCountType . Highlight , 0 ) ;
144+
145+ // Add another event on the thread which is not sent by us.
146+ const event = mkEvent ( {
147+ event : true ,
148+ type : "m.room.message" ,
149+ user : "@alice:server.org" ,
150+ room : room . roomId ,
151+ content : {
152+ "msgtype" : MsgType . Text ,
153+ "body" : "Hello from Bob" ,
154+ "m.relates_to" : {
155+ event_id : THREAD_ID ,
156+ rel_type : RelationType . Thread ,
157+ } ,
158+ } ,
159+ } ) ;
160+ room . addLiveEvents ( [ event ] ) ;
161+ } ) ;
162+
163+ const { container } = render ( getComponent ( THREAD_ID ) ) ;
164+ expect ( container . querySelector ( ".mx_NotificationBadge_dot" ) ) . toBeTruthy ( ) ;
165+ expect ( container . querySelector ( ".mx_NotificationBadge_visible" ) ) . toBeTruthy ( ) ;
166+ expect ( container . querySelector ( ".mx_NotificationBadge_highlighted" ) ) . toBeFalsy ( ) ;
167+ } ) ;
128168} ) ;
0 commit comments