Apply prettier formatting
This commit is contained in:
parent
1cac306093
commit
526645c791
1576 changed files with 65385 additions and 62478 deletions
|
@ -86,13 +86,10 @@ describe("VoiceBroadcastRecorder", () => {
|
|||
};
|
||||
|
||||
const expectOnFirstChunkRecorded = (): void => {
|
||||
expect(onChunkRecorded).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
{
|
||||
buffer: concat(headers1, headers2, chunk1),
|
||||
length: 42,
|
||||
},
|
||||
);
|
||||
expect(onChunkRecorded).toHaveBeenNthCalledWith(1, {
|
||||
buffer: concat(headers1, headers2, chunk1),
|
||||
length: 42,
|
||||
});
|
||||
};
|
||||
|
||||
const itShouldNotEmitAChunkRecordedEvent = (): void => {
|
||||
|
@ -223,13 +220,10 @@ describe("VoiceBroadcastRecorder", () => {
|
|||
it("should emit ChunkRecorded events", () => {
|
||||
expectOnFirstChunkRecorded();
|
||||
|
||||
expect(onChunkRecorded).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
{
|
||||
buffer: concat(headers1, headers2, chunk2a, chunk2b),
|
||||
length: 72 - 42, // 72 (position at second chunk) - 42 (position of first chunk)
|
||||
},
|
||||
);
|
||||
expect(onChunkRecorded).toHaveBeenNthCalledWith(2, {
|
||||
buffer: concat(headers1, headers2, chunk2a, chunk2b),
|
||||
length: 72 - 42, // 72 (position at second chunk) - 42 (position of first chunk)
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -57,13 +57,15 @@ describe("VoiceBroadcastBody", () => {
|
|||
let testPlayback: VoiceBroadcastPlayback;
|
||||
|
||||
const renderVoiceBroadcast = () => {
|
||||
render(<VoiceBroadcastBody
|
||||
mxEvent={infoEvent}
|
||||
mediaEventHelper={new MediaEventHelper(infoEvent)}
|
||||
onHeightChanged={() => {}}
|
||||
onMessageAllowed={() => {}}
|
||||
permalinkCreator={new RoomPermalinkCreator(room)}
|
||||
/>);
|
||||
render(
|
||||
<VoiceBroadcastBody
|
||||
mxEvent={infoEvent}
|
||||
mediaEventHelper={new MediaEventHelper(infoEvent)}
|
||||
onHeightChanged={() => {}}
|
||||
onMessageAllowed={() => {}}
|
||||
permalinkCreator={new RoomPermalinkCreator(room)}
|
||||
/>,
|
||||
);
|
||||
testRecording = VoiceBroadcastRecordingsStore.instance().getByInfoEvent(infoEvent, client);
|
||||
};
|
||||
|
||||
|
@ -79,12 +81,7 @@ describe("VoiceBroadcastBody", () => {
|
|||
return null;
|
||||
});
|
||||
|
||||
infoEvent = mkVoiceBroadcastInfoStateEvent(
|
||||
roomId,
|
||||
VoiceBroadcastInfoState.Started,
|
||||
userId,
|
||||
deviceId,
|
||||
);
|
||||
infoEvent = mkVoiceBroadcastInfoStateEvent(roomId, VoiceBroadcastInfoState.Started, userId, deviceId);
|
||||
stoppedEvent = mkVoiceBroadcastInfoStateEvent(
|
||||
roomId,
|
||||
VoiceBroadcastInfoState.Stopped,
|
||||
|
|
|
@ -31,11 +31,7 @@ describe("VoiceBroadcastControl", () => {
|
|||
|
||||
describe("when rendering it", () => {
|
||||
beforeEach(() => {
|
||||
result = render(<VoiceBroadcastControl
|
||||
onClick={onClick}
|
||||
label="test label"
|
||||
icon={StopIcon}
|
||||
/>);
|
||||
result = render(<VoiceBroadcastControl onClick={onClick} label="test label" icon={StopIcon} />);
|
||||
});
|
||||
|
||||
it("should render as expected", () => {
|
||||
|
|
|
@ -23,7 +23,7 @@ import { mkRoom, stubClient } from "../../../test-utils";
|
|||
jest.mock("../../../../src/components/views/avatars/RoomAvatar", () => ({
|
||||
__esModule: true,
|
||||
default: jest.fn().mockImplementation(({ room }) => {
|
||||
return <div data-testid="room-avatar">room avatar: { room.name }</div>;
|
||||
return <div data-testid="room-avatar">room avatar: {room.name}</div>;
|
||||
}),
|
||||
}));
|
||||
|
||||
|
@ -35,18 +35,16 @@ describe("VoiceBroadcastHeader", () => {
|
|||
const sender = new RoomMember(roomId, userId);
|
||||
let container: Container;
|
||||
|
||||
const renderHeader = (
|
||||
live: VoiceBroadcastLiveness,
|
||||
showBroadcast?: boolean,
|
||||
buffering?: boolean,
|
||||
): RenderResult => {
|
||||
return render(<VoiceBroadcastHeader
|
||||
live={live}
|
||||
microphoneLabel={sender.name}
|
||||
room={room}
|
||||
showBroadcast={showBroadcast}
|
||||
showBuffering={buffering}
|
||||
/>);
|
||||
const renderHeader = (live: VoiceBroadcastLiveness, showBroadcast?: boolean, buffering?: boolean): RenderResult => {
|
||||
return render(
|
||||
<VoiceBroadcastHeader
|
||||
live={live}
|
||||
microphoneLabel={sender.name}
|
||||
room={room}
|
||||
showBroadcast={showBroadcast}
|
||||
showBuffering={buffering}
|
||||
/>,
|
||||
);
|
||||
};
|
||||
|
||||
beforeAll(() => {
|
||||
|
|
|
@ -35,7 +35,7 @@ import { mkVoiceBroadcastInfoStateEvent } from "../../utils/test-utils";
|
|||
jest.mock("../../../../src/components/views/avatars/RoomAvatar", () => ({
|
||||
__esModule: true,
|
||||
default: jest.fn().mockImplementation(({ room }) => {
|
||||
return <div data-testid="room-avatar">room avatar: { room.name }</div>;
|
||||
return <div data-testid="room-avatar">room avatar: {room.name}</div>;
|
||||
}),
|
||||
}));
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ jest.mock("../../../../src/utils/media/requestMediaPermissions");
|
|||
jest.mock("../../../../src/components/views/avatars/RoomAvatar", () => ({
|
||||
__esModule: true,
|
||||
default: jest.fn().mockImplementation(({ room }) => {
|
||||
return <div data-testid="room-avatar">room avatar: { room.name }</div>;
|
||||
return <div data-testid="room-avatar">room avatar: {room.name}</div>;
|
||||
}),
|
||||
}));
|
||||
|
||||
|
@ -55,11 +55,13 @@ describe("VoiceBroadcastPreRecordingPip", () => {
|
|||
sender = new RoomMember(room.roomId, client.getUserId() || "");
|
||||
playbacksStore = new VoiceBroadcastPlaybacksStore();
|
||||
recordingsStore = new VoiceBroadcastRecordingsStore();
|
||||
mocked(requestMediaPermissions).mockReturnValue(new Promise<MediaStream>((r) => {
|
||||
r({
|
||||
getTracks: () => [],
|
||||
} as unknown as MediaStream);
|
||||
}));
|
||||
mocked(requestMediaPermissions).mockReturnValue(
|
||||
new Promise<MediaStream>((r) => {
|
||||
r({
|
||||
getTracks: () => [],
|
||||
} as unknown as MediaStream);
|
||||
}),
|
||||
);
|
||||
jest.spyOn(MediaDeviceHandler, "getDevices").mockResolvedValue({
|
||||
[MediaDeviceKindEnum.AudioInput]: [
|
||||
{
|
||||
|
@ -75,13 +77,7 @@ describe("VoiceBroadcastPreRecordingPip", () => {
|
|||
[MediaDeviceKindEnum.VideoInput]: [],
|
||||
});
|
||||
jest.spyOn(MediaDeviceHandler.instance, "setDevice").mockImplementation();
|
||||
preRecording = new VoiceBroadcastPreRecording(
|
||||
room,
|
||||
sender,
|
||||
client,
|
||||
playbacksStore,
|
||||
recordingsStore,
|
||||
);
|
||||
preRecording = new VoiceBroadcastPreRecording(room, sender, client, playbacksStore, recordingsStore);
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
|
@ -90,9 +86,7 @@ describe("VoiceBroadcastPreRecordingPip", () => {
|
|||
|
||||
describe("when rendered", () => {
|
||||
beforeEach(async () => {
|
||||
renderResult = render(<VoiceBroadcastPreRecordingPip
|
||||
voiceBroadcastPreRecording={preRecording}
|
||||
/>);
|
||||
renderResult = render(<VoiceBroadcastPreRecordingPip voiceBroadcastPreRecording={preRecording} />);
|
||||
|
||||
await act(async () => {
|
||||
flushPromises();
|
||||
|
|
|
@ -30,7 +30,7 @@ import { mkEvent, stubClient } from "../../../test-utils";
|
|||
jest.mock("../../../../src/components/views/avatars/RoomAvatar", () => ({
|
||||
__esModule: true,
|
||||
default: jest.fn().mockImplementation(({ room }) => {
|
||||
return <div data-testid="room-avatar">room avatar: { room.name }</div>;
|
||||
return <div data-testid="room-avatar">room avatar: {room.name}</div>;
|
||||
}),
|
||||
}));
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ jest.mock("../../../../src/utils/media/requestMediaPermissions");
|
|||
jest.mock("../../../../src/components/views/avatars/RoomAvatar", () => ({
|
||||
__esModule: true,
|
||||
default: jest.fn().mockImplementation(({ room }) => {
|
||||
return <div data-testid="room-avatar">room avatar: { room.name }</div>;
|
||||
return <div data-testid="room-avatar">room avatar: {room.name}</div>;
|
||||
}),
|
||||
}));
|
||||
|
||||
|
@ -62,12 +62,7 @@ describe("VoiceBroadcastRecordingPip", () => {
|
|||
let restoreConsole: () => void;
|
||||
|
||||
const renderPip = async (state: VoiceBroadcastInfoState) => {
|
||||
infoEvent = mkVoiceBroadcastInfoStateEvent(
|
||||
roomId,
|
||||
state,
|
||||
client.getUserId() || "",
|
||||
client.getDeviceId() || "",
|
||||
);
|
||||
infoEvent = mkVoiceBroadcastInfoStateEvent(roomId, state, client.getUserId() || "", client.getDeviceId() || "");
|
||||
recording = new VoiceBroadcastRecording(infoEvent, client, state);
|
||||
jest.spyOn(recording, "pause");
|
||||
jest.spyOn(recording, "resume");
|
||||
|
@ -79,11 +74,13 @@ describe("VoiceBroadcastRecordingPip", () => {
|
|||
|
||||
beforeAll(() => {
|
||||
client = stubClient();
|
||||
mocked(requestMediaPermissions).mockReturnValue(new Promise<MediaStream>((r) => {
|
||||
r({
|
||||
getTracks: () => [],
|
||||
} as unknown as MediaStream);
|
||||
}));
|
||||
mocked(requestMediaPermissions).mockReturnValue(
|
||||
new Promise<MediaStream>((r) => {
|
||||
r({
|
||||
getTracks: () => [],
|
||||
} as unknown as MediaStream);
|
||||
}),
|
||||
);
|
||||
jest.spyOn(MediaDeviceHandler, "getDevices").mockResolvedValue({
|
||||
[MediaDeviceKindEnum.AudioInput]: [
|
||||
{
|
||||
|
|
|
@ -115,12 +115,7 @@ describe("VoiceBroadcastPlayback", () => {
|
|||
};
|
||||
|
||||
const mkInfoEvent = (state: VoiceBroadcastInfoState) => {
|
||||
return mkVoiceBroadcastInfoStateEvent(
|
||||
roomId,
|
||||
state,
|
||||
userId,
|
||||
deviceId,
|
||||
);
|
||||
return mkVoiceBroadcastInfoStateEvent(roomId, state, userId, deviceId);
|
||||
};
|
||||
|
||||
const mkPlayback = async () => {
|
||||
|
@ -350,7 +345,7 @@ describe("VoiceBroadcastPlayback", () => {
|
|||
});
|
||||
|
||||
describe("and skipping to the middle of the second chunk", () => {
|
||||
const middleOfSecondChunk = (chunk1Length + (chunk2Length / 2)) / 1000;
|
||||
const middleOfSecondChunk = (chunk1Length + chunk2Length / 2) / 1000;
|
||||
|
||||
beforeEach(async () => {
|
||||
await playback.skipTo(middleOfSecondChunk);
|
||||
|
|
|
@ -56,12 +56,7 @@ describe("VoiceBroadcastPreRecording", () => {
|
|||
});
|
||||
|
||||
it("should start a new voice broadcast recording", () => {
|
||||
expect(startNewVoiceBroadcastRecording).toHaveBeenCalledWith(
|
||||
room,
|
||||
client,
|
||||
playbacksStore,
|
||||
recordingsStore,
|
||||
);
|
||||
expect(startNewVoiceBroadcastRecording).toHaveBeenCalledWith(room, client, playbacksStore, recordingsStore);
|
||||
});
|
||||
|
||||
it("should emit a dismiss event", () => {
|
||||
|
|
|
@ -47,7 +47,7 @@ import dis from "../../../src/dispatcher/dispatcher";
|
|||
import { VoiceRecording } from "../../../src/audio/VoiceRecording";
|
||||
|
||||
jest.mock("../../../src/voice-broadcast/audio/VoiceBroadcastRecorder", () => ({
|
||||
...jest.requireActual("../../../src/voice-broadcast/audio/VoiceBroadcastRecorder") as object,
|
||||
...(jest.requireActual("../../../src/voice-broadcast/audio/VoiceBroadcastRecorder") as object),
|
||||
createVoiceBroadcastRecorder: jest.fn(),
|
||||
}));
|
||||
|
||||
|
@ -141,44 +141,41 @@ describe("VoiceBroadcastRecording", () => {
|
|||
new Blob([new Uint8Array(data)], { type: voiceBroadcastRecorder.contentType }),
|
||||
);
|
||||
|
||||
expect(mocked(client.sendMessage)).toHaveBeenCalledWith(
|
||||
roomId,
|
||||
{
|
||||
body: "Voice message",
|
||||
expect(mocked(client.sendMessage)).toHaveBeenCalledWith(roomId, {
|
||||
body: "Voice message",
|
||||
file: {
|
||||
file: true,
|
||||
},
|
||||
info: {
|
||||
duration,
|
||||
mimetype: "audio/ogg",
|
||||
size,
|
||||
},
|
||||
["m.relates_to"]: {
|
||||
event_id: infoEvent.getId(),
|
||||
rel_type: "m.reference",
|
||||
},
|
||||
msgtype: "m.audio",
|
||||
["org.matrix.msc1767.audio"]: {
|
||||
duration,
|
||||
waveform: undefined,
|
||||
},
|
||||
["org.matrix.msc1767.file"]: {
|
||||
file: {
|
||||
file: true,
|
||||
},
|
||||
info: {
|
||||
duration,
|
||||
mimetype: "audio/ogg",
|
||||
size,
|
||||
},
|
||||
["m.relates_to"]: {
|
||||
event_id: infoEvent.getId(),
|
||||
rel_type: "m.reference",
|
||||
},
|
||||
msgtype: "m.audio",
|
||||
["org.matrix.msc1767.audio"]: {
|
||||
duration,
|
||||
waveform: undefined,
|
||||
},
|
||||
["org.matrix.msc1767.file"]: {
|
||||
file: {
|
||||
file: true,
|
||||
},
|
||||
mimetype: "audio/ogg",
|
||||
name: "Voice message.ogg",
|
||||
size,
|
||||
url: "mxc://example.com/vb",
|
||||
},
|
||||
["org.matrix.msc1767.text"]: "Voice message",
|
||||
["org.matrix.msc3245.voice"]: {},
|
||||
mimetype: "audio/ogg",
|
||||
name: "Voice message.ogg",
|
||||
size,
|
||||
url: "mxc://example.com/vb",
|
||||
["io.element.voice_broadcast_chunk"]: {
|
||||
sequence,
|
||||
},
|
||||
},
|
||||
);
|
||||
["org.matrix.msc1767.text"]: "Voice message",
|
||||
["org.matrix.msc3245.voice"]: {},
|
||||
url: "mxc://example.com/vb",
|
||||
["io.element.voice_broadcast_chunk"]: {
|
||||
sequence,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -202,40 +199,42 @@ describe("VoiceBroadcastRecording", () => {
|
|||
file: uploadedFile,
|
||||
});
|
||||
|
||||
mocked(createVoiceMessageContent).mockImplementation((
|
||||
mxc: string,
|
||||
mimetype: string,
|
||||
duration: number,
|
||||
size: number,
|
||||
file?: IEncryptedFile,
|
||||
waveform?: number[],
|
||||
) => {
|
||||
return {
|
||||
body: "Voice message",
|
||||
msgtype: MsgType.Audio,
|
||||
url: mxc,
|
||||
file,
|
||||
info: {
|
||||
duration,
|
||||
mimetype,
|
||||
size,
|
||||
},
|
||||
["org.matrix.msc1767.text"]: "Voice message",
|
||||
["org.matrix.msc1767.file"]: {
|
||||
mocked(createVoiceMessageContent).mockImplementation(
|
||||
(
|
||||
mxc: string,
|
||||
mimetype: string,
|
||||
duration: number,
|
||||
size: number,
|
||||
file?: IEncryptedFile,
|
||||
waveform?: number[],
|
||||
) => {
|
||||
return {
|
||||
body: "Voice message",
|
||||
msgtype: MsgType.Audio,
|
||||
url: mxc,
|
||||
file,
|
||||
name: "Voice message.ogg",
|
||||
mimetype,
|
||||
size,
|
||||
},
|
||||
["org.matrix.msc1767.audio"]: {
|
||||
duration,
|
||||
// https://github.com/matrix-org/matrix-doc/pull/3246
|
||||
waveform,
|
||||
},
|
||||
["org.matrix.msc3245.voice"]: {}, // No content, this is a rendering hint
|
||||
};
|
||||
});
|
||||
info: {
|
||||
duration,
|
||||
mimetype,
|
||||
size,
|
||||
},
|
||||
["org.matrix.msc1767.text"]: "Voice message",
|
||||
["org.matrix.msc1767.file"]: {
|
||||
url: mxc,
|
||||
file,
|
||||
name: "Voice message.ogg",
|
||||
mimetype,
|
||||
size,
|
||||
},
|
||||
["org.matrix.msc1767.audio"]: {
|
||||
duration,
|
||||
// https://github.com/matrix-org/matrix-doc/pull/3246
|
||||
waveform,
|
||||
},
|
||||
["org.matrix.msc3245.voice"]: {}, // No content, this is a rendering hint
|
||||
};
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
@ -291,9 +290,12 @@ describe("VoiceBroadcastRecording", () => {
|
|||
|
||||
describe("and receiving a call action", () => {
|
||||
beforeEach(() => {
|
||||
dis.dispatch({
|
||||
action: "call_state",
|
||||
}, true);
|
||||
dis.dispatch(
|
||||
{
|
||||
action: "call_state",
|
||||
},
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
itShouldBeInState(VoiceBroadcastInfoState.Paused);
|
||||
|
@ -327,13 +329,10 @@ describe("VoiceBroadcastRecording", () => {
|
|||
|
||||
describe("and a chunk has been recorded", () => {
|
||||
beforeEach(async () => {
|
||||
voiceBroadcastRecorder.emit(
|
||||
VoiceBroadcastRecorderEvent.ChunkRecorded,
|
||||
{
|
||||
buffer: new Uint8Array([1, 2, 3]),
|
||||
length: 23,
|
||||
},
|
||||
);
|
||||
voiceBroadcastRecorder.emit(VoiceBroadcastRecorderEvent.ChunkRecorded, {
|
||||
buffer: new Uint8Array([1, 2, 3]),
|
||||
length: 23,
|
||||
});
|
||||
});
|
||||
|
||||
itShouldSendAVoiceMessage([1, 2, 3], 3, 23, 1);
|
||||
|
@ -451,21 +450,19 @@ describe("VoiceBroadcastRecording", () => {
|
|||
|
||||
const timelineSet = {
|
||||
relations: {
|
||||
getChildEventsForEvent: jest.fn().mockImplementation(
|
||||
(
|
||||
eventId: string,
|
||||
relationType: RelationType | string,
|
||||
eventType: EventType | string,
|
||||
) => {
|
||||
if (
|
||||
eventId === infoEvent.getId()
|
||||
&& relationType === RelationType.Reference
|
||||
&& eventType === VoiceBroadcastInfoEventType
|
||||
) {
|
||||
return relationsContainer;
|
||||
}
|
||||
},
|
||||
),
|
||||
getChildEventsForEvent: jest
|
||||
.fn()
|
||||
.mockImplementation(
|
||||
(eventId: string, relationType: RelationType | string, eventType: EventType | string) => {
|
||||
if (
|
||||
eventId === infoEvent.getId() &&
|
||||
relationType === RelationType.Reference &&
|
||||
eventType === VoiceBroadcastInfoEventType
|
||||
) {
|
||||
return relationsContainer;
|
||||
}
|
||||
},
|
||||
),
|
||||
},
|
||||
} as unknown as EventTimelineSet;
|
||||
mocked(room.getUnfilteredTimelineSet).mockReturnValue(timelineSet);
|
||||
|
|
|
@ -15,11 +15,7 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import { mocked } from "jest-mock";
|
||||
import {
|
||||
MatrixClient,
|
||||
MatrixEvent,
|
||||
Room,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { MatrixClient, MatrixEvent, Room } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import {
|
||||
VoiceBroadcastInfoState,
|
||||
|
@ -61,18 +57,8 @@ describe("VoiceBroadcastPlaybacksStore", () => {
|
|||
return null;
|
||||
});
|
||||
|
||||
infoEvent1 = mkVoiceBroadcastInfoStateEvent(
|
||||
roomId,
|
||||
VoiceBroadcastInfoState.Started,
|
||||
userId,
|
||||
deviceId,
|
||||
);
|
||||
infoEvent2 = mkVoiceBroadcastInfoStateEvent(
|
||||
roomId,
|
||||
VoiceBroadcastInfoState.Started,
|
||||
userId,
|
||||
deviceId,
|
||||
);
|
||||
infoEvent1 = mkVoiceBroadcastInfoStateEvent(roomId, VoiceBroadcastInfoState.Started, userId, deviceId);
|
||||
infoEvent2 = mkVoiceBroadcastInfoStateEvent(roomId, VoiceBroadcastInfoState.Started, userId, deviceId);
|
||||
playback1 = new VoiceBroadcastPlayback(infoEvent1, client);
|
||||
jest.spyOn(playback1, "off");
|
||||
playback2 = new VoiceBroadcastPlayback(infoEvent2, client);
|
||||
|
|
|
@ -50,11 +50,7 @@ describe("VoiceBroadcastChunkEvents", () => {
|
|||
beforeEach(() => {
|
||||
chunkEvents.addEvent(eventSeq2Time4);
|
||||
chunkEvents.addEvent(eventSeq1Time1);
|
||||
chunkEvents.addEvents([
|
||||
eventSeq4Time1,
|
||||
eventSeq2Time4Dup,
|
||||
eventSeq3Time2,
|
||||
]);
|
||||
chunkEvents.addEvents([eventSeq4Time1, eventSeq2Time4Dup, eventSeq3Time2]);
|
||||
});
|
||||
|
||||
it("should provide the events sort by sequence", () => {
|
||||
|
@ -122,12 +118,7 @@ describe("VoiceBroadcastChunkEvents", () => {
|
|||
beforeEach(() => {
|
||||
chunkEvents.addEvent(eventSeq2Time4);
|
||||
chunkEvents.addEvent(eventSeq1Time1);
|
||||
chunkEvents.addEvents([
|
||||
eventSeq4Time1,
|
||||
eventSeqUTime3,
|
||||
eventSeq2Time4Dup,
|
||||
eventSeq3Time2,
|
||||
]);
|
||||
chunkEvents.addEvents([eventSeq4Time1, eventSeqUTime3, eventSeq2Time4Dup, eventSeq3Time2]);
|
||||
});
|
||||
|
||||
it("should provide the events sort by timestamp without duplicates", () => {
|
||||
|
|
|
@ -32,11 +32,9 @@ describe("findRoomLiveVoiceBroadcastFromUserAndDevice", () => {
|
|||
|
||||
const itShouldReturnNull = () => {
|
||||
it("should return null", () => {
|
||||
expect(findRoomLiveVoiceBroadcastFromUserAndDevice(
|
||||
room,
|
||||
client.getUserId(),
|
||||
client.getDeviceId(),
|
||||
)).toBeNull();
|
||||
expect(
|
||||
findRoomLiveVoiceBroadcastFromUserAndDevice(room, client.getUserId(), client.getDeviceId()),
|
||||
).toBeNull();
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -117,11 +115,9 @@ describe("findRoomLiveVoiceBroadcastFromUserAndDevice", () => {
|
|||
client.getUserId(),
|
||||
);
|
||||
|
||||
expect(findRoomLiveVoiceBroadcastFromUserAndDevice(
|
||||
room,
|
||||
client.getUserId(),
|
||||
client.getDeviceId(),
|
||||
)).toBe(event);
|
||||
expect(findRoomLiveVoiceBroadcastFromUserAndDevice(room, client.getUserId(), client.getDeviceId())).toBe(
|
||||
event,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -31,16 +31,8 @@ describe("hasRoomLiveVoiceBroadcast", () => {
|
|||
let room: Room;
|
||||
let expectedEvent: MatrixEvent | null = null;
|
||||
|
||||
const addVoiceBroadcastInfoEvent = (
|
||||
state: VoiceBroadcastInfoState,
|
||||
sender: string,
|
||||
): MatrixEvent => {
|
||||
const infoEvent = mkVoiceBroadcastInfoStateEvent(
|
||||
room.roomId,
|
||||
state,
|
||||
sender,
|
||||
"ASD123",
|
||||
);
|
||||
const addVoiceBroadcastInfoEvent = (state: VoiceBroadcastInfoState, sender: string): MatrixEvent => {
|
||||
const infoEvent = mkVoiceBroadcastInfoStateEvent(room.roomId, state, sender, "ASD123");
|
||||
room.currentState.setStateEvents([infoEvent]);
|
||||
return infoEvent;
|
||||
};
|
||||
|
|
|
@ -45,13 +45,9 @@ describe("setUpVoiceBroadcastPreRecording", () => {
|
|||
|
||||
const itShouldReturnNull = () => {
|
||||
it("should return null", () => {
|
||||
expect(setUpVoiceBroadcastPreRecording(
|
||||
room,
|
||||
client,
|
||||
playbacksStore,
|
||||
recordingsStore,
|
||||
preRecordingStore,
|
||||
)).toBeNull();
|
||||
expect(
|
||||
setUpVoiceBroadcastPreRecording(room, client, playbacksStore, recordingsStore, preRecordingStore),
|
||||
).toBeNull();
|
||||
expect(checkVoiceBroadcastPreConditions).toHaveBeenCalledWith(room, client, recordingsStore);
|
||||
});
|
||||
};
|
||||
|
@ -110,9 +106,7 @@ describe("setUpVoiceBroadcastPreRecording", () => {
|
|||
describe("and there is a room member and listening to another broadcast", () => {
|
||||
beforeEach(() => {
|
||||
playbacksStore.setCurrent(playback);
|
||||
room.currentState.setStateEvents([
|
||||
mkRoomMemberJoinEvent(userId, roomId),
|
||||
]);
|
||||
room.currentState.setStateEvents([mkRoomMemberJoinEvent(userId, roomId)]);
|
||||
});
|
||||
|
||||
it("should pause the current playback and create a voice broadcast pre-recording", () => {
|
||||
|
|
|
@ -31,42 +31,12 @@ const testCases = [
|
|||
VoiceBroadcastInfoState.Started,
|
||||
true, // expected return value
|
||||
],
|
||||
[
|
||||
"@user1:example.com",
|
||||
"@user1:example.com",
|
||||
VoiceBroadcastInfoState.Paused,
|
||||
true,
|
||||
],
|
||||
[
|
||||
"@user1:example.com",
|
||||
"@user1:example.com",
|
||||
VoiceBroadcastInfoState.Resumed,
|
||||
true,
|
||||
],
|
||||
[
|
||||
"@user1:example.com",
|
||||
"@user1:example.com",
|
||||
VoiceBroadcastInfoState.Stopped,
|
||||
false,
|
||||
],
|
||||
[
|
||||
"@user2:example.com",
|
||||
"@user1:example.com",
|
||||
VoiceBroadcastInfoState.Started,
|
||||
false,
|
||||
],
|
||||
[
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
],
|
||||
[
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
false,
|
||||
],
|
||||
["@user1:example.com", "@user1:example.com", VoiceBroadcastInfoState.Paused, true],
|
||||
["@user1:example.com", "@user1:example.com", VoiceBroadcastInfoState.Resumed, true],
|
||||
["@user1:example.com", "@user1:example.com", VoiceBroadcastInfoState.Stopped, false],
|
||||
["@user2:example.com", "@user1:example.com", VoiceBroadcastInfoState.Started, false],
|
||||
[null, null, null, false],
|
||||
[undefined, undefined, undefined, false],
|
||||
];
|
||||
|
||||
describe("shouldDisplayAsVoiceBroadcastRecordingTile", () => {
|
||||
|
@ -94,5 +64,6 @@ describe("shouldDisplayAsVoiceBroadcastRecordingTile", () => {
|
|||
it(`should return ${expected}`, () => {
|
||||
expect(shouldDisplayAsVoiceBroadcastRecordingTile(state, client, event)).toBe(expected);
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
|
|
|
@ -125,25 +125,22 @@ describe("shouldDisplayAsVoiceBroadcastTile", () => {
|
|||
itShouldReturnTrue();
|
||||
});
|
||||
|
||||
describe.each(
|
||||
[
|
||||
VoiceBroadcastInfoState.Paused,
|
||||
VoiceBroadcastInfoState.Resumed,
|
||||
VoiceBroadcastInfoState.Stopped,
|
||||
],
|
||||
)("when a voice broadcast info event in state %s occurs", (state: VoiceBroadcastInfoState) => {
|
||||
beforeEach(() => {
|
||||
event = mkEvent({
|
||||
event: true,
|
||||
type: VoiceBroadcastInfoEventType,
|
||||
room: roomId,
|
||||
user: senderId,
|
||||
content: {
|
||||
state,
|
||||
},
|
||||
describe.each([VoiceBroadcastInfoState.Paused, VoiceBroadcastInfoState.Resumed, VoiceBroadcastInfoState.Stopped])(
|
||||
"when a voice broadcast info event in state %s occurs",
|
||||
(state: VoiceBroadcastInfoState) => {
|
||||
beforeEach(() => {
|
||||
event = mkEvent({
|
||||
event: true,
|
||||
type: VoiceBroadcastInfoEventType,
|
||||
room: roomId,
|
||||
user: senderId,
|
||||
content: {
|
||||
state,
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
itShouldReturnFalse();
|
||||
});
|
||||
itShouldReturnFalse();
|
||||
},
|
||||
);
|
||||
});
|
||||
|
|
|
@ -59,18 +59,15 @@ describe("startNewVoiceBroadcastRecording", () => {
|
|||
|
||||
return null;
|
||||
});
|
||||
mocked(client.sendStateEvent).mockImplementation((
|
||||
sendRoomId: string,
|
||||
eventType: string,
|
||||
content: any,
|
||||
stateKey: string,
|
||||
): Promise<ISendEventResponse> => {
|
||||
if (sendRoomId === roomId && eventType === VoiceBroadcastInfoEventType) {
|
||||
return Promise.resolve({ event_id: infoEvent.getId()! });
|
||||
}
|
||||
mocked(client.sendStateEvent).mockImplementation(
|
||||
(sendRoomId: string, eventType: string, content: any, stateKey: string): Promise<ISendEventResponse> => {
|
||||
if (sendRoomId === roomId && eventType === VoiceBroadcastInfoEventType) {
|
||||
return Promise.resolve({ event_id: infoEvent.getId()! });
|
||||
}
|
||||
|
||||
throw new Error("Unexpected sendStateEvent call");
|
||||
});
|
||||
throw new Error("Unexpected sendStateEvent call");
|
||||
},
|
||||
);
|
||||
|
||||
infoEvent = mkVoiceBroadcastInfoStateEvent(
|
||||
roomId,
|
||||
|
@ -93,10 +90,7 @@ describe("startNewVoiceBroadcastRecording", () => {
|
|||
getCurrent: jest.fn(),
|
||||
} as unknown as VoiceBroadcastRecordingsStore;
|
||||
|
||||
mocked(VoiceBroadcastRecording).mockImplementation((
|
||||
infoEvent: MatrixEvent,
|
||||
client: MatrixClient,
|
||||
): any => {
|
||||
mocked(VoiceBroadcastRecording).mockImplementation((infoEvent: MatrixEvent, client: MatrixClient): any => {
|
||||
return {
|
||||
infoEvent,
|
||||
client,
|
||||
|
@ -124,19 +118,21 @@ describe("startNewVoiceBroadcastRecording", () => {
|
|||
});
|
||||
|
||||
it("should stop listen to the current broadcast and create a new recording", async () => {
|
||||
mocked(client.sendStateEvent).mockImplementation(async (
|
||||
_roomId: string,
|
||||
_eventType: string,
|
||||
_content: any,
|
||||
_stateKey = "",
|
||||
): Promise<ISendEventResponse> => {
|
||||
window.setTimeout(() => {
|
||||
// emit state events after resolving the promise
|
||||
room.currentState.setStateEvents([otherEvent]);
|
||||
room.currentState.setStateEvents([infoEvent]);
|
||||
}, 0);
|
||||
return { event_id: infoEvent.getId()! };
|
||||
});
|
||||
mocked(client.sendStateEvent).mockImplementation(
|
||||
async (
|
||||
_roomId: string,
|
||||
_eventType: string,
|
||||
_content: any,
|
||||
_stateKey = "",
|
||||
): Promise<ISendEventResponse> => {
|
||||
window.setTimeout(() => {
|
||||
// emit state events after resolving the promise
|
||||
room.currentState.setStateEvents([otherEvent]);
|
||||
room.currentState.setStateEvents([infoEvent]);
|
||||
}, 0);
|
||||
return { event_id: infoEvent.getId()! };
|
||||
},
|
||||
);
|
||||
const recording = await startNewVoiceBroadcastRecording(room, client, playbacksStore, recordingsStore);
|
||||
expect(recording).not.toBeNull();
|
||||
|
||||
|
@ -161,9 +157,7 @@ describe("startNewVoiceBroadcastRecording", () => {
|
|||
|
||||
describe("when there is already a current voice broadcast", () => {
|
||||
beforeEach(async () => {
|
||||
mocked(recordingsStore.getCurrent).mockReturnValue(
|
||||
new VoiceBroadcastRecording(infoEvent, client),
|
||||
);
|
||||
mocked(recordingsStore.getCurrent).mockReturnValue(new VoiceBroadcastRecording(infoEvent, client));
|
||||
|
||||
result = await startNewVoiceBroadcastRecording(room, client, playbacksStore, recordingsStore);
|
||||
});
|
||||
|
@ -203,12 +197,7 @@ describe("startNewVoiceBroadcastRecording", () => {
|
|||
describe("when there already is a live broadcast of another user", () => {
|
||||
beforeEach(async () => {
|
||||
room.currentState.setStateEvents([
|
||||
mkVoiceBroadcastInfoStateEvent(
|
||||
roomId,
|
||||
VoiceBroadcastInfoState.Resumed,
|
||||
otherUserId,
|
||||
"ASD123",
|
||||
),
|
||||
mkVoiceBroadcastInfoStateEvent(roomId, VoiceBroadcastInfoState.Resumed, otherUserId, "ASD123"),
|
||||
]);
|
||||
|
||||
result = await startNewVoiceBroadcastRecording(room, client, playbacksStore, recordingsStore);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue