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

Show "Share my location" button #8054

Merged
merged 6 commits into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/components/views/location/LocationShareMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,17 @@ type Props = Omit<ILocationPickerProps, 'onChoose' | 'shareType'> & {
};

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<Props> = ({
Expand Down
102 changes: 81 additions & 21 deletions test/components/views/location/LocationShareMenu-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -90,21 +90,24 @@ describe('<LocationShareMenu />', () => {
});

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(() => {
Expand All @@ -114,16 +117,16 @@ describe('<LocationShareMenu />', () => {
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();
Expand Down Expand Up @@ -170,7 +173,7 @@ describe('<LocationShareMenu />', () => {
});

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();
Expand Down Expand Up @@ -205,7 +208,6 @@ describe('<LocationShareMenu />', () => {
});

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 });

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

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 });

Expand All @@ -249,4 +250,63 @@ describe('<LocationShareMenu />', () => {
}));
});
});

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', () => {
const component = getComponent();

expect(
getShareTypeOption(component, LocationShareType.Own).length,
).toBeTruthy();

expect(
getShareTypeOption(component, LocationShareType.Pin).length,
).toBeTruthy();

expect(
getShareTypeOption(component, LocationShareType.Live).length,
).toBeTruthy();
});
});

describe('with live location and pin drop enabled', () => {
andybalaam marked this conversation as resolved.
Show resolved Hide resolved
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),
);
}