Show "Share my location" button (#8054)
parent
2778fd135e
commit
e1fdff46f5
|
@ -36,14 +36,17 @@ type Props = Omit<ILocationPickerProps, 'onChoose' | 'shareType'> & {
|
||||||
};
|
};
|
||||||
|
|
||||||
const getEnabledShareTypes = (): LocationShareType[] => {
|
const getEnabledShareTypes = (): LocationShareType[] => {
|
||||||
const isPinDropLocationShareEnabled = SettingsStore.getValue("feature_location_share_pin_drop");
|
const enabledShareTypes = [LocationShareType.Own];
|
||||||
|
|
||||||
if (isPinDropLocationShareEnabled) {
|
if (SettingsStore.getValue("feature_location_share_live")) {
|
||||||
return [LocationShareType.Own, LocationShareType.Pin];
|
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> = ({
|
const LocationShareMenu: React.FC<Props> = ({
|
||||||
|
|
|
@ -15,7 +15,7 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { mount } from 'enzyme';
|
import { mount, ReactWrapper } from 'enzyme';
|
||||||
import { RoomMember } from 'matrix-js-sdk/src/models/room-member';
|
import { RoomMember } from 'matrix-js-sdk/src/models/room-member';
|
||||||
import { MatrixClient } from 'matrix-js-sdk/src/client';
|
import { MatrixClient } from 'matrix-js-sdk/src/client';
|
||||||
import { mocked } from 'jest-mock';
|
import { mocked } from 'jest-mock';
|
||||||
|
@ -90,21 +90,24 @@ describe('<LocationShareMenu />', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mocked(SettingsStore).getValue.mockImplementation(
|
mocked(SettingsStore).getValue.mockReturnValue(false);
|
||||||
(settingName) => settingName === "feature_location_share_pin_drop",
|
|
||||||
);
|
|
||||||
|
|
||||||
mockClient.sendMessage.mockClear();
|
mockClient.sendMessage.mockClear();
|
||||||
|
|
||||||
jest.spyOn(MatrixClientPeg, 'get').mockReturnValue(mockClient as unknown as MatrixClient);
|
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}`);
|
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 getBackButton = (component: ReactWrapper) =>
|
||||||
const getSubmitButton = component => findByTestId(component, 'location-picker-submit-button');
|
findByTestId(component, 'share-dialog-buttons-back');
|
||||||
const setLocation = (component) => {
|
|
||||||
|
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
|
// set the location
|
||||||
const locationPickerInstance = component.find('LocationPicker').instance();
|
const locationPickerInstance = component.find('LocationPicker').instance();
|
||||||
act(() => {
|
act(() => {
|
||||||
|
@ -114,15 +117,15 @@ describe('<LocationShareMenu />', () => {
|
||||||
component.setProps({});
|
component.setProps({});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
const setShareType = (component, shareType) => act(() => {
|
|
||||||
getShareTypeOption(component, shareType).at(0).simulate('click');
|
const setShareType = (component: ReactWrapper, shareType: LocationShareType) =>
|
||||||
component.setProps({});
|
act(() => {
|
||||||
});
|
getShareTypeOption(component, shareType).at(0).simulate('click');
|
||||||
|
component.setProps({});
|
||||||
|
});
|
||||||
|
|
||||||
describe('when only Own share type is enabled', () => {
|
describe('when only Own share type is enabled', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => enableSettings([]));
|
||||||
mocked(SettingsStore).getValue.mockReturnValue(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('renders location picker when only Own share type is enabled', () => {
|
it('renders location picker when only Own share type is enabled', () => {
|
||||||
const component = getComponent();
|
const component = getComponent();
|
||||||
|
@ -170,7 +173,7 @@ describe('<LocationShareMenu />', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with pin drop share type enabled', () => {
|
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', () => {
|
it('renders share type switch with own and pin drop options', () => {
|
||||||
const component = getComponent();
|
const component = getComponent();
|
||||||
|
@ -205,7 +208,6 @@ describe('<LocationShareMenu />', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('clicking back button from location picker screen goes back to share screen', () => {
|
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 onFinished = jest.fn();
|
||||||
const component = getComponent({ onFinished });
|
const component = getComponent({ onFinished });
|
||||||
|
|
||||||
|
@ -224,7 +226,6 @@ describe('<LocationShareMenu />', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('creates pin drop location share event on submission', () => {
|
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 onFinished = jest.fn();
|
||||||
const component = getComponent({ onFinished });
|
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