2022-03-22 13:57:12 +00:00
|
|
|
/*
|
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
import React from "react";
|
|
|
|
import { act } from "react-dom/test-utils";
|
2022-08-02 13:10:43 +00:00
|
|
|
// eslint-disable-next-line deprecate/import
|
2022-12-12 11:24:14 +00:00
|
|
|
import { mount } from "enzyme";
|
|
|
|
import { Room, Beacon, BeaconEvent, getBeaconInfoIdentifier } from "matrix-js-sdk/src/matrix";
|
|
|
|
import { logger } from "matrix-js-sdk/src/logger";
|
2022-03-22 13:57:12 +00:00
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
import RoomLiveShareWarning from "../../../../src/components/views/beacon/RoomLiveShareWarning";
|
|
|
|
import { OwnBeaconStore, OwnBeaconStoreEvent } from "../../../../src/stores/OwnBeaconStore";
|
2022-03-22 13:57:12 +00:00
|
|
|
import {
|
2022-03-28 10:48:38 +00:00
|
|
|
advanceDateAndTime,
|
2022-03-22 13:57:12 +00:00
|
|
|
findByTestId,
|
2022-03-30 12:31:19 +00:00
|
|
|
flushPromisesWithFakeTimers,
|
2022-03-22 13:57:12 +00:00
|
|
|
getMockClientWithEventEmitter,
|
|
|
|
makeBeaconInfoEvent,
|
2022-03-28 10:48:38 +00:00
|
|
|
mockGeolocation,
|
2022-03-22 13:57:12 +00:00
|
|
|
resetAsyncStoreWithClient,
|
|
|
|
setupAsyncStoreWithClient,
|
2022-12-12 11:24:14 +00:00
|
|
|
} from "../../../test-utils";
|
|
|
|
import defaultDispatcher from "../../../../src/dispatcher/dispatcher";
|
|
|
|
import { Action } from "../../../../src/dispatcher/actions";
|
2022-03-22 13:57:12 +00:00
|
|
|
|
|
|
|
jest.useFakeTimers();
|
2022-12-12 11:24:14 +00:00
|
|
|
describe("<RoomLiveShareWarning />", () => {
|
|
|
|
const aliceId = "@alice:server.org";
|
|
|
|
const room1Id = "$room1:server.org";
|
|
|
|
const room2Id = "$room2:server.org";
|
|
|
|
const room3Id = "$room3:server.org";
|
2022-03-22 13:57:12 +00:00
|
|
|
const mockClient = getMockClientWithEventEmitter({
|
|
|
|
getVisibleRooms: jest.fn().mockReturnValue([]),
|
|
|
|
getUserId: jest.fn().mockReturnValue(aliceId),
|
2022-12-12 11:24:14 +00:00
|
|
|
unstable_setLiveBeacon: jest.fn().mockResolvedValue({ event_id: "1" }),
|
2022-03-28 10:48:38 +00:00
|
|
|
sendEvent: jest.fn(),
|
2022-03-22 13:57:12 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// 14.03.2022 16:15
|
|
|
|
const now = 1647270879403;
|
2022-03-23 10:12:58 +00:00
|
|
|
const MINUTE_MS = 60000;
|
2022-03-22 13:57:12 +00:00
|
|
|
const HOUR_MS = 3600000;
|
|
|
|
// mock the date so events are stable for snapshots etc
|
2022-12-12 11:24:14 +00:00
|
|
|
jest.spyOn(global.Date, "now").mockReturnValue(now);
|
|
|
|
const room1Beacon1 = makeBeaconInfoEvent(
|
|
|
|
aliceId,
|
|
|
|
room1Id,
|
|
|
|
{
|
|
|
|
isLive: true,
|
|
|
|
timeout: HOUR_MS,
|
|
|
|
},
|
|
|
|
"$0",
|
|
|
|
);
|
|
|
|
const room2Beacon1 = makeBeaconInfoEvent(aliceId, room2Id, { isLive: true, timeout: HOUR_MS }, "$1");
|
|
|
|
const room2Beacon2 = makeBeaconInfoEvent(aliceId, room2Id, { isLive: true, timeout: HOUR_MS * 12 }, "$2");
|
|
|
|
const room3Beacon1 = makeBeaconInfoEvent(aliceId, room3Id, { isLive: true, timeout: HOUR_MS }, "$3");
|
2022-03-22 13:57:12 +00:00
|
|
|
|
|
|
|
// make fresh rooms every time
|
|
|
|
// as we update room state
|
|
|
|
const makeRoomsWithStateEvents = (stateEvents = []): [Room, Room] => {
|
|
|
|
const room1 = new Room(room1Id, mockClient, aliceId);
|
|
|
|
const room2 = new Room(room2Id, mockClient, aliceId);
|
|
|
|
|
|
|
|
room1.currentState.setStateEvents(stateEvents);
|
|
|
|
room2.currentState.setStateEvents(stateEvents);
|
|
|
|
mockClient.getVisibleRooms.mockReturnValue([room1, room2]);
|
|
|
|
|
|
|
|
return [room1, room2];
|
|
|
|
};
|
|
|
|
|
|
|
|
const makeOwnBeaconStore = async () => {
|
|
|
|
const store = OwnBeaconStore.instance;
|
|
|
|
|
|
|
|
await setupAsyncStoreWithClient(store, mockClient);
|
|
|
|
return store;
|
|
|
|
};
|
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
roomId: room1Id,
|
|
|
|
};
|
|
|
|
const getComponent = (props = {}) => {
|
|
|
|
let component;
|
|
|
|
// component updates on render
|
|
|
|
// wrap in act
|
|
|
|
act(() => {
|
|
|
|
component = mount(<RoomLiveShareWarning {...defaultProps} {...props} />);
|
|
|
|
});
|
|
|
|
return component;
|
|
|
|
};
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
const localStorageSpy = jest.spyOn(localStorage.__proto__, "getItem").mockReturnValue(undefined);
|
2022-04-22 12:05:36 +00:00
|
|
|
|
2022-03-22 13:57:12 +00:00
|
|
|
beforeEach(() => {
|
2022-03-28 16:46:39 +00:00
|
|
|
mockGeolocation();
|
2022-12-12 11:24:14 +00:00
|
|
|
jest.spyOn(global.Date, "now").mockReturnValue(now);
|
|
|
|
mockClient.unstable_setLiveBeacon.mockReset().mockResolvedValue({ event_id: "1" });
|
2022-04-22 12:05:36 +00:00
|
|
|
|
|
|
|
// assume all beacons were created on this device
|
2022-12-12 11:24:14 +00:00
|
|
|
localStorageSpy.mockReturnValue(
|
|
|
|
JSON.stringify([room1Beacon1.getId(), room2Beacon1.getId(), room2Beacon2.getId(), room3Beacon1.getId()]),
|
|
|
|
);
|
2022-03-22 13:57:12 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(async () => {
|
2022-12-12 11:24:14 +00:00
|
|
|
jest.spyOn(OwnBeaconStore.instance, "beaconHasLocationPublishError").mockRestore();
|
2022-03-22 13:57:12 +00:00
|
|
|
await resetAsyncStoreWithClient(OwnBeaconStore.instance);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(() => {
|
2022-12-12 11:24:14 +00:00
|
|
|
jest.spyOn(global.Date, "now").mockRestore();
|
2022-04-22 12:05:36 +00:00
|
|
|
localStorageSpy.mockRestore();
|
2022-12-12 11:24:14 +00:00
|
|
|
jest.spyOn(defaultDispatcher, "dispatch").mockRestore();
|
2022-03-22 13:57:12 +00:00
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
const getExpiryText = (wrapper) => findByTestId(wrapper, "room-live-share-expiry").text();
|
2022-03-23 10:12:58 +00:00
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it("renders nothing when user has no live beacons at all", async () => {
|
2022-03-22 13:57:12 +00:00
|
|
|
await makeOwnBeaconStore();
|
|
|
|
const component = getComponent();
|
|
|
|
expect(component.html()).toBe(null);
|
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it("renders nothing when user has no live beacons in room", async () => {
|
2022-03-22 13:57:12 +00:00
|
|
|
await act(async () => {
|
|
|
|
await makeRoomsWithStateEvents([room2Beacon1]);
|
|
|
|
await makeOwnBeaconStore();
|
|
|
|
});
|
|
|
|
const component = getComponent({ roomId: room1Id });
|
|
|
|
expect(component.html()).toBe(null);
|
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it("does not render when geolocation is not working", async () => {
|
|
|
|
jest.spyOn(logger, "error").mockImplementation(() => {});
|
2022-03-28 16:46:39 +00:00
|
|
|
// @ts-ignore
|
|
|
|
navigator.geolocation = undefined;
|
|
|
|
await act(async () => {
|
|
|
|
await makeRoomsWithStateEvents([room1Beacon1, room2Beacon1, room2Beacon2]);
|
|
|
|
await makeOwnBeaconStore();
|
|
|
|
});
|
|
|
|
const component = getComponent({ roomId: room1Id });
|
|
|
|
|
|
|
|
// beacons have generated ids that break snapshots
|
|
|
|
// assert on html
|
|
|
|
expect(component.html()).toBeNull();
|
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
describe("when user has live beacons and geolocation is available", () => {
|
2022-03-22 13:57:12 +00:00
|
|
|
beforeEach(async () => {
|
|
|
|
await act(async () => {
|
|
|
|
await makeRoomsWithStateEvents([room1Beacon1, room2Beacon1, room2Beacon2]);
|
|
|
|
await makeOwnBeaconStore();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it("renders correctly with one live beacon in room", () => {
|
2022-03-22 13:57:12 +00:00
|
|
|
const component = getComponent({ roomId: room1Id });
|
2022-03-28 10:48:38 +00:00
|
|
|
// beacons have generated ids that break snapshots
|
|
|
|
// assert on html
|
|
|
|
expect(component.html()).toMatchSnapshot();
|
2022-03-22 13:57:12 +00:00
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it("renders correctly with two live beacons in room", () => {
|
2022-03-22 13:57:12 +00:00
|
|
|
const component = getComponent({ roomId: room2Id });
|
2022-03-28 10:48:38 +00:00
|
|
|
// beacons have generated ids that break snapshots
|
|
|
|
// assert on html
|
|
|
|
expect(component.html()).toMatchSnapshot();
|
2022-03-22 13:57:12 +00:00
|
|
|
// later expiry displayed
|
2022-12-12 11:24:14 +00:00
|
|
|
expect(getExpiryText(component)).toEqual("12h left");
|
2022-03-22 13:57:12 +00:00
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it("removes itself when user stops having live beacons", async () => {
|
2022-03-22 13:57:12 +00:00
|
|
|
const component = getComponent({ roomId: room1Id });
|
|
|
|
// started out rendered
|
|
|
|
expect(component.html()).toBeTruthy();
|
|
|
|
|
|
|
|
// time travel until room1Beacon1 is expired
|
2022-03-23 10:12:58 +00:00
|
|
|
act(() => {
|
|
|
|
advanceDateAndTime(HOUR_MS + 1);
|
|
|
|
});
|
2022-03-22 13:57:12 +00:00
|
|
|
act(() => {
|
|
|
|
mockClient.emit(BeaconEvent.LivenessChange, false, new Beacon(room1Beacon1));
|
|
|
|
component.setProps({});
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(component.html()).toBe(null);
|
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it("removes itself when user stops monitoring live position", async () => {
|
2022-03-28 16:46:39 +00:00
|
|
|
const component = getComponent({ roomId: room1Id });
|
|
|
|
// started out rendered
|
|
|
|
expect(component.html()).toBeTruthy();
|
|
|
|
|
|
|
|
act(() => {
|
|
|
|
// cheat to clear this
|
|
|
|
// @ts-ignore
|
|
|
|
OwnBeaconStore.instance.clearPositionWatch = undefined;
|
|
|
|
OwnBeaconStore.instance.emit(OwnBeaconStoreEvent.MonitoringLivePosition);
|
|
|
|
component.setProps({});
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(component.html()).toBe(null);
|
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it("renders when user adds a live beacon", async () => {
|
2022-03-22 13:57:12 +00:00
|
|
|
const component = getComponent({ roomId: room3Id });
|
|
|
|
// started out not rendered
|
|
|
|
expect(component.html()).toBeFalsy();
|
|
|
|
|
|
|
|
act(() => {
|
|
|
|
mockClient.emit(BeaconEvent.New, room3Beacon1, new Beacon(room3Beacon1));
|
|
|
|
component.setProps({});
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(component.html()).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it("updates beacon time left periodically", () => {
|
2022-03-23 10:12:58 +00:00
|
|
|
const component = getComponent({ roomId: room1Id });
|
2022-12-12 11:24:14 +00:00
|
|
|
expect(getExpiryText(component)).toEqual("1h left");
|
2022-03-23 10:12:58 +00:00
|
|
|
|
|
|
|
act(() => {
|
|
|
|
advanceDateAndTime(MINUTE_MS * 25);
|
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
expect(getExpiryText(component)).toEqual("35m left");
|
2022-03-23 10:12:58 +00:00
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it("updates beacon time left when beacon updates", () => {
|
2022-04-08 08:53:06 +00:00
|
|
|
const component = getComponent({ roomId: room1Id });
|
2022-12-12 11:24:14 +00:00
|
|
|
expect(getExpiryText(component)).toEqual("1h left");
|
2022-04-08 08:53:06 +00:00
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
expect(getExpiryText(component)).toEqual("1h left");
|
2022-04-08 08:53:06 +00:00
|
|
|
|
|
|
|
act(() => {
|
|
|
|
const beacon = OwnBeaconStore.instance.getBeaconById(getBeaconInfoIdentifier(room1Beacon1));
|
2022-12-12 11:24:14 +00:00
|
|
|
const room1Beacon1Update = makeBeaconInfoEvent(
|
|
|
|
aliceId,
|
|
|
|
room1Id,
|
|
|
|
{
|
|
|
|
isLive: true,
|
|
|
|
timeout: 3 * HOUR_MS,
|
|
|
|
},
|
|
|
|
"$0",
|
|
|
|
);
|
2022-04-08 08:53:06 +00:00
|
|
|
beacon.update(room1Beacon1Update);
|
|
|
|
});
|
|
|
|
|
|
|
|
// update to expiry of new beacon
|
2022-12-12 11:24:14 +00:00
|
|
|
expect(getExpiryText(component)).toEqual("3h left");
|
2022-04-08 08:53:06 +00:00
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it("clears expiry time interval on unmount", () => {
|
|
|
|
const clearIntervalSpy = jest.spyOn(global, "clearInterval");
|
2022-03-23 10:12:58 +00:00
|
|
|
const component = getComponent({ roomId: room1Id });
|
2022-12-12 11:24:14 +00:00
|
|
|
expect(getExpiryText(component)).toEqual("1h left");
|
2022-03-23 10:12:58 +00:00
|
|
|
|
|
|
|
act(() => {
|
|
|
|
component.unmount();
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(clearIntervalSpy).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it("navigates to beacon tile on click", () => {
|
|
|
|
const dispatcherSpy = jest.spyOn(defaultDispatcher, "dispatch");
|
2022-06-07 10:15:09 +00:00
|
|
|
const component = getComponent({ roomId: room1Id });
|
|
|
|
|
|
|
|
act(() => {
|
2022-12-12 11:24:14 +00:00
|
|
|
component.simulate("click");
|
2022-06-07 10:15:09 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(dispatcherSpy).toHaveBeenCalledWith({
|
|
|
|
action: Action.ViewRoom,
|
|
|
|
event_id: room1Beacon1.getId(),
|
|
|
|
room_id: room1Id,
|
|
|
|
highlighted: true,
|
|
|
|
scroll_into_view: true,
|
|
|
|
metricsTrigger: undefined,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
describe("stopping beacons", () => {
|
|
|
|
it("stops beacon on stop sharing click", () => {
|
2022-03-22 13:57:12 +00:00
|
|
|
const component = getComponent({ roomId: room2Id });
|
|
|
|
|
|
|
|
act(() => {
|
2022-12-12 11:24:14 +00:00
|
|
|
findByTestId(component, "room-live-share-primary-button").at(0).simulate("click");
|
2022-03-22 13:57:12 +00:00
|
|
|
component.setProps({});
|
|
|
|
});
|
|
|
|
|
2022-04-08 08:53:06 +00:00
|
|
|
expect(mockClient.unstable_setLiveBeacon).toHaveBeenCalled();
|
2022-12-12 11:24:14 +00:00
|
|
|
expect(component.find("Spinner").length).toBeTruthy();
|
|
|
|
expect(findByTestId(component, "room-live-share-primary-button").at(0).props().disabled).toBeTruthy();
|
2022-03-22 13:57:12 +00:00
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it("displays error when stop sharing fails", async () => {
|
2022-03-30 12:31:19 +00:00
|
|
|
const component = getComponent({ roomId: room1Id });
|
|
|
|
|
|
|
|
// fail first time
|
|
|
|
mockClient.unstable_setLiveBeacon
|
2022-12-12 11:24:14 +00:00
|
|
|
.mockRejectedValueOnce(new Error("oups"))
|
|
|
|
.mockResolvedValue({ event_id: "1" });
|
2022-03-30 12:31:19 +00:00
|
|
|
|
|
|
|
await act(async () => {
|
2022-12-12 11:24:14 +00:00
|
|
|
findByTestId(component, "room-live-share-primary-button").at(0).simulate("click");
|
2022-03-30 12:31:19 +00:00
|
|
|
await flushPromisesWithFakeTimers();
|
|
|
|
});
|
|
|
|
component.setProps({});
|
|
|
|
|
|
|
|
expect(component.html()).toMatchSnapshot();
|
|
|
|
|
|
|
|
act(() => {
|
2022-12-12 11:24:14 +00:00
|
|
|
findByTestId(component, "room-live-share-primary-button").at(0).simulate("click");
|
2022-03-30 12:31:19 +00:00
|
|
|
component.setProps({});
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(mockClient.unstable_setLiveBeacon).toHaveBeenCalledTimes(2);
|
2022-03-22 13:57:12 +00:00
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it("displays again with correct state after stopping a beacon", () => {
|
2022-03-22 13:57:12 +00:00
|
|
|
// make sure the loading state is reset correctly after removing a beacon
|
2022-03-23 10:12:58 +00:00
|
|
|
const component = getComponent({ roomId: room1Id });
|
2022-03-22 13:57:12 +00:00
|
|
|
|
2022-03-23 10:12:58 +00:00
|
|
|
// stop the beacon
|
2022-03-22 13:57:12 +00:00
|
|
|
act(() => {
|
2022-12-12 11:24:14 +00:00
|
|
|
findByTestId(component, "room-live-share-primary-button").at(0).simulate("click");
|
2022-03-22 13:57:12 +00:00
|
|
|
});
|
|
|
|
// time travel until room1Beacon1 is expired
|
2022-03-23 10:12:58 +00:00
|
|
|
act(() => {
|
|
|
|
advanceDateAndTime(HOUR_MS + 1);
|
|
|
|
});
|
2022-03-22 13:57:12 +00:00
|
|
|
act(() => {
|
|
|
|
mockClient.emit(BeaconEvent.LivenessChange, false, new Beacon(room1Beacon1));
|
|
|
|
});
|
|
|
|
|
2022-03-23 10:12:58 +00:00
|
|
|
const newLiveBeacon = makeBeaconInfoEvent(aliceId, room1Id, { isLive: true });
|
2022-03-22 13:57:12 +00:00
|
|
|
act(() => {
|
|
|
|
mockClient.emit(BeaconEvent.New, newLiveBeacon, new Beacon(newLiveBeacon));
|
|
|
|
});
|
|
|
|
|
|
|
|
// button not disabled and expiry time shown
|
2022-12-12 11:24:14 +00:00
|
|
|
expect(findByTestId(component, "room-live-share-primary-button").at(0).props().disabled).toBeFalsy();
|
|
|
|
expect(findByTestId(component, "room-live-share-expiry").text()).toEqual("1h left");
|
2022-03-22 13:57:12 +00:00
|
|
|
});
|
|
|
|
});
|
2022-03-31 08:57:12 +00:00
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
describe("with location publish errors", () => {
|
|
|
|
it("displays location publish error when mounted with location publish errors", async () => {
|
|
|
|
const locationPublishErrorSpy = jest
|
|
|
|
.spyOn(OwnBeaconStore.instance, "beaconHasLocationPublishError")
|
2022-04-13 08:44:15 +00:00
|
|
|
.mockReturnValue(true);
|
2022-03-31 08:57:12 +00:00
|
|
|
const component = getComponent({ roomId: room2Id });
|
|
|
|
|
|
|
|
expect(component).toMatchSnapshot();
|
2022-12-12 11:24:14 +00:00
|
|
|
expect(locationPublishErrorSpy).toHaveBeenCalledWith(getBeaconInfoIdentifier(room2Beacon1), 0, [
|
|
|
|
getBeaconInfoIdentifier(room2Beacon1),
|
|
|
|
]);
|
2022-03-31 08:57:12 +00:00
|
|
|
});
|
|
|
|
|
2022-04-25 12:44:18 +00:00
|
|
|
it(
|
2022-12-12 11:24:14 +00:00
|
|
|
"displays location publish error when locationPublishError event is emitted" +
|
|
|
|
" and beacons have errors",
|
2022-04-25 12:44:18 +00:00
|
|
|
async () => {
|
2022-12-12 11:24:14 +00:00
|
|
|
const locationPublishErrorSpy = jest
|
|
|
|
.spyOn(OwnBeaconStore.instance, "beaconHasLocationPublishError")
|
2022-04-25 12:44:18 +00:00
|
|
|
.mockReturnValue(false);
|
|
|
|
const component = getComponent({ roomId: room2Id });
|
|
|
|
|
|
|
|
// update mock and emit event
|
|
|
|
act(() => {
|
|
|
|
locationPublishErrorSpy.mockReturnValue(true);
|
|
|
|
OwnBeaconStore.instance.emit(
|
2022-12-12 11:24:14 +00:00
|
|
|
OwnBeaconStoreEvent.LocationPublishError,
|
|
|
|
getBeaconInfoIdentifier(room2Beacon1),
|
2022-04-25 12:44:18 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
component.setProps({});
|
2022-03-31 08:57:12 +00:00
|
|
|
|
2022-04-25 12:44:18 +00:00
|
|
|
// renders wire error ui
|
2022-12-12 11:24:14 +00:00
|
|
|
expect(component.find(".mx_RoomLiveShareWarning_label").text()).toEqual(
|
|
|
|
"An error occurred whilst sharing your live location, please try again",
|
2022-04-25 12:44:18 +00:00
|
|
|
);
|
2022-12-12 11:24:14 +00:00
|
|
|
expect(findByTestId(component, "room-live-share-wire-error-close-button").length).toBeTruthy();
|
|
|
|
},
|
|
|
|
);
|
2022-03-31 08:57:12 +00:00
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it("stops displaying wire error when errors are cleared", async () => {
|
|
|
|
const locationPublishErrorSpy = jest
|
|
|
|
.spyOn(OwnBeaconStore.instance, "beaconHasLocationPublishError")
|
2022-04-13 08:44:15 +00:00
|
|
|
.mockReturnValue(true);
|
2022-03-31 08:57:12 +00:00
|
|
|
const component = getComponent({ roomId: room2Id });
|
|
|
|
|
|
|
|
// update mock and emit event
|
|
|
|
act(() => {
|
2022-04-25 12:44:18 +00:00
|
|
|
locationPublishErrorSpy.mockReturnValue(false);
|
|
|
|
OwnBeaconStore.instance.emit(
|
2022-12-12 11:24:14 +00:00
|
|
|
OwnBeaconStoreEvent.LocationPublishError,
|
|
|
|
getBeaconInfoIdentifier(room2Beacon1),
|
2022-04-25 12:44:18 +00:00
|
|
|
);
|
2022-03-31 08:57:12 +00:00
|
|
|
});
|
|
|
|
component.setProps({});
|
|
|
|
|
|
|
|
// renders error-free ui
|
2022-12-12 11:24:14 +00:00
|
|
|
expect(component.find(".mx_RoomLiveShareWarning_label").text()).toEqual(
|
|
|
|
"You are sharing your live location",
|
2022-03-31 08:57:12 +00:00
|
|
|
);
|
2022-12-12 11:24:14 +00:00
|
|
|
expect(findByTestId(component, "room-live-share-wire-error-close-button").length).toBeFalsy();
|
2022-03-31 08:57:12 +00:00
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it("clicking retry button resets location publish errors", async () => {
|
|
|
|
jest.spyOn(OwnBeaconStore.instance, "beaconHasLocationPublishError").mockReturnValue(true);
|
|
|
|
const resetErrorSpy = jest.spyOn(OwnBeaconStore.instance, "resetLocationPublishError");
|
2022-03-31 08:57:12 +00:00
|
|
|
|
|
|
|
const component = getComponent({ roomId: room2Id });
|
|
|
|
|
|
|
|
act(() => {
|
2022-12-12 11:24:14 +00:00
|
|
|
findByTestId(component, "room-live-share-primary-button").at(0).simulate("click");
|
2022-03-31 08:57:12 +00:00
|
|
|
});
|
|
|
|
|
2022-04-08 08:53:06 +00:00
|
|
|
expect(resetErrorSpy).toHaveBeenCalledWith(getBeaconInfoIdentifier(room2Beacon1));
|
2022-03-31 08:57:12 +00:00
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it("clicking close button stops beacons", async () => {
|
|
|
|
jest.spyOn(OwnBeaconStore.instance, "beaconHasLocationPublishError").mockReturnValue(true);
|
|
|
|
const stopBeaconSpy = jest.spyOn(OwnBeaconStore.instance, "stopBeacon");
|
2022-03-31 08:57:12 +00:00
|
|
|
|
|
|
|
const component = getComponent({ roomId: room2Id });
|
|
|
|
|
|
|
|
act(() => {
|
2022-12-12 11:24:14 +00:00
|
|
|
findByTestId(component, "room-live-share-wire-error-close-button").at(0).simulate("click");
|
2022-03-31 08:57:12 +00:00
|
|
|
});
|
|
|
|
|
2022-04-08 08:53:06 +00:00
|
|
|
expect(stopBeaconSpy).toHaveBeenCalledWith(getBeaconInfoIdentifier(room2Beacon1));
|
2022-03-31 08:57:12 +00:00
|
|
|
});
|
|
|
|
});
|
2022-03-22 13:57:12 +00:00
|
|
|
});
|
|
|
|
});
|