mirror of
https://github.com/Novaloop-AG/healthchat-web.git
synced 2026-11-06 14:38:21 +00:00
Prepare for repo merge
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
Copyright 2024 New Vector Ltd.
|
||||
Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { mocked } from "jest-mock";
|
||||
import { MatrixClient, MatrixEvent, Room } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import {
|
||||
VoiceBroadcastInfoState,
|
||||
VoiceBroadcastPlayback,
|
||||
VoiceBroadcastPlaybackEvent,
|
||||
VoiceBroadcastPlaybacksStore,
|
||||
VoiceBroadcastPlaybacksStoreEvent,
|
||||
VoiceBroadcastPlaybackState,
|
||||
VoiceBroadcastRecordingsStore,
|
||||
} from "../../../src/voice-broadcast";
|
||||
import { mkStubRoom, stubClient } from "../../test-utils";
|
||||
import { mkVoiceBroadcastInfoStateEvent } from "../utils/test-utils";
|
||||
|
||||
describe("VoiceBroadcastPlaybacksStore", () => {
|
||||
const roomId = "!room:example.com";
|
||||
let client: MatrixClient;
|
||||
let userId: string;
|
||||
let deviceId: string;
|
||||
let room: Room;
|
||||
let infoEvent1: MatrixEvent;
|
||||
let infoEvent2: MatrixEvent;
|
||||
let playback1: VoiceBroadcastPlayback;
|
||||
let playback2: VoiceBroadcastPlayback;
|
||||
let playbacks: VoiceBroadcastPlaybacksStore;
|
||||
let onCurrentChanged: (playback: VoiceBroadcastPlayback | null) => void;
|
||||
|
||||
beforeEach(() => {
|
||||
client = stubClient();
|
||||
userId = client.getUserId() || "";
|
||||
deviceId = client.getDeviceId() || "";
|
||||
mocked(client.relations).mockClear();
|
||||
mocked(client.relations).mockResolvedValue({ events: [] });
|
||||
|
||||
room = mkStubRoom(roomId, "test room", client);
|
||||
mocked(client.getRoom).mockImplementation((roomId: string): Room | null => {
|
||||
if (roomId === room.roomId) {
|
||||
return room;
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
infoEvent1 = mkVoiceBroadcastInfoStateEvent(roomId, VoiceBroadcastInfoState.Started, userId, deviceId);
|
||||
infoEvent2 = mkVoiceBroadcastInfoStateEvent(roomId, VoiceBroadcastInfoState.Started, userId, deviceId);
|
||||
const recordings = new VoiceBroadcastRecordingsStore();
|
||||
playback1 = new VoiceBroadcastPlayback(infoEvent1, client, recordings);
|
||||
jest.spyOn(playback1, "off");
|
||||
playback2 = new VoiceBroadcastPlayback(infoEvent2, client, recordings);
|
||||
jest.spyOn(playback2, "off");
|
||||
|
||||
playbacks = new VoiceBroadcastPlaybacksStore(recordings);
|
||||
jest.spyOn(playbacks, "removeAllListeners");
|
||||
onCurrentChanged = jest.fn();
|
||||
playbacks.on(VoiceBroadcastPlaybacksStoreEvent.CurrentChanged, onCurrentChanged);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
playbacks.off(VoiceBroadcastPlaybacksStoreEvent.CurrentChanged, onCurrentChanged);
|
||||
});
|
||||
|
||||
describe("when setting a current Voice Broadcast playback", () => {
|
||||
beforeEach(() => {
|
||||
playbacks.setCurrent(playback1);
|
||||
});
|
||||
|
||||
it("should return it as current", () => {
|
||||
expect(playbacks.getCurrent()).toBe(playback1);
|
||||
});
|
||||
|
||||
it("should return it by id", () => {
|
||||
expect(playbacks.getByInfoEvent(infoEvent1, client)).toBe(playback1);
|
||||
});
|
||||
|
||||
it("should emit a CurrentChanged event", () => {
|
||||
expect(onCurrentChanged).toHaveBeenCalledWith(playback1);
|
||||
});
|
||||
|
||||
describe("and setting the same again", () => {
|
||||
beforeEach(() => {
|
||||
mocked(onCurrentChanged).mockClear();
|
||||
playbacks.setCurrent(playback1);
|
||||
});
|
||||
|
||||
it("should not emit a CurrentChanged event", () => {
|
||||
expect(onCurrentChanged).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("and setting another playback and start both", () => {
|
||||
beforeEach(() => {
|
||||
playbacks.setCurrent(playback2);
|
||||
playback1.start();
|
||||
playback2.start();
|
||||
});
|
||||
|
||||
it("should set playback1 to paused", () => {
|
||||
expect(playback1.getState()).toBe(VoiceBroadcastPlaybackState.Paused);
|
||||
});
|
||||
|
||||
it("should set playback2 to buffering", () => {
|
||||
// buffering because there are no chunks, yet
|
||||
expect(playback2.getState()).toBe(VoiceBroadcastPlaybackState.Buffering);
|
||||
});
|
||||
|
||||
describe("and calling destroy", () => {
|
||||
beforeEach(() => {
|
||||
playbacks.destroy();
|
||||
});
|
||||
|
||||
it("should remove all listeners", () => {
|
||||
expect(playbacks.removeAllListeners).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should deregister the listeners on the playbacks", () => {
|
||||
expect(playback1.off).toHaveBeenCalledWith(
|
||||
VoiceBroadcastPlaybackEvent.StateChanged,
|
||||
expect.any(Function),
|
||||
);
|
||||
expect(playback2.off).toHaveBeenCalledWith(
|
||||
VoiceBroadcastPlaybackEvent.StateChanged,
|
||||
expect.any(Function),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("getByInfoEventId", () => {
|
||||
let returnedPlayback: VoiceBroadcastPlayback;
|
||||
|
||||
describe("when retrieving a known playback", () => {
|
||||
beforeEach(() => {
|
||||
playbacks.setCurrent(playback1);
|
||||
returnedPlayback = playbacks.getByInfoEvent(infoEvent1, client);
|
||||
});
|
||||
|
||||
it("should return the playback", () => {
|
||||
expect(returnedPlayback).toBe(playback1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when retrieving an unknown playback", () => {
|
||||
beforeEach(() => {
|
||||
returnedPlayback = playbacks.getByInfoEvent(infoEvent1, client);
|
||||
});
|
||||
|
||||
it("should return the playback", () => {
|
||||
expect(returnedPlayback.infoEvent).toBe(infoEvent1);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
Copyright 2024 New Vector Ltd.
|
||||
Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { mocked } from "jest-mock";
|
||||
import { MatrixClient, Room, RoomMember } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import {
|
||||
VoiceBroadcastPlaybacksStore,
|
||||
VoiceBroadcastPreRecording,
|
||||
VoiceBroadcastPreRecordingStore,
|
||||
VoiceBroadcastRecordingsStore,
|
||||
} from "../../../src/voice-broadcast";
|
||||
import { stubClient } from "../../test-utils";
|
||||
|
||||
describe("VoiceBroadcastPreRecordingStore", () => {
|
||||
const roomId = "!room:example.com";
|
||||
let client: MatrixClient;
|
||||
let room: Room;
|
||||
let sender: RoomMember;
|
||||
let playbacksStore: VoiceBroadcastPlaybacksStore;
|
||||
let recordingsStore: VoiceBroadcastRecordingsStore;
|
||||
let store: VoiceBroadcastPreRecordingStore;
|
||||
let preRecording1: VoiceBroadcastPreRecording;
|
||||
|
||||
beforeAll(() => {
|
||||
client = stubClient();
|
||||
room = new Room(roomId, client, client.getUserId() || "");
|
||||
sender = new RoomMember(roomId, client.getUserId() || "");
|
||||
recordingsStore = new VoiceBroadcastRecordingsStore();
|
||||
playbacksStore = new VoiceBroadcastPlaybacksStore(recordingsStore);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
store = new VoiceBroadcastPreRecordingStore();
|
||||
jest.spyOn(store, "emit");
|
||||
jest.spyOn(store, "removeAllListeners");
|
||||
preRecording1 = new VoiceBroadcastPreRecording(room, sender, client, playbacksStore, recordingsStore);
|
||||
jest.spyOn(preRecording1, "off");
|
||||
});
|
||||
|
||||
it("getCurrent() should return null", () => {
|
||||
expect(store.getCurrent()).toBeNull();
|
||||
});
|
||||
|
||||
it("clearCurrent() should work", () => {
|
||||
store.clearCurrent();
|
||||
expect(store.getCurrent()).toBeNull();
|
||||
});
|
||||
|
||||
describe("when setting a current recording", () => {
|
||||
beforeEach(() => {
|
||||
store.setCurrent(preRecording1);
|
||||
});
|
||||
|
||||
it("getCurrent() should return the recording", () => {
|
||||
expect(store.getCurrent()).toBe(preRecording1);
|
||||
});
|
||||
|
||||
it("should emit a changed event with the recording", () => {
|
||||
expect(store.emit).toHaveBeenCalledWith("changed", preRecording1);
|
||||
});
|
||||
|
||||
describe("and calling destroy()", () => {
|
||||
beforeEach(() => {
|
||||
store.destroy();
|
||||
});
|
||||
|
||||
it("should remove all listeners", () => {
|
||||
expect(store.removeAllListeners).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should deregister from the pre-recordings", () => {
|
||||
expect(preRecording1.off).toHaveBeenCalledWith("dismiss", expect.any(Function));
|
||||
});
|
||||
});
|
||||
|
||||
describe("and cancelling the pre-recording", () => {
|
||||
beforeEach(() => {
|
||||
preRecording1.cancel();
|
||||
});
|
||||
|
||||
it("should clear the current recording", () => {
|
||||
expect(store.getCurrent()).toBeNull();
|
||||
});
|
||||
|
||||
it("should emit a changed event with null", () => {
|
||||
expect(store.emit).toHaveBeenCalledWith("changed", null);
|
||||
});
|
||||
});
|
||||
|
||||
describe("and setting the same pre-recording again", () => {
|
||||
beforeEach(() => {
|
||||
mocked(store.emit).mockClear();
|
||||
store.setCurrent(preRecording1);
|
||||
});
|
||||
|
||||
it("should not emit a changed event", () => {
|
||||
expect(store.emit).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("and setting another pre-recording", () => {
|
||||
let preRecording2: VoiceBroadcastPreRecording;
|
||||
|
||||
beforeEach(() => {
|
||||
mocked(store.emit).mockClear();
|
||||
mocked(preRecording1.off).mockClear();
|
||||
preRecording2 = new VoiceBroadcastPreRecording(room, sender, client, playbacksStore, recordingsStore);
|
||||
store.setCurrent(preRecording2);
|
||||
});
|
||||
|
||||
it("should deregister from the current pre-recording", () => {
|
||||
expect(preRecording1.off).toHaveBeenCalledWith("dismiss", expect.any(Function));
|
||||
});
|
||||
|
||||
it("getCurrent() should return the new recording", () => {
|
||||
expect(store.getCurrent()).toBe(preRecording2);
|
||||
});
|
||||
|
||||
it("should emit a changed event with the new recording", () => {
|
||||
expect(store.emit).toHaveBeenCalledWith("changed", preRecording2);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
Copyright 2024 New Vector Ltd.
|
||||
Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { mocked } from "jest-mock";
|
||||
import { MatrixClient, MatrixEvent, Room } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import {
|
||||
VoiceBroadcastRecordingsStore,
|
||||
VoiceBroadcastRecordingsStoreEvent,
|
||||
VoiceBroadcastRecording,
|
||||
VoiceBroadcastInfoState,
|
||||
} from "../../../src/voice-broadcast";
|
||||
import { mkStubRoom, stubClient } from "../../test-utils";
|
||||
import { mkVoiceBroadcastInfoStateEvent } from "../utils/test-utils";
|
||||
|
||||
describe("VoiceBroadcastRecordingsStore", () => {
|
||||
const roomId = "!room:example.com";
|
||||
let client: MatrixClient;
|
||||
let room: Room;
|
||||
let infoEvent: MatrixEvent;
|
||||
let otherInfoEvent: MatrixEvent;
|
||||
let recording: VoiceBroadcastRecording;
|
||||
let otherRecording: VoiceBroadcastRecording;
|
||||
let recordings: VoiceBroadcastRecordingsStore;
|
||||
let onCurrentChanged: (recording: VoiceBroadcastRecording | null) => void;
|
||||
|
||||
beforeEach(() => {
|
||||
client = stubClient();
|
||||
room = mkStubRoom(roomId, "test room", client);
|
||||
mocked(client.getRoom).mockImplementation((roomId: string) => {
|
||||
if (roomId === room.roomId) {
|
||||
return room;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
infoEvent = mkVoiceBroadcastInfoStateEvent(
|
||||
roomId,
|
||||
VoiceBroadcastInfoState.Started,
|
||||
client.getUserId()!,
|
||||
client.getDeviceId()!,
|
||||
);
|
||||
otherInfoEvent = mkVoiceBroadcastInfoStateEvent(
|
||||
roomId,
|
||||
VoiceBroadcastInfoState.Started,
|
||||
client.getUserId()!,
|
||||
client.getDeviceId()!,
|
||||
);
|
||||
recording = new VoiceBroadcastRecording(infoEvent, client);
|
||||
otherRecording = new VoiceBroadcastRecording(otherInfoEvent, client);
|
||||
recordings = new VoiceBroadcastRecordingsStore();
|
||||
onCurrentChanged = jest.fn();
|
||||
recordings.on(VoiceBroadcastRecordingsStoreEvent.CurrentChanged, onCurrentChanged);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
recording.destroy();
|
||||
recordings.off(VoiceBroadcastRecordingsStoreEvent.CurrentChanged, onCurrentChanged);
|
||||
});
|
||||
|
||||
it("when setting a recording without info event Id, it should raise an error", () => {
|
||||
infoEvent.event.event_id = undefined;
|
||||
expect(() => {
|
||||
recordings.setCurrent(recording);
|
||||
}).toThrow("Got broadcast info event without Id");
|
||||
});
|
||||
|
||||
describe("when setting a current Voice Broadcast recording", () => {
|
||||
beforeEach(() => {
|
||||
recordings.setCurrent(recording);
|
||||
});
|
||||
|
||||
it("should return it as current", () => {
|
||||
expect(recordings.hasCurrent()).toBe(true);
|
||||
expect(recordings.getCurrent()).toBe(recording);
|
||||
});
|
||||
|
||||
it("should return it by id", () => {
|
||||
expect(recordings.getByInfoEvent(infoEvent, client)).toBe(recording);
|
||||
});
|
||||
|
||||
it("should emit a CurrentChanged event", () => {
|
||||
expect(onCurrentChanged).toHaveBeenCalledWith(recording);
|
||||
});
|
||||
|
||||
describe("and setting the same again", () => {
|
||||
beforeEach(() => {
|
||||
mocked(onCurrentChanged).mockClear();
|
||||
recordings.setCurrent(recording);
|
||||
});
|
||||
|
||||
it("should not emit a CurrentChanged event", () => {
|
||||
expect(onCurrentChanged).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("and calling clearCurrent()", () => {
|
||||
beforeEach(() => {
|
||||
recordings.clearCurrent();
|
||||
});
|
||||
|
||||
it("should clear the current recording", () => {
|
||||
expect(recordings.hasCurrent()).toBe(false);
|
||||
expect(recordings.getCurrent()).toBeNull();
|
||||
});
|
||||
|
||||
it("should emit a current changed event", () => {
|
||||
expect(onCurrentChanged).toHaveBeenCalledWith(null);
|
||||
});
|
||||
|
||||
it("and calling it again should work", () => {
|
||||
recordings.clearCurrent();
|
||||
expect(recordings.getCurrent()).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("and setting another recording and stopping the previous recording", () => {
|
||||
beforeEach(() => {
|
||||
recordings.setCurrent(otherRecording);
|
||||
recording.stop();
|
||||
});
|
||||
|
||||
it("should keep the current recording", () => {
|
||||
expect(recordings.getCurrent()).toBe(otherRecording);
|
||||
});
|
||||
});
|
||||
|
||||
describe("and the recording stops", () => {
|
||||
beforeEach(() => {
|
||||
recording.stop();
|
||||
});
|
||||
|
||||
it("should clear the current recording", () => {
|
||||
expect(recordings.getCurrent()).toBeNull();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("getByInfoEventId", () => {
|
||||
let returnedRecording: VoiceBroadcastRecording;
|
||||
|
||||
describe("when retrieving a known recording", () => {
|
||||
beforeEach(() => {
|
||||
recordings.setCurrent(recording);
|
||||
returnedRecording = recordings.getByInfoEvent(infoEvent, client);
|
||||
});
|
||||
|
||||
it("should return the recording", () => {
|
||||
expect(returnedRecording).toBe(recording);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when retrieving an unknown recording", () => {
|
||||
beforeEach(() => {
|
||||
returnedRecording = recordings.getByInfoEvent(infoEvent, client);
|
||||
});
|
||||
|
||||
it("should return the recording", () => {
|
||||
expect(returnedRecording.infoEvent).toBe(infoEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user