@@ -25,14 +25,7 @@ import { EventType } from "matrix-js-sdk/src/matrix";
25
25
import { MEGOLM_ALGORITHM } from "matrix-js-sdk/src/crypto/olmlib" ;
26
26
import { fireEvent , render } from "@testing-library/react" ;
27
27
28
- import {
29
- stubClient ,
30
- mockPlatformPeg ,
31
- unmockPlatformPeg ,
32
- wrapInMatrixClientContext ,
33
- flushPromises ,
34
- } from "../../test-utils" ;
35
- import { MatrixClientPeg } from "../../../src/MatrixClientPeg" ;
28
+ import { stubClient , mockPlatformPeg , wrapInMatrixClientContext , flushPromises } from "../../test-utils" ;
36
29
import { Action } from "../../../src/dispatcher/actions" ;
37
30
import { defaultDispatcher } from "../../../src/dispatcher/dispatcher" ;
38
31
import { ViewRoomPayload } from "../../../src/dispatcher/payloads/ViewRoomPayload" ;
@@ -60,8 +53,7 @@ describe("RoomView", () => {
60
53
61
54
beforeEach ( async ( ) => {
62
55
mockPlatformPeg ( { reload : ( ) => { } } ) ;
63
- stubClient ( ) ;
64
- cli = mocked ( MatrixClientPeg . get ( ) ) ;
56
+ cli = mocked ( stubClient ( ) ) ;
65
57
66
58
room = new Room ( `!${ roomCount ++ } :example.org` , cli , "@alice:example.org" ) ;
67
59
room . getPendingEvents = ( ) => [ ] ;
@@ -78,11 +70,6 @@ describe("RoomView", () => {
78
70
jest . spyOn ( VoipUserMapper . sharedInstance ( ) , "getVirtualRoomForRoom" ) . mockResolvedValue ( null ) ;
79
71
} ) ;
80
72
81
- afterEach ( async ( ) => {
82
- unmockPlatformPeg ( ) ;
83
- jest . restoreAllMocks ( ) ;
84
- } ) ;
85
-
86
73
const mountRoomView = async ( ) : Promise < ReactWrapper > => {
87
74
if ( stores . roomViewStore . getRoomId ( ) !== room . roomId ) {
88
75
const switchedRoom = new Promise < void > ( ( resolve ) => {
@@ -199,32 +186,35 @@ describe("RoomView", () => {
199
186
} ) ;
200
187
201
188
it ( "checks for a virtual room on room event" , async ( ) => {
189
+ const mock = VoipUserMapper . sharedInstance ( ) . getVirtualRoomForRoom as unknown as jest . SpyInstance ;
202
190
await renderRoomView ( ) ;
203
- expect ( VoipUserMapper . sharedInstance ( ) . getVirtualRoomForRoom ) . toHaveBeenCalledWith ( room . roomId ) ;
191
+ expect ( mock ) . toHaveBeenCalledWith ( room . roomId ) ;
204
192
193
+ mock . mockReset ( ) ;
205
194
cli . emit ( ClientEvent . Room , room ) ;
206
195
207
196
// called again after room event
208
- expect ( VoipUserMapper . sharedInstance ( ) . getVirtualRoomForRoom ) . toHaveBeenCalledTimes ( 2 ) ;
197
+ expect ( VoipUserMapper . sharedInstance ( ) . getVirtualRoomForRoom ) . toHaveBeenCalled ( ) ;
209
198
} ) ;
210
199
} ) ;
211
200
212
201
describe ( "video rooms" , ( ) => {
213
202
beforeEach ( async ( ) => {
214
203
// Make it a video room
215
204
room . isElementVideoRoom = ( ) => true ;
205
+ room . updateMyMembership ( "join" ) ;
216
206
await SettingsStore . setValue ( "feature_video_rooms" , null , SettingLevel . DEVICE , true ) ;
217
207
} ) ;
218
208
219
209
it ( "normally doesn't open the chat panel" , async ( ) => {
220
210
jest . spyOn ( NotificationState . prototype , "isUnread" , "get" ) . mockReturnValue ( false ) ;
221
- await mountRoomView ( ) ;
211
+ await renderRoomView ( ) ;
222
212
expect ( stores . rightPanelStore . isOpen ) . toEqual ( false ) ;
223
213
} ) ;
224
214
225
215
it ( "opens the chat panel if there are unread messages" , async ( ) => {
226
216
jest . spyOn ( NotificationState . prototype , "isUnread" , "get" ) . mockReturnValue ( true ) ;
227
- await mountRoomView ( ) ;
217
+ await renderRoomView ( ) ;
228
218
expect ( stores . rightPanelStore . isOpen ) . toEqual ( true ) ;
229
219
expect ( stores . rightPanelStore . currentCard . phase ) . toEqual ( RightPanelPhases . Timeline ) ;
230
220
} ) ;
0 commit comments