2022-10-07 02:27:28 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from "react";
|
|
|
|
import { mocked, Mocked } from "jest-mock";
|
2023-01-04 04:44:38 +00:00
|
|
|
import { screen, render, act, cleanup } from "@testing-library/react";
|
|
|
|
import userEvent from "@testing-library/user-event";
|
2022-10-07 02:27:28 +00:00
|
|
|
import { MatrixClient, PendingEventOrdering } from "matrix-js-sdk/src/client";
|
|
|
|
import { Room } from "matrix-js-sdk/src/models/room";
|
|
|
|
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
|
|
|
|
import { Widget, ClientWidgetApi } from "matrix-widget-api";
|
2022-11-24 08:08:41 +00:00
|
|
|
import { MatrixEvent } from "matrix-js-sdk/src/matrix";
|
2023-01-04 04:44:38 +00:00
|
|
|
import { UserEvent } from "@testing-library/user-event/dist/types/setup/setup";
|
2022-10-07 02:27:28 +00:00
|
|
|
|
|
|
|
import type { RoomMember } from "matrix-js-sdk/src/models/room-member";
|
|
|
|
import {
|
|
|
|
useMockedCalls,
|
|
|
|
MockedCall,
|
|
|
|
mkRoomMember,
|
|
|
|
stubClient,
|
|
|
|
setupAsyncStoreWithClient,
|
|
|
|
resetAsyncStoreWithClient,
|
|
|
|
wrapInMatrixClientContext,
|
2022-11-10 08:38:48 +00:00
|
|
|
wrapInSdkContext,
|
|
|
|
mkRoomCreateEvent,
|
2023-01-04 04:44:38 +00:00
|
|
|
mockPlatformPeg,
|
2022-12-22 10:37:07 +00:00
|
|
|
flushPromises,
|
2023-01-04 04:44:38 +00: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";
|
|
|
|
import { TestSdkContext } from "../../TestSdkContext";
|
2022-11-10 08:38:48 +00:00
|
|
|
import {
|
|
|
|
VoiceBroadcastInfoState,
|
2022-11-24 08:08:41 +00:00
|
|
|
VoiceBroadcastPlaybacksStore,
|
2022-11-10 08:38:48 +00:00
|
|
|
VoiceBroadcastPreRecording,
|
|
|
|
VoiceBroadcastPreRecordingStore,
|
|
|
|
VoiceBroadcastRecording,
|
|
|
|
VoiceBroadcastRecordingsStore,
|
2023-01-04 04:44:38 +00:00
|
|
|
} from "../../../src/voice-broadcast";
|
|
|
|
import { mkVoiceBroadcastInfoStateEvent } from "../../voice-broadcast/utils/test-utils";
|
|
|
|
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";
|
|
|
|
|
|
|
|
describe("PipContainer", () => {
|
2022-10-07 02:27:28 +00:00
|
|
|
useMockedCalls();
|
|
|
|
jest.spyOn(HTMLMediaElement.prototype, "play").mockImplementation(async () => {});
|
|
|
|
|
2023-01-04 04:44:38 +00:00
|
|
|
let user: UserEvent;
|
2022-11-10 08:38:48 +00:00
|
|
|
let sdkContext: TestSdkContext;
|
2022-10-07 02:27:28 +00:00
|
|
|
let client: Mocked<MatrixClient>;
|
|
|
|
let room: Room;
|
2022-11-24 08:08:41 +00:00
|
|
|
let room2: Room;
|
2022-10-07 02:27:28 +00:00
|
|
|
let alice: RoomMember;
|
2022-11-10 08:38:48 +00:00
|
|
|
let voiceBroadcastRecordingsStore: VoiceBroadcastRecordingsStore;
|
|
|
|
let voiceBroadcastPreRecordingStore: VoiceBroadcastPreRecordingStore;
|
2022-11-24 08:08:41 +00:00
|
|
|
let voiceBroadcastPlaybacksStore: VoiceBroadcastPlaybacksStore;
|
2022-10-07 02:27:28 +00:00
|
|
|
|
2022-12-22 10:37:07 +00:00
|
|
|
const actFlushPromises = async () => {
|
|
|
|
await act(async () => {
|
|
|
|
await flushPromises();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-10-07 02:27:28 +00:00
|
|
|
beforeEach(async () => {
|
2023-01-04 04:44:38 +00:00
|
|
|
user = userEvent.setup();
|
|
|
|
|
2022-10-07 02:27:28 +00:00
|
|
|
stubClient();
|
|
|
|
client = mocked(MatrixClientPeg.get());
|
2023-05-23 15:24:12 +00:00
|
|
|
DMRoomMap.makeShared(client);
|
2022-10-07 02:27:28 +00:00
|
|
|
|
|
|
|
room = new Room("!1:example.org", client, "@alice:example.org", {
|
|
|
|
pendingEventOrdering: PendingEventOrdering.Detached,
|
|
|
|
});
|
|
|
|
alice = mkRoomMember(room.roomId, "@alice:example.org");
|
2022-11-24 08:08:41 +00: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 11:24:14 +00:00
|
|
|
room.currentState.setStateEvents([mkRoomCreateEvent(alice.userId, room.roomId)]);
|
|
|
|
jest.spyOn(room, "getMember").mockImplementation((userId) => (userId === alice.userId ? alice : null));
|
2022-10-07 02:27:28 +00:00
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
room2.currentState.setStateEvents([mkRoomCreateEvent(alice.userId, room2.roomId)]);
|
2022-10-07 02:27:28 +00:00
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
await Promise.all(
|
|
|
|
[CallStore.instance, WidgetMessagingStore.instance].map((store) =>
|
|
|
|
setupAsyncStoreWithClient(store, client),
|
|
|
|
),
|
|
|
|
);
|
2022-11-10 08:38:48 +00:00
|
|
|
|
|
|
|
sdkContext = new TestSdkContext();
|
2023-01-04 04:44:38 +00:00
|
|
|
// @ts-ignore PipContainer uses SDKContext in the constructor
|
|
|
|
SdkContextClass.instance = sdkContext;
|
2022-11-10 08:38:48 +00:00
|
|
|
voiceBroadcastRecordingsStore = new VoiceBroadcastRecordingsStore();
|
|
|
|
voiceBroadcastPreRecordingStore = new VoiceBroadcastPreRecordingStore();
|
2023-01-02 12:21:33 +00:00
|
|
|
voiceBroadcastPlaybacksStore = new VoiceBroadcastPlaybacksStore(voiceBroadcastRecordingsStore);
|
2022-11-10 08:38:48 +00:00
|
|
|
sdkContext.client = client;
|
|
|
|
sdkContext._VoiceBroadcastRecordingsStore = voiceBroadcastRecordingsStore;
|
|
|
|
sdkContext._VoiceBroadcastPreRecordingStore = voiceBroadcastPreRecordingStore;
|
2022-11-24 08:08:41 +00:00
|
|
|
sdkContext._VoiceBroadcastPlaybacksStore = voiceBroadcastPlaybacksStore;
|
2022-10-07 02:27:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(async () => {
|
|
|
|
cleanup();
|
|
|
|
await Promise.all([CallStore.instance, WidgetMessagingStore.instance].map(resetAsyncStoreWithClient));
|
|
|
|
client.reEmitter.stopReEmitting(room, [RoomStateEvent.Events]);
|
|
|
|
jest.restoreAllMocks();
|
|
|
|
});
|
|
|
|
|
2022-11-10 08:38:48 +00:00
|
|
|
const renderPip = () => {
|
2023-01-04 04:44:38 +00:00
|
|
|
const PipContainer = wrapInMatrixClientContext(wrapInSdkContext(UnwrappedPipContainer, sdkContext));
|
|
|
|
render(<PipContainer />);
|
2022-11-10 08:38:48 +00:00
|
|
|
};
|
2022-10-07 02:27:28 +00:00
|
|
|
|
2023-01-04 04:44:38 +00:00
|
|
|
const viewRoom = (roomId: string) => {
|
2022-12-12 11:24:14 +00:00
|
|
|
defaultDispatcher.dispatch<ViewRoomPayload>(
|
|
|
|
{
|
|
|
|
action: Action.ViewRoom,
|
|
|
|
room_id: roomId,
|
|
|
|
metricsTrigger: undefined,
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
);
|
2023-01-04 04:44:38 +00:00
|
|
|
};
|
2022-10-07 02:27:28 +00:00
|
|
|
|
2023-01-04 04:44:38 +00:00
|
|
|
const withCall = async (fn: (call: MockedCall) => Promise<void>): Promise<void> => {
|
2022-10-07 02:27:28 +00: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);
|
|
|
|
WidgetMessagingStore.instance.storeMessaging(widget, room.roomId, {
|
|
|
|
stop: () => {},
|
|
|
|
} as unknown as ClientWidgetApi);
|
|
|
|
|
|
|
|
await act(async () => {
|
|
|
|
await call.connect();
|
|
|
|
ActiveWidgetStore.instance.setWidgetPersistence(widget.id, room.roomId, true);
|
|
|
|
});
|
|
|
|
|
2023-01-04 04:44:38 +00:00
|
|
|
await fn(call);
|
2022-10-07 02:27:28 +00:00
|
|
|
|
|
|
|
cleanup();
|
|
|
|
call.destroy();
|
|
|
|
ActiveWidgetStore.instance.destroyPersistentWidget(widget.id, room.roomId);
|
|
|
|
};
|
|
|
|
|
2023-01-04 04:44:38 +00:00
|
|
|
const withWidget = async (fn: () => Promise<void>): Promise<void> => {
|
2022-10-07 02:27:28 +00:00
|
|
|
act(() => ActiveWidgetStore.instance.setWidgetPersistence("1", room.roomId, true));
|
2023-01-04 04:44:38 +00:00
|
|
|
await fn();
|
2022-10-07 02:27:28 +00:00
|
|
|
cleanup();
|
|
|
|
ActiveWidgetStore.instance.destroyPersistentWidget("1", room.roomId);
|
|
|
|
};
|
|
|
|
|
2022-11-24 08:08:41 +00:00
|
|
|
const makeVoiceBroadcastInfoStateEvent = (): MatrixEvent => {
|
|
|
|
return mkVoiceBroadcastInfoStateEvent(
|
2022-11-22 06:57:38 +00:00
|
|
|
room.roomId,
|
|
|
|
VoiceBroadcastInfoState.Started,
|
|
|
|
alice.userId,
|
|
|
|
client.getDeviceId() || "",
|
|
|
|
);
|
2022-11-24 08:08:41 +00:00
|
|
|
};
|
2022-11-22 06:57:38 +00:00
|
|
|
|
2022-11-24 08:08:41 +00:00
|
|
|
const setUpVoiceBroadcastRecording = () => {
|
|
|
|
const infoEvent = makeVoiceBroadcastInfoStateEvent();
|
|
|
|
const voiceBroadcastRecording = new VoiceBroadcastRecording(infoEvent, client);
|
2022-11-22 06:57:38 +00:00
|
|
|
voiceBroadcastRecordingsStore.setCurrent(voiceBroadcastRecording);
|
|
|
|
};
|
|
|
|
|
|
|
|
const setUpVoiceBroadcastPreRecording = () => {
|
|
|
|
const voiceBroadcastPreRecording = new VoiceBroadcastPreRecording(
|
|
|
|
room,
|
|
|
|
alice,
|
|
|
|
client,
|
2022-11-30 10:16:22 +00:00
|
|
|
voiceBroadcastPlaybacksStore,
|
2022-11-22 06:57:38 +00:00
|
|
|
voiceBroadcastRecordingsStore,
|
|
|
|
);
|
|
|
|
voiceBroadcastPreRecordingStore.setCurrent(voiceBroadcastPreRecording);
|
|
|
|
};
|
|
|
|
|
2022-11-24 08:08:41 +00:00
|
|
|
const setUpRoomViewStore = () => {
|
2023-01-04 04:44:38 +00:00
|
|
|
sdkContext._RoomViewStore = new RoomViewStore(defaultDispatcher, sdkContext);
|
2022-11-24 08:08:41 +00:00
|
|
|
};
|
|
|
|
|
2022-12-15 11:43:01 +00:00
|
|
|
const mkVoiceBroadcast = (room: Room): MatrixEvent => {
|
2022-11-24 08:08:41 +00:00
|
|
|
const infoEvent = makeVoiceBroadcastInfoStateEvent();
|
|
|
|
room.currentState.setStateEvents([infoEvent]);
|
2022-12-12 11:24:14 +00:00
|
|
|
defaultDispatcher.dispatch<IRoomStateEventsActionPayload>(
|
|
|
|
{
|
|
|
|
action: "MatrixActions.RoomState.events",
|
|
|
|
event: infoEvent,
|
|
|
|
state: room.currentState,
|
|
|
|
lastStateEvent: null,
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
);
|
2022-11-24 08:08:41 +00:00
|
|
|
return infoEvent;
|
|
|
|
};
|
|
|
|
|
2022-10-07 02:27:28 +00:00
|
|
|
it("hides if there's no content", () => {
|
|
|
|
renderPip();
|
|
|
|
expect(screen.queryByRole("complementary")).toBeNull();
|
|
|
|
});
|
|
|
|
|
2023-01-04 04:44:38 +00:00
|
|
|
it("shows an active call with back and leave buttons", async () => {
|
2022-10-07 02:27:28 +00:00
|
|
|
renderPip();
|
|
|
|
|
2023-01-04 04:44:38 +00:00
|
|
|
await withCall(async (call) => {
|
2022-10-07 02:27:28 +00:00
|
|
|
screen.getByRole("complementary");
|
|
|
|
|
2023-01-04 04:44:38 +00:00
|
|
|
// The return button should jump to the call
|
2022-10-07 02:27:28 +00:00
|
|
|
const dispatcherSpy = jest.fn();
|
|
|
|
const dispatcherRef = defaultDispatcher.register(dispatcherSpy);
|
2023-01-04 04:44:38 +00: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 02:27:28 +00:00
|
|
|
defaultDispatcher.unregister(dispatcherRef);
|
2023-01-04 04:44:38 +00: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 02:27:28 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-01-04 04:44:38 +00:00
|
|
|
it("shows a persistent widget with back button when viewing the room", async () => {
|
|
|
|
setUpRoomViewStore();
|
2022-10-07 02:27:28 +00:00
|
|
|
viewRoom(room.roomId);
|
2023-01-04 04:44:38 +00:00
|
|
|
const widget = WidgetStore.instance.addVirtualWidget(
|
|
|
|
{
|
|
|
|
id: "1",
|
|
|
|
creatorUserId: "@alice:exaxmple.org",
|
|
|
|
type: WidgetType.CUSTOM.preferred,
|
|
|
|
url: "https://example.org",
|
|
|
|
name: "Example widget",
|
|
|
|
},
|
|
|
|
room.roomId,
|
|
|
|
);
|
2022-10-07 02:27:28 +00:00
|
|
|
renderPip();
|
|
|
|
|
2023-01-04 04:44:38 +00:00
|
|
|
await withWidget(async () => {
|
2022-10-07 02:27:28 +00:00
|
|
|
screen.getByRole("complementary");
|
2023-01-04 04:44:38 +00:00
|
|
|
|
|
|
|
// The return button should maximize the widget
|
|
|
|
const moveSpy = jest.spyOn(WidgetLayoutStore.instance, "moveToContainer");
|
|
|
|
await user.click(screen.getByRole("button", { name: "Back" }));
|
|
|
|
expect(moveSpy).toHaveBeenCalledWith(room, widget, Container.Center);
|
|
|
|
|
|
|
|
expect(screen.queryByRole("button", { name: "Leave" })).toBeNull();
|
2022-10-07 02:27:28 +00:00
|
|
|
});
|
2023-01-04 04:44:38 +00:00
|
|
|
|
|
|
|
WidgetStore.instance.removeVirtualWidget("1", room.roomId);
|
2022-10-07 02:27:28 +00:00
|
|
|
});
|
|
|
|
|
2023-01-04 04:44:38 +00: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 08:08:41 +00:00
|
|
|
viewRoom(room2.roomId);
|
2023-01-04 04:44:38 +00:00
|
|
|
const widget = WidgetStore.instance.addVirtualWidget(
|
|
|
|
{
|
|
|
|
id: "1",
|
|
|
|
creatorUserId: "@alice:exaxmple.org",
|
|
|
|
type: WidgetType.JITSI.preferred,
|
|
|
|
url: "https://meet.example.org",
|
|
|
|
name: "Jitsi example",
|
|
|
|
},
|
|
|
|
room.roomId,
|
|
|
|
);
|
2022-10-07 02:27:28 +00:00
|
|
|
renderPip();
|
|
|
|
|
2023-01-04 04:44:38 +00:00
|
|
|
await withWidget(async () => {
|
2022-10-07 02:27:28 +00:00
|
|
|
screen.getByRole("complementary");
|
2023-01-04 04:44:38 +00:00
|
|
|
|
|
|
|
// The return button should view the room
|
|
|
|
const dispatcherSpy = jest.fn();
|
|
|
|
const dispatcherRef = defaultDispatcher.register(dispatcherSpy);
|
|
|
|
await user.click(screen.getByRole("button", { name: "Back" }));
|
|
|
|
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 02:27:28 +00:00
|
|
|
});
|
2023-01-04 04:44:38 +00:00
|
|
|
|
|
|
|
WidgetStore.instance.removeVirtualWidget("1", room.roomId);
|
2022-10-07 02:27:28 +00:00
|
|
|
});
|
2022-11-10 08:38:48 +00:00
|
|
|
|
2022-11-22 06:57:38 +00:00
|
|
|
describe("when there is a voice broadcast recording and pre-recording", () => {
|
2022-12-22 10:37:07 +00:00
|
|
|
beforeEach(async () => {
|
2022-11-22 06:57:38 +00:00
|
|
|
setUpVoiceBroadcastPreRecording();
|
|
|
|
setUpVoiceBroadcastRecording();
|
2022-11-10 08:38:48 +00:00
|
|
|
renderPip();
|
2022-12-22 10:37:07 +00:00
|
|
|
await actFlushPromises();
|
2022-11-10 08:38:48 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should render the voice broadcast recording PiP", () => {
|
2022-12-28 13:43:44 +00:00
|
|
|
// check for the „Live“ badge to be present
|
2022-11-24 08:08:41 +00:00
|
|
|
expect(screen.queryByText("Live")).toBeInTheDocument();
|
2022-11-10 08:38:48 +00:00
|
|
|
});
|
2022-12-28 13:43:44 +00: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 04:44:38 +00:00
|
|
|
// Call: Check for the „Leave“ button to be present
|
|
|
|
screen.getByRole("button", { name: "Leave" });
|
2022-12-28 13:43:44 +00:00
|
|
|
});
|
|
|
|
});
|
2022-11-10 08:38:48 +00:00
|
|
|
});
|
|
|
|
|
2022-11-30 10:16:22 +00:00
|
|
|
describe("when there is a voice broadcast playback and pre-recording", () => {
|
2022-12-22 10:37:07 +00:00
|
|
|
beforeEach(async () => {
|
2022-12-15 11:43:01 +00:00
|
|
|
mkVoiceBroadcast(room);
|
2022-11-30 10:16:22 +00:00
|
|
|
setUpVoiceBroadcastPreRecording();
|
|
|
|
renderPip();
|
2022-12-22 10:37:07 +00:00
|
|
|
await actFlushPromises();
|
2022-11-30 10:16:22 +00: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 08:38:48 +00:00
|
|
|
describe("when there is a voice broadcast pre-recording", () => {
|
2022-12-22 10:37:07 +00:00
|
|
|
beforeEach(async () => {
|
2022-11-22 06:57:38 +00:00
|
|
|
setUpVoiceBroadcastPreRecording();
|
2022-11-10 08:38:48 +00:00
|
|
|
renderPip();
|
2022-12-22 10:37:07 +00:00
|
|
|
await actFlushPromises();
|
2022-11-10 08:38:48 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should render the voice broadcast pre-recording PiP", () => {
|
|
|
|
// check for the „Go live“ button
|
2022-11-24 08:08:41 +00:00
|
|
|
expect(screen.queryByText("Go live")).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-12-15 11:43:01 +00: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 10:37:07 +00:00
|
|
|
await actFlushPromises();
|
|
|
|
|
|
|
|
expect(voiceBroadcastPlaybacksStore.getCurrent()).toBeTruthy();
|
|
|
|
|
2022-12-15 11:43:01 +00: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 08:08:41 +00:00
|
|
|
describe("when viewing a room with a live voice broadcast", () => {
|
2022-12-15 11:43:01 +00:00
|
|
|
let startEvent!: MatrixEvent;
|
2022-11-24 08:08:41 +00:00
|
|
|
|
2022-12-22 10:37:07 +00:00
|
|
|
beforeEach(async () => {
|
2022-11-24 08:08:41 +00:00
|
|
|
setUpRoomViewStore();
|
|
|
|
viewRoom(room.roomId);
|
2022-12-15 11:43:01 +00:00
|
|
|
startEvent = mkVoiceBroadcast(room);
|
2022-11-24 08:08:41 +00:00
|
|
|
renderPip();
|
2022-12-22 10:37:07 +00:00
|
|
|
await actFlushPromises();
|
2022-11-24 08:08:41 +00: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 10:37:07 +00:00
|
|
|
beforeEach(async () => {
|
|
|
|
const stopEvent = mkVoiceBroadcastInfoStateEvent(
|
|
|
|
room.roomId,
|
|
|
|
VoiceBroadcastInfoState.Stopped,
|
|
|
|
alice.userId,
|
|
|
|
client.getDeviceId() || "",
|
|
|
|
startEvent,
|
|
|
|
);
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-11-24 08:08:41 +00:00
|
|
|
room.currentState.setStateEvents([stopEvent]);
|
2022-12-12 11:24:14 +00:00
|
|
|
defaultDispatcher.dispatch<IRoomStateEventsActionPayload>(
|
|
|
|
{
|
|
|
|
action: "MatrixActions.RoomState.events",
|
|
|
|
event: stopEvent,
|
|
|
|
state: room.currentState,
|
|
|
|
lastStateEvent: stopEvent,
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
);
|
2022-12-22 10:37:07 +00:00
|
|
|
await flushPromises();
|
2022-11-24 08:08:41 +00: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 10:37:07 +00:00
|
|
|
beforeEach(async () => {
|
|
|
|
await act(async () => {
|
2022-11-24 08:08:41 +00:00
|
|
|
viewRoom(room2.roomId);
|
2022-12-22 10:37:07 +00:00
|
|
|
await flushPromises();
|
2022-11-24 08:08:41 +00: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 08:38:48 +00:00
|
|
|
});
|
|
|
|
});
|
2022-10-07 02:27:28 +00:00
|
|
|
});
|