@@ -18,6 +18,8 @@ import React from "react";
1818import { mount } from "enzyme" ;
1919import { act } from "react-dom/test-utils" ;
2020import { mocked } from "jest-mock" ;
21+ import { MatrixClient } from "matrix-js-sdk/src/client" ;
22+ import { Room } from "matrix-js-sdk/src/models/room" ;
2123import { RoomMember } from "matrix-js-sdk/src/models/room-member" ;
2224
2325import {
@@ -26,6 +28,7 @@ import {
2628 mkRoom ,
2729 mkVideoChannelMember ,
2830 stubVideoChannelStore ,
31+ StubVideoChannelStore ,
2932} from "../../../test-utils" ;
3033import RoomTile from "../../../../src/components/views/rooms/RoomTile" ;
3134import SettingsStore from "../../../../src/settings/SettingsStore" ;
@@ -39,9 +42,8 @@ describe("RoomTile", () => {
3942 jest . spyOn ( PlatformPeg , 'get' )
4043 . mockReturnValue ( { overrideBrowserShortcuts : ( ) => false } as unknown as BasePlatform ) ;
4144
42- let cli ;
43- let store ;
44-
45+ let cli : MatrixClient ;
46+ let store : StubVideoChannelStore ;
4547 beforeEach ( ( ) => {
4648 const realGetValue = SettingsStore . getValue ;
4749 SettingsStore . getValue = < T , > ( name : string , roomId ?: string ) : T => {
@@ -52,16 +54,19 @@ describe("RoomTile", () => {
5254 } ;
5355
5456 stubClient ( ) ;
55- cli = mocked ( MatrixClientPeg . get ( ) ) ;
57+ cli = MatrixClientPeg . get ( ) ;
5658 store = stubVideoChannelStore ( ) ;
5759 DMRoomMap . makeShared ( ) ;
5860 } ) ;
5961
6062 afterEach ( ( ) => jest . clearAllMocks ( ) ) ;
6163
6264 describe ( "video rooms" , ( ) => {
63- const room = mkRoom ( cli , "!1:example.org" ) ;
64- room . isElementVideoRoom . mockReturnValue ( true ) ;
65+ let room : Room ;
66+ beforeEach ( ( ) => {
67+ room = mkRoom ( cli , "!1:example.org" ) ;
68+ mocked ( room . isElementVideoRoom ) . mockReturnValue ( true ) ;
69+ } ) ;
6570
6671 it ( "tracks connection state" , ( ) => {
6772 const tile = mount (
@@ -97,7 +102,7 @@ describe("RoomTile", () => {
97102 mkVideoChannelMember ( "@chris:example.org" , [ "device 1" ] ) ,
98103 ] ) ) ;
99104
100- mocked ( room . currentState ) . getMember . mockImplementation ( userId => ( {
105+ mocked ( room ) . getMember . mockImplementation ( userId => ( {
101106 userId,
102107 membership : userId === "@chris:example.org" ? "leave" : "join" ,
103108 name : userId ,
@@ -117,8 +122,36 @@ describe("RoomTile", () => {
117122 ) ;
118123
119124 // Only Alice should display as connected
120- const participants = tile . find ( ".mx_RoomTile_videoParticipants" ) ;
121- expect ( participants . text ( ) ) . toEqual ( "1" ) ;
125+ expect ( tile . find ( ".mx_RoomTile_videoParticipants" ) . text ( ) ) . toEqual ( "1" ) ;
126+ } ) ;
127+
128+ it ( "reflects local echo in connected members" , ( ) => {
129+ mocked ( room . currentState ) . getStateEvents . mockImplementation ( mockStateEventImplementation ( [
130+ // Make the remote echo claim that we're connected, while leaving the store disconnected
131+ mkVideoChannelMember ( cli . getUserId ( ) , [ cli . getDeviceId ( ) ] ) ,
132+ ] ) ) ;
133+
134+ mocked ( room ) . getMember . mockImplementation ( userId => ( {
135+ userId,
136+ membership : "join" ,
137+ name : userId ,
138+ rawDisplayName : userId ,
139+ roomId : "!1:example.org" ,
140+ getAvatarUrl : ( ) => { } ,
141+ getMxcAvatarUrl : ( ) => { } ,
142+ } ) as unknown as RoomMember ) ;
143+
144+ const tile = mount (
145+ < RoomTile
146+ room = { room }
147+ showMessagePreview = { false }
148+ isMinimized = { false }
149+ tag = { DefaultTagID . Untagged }
150+ /> ,
151+ ) ;
152+
153+ // Because of our local echo, we should still appear as disconnected
154+ expect ( tile . find ( ".mx_RoomTile_videoParticipants" ) . exists ( ) ) . toEqual ( false ) ;
122155 } ) ;
123156 } ) ;
124157} ) ;
0 commit comments