You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-08-07 21:23:00 +03:00
Merge branch 'develop' into feat/add-message-edition-wysiwyg-composer
This commit is contained in:
@@ -820,19 +820,25 @@ describe("ElementCall", () => {
|
||||
await call.connect();
|
||||
|
||||
messaging.emit(
|
||||
`action:${ElementWidgetActions.Screenshare}`,
|
||||
`action:${ElementWidgetActions.ScreenshareRequest}`,
|
||||
new CustomEvent("widgetapirequest", { detail: {} }),
|
||||
);
|
||||
|
||||
waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(messaging!.transport.reply).toHaveBeenCalledWith(
|
||||
expect.objectContaining({}),
|
||||
expect.objectContaining({ desktopCapturerSourceId: sourceId }),
|
||||
expect.objectContaining({ pending: true }),
|
||||
);
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(messaging!.transport.send).toHaveBeenCalledWith(
|
||||
"io.element.screenshare_start", expect.objectContaining({ desktopCapturerSourceId: sourceId }),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it("passes failed if we couldn't get a source id", async () => {
|
||||
it("sends ScreenshareStop if we couldn't get a source id", async () => {
|
||||
jest.spyOn(Modal, "createDialog").mockReturnValue(
|
||||
{ finished: new Promise((r) => r([null])) } as IHandle<any[]>,
|
||||
);
|
||||
@@ -841,32 +847,38 @@ describe("ElementCall", () => {
|
||||
await call.connect();
|
||||
|
||||
messaging.emit(
|
||||
`action:${ElementWidgetActions.Screenshare}`,
|
||||
`action:${ElementWidgetActions.ScreenshareRequest}`,
|
||||
new CustomEvent("widgetapirequest", { detail: {} }),
|
||||
);
|
||||
|
||||
waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(messaging!.transport.reply).toHaveBeenCalledWith(
|
||||
expect.objectContaining({}),
|
||||
expect.objectContaining({ failed: true }),
|
||||
expect.objectContaining({ pending: true }),
|
||||
);
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(messaging!.transport.send).toHaveBeenCalledWith(
|
||||
"io.element.screenshare_stop", expect.objectContaining({ }),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it("passes an empty object if we don't support desktop capturer", async () => {
|
||||
it("replies with pending: false if we don't support desktop capturer", async () => {
|
||||
jest.spyOn(PlatformPeg.get(), "supportsDesktopCapturer").mockReturnValue(false);
|
||||
|
||||
await call.connect();
|
||||
|
||||
messaging.emit(
|
||||
`action:${ElementWidgetActions.Screenshare}`,
|
||||
`action:${ElementWidgetActions.ScreenshareRequest}`,
|
||||
new CustomEvent("widgetapirequest", { detail: {} }),
|
||||
);
|
||||
|
||||
waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(messaging!.transport.reply).toHaveBeenCalledWith(
|
||||
expect.objectContaining({}),
|
||||
expect.objectContaining({}),
|
||||
expect.objectContaining({ pending: false }),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@@ -66,6 +66,8 @@ describe("StopGapWidgetDriver", () => {
|
||||
"m.always_on_screen",
|
||||
"town.robin.msc3846.turn_servers",
|
||||
"org.matrix.msc2762.timeline:!1:example.org",
|
||||
"org.matrix.msc2762.send.event:org.matrix.rageshake_request",
|
||||
"org.matrix.msc2762.receive.event:org.matrix.rageshake_request",
|
||||
"org.matrix.msc2762.receive.state_event:m.room.member",
|
||||
"org.matrix.msc2762.send.state_event:org.matrix.msc3401.call",
|
||||
"org.matrix.msc2762.receive.state_event:org.matrix.msc3401.call",
|
||||
|
@@ -74,7 +74,25 @@ describe("VoiceBroadcastPlayback", () => {
|
||||
|
||||
const itShouldEmitAStateChangedEvent = (state: VoiceBroadcastPlaybackState) => {
|
||||
it(`should emit a ${state} state changed event`, () => {
|
||||
expect(mocked(onStateChanged)).toHaveBeenCalledWith(state);
|
||||
expect(mocked(onStateChanged)).toHaveBeenCalledWith(state, playback);
|
||||
});
|
||||
};
|
||||
|
||||
const startPlayback = () => {
|
||||
beforeEach(async () => {
|
||||
await playback.start();
|
||||
});
|
||||
};
|
||||
|
||||
const pausePlayback = () => {
|
||||
beforeEach(() => {
|
||||
playback.pause();
|
||||
});
|
||||
};
|
||||
|
||||
const stopPlayback = () => {
|
||||
beforeEach(() => {
|
||||
playback.stop();
|
||||
});
|
||||
};
|
||||
|
||||
@@ -180,14 +198,28 @@ describe("VoiceBroadcastPlayback", () => {
|
||||
});
|
||||
|
||||
describe("and calling start", () => {
|
||||
beforeEach(async () => {
|
||||
await playback.start();
|
||||
});
|
||||
startPlayback();
|
||||
|
||||
it("should be in buffering state", () => {
|
||||
expect(playback.getState()).toBe(VoiceBroadcastPlaybackState.Buffering);
|
||||
});
|
||||
|
||||
describe("and calling stop", () => {
|
||||
stopPlayback();
|
||||
itShouldSetTheStateTo(VoiceBroadcastPlaybackState.Stopped);
|
||||
|
||||
describe("and calling pause", () => {
|
||||
pausePlayback();
|
||||
// stopped voice broadcasts cannot be paused
|
||||
itShouldSetTheStateTo(VoiceBroadcastPlaybackState.Stopped);
|
||||
});
|
||||
});
|
||||
|
||||
describe("and calling pause", () => {
|
||||
pausePlayback();
|
||||
itShouldSetTheStateTo(VoiceBroadcastPlaybackState.Paused);
|
||||
});
|
||||
|
||||
describe("and receiving the first chunk", () => {
|
||||
beforeEach(() => {
|
||||
// TODO Michael W: Use RelationsHelper
|
||||
@@ -212,9 +244,7 @@ describe("VoiceBroadcastPlayback", () => {
|
||||
});
|
||||
|
||||
describe("and calling start", () => {
|
||||
beforeEach(async () => {
|
||||
await playback.start();
|
||||
});
|
||||
startPlayback();
|
||||
|
||||
it("should play the last chunk", () => {
|
||||
// assert that the last chunk is played first
|
||||
@@ -258,10 +288,7 @@ describe("VoiceBroadcastPlayback", () => {
|
||||
});
|
||||
|
||||
describe("and calling start", () => {
|
||||
beforeEach(async () => {
|
||||
await playback.start();
|
||||
});
|
||||
|
||||
startPlayback();
|
||||
itShouldSetTheStateTo(VoiceBroadcastPlaybackState.Buffering);
|
||||
});
|
||||
});
|
||||
@@ -278,9 +305,7 @@ describe("VoiceBroadcastPlayback", () => {
|
||||
itShouldSetTheStateTo(VoiceBroadcastPlaybackState.Stopped);
|
||||
|
||||
describe("and calling start", () => {
|
||||
beforeEach(async () => {
|
||||
await playback.start();
|
||||
});
|
||||
startPlayback();
|
||||
|
||||
itShouldSetTheStateTo(VoiceBroadcastPlaybackState.Playing);
|
||||
|
||||
@@ -303,13 +328,15 @@ describe("VoiceBroadcastPlayback", () => {
|
||||
});
|
||||
|
||||
describe("and calling pause", () => {
|
||||
beforeEach(() => {
|
||||
playback.pause();
|
||||
});
|
||||
|
||||
pausePlayback();
|
||||
itShouldSetTheStateTo(VoiceBroadcastPlaybackState.Paused);
|
||||
itShouldEmitAStateChangedEvent(VoiceBroadcastPlaybackState.Paused);
|
||||
});
|
||||
|
||||
describe("and calling stop", () => {
|
||||
stopPlayback();
|
||||
itShouldSetTheStateTo(VoiceBroadcastPlaybackState.Stopped);
|
||||
});
|
||||
});
|
||||
|
||||
describe("and calling toggle for the first time", () => {
|
||||
@@ -337,9 +364,7 @@ describe("VoiceBroadcastPlayback", () => {
|
||||
});
|
||||
|
||||
describe("and calling stop", () => {
|
||||
beforeEach(() => {
|
||||
playback.stop();
|
||||
});
|
||||
stopPlayback();
|
||||
|
||||
itShouldSetTheStateTo(VoiceBroadcastPlaybackState.Stopped);
|
||||
|
||||
|
@@ -22,24 +22,24 @@ import {
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import {
|
||||
VoiceBroadcastInfoEventType,
|
||||
VoiceBroadcastInfoState,
|
||||
VoiceBroadcastPlayback,
|
||||
VoiceBroadcastPlaybackEvent,
|
||||
VoiceBroadcastPlaybacksStore,
|
||||
VoiceBroadcastPlaybacksStoreEvent,
|
||||
VoiceBroadcastPlaybackState,
|
||||
} from "../../../src/voice-broadcast";
|
||||
import { mkEvent, mkStubRoom, stubClient } from "../../test-utils";
|
||||
|
||||
jest.mock("../../../src/voice-broadcast/models/VoiceBroadcastPlayback", () => ({
|
||||
...jest.requireActual("../../../src/voice-broadcast/models/VoiceBroadcastPlayback") as object,
|
||||
VoiceBroadcastPlayback: jest.fn().mockImplementation((infoEvent: MatrixEvent) => ({ infoEvent })),
|
||||
}));
|
||||
import { mkStubRoom, stubClient } from "../../test-utils";
|
||||
import { mkVoiceBroadcastInfoStateEvent } from "../utils/test-utils";
|
||||
|
||||
describe("VoiceBroadcastPlaybacksStore", () => {
|
||||
const roomId = "!room:example.com";
|
||||
let client: MatrixClient;
|
||||
let room: Room;
|
||||
let infoEvent: MatrixEvent;
|
||||
let playback: VoiceBroadcastPlayback;
|
||||
let infoEvent1: MatrixEvent;
|
||||
let infoEvent2: MatrixEvent;
|
||||
let playback1: VoiceBroadcastPlayback;
|
||||
let playback2: VoiceBroadcastPlayback;
|
||||
let playbacks: VoiceBroadcastPlaybacksStore;
|
||||
let onCurrentChanged: (playback: VoiceBroadcastPlayback) => void;
|
||||
|
||||
@@ -51,17 +51,26 @@ describe("VoiceBroadcastPlaybacksStore", () => {
|
||||
return room;
|
||||
}
|
||||
});
|
||||
infoEvent = mkEvent({
|
||||
event: true,
|
||||
type: VoiceBroadcastInfoEventType,
|
||||
user: client.getUserId(),
|
||||
room: roomId,
|
||||
content: {},
|
||||
});
|
||||
playback = {
|
||||
infoEvent,
|
||||
} as unknown as VoiceBroadcastPlayback;
|
||||
|
||||
infoEvent1 = mkVoiceBroadcastInfoStateEvent(
|
||||
roomId,
|
||||
VoiceBroadcastInfoState.Started,
|
||||
client.getUserId(),
|
||||
client.getDeviceId(),
|
||||
);
|
||||
infoEvent2 = mkVoiceBroadcastInfoStateEvent(
|
||||
roomId,
|
||||
VoiceBroadcastInfoState.Started,
|
||||
client.getUserId(),
|
||||
client.getDeviceId(),
|
||||
);
|
||||
playback1 = new VoiceBroadcastPlayback(infoEvent1, client);
|
||||
jest.spyOn(playback1, "off");
|
||||
playback2 = new VoiceBroadcastPlayback(infoEvent2, client);
|
||||
jest.spyOn(playback2, "off");
|
||||
|
||||
playbacks = new VoiceBroadcastPlaybacksStore();
|
||||
jest.spyOn(playbacks, "removeAllListeners");
|
||||
onCurrentChanged = jest.fn();
|
||||
playbacks.on(VoiceBroadcastPlaybacksStoreEvent.CurrentChanged, onCurrentChanged);
|
||||
});
|
||||
@@ -72,31 +81,69 @@ describe("VoiceBroadcastPlaybacksStore", () => {
|
||||
|
||||
describe("when setting a current Voice Broadcast playback", () => {
|
||||
beforeEach(() => {
|
||||
playbacks.setCurrent(playback);
|
||||
playbacks.setCurrent(playback1);
|
||||
});
|
||||
|
||||
it("should return it as current", () => {
|
||||
expect(playbacks.getCurrent()).toBe(playback);
|
||||
expect(playbacks.getCurrent()).toBe(playback1);
|
||||
});
|
||||
|
||||
it("should return it by id", () => {
|
||||
expect(playbacks.getByInfoEvent(infoEvent, client)).toBe(playback);
|
||||
expect(playbacks.getByInfoEvent(infoEvent1, client)).toBe(playback1);
|
||||
});
|
||||
|
||||
it("should emit a CurrentChanged event", () => {
|
||||
expect(onCurrentChanged).toHaveBeenCalledWith(playback);
|
||||
expect(onCurrentChanged).toHaveBeenCalledWith(playback1);
|
||||
});
|
||||
|
||||
describe("and setting the same again", () => {
|
||||
beforeEach(() => {
|
||||
mocked(onCurrentChanged).mockClear();
|
||||
playbacks.setCurrent(playback);
|
||||
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", () => {
|
||||
@@ -104,24 +151,22 @@ describe("VoiceBroadcastPlaybacksStore", () => {
|
||||
|
||||
describe("when retrieving a known playback", () => {
|
||||
beforeEach(() => {
|
||||
playbacks.setCurrent(playback);
|
||||
returnedPlayback = playbacks.getByInfoEvent(infoEvent, client);
|
||||
playbacks.setCurrent(playback1);
|
||||
returnedPlayback = playbacks.getByInfoEvent(infoEvent1, client);
|
||||
});
|
||||
|
||||
it("should return the playback", () => {
|
||||
expect(returnedPlayback).toBe(playback);
|
||||
expect(returnedPlayback).toBe(playback1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when retrieving an unknown playback", () => {
|
||||
beforeEach(() => {
|
||||
returnedPlayback = playbacks.getByInfoEvent(infoEvent, client);
|
||||
returnedPlayback = playbacks.getByInfoEvent(infoEvent1, client);
|
||||
});
|
||||
|
||||
it("should return the playback", () => {
|
||||
expect(returnedPlayback).toEqual({
|
||||
infoEvent,
|
||||
});
|
||||
expect(returnedPlayback.infoEvent).toBe(infoEvent1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user