1
1
/*
2
- Copyright 2022 The Matrix.org Foundation C.I.C.
2
+ Copyright 2022-2023 The Matrix.org Foundation C.I.C.
3
3
4
4
Licensed under the Apache License, Version 2.0 (the "License");
5
5
you may not use this file except in compliance with the License.
@@ -29,6 +29,8 @@ import ThreadView from "../../../src/components/structures/ThreadView";
29
29
import MatrixClientContext from "../../../src/contexts/MatrixClientContext" ;
30
30
import RoomContext from "../../../src/contexts/RoomContext" ;
31
31
import { SdkContextClass } from "../../../src/contexts/SDKContext" ;
32
+ import { Action } from "../../../src/dispatcher/actions" ;
33
+ import dispatcher from "../../../src/dispatcher/dispatcher" ;
32
34
import { MatrixClientPeg } from "../../../src/MatrixClientPeg" ;
33
35
import DMRoomMap from "../../../src/utils/DMRoomMap" ;
34
36
import ResizeNotifier from "../../../src/utils/ResizeNotifier" ;
@@ -47,7 +49,7 @@ describe("ThreadView", () => {
47
49
48
50
let changeEvent : ( event : MatrixEvent ) => void ;
49
51
50
- function TestThreadView ( ) {
52
+ function TestThreadView ( { initialEvent } : { initialEvent ?: MatrixEvent } ) {
51
53
const [ event , setEvent ] = useState ( rootEvent ) ;
52
54
changeEvent = setEvent ;
53
55
@@ -58,15 +60,21 @@ describe("ThreadView", () => {
58
60
canSendMessages : true ,
59
61
} ) }
60
62
>
61
- < ThreadView room = { room } onClose = { jest . fn ( ) } mxEvent = { event } resizeNotifier = { new ResizeNotifier ( ) } />
63
+ < ThreadView
64
+ room = { room }
65
+ onClose = { jest . fn ( ) }
66
+ mxEvent = { event }
67
+ initialEvent = { initialEvent }
68
+ resizeNotifier = { new ResizeNotifier ( ) }
69
+ />
62
70
</ RoomContext . Provider >
63
71
,
64
72
</ MatrixClientContext . Provider >
65
73
) ;
66
74
}
67
75
68
- async function getComponent ( ) : Promise < RenderResult > {
69
- const renderResult = render ( < TestThreadView /> ) ;
76
+ async function getComponent ( initialEvent ?: MatrixEvent ) : Promise < RenderResult > {
77
+ const renderResult = render ( < TestThreadView initialEvent = { initialEvent } /> ) ;
70
78
71
79
await waitFor ( ( ) => {
72
80
expect ( ( ) => getByTestId ( renderResult . container , "spinner" ) ) . toThrow ( ) ;
@@ -171,4 +179,17 @@ describe("ThreadView", () => {
171
179
unmount ( ) ;
172
180
await waitFor ( ( ) => expect ( SdkContextClass . instance . roomViewStore . getThreadId ( ) ) . toBeNull ( ) ) ;
173
181
} ) ;
182
+
183
+ it ( "clears highlight message in the room view store" , async ( ) => {
184
+ jest . spyOn ( SdkContextClass . instance . roomViewStore , "getRoomId" ) . mockReturnValue ( room . roomId ) ;
185
+ const mock = jest . spyOn ( dispatcher , "dispatch" ) ;
186
+ const { unmount } = await getComponent ( rootEvent ) ;
187
+ mock . mockClear ( ) ;
188
+ unmount ( ) ;
189
+ expect ( mock ) . toHaveBeenCalledWith ( {
190
+ action : Action . ViewRoom ,
191
+ room_id : room . roomId ,
192
+ metricsTrigger : undefined ,
193
+ } ) ;
194
+ } ) ;
174
195
} ) ;
0 commit comments