diff --git a/src/components/views/location/LocationShareMenu.tsx b/src/components/views/location/LocationShareMenu.tsx index 40adca86ef0..414bcad9a48 100644 --- a/src/components/views/location/LocationShareMenu.tsx +++ b/src/components/views/location/LocationShareMenu.tsx @@ -36,14 +36,17 @@ type Props = Omit & { }; const getEnabledShareTypes = (): LocationShareType[] => { - const isPinDropLocationShareEnabled = SettingsStore.getValue("feature_location_share_pin_drop"); + const enabledShareTypes = [LocationShareType.Own]; - if (isPinDropLocationShareEnabled) { - return [LocationShareType.Own, LocationShareType.Pin]; + if (SettingsStore.getValue("feature_location_share_live")) { + enabledShareTypes.push(LocationShareType.Live); } - return [ - LocationShareType.Own, - ]; + + if (SettingsStore.getValue("feature_location_share_pin_drop")) { + enabledShareTypes.push(LocationShareType.Pin); + } + + return enabledShareTypes; }; const LocationShareMenu: React.FC = ({ diff --git a/test/components/views/location/LocationShareMenu-test.tsx b/test/components/views/location/LocationShareMenu-test.tsx index 6083c746fca..57863800503 100644 --- a/test/components/views/location/LocationShareMenu-test.tsx +++ b/test/components/views/location/LocationShareMenu-test.tsx @@ -15,7 +15,7 @@ limitations under the License. */ import React from 'react'; -import { mount } from 'enzyme'; +import { mount, ReactWrapper } from 'enzyme'; import { RoomMember } from 'matrix-js-sdk/src/models/room-member'; import { MatrixClient } from 'matrix-js-sdk/src/client'; import { mocked } from 'jest-mock'; @@ -90,21 +90,24 @@ describe('', () => { }); beforeEach(() => { - mocked(SettingsStore).getValue.mockImplementation( - (settingName) => settingName === "feature_location_share_pin_drop", - ); - + mocked(SettingsStore).getValue.mockReturnValue(false); mockClient.sendMessage.mockClear(); - jest.spyOn(MatrixClientPeg, 'get').mockReturnValue(mockClient as unknown as MatrixClient); }); - const getShareTypeOption = (component, shareType: LocationShareType) => + const getShareTypeOption = (component: ReactWrapper, shareType: LocationShareType) => findByTestId(component, `share-location-option-${shareType}`); - const getBackButton = component => findByTestId(component, 'share-dialog-buttons-back'); - const getCancelButton = component => findByTestId(component, 'share-dialog-buttons-cancel'); - const getSubmitButton = component => findByTestId(component, 'location-picker-submit-button'); - const setLocation = (component) => { + + const getBackButton = (component: ReactWrapper) => + findByTestId(component, 'share-dialog-buttons-back'); + + const getCancelButton = (component: ReactWrapper) => + findByTestId(component, 'share-dialog-buttons-cancel'); + + const getSubmitButton = (component: ReactWrapper) => + findByTestId(component, 'location-picker-submit-button'); + + const setLocation = (component: ReactWrapper) => { // set the location const locationPickerInstance = component.find('LocationPicker').instance(); act(() => { @@ -114,16 +117,16 @@ describe('', () => { component.setProps({}); }); }; - const setShareType = (component, shareType) => act(() => { - getShareTypeOption(component, shareType).at(0).simulate('click'); - component.setProps({}); - }); - describe('when only Own share type is enabled', () => { - beforeEach(() => { - mocked(SettingsStore).getValue.mockReturnValue(false); + const setShareType = (component: ReactWrapper, shareType: LocationShareType) => + act(() => { + getShareTypeOption(component, shareType).at(0).simulate('click'); + component.setProps({}); }); + describe('when only Own share type is enabled', () => { + beforeEach(() => enableSettings([])); + it('renders location picker when only Own share type is enabled', () => { const component = getComponent(); expect(component.find('ShareType').length).toBeFalsy(); @@ -170,7 +173,7 @@ describe('', () => { }); describe('with pin drop share type enabled', () => { - // feature_location_share_pin_drop is set to enabled by default mocking + beforeEach(() => enableSettings(["feature_location_share_pin_drop"])); it('renders share type switch with own and pin drop options', () => { const component = getComponent(); @@ -205,7 +208,6 @@ describe('', () => { }); it('clicking back button from location picker screen goes back to share screen', () => { - // feature_location_share_pin_drop is set to enabled by default mocking const onFinished = jest.fn(); const component = getComponent({ onFinished }); @@ -224,7 +226,6 @@ describe('', () => { }); it('creates pin drop location share event on submission', () => { - // feature_location_share_pin_drop is set to enabled by default mocking const onFinished = jest.fn(); const component = getComponent({ onFinished }); @@ -249,4 +250,40 @@ describe('', () => { })); }); }); + + describe('with live location and pin drop enabled', () => { + beforeEach(() => enableSettings([ + "feature_location_share_pin_drop", + "feature_location_share_live", + ])); + + it('renders share type switch with all 3 options', () => { + // Given pin and live feature flags are enabled + // When I click Location + const component = getComponent(); + + // The the Location picker is not visible yet + expect(component.find('LocationPicker').length).toBeFalsy(); + + // And all 3 buttons are visible on the LocationShare dialog + expect( + getShareTypeOption(component, LocationShareType.Own).length, + ).toBeTruthy(); + + expect( + getShareTypeOption(component, LocationShareType.Pin).length, + ).toBeTruthy(); + + expect( + getShareTypeOption(component, LocationShareType.Live).length, + ).toBeTruthy(); + }); + }); }); + +function enableSettings(settings: string[]) { + mocked(SettingsStore).getValue.mockReturnValue(false); + mocked(SettingsStore).getValue.mockImplementation( + (settingName: string) => settings.includes(settingName), + ); +}