@@ -17,15 +17,16 @@ limitations under the License.
17
17
import React from "react" ;
18
18
import "jest-mock" ;
19
19
import { screen , act , render } from "@testing-library/react" ;
20
- import { MatrixClient , PendingEventOrdering } from "matrix-js-sdk/src/client" ;
20
+ import { MsgType } from "matrix-js-sdk/src/matrix" ;
21
+ import { PendingEventOrdering } from "matrix-js-sdk/src/client" ;
21
22
import { NotificationCountType , Room } from "matrix-js-sdk/src/models/room" ;
22
- import { mocked } from "jest-mock" ;
23
23
import { EventStatus } from "matrix-js-sdk/src/models/event-status" ;
24
24
25
25
import {
26
26
UnreadNotificationBadge ,
27
27
} from "../../../../../src/components/views/rooms/NotificationBadge/UnreadNotificationBadge" ;
28
- import { mkMessage , stubClient } from "../../../../test-utils/test-utils" ;
28
+ import { mkEvent , mkMessage , stubClient } from "../../../../test-utils/test-utils" ;
29
+ import { mkThread } from "../../../../test-utils/threads" ;
29
30
import { MatrixClientPeg } from "../../../../../src/MatrixClientPeg" ;
30
31
import * as RoomNotifs from "../../../../../src/RoomNotifs" ;
31
32
@@ -36,28 +37,35 @@ jest.mock('../../../../../src/RoomNotifs', () => ({
36
37
} ) ) ;
37
38
38
39
const ROOM_ID = "!roomId:example.org" ;
39
- let THREAD_ID ;
40
+ let THREAD_ID : string ;
40
41
41
42
describe ( "UnreadNotificationBadge" , ( ) => {
42
- let mockClient : MatrixClient ;
43
+ stubClient ( ) ;
44
+ const client = MatrixClientPeg . get ( ) ;
43
45
let room : Room ;
44
46
45
47
function getComponent ( threadId ?: string ) {
46
48
return < UnreadNotificationBadge room = { room } threadId = { threadId } /> ;
47
49
}
48
50
51
+ beforeAll ( ( ) => {
52
+ client . supportsExperimentalThreads = ( ) => true ;
53
+ } ) ;
54
+
49
55
beforeEach ( ( ) => {
50
56
jest . clearAllMocks ( ) ;
51
57
52
- stubClient ( ) ;
53
- mockClient = mocked ( MatrixClientPeg . get ( ) ) ;
54
-
55
- room = new Room ( ROOM_ID , mockClient , mockClient . getUserId ( ) ?? "" , {
58
+ room = new Room ( ROOM_ID , client , client . getUserId ( ) ! , {
56
59
pendingEventOrdering : PendingEventOrdering . Detached ,
57
60
} ) ;
58
61
room . setUnreadNotificationCount ( NotificationCountType . Total , 1 ) ;
59
62
room . setUnreadNotificationCount ( NotificationCountType . Highlight , 0 ) ;
60
63
64
+ const { rootEvent } = mkThread (
65
+ { room, client, authorId : client . getUserId ( ) ! , participantUserIds : [ client . getUserId ( ) ! ] } ,
66
+ ) ;
67
+ THREAD_ID = rootEvent . getId ( ) ! ;
68
+
61
69
room . setThreadUnreadNotificationCount ( THREAD_ID , NotificationCountType . Total , 1 ) ;
62
70
room . setThreadUnreadNotificationCount ( THREAD_ID , NotificationCountType . Highlight , 0 ) ;
63
71
@@ -129,4 +137,33 @@ describe("UnreadNotificationBadge", () => {
129
137
const { container } = render ( getComponent ( ) ) ;
130
138
expect ( container . querySelector ( ".mx_NotificationBadge" ) ) . toBeNull ( ) ;
131
139
} ) ;
140
+
141
+ it ( "activity renders unread notification badge" , ( ) => {
142
+ act ( ( ) => {
143
+ room . setThreadUnreadNotificationCount ( THREAD_ID , NotificationCountType . Total , 0 ) ;
144
+ room . setThreadUnreadNotificationCount ( THREAD_ID , NotificationCountType . Highlight , 0 ) ;
145
+
146
+ // Add another event on the thread which is not sent by us.
147
+ const event = mkEvent ( {
148
+ event : true ,
149
+ type : "m.room.message" ,
150
+ user : "@alice:server.org" ,
151
+ room : room . roomId ,
152
+ content : {
153
+ "msgtype" : MsgType . Text ,
154
+ "body" : 'Hello from Bob' ,
155
+ "m.relates_to" : {
156
+ event_id : THREAD_ID ,
157
+ rel_type : "m.thread" ,
158
+ } ,
159
+ } ,
160
+ } ) ;
161
+ room . addLiveEvents ( [ event ] ) ;
162
+ } ) ;
163
+
164
+ const { container } = render ( getComponent ( THREAD_ID ) ) ;
165
+ expect ( container . querySelector ( ".mx_NotificationBadge_dot" ) ) . toBeTruthy ( ) ;
166
+ expect ( container . querySelector ( ".mx_NotificationBadge_visible" ) ) . toBeTruthy ( ) ;
167
+ expect ( container . querySelector ( ".mx_NotificationBadge_highlighted" ) ) . toBeFalsy ( ) ;
168
+ } ) ;
132
169
} ) ;
0 commit comments