@@ -20,12 +20,16 @@ import { act } from 'react-dom/test-utils';
20
20
import maplibregl from 'maplibre-gl' ;
21
21
import {
22
22
BeaconEvent ,
23
- Room ,
24
23
getBeaconInfoIdentifier ,
25
24
} from 'matrix-js-sdk/src/matrix' ;
26
25
27
26
import 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' ;
29
33
import { RoomPermalinkCreator } from '../../../../src/utils/permalinks/Permalinks' ;
30
34
import { MediaEventHelper } from '../../../../src/utils/MediaEventHelper' ;
31
35
import MatrixClientContext from '../../../../src/contexts/MatrixClientContext' ;
@@ -51,17 +55,6 @@ describe('<MBeaconBody />', () => {
51
55
getRoom : jest . fn ( ) ,
52
56
} ) ;
53
57
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
-
65
58
const defaultEvent = makeBeaconInfoEvent ( aliceId ,
66
59
roomId ,
67
60
{ isLive : true } ,
@@ -96,7 +89,7 @@ describe('<MBeaconBody />', () => {
96
89
{ isLive : false } ,
97
90
'$alice-room1-1' ,
98
91
) ;
99
- makeRoomWithStateEvents ( [ beaconInfoEvent ] ) ;
92
+ makeRoomWithStateEvents ( [ beaconInfoEvent ] , { roomId , mockClient } ) ;
100
93
const component = getComponent ( { mxEvent : beaconInfoEvent } ) ;
101
94
expect ( component . text ( ) ) . toEqual ( "Live location ended" ) ;
102
95
} ) ;
@@ -108,7 +101,7 @@ describe('<MBeaconBody />', () => {
108
101
{ isLive : true , timestamp : now - 600000 , timeout : 500 } ,
109
102
'$alice-room1-1' ,
110
103
) ;
111
- makeRoomWithStateEvents ( [ beaconInfoEvent ] ) ;
104
+ makeRoomWithStateEvents ( [ beaconInfoEvent ] , { roomId , mockClient } ) ;
112
105
const component = getComponent ( { mxEvent : beaconInfoEvent } ) ;
113
106
expect ( component . text ( ) ) . toEqual ( "Live location ended" ) ;
114
107
} ) ;
@@ -120,7 +113,7 @@ describe('<MBeaconBody />', () => {
120
113
{ isLive : true , timestamp : now - 600000 , timeout : 500 } ,
121
114
'$alice-room1-1' ,
122
115
) ;
123
- makeRoomWithStateEvents ( [ beaconInfoEvent ] ) ;
116
+ makeRoomWithStateEvents ( [ beaconInfoEvent ] , { roomId , mockClient } ) ;
124
117
const component = getComponent ( { mxEvent : beaconInfoEvent } ) ;
125
118
act ( ( ) => {
126
119
component . find ( '.mx_MBeaconBody_map' ) . simulate ( 'click' ) ;
@@ -145,7 +138,7 @@ describe('<MBeaconBody />', () => {
145
138
'$alice-room1-2' ,
146
139
) ;
147
140
148
- makeRoomWithStateEvents ( [ aliceBeaconInfo1 , aliceBeaconInfo2 ] ) ;
141
+ makeRoomWithStateEvents ( [ aliceBeaconInfo1 , aliceBeaconInfo2 ] , { roomId , mockClient } ) ;
149
142
150
143
const component = getComponent ( { mxEvent : aliceBeaconInfo1 } ) ;
151
144
// beacon1 has been superceded by beacon2
@@ -168,7 +161,7 @@ describe('<MBeaconBody />', () => {
168
161
'$alice-room1-2' ,
169
162
) ;
170
163
171
- const room = makeRoomWithStateEvents ( [ aliceBeaconInfo1 ] ) ;
164
+ const room = makeRoomWithStateEvents ( [ aliceBeaconInfo1 ] , { roomId , mockClient } ) ;
172
165
const component = getComponent ( { mxEvent : aliceBeaconInfo1 } ) ;
173
166
174
167
const beaconInstance = room . currentState . beacons . get ( getBeaconInfoIdentifier ( aliceBeaconInfo1 ) ) ;
@@ -193,7 +186,7 @@ describe('<MBeaconBody />', () => {
193
186
'$alice-room1-1' ,
194
187
) ;
195
188
196
- const room = makeRoomWithStateEvents ( [ aliceBeaconInfo ] ) ;
189
+ const room = makeRoomWithStateEvents ( [ aliceBeaconInfo ] , { roomId , mockClient } ) ;
197
190
const beaconInstance = room . currentState . beacons . get ( getBeaconInfoIdentifier ( aliceBeaconInfo ) ) ;
198
191
const component = getComponent ( { mxEvent : aliceBeaconInfo } ) ;
199
192
@@ -226,14 +219,14 @@ describe('<MBeaconBody />', () => {
226
219
) ;
227
220
228
221
it ( 'renders a live beacon without a location correctly' , ( ) => {
229
- makeRoomWithStateEvents ( [ aliceBeaconInfo ] ) ;
222
+ makeRoomWithStateEvents ( [ aliceBeaconInfo ] , { roomId , mockClient } ) ;
230
223
const component = getComponent ( { mxEvent : aliceBeaconInfo } ) ;
231
224
232
225
expect ( component . text ( ) ) . toEqual ( "Loading live location..." ) ;
233
226
} ) ;
234
227
235
228
it ( 'does nothing on click when a beacon has no location' , ( ) => {
236
- makeRoomWithStateEvents ( [ aliceBeaconInfo ] ) ;
229
+ makeRoomWithStateEvents ( [ aliceBeaconInfo ] , { roomId , mockClient } ) ;
237
230
const component = getComponent ( { mxEvent : aliceBeaconInfo } ) ;
238
231
239
232
act ( ( ) => {
@@ -244,7 +237,7 @@ describe('<MBeaconBody />', () => {
244
237
} ) ;
245
238
246
239
it ( 'renders a live beacon with a location correctly' , ( ) => {
247
- const room = makeRoomWithStateEvents ( [ aliceBeaconInfo ] ) ;
240
+ const room = makeRoomWithStateEvents ( [ aliceBeaconInfo ] , { roomId , mockClient } ) ;
248
241
const beaconInstance = room . currentState . beacons . get ( getBeaconInfoIdentifier ( aliceBeaconInfo ) ) ;
249
242
beaconInstance . addLocations ( [ location1 ] ) ;
250
243
const component = getComponent ( { mxEvent : aliceBeaconInfo } ) ;
@@ -253,7 +246,7 @@ describe('<MBeaconBody />', () => {
253
246
} ) ;
254
247
255
248
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 } ) ;
257
250
const beaconInstance = room . currentState . beacons . get ( getBeaconInfoIdentifier ( aliceBeaconInfo ) ) ;
258
251
beaconInstance . addLocations ( [ location1 ] ) ;
259
252
const component = getComponent ( { mxEvent : aliceBeaconInfo } ) ;
@@ -267,7 +260,7 @@ describe('<MBeaconBody />', () => {
267
260
} ) ;
268
261
269
262
it ( 'does nothing on click when a beacon has no location' , ( ) => {
270
- makeRoomWithStateEvents ( [ aliceBeaconInfo ] ) ;
263
+ makeRoomWithStateEvents ( [ aliceBeaconInfo ] , { roomId , mockClient } ) ;
271
264
const component = getComponent ( { mxEvent : aliceBeaconInfo } ) ;
272
265
273
266
act ( ( ) => {
@@ -278,7 +271,7 @@ describe('<MBeaconBody />', () => {
278
271
} ) ;
279
272
280
273
it ( 'renders a live beacon with a location correctly' , ( ) => {
281
- const room = makeRoomWithStateEvents ( [ aliceBeaconInfo ] ) ;
274
+ const room = makeRoomWithStateEvents ( [ aliceBeaconInfo ] , { roomId , mockClient } ) ;
282
275
const beaconInstance = room . currentState . beacons . get ( getBeaconInfoIdentifier ( aliceBeaconInfo ) ) ;
283
276
beaconInstance . addLocations ( [ location1 ] ) ;
284
277
const component = getComponent ( { mxEvent : aliceBeaconInfo } ) ;
@@ -287,7 +280,7 @@ describe('<MBeaconBody />', () => {
287
280
} ) ;
288
281
289
282
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 } ) ;
291
284
const beaconInstance = room . currentState . beacons . get ( getBeaconInfoIdentifier ( aliceBeaconInfo ) ) ;
292
285
beaconInstance . addLocations ( [ location1 ] ) ;
293
286
const component = getComponent ( { mxEvent : aliceBeaconInfo } ) ;
@@ -301,7 +294,7 @@ describe('<MBeaconBody />', () => {
301
294
} ) ;
302
295
303
296
it ( 'updates latest location' , ( ) => {
304
- const room = makeRoomWithStateEvents ( [ aliceBeaconInfo ] ) ;
297
+ const room = makeRoomWithStateEvents ( [ aliceBeaconInfo ] , { roomId , mockClient } ) ;
305
298
const component = getComponent ( { mxEvent : aliceBeaconInfo } ) ;
306
299
307
300
const beaconInstance = room . currentState . beacons . get ( getBeaconInfoIdentifier ( aliceBeaconInfo ) ) ;
0 commit comments