2022-11-10 09:38:48 +01:00
|
|
|
/*
|
2024-09-09 15:57:16 +02:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2022-11-10 09:38:48 +01: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-11-10 09:38:48 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
import { MatrixClient, Room, RoomMember } from "matrix-js-sdk/src/matrix";
|
|
|
|
|
|
|
|
import {
|
|
|
|
startNewVoiceBroadcastRecording,
|
2022-11-30 11:16:22 +01:00
|
|
|
VoiceBroadcastPlaybacksStore,
|
2022-11-10 09:38:48 +01:00
|
|
|
VoiceBroadcastPreRecording,
|
|
|
|
VoiceBroadcastRecordingsStore,
|
|
|
|
} from "../../../src/voice-broadcast";
|
|
|
|
import { stubClient } from "../../test-utils";
|
|
|
|
|
|
|
|
jest.mock("../../../src/voice-broadcast/utils/startNewVoiceBroadcastRecording");
|
|
|
|
|
|
|
|
describe("VoiceBroadcastPreRecording", () => {
|
|
|
|
const roomId = "!room:example.com";
|
|
|
|
let client: MatrixClient;
|
|
|
|
let room: Room;
|
|
|
|
let sender: RoomMember;
|
2022-11-30 11:16:22 +01:00
|
|
|
let playbacksStore: VoiceBroadcastPlaybacksStore;
|
2022-11-10 09:38:48 +01:00
|
|
|
let recordingsStore: VoiceBroadcastRecordingsStore;
|
|
|
|
let preRecording: VoiceBroadcastPreRecording;
|
|
|
|
let onDismiss: (voiceBroadcastPreRecording: VoiceBroadcastPreRecording) => void;
|
|
|
|
|
|
|
|
beforeAll(() => {
|
|
|
|
client = stubClient();
|
|
|
|
room = new Room(roomId, client, client.getUserId() || "");
|
|
|
|
sender = new RoomMember(roomId, client.getUserId() || "");
|
|
|
|
recordingsStore = new VoiceBroadcastRecordingsStore();
|
2023-01-02 13:21:33 +01:00
|
|
|
playbacksStore = new VoiceBroadcastPlaybacksStore(recordingsStore);
|
2022-11-10 09:38:48 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
onDismiss = jest.fn();
|
2022-11-30 11:16:22 +01:00
|
|
|
preRecording = new VoiceBroadcastPreRecording(room, sender, client, playbacksStore, recordingsStore);
|
2022-11-10 09:38:48 +01:00
|
|
|
preRecording.on("dismiss", onDismiss);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("start", () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
preRecording.start();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should start a new voice broadcast recording", () => {
|
2022-12-12 12:24:14 +01:00
|
|
|
expect(startNewVoiceBroadcastRecording).toHaveBeenCalledWith(room, client, playbacksStore, recordingsStore);
|
2022-11-10 09:38:48 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should emit a dismiss event", () => {
|
|
|
|
expect(onDismiss).toHaveBeenCalledWith(preRecording);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("cancel", () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
preRecording.cancel();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should emit a dismiss event", () => {
|
|
|
|
expect(onDismiss).toHaveBeenCalledWith(preRecording);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|