mirror of https://github.com/vector-im/riot-web
Show "Share my location" button (#8054)
parent
2778fd135e
commit
e1fdff46f5
|
@ -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> = ({
|
||||
|
|
|
@ -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('<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(() => {
|
||||
|
@ -114,15 +117,15 @@ describe('<LocationShareMenu />', () => {
|
|||
component.setProps({});
|
||||
});
|
||||
};
|
||||
const setShareType = (component, shareType) => act(() => {
|
||||
getShareTypeOption(component, shareType).at(0).simulate('click');
|
||||
component.setProps({});
|
||||
});
|
||||
|
||||
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(() => {
|
||||
mocked(SettingsStore).getValue.mockReturnValue(false);
|
||||
});
|
||||
beforeEach(() => enableSettings([]));
|
||||
|
||||
it('renders location picker when only Own share type is enabled', () => {
|
||||
const component = getComponent();
|
||||
|
@ -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();
|
||||
|
@ -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 });
|
||||
|
||||
|
@ -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 });
|
||||
|
||||
|
@ -249,4 +250,40 @@ 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', () => {
|
||||
// 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),
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue