Apply prettier formatting
This commit is contained in:
parent
1cac306093
commit
526645c791
1576 changed files with 65385 additions and 62478 deletions
|
@ -14,43 +14,43 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import React from "react";
|
||||
// eslint-disable-next-line deprecate/import
|
||||
import { mount, ReactWrapper } from 'enzyme';
|
||||
import { mocked } from 'jest-mock';
|
||||
import { RoomMember } from 'matrix-js-sdk/src/models/room-member';
|
||||
import { MatrixClient } from 'matrix-js-sdk/src/client';
|
||||
import { RelationType } from 'matrix-js-sdk/src/matrix';
|
||||
import { logger } from 'matrix-js-sdk/src/logger';
|
||||
import { M_ASSET, LocationAssetType } from 'matrix-js-sdk/src/@types/location';
|
||||
import { act } from 'react-dom/test-utils';
|
||||
import { mount, ReactWrapper } from "enzyme";
|
||||
import { mocked } from "jest-mock";
|
||||
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
|
||||
import { MatrixClient } from "matrix-js-sdk/src/client";
|
||||
import { RelationType } from "matrix-js-sdk/src/matrix";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { M_ASSET, LocationAssetType } from "matrix-js-sdk/src/@types/location";
|
||||
import { act } from "react-dom/test-utils";
|
||||
|
||||
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/shareLocation';
|
||||
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/shareLocation";
|
||||
import {
|
||||
findByTagAndTestId,
|
||||
findByTestId,
|
||||
flushPromisesWithFakeTimers,
|
||||
getMockClientWithEventEmitter,
|
||||
setupAsyncStoreWithClient,
|
||||
} from '../../../test-utils';
|
||||
import Modal from '../../../../src/Modal';
|
||||
import { DEFAULT_DURATION_MS } from '../../../../src/components/views/location/LiveDurationDropdown';
|
||||
import { OwnBeaconStore } from '../../../../src/stores/OwnBeaconStore';
|
||||
import { SettingLevel } from '../../../../src/settings/SettingLevel';
|
||||
import QuestionDialog from '../../../../src/components/views/dialogs/QuestionDialog';
|
||||
} from "../../../test-utils";
|
||||
import Modal from "../../../../src/Modal";
|
||||
import { DEFAULT_DURATION_MS } from "../../../../src/components/views/location/LiveDurationDropdown";
|
||||
import { OwnBeaconStore } from "../../../../src/stores/OwnBeaconStore";
|
||||
import { SettingLevel } from "../../../../src/settings/SettingLevel";
|
||||
import QuestionDialog from "../../../../src/components/views/dialogs/QuestionDialog";
|
||||
|
||||
jest.useFakeTimers();
|
||||
|
||||
jest.mock('../../../../src/utils/location/findMapStyleUrl', () => ({
|
||||
findMapStyleUrl: jest.fn().mockReturnValue('test'),
|
||||
jest.mock("../../../../src/utils/location/findMapStyleUrl", () => ({
|
||||
findMapStyleUrl: jest.fn().mockReturnValue("test"),
|
||||
}));
|
||||
|
||||
jest.mock('../../../../src/settings/SettingsStore', () => ({
|
||||
jest.mock("../../../../src/settings/SettingsStore", () => ({
|
||||
getValue: jest.fn(),
|
||||
setValue: jest.fn(),
|
||||
monitorSetting: jest.fn(),
|
||||
|
@ -58,44 +58,45 @@ jest.mock('../../../../src/settings/SettingsStore', () => ({
|
|||
unwatchSetting: jest.fn(),
|
||||
}));
|
||||
|
||||
jest.mock('../../../../src/stores/OwnProfileStore', () => ({
|
||||
jest.mock("../../../../src/stores/OwnProfileStore", () => ({
|
||||
OwnProfileStore: {
|
||||
instance: {
|
||||
displayName: 'Ernie',
|
||||
getHttpAvatarUrl: jest.fn().mockReturnValue('image.com/img'),
|
||||
displayName: "Ernie",
|
||||
getHttpAvatarUrl: jest.fn().mockReturnValue("image.com/img"),
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock('../../../../src/Modal', () => ({
|
||||
jest.mock("../../../../src/Modal", () => ({
|
||||
createDialog: jest.fn(),
|
||||
on: jest.fn(),
|
||||
off: jest.fn(),
|
||||
ModalManagerEvent: { Opened: "opened" },
|
||||
}));
|
||||
|
||||
describe('<LocationShareMenu />', () => {
|
||||
const userId = '@ernie:server.org';
|
||||
describe("<LocationShareMenu />", () => {
|
||||
const userId = "@ernie:server.org";
|
||||
const mockClient = getMockClientWithEventEmitter({
|
||||
getUserId: jest.fn().mockReturnValue(userId),
|
||||
getClientWellKnown: jest.fn().mockResolvedValue({
|
||||
map_style_url: 'maps.com',
|
||||
map_style_url: "maps.com",
|
||||
}),
|
||||
sendMessage: jest.fn(),
|
||||
unstable_createLiveBeacon: jest.fn().mockResolvedValue({ event_id: '1' }),
|
||||
unstable_setLiveBeacon: jest.fn().mockResolvedValue({ event_id: '1' }),
|
||||
unstable_createLiveBeacon: jest.fn().mockResolvedValue({ event_id: "1" }),
|
||||
unstable_setLiveBeacon: jest.fn().mockResolvedValue({ event_id: "1" }),
|
||||
getVisibleRooms: jest.fn().mockReturnValue([]),
|
||||
});
|
||||
|
||||
const defaultProps = {
|
||||
menuPosition: {
|
||||
top: 1, left: 1,
|
||||
top: 1,
|
||||
left: 1,
|
||||
chevronFace: ChevronFace.Bottom,
|
||||
},
|
||||
onFinished: jest.fn(),
|
||||
openMenu: jest.fn(),
|
||||
roomId: '!room:server.org',
|
||||
sender: new RoomMember('!room:server.org', userId),
|
||||
roomId: "!room:server.org",
|
||||
sender: new RoomMember("!room:server.org", userId),
|
||||
};
|
||||
|
||||
const position = {
|
||||
|
@ -105,7 +106,7 @@ describe('<LocationShareMenu />', () => {
|
|||
accuracy: 10,
|
||||
},
|
||||
timestamp: 1646305006802,
|
||||
type: 'geolocate',
|
||||
type: "geolocate",
|
||||
};
|
||||
|
||||
const makeOwnBeaconStore = async () => {
|
||||
|
@ -122,11 +123,11 @@ describe('<LocationShareMenu />', () => {
|
|||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
jest.spyOn(logger, 'error').mockRestore();
|
||||
jest.spyOn(logger, "error").mockRestore();
|
||||
mocked(SettingsStore).getValue.mockReturnValue(false);
|
||||
mockClient.sendMessage.mockClear();
|
||||
mockClient.unstable_createLiveBeacon.mockClear().mockResolvedValue({ event_id: '1' });
|
||||
jest.spyOn(MatrixClientPeg, 'get').mockReturnValue(mockClient as unknown as MatrixClient);
|
||||
mockClient.unstable_createLiveBeacon.mockClear().mockResolvedValue({ event_id: "1" });
|
||||
jest.spyOn(MatrixClientPeg, "get").mockReturnValue(mockClient as unknown as MatrixClient);
|
||||
mocked(Modal).createDialog.mockClear();
|
||||
|
||||
jest.clearAllMocks();
|
||||
|
@ -135,20 +136,20 @@ describe('<LocationShareMenu />', () => {
|
|||
});
|
||||
|
||||
const getShareTypeOption = (component: ReactWrapper, shareType: LocationShareType) =>
|
||||
findByTagAndTestId(component, `share-location-option-${shareType}`, 'button');
|
||||
findByTagAndTestId(component, `share-location-option-${shareType}`, "button");
|
||||
|
||||
const getBackButton = (component: ReactWrapper) =>
|
||||
findByTagAndTestId(component, 'share-dialog-buttons-back', 'button');
|
||||
findByTagAndTestId(component, "share-dialog-buttons-back", "button");
|
||||
|
||||
const getCancelButton = (component: ReactWrapper) =>
|
||||
findByTagAndTestId(component, 'share-dialog-buttons-cancel', 'button');
|
||||
findByTagAndTestId(component, "share-dialog-buttons-cancel", "button");
|
||||
|
||||
const getSubmitButton = (component: ReactWrapper) =>
|
||||
findByTagAndTestId(component, 'location-picker-submit-button', 'button');
|
||||
findByTagAndTestId(component, "location-picker-submit-button", "button");
|
||||
|
||||
const setLocation = (component: ReactWrapper) => {
|
||||
// set the location
|
||||
const locationPickerInstance = component.find('LocationPicker').instance();
|
||||
const locationPickerInstance = component.find("LocationPicker").instance();
|
||||
act(() => {
|
||||
// @ts-ignore
|
||||
locationPickerInstance.onGeolocate(position);
|
||||
|
@ -159,38 +160,38 @@ describe('<LocationShareMenu />', () => {
|
|||
|
||||
const setShareType = (component: ReactWrapper, shareType: LocationShareType) =>
|
||||
act(() => {
|
||||
getShareTypeOption(component, shareType).at(0).simulate('click');
|
||||
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(() => enableSettings([]));
|
||||
|
||||
it('renders own and live location options', () => {
|
||||
it("renders own and live location options", () => {
|
||||
const component = getComponent();
|
||||
expect(getShareTypeOption(component, LocationShareType.Own).length).toBe(1);
|
||||
expect(getShareTypeOption(component, LocationShareType.Live).length).toBe(1);
|
||||
});
|
||||
|
||||
it('renders back button from location picker screen', () => {
|
||||
it("renders back button from location picker screen", () => {
|
||||
const component = getComponent();
|
||||
setShareType(component, LocationShareType.Own);
|
||||
|
||||
expect(getBackButton(component).length).toBe(1);
|
||||
});
|
||||
|
||||
it('clicking cancel button from location picker closes dialog', () => {
|
||||
it("clicking cancel button from location picker closes dialog", () => {
|
||||
const onFinished = jest.fn();
|
||||
const component = getComponent({ onFinished });
|
||||
|
||||
act(() => {
|
||||
getCancelButton(component).at(0).simulate('click');
|
||||
getCancelButton(component).at(0).simulate("click");
|
||||
});
|
||||
|
||||
expect(onFinished).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('creates static own location share event on submission', () => {
|
||||
it("creates static own location share event on submission", () => {
|
||||
const onFinished = jest.fn();
|
||||
const component = getComponent({ onFinished });
|
||||
|
||||
|
@ -199,7 +200,7 @@ describe('<LocationShareMenu />', () => {
|
|||
setLocation(component);
|
||||
|
||||
act(() => {
|
||||
getSubmitButton(component).at(0).simulate('click');
|
||||
getSubmitButton(component).at(0).simulate("click");
|
||||
component.setProps({});
|
||||
});
|
||||
|
||||
|
@ -207,66 +208,68 @@ describe('<LocationShareMenu />', () => {
|
|||
const [messageRoomId, relation, messageBody] = mockClient.sendMessage.mock.calls[0];
|
||||
expect(messageRoomId).toEqual(defaultProps.roomId);
|
||||
expect(relation).toEqual(null);
|
||||
expect(messageBody).toEqual(expect.objectContaining({
|
||||
[M_ASSET.name]: {
|
||||
type: LocationAssetType.Self,
|
||||
},
|
||||
}));
|
||||
expect(messageBody).toEqual(
|
||||
expect.objectContaining({
|
||||
[M_ASSET.name]: {
|
||||
type: LocationAssetType.Self,
|
||||
},
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with pin drop share type enabled', () => {
|
||||
it('renders share type switch with own and pin drop options', () => {
|
||||
describe("with pin drop share type enabled", () => {
|
||||
it("renders share type switch with own and pin drop options", () => {
|
||||
const component = getComponent();
|
||||
expect(component.find('LocationPicker').length).toBe(0);
|
||||
expect(component.find("LocationPicker").length).toBe(0);
|
||||
|
||||
expect(getShareTypeOption(component, LocationShareType.Own).length).toBe(1);
|
||||
expect(getShareTypeOption(component, LocationShareType.Pin).length).toBe(1);
|
||||
});
|
||||
|
||||
it('does not render back button on share type screen', () => {
|
||||
it("does not render back button on share type screen", () => {
|
||||
const component = getComponent();
|
||||
expect(getBackButton(component).length).toBe(0);
|
||||
});
|
||||
|
||||
it('clicking cancel button from share type screen closes dialog', () => {
|
||||
it("clicking cancel button from share type screen closes dialog", () => {
|
||||
const onFinished = jest.fn();
|
||||
const component = getComponent({ onFinished });
|
||||
|
||||
act(() => {
|
||||
getCancelButton(component).at(0).simulate('click');
|
||||
getCancelButton(component).at(0).simulate("click");
|
||||
});
|
||||
|
||||
expect(onFinished).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('selecting own location share type advances to location picker', () => {
|
||||
it("selecting own location share type advances to location picker", () => {
|
||||
const component = getComponent();
|
||||
|
||||
setShareType(component, LocationShareType.Own);
|
||||
|
||||
expect(component.find('LocationPicker').length).toBe(1);
|
||||
expect(component.find("LocationPicker").length).toBe(1);
|
||||
});
|
||||
|
||||
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", () => {
|
||||
const onFinished = jest.fn();
|
||||
const component = getComponent({ onFinished });
|
||||
|
||||
// advance to location picker
|
||||
setShareType(component, LocationShareType.Own);
|
||||
|
||||
expect(component.find('LocationPicker').length).toBe(1);
|
||||
expect(component.find("LocationPicker").length).toBe(1);
|
||||
|
||||
act(() => {
|
||||
getBackButton(component).at(0).simulate('click');
|
||||
getBackButton(component).at(0).simulate("click");
|
||||
component.setProps({});
|
||||
});
|
||||
|
||||
// back to share type
|
||||
expect(component.find('ShareType').length).toBe(1);
|
||||
expect(component.find("ShareType").length).toBe(1);
|
||||
});
|
||||
|
||||
it('creates pin drop location share event on submission', () => {
|
||||
it("creates pin drop location share event on submission", () => {
|
||||
const onFinished = jest.fn();
|
||||
const component = getComponent({ onFinished });
|
||||
|
||||
|
@ -276,7 +279,7 @@ describe('<LocationShareMenu />', () => {
|
|||
setLocation(component);
|
||||
|
||||
act(() => {
|
||||
getSubmitButton(component).at(0).simulate('click');
|
||||
getSubmitButton(component).at(0).simulate("click");
|
||||
component.setProps({});
|
||||
});
|
||||
|
||||
|
@ -284,76 +287,81 @@ describe('<LocationShareMenu />', () => {
|
|||
const [messageRoomId, relation, messageBody] = mockClient.sendMessage.mock.calls[0];
|
||||
expect(messageRoomId).toEqual(defaultProps.roomId);
|
||||
expect(relation).toEqual(null);
|
||||
expect(messageBody).toEqual(expect.objectContaining({
|
||||
[M_ASSET.name]: {
|
||||
type: LocationAssetType.Pin,
|
||||
},
|
||||
}));
|
||||
expect(messageBody).toEqual(
|
||||
expect.objectContaining({
|
||||
[M_ASSET.name]: {
|
||||
type: LocationAssetType.Pin,
|
||||
},
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with live location disabled', () => {
|
||||
describe("with live location disabled", () => {
|
||||
beforeEach(() => enableSettings([]));
|
||||
|
||||
const getToggle = (component: ReactWrapper) =>
|
||||
findByTestId(component, 'enable-live-share-toggle').find('[role="switch"]').at(0);
|
||||
findByTestId(component, "enable-live-share-toggle").find('[role="switch"]').at(0);
|
||||
const getSubmitEnableButton = (component: ReactWrapper) =>
|
||||
findByTestId(component, 'enable-live-share-submit').at(0);
|
||||
findByTestId(component, "enable-live-share-submit").at(0);
|
||||
|
||||
it('goes to labs flag screen after live options is clicked', () => {
|
||||
it("goes to labs flag screen after live options is clicked", () => {
|
||||
const onFinished = jest.fn();
|
||||
const component = getComponent({ onFinished });
|
||||
|
||||
setShareType(component, LocationShareType.Live);
|
||||
|
||||
expect(findByTestId(component, 'location-picker-enable-live-share')).toMatchSnapshot();
|
||||
expect(findByTestId(component, "location-picker-enable-live-share")).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('disables OK button when labs flag is not enabled', () => {
|
||||
it("disables OK button when labs flag is not enabled", () => {
|
||||
const component = getComponent();
|
||||
|
||||
setShareType(component, LocationShareType.Live);
|
||||
|
||||
expect(getSubmitEnableButton(component).props()['disabled']).toBeTruthy();
|
||||
expect(getSubmitEnableButton(component).props()["disabled"]).toBeTruthy();
|
||||
});
|
||||
|
||||
it('enables OK button when labs flag is toggled to enabled', () => {
|
||||
it("enables OK button when labs flag is toggled to enabled", () => {
|
||||
const component = getComponent();
|
||||
|
||||
setShareType(component, LocationShareType.Live);
|
||||
|
||||
act(() => {
|
||||
getToggle(component).simulate('click');
|
||||
getToggle(component).simulate("click");
|
||||
component.setProps({});
|
||||
});
|
||||
expect(getSubmitEnableButton(component).props()['disabled']).toBeFalsy();
|
||||
expect(getSubmitEnableButton(component).props()["disabled"]).toBeFalsy();
|
||||
});
|
||||
|
||||
it('enables live share setting on ok button submit', () => {
|
||||
it("enables live share setting on ok button submit", () => {
|
||||
const component = getComponent();
|
||||
|
||||
setShareType(component, LocationShareType.Live);
|
||||
|
||||
act(() => {
|
||||
getToggle(component).simulate('click');
|
||||
getToggle(component).simulate("click");
|
||||
component.setProps({});
|
||||
});
|
||||
|
||||
act(() => {
|
||||
getSubmitEnableButton(component).simulate('click');
|
||||
getSubmitEnableButton(component).simulate("click");
|
||||
});
|
||||
|
||||
expect(SettingsStore.setValue).toHaveBeenCalledWith(
|
||||
'feature_location_share_live', undefined, SettingLevel.DEVICE, true,
|
||||
"feature_location_share_live",
|
||||
undefined,
|
||||
SettingLevel.DEVICE,
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
it('navigates to location picker when live share is enabled in settings store', () => {
|
||||
it("navigates to location picker when live share is enabled in settings store", () => {
|
||||
// @ts-ignore
|
||||
mocked(SettingsStore.watchSetting).mockImplementation((featureName, roomId, callback) => {
|
||||
callback(featureName, roomId, SettingLevel.DEVICE, '', '');
|
||||
callback(featureName, roomId, SettingLevel.DEVICE, "", "");
|
||||
window.setTimeout(() => {
|
||||
callback(featureName, roomId, SettingLevel.DEVICE, '', '');
|
||||
callback(featureName, roomId, SettingLevel.DEVICE, "", "");
|
||||
}, 1000);
|
||||
});
|
||||
mocked(SettingsStore.getValue).mockReturnValue(false);
|
||||
|
@ -362,7 +370,7 @@ describe('<LocationShareMenu />', () => {
|
|||
setShareType(component, LocationShareType.Live);
|
||||
|
||||
// we're on enable live share screen
|
||||
expect(findByTestId(component, 'location-picker-enable-live-share').length).toBeTruthy();
|
||||
expect(findByTestId(component, "location-picker-enable-live-share").length).toBeTruthy();
|
||||
|
||||
act(() => {
|
||||
mocked(SettingsStore.getValue).mockReturnValue(true);
|
||||
|
@ -373,24 +381,24 @@ describe('<LocationShareMenu />', () => {
|
|||
component.setProps({});
|
||||
|
||||
// advanced to location picker
|
||||
expect(component.find('LocationPicker').length).toBeTruthy();
|
||||
expect(component.find("LocationPicker").length).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Live location share', () => {
|
||||
describe("Live location share", () => {
|
||||
beforeEach(() => enableSettings(["feature_location_share_live"]));
|
||||
|
||||
it('does not display live location share option when composer has a relation', () => {
|
||||
it("does not display live location share option when composer has a relation", () => {
|
||||
const relation = {
|
||||
rel_type: RelationType.Thread,
|
||||
event_id: '12345',
|
||||
event_id: "12345",
|
||||
};
|
||||
const component = getComponent({ relation });
|
||||
|
||||
expect(getShareTypeOption(component, LocationShareType.Live).length).toBeFalsy();
|
||||
});
|
||||
|
||||
it('creates beacon info event on submission', async () => {
|
||||
it("creates beacon info event on submission", async () => {
|
||||
const onFinished = jest.fn();
|
||||
const component = getComponent({ onFinished });
|
||||
|
||||
|
@ -399,7 +407,7 @@ describe('<LocationShareMenu />', () => {
|
|||
setLocation(component);
|
||||
|
||||
act(() => {
|
||||
getSubmitButton(component).at(0).simulate('click');
|
||||
getSubmitButton(component).at(0).simulate("click");
|
||||
component.setProps({});
|
||||
});
|
||||
|
||||
|
@ -409,21 +417,23 @@ describe('<LocationShareMenu />', () => {
|
|||
expect(onFinished).toHaveBeenCalled();
|
||||
const [eventRoomId, eventContent] = mockClient.unstable_createLiveBeacon.mock.calls[0];
|
||||
expect(eventRoomId).toEqual(defaultProps.roomId);
|
||||
expect(eventContent).toEqual(expect.objectContaining({
|
||||
// default timeout
|
||||
timeout: DEFAULT_DURATION_MS,
|
||||
description: `Ernie's live location`,
|
||||
live: true,
|
||||
[M_ASSET.name]: {
|
||||
type: LocationAssetType.Self,
|
||||
},
|
||||
}));
|
||||
expect(eventContent).toEqual(
|
||||
expect.objectContaining({
|
||||
// default timeout
|
||||
timeout: DEFAULT_DURATION_MS,
|
||||
description: `Ernie's live location`,
|
||||
live: true,
|
||||
[M_ASSET.name]: {
|
||||
type: LocationAssetType.Self,
|
||||
},
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('opens error dialog when beacon creation fails', async () => {
|
||||
it("opens error dialog when beacon creation fails", async () => {
|
||||
// stub logger to keep console clean from expected error
|
||||
const logSpy = jest.spyOn(logger, 'error').mockReturnValue(undefined);
|
||||
const error = new Error('oh no');
|
||||
const logSpy = jest.spyOn(logger, "error").mockReturnValue(undefined);
|
||||
const error = new Error("oh no");
|
||||
mockClient.unstable_createLiveBeacon.mockRejectedValue(error);
|
||||
const component = getComponent();
|
||||
|
||||
|
@ -432,7 +442,7 @@ describe('<LocationShareMenu />', () => {
|
|||
setLocation(component);
|
||||
|
||||
act(() => {
|
||||
getSubmitButton(component).at(0).simulate('click');
|
||||
getSubmitButton(component).at(0).simulate("click");
|
||||
component.setProps({});
|
||||
});
|
||||
|
||||
|
@ -441,18 +451,21 @@ describe('<LocationShareMenu />', () => {
|
|||
await flushPromisesWithFakeTimers();
|
||||
|
||||
expect(logSpy).toHaveBeenCalledWith("We couldn't start sharing your live location", error);
|
||||
expect(mocked(Modal).createDialog).toHaveBeenCalledWith(QuestionDialog, expect.objectContaining({
|
||||
button: 'Try again',
|
||||
description: 'Element could not send your location. Please try again later.',
|
||||
title: `We couldn't send your location`,
|
||||
cancelButton: 'Cancel',
|
||||
}));
|
||||
expect(mocked(Modal).createDialog).toHaveBeenCalledWith(
|
||||
QuestionDialog,
|
||||
expect.objectContaining({
|
||||
button: "Try again",
|
||||
description: "Element could not send your location. Please try again later.",
|
||||
title: `We couldn't send your location`,
|
||||
cancelButton: "Cancel",
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('opens error dialog when beacon creation fails with permission error', async () => {
|
||||
it("opens error dialog when beacon creation fails with permission error", async () => {
|
||||
// stub logger to keep console clean from expected error
|
||||
const logSpy = jest.spyOn(logger, 'error').mockReturnValue(undefined);
|
||||
const error = { errcode: 'M_FORBIDDEN' } as unknown as Error;
|
||||
const logSpy = jest.spyOn(logger, "error").mockReturnValue(undefined);
|
||||
const error = { errcode: "M_FORBIDDEN" } as unknown as Error;
|
||||
mockClient.unstable_createLiveBeacon.mockRejectedValue(error);
|
||||
const component = getComponent();
|
||||
|
||||
|
@ -461,7 +474,7 @@ describe('<LocationShareMenu />', () => {
|
|||
setLocation(component);
|
||||
|
||||
act(() => {
|
||||
getSubmitButton(component).at(0).simulate('click');
|
||||
getSubmitButton(component).at(0).simulate("click");
|
||||
component.setProps({});
|
||||
});
|
||||
|
||||
|
@ -470,12 +483,15 @@ describe('<LocationShareMenu />', () => {
|
|||
await flushPromisesWithFakeTimers();
|
||||
|
||||
expect(logSpy).toHaveBeenCalledWith("Insufficient permissions to start sharing your live location", error);
|
||||
expect(mocked(Modal).createDialog).toHaveBeenCalledWith(QuestionDialog, expect.objectContaining({
|
||||
button: 'OK',
|
||||
description: 'You need to have the right permissions in order to share locations in this room.',
|
||||
title: `You don't have permission to share locations`,
|
||||
hasCancelButton: false,
|
||||
}));
|
||||
expect(mocked(Modal).createDialog).toHaveBeenCalledWith(
|
||||
QuestionDialog,
|
||||
expect.objectContaining({
|
||||
button: "OK",
|
||||
description: "You need to have the right permissions in order to share locations in this room.",
|
||||
title: `You don't have permission to share locations`,
|
||||
hasCancelButton: false,
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue