Fix displaying already stopped broadcasts in the timeline (#9470)
This commit is contained in:
parent
3c9ba3e69f
commit
d898af820b
3 changed files with 43 additions and 26 deletions
|
@ -49,6 +49,7 @@ export const VoiceBroadcastBody: React.FC<IBodyProps> = ({ mxEvent }) => {
|
||||||
client,
|
client,
|
||||||
);
|
);
|
||||||
relationsHelper.on(RelationsHelperEvent.Add, onInfoEvent);
|
relationsHelper.on(RelationsHelperEvent.Add, onInfoEvent);
|
||||||
|
relationsHelper.emitCurrent();
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
relationsHelper.destroy();
|
relationsHelper.destroy();
|
||||||
|
|
|
@ -17,11 +17,10 @@ limitations under the License.
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { act, render, screen } from "@testing-library/react";
|
import { act, render, screen } from "@testing-library/react";
|
||||||
import { mocked } from "jest-mock";
|
import { mocked } from "jest-mock";
|
||||||
import { MatrixClient, MatrixEvent } from "matrix-js-sdk/src/matrix";
|
import { MatrixClient, MatrixEvent, Room } from "matrix-js-sdk/src/matrix";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
VoiceBroadcastBody,
|
VoiceBroadcastBody,
|
||||||
VoiceBroadcastInfoEventType,
|
|
||||||
VoiceBroadcastInfoState,
|
VoiceBroadcastInfoState,
|
||||||
VoiceBroadcastRecordingBody,
|
VoiceBroadcastRecordingBody,
|
||||||
VoiceBroadcastRecordingsStore,
|
VoiceBroadcastRecordingsStore,
|
||||||
|
@ -30,8 +29,8 @@ import {
|
||||||
VoiceBroadcastPlayback,
|
VoiceBroadcastPlayback,
|
||||||
VoiceBroadcastPlaybacksStore,
|
VoiceBroadcastPlaybacksStore,
|
||||||
} from "../../../src/voice-broadcast";
|
} from "../../../src/voice-broadcast";
|
||||||
import { mkEvent, stubClient } from "../../test-utils";
|
import { stubClient } from "../../test-utils";
|
||||||
import { RelationsHelper } from "../../../src/events/RelationsHelper";
|
import { mkVoiceBroadcastInfoStateEvent } from "../utils/test-utils";
|
||||||
|
|
||||||
jest.mock("../../../src/voice-broadcast/components/molecules/VoiceBroadcastRecordingBody", () => ({
|
jest.mock("../../../src/voice-broadcast/components/molecules/VoiceBroadcastRecordingBody", () => ({
|
||||||
VoiceBroadcastRecordingBody: jest.fn(),
|
VoiceBroadcastRecordingBody: jest.fn(),
|
||||||
|
@ -41,27 +40,15 @@ jest.mock("../../../src/voice-broadcast/components/molecules/VoiceBroadcastPlayb
|
||||||
VoiceBroadcastPlaybackBody: jest.fn(),
|
VoiceBroadcastPlaybackBody: jest.fn(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
jest.mock("../../../src/events/RelationsHelper");
|
|
||||||
|
|
||||||
describe("VoiceBroadcastBody", () => {
|
describe("VoiceBroadcastBody", () => {
|
||||||
const roomId = "!room:example.com";
|
const roomId = "!room:example.com";
|
||||||
let client: MatrixClient;
|
let client: MatrixClient;
|
||||||
|
let room: Room;
|
||||||
let infoEvent: MatrixEvent;
|
let infoEvent: MatrixEvent;
|
||||||
|
let stoppedEvent: MatrixEvent;
|
||||||
let testRecording: VoiceBroadcastRecording;
|
let testRecording: VoiceBroadcastRecording;
|
||||||
let testPlayback: VoiceBroadcastPlayback;
|
let testPlayback: VoiceBroadcastPlayback;
|
||||||
|
|
||||||
const mkVoiceBroadcastInfoEvent = (state: VoiceBroadcastInfoState) => {
|
|
||||||
return mkEvent({
|
|
||||||
event: true,
|
|
||||||
type: VoiceBroadcastInfoEventType,
|
|
||||||
user: client.getUserId(),
|
|
||||||
room: roomId,
|
|
||||||
content: {
|
|
||||||
state,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const renderVoiceBroadcast = () => {
|
const renderVoiceBroadcast = () => {
|
||||||
render(<VoiceBroadcastBody
|
render(<VoiceBroadcastBody
|
||||||
mxEvent={infoEvent}
|
mxEvent={infoEvent}
|
||||||
|
@ -75,7 +62,19 @@ describe("VoiceBroadcastBody", () => {
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
client = stubClient();
|
client = stubClient();
|
||||||
infoEvent = mkVoiceBroadcastInfoEvent(VoiceBroadcastInfoState.Started);
|
room = new Room(roomId, client, client.getUserId());
|
||||||
|
mocked(client.getRoom).mockImplementation((getRoomId: string) => {
|
||||||
|
if (getRoomId === roomId) return room;
|
||||||
|
});
|
||||||
|
|
||||||
|
infoEvent = mkVoiceBroadcastInfoStateEvent(roomId, VoiceBroadcastInfoState.Started, client.getUserId());
|
||||||
|
stoppedEvent = mkVoiceBroadcastInfoStateEvent(
|
||||||
|
roomId,
|
||||||
|
VoiceBroadcastInfoState.Stopped,
|
||||||
|
client.getUserId(),
|
||||||
|
infoEvent,
|
||||||
|
);
|
||||||
|
room.addEventsToTimeline([infoEvent], true, room.getLiveTimeline());
|
||||||
testRecording = new VoiceBroadcastRecording(infoEvent, client);
|
testRecording = new VoiceBroadcastRecording(infoEvent, client);
|
||||||
testPlayback = new VoiceBroadcastPlayback(infoEvent, client);
|
testPlayback = new VoiceBroadcastPlayback(infoEvent, client);
|
||||||
mocked(VoiceBroadcastRecordingBody).mockImplementation(({ recording }) => {
|
mocked(VoiceBroadcastRecordingBody).mockImplementation(({ recording }) => {
|
||||||
|
@ -107,7 +106,18 @@ describe("VoiceBroadcastBody", () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when displaying a voice broadcast recording", () => {
|
describe("when there is a stopped voice broadcast", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
room.addEventsToTimeline([stoppedEvent], true, room.getLiveTimeline());
|
||||||
|
renderVoiceBroadcast();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should render a voice broadcast playback body", () => {
|
||||||
|
screen.getByTestId("voice-broadcast-playback-body");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("when there is a started voice broadcast from the current user", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
renderVoiceBroadcast();
|
renderVoiceBroadcast();
|
||||||
});
|
});
|
||||||
|
@ -118,13 +128,8 @@ describe("VoiceBroadcastBody", () => {
|
||||||
|
|
||||||
describe("and the recordings ends", () => {
|
describe("and the recordings ends", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const stoppedEvent = mkVoiceBroadcastInfoEvent(VoiceBroadcastInfoState.Stopped);
|
|
||||||
// get the RelationsHelper instanced used in VoiceBroadcastBody
|
|
||||||
const relationsHelper = mocked(RelationsHelper).mock.instances[5];
|
|
||||||
act(() => {
|
act(() => {
|
||||||
// invoke the callback of the VoiceBroadcastBody hook to simulate an ended broadcast
|
room.addEventsToTimeline([stoppedEvent], true, room.getLiveTimeline());
|
||||||
// @ts-ignore
|
|
||||||
mocked(relationsHelper.on).mock.calls[0][1](stoppedEvent);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,17 @@ export const mkVoiceBroadcastInfoStateEvent = (
|
||||||
roomId: string,
|
roomId: string,
|
||||||
state: VoiceBroadcastInfoState,
|
state: VoiceBroadcastInfoState,
|
||||||
sender: string,
|
sender: string,
|
||||||
|
startedInfoEvent?: MatrixEvent,
|
||||||
): MatrixEvent => {
|
): MatrixEvent => {
|
||||||
|
const relationContent = {};
|
||||||
|
|
||||||
|
if (startedInfoEvent) {
|
||||||
|
relationContent["m.relates_to"] = {
|
||||||
|
event_id: startedInfoEvent.getId(),
|
||||||
|
rel_type: "m.reference",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return mkEvent({
|
return mkEvent({
|
||||||
event: true,
|
event: true,
|
||||||
room: roomId,
|
room: roomId,
|
||||||
|
@ -32,6 +42,7 @@ export const mkVoiceBroadcastInfoStateEvent = (
|
||||||
skey: sender,
|
skey: sender,
|
||||||
content: {
|
content: {
|
||||||
state,
|
state,
|
||||||
|
...relationContent,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue