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

Commit cbf5fbf

Browse files
authored
Enable the live location share button (#8056)
1 parent e1fdff4 commit cbf5fbf

File tree

3 files changed

+29
-23
lines changed

3 files changed

+29
-23
lines changed

src/components/views/location/ShareType.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ const ShareTypeOption: React.FC<ShareTypeOptionProps> = ({
5656
element='button'
5757
className='mx_ShareType_option'
5858
onClick={onClick}
59-
// not yet implemented
60-
disabled={shareType === LocationShareType.Live}
6159
{...rest}>
6260
{ shareType === LocationShareType.Own && <UserAvatar /> }
6361
{ shareType === LocationShareType.Pin &&

test/components/views/location/LocationShareMenu-test.tsx

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { ChevronFace } from '../../../../src/components/structures/ContextMenu';
2929
import SettingsStore from '../../../../src/settings/SettingsStore';
3030
import { MatrixClientPeg } from '../../../../src/MatrixClientPeg';
3131
import { LocationShareType } from '../../../../src/components/views/location/shareLocation';
32-
import { findByTestId } from '../../../test-utils';
32+
import { findByTagAndTestId } from '../../../test-utils';
3333

3434
jest.mock('../../../../src/components/views/location/findMapStyleUrl', () => ({
3535
findMapStyleUrl: jest.fn().mockReturnValue('test'),
@@ -96,16 +96,16 @@ describe('<LocationShareMenu />', () => {
9696
});
9797

9898
const getShareTypeOption = (component: ReactWrapper, shareType: LocationShareType) =>
99-
findByTestId(component, `share-location-option-${shareType}`);
99+
findByTagAndTestId(component, `share-location-option-${shareType}`, 'button');
100100

101101
const getBackButton = (component: ReactWrapper) =>
102-
findByTestId(component, 'share-dialog-buttons-back');
102+
findByTagAndTestId(component, 'share-dialog-buttons-back', 'button');
103103

104104
const getCancelButton = (component: ReactWrapper) =>
105-
findByTestId(component, 'share-dialog-buttons-cancel');
105+
findByTagAndTestId(component, 'share-dialog-buttons-cancel', 'button');
106106

107107
const getSubmitButton = (component: ReactWrapper) =>
108-
findByTestId(component, 'location-picker-submit-button');
108+
findByTagAndTestId(component, 'location-picker-submit-button', 'button');
109109

110110
const setLocation = (component: ReactWrapper) => {
111111
// set the location
@@ -129,13 +129,13 @@ describe('<LocationShareMenu />', () => {
129129

130130
it('renders location picker when only Own share type is enabled', () => {
131131
const component = getComponent();
132-
expect(component.find('ShareType').length).toBeFalsy();
133-
expect(component.find('LocationPicker').length).toBeTruthy();
132+
expect(component.find('ShareType').length).toBe(0);
133+
expect(component.find('LocationPicker').length).toBe(1);
134134
});
135135

136136
it('does not render back button when only Own share type is enabled', () => {
137137
const component = getComponent();
138-
expect(getBackButton(component).length).toBeFalsy();
138+
expect(getBackButton(component).length).toBe(0);
139139
});
140140

141141
it('clicking cancel button from location picker closes dialog', () => {
@@ -177,15 +177,15 @@ describe('<LocationShareMenu />', () => {
177177

178178
it('renders share type switch with own and pin drop options', () => {
179179
const component = getComponent();
180-
expect(component.find('LocationPicker').length).toBeFalsy();
180+
expect(component.find('LocationPicker').length).toBe(0);
181181

182-
expect(getShareTypeOption(component, LocationShareType.Own).length).toBeTruthy();
183-
expect(getShareTypeOption(component, LocationShareType.Pin).length).toBeTruthy();
182+
expect(getShareTypeOption(component, LocationShareType.Own).length).toBe(1);
183+
expect(getShareTypeOption(component, LocationShareType.Pin).length).toBe(1);
184184
});
185185

186186
it('does not render back button on share type screen', () => {
187187
const component = getComponent();
188-
expect(getBackButton(component).length).toBeFalsy();
188+
expect(getBackButton(component).length).toBe(0);
189189
});
190190

191191
it('clicking cancel button from share type screen closes dialog', () => {
@@ -204,7 +204,7 @@ describe('<LocationShareMenu />', () => {
204204

205205
setShareType(component, LocationShareType.Own);
206206

207-
expect(component.find('LocationPicker').length).toBeTruthy();
207+
expect(component.find('LocationPicker').length).toBe(1);
208208
});
209209

210210
it('clicking back button from location picker screen goes back to share screen', () => {
@@ -214,15 +214,15 @@ describe('<LocationShareMenu />', () => {
214214
// advance to location picker
215215
setShareType(component, LocationShareType.Own);
216216

217-
expect(component.find('LocationPicker').length).toBeTruthy();
217+
expect(component.find('LocationPicker').length).toBe(1);
218218

219219
act(() => {
220220
getBackButton(component).at(0).simulate('click');
221221
component.setProps({});
222222
});
223223

224224
// back to share type
225-
expect(component.find('ShareType').length).toBeTruthy();
225+
expect(component.find('ShareType').length).toBe(1);
226226
});
227227

228228
it('creates pin drop location share event on submission', () => {
@@ -263,20 +263,22 @@ describe('<LocationShareMenu />', () => {
263263
const component = getComponent();
264264

265265
// The the Location picker is not visible yet
266-
expect(component.find('LocationPicker').length).toBeFalsy();
266+
expect(component.find('LocationPicker').length).toBe(0);
267267

268268
// And all 3 buttons are visible on the LocationShare dialog
269269
expect(
270270
getShareTypeOption(component, LocationShareType.Own).length,
271-
).toBeTruthy();
271+
).toBe(1);
272272

273273
expect(
274274
getShareTypeOption(component, LocationShareType.Pin).length,
275-
).toBeTruthy();
275+
).toBe(1);
276276

277-
expect(
278-
getShareTypeOption(component, LocationShareType.Live).length,
279-
).toBeTruthy();
277+
const liveButton = getShareTypeOption(component, LocationShareType.Live);
278+
expect(liveButton.length).toBe(1);
279+
280+
// The live location button is enabled
281+
expect(liveButton.hasClass("mx_AccessibleButton_disabled")).toBeFalsy();
280282
});
281283
});
282284
});

test/test-utils/utilities.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ const findByAttr = (attr: string) => (component: ReactWrapper, value: string) =>
2323
export const findByTestId = findByAttr('data-test-id');
2424
export const findById = findByAttr('id');
2525

26+
const findByTagAndAttr = (attr: string) =>
27+
(component: ReactWrapper, value: string, tag: string) =>
28+
component.find(`${tag}[${attr}="${value}"]`);
29+
30+
export const findByTagAndTestId = findByTagAndAttr('data-test-id');
31+
2632
export const flushPromises = async () => await new Promise(resolve => setTimeout(resolve));
2733

2834
/**

0 commit comments

Comments
 (0)