2022-11-10 16:38:48 +08:00
|
|
|
/*
|
2024-09-09 21:57:16 +08:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2022-11-10 16:38:48 +08:00
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
|
2024-09-09 21:57:16 +08: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 16:38:48 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
import { MatrixClient, Room, RoomMember } from "matrix-js-sdk/src/matrix";
|
|
|
|
|
|
|
|
import {
|
|
|
|
startNewVoiceBroadcastRecording,
|
2022-11-30 18:16:22 +08:00
|
|
|
VoiceBroadcastPlaybacksStore,
|
2022-11-10 16:38:48 +08:00
|
|
|
VoiceBroadcastPreRecording,
|
|
|
|
VoiceBroadcastRecordingsStore,
|
2024-10-15 21:57:26 +08:00
|
|
|
} from "../../../../src/voice-broadcast";
|
|
|
|
import { stubClient } from "../../../test-utils";
|
2022-11-10 16:38:48 +08:00
|
|
|
|
2024-10-15 21:57:26 +08:00
|
|
|
jest.mock("../../../../src/voice-broadcast/utils/startNewVoiceBroadcastRecording");
|
2022-11-10 16:38:48 +08:00
|
|
|
|
|
|
|
describe("VoiceBroadcastPreRecording", () => {
|
|
|
|
const roomId = "!room:example.com";
|
|
|
|
let client: MatrixClient;
|
|
|
|
let room: Room;
|
|
|
|
let sender: RoomMember;
|
2022-11-30 18:16:22 +08:00
|
|
|
let playbacksStore: VoiceBroadcastPlaybacksStore;
|
2022-11-10 16:38:48 +08: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 20:21:33 +08:00
|
|
|
playbacksStore = new VoiceBroadcastPlaybacksStore(recordingsStore);
|
2022-11-10 16:38:48 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
onDismiss = jest.fn();
|
2022-11-30 18:16:22 +08:00
|
|
|
preRecording = new VoiceBroadcastPreRecording(room, sender, client, playbacksStore, recordingsStore);
|
2022-11-10 16:38:48 +08:00
|
|
|
preRecording.on("dismiss", onDismiss);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("start", () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
preRecording.start();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should start a new voice broadcast recording", () => {
|
|
|
|
expect(startNewVoiceBroadcastRecording).toHaveBeenCalledWith(room, client, playbacksStore, recordingsStore);
|
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|