Hide voice broadcast chunks (#9397)
This commit is contained in:
parent
96213d644b
commit
b871456681
3 changed files with 59 additions and 8 deletions
|
@ -1,12 +1,9 @@
|
|||
/*
|
||||
Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -14,23 +11,70 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { EventType, MatrixEvent } from "matrix-js-sdk/src/matrix";
|
||||
import { EventType, MatrixClient, MatrixEvent, MsgType } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { JSONEventFactory, pickFactory } from "../../src/events/EventTileFactory";
|
||||
import { createTestClient } from "../test-utils";
|
||||
import { VoiceBroadcastChunkEventType } from "../../src/voice-broadcast";
|
||||
import { createTestClient, mkEvent } from "../test-utils";
|
||||
|
||||
const roomId = "!room:example.com";
|
||||
|
||||
describe("pickFactory", () => {
|
||||
let voiceBroadcastChunkEvent: MatrixEvent;
|
||||
let audioMessageEvent: MatrixEvent;
|
||||
let client: MatrixClient;
|
||||
|
||||
beforeAll(() => {
|
||||
client = createTestClient();
|
||||
voiceBroadcastChunkEvent = mkEvent({
|
||||
event: true,
|
||||
type: EventType.RoomMessage,
|
||||
user: client.getUserId(),
|
||||
room: roomId,
|
||||
content: {
|
||||
msgtype: MsgType.Audio,
|
||||
[VoiceBroadcastChunkEventType]: {},
|
||||
},
|
||||
});
|
||||
audioMessageEvent = mkEvent({
|
||||
event: true,
|
||||
type: EventType.RoomMessage,
|
||||
user: client.getUserId(),
|
||||
room: roomId,
|
||||
content: {
|
||||
msgtype: MsgType.Audio,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("should return JSONEventFactory for a no-op m.room.power_levels event", () => {
|
||||
const cli = createTestClient();
|
||||
const event = new MatrixEvent({
|
||||
type: EventType.RoomPowerLevels,
|
||||
state_key: "",
|
||||
content: {},
|
||||
sender: cli.getUserId(),
|
||||
sender: client.getUserId(),
|
||||
room_id: roomId,
|
||||
});
|
||||
expect(pickFactory(event, cli, true)).toBe(JSONEventFactory);
|
||||
expect(pickFactory(event, client, true)).toBe(JSONEventFactory);
|
||||
});
|
||||
|
||||
describe("when showing hidden events", () => {
|
||||
it("should return a function for a voice broadcast event", () => {
|
||||
expect(pickFactory(voiceBroadcastChunkEvent, client, true)).toBeInstanceOf(Function);
|
||||
});
|
||||
|
||||
it("should return a function for an audio message event", () => {
|
||||
expect(pickFactory(audioMessageEvent, client, true)).toBeInstanceOf(Function);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when not showing hidden events", () => {
|
||||
it("should return undefined for a voice broadcast event", () => {
|
||||
expect(pickFactory(voiceBroadcastChunkEvent, client, false)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("should return a function for an audio message event", () => {
|
||||
expect(pickFactory(audioMessageEvent, client, false)).toBeInstanceOf(Function);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue