Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit e1fdff4

Browse files
authored
Show "Share my location" button (#8054)
1 parent 2778fd1 commit e1fdff4

File tree

2 files changed

+67
-27
lines changed

2 files changed

+67
-27
lines changed

src/components/views/location/LocationShareMenu.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,17 @@ type Props = Omit<ILocationPickerProps, 'onChoose' | 'shareType'> & {
3636
};
3737

3838
const getEnabledShareTypes = (): LocationShareType[] => {
39-
const isPinDropLocationShareEnabled = SettingsStore.getValue("feature_location_share_pin_drop");
39+
const enabledShareTypes = [LocationShareType.Own];
4040

41-
if (isPinDropLocationShareEnabled) {
42-
return [LocationShareType.Own, LocationShareType.Pin];
41+
if (SettingsStore.getValue("feature_location_share_live")) {
42+
enabledShareTypes.push(LocationShareType.Live);
4343
}
44-
return [
45-
LocationShareType.Own,
46-
];
44+
45+
if (SettingsStore.getValue("feature_location_share_pin_drop")) {
46+
enabledShareTypes.push(LocationShareType.Pin);
47+
}
48+
49+
return enabledShareTypes;
4750
};
4851

4952
const LocationShareMenu: React.FC<Props> = ({

test/components/views/location/LocationShareMenu-test.tsx

Lines changed: 58 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ limitations under the License.
1515
*/
1616

1717
import React from 'react';
18-
import { mount } from 'enzyme';
18+
import { mount, ReactWrapper } from 'enzyme';
1919
import { RoomMember } from 'matrix-js-sdk/src/models/room-member';
2020
import { MatrixClient } from 'matrix-js-sdk/src/client';
2121
import { mocked } from 'jest-mock';
@@ -90,21 +90,24 @@ describe('<LocationShareMenu />', () => {
9090
});
9191

9292
beforeEach(() => {
93-
mocked(SettingsStore).getValue.mockImplementation(
94-
(settingName) => settingName === "feature_location_share_pin_drop",
95-
);
96-
93+
mocked(SettingsStore).getValue.mockReturnValue(false);
9794
mockClient.sendMessage.mockClear();
98-
9995
jest.spyOn(MatrixClientPeg, 'get').mockReturnValue(mockClient as unknown as MatrixClient);
10096
});
10197

102-
const getShareTypeOption = (component, shareType: LocationShareType) =>
98+
const getShareTypeOption = (component: ReactWrapper, shareType: LocationShareType) =>
10399
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) => {
108111
// set the location
109112
const locationPickerInstance = component.find('LocationPicker').instance();
110113
act(() => {
@@ -114,16 +117,16 @@ describe('<LocationShareMenu />', () => {
114117
component.setProps({});
115118
});
116119
};
117-
const setShareType = (component, shareType) => act(() => {
118-
getShareTypeOption(component, shareType).at(0).simulate('click');
119-
component.setProps({});
120-
});
121120

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({});
125125
});
126126

127+
describe('when only Own share type is enabled', () => {
128+
beforeEach(() => enableSettings([]));
129+
127130
it('renders location picker when only Own share type is enabled', () => {
128131
const component = getComponent();
129132
expect(component.find('ShareType').length).toBeFalsy();
@@ -170,7 +173,7 @@ describe('<LocationShareMenu />', () => {
170173
});
171174

172175
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"]));
174177

175178
it('renders share type switch with own and pin drop options', () => {
176179
const component = getComponent();
@@ -205,7 +208,6 @@ describe('<LocationShareMenu />', () => {
205208
});
206209

207210
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
209211
const onFinished = jest.fn();
210212
const component = getComponent({ onFinished });
211213

@@ -224,7 +226,6 @@ describe('<LocationShareMenu />', () => {
224226
});
225227

226228
it('creates pin drop location share event on submission', () => {
227-
// feature_location_share_pin_drop is set to enabled by default mocking
228229
const onFinished = jest.fn();
229230
const component = getComponent({ onFinished });
230231

@@ -249,4 +250,40 @@ describe('<LocationShareMenu />', () => {
249250
}));
250251
});
251252
});
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+
});
252282
});
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

Comments
 (0)