riot-web/test/components/views/beacon/RoomLiveShareWarning-test.tsx

427 lines
17 KiB
TypeScript
Raw Normal View History

/*
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 12:24:14 +01:00
import React from "react";
2022-12-29 16:35:19 +01:00
import { Room, Beacon, BeaconEvent, getBeaconInfoIdentifier, MatrixEvent } from "matrix-js-sdk/src/matrix";
2022-12-12 12:24:14 +01:00
import { logger } from "matrix-js-sdk/src/logger";
import { act, fireEvent, getByTestId, render, screen, waitFor } from "@testing-library/react";
2022-12-12 12:24:14 +01:00
import RoomLiveShareWarning from "../../../../src/components/views/beacon/RoomLiveShareWarning";
import { OwnBeaconStore, OwnBeaconStoreEvent } from "../../../../src/stores/OwnBeaconStore";
import {
advanceDateAndTime,
flushPromisesWithFakeTimers,
getMockClientWithEventEmitter,
makeBeaconInfoEvent,
mockGeolocation,
resetAsyncStoreWithClient,
setupAsyncStoreWithClient,
2022-12-12 12:24:14 +01:00
} from "../../../test-utils";
import defaultDispatcher from "../../../../src/dispatcher/dispatcher";
import { Action } from "../../../../src/dispatcher/actions";
jest.useFakeTimers();
2022-12-12 12:24:14 +01:00
describe("<RoomLiveShareWarning />", () => {
const aliceId = "@alice:server.org";
const room1Id = "$room1:server.org";
const room2Id = "$room2:server.org";
const room3Id = "$room3:server.org";
const mockClient = getMockClientWithEventEmitter({
getVisibleRooms: jest.fn().mockReturnValue([]),
getUserId: jest.fn().mockReturnValue(aliceId),
2022-12-12 12:24:14 +01:00
unstable_setLiveBeacon: jest.fn().mockResolvedValue({ event_id: "1" }),
sendEvent: jest.fn(),
});
// 14.03.2022 16:15
const now = 1647270879403;
Live location sharing - refresh beacon expiry in room (#8116) * add duration dropdown to live location picker Signed-off-by: Kerry Archibald <kerrya@element.io> * tidy comments Signed-off-by: Kerry Archibald <kerrya@element.io> * setup component Signed-off-by: Kerry Archibald <kerrya@element.io> * replace references to beaconInfoId with beacon.identifier Signed-off-by: Kerry Archibald <kerrya@element.io> * icon Signed-off-by: Kerry Archibald <kerrya@element.io> * component for styled live beacon icon Signed-off-by: Kerry Archibald <kerrya@element.io> * emit liveness change whenever livebeaconIds changes Signed-off-by: Kerry Archibald <kerrya@element.io> * Handle multiple live beacons in room share warning, test Signed-off-by: Kerry Archibald <kerrya@element.io> * un xdescribe beaconstore tests Signed-off-by: Kerry Archibald <kerrya@element.io> * missed copyrights Signed-off-by: Kerry Archibald <kerrya@element.io> * i18n Signed-off-by: Kerry Archibald <kerrya@element.io> * refresh beacon time remaining Signed-off-by: Kerry Archibald <kerrya@element.io> * kill timeout Signed-off-by: Kerry Archibald <kerrya@element.io> * use useInterval Signed-off-by: Kerry Archibald <kerrya@element.io> * beacon not optional in useMsRemaining Signed-off-by: Kerry Archibald <kerrya@element.io> * just use single "you are sharing" message Signed-off-by: Kerry Archibald <kerrya@element.io> * trigger Signed-off-by: Kerry Archibald <kerrya@element.io> * i18n Signed-off-by: Kerry Archibald <kerrya@element.io> * i18n again Signed-off-by: Kerry Archibald <kerrya@element.io>
2022-03-23 11:12:58 +01:00
const MINUTE_MS = 60000;
const HOUR_MS = 3600000;
// mock the date so events are stable for snapshots etc
2022-12-12 12:24:14 +01: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");
// make fresh rooms every time
// as we update room state
2022-12-29 16:35:19 +01:00
const makeRoomsWithStateEvents = (stateEvents: MatrixEvent[] = []): [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 = {}) => {
2022-12-29 16:35:19 +01:00
return render(<RoomLiveShareWarning {...defaultProps} {...props} />);
};
2022-12-12 12:24:14 +01:00
const localStorageSpy = jest.spyOn(localStorage.__proto__, "getItem").mockReturnValue(undefined);
beforeEach(() => {
mockGeolocation();
2022-12-12 12:24:14 +01:00
jest.spyOn(global.Date, "now").mockReturnValue(now);
mockClient.unstable_setLiveBeacon.mockReset().mockResolvedValue({ event_id: "1" });
// assume all beacons were created on this device
2022-12-12 12:24:14 +01:00
localStorageSpy.mockReturnValue(
JSON.stringify([room1Beacon1.getId(), room2Beacon1.getId(), room2Beacon2.getId(), room3Beacon1.getId()]),
);
});
afterEach(async () => {
2022-12-12 12:24:14 +01:00
jest.spyOn(OwnBeaconStore.instance, "beaconHasLocationPublishError").mockRestore();
await resetAsyncStoreWithClient(OwnBeaconStore.instance);
});
afterAll(() => {
2022-12-12 12:24:14 +01:00
jest.spyOn(global.Date, "now").mockRestore();
localStorageSpy.mockRestore();
2022-12-12 12:24:14 +01:00
jest.spyOn(defaultDispatcher, "dispatch").mockRestore();
});
2022-12-12 12:24:14 +01:00
it("renders nothing when user has no live beacons at all", async () => {
await makeOwnBeaconStore();
2022-12-29 16:35:19 +01:00
const { asFragment } = getComponent();
expect(asFragment()).toMatchInlineSnapshot(`<DocumentFragment />`);
});
2022-12-12 12:24:14 +01:00
it("renders nothing when user has no live beacons in room", async () => {
await act(async () => {
await makeRoomsWithStateEvents([room2Beacon1]);
await makeOwnBeaconStore();
});
2022-12-29 16:35:19 +01:00
const { asFragment } = getComponent({ roomId: room1Id });
expect(asFragment()).toMatchInlineSnapshot(`<DocumentFragment />`);
});
2022-12-12 12:24:14 +01:00
it("does not render when geolocation is not working", async () => {
jest.spyOn(logger, "error").mockImplementation(() => {});
// @ts-ignore
navigator.geolocation = undefined;
await act(async () => {
await makeRoomsWithStateEvents([room1Beacon1, room2Beacon1, room2Beacon2]);
await makeOwnBeaconStore();
});
2022-12-29 16:35:19 +01:00
const { asFragment } = getComponent({ roomId: room1Id });
2022-12-29 16:35:19 +01:00
expect(asFragment()).toMatchInlineSnapshot(`<DocumentFragment />`);
});
2022-12-12 12:24:14 +01:00
describe("when user has live beacons and geolocation is available", () => {
beforeEach(async () => {
await act(async () => {
await makeRoomsWithStateEvents([room1Beacon1, room2Beacon1, room2Beacon2]);
await makeOwnBeaconStore();
});
});
2022-12-12 12:24:14 +01:00
it("renders correctly with one live beacon in room", () => {
2022-12-29 16:35:19 +01:00
const { asFragment } = getComponent({ roomId: room1Id });
// beacons have generated ids that break snapshots
// assert on html
2022-12-29 16:35:19 +01:00
expect(asFragment()).toMatchSnapshot();
});
2022-12-12 12:24:14 +01:00
it("renders correctly with two live beacons in room", () => {
2022-12-29 16:35:19 +01:00
const { asFragment, container } = getComponent({ roomId: room2Id });
// beacons have generated ids that break snapshots
// assert on html
2022-12-29 16:35:19 +01:00
expect(asFragment()).toMatchSnapshot();
// later expiry displayed
2022-12-29 16:35:19 +01:00
expect(container).toHaveTextContent("12h left");
});
2022-12-12 12:24:14 +01:00
it("removes itself when user stops having live beacons", async () => {
2022-12-29 16:35:19 +01:00
const { container } = getComponent({ roomId: room1Id });
// started out rendered
2022-12-29 16:35:19 +01:00
expect(container.firstChild).toBeTruthy();
// time travel until room1Beacon1 is expired
Live location sharing - refresh beacon expiry in room (#8116) * add duration dropdown to live location picker Signed-off-by: Kerry Archibald <kerrya@element.io> * tidy comments Signed-off-by: Kerry Archibald <kerrya@element.io> * setup component Signed-off-by: Kerry Archibald <kerrya@element.io> * replace references to beaconInfoId with beacon.identifier Signed-off-by: Kerry Archibald <kerrya@element.io> * icon Signed-off-by: Kerry Archibald <kerrya@element.io> * component for styled live beacon icon Signed-off-by: Kerry Archibald <kerrya@element.io> * emit liveness change whenever livebeaconIds changes Signed-off-by: Kerry Archibald <kerrya@element.io> * Handle multiple live beacons in room share warning, test Signed-off-by: Kerry Archibald <kerrya@element.io> * un xdescribe beaconstore tests Signed-off-by: Kerry Archibald <kerrya@element.io> * missed copyrights Signed-off-by: Kerry Archibald <kerrya@element.io> * i18n Signed-off-by: Kerry Archibald <kerrya@element.io> * refresh beacon time remaining Signed-off-by: Kerry Archibald <kerrya@element.io> * kill timeout Signed-off-by: Kerry Archibald <kerrya@element.io> * use useInterval Signed-off-by: Kerry Archibald <kerrya@element.io> * beacon not optional in useMsRemaining Signed-off-by: Kerry Archibald <kerrya@element.io> * just use single "you are sharing" message Signed-off-by: Kerry Archibald <kerrya@element.io> * trigger Signed-off-by: Kerry Archibald <kerrya@element.io> * i18n Signed-off-by: Kerry Archibald <kerrya@element.io> * i18n again Signed-off-by: Kerry Archibald <kerrya@element.io>
2022-03-23 11:12:58 +01:00
act(() => {
advanceDateAndTime(HOUR_MS + 1);
});
act(() => {
mockClient.emit(BeaconEvent.LivenessChange, false, new Beacon(room1Beacon1));
});
2022-12-29 16:35:19 +01:00
await waitFor(() => expect(container.firstChild).toBeFalsy());
});
2022-12-12 12:24:14 +01:00
it("removes itself when user stops monitoring live position", async () => {
2022-12-29 16:35:19 +01:00
const { container } = getComponent({ roomId: room1Id });
// started out rendered
2022-12-29 16:35:19 +01:00
expect(container.firstChild).toBeTruthy();
act(() => {
// cheat to clear this
// @ts-ignore
OwnBeaconStore.instance.clearPositionWatch = undefined;
OwnBeaconStore.instance.emit(OwnBeaconStoreEvent.MonitoringLivePosition);
});
2022-12-29 16:35:19 +01:00
await waitFor(() => expect(container.firstChild).toBeFalsy());
});
2022-12-12 12:24:14 +01:00
it("renders when user adds a live beacon", async () => {
2022-12-29 16:35:19 +01:00
const { container } = getComponent({ roomId: room3Id });
// started out not rendered
2022-12-29 16:35:19 +01:00
expect(container.firstChild).toBeFalsy();
act(() => {
mockClient.emit(BeaconEvent.New, room3Beacon1, new Beacon(room3Beacon1));
});
2022-12-29 16:35:19 +01:00
await waitFor(() => expect(container.firstChild).toBeTruthy());
});
2022-12-12 12:24:14 +01:00
it("updates beacon time left periodically", () => {
2022-12-29 16:35:19 +01:00
const { container } = getComponent({ roomId: room1Id });
expect(container).toHaveTextContent("1h left");
Live location sharing - refresh beacon expiry in room (#8116) * add duration dropdown to live location picker Signed-off-by: Kerry Archibald <kerrya@element.io> * tidy comments Signed-off-by: Kerry Archibald <kerrya@element.io> * setup component Signed-off-by: Kerry Archibald <kerrya@element.io> * replace references to beaconInfoId with beacon.identifier Signed-off-by: Kerry Archibald <kerrya@element.io> * icon Signed-off-by: Kerry Archibald <kerrya@element.io> * component for styled live beacon icon Signed-off-by: Kerry Archibald <kerrya@element.io> * emit liveness change whenever livebeaconIds changes Signed-off-by: Kerry Archibald <kerrya@element.io> * Handle multiple live beacons in room share warning, test Signed-off-by: Kerry Archibald <kerrya@element.io> * un xdescribe beaconstore tests Signed-off-by: Kerry Archibald <kerrya@element.io> * missed copyrights Signed-off-by: Kerry Archibald <kerrya@element.io> * i18n Signed-off-by: Kerry Archibald <kerrya@element.io> * refresh beacon time remaining Signed-off-by: Kerry Archibald <kerrya@element.io> * kill timeout Signed-off-by: Kerry Archibald <kerrya@element.io> * use useInterval Signed-off-by: Kerry Archibald <kerrya@element.io> * beacon not optional in useMsRemaining Signed-off-by: Kerry Archibald <kerrya@element.io> * just use single "you are sharing" message Signed-off-by: Kerry Archibald <kerrya@element.io> * trigger Signed-off-by: Kerry Archibald <kerrya@element.io> * i18n Signed-off-by: Kerry Archibald <kerrya@element.io> * i18n again Signed-off-by: Kerry Archibald <kerrya@element.io>
2022-03-23 11:12:58 +01:00
act(() => {
advanceDateAndTime(MINUTE_MS * 25);
});
2022-12-29 16:35:19 +01:00
expect(container).toHaveTextContent("35m left");
Live location sharing - refresh beacon expiry in room (#8116) * add duration dropdown to live location picker Signed-off-by: Kerry Archibald <kerrya@element.io> * tidy comments Signed-off-by: Kerry Archibald <kerrya@element.io> * setup component Signed-off-by: Kerry Archibald <kerrya@element.io> * replace references to beaconInfoId with beacon.identifier Signed-off-by: Kerry Archibald <kerrya@element.io> * icon Signed-off-by: Kerry Archibald <kerrya@element.io> * component for styled live beacon icon Signed-off-by: Kerry Archibald <kerrya@element.io> * emit liveness change whenever livebeaconIds changes Signed-off-by: Kerry Archibald <kerrya@element.io> * Handle multiple live beacons in room share warning, test Signed-off-by: Kerry Archibald <kerrya@element.io> * un xdescribe beaconstore tests Signed-off-by: Kerry Archibald <kerrya@element.io> * missed copyrights Signed-off-by: Kerry Archibald <kerrya@element.io> * i18n Signed-off-by: Kerry Archibald <kerrya@element.io> * refresh beacon time remaining Signed-off-by: Kerry Archibald <kerrya@element.io> * kill timeout Signed-off-by: Kerry Archibald <kerrya@element.io> * use useInterval Signed-off-by: Kerry Archibald <kerrya@element.io> * beacon not optional in useMsRemaining Signed-off-by: Kerry Archibald <kerrya@element.io> * just use single "you are sharing" message Signed-off-by: Kerry Archibald <kerrya@element.io> * trigger Signed-off-by: Kerry Archibald <kerrya@element.io> * i18n Signed-off-by: Kerry Archibald <kerrya@element.io> * i18n again Signed-off-by: Kerry Archibald <kerrya@element.io>
2022-03-23 11:12:58 +01:00
});
2022-12-12 12:24:14 +01:00
it("updates beacon time left when beacon updates", () => {
2022-12-29 16:35:19 +01:00
const { container } = getComponent({ roomId: room1Id });
expect(container).toHaveTextContent("1h left");
act(() => {
const beacon = OwnBeaconStore.instance.getBeaconById(getBeaconInfoIdentifier(room1Beacon1));
2022-12-12 12:24:14 +01:00
const room1Beacon1Update = makeBeaconInfoEvent(
aliceId,
room1Id,
{
isLive: true,
timeout: 3 * HOUR_MS,
},
"$0",
);
2022-12-29 16:35:19 +01:00
beacon?.update(room1Beacon1Update);
});
// update to expiry of new beacon
2022-12-29 16:35:19 +01:00
expect(container).toHaveTextContent("3h left");
});
2022-12-12 12:24:14 +01:00
it("clears expiry time interval on unmount", () => {
const clearIntervalSpy = jest.spyOn(global, "clearInterval");
2022-12-29 16:35:19 +01:00
const { container, unmount } = getComponent({ roomId: room1Id });
expect(container).toHaveTextContent("1h left");
Live location sharing - refresh beacon expiry in room (#8116) * add duration dropdown to live location picker Signed-off-by: Kerry Archibald <kerrya@element.io> * tidy comments Signed-off-by: Kerry Archibald <kerrya@element.io> * setup component Signed-off-by: Kerry Archibald <kerrya@element.io> * replace references to beaconInfoId with beacon.identifier Signed-off-by: Kerry Archibald <kerrya@element.io> * icon Signed-off-by: Kerry Archibald <kerrya@element.io> * component for styled live beacon icon Signed-off-by: Kerry Archibald <kerrya@element.io> * emit liveness change whenever livebeaconIds changes Signed-off-by: Kerry Archibald <kerrya@element.io> * Handle multiple live beacons in room share warning, test Signed-off-by: Kerry Archibald <kerrya@element.io> * un xdescribe beaconstore tests Signed-off-by: Kerry Archibald <kerrya@element.io> * missed copyrights Signed-off-by: Kerry Archibald <kerrya@element.io> * i18n Signed-off-by: Kerry Archibald <kerrya@element.io> * refresh beacon time remaining Signed-off-by: Kerry Archibald <kerrya@element.io> * kill timeout Signed-off-by: Kerry Archibald <kerrya@element.io> * use useInterval Signed-off-by: Kerry Archibald <kerrya@element.io> * beacon not optional in useMsRemaining Signed-off-by: Kerry Archibald <kerrya@element.io> * just use single "you are sharing" message Signed-off-by: Kerry Archibald <kerrya@element.io> * trigger Signed-off-by: Kerry Archibald <kerrya@element.io> * i18n Signed-off-by: Kerry Archibald <kerrya@element.io> * i18n again Signed-off-by: Kerry Archibald <kerrya@element.io>
2022-03-23 11:12:58 +01:00
2022-12-29 16:35:19 +01:00
unmount();
Live location sharing - refresh beacon expiry in room (#8116) * add duration dropdown to live location picker Signed-off-by: Kerry Archibald <kerrya@element.io> * tidy comments Signed-off-by: Kerry Archibald <kerrya@element.io> * setup component Signed-off-by: Kerry Archibald <kerrya@element.io> * replace references to beaconInfoId with beacon.identifier Signed-off-by: Kerry Archibald <kerrya@element.io> * icon Signed-off-by: Kerry Archibald <kerrya@element.io> * component for styled live beacon icon Signed-off-by: Kerry Archibald <kerrya@element.io> * emit liveness change whenever livebeaconIds changes Signed-off-by: Kerry Archibald <kerrya@element.io> * Handle multiple live beacons in room share warning, test Signed-off-by: Kerry Archibald <kerrya@element.io> * un xdescribe beaconstore tests Signed-off-by: Kerry Archibald <kerrya@element.io> * missed copyrights Signed-off-by: Kerry Archibald <kerrya@element.io> * i18n Signed-off-by: Kerry Archibald <kerrya@element.io> * refresh beacon time remaining Signed-off-by: Kerry Archibald <kerrya@element.io> * kill timeout Signed-off-by: Kerry Archibald <kerrya@element.io> * use useInterval Signed-off-by: Kerry Archibald <kerrya@element.io> * beacon not optional in useMsRemaining Signed-off-by: Kerry Archibald <kerrya@element.io> * just use single "you are sharing" message Signed-off-by: Kerry Archibald <kerrya@element.io> * trigger Signed-off-by: Kerry Archibald <kerrya@element.io> * i18n Signed-off-by: Kerry Archibald <kerrya@element.io> * i18n again Signed-off-by: Kerry Archibald <kerrya@element.io>
2022-03-23 11:12:58 +01:00
expect(clearIntervalSpy).toHaveBeenCalled();
});
2022-12-12 12:24:14 +01:00
it("navigates to beacon tile on click", () => {
const dispatcherSpy = jest.spyOn(defaultDispatcher, "dispatch");
2022-12-29 16:35:19 +01:00
const { container } = getComponent({ roomId: room1Id });
act(() => {
2022-12-29 16:35:19 +01:00
fireEvent.click(container.firstChild! as Node);
});
expect(dispatcherSpy).toHaveBeenCalledWith({
action: Action.ViewRoom,
event_id: room1Beacon1.getId(),
room_id: room1Id,
highlighted: true,
scroll_into_view: true,
metricsTrigger: undefined,
});
});
2022-12-12 12:24:14 +01:00
describe("stopping beacons", () => {
2022-12-29 16:35:19 +01:00
it("stops beacon on stop sharing click", async () => {
const { container } = getComponent({ roomId: room2Id });
2022-12-29 16:35:19 +01:00
const btn = getByTestId(container, "room-live-share-primary-button");
fireEvent.click(btn);
expect(mockClient.unstable_setLiveBeacon).toHaveBeenCalled();
2022-12-29 16:35:19 +01:00
await waitFor(() => expect(screen.queryByTestId("spinner")).toBeInTheDocument());
expect(btn.hasAttribute("disabled")).toBe(true);
});
2022-12-12 12:24:14 +01:00
it("displays error when stop sharing fails", async () => {
2022-12-29 16:35:19 +01:00
const { container, asFragment } = getComponent({ roomId: room1Id });
const btn = getByTestId(container, "room-live-share-primary-button");
// fail first time
mockClient.unstable_setLiveBeacon
2022-12-12 12:24:14 +01:00
.mockRejectedValueOnce(new Error("oups"))
.mockResolvedValue({ event_id: "1" });
await act(async () => {
2022-12-29 16:35:19 +01:00
fireEvent.click(btn);
await flushPromisesWithFakeTimers();
});
2022-12-29 16:35:19 +01:00
expect(asFragment()).toMatchSnapshot();
act(() => {
2022-12-29 16:35:19 +01:00
fireEvent.click(btn);
});
expect(mockClient.unstable_setLiveBeacon).toHaveBeenCalledTimes(2);
});
2022-12-12 12:24:14 +01:00
it("displays again with correct state after stopping a beacon", () => {
// make sure the loading state is reset correctly after removing a beacon
2022-12-29 16:35:19 +01:00
const { container } = getComponent({ roomId: room1Id });
const btn = getByTestId(container, "room-live-share-primary-button");
Live location sharing - refresh beacon expiry in room (#8116) * add duration dropdown to live location picker Signed-off-by: Kerry Archibald <kerrya@element.io> * tidy comments Signed-off-by: Kerry Archibald <kerrya@element.io> * setup component Signed-off-by: Kerry Archibald <kerrya@element.io> * replace references to beaconInfoId with beacon.identifier Signed-off-by: Kerry Archibald <kerrya@element.io> * icon Signed-off-by: Kerry Archibald <kerrya@element.io> * component for styled live beacon icon Signed-off-by: Kerry Archibald <kerrya@element.io> * emit liveness change whenever livebeaconIds changes Signed-off-by: Kerry Archibald <kerrya@element.io> * Handle multiple live beacons in room share warning, test Signed-off-by: Kerry Archibald <kerrya@element.io> * un xdescribe beaconstore tests Signed-off-by: Kerry Archibald <kerrya@element.io> * missed copyrights Signed-off-by: Kerry Archibald <kerrya@element.io> * i18n Signed-off-by: Kerry Archibald <kerrya@element.io> * refresh beacon time remaining Signed-off-by: Kerry Archibald <kerrya@element.io> * kill timeout Signed-off-by: Kerry Archibald <kerrya@element.io> * use useInterval Signed-off-by: Kerry Archibald <kerrya@element.io> * beacon not optional in useMsRemaining Signed-off-by: Kerry Archibald <kerrya@element.io> * just use single "you are sharing" message Signed-off-by: Kerry Archibald <kerrya@element.io> * trigger Signed-off-by: Kerry Archibald <kerrya@element.io> * i18n Signed-off-by: Kerry Archibald <kerrya@element.io> * i18n again Signed-off-by: Kerry Archibald <kerrya@element.io>
2022-03-23 11:12:58 +01:00
// stop the beacon
act(() => {
2022-12-29 16:35:19 +01:00
fireEvent.click(btn);
});
// time travel until room1Beacon1 is expired
Live location sharing - refresh beacon expiry in room (#8116) * add duration dropdown to live location picker Signed-off-by: Kerry Archibald <kerrya@element.io> * tidy comments Signed-off-by: Kerry Archibald <kerrya@element.io> * setup component Signed-off-by: Kerry Archibald <kerrya@element.io> * replace references to beaconInfoId with beacon.identifier Signed-off-by: Kerry Archibald <kerrya@element.io> * icon Signed-off-by: Kerry Archibald <kerrya@element.io> * component for styled live beacon icon Signed-off-by: Kerry Archibald <kerrya@element.io> * emit liveness change whenever livebeaconIds changes Signed-off-by: Kerry Archibald <kerrya@element.io> * Handle multiple live beacons in room share warning, test Signed-off-by: Kerry Archibald <kerrya@element.io> * un xdescribe beaconstore tests Signed-off-by: Kerry Archibald <kerrya@element.io> * missed copyrights Signed-off-by: Kerry Archibald <kerrya@element.io> * i18n Signed-off-by: Kerry Archibald <kerrya@element.io> * refresh beacon time remaining Signed-off-by: Kerry Archibald <kerrya@element.io> * kill timeout Signed-off-by: Kerry Archibald <kerrya@element.io> * use useInterval Signed-off-by: Kerry Archibald <kerrya@element.io> * beacon not optional in useMsRemaining Signed-off-by: Kerry Archibald <kerrya@element.io> * just use single "you are sharing" message Signed-off-by: Kerry Archibald <kerrya@element.io> * trigger Signed-off-by: Kerry Archibald <kerrya@element.io> * i18n Signed-off-by: Kerry Archibald <kerrya@element.io> * i18n again Signed-off-by: Kerry Archibald <kerrya@element.io>
2022-03-23 11:12:58 +01:00
act(() => {
advanceDateAndTime(HOUR_MS + 1);
});
act(() => {
mockClient.emit(BeaconEvent.LivenessChange, false, new Beacon(room1Beacon1));
});
Live location sharing - refresh beacon expiry in room (#8116) * add duration dropdown to live location picker Signed-off-by: Kerry Archibald <kerrya@element.io> * tidy comments Signed-off-by: Kerry Archibald <kerrya@element.io> * setup component Signed-off-by: Kerry Archibald <kerrya@element.io> * replace references to beaconInfoId with beacon.identifier Signed-off-by: Kerry Archibald <kerrya@element.io> * icon Signed-off-by: Kerry Archibald <kerrya@element.io> * component for styled live beacon icon Signed-off-by: Kerry Archibald <kerrya@element.io> * emit liveness change whenever livebeaconIds changes Signed-off-by: Kerry Archibald <kerrya@element.io> * Handle multiple live beacons in room share warning, test Signed-off-by: Kerry Archibald <kerrya@element.io> * un xdescribe beaconstore tests Signed-off-by: Kerry Archibald <kerrya@element.io> * missed copyrights Signed-off-by: Kerry Archibald <kerrya@element.io> * i18n Signed-off-by: Kerry Archibald <kerrya@element.io> * refresh beacon time remaining Signed-off-by: Kerry Archibald <kerrya@element.io> * kill timeout Signed-off-by: Kerry Archibald <kerrya@element.io> * use useInterval Signed-off-by: Kerry Archibald <kerrya@element.io> * beacon not optional in useMsRemaining Signed-off-by: Kerry Archibald <kerrya@element.io> * just use single "you are sharing" message Signed-off-by: Kerry Archibald <kerrya@element.io> * trigger Signed-off-by: Kerry Archibald <kerrya@element.io> * i18n Signed-off-by: Kerry Archibald <kerrya@element.io> * i18n again Signed-off-by: Kerry Archibald <kerrya@element.io>
2022-03-23 11:12:58 +01:00
const newLiveBeacon = makeBeaconInfoEvent(aliceId, room1Id, { isLive: true });
act(() => {
mockClient.emit(BeaconEvent.New, newLiveBeacon, new Beacon(newLiveBeacon));
});
// button not disabled and expiry time shown
2022-12-29 16:35:19 +01:00
expect(btn.hasAttribute("disabled")).toBe(true);
});
});
2022-12-12 12:24:14 +01: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")
Live location sharing - beacon in timeline happy path (#8285) * extract location markers into generic Marker Signed-off-by: Kerry Archibald <kerrya@element.io> * wrap marker in smartmarker Signed-off-by: Kerry Archibald <kerrya@element.io> * test smartmarker Signed-off-by: Kerry Archibald <kerrya@element.io> * working map in location body Signed-off-by: Kerry Archibald <kerrya@element.io> * remove skinned sdk Signed-off-by: Kerry Archibald <kerrya@element.io> * use new ZoomButtons in MLocationBody Signed-off-by: Kerry Archibald <kerrya@element.io> * test LocationViewDialog Signed-off-by: Kerry Archibald <kerrya@element.io> * update commentt Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io> * extract livetimeremaining into own component Signed-off-by: Kerry Archibald <kerrya@element.io> * extract more beacon state utils Signed-off-by: Kerry Archibald <kerrya@element.io> * update tests for roomlivesharewarning Signed-off-by: Kerry Archibald <kerrya@element.io> * add idle status to live beacon icon * add beacon map and status chin Signed-off-by: Kerry Archibald <kerrya@element.io> * add handling for bubbles Signed-off-by: Kerry Archibald <kerrya@element.io> * tests for BeaconBody Signed-off-by: Kerry Archibald <kerrya@element.io> * i18n Signed-off-by: Kerry Archibald <kerrya@element.io> * move displaystatus check up to mbeaconbody Signed-off-by: Kerry Archibald <kerrya@element.io> * test BeaconStatus Signed-off-by: Kerry Archibald <kerrya@element.io> * rename BeaconStatusChin -> BeaconStatus Signed-off-by: Kerry Archibald <kerrya@element.io> * make BeaconStatus generic Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io> * adjust spinner size Signed-off-by: Kerry Archibald <kerrya@element.io> * polish and copyrights Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io> * better comment Signed-off-by: Kerry Archibald <kerrya@element.io>
2022-04-13 10:44:15 +02:00
.mockReturnValue(true);
2022-12-29 16:35:19 +01:00
const { asFragment } = getComponent({ roomId: room2Id });
2022-12-29 16:35:19 +01:00
expect(asFragment()).toMatchSnapshot();
2022-12-12 12:24:14 +01:00
expect(locationPublishErrorSpy).toHaveBeenCalledWith(getBeaconInfoIdentifier(room2Beacon1), 0, [
getBeaconInfoIdentifier(room2Beacon1),
]);
});
it(
2022-12-12 12:24:14 +01:00
"displays location publish error when locationPublishError event is emitted" +
" and beacons have errors",
async () => {
2022-12-12 12:24:14 +01:00
const locationPublishErrorSpy = jest
.spyOn(OwnBeaconStore.instance, "beaconHasLocationPublishError")
.mockReturnValue(false);
2022-12-29 16:35:19 +01:00
const { container } = getComponent({ roomId: room2Id });
// update mock and emit event
act(() => {
locationPublishErrorSpy.mockReturnValue(true);
OwnBeaconStore.instance.emit(
2022-12-12 12:24:14 +01:00
OwnBeaconStoreEvent.LocationPublishError,
getBeaconInfoIdentifier(room2Beacon1),
);
});
// renders wire error ui
2022-12-29 16:35:19 +01:00
expect(container).toHaveTextContent(
2022-12-12 12:24:14 +01:00
"An error occurred whilst sharing your live location, please try again",
);
2022-12-29 16:35:19 +01:00
expect(screen.queryByTestId("room-live-share-wire-error-close-button")).toBeInTheDocument();
2022-12-12 12:24:14 +01:00
},
);
2022-12-12 12:24:14 +01:00
it("stops displaying wire error when errors are cleared", async () => {
const locationPublishErrorSpy = jest
.spyOn(OwnBeaconStore.instance, "beaconHasLocationPublishError")
Live location sharing - beacon in timeline happy path (#8285) * extract location markers into generic Marker Signed-off-by: Kerry Archibald <kerrya@element.io> * wrap marker in smartmarker Signed-off-by: Kerry Archibald <kerrya@element.io> * test smartmarker Signed-off-by: Kerry Archibald <kerrya@element.io> * working map in location body Signed-off-by: Kerry Archibald <kerrya@element.io> * remove skinned sdk Signed-off-by: Kerry Archibald <kerrya@element.io> * use new ZoomButtons in MLocationBody Signed-off-by: Kerry Archibald <kerrya@element.io> * test LocationViewDialog Signed-off-by: Kerry Archibald <kerrya@element.io> * update commentt Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io> * extract livetimeremaining into own component Signed-off-by: Kerry Archibald <kerrya@element.io> * extract more beacon state utils Signed-off-by: Kerry Archibald <kerrya@element.io> * update tests for roomlivesharewarning Signed-off-by: Kerry Archibald <kerrya@element.io> * add idle status to live beacon icon * add beacon map and status chin Signed-off-by: Kerry Archibald <kerrya@element.io> * add handling for bubbles Signed-off-by: Kerry Archibald <kerrya@element.io> * tests for BeaconBody Signed-off-by: Kerry Archibald <kerrya@element.io> * i18n Signed-off-by: Kerry Archibald <kerrya@element.io> * move displaystatus check up to mbeaconbody Signed-off-by: Kerry Archibald <kerrya@element.io> * test BeaconStatus Signed-off-by: Kerry Archibald <kerrya@element.io> * rename BeaconStatusChin -> BeaconStatus Signed-off-by: Kerry Archibald <kerrya@element.io> * make BeaconStatus generic Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io> * adjust spinner size Signed-off-by: Kerry Archibald <kerrya@element.io> * polish and copyrights Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io> * better comment Signed-off-by: Kerry Archibald <kerrya@element.io>
2022-04-13 10:44:15 +02:00
.mockReturnValue(true);
2022-12-29 16:35:19 +01:00
const { container } = getComponent({ roomId: room2Id });
// update mock and emit event
act(() => {
locationPublishErrorSpy.mockReturnValue(false);
OwnBeaconStore.instance.emit(
2022-12-12 12:24:14 +01:00
OwnBeaconStoreEvent.LocationPublishError,
getBeaconInfoIdentifier(room2Beacon1),
);
});
// renders error-free ui
2022-12-29 16:35:19 +01:00
expect(container).toHaveTextContent("You are sharing your live location");
expect(screen.queryByTestId("room-live-share-wire-error-close-button")).not.toBeInTheDocument();
});
2022-12-12 12:24:14 +01: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-12-29 16:35:19 +01:00
const { container } = getComponent({ roomId: room2Id });
const btn = getByTestId(container, "room-live-share-primary-button");
act(() => {
2022-12-29 16:35:19 +01:00
fireEvent.click(btn);
});
expect(resetErrorSpy).toHaveBeenCalledWith(getBeaconInfoIdentifier(room2Beacon1));
});
2022-12-12 12:24:14 +01:00
it("clicking close button stops beacons", async () => {
jest.spyOn(OwnBeaconStore.instance, "beaconHasLocationPublishError").mockReturnValue(true);
const stopBeaconSpy = jest.spyOn(OwnBeaconStore.instance, "stopBeacon");
2022-12-29 16:35:19 +01:00
const { container } = getComponent({ roomId: room2Id });
const btn = getByTestId(container, "room-live-share-wire-error-close-button");
act(() => {
2022-12-29 16:35:19 +01:00
fireEvent.click(btn);
});
expect(stopBeaconSpy).toHaveBeenCalledWith(getBeaconInfoIdentifier(room2Beacon1));
});
});
});
});