2022-10-07 04:27:28 +02:00
|
|
|
/*
|
2024-09-09 15:57:16 +02:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2022-10-07 04:27:28 +02:00
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
|
2024-09-09 15:57:16 +02:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2022-10-07 04:27:28 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
import React from "react";
|
|
|
|
import { mocked, Mocked } from "jest-mock";
|
2024-10-14 18:11:58 +02:00
|
|
|
import { screen, render, act, cleanup } from "jest-matrix-react";
|
2023-01-04 05:44:38 +01:00
|
|
|
import userEvent from "@testing-library/user-event";
|
2023-08-09 09:18:41 +02:00
|
|
|
import { MatrixClient, PendingEventOrdering, Room, MatrixEvent, RoomStateEvent } from "matrix-js-sdk/src/matrix";
|
2022-10-07 04:27:28 +02:00
|
|
|
import { Widget, ClientWidgetApi } from "matrix-widget-api";
|
2023-01-04 05:44:38 +01:00
|
|
|
import { UserEvent } from "@testing-library/user-event/dist/types/setup/setup";
|
2022-10-07 04:27:28 +02:00
|
|
|
|
2023-08-04 13:22:08 +02:00
|
|
|
import type { RoomMember } from "matrix-js-sdk/src/matrix";
|
2022-10-07 04:27:28 +02:00
|
|
|
import {
|
|
|
|
useMockedCalls,
|
|
|
|
MockedCall,
|
|
|
|
mkRoomMember,
|
|
|
|
stubClient,
|
|
|
|
setupAsyncStoreWithClient,
|
|
|
|
resetAsyncStoreWithClient,
|
|
|
|
wrapInMatrixClientContext,
|
2022-11-10 09:38:48 +01:00
|
|
|
wrapInSdkContext,
|
|
|
|
mkRoomCreateEvent,
|
2023-01-04 05:44:38 +01:00
|
|
|
mockPlatformPeg,
|
2022-12-22 11:37:07 +01:00
|
|
|
flushPromises,
|
2023-08-16 10:29:34 +02:00
|
|
|
useMockMediaDevices,
|
2024-10-15 15:57:26 +02:00
|
|
|
} from "../../../test-utils";
|
|
|
|
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
|
|
|
import { CallStore } from "../../../../src/stores/CallStore";
|
|
|
|
import { WidgetMessagingStore } from "../../../../src/stores/widgets/WidgetMessagingStore";
|
|
|
|
import { PipContainer as UnwrappedPipContainer } from "../../../../src/components/structures/PipContainer";
|
|
|
|
import ActiveWidgetStore from "../../../../src/stores/ActiveWidgetStore";
|
|
|
|
import DMRoomMap from "../../../../src/utils/DMRoomMap";
|
|
|
|
import defaultDispatcher from "../../../../src/dispatcher/dispatcher";
|
|
|
|
import { Action } from "../../../../src/dispatcher/actions";
|
|
|
|
import { ViewRoomPayload } from "../../../../src/dispatcher/payloads/ViewRoomPayload";
|
2023-01-04 05:44:38 +01:00
|
|
|
import { TestSdkContext } from "../../TestSdkContext";
|
2022-11-10 09:38:48 +01:00
|
|
|
import {
|
|
|
|
VoiceBroadcastInfoState,
|
2022-11-24 09:08:41 +01:00
|
|
|
VoiceBroadcastPlaybacksStore,
|
2022-11-10 09:38:48 +01:00
|
|
|
VoiceBroadcastPreRecording,
|
|
|
|
VoiceBroadcastPreRecordingStore,
|
|
|
|
VoiceBroadcastRecording,
|
|
|
|
VoiceBroadcastRecordingsStore,
|
2024-10-15 15:57:26 +02:00
|
|
|
} from "../../../../src/voice-broadcast";
|
2023-01-04 05:44:38 +01:00
|
|
|
import { mkVoiceBroadcastInfoStateEvent } from "../../voice-broadcast/utils/test-utils";
|
2024-10-15 15:57:26 +02:00
|
|
|
import { RoomViewStore } from "../../../../src/stores/RoomViewStore";
|
|
|
|
import { IRoomStateEventsActionPayload } from "../../../../src/actions/MatrixActionCreators";
|
|
|
|
import { Container, WidgetLayoutStore } from "../../../../src/stores/widgets/WidgetLayoutStore";
|
|
|
|
import WidgetStore from "../../../../src/stores/WidgetStore";
|
|
|
|
import { WidgetType } from "../../../../src/widgets/WidgetType";
|
|
|
|
import { SdkContextClass } from "../../../../src/contexts/SDKContext";
|
|
|
|
import { ElementWidgetActions } from "../../../../src/stores/widgets/ElementWidgetActions";
|
2023-01-04 05:44:38 +01:00
|
|
|
|
2024-10-15 15:57:26 +02:00
|
|
|
jest.mock("../../../../src/stores/OwnProfileStore", () => ({
|
2024-01-08 13:11:44 +01:00
|
|
|
OwnProfileStore: {
|
|
|
|
instance: {
|
|
|
|
isProfileInfoFetched: true,
|
|
|
|
removeListener: jest.fn(),
|
|
|
|
getHttpAvatarUrl: jest.fn().mockReturnValue("http://avatar_url"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
|
2023-01-04 05:44:38 +01:00
|
|
|
describe("PipContainer", () => {
|
2022-10-07 04:27:28 +02:00
|
|
|
useMockedCalls();
|
|
|
|
jest.spyOn(HTMLMediaElement.prototype, "play").mockImplementation(async () => {});
|
|
|
|
|
2023-01-04 05:44:38 +01:00
|
|
|
let user: UserEvent;
|
2022-11-10 09:38:48 +01:00
|
|
|
let sdkContext: TestSdkContext;
|
2022-10-07 04:27:28 +02:00
|
|
|
let client: Mocked<MatrixClient>;
|
|
|
|
let room: Room;
|
2022-11-24 09:08:41 +01:00
|
|
|
let room2: Room;
|
2022-10-07 04:27:28 +02:00
|
|
|
let alice: RoomMember;
|
2022-11-10 09:38:48 +01:00
|
|
|
let voiceBroadcastRecordingsStore: VoiceBroadcastRecordingsStore;
|
|
|
|
let voiceBroadcastPreRecordingStore: VoiceBroadcastPreRecordingStore;
|
2022-11-24 09:08:41 +01:00
|
|
|
let voiceBroadcastPlaybacksStore: VoiceBroadcastPlaybacksStore;
|
2022-10-07 04:27:28 +02:00
|
|
|
|
2022-12-22 11:37:07 +01:00
|
|
|
const actFlushPromises = async () => {
|
2024-11-20 14:29:23 +01:00
|
|
|
await flushPromises();
|
2022-12-22 11:37:07 +01:00
|
|
|
};
|
|
|
|
|
2022-10-07 04:27:28 +02:00
|
|
|
beforeEach(async () => {
|
2023-08-16 10:29:34 +02:00
|
|
|
useMockMediaDevices();
|
|
|
|
|
2023-01-04 05:44:38 +01:00
|
|
|
user = userEvent.setup();
|
|
|
|
|
2022-10-07 04:27:28 +02:00
|
|
|
stubClient();
|
2023-06-05 19:12:23 +02:00
|
|
|
client = mocked(MatrixClientPeg.safeGet());
|
2024-01-08 13:11:44 +01:00
|
|
|
client.getUserId.mockReturnValue("@alice:example.org");
|
|
|
|
client.getSafeUserId.mockReturnValue("@alice:example.org");
|
2023-05-23 17:24:12 +02:00
|
|
|
DMRoomMap.makeShared(client);
|
2022-10-07 04:27:28 +02:00
|
|
|
|
|
|
|
room = new Room("!1:example.org", client, "@alice:example.org", {
|
|
|
|
pendingEventOrdering: PendingEventOrdering.Detached,
|
|
|
|
});
|
|
|
|
alice = mkRoomMember(room.roomId, "@alice:example.org");
|
2022-11-24 09:08:41 +01:00
|
|
|
|
|
|
|
room2 = new Room("!2:example.com", client, "@alice:example.org", {
|
|
|
|
pendingEventOrdering: PendingEventOrdering.Detached,
|
|
|
|
});
|
|
|
|
client.getRoom.mockImplementation((roomId: string) => {
|
|
|
|
if (roomId === room.roomId) return room;
|
|
|
|
if (roomId === room2.roomId) return room2;
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
client.getRooms.mockReturnValue([room, room2]);
|
|
|
|
client.reEmitter.reEmit(room, [RoomStateEvent.Events]);
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
room.currentState.setStateEvents([mkRoomCreateEvent(alice.userId, room.roomId)]);
|
|
|
|
jest.spyOn(room, "getMember").mockImplementation((userId) => (userId === alice.userId ? alice : null));
|
2022-10-07 04:27:28 +02:00
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
room2.currentState.setStateEvents([mkRoomCreateEvent(alice.userId, room2.roomId)]);
|
2022-10-07 04:27:28 +02:00
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
await Promise.all(
|
|
|
|
[CallStore.instance, WidgetMessagingStore.instance].map((store) =>
|
|
|
|
setupAsyncStoreWithClient(store, client),
|
|
|
|
),
|
|
|
|
);
|
2022-11-10 09:38:48 +01:00
|
|
|
|
|
|
|
sdkContext = new TestSdkContext();
|
2023-01-04 05:44:38 +01:00
|
|
|
// @ts-ignore PipContainer uses SDKContext in the constructor
|
|
|
|
SdkContextClass.instance = sdkContext;
|
2022-11-10 09:38:48 +01:00
|
|
|
voiceBroadcastRecordingsStore = new VoiceBroadcastRecordingsStore();
|
|
|
|
voiceBroadcastPreRecordingStore = new VoiceBroadcastPreRecordingStore();
|
2023-01-02 13:21:33 +01:00
|
|
|
voiceBroadcastPlaybacksStore = new VoiceBroadcastPlaybacksStore(voiceBroadcastRecordingsStore);
|
2022-11-10 09:38:48 +01:00
|
|
|
sdkContext.client = client;
|
|
|
|
sdkContext._VoiceBroadcastRecordingsStore = voiceBroadcastRecordingsStore;
|
|
|
|
sdkContext._VoiceBroadcastPreRecordingStore = voiceBroadcastPreRecordingStore;
|
2022-11-24 09:08:41 +01:00
|
|
|
sdkContext._VoiceBroadcastPlaybacksStore = voiceBroadcastPlaybacksStore;
|
2022-10-07 04:27:28 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(async () => {
|
|
|
|
cleanup();
|
|
|
|
await Promise.all([CallStore.instance, WidgetMessagingStore.instance].map(resetAsyncStoreWithClient));
|
|
|
|
client.reEmitter.stopReEmitting(room, [RoomStateEvent.Events]);
|
2023-08-16 12:20:48 +02:00
|
|
|
jest.clearAllMocks();
|
2022-10-07 04:27:28 +02:00
|
|
|
});
|
|
|
|
|
2022-11-10 09:38:48 +01:00
|
|
|
const renderPip = () => {
|
2023-01-04 05:44:38 +01:00
|
|
|
const PipContainer = wrapInMatrixClientContext(wrapInSdkContext(UnwrappedPipContainer, sdkContext));
|
|
|
|
render(<PipContainer />);
|
2022-11-10 09:38:48 +01:00
|
|
|
};
|
2022-10-07 04:27:28 +02:00
|
|
|
|
2023-01-04 05:44:38 +01:00
|
|
|
const viewRoom = (roomId: string) => {
|
2022-12-12 12:24:14 +01:00
|
|
|
defaultDispatcher.dispatch<ViewRoomPayload>(
|
|
|
|
{
|
|
|
|
action: Action.ViewRoom,
|
|
|
|
room_id: roomId,
|
|
|
|
metricsTrigger: undefined,
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
);
|
2023-01-04 05:44:38 +01:00
|
|
|
};
|
2022-10-07 04:27:28 +02:00
|
|
|
|
2023-01-04 05:44:38 +01:00
|
|
|
const withCall = async (fn: (call: MockedCall) => Promise<void>): Promise<void> => {
|
2022-10-07 04:27:28 +02:00
|
|
|
MockedCall.create(room, "1");
|
|
|
|
const call = CallStore.instance.getCall(room.roomId);
|
|
|
|
if (!(call instanceof MockedCall)) throw new Error("Failed to create call");
|
|
|
|
|
|
|
|
const widget = new Widget(call.widget);
|
|
|
|
await act(async () => {
|
2024-11-20 14:29:23 +01:00
|
|
|
WidgetStore.instance.addVirtualWidget(call.widget, room.roomId);
|
|
|
|
WidgetMessagingStore.instance.storeMessaging(widget, room.roomId, {
|
|
|
|
stop: () => {},
|
|
|
|
} as unknown as ClientWidgetApi);
|
|
|
|
|
2024-01-29 17:06:12 +01:00
|
|
|
await call.start();
|
2022-10-07 04:27:28 +02:00
|
|
|
ActiveWidgetStore.instance.setWidgetPersistence(widget.id, room.roomId, true);
|
|
|
|
});
|
|
|
|
|
2023-01-04 05:44:38 +01:00
|
|
|
await fn(call);
|
2022-10-07 04:27:28 +02:00
|
|
|
|
|
|
|
cleanup();
|
2024-11-20 14:29:23 +01:00
|
|
|
act(() => {
|
|
|
|
call.destroy();
|
|
|
|
ActiveWidgetStore.instance.destroyPersistentWidget(widget.id, room.roomId);
|
|
|
|
WidgetStore.instance.removeVirtualWidget(widget.id, room.roomId);
|
|
|
|
});
|
2022-10-07 04:27:28 +02:00
|
|
|
};
|
|
|
|
|
2023-01-04 05:44:38 +01:00
|
|
|
const withWidget = async (fn: () => Promise<void>): Promise<void> => {
|
2022-10-07 04:27:28 +02:00
|
|
|
act(() => ActiveWidgetStore.instance.setWidgetPersistence("1", room.roomId, true));
|
2023-01-04 05:44:38 +01:00
|
|
|
await fn();
|
2022-10-07 04:27:28 +02:00
|
|
|
cleanup();
|
|
|
|
ActiveWidgetStore.instance.destroyPersistentWidget("1", room.roomId);
|
|
|
|
};
|
|
|
|
|
2022-11-24 09:08:41 +01:00
|
|
|
const makeVoiceBroadcastInfoStateEvent = (): MatrixEvent => {
|
|
|
|
return mkVoiceBroadcastInfoStateEvent(
|
2022-11-22 07:57:38 +01:00
|
|
|
room.roomId,
|
|
|
|
VoiceBroadcastInfoState.Started,
|
|
|
|
alice.userId,
|
|
|
|
client.getDeviceId() || "",
|
|
|
|
);
|
2022-11-24 09:08:41 +01:00
|
|
|
};
|
2022-11-22 07:57:38 +01:00
|
|
|
|
2022-11-24 09:08:41 +01:00
|
|
|
const setUpVoiceBroadcastRecording = () => {
|
|
|
|
const infoEvent = makeVoiceBroadcastInfoStateEvent();
|
|
|
|
const voiceBroadcastRecording = new VoiceBroadcastRecording(infoEvent, client);
|
2022-11-22 07:57:38 +01:00
|
|
|
voiceBroadcastRecordingsStore.setCurrent(voiceBroadcastRecording);
|
|
|
|
};
|
|
|
|
|
|
|
|
const setUpVoiceBroadcastPreRecording = () => {
|
|
|
|
const voiceBroadcastPreRecording = new VoiceBroadcastPreRecording(
|
|
|
|
room,
|
|
|
|
alice,
|
|
|
|
client,
|
2022-11-30 11:16:22 +01:00
|
|
|
voiceBroadcastPlaybacksStore,
|
2022-11-22 07:57:38 +01:00
|
|
|
voiceBroadcastRecordingsStore,
|
|
|
|
);
|
|
|
|
voiceBroadcastPreRecordingStore.setCurrent(voiceBroadcastPreRecording);
|
|
|
|
};
|
|
|
|
|
2022-11-24 09:08:41 +01:00
|
|
|
const setUpRoomViewStore = () => {
|
2023-01-04 05:44:38 +01:00
|
|
|
sdkContext._RoomViewStore = new RoomViewStore(defaultDispatcher, sdkContext);
|
2022-11-24 09:08:41 +01:00
|
|
|
};
|
|
|
|
|
2022-12-15 12:43:01 +01:00
|
|
|
const mkVoiceBroadcast = (room: Room): MatrixEvent => {
|
2022-11-24 09:08:41 +01:00
|
|
|
const infoEvent = makeVoiceBroadcastInfoStateEvent();
|
|
|
|
room.currentState.setStateEvents([infoEvent]);
|
2022-12-12 12:24:14 +01:00
|
|
|
defaultDispatcher.dispatch<IRoomStateEventsActionPayload>(
|
|
|
|
{
|
|
|
|
action: "MatrixActions.RoomState.events",
|
|
|
|
event: infoEvent,
|
|
|
|
state: room.currentState,
|
|
|
|
lastStateEvent: null,
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
);
|
2022-11-24 09:08:41 +01:00
|
|
|
return infoEvent;
|
|
|
|
};
|
|
|
|
|
2022-10-07 04:27:28 +02:00
|
|
|
it("hides if there's no content", () => {
|
|
|
|
renderPip();
|
|
|
|
expect(screen.queryByRole("complementary")).toBeNull();
|
|
|
|
});
|
|
|
|
|
2023-01-04 05:44:38 +01:00
|
|
|
it("shows an active call with back and leave buttons", async () => {
|
2022-10-07 04:27:28 +02:00
|
|
|
renderPip();
|
|
|
|
|
2023-01-04 05:44:38 +01:00
|
|
|
await withCall(async (call) => {
|
2022-10-07 04:27:28 +02:00
|
|
|
screen.getByRole("complementary");
|
|
|
|
|
2023-01-04 05:44:38 +01:00
|
|
|
// The return button should jump to the call
|
2022-10-07 04:27:28 +02:00
|
|
|
const dispatcherSpy = jest.fn();
|
|
|
|
const dispatcherRef = defaultDispatcher.register(dispatcherSpy);
|
2023-01-04 05:44:38 +01:00
|
|
|
await user.click(screen.getByRole("button", { name: "Back" }));
|
|
|
|
expect(dispatcherSpy).toHaveBeenCalledWith({
|
|
|
|
action: Action.ViewRoom,
|
|
|
|
room_id: room.roomId,
|
|
|
|
view_call: true,
|
|
|
|
metricsTrigger: expect.any(String),
|
|
|
|
});
|
2022-10-07 04:27:28 +02:00
|
|
|
defaultDispatcher.unregister(dispatcherRef);
|
2023-01-04 05:44:38 +01:00
|
|
|
|
|
|
|
// The leave button should disconnect from the call
|
|
|
|
const disconnectSpy = jest.spyOn(call, "disconnect");
|
|
|
|
await user.click(screen.getByRole("button", { name: "Leave" }));
|
|
|
|
expect(disconnectSpy).toHaveBeenCalled();
|
2022-10-07 04:27:28 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-01-04 05:44:38 +01:00
|
|
|
it("shows a persistent widget with back button when viewing the room", async () => {
|
|
|
|
setUpRoomViewStore();
|
2022-10-07 04:27:28 +02:00
|
|
|
viewRoom(room.roomId);
|
2023-01-04 05:44:38 +01:00
|
|
|
const widget = WidgetStore.instance.addVirtualWidget(
|
|
|
|
{
|
|
|
|
id: "1",
|
2024-01-08 13:11:44 +01:00
|
|
|
creatorUserId: "@alice:example.org",
|
2023-01-04 05:44:38 +01:00
|
|
|
type: WidgetType.CUSTOM.preferred,
|
|
|
|
url: "https://example.org",
|
|
|
|
name: "Example widget",
|
|
|
|
},
|
|
|
|
room.roomId,
|
|
|
|
);
|
2022-10-07 04:27:28 +02:00
|
|
|
renderPip();
|
|
|
|
|
2023-01-04 05:44:38 +01:00
|
|
|
await withWidget(async () => {
|
2022-10-07 04:27:28 +02:00
|
|
|
screen.getByRole("complementary");
|
2023-01-04 05:44:38 +01:00
|
|
|
|
|
|
|
// The return button should maximize the widget
|
|
|
|
const moveSpy = jest.spyOn(WidgetLayoutStore.instance, "moveToContainer");
|
2024-01-08 13:11:44 +01:00
|
|
|
await user.click(await screen.findByRole("button", { name: "Back" }));
|
2023-01-04 05:44:38 +01:00
|
|
|
expect(moveSpy).toHaveBeenCalledWith(room, widget, Container.Center);
|
|
|
|
|
|
|
|
expect(screen.queryByRole("button", { name: "Leave" })).toBeNull();
|
2022-10-07 04:27:28 +02:00
|
|
|
});
|
2023-01-04 05:44:38 +01:00
|
|
|
|
|
|
|
WidgetStore.instance.removeVirtualWidget("1", room.roomId);
|
2022-10-07 04:27:28 +02:00
|
|
|
});
|
|
|
|
|
2023-01-04 05:44:38 +01:00
|
|
|
it("shows a persistent Jitsi widget with back and leave buttons when not viewing the room", async () => {
|
|
|
|
mockPlatformPeg({ supportsJitsiScreensharing: () => true });
|
|
|
|
setUpRoomViewStore();
|
2022-11-24 09:08:41 +01:00
|
|
|
viewRoom(room2.roomId);
|
2023-01-04 05:44:38 +01:00
|
|
|
const widget = WidgetStore.instance.addVirtualWidget(
|
|
|
|
{
|
|
|
|
id: "1",
|
2024-01-08 13:11:44 +01:00
|
|
|
creatorUserId: "@alice:example.org",
|
2023-01-04 05:44:38 +01:00
|
|
|
type: WidgetType.JITSI.preferred,
|
|
|
|
url: "https://meet.example.org",
|
|
|
|
name: "Jitsi example",
|
|
|
|
},
|
|
|
|
room.roomId,
|
|
|
|
);
|
2022-10-07 04:27:28 +02:00
|
|
|
renderPip();
|
|
|
|
|
2023-01-04 05:44:38 +01:00
|
|
|
await withWidget(async () => {
|
2022-10-07 04:27:28 +02:00
|
|
|
screen.getByRole("complementary");
|
2023-01-04 05:44:38 +01:00
|
|
|
|
|
|
|
// The return button should view the room
|
|
|
|
const dispatcherSpy = jest.fn();
|
|
|
|
const dispatcherRef = defaultDispatcher.register(dispatcherSpy);
|
2024-01-08 13:11:44 +01:00
|
|
|
await user.click(await screen.findByRole("button", { name: "Back" }));
|
2023-01-04 05:44:38 +01:00
|
|
|
expect(dispatcherSpy).toHaveBeenCalledWith({
|
|
|
|
action: Action.ViewRoom,
|
|
|
|
room_id: room.roomId,
|
|
|
|
metricsTrigger: expect.any(String),
|
|
|
|
});
|
|
|
|
defaultDispatcher.unregister(dispatcherRef);
|
|
|
|
|
|
|
|
// The leave button should hangup the call
|
|
|
|
const sendSpy = jest
|
|
|
|
.fn<
|
|
|
|
ReturnType<ClientWidgetApi["transport"]["send"]>,
|
|
|
|
Parameters<ClientWidgetApi["transport"]["send"]>
|
|
|
|
>()
|
|
|
|
.mockResolvedValue({});
|
|
|
|
const mockMessaging = { transport: { send: sendSpy }, stop: () => {} } as unknown as ClientWidgetApi;
|
|
|
|
WidgetMessagingStore.instance.storeMessaging(new Widget(widget), room.roomId, mockMessaging);
|
|
|
|
await user.click(screen.getByRole("button", { name: "Leave" }));
|
|
|
|
expect(sendSpy).toHaveBeenCalledWith(ElementWidgetActions.HangupCall, {});
|
2022-10-07 04:27:28 +02:00
|
|
|
});
|
2023-01-04 05:44:38 +01:00
|
|
|
|
|
|
|
WidgetStore.instance.removeVirtualWidget("1", room.roomId);
|
2022-10-07 04:27:28 +02:00
|
|
|
});
|
2022-11-10 09:38:48 +01:00
|
|
|
|
2022-11-22 07:57:38 +01:00
|
|
|
describe("when there is a voice broadcast recording and pre-recording", () => {
|
2022-12-22 11:37:07 +01:00
|
|
|
beforeEach(async () => {
|
2022-11-22 07:57:38 +01:00
|
|
|
setUpVoiceBroadcastPreRecording();
|
|
|
|
setUpVoiceBroadcastRecording();
|
2022-11-10 09:38:48 +01:00
|
|
|
renderPip();
|
2022-12-22 11:37:07 +01:00
|
|
|
await actFlushPromises();
|
2022-11-10 09:38:48 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should render the voice broadcast recording PiP", () => {
|
2022-12-28 14:43:44 +01:00
|
|
|
// check for the „Live“ badge to be present
|
2022-11-24 09:08:41 +01:00
|
|
|
expect(screen.queryByText("Live")).toBeInTheDocument();
|
2022-11-10 09:38:48 +01:00
|
|
|
});
|
2022-12-28 14:43:44 +01:00
|
|
|
|
|
|
|
it("and a call it should show both, the call and the recording", async () => {
|
|
|
|
await withCall(async () => {
|
|
|
|
// Broadcast: Check for the „Live“ badge to be present
|
|
|
|
expect(screen.queryByText("Live")).toBeInTheDocument();
|
2023-01-04 05:44:38 +01:00
|
|
|
// Call: Check for the „Leave“ button to be present
|
|
|
|
screen.getByRole("button", { name: "Leave" });
|
2022-12-28 14:43:44 +01:00
|
|
|
});
|
|
|
|
});
|
2022-11-10 09:38:48 +01:00
|
|
|
});
|
|
|
|
|
2022-11-30 11:16:22 +01:00
|
|
|
describe("when there is a voice broadcast playback and pre-recording", () => {
|
2022-12-22 11:37:07 +01:00
|
|
|
beforeEach(async () => {
|
2022-12-15 12:43:01 +01:00
|
|
|
mkVoiceBroadcast(room);
|
2022-11-30 11:16:22 +01:00
|
|
|
setUpVoiceBroadcastPreRecording();
|
|
|
|
renderPip();
|
2022-12-22 11:37:07 +01:00
|
|
|
await actFlushPromises();
|
2022-11-30 11:16:22 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should render the voice broadcast pre-recording PiP", () => {
|
|
|
|
// check for the „Go live“ button
|
|
|
|
expect(screen.queryByText("Go live")).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-11-10 09:38:48 +01:00
|
|
|
describe("when there is a voice broadcast pre-recording", () => {
|
2022-12-22 11:37:07 +01:00
|
|
|
beforeEach(async () => {
|
2022-11-22 07:57:38 +01:00
|
|
|
setUpVoiceBroadcastPreRecording();
|
2022-11-10 09:38:48 +01:00
|
|
|
renderPip();
|
2022-12-22 11:37:07 +01:00
|
|
|
await actFlushPromises();
|
2022-11-10 09:38:48 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should render the voice broadcast pre-recording PiP", () => {
|
|
|
|
// check for the „Go live“ button
|
2022-11-24 09:08:41 +01:00
|
|
|
expect(screen.queryByText("Go live")).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-12-15 12:43:01 +01:00
|
|
|
describe("when listening to a voice broadcast in a room and then switching to another room", () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
setUpRoomViewStore();
|
|
|
|
viewRoom(room.roomId);
|
|
|
|
mkVoiceBroadcast(room);
|
2022-12-22 11:37:07 +01:00
|
|
|
await actFlushPromises();
|
|
|
|
|
|
|
|
expect(voiceBroadcastPlaybacksStore.getCurrent()).toBeTruthy();
|
|
|
|
|
2022-12-15 12:43:01 +01:00
|
|
|
await voiceBroadcastPlaybacksStore.getCurrent()?.start();
|
|
|
|
viewRoom(room2.roomId);
|
|
|
|
renderPip();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should render the small voice broadcast playback PiP", () => {
|
|
|
|
// check for the „pause voice broadcast“ button
|
|
|
|
expect(screen.getByLabelText("pause voice broadcast")).toBeInTheDocument();
|
|
|
|
// check for the absence of the „30s forward“ button
|
|
|
|
expect(screen.queryByLabelText("30s forward")).not.toBeInTheDocument();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-11-24 09:08:41 +01:00
|
|
|
describe("when viewing a room with a live voice broadcast", () => {
|
2022-12-15 12:43:01 +01:00
|
|
|
let startEvent!: MatrixEvent;
|
2022-11-24 09:08:41 +01:00
|
|
|
|
2022-12-22 11:37:07 +01:00
|
|
|
beforeEach(async () => {
|
2022-11-24 09:08:41 +01:00
|
|
|
setUpRoomViewStore();
|
|
|
|
viewRoom(room.roomId);
|
2022-12-15 12:43:01 +01:00
|
|
|
startEvent = mkVoiceBroadcast(room);
|
2022-11-24 09:08:41 +01:00
|
|
|
renderPip();
|
2022-12-22 11:37:07 +01:00
|
|
|
await actFlushPromises();
|
2022-11-24 09:08:41 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should render the voice broadcast playback pip", () => {
|
|
|
|
// check for the „resume voice broadcast“ button
|
|
|
|
expect(screen.queryByLabelText("play voice broadcast")).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("and the broadcast stops", () => {
|
2022-12-22 11:37:07 +01:00
|
|
|
beforeEach(async () => {
|
|
|
|
const stopEvent = mkVoiceBroadcastInfoStateEvent(
|
|
|
|
room.roomId,
|
|
|
|
VoiceBroadcastInfoState.Stopped,
|
|
|
|
alice.userId,
|
|
|
|
client.getDeviceId() || "",
|
|
|
|
startEvent,
|
|
|
|
);
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-11-24 09:08:41 +01:00
|
|
|
room.currentState.setStateEvents([stopEvent]);
|
2022-12-12 12:24:14 +01:00
|
|
|
defaultDispatcher.dispatch<IRoomStateEventsActionPayload>(
|
|
|
|
{
|
|
|
|
action: "MatrixActions.RoomState.events",
|
|
|
|
event: stopEvent,
|
|
|
|
state: room.currentState,
|
|
|
|
lastStateEvent: stopEvent,
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
);
|
2022-12-22 11:37:07 +01:00
|
|
|
await flushPromises();
|
2022-11-24 09:08:41 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should not render the voice broadcast playback pip", () => {
|
|
|
|
// check for the „resume voice broadcast“ button
|
|
|
|
expect(screen.queryByLabelText("play voice broadcast")).not.toBeInTheDocument();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("and leaving the room", () => {
|
2022-12-22 11:37:07 +01:00
|
|
|
beforeEach(async () => {
|
|
|
|
await act(async () => {
|
2022-11-24 09:08:41 +01:00
|
|
|
viewRoom(room2.roomId);
|
2022-12-22 11:37:07 +01:00
|
|
|
await flushPromises();
|
2022-11-24 09:08:41 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should not render the voice broadcast playback pip", () => {
|
|
|
|
// check for the „resume voice broadcast“ button
|
|
|
|
expect(screen.queryByLabelText("play voice broadcast")).not.toBeInTheDocument();
|
|
|
|
});
|
2022-11-10 09:38:48 +01:00
|
|
|
});
|
|
|
|
});
|
2022-10-07 04:27:28 +02:00
|
|
|
});
|