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