@@ -15,7 +15,7 @@ limitations under the License.
15
15
*/
16
16
17
17
import React from 'react' ;
18
- import { mount } from 'enzyme' ;
18
+ import { mount , ReactWrapper } from 'enzyme' ;
19
19
import { RoomMember } from 'matrix-js-sdk/src/models/room-member' ;
20
20
import { MatrixClient } from 'matrix-js-sdk/src/client' ;
21
21
import { mocked } from 'jest-mock' ;
@@ -90,21 +90,24 @@ describe('<LocationShareMenu />', () => {
90
90
} ) ;
91
91
92
92
beforeEach ( ( ) => {
93
- mocked ( SettingsStore ) . getValue . mockImplementation (
94
- ( settingName ) => settingName === "feature_location_share_pin_drop" ,
95
- ) ;
96
-
93
+ mocked ( SettingsStore ) . getValue . mockReturnValue ( false ) ;
97
94
mockClient . sendMessage . mockClear ( ) ;
98
-
99
95
jest . spyOn ( MatrixClientPeg , 'get' ) . mockReturnValue ( mockClient as unknown as MatrixClient ) ;
100
96
} ) ;
101
97
102
- const getShareTypeOption = ( component , shareType : LocationShareType ) =>
98
+ const getShareTypeOption = ( component : ReactWrapper , shareType : LocationShareType ) =>
103
99
findByTestId ( component , `share-location-option-${ shareType } ` ) ;
104
- const getBackButton = component => findByTestId ( component , 'share-dialog-buttons-back' ) ;
105
- const getCancelButton = component => findByTestId ( component , 'share-dialog-buttons-cancel' ) ;
106
- const getSubmitButton = component => findByTestId ( component , 'location-picker-submit-button' ) ;
107
- const setLocation = ( component ) => {
100
+
101
+ const getBackButton = ( component : ReactWrapper ) =>
102
+ findByTestId ( component , 'share-dialog-buttons-back' ) ;
103
+
104
+ const getCancelButton = ( component : ReactWrapper ) =>
105
+ findByTestId ( component , 'share-dialog-buttons-cancel' ) ;
106
+
107
+ const getSubmitButton = ( component : ReactWrapper ) =>
108
+ findByTestId ( component , 'location-picker-submit-button' ) ;
109
+
110
+ const setLocation = ( component : ReactWrapper ) => {
108
111
// set the location
109
112
const locationPickerInstance = component . find ( 'LocationPicker' ) . instance ( ) ;
110
113
act ( ( ) => {
@@ -114,16 +117,16 @@ describe('<LocationShareMenu />', () => {
114
117
component . setProps ( { } ) ;
115
118
} ) ;
116
119
} ;
117
- const setShareType = ( component , shareType ) => act ( ( ) => {
118
- getShareTypeOption ( component , shareType ) . at ( 0 ) . simulate ( 'click' ) ;
119
- component . setProps ( { } ) ;
120
- } ) ;
121
120
122
- describe ( 'when only Own share type is enabled' , ( ) => {
123
- beforeEach ( ( ) => {
124
- mocked ( SettingsStore ) . getValue . mockReturnValue ( false ) ;
121
+ const setShareType = ( component : ReactWrapper , shareType : LocationShareType ) =>
122
+ act ( ( ) => {
123
+ getShareTypeOption ( component , shareType ) . at ( 0 ) . simulate ( 'click' ) ;
124
+ component . setProps ( { } ) ;
125
125
} ) ;
126
126
127
+ describe ( 'when only Own share type is enabled' , ( ) => {
128
+ beforeEach ( ( ) => enableSettings ( [ ] ) ) ;
129
+
127
130
it ( 'renders location picker when only Own share type is enabled' , ( ) => {
128
131
const component = getComponent ( ) ;
129
132
expect ( component . find ( 'ShareType' ) . length ) . toBeFalsy ( ) ;
@@ -170,7 +173,7 @@ describe('<LocationShareMenu />', () => {
170
173
} ) ;
171
174
172
175
describe ( 'with pin drop share type enabled' , ( ) => {
173
- // feature_location_share_pin_drop is set to enabled by default mocking
176
+ beforeEach ( ( ) => enableSettings ( [ "feature_location_share_pin_drop" ] ) ) ;
174
177
175
178
it ( 'renders share type switch with own and pin drop options' , ( ) => {
176
179
const component = getComponent ( ) ;
@@ -205,7 +208,6 @@ describe('<LocationShareMenu />', () => {
205
208
} ) ;
206
209
207
210
it ( 'clicking back button from location picker screen goes back to share screen' , ( ) => {
208
- // feature_location_share_pin_drop is set to enabled by default mocking
209
211
const onFinished = jest . fn ( ) ;
210
212
const component = getComponent ( { onFinished } ) ;
211
213
@@ -224,7 +226,6 @@ describe('<LocationShareMenu />', () => {
224
226
} ) ;
225
227
226
228
it ( 'creates pin drop location share event on submission' , ( ) => {
227
- // feature_location_share_pin_drop is set to enabled by default mocking
228
229
const onFinished = jest . fn ( ) ;
229
230
const component = getComponent ( { onFinished } ) ;
230
231
@@ -249,4 +250,40 @@ describe('<LocationShareMenu />', () => {
249
250
} ) ) ;
250
251
} ) ;
251
252
} ) ;
253
+
254
+ describe ( 'with live location and pin drop enabled' , ( ) => {
255
+ beforeEach ( ( ) => enableSettings ( [
256
+ "feature_location_share_pin_drop" ,
257
+ "feature_location_share_live" ,
258
+ ] ) ) ;
259
+
260
+ it ( 'renders share type switch with all 3 options' , ( ) => {
261
+ // Given pin and live feature flags are enabled
262
+ // When I click Location
263
+ const component = getComponent ( ) ;
264
+
265
+ // The the Location picker is not visible yet
266
+ expect ( component . find ( 'LocationPicker' ) . length ) . toBeFalsy ( ) ;
267
+
268
+ // And all 3 buttons are visible on the LocationShare dialog
269
+ expect (
270
+ getShareTypeOption ( component , LocationShareType . Own ) . length ,
271
+ ) . toBeTruthy ( ) ;
272
+
273
+ expect (
274
+ getShareTypeOption ( component , LocationShareType . Pin ) . length ,
275
+ ) . toBeTruthy ( ) ;
276
+
277
+ expect (
278
+ getShareTypeOption ( component , LocationShareType . Live ) . length ,
279
+ ) . toBeTruthy ( ) ;
280
+ } ) ;
281
+ } ) ;
252
282
} ) ;
283
+
284
+ function enableSettings ( settings : string [ ] ) {
285
+ mocked ( SettingsStore ) . getValue . mockReturnValue ( false ) ;
286
+ mocked ( SettingsStore ) . getValue . mockImplementation (
287
+ ( settingName : string ) => settings . includes ( settingName ) ,
288
+ ) ;
289
+ }
0 commit comments