= ({
+ setShareType, enabledShareTypes,
+}) => {
+ const labels = {
+ [LocationShareType.Own]: _t('My current location'),
+ [LocationShareType.Live]: _t('My live location'),
+ [LocationShareType.Pin]: _t('Drop a Pin'),
+ };
+ return
+
+ { _t("What location type do you want to share?") }
+ { enabledShareTypes.map((type) =>
+ setShareType(type)}
+ label={labels[type]}
+ shareType={type}
+ data-test-id={`share-location-option-${type}`}
+ />,
+ ) }
+
;
+};
+
+export default ShareType;
diff --git a/src/components/views/location/shareLocation.ts b/src/components/views/location/shareLocation.ts
index e7261230d0..90733810b3 100644
--- a/src/components/views/location/shareLocation.ts
+++ b/src/components/views/location/shareLocation.ts
@@ -1,4 +1,3 @@
-
/*
Copyright 2022 The Matrix.org Foundation C.I.C.
diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json
index 8c0f80e6fe..246658d5c3 100644
--- a/src/i18n/strings/en_EN.json
+++ b/src/i18n/strings/en_EN.json
@@ -2179,6 +2179,10 @@
"Unknown error fetching location. Please try again later.": "Unknown error fetching location. Please try again later.",
"We couldn’t send your location": "We couldn’t send your location",
"Element could not send your location. Please try again later.": "Element could not send your location. Please try again later.",
+ "My current location": "My current location",
+ "My live location": "My live location",
+ "Drop a Pin": "Drop a Pin",
+ "What location type do you want to share?": "What location type do you want to share?",
"Failed to load group members": "Failed to load group members",
"Filter community members": "Filter community members",
"Are you sure you want to remove '%(roomName)s' from %(groupId)s?": "Are you sure you want to remove '%(roomName)s' from %(groupId)s?",
diff --git a/test/components/views/location/LocationShareMenu-test.tsx b/test/components/views/location/LocationShareMenu-test.tsx
index fdf6b42158..7607f6ef55 100644
--- a/test/components/views/location/LocationShareMenu-test.tsx
+++ b/test/components/views/location/LocationShareMenu-test.tsx
@@ -17,15 +17,46 @@ limitations under the License.
import React from 'react';
import { mount } 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';
+import { act } from 'react-dom/test-utils';
import '../../../skinned-sdk';
import LocationShareMenu from '../../../../src/components/views/location/LocationShareMenu';
import MatrixClientContext from '../../../../src/contexts/MatrixClientContext';
import { ChevronFace } from '../../../../src/components/structures/ContextMenu';
+import SettingsStore from '../../../../src/settings/SettingsStore';
+import { MatrixClientPeg } from '../../../../src/MatrixClientPeg';
+import { LocationShareType } from '../../../../src/components/views/location/ShareType';
+import { findByTestId } from '../../../test-utils';
+
+jest.mock('../../../../src/components/views/messages/MLocationBody', () => ({
+ findMapStyleUrl: jest.fn().mockReturnValue('test'),
+}));
+
+jest.mock('../../../../src/settings/SettingsStore', () => ({
+ getValue: jest.fn(),
+ monitorSetting: jest.fn(),
+}));
+
+jest.mock('../../../../src/stores/OwnProfileStore', () => ({
+ OwnProfileStore: {
+ instance: {
+ displayName: 'Ernie',
+ getHttpAvatarUrl: jest.fn().mockReturnValue('image.com/img'),
+ },
+ },
+}));
describe('', () => {
+ const userId = '@ernie:server.org';
const mockClient = {
on: jest.fn(),
+ removeListener: jest.fn(),
+ getUserId: jest.fn().mockReturnValue(userId),
+ getClientWellKnown: jest.fn().mockResolvedValue({
+ map_style_url: 'maps.com',
+ }),
};
const defaultProps = {
@@ -36,7 +67,7 @@ describe('', () => {
onFinished: jest.fn(),
openMenu: jest.fn(),
roomId: '!room:server.org',
- sender: { id: '@ernie:server.org' } as unknown as RoomMember,
+ sender: new RoomMember('!room:server.org', userId),
};
const getComponent = (props = {}) =>
mount(, {
@@ -44,8 +75,43 @@ describe('', () => {
wrappingComponentProps: { value: mockClient },
});
- it('renders', () => {
+ beforeEach(() => {
+ mocked(SettingsStore).getValue.mockImplementation(
+ (settingName) => settingName === "feature_location_share_pin_drop",
+ );
+
+ jest.spyOn(MatrixClientPeg, 'get').mockReturnValue(mockClient as unknown as MatrixClient);
+ });
+
+ const getShareTypeOption = (component, shareType: LocationShareType) =>
+ findByTestId(component, `share-location-option-${shareType}`);
+
+ it('renders location picker when only Own share type is enabled', () => {
+ mocked(SettingsStore).getValue.mockReturnValue(false);
const component = getComponent();
- expect(component).toMatchSnapshot();
+ expect(component.find('ShareType').length).toBeFalsy();
+ expect(component.find('LocationPicker').length).toBeTruthy();
+ });
+
+ it('renders share type switch with own and pin drop options when enabled', () => {
+ // feature_location_share_pin_drop is set to enabled by default mocking
+ const component = getComponent();
+ expect(component.find('LocationPicker').length).toBeFalsy();
+
+ expect(getShareTypeOption(component, LocationShareType.Own).length).toBeTruthy();
+ expect(getShareTypeOption(component, LocationShareType.Pin).length).toBeTruthy();
+ });
+
+ it('selecting own location share type advances to location picker', () => {
+ // feature_location_share_pin_drop is set to enabled by default mocking
+ const component = getComponent();
+
+ act(() => {
+ getShareTypeOption(component, LocationShareType.Own).at(0).simulate('click');
+ });
+
+ component.setProps({});
+
+ expect(component.find('LocationPicker').length).toBeTruthy();
});
});
diff --git a/test/components/views/location/__snapshots__/LocationShareMenu-test.tsx.snap b/test/components/views/location/__snapshots__/LocationShareMenu-test.tsx.snap
deleted file mode 100644
index 130496e668..0000000000
--- a/test/components/views/location/__snapshots__/LocationShareMenu-test.tsx.snap
+++ /dev/null
@@ -1,289 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[` renders 1`] = `
-
-
-
-
-
-`;