@@ -20,12 +20,16 @@ import { act } from 'react-dom/test-utils';
2020import maplibregl from 'maplibre-gl' ;
2121import {
2222 BeaconEvent ,
23- Room ,
2423 getBeaconInfoIdentifier ,
2524} from 'matrix-js-sdk/src/matrix' ;
2625
2726import MBeaconBody from '../../../../src/components/views/messages/MBeaconBody' ;
28- import { getMockClientWithEventEmitter , makeBeaconEvent , makeBeaconInfoEvent } from '../../../test-utils' ;
27+ import {
28+ getMockClientWithEventEmitter ,
29+ makeBeaconEvent ,
30+ makeBeaconInfoEvent ,
31+ makeRoomWithStateEvents ,
32+ } from '../../../test-utils' ;
2933import { RoomPermalinkCreator } from '../../../../src/utils/permalinks/Permalinks' ;
3034import { MediaEventHelper } from '../../../../src/utils/MediaEventHelper' ;
3135import MatrixClientContext from '../../../../src/contexts/MatrixClientContext' ;
@@ -51,17 +55,6 @@ describe('<MBeaconBody />', () => {
5155 getRoom : jest . fn ( ) ,
5256 } ) ;
5357
54- // make fresh rooms every time
55- // as we update room state
56- const makeRoomWithStateEvents = ( stateEvents = [ ] ) : Room => {
57- const room1 = new Room ( roomId , mockClient , aliceId ) ;
58-
59- room1 . currentState . setStateEvents ( stateEvents ) ;
60- mockClient . getRoom . mockReturnValue ( room1 ) ;
61-
62- return room1 ;
63- } ;
64-
6558 const defaultEvent = makeBeaconInfoEvent ( aliceId ,
6659 roomId ,
6760 { isLive : true } ,
@@ -96,7 +89,7 @@ describe('<MBeaconBody />', () => {
9689 { isLive : false } ,
9790 '$alice-room1-1' ,
9891 ) ;
99- makeRoomWithStateEvents ( [ beaconInfoEvent ] ) ;
92+ makeRoomWithStateEvents ( [ beaconInfoEvent ] , { roomId , mockClient } ) ;
10093 const component = getComponent ( { mxEvent : beaconInfoEvent } ) ;
10194 expect ( component . text ( ) ) . toEqual ( "Live location ended" ) ;
10295 } ) ;
@@ -108,7 +101,7 @@ describe('<MBeaconBody />', () => {
108101 { isLive : true , timestamp : now - 600000 , timeout : 500 } ,
109102 '$alice-room1-1' ,
110103 ) ;
111- makeRoomWithStateEvents ( [ beaconInfoEvent ] ) ;
104+ makeRoomWithStateEvents ( [ beaconInfoEvent ] , { roomId , mockClient } ) ;
112105 const component = getComponent ( { mxEvent : beaconInfoEvent } ) ;
113106 expect ( component . text ( ) ) . toEqual ( "Live location ended" ) ;
114107 } ) ;
@@ -120,7 +113,7 @@ describe('<MBeaconBody />', () => {
120113 { isLive : true , timestamp : now - 600000 , timeout : 500 } ,
121114 '$alice-room1-1' ,
122115 ) ;
123- makeRoomWithStateEvents ( [ beaconInfoEvent ] ) ;
116+ makeRoomWithStateEvents ( [ beaconInfoEvent ] , { roomId , mockClient } ) ;
124117 const component = getComponent ( { mxEvent : beaconInfoEvent } ) ;
125118 act ( ( ) => {
126119 component . find ( '.mx_MBeaconBody_map' ) . simulate ( 'click' ) ;
@@ -145,7 +138,7 @@ describe('<MBeaconBody />', () => {
145138 '$alice-room1-2' ,
146139 ) ;
147140
148- makeRoomWithStateEvents ( [ aliceBeaconInfo1 , aliceBeaconInfo2 ] ) ;
141+ makeRoomWithStateEvents ( [ aliceBeaconInfo1 , aliceBeaconInfo2 ] , { roomId , mockClient } ) ;
149142
150143 const component = getComponent ( { mxEvent : aliceBeaconInfo1 } ) ;
151144 // beacon1 has been superceded by beacon2
@@ -168,7 +161,7 @@ describe('<MBeaconBody />', () => {
168161 '$alice-room1-2' ,
169162 ) ;
170163
171- const room = makeRoomWithStateEvents ( [ aliceBeaconInfo1 ] ) ;
164+ const room = makeRoomWithStateEvents ( [ aliceBeaconInfo1 ] , { roomId , mockClient } ) ;
172165 const component = getComponent ( { mxEvent : aliceBeaconInfo1 } ) ;
173166
174167 const beaconInstance = room . currentState . beacons . get ( getBeaconInfoIdentifier ( aliceBeaconInfo1 ) ) ;
@@ -193,7 +186,7 @@ describe('<MBeaconBody />', () => {
193186 '$alice-room1-1' ,
194187 ) ;
195188
196- const room = makeRoomWithStateEvents ( [ aliceBeaconInfo ] ) ;
189+ const room = makeRoomWithStateEvents ( [ aliceBeaconInfo ] , { roomId , mockClient } ) ;
197190 const beaconInstance = room . currentState . beacons . get ( getBeaconInfoIdentifier ( aliceBeaconInfo ) ) ;
198191 const component = getComponent ( { mxEvent : aliceBeaconInfo } ) ;
199192
@@ -226,14 +219,14 @@ describe('<MBeaconBody />', () => {
226219 ) ;
227220
228221 it ( 'renders a live beacon without a location correctly' , ( ) => {
229- makeRoomWithStateEvents ( [ aliceBeaconInfo ] ) ;
222+ makeRoomWithStateEvents ( [ aliceBeaconInfo ] , { roomId , mockClient } ) ;
230223 const component = getComponent ( { mxEvent : aliceBeaconInfo } ) ;
231224
232225 expect ( component . text ( ) ) . toEqual ( "Loading live location..." ) ;
233226 } ) ;
234227
235228 it ( 'does nothing on click when a beacon has no location' , ( ) => {
236- makeRoomWithStateEvents ( [ aliceBeaconInfo ] ) ;
229+ makeRoomWithStateEvents ( [ aliceBeaconInfo ] , { roomId , mockClient } ) ;
237230 const component = getComponent ( { mxEvent : aliceBeaconInfo } ) ;
238231
239232 act ( ( ) => {
@@ -244,7 +237,7 @@ describe('<MBeaconBody />', () => {
244237 } ) ;
245238
246239 it ( 'renders a live beacon with a location correctly' , ( ) => {
247- const room = makeRoomWithStateEvents ( [ aliceBeaconInfo ] ) ;
240+ const room = makeRoomWithStateEvents ( [ aliceBeaconInfo ] , { roomId , mockClient } ) ;
248241 const beaconInstance = room . currentState . beacons . get ( getBeaconInfoIdentifier ( aliceBeaconInfo ) ) ;
249242 beaconInstance . addLocations ( [ location1 ] ) ;
250243 const component = getComponent ( { mxEvent : aliceBeaconInfo } ) ;
@@ -253,7 +246,7 @@ describe('<MBeaconBody />', () => {
253246 } ) ;
254247
255248 it ( 'opens maximised map view on click when beacon has a live location' , ( ) => {
256- const room = makeRoomWithStateEvents ( [ aliceBeaconInfo ] ) ;
249+ const room = makeRoomWithStateEvents ( [ aliceBeaconInfo ] , { roomId , mockClient } ) ;
257250 const beaconInstance = room . currentState . beacons . get ( getBeaconInfoIdentifier ( aliceBeaconInfo ) ) ;
258251 beaconInstance . addLocations ( [ location1 ] ) ;
259252 const component = getComponent ( { mxEvent : aliceBeaconInfo } ) ;
@@ -267,7 +260,7 @@ describe('<MBeaconBody />', () => {
267260 } ) ;
268261
269262 it ( 'does nothing on click when a beacon has no location' , ( ) => {
270- makeRoomWithStateEvents ( [ aliceBeaconInfo ] ) ;
263+ makeRoomWithStateEvents ( [ aliceBeaconInfo ] , { roomId , mockClient } ) ;
271264 const component = getComponent ( { mxEvent : aliceBeaconInfo } ) ;
272265
273266 act ( ( ) => {
@@ -278,7 +271,7 @@ describe('<MBeaconBody />', () => {
278271 } ) ;
279272
280273 it ( 'renders a live beacon with a location correctly' , ( ) => {
281- const room = makeRoomWithStateEvents ( [ aliceBeaconInfo ] ) ;
274+ const room = makeRoomWithStateEvents ( [ aliceBeaconInfo ] , { roomId , mockClient } ) ;
282275 const beaconInstance = room . currentState . beacons . get ( getBeaconInfoIdentifier ( aliceBeaconInfo ) ) ;
283276 beaconInstance . addLocations ( [ location1 ] ) ;
284277 const component = getComponent ( { mxEvent : aliceBeaconInfo } ) ;
@@ -287,7 +280,7 @@ describe('<MBeaconBody />', () => {
287280 } ) ;
288281
289282 it ( 'opens maximised map view on click when beacon has a live location' , ( ) => {
290- const room = makeRoomWithStateEvents ( [ aliceBeaconInfo ] ) ;
283+ const room = makeRoomWithStateEvents ( [ aliceBeaconInfo ] , { roomId , mockClient } ) ;
291284 const beaconInstance = room . currentState . beacons . get ( getBeaconInfoIdentifier ( aliceBeaconInfo ) ) ;
292285 beaconInstance . addLocations ( [ location1 ] ) ;
293286 const component = getComponent ( { mxEvent : aliceBeaconInfo } ) ;
@@ -301,7 +294,7 @@ describe('<MBeaconBody />', () => {
301294 } ) ;
302295
303296 it ( 'updates latest location' , ( ) => {
304- const room = makeRoomWithStateEvents ( [ aliceBeaconInfo ] ) ;
297+ const room = makeRoomWithStateEvents ( [ aliceBeaconInfo ] , { roomId , mockClient } ) ;
305298 const component = getComponent ( { mxEvent : aliceBeaconInfo } ) ;
306299
307300 const beaconInstance = room . currentState . beacons . get ( getBeaconInfoIdentifier ( aliceBeaconInfo ) ) ;
0 commit comments