2022-04-21 16:14:10 +00:00
|
|
|
/*
|
2024-09-09 13:57:16 +00:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2022-04-21 16:14:10 +00:00
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
|
2024-09-09 13:57:16 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2022-04-21 16:14:10 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
import {
|
2023-08-23 09:04:25 +00:00
|
|
|
M_LOCATION,
|
2022-04-21 16:14:10 +00:00
|
|
|
EventStatus,
|
|
|
|
EventType,
|
2022-10-28 11:48:15 +00:00
|
|
|
IEvent,
|
|
|
|
MatrixClient,
|
2022-04-21 16:14:10 +00:00
|
|
|
MatrixEvent,
|
|
|
|
MsgType,
|
2022-10-28 11:48:15 +00:00
|
|
|
PendingEventOrdering,
|
2022-04-21 16:14:10 +00:00
|
|
|
RelationType,
|
2022-10-28 11:48:15 +00:00
|
|
|
Room,
|
2023-08-14 08:58:55 +00:00
|
|
|
Thread,
|
2022-04-21 16:14:10 +00:00
|
|
|
} from "matrix-js-sdk/src/matrix";
|
|
|
|
|
|
|
|
import { MatrixClientPeg } from "../../src/MatrixClientPeg";
|
|
|
|
import {
|
|
|
|
canCancel,
|
|
|
|
canEditContent,
|
|
|
|
canEditOwnEvent,
|
2022-10-28 11:48:15 +00:00
|
|
|
fetchInitialEvent,
|
2022-11-29 14:55:48 +00:00
|
|
|
findEditableEvent,
|
2022-12-12 15:03:56 +00:00
|
|
|
highlightEvent,
|
2022-04-21 16:14:10 +00:00
|
|
|
isContentActionable,
|
|
|
|
isLocationEvent,
|
|
|
|
isVoiceMessage,
|
|
|
|
} from "../../src/utils/EventUtils";
|
2022-10-28 11:48:15 +00:00
|
|
|
import { getMockClientWithEventEmitter, makeBeaconInfoEvent, makePollStartEvent, stubClient } from "../test-utils";
|
2022-12-12 15:03:56 +00:00
|
|
|
import dis from "../../src/dispatcher/dispatcher";
|
|
|
|
import { Action } from "../../src/dispatcher/actions";
|
2023-01-05 07:40:09 +00:00
|
|
|
import { mkVoiceBroadcastInfoStateEvent } from "../voice-broadcast/utils/test-utils";
|
|
|
|
import { VoiceBroadcastInfoState } from "../../src/voice-broadcast/types";
|
2022-12-12 15:03:56 +00:00
|
|
|
|
|
|
|
jest.mock("../../src/dispatcher/dispatcher");
|
2022-04-21 16:14:10 +00:00
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
describe("EventUtils", () => {
|
|
|
|
const userId = "@user:server";
|
|
|
|
const roomId = "!room:server";
|
2022-04-21 16:14:10 +00:00
|
|
|
const mockClient = getMockClientWithEventEmitter({
|
|
|
|
getUserId: jest.fn().mockReturnValue(userId),
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
mockClient.getUserId.mockClear().mockReturnValue(userId);
|
|
|
|
});
|
|
|
|
afterAll(() => {
|
2022-12-12 11:24:14 +00:00
|
|
|
jest.spyOn(MatrixClientPeg, "get").mockRestore();
|
2022-04-21 16:14:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// setup events
|
|
|
|
const unsentEvent = new MatrixEvent({
|
|
|
|
type: EventType.RoomMessage,
|
|
|
|
sender: userId,
|
|
|
|
});
|
|
|
|
unsentEvent.status = EventStatus.ENCRYPTING;
|
|
|
|
|
|
|
|
const redactedEvent = new MatrixEvent({
|
|
|
|
type: EventType.RoomMessage,
|
|
|
|
sender: userId,
|
|
|
|
});
|
2024-03-25 12:21:02 +00:00
|
|
|
redactedEvent.makeRedacted(
|
|
|
|
redactedEvent,
|
|
|
|
new Room(redactedEvent.getRoomId()!, mockClient, mockClient.getUserId()!),
|
|
|
|
);
|
2022-04-21 16:14:10 +00:00
|
|
|
|
2022-06-02 15:43:19 +00:00
|
|
|
const stateEvent = new MatrixEvent({
|
|
|
|
type: EventType.RoomTopic,
|
2022-12-12 11:24:14 +00:00
|
|
|
state_key: "",
|
2022-06-02 15:43:19 +00:00
|
|
|
});
|
|
|
|
const beaconInfoEvent = makeBeaconInfoEvent(userId, roomId);
|
2022-04-21 16:14:10 +00:00
|
|
|
|
|
|
|
const roomMemberEvent = new MatrixEvent({
|
|
|
|
type: EventType.RoomMember,
|
|
|
|
sender: userId,
|
|
|
|
});
|
|
|
|
|
|
|
|
const stickerEvent = new MatrixEvent({
|
|
|
|
type: EventType.Sticker,
|
|
|
|
sender: userId,
|
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
const pollStartEvent = makePollStartEvent("What?", userId);
|
2022-04-21 16:14:10 +00:00
|
|
|
|
|
|
|
const notDecryptedEvent = new MatrixEvent({
|
|
|
|
type: EventType.RoomMessage,
|
|
|
|
sender: userId,
|
|
|
|
content: {
|
2022-12-12 11:24:14 +00:00
|
|
|
msgtype: "m.bad.encrypted",
|
2022-04-21 16:14:10 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const noMsgType = new MatrixEvent({
|
|
|
|
type: EventType.RoomMessage,
|
|
|
|
sender: userId,
|
|
|
|
content: {
|
|
|
|
msgtype: undefined,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const noContentBody = new MatrixEvent({
|
|
|
|
type: EventType.RoomMessage,
|
|
|
|
sender: userId,
|
|
|
|
content: {
|
|
|
|
msgtype: MsgType.Image,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const emptyContentBody = new MatrixEvent({
|
|
|
|
type: EventType.RoomMessage,
|
|
|
|
sender: userId,
|
|
|
|
content: {
|
|
|
|
msgtype: MsgType.Text,
|
2022-12-12 11:24:14 +00:00
|
|
|
body: "",
|
2022-04-21 16:14:10 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const objectContentBody = new MatrixEvent({
|
|
|
|
type: EventType.RoomMessage,
|
|
|
|
sender: userId,
|
|
|
|
content: {
|
|
|
|
msgtype: MsgType.File,
|
|
|
|
body: {},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const niceTextMessage = new MatrixEvent({
|
|
|
|
type: EventType.RoomMessage,
|
|
|
|
sender: userId,
|
|
|
|
content: {
|
|
|
|
msgtype: MsgType.Text,
|
2022-12-12 11:24:14 +00:00
|
|
|
body: "Hello",
|
2022-04-21 16:14:10 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const bobsTextMessage = new MatrixEvent({
|
|
|
|
type: EventType.RoomMessage,
|
2022-12-12 11:24:14 +00:00
|
|
|
sender: "@bob:server",
|
2022-04-21 16:14:10 +00:00
|
|
|
content: {
|
|
|
|
msgtype: MsgType.Text,
|
2022-12-12 11:24:14 +00:00
|
|
|
body: "Hello from Bob",
|
2022-04-21 16:14:10 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-01-05 07:40:09 +00:00
|
|
|
const voiceBroadcastStart = mkVoiceBroadcastInfoStateEvent(
|
|
|
|
"!room:example.com",
|
|
|
|
VoiceBroadcastInfoState.Started,
|
|
|
|
"@user:example.com",
|
|
|
|
"ABC123",
|
|
|
|
);
|
|
|
|
|
|
|
|
const voiceBroadcastStop = mkVoiceBroadcastInfoStateEvent(
|
|
|
|
"!room:example.com",
|
|
|
|
VoiceBroadcastInfoState.Stopped,
|
|
|
|
"@user:example.com",
|
|
|
|
"ABC123",
|
|
|
|
);
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
describe("isContentActionable()", () => {
|
2022-04-21 16:14:10 +00:00
|
|
|
type TestCase = [string, MatrixEvent];
|
|
|
|
it.each<TestCase>([
|
2022-12-12 11:24:14 +00:00
|
|
|
["unsent event", unsentEvent],
|
|
|
|
["redacted event", redactedEvent],
|
|
|
|
["state event", stateEvent],
|
|
|
|
["undecrypted event", notDecryptedEvent],
|
|
|
|
["room member event", roomMemberEvent],
|
|
|
|
["event without msgtype", noMsgType],
|
|
|
|
["event without content body property", noContentBody],
|
2023-01-05 07:40:09 +00:00
|
|
|
["broadcast stop event", voiceBroadcastStop],
|
2022-12-12 11:24:14 +00:00
|
|
|
])("returns false for %s", (_description, event) => {
|
2022-04-21 16:14:10 +00:00
|
|
|
expect(isContentActionable(event)).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it.each<TestCase>([
|
2022-12-12 11:24:14 +00:00
|
|
|
["sticker event", stickerEvent],
|
|
|
|
["poll start event", pollStartEvent],
|
|
|
|
["event with empty content body", emptyContentBody],
|
|
|
|
["event with a content body", niceTextMessage],
|
|
|
|
["beacon_info event", beaconInfoEvent],
|
2023-01-05 07:40:09 +00:00
|
|
|
["broadcast start event", voiceBroadcastStart],
|
2022-12-12 11:24:14 +00:00
|
|
|
])("returns true for %s", (_description, event) => {
|
2022-04-21 16:14:10 +00:00
|
|
|
expect(isContentActionable(event)).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
describe("editable content helpers", () => {
|
2022-04-21 16:14:10 +00:00
|
|
|
const replaceRelationEvent = new MatrixEvent({
|
|
|
|
type: EventType.RoomMessage,
|
|
|
|
sender: userId,
|
|
|
|
content: {
|
|
|
|
msgtype: MsgType.Text,
|
2022-12-12 11:24:14 +00:00
|
|
|
body: "Hello",
|
|
|
|
["m.relates_to"]: {
|
2022-04-21 16:14:10 +00:00
|
|
|
rel_type: RelationType.Replace,
|
2022-12-12 11:24:14 +00:00
|
|
|
event_id: "1",
|
2022-04-21 16:14:10 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const referenceRelationEvent = new MatrixEvent({
|
|
|
|
type: EventType.RoomMessage,
|
|
|
|
sender: userId,
|
|
|
|
content: {
|
|
|
|
msgtype: MsgType.Text,
|
2022-12-12 11:24:14 +00:00
|
|
|
body: "Hello",
|
|
|
|
["m.relates_to"]: {
|
2022-04-21 16:14:10 +00:00
|
|
|
rel_type: RelationType.Reference,
|
2022-12-12 11:24:14 +00:00
|
|
|
event_id: "1",
|
2022-04-21 16:14:10 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const emoteEvent = new MatrixEvent({
|
|
|
|
type: EventType.RoomMessage,
|
|
|
|
sender: userId,
|
|
|
|
content: {
|
|
|
|
msgtype: MsgType.Emote,
|
2022-12-12 11:24:14 +00:00
|
|
|
body: "🧪",
|
2022-04-21 16:14:10 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
type TestCase = [string, MatrixEvent];
|
|
|
|
|
|
|
|
const uneditableCases: TestCase[] = [
|
2022-12-12 11:24:14 +00:00
|
|
|
["redacted event", redactedEvent],
|
|
|
|
["state event", stateEvent],
|
|
|
|
["event that is not room message", roomMemberEvent],
|
|
|
|
["event without msgtype", noMsgType],
|
|
|
|
["event without content body property", noContentBody],
|
|
|
|
["event with empty content body property", emptyContentBody],
|
|
|
|
["event with non-string body", objectContentBody],
|
|
|
|
["event not sent by current user", bobsTextMessage],
|
|
|
|
["event with a replace relation", replaceRelationEvent],
|
2022-04-21 16:14:10 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
const editableCases: TestCase[] = [
|
2022-12-12 11:24:14 +00:00
|
|
|
["event with reference relation", referenceRelationEvent],
|
|
|
|
["emote event", emoteEvent],
|
|
|
|
["poll start event", pollStartEvent],
|
|
|
|
["event with a content body", niceTextMessage],
|
2022-04-21 16:14:10 +00:00
|
|
|
];
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
describe("canEditContent()", () => {
|
|
|
|
it.each<TestCase>(uneditableCases)("returns false for %s", (_description, event) => {
|
2023-05-23 15:24:12 +00:00
|
|
|
expect(canEditContent(mockClient, event)).toBe(false);
|
2022-04-21 16:14:10 +00:00
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it.each<TestCase>(editableCases)("returns true for %s", (_description, event) => {
|
2023-05-23 15:24:12 +00:00
|
|
|
expect(canEditContent(mockClient, event)).toBe(true);
|
2022-04-21 16:14:10 +00:00
|
|
|
});
|
|
|
|
});
|
2022-12-12 11:24:14 +00:00
|
|
|
describe("canEditOwnContent()", () => {
|
|
|
|
it.each<TestCase>(uneditableCases)("returns false for %s", (_description, event) => {
|
2023-05-23 15:24:12 +00:00
|
|
|
expect(canEditOwnEvent(mockClient, event)).toBe(false);
|
2022-04-21 16:14:10 +00:00
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it.each<TestCase>(editableCases)("returns true for %s", (_description, event) => {
|
2023-05-23 15:24:12 +00:00
|
|
|
expect(canEditOwnEvent(mockClient, event)).toBe(true);
|
2022-04-21 16:14:10 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
describe("isVoiceMessage()", () => {
|
|
|
|
it("returns true for an event with msc2516.voice content", () => {
|
2022-04-21 16:14:10 +00:00
|
|
|
const event = new MatrixEvent({
|
|
|
|
type: EventType.RoomMessage,
|
|
|
|
content: {
|
2022-12-12 11:24:14 +00:00
|
|
|
["org.matrix.msc2516.voice"]: {},
|
2022-04-21 16:14:10 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(isVoiceMessage(event)).toBe(true);
|
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it("returns true for an event with msc3245.voice content", () => {
|
2022-04-21 16:14:10 +00:00
|
|
|
const event = new MatrixEvent({
|
|
|
|
type: EventType.RoomMessage,
|
|
|
|
content: {
|
2022-12-12 11:24:14 +00:00
|
|
|
["org.matrix.msc3245.voice"]: {},
|
2022-04-21 16:14:10 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(isVoiceMessage(event)).toBe(true);
|
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it("returns false for an event with voice content", () => {
|
2022-04-21 16:14:10 +00:00
|
|
|
const event = new MatrixEvent({
|
|
|
|
type: EventType.RoomMessage,
|
|
|
|
content: {
|
2022-12-12 11:24:14 +00:00
|
|
|
body: "hello",
|
2022-04-21 16:14:10 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(isVoiceMessage(event)).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
describe("isLocationEvent()", () => {
|
|
|
|
it("returns true for an event with m.location stable type", () => {
|
2022-04-21 16:14:10 +00:00
|
|
|
const event = new MatrixEvent({
|
|
|
|
type: M_LOCATION.altName,
|
|
|
|
});
|
|
|
|
expect(isLocationEvent(event)).toBe(true);
|
|
|
|
});
|
2022-12-12 11:24:14 +00:00
|
|
|
it("returns true for an event with m.location unstable prefixed type", () => {
|
2022-04-21 16:14:10 +00:00
|
|
|
const event = new MatrixEvent({
|
|
|
|
type: M_LOCATION.name,
|
|
|
|
});
|
|
|
|
expect(isLocationEvent(event)).toBe(true);
|
|
|
|
});
|
2022-12-12 11:24:14 +00:00
|
|
|
it("returns true for a room message with stable m.location msgtype", () => {
|
2022-04-21 16:14:10 +00:00
|
|
|
const event = new MatrixEvent({
|
|
|
|
type: EventType.RoomMessage,
|
|
|
|
content: {
|
|
|
|
msgtype: M_LOCATION.altName,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(isLocationEvent(event)).toBe(true);
|
|
|
|
});
|
2022-12-12 11:24:14 +00:00
|
|
|
it("returns true for a room message with unstable m.location msgtype", () => {
|
2022-04-21 16:14:10 +00:00
|
|
|
const event = new MatrixEvent({
|
|
|
|
type: EventType.RoomMessage,
|
|
|
|
content: {
|
|
|
|
msgtype: M_LOCATION.name,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(isLocationEvent(event)).toBe(true);
|
|
|
|
});
|
2022-12-12 11:24:14 +00:00
|
|
|
it("returns false for a non location event", () => {
|
2022-04-21 16:14:10 +00:00
|
|
|
const event = new MatrixEvent({
|
|
|
|
type: EventType.RoomMessage,
|
|
|
|
content: {
|
2022-12-12 11:24:14 +00:00
|
|
|
body: "Hello",
|
2022-04-21 16:14:10 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(isLocationEvent(event)).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
describe("canCancel()", () => {
|
|
|
|
it.each([[EventStatus.QUEUED], [EventStatus.NOT_SENT], [EventStatus.ENCRYPTING]])(
|
|
|
|
"return true for status %s",
|
|
|
|
(status) => {
|
|
|
|
expect(canCancel(status)).toBe(true);
|
|
|
|
},
|
|
|
|
);
|
2022-04-21 16:14:10 +00:00
|
|
|
|
|
|
|
it.each([
|
|
|
|
[EventStatus.SENDING],
|
|
|
|
[EventStatus.CANCELLED],
|
|
|
|
[EventStatus.SENT],
|
2022-12-12 11:24:14 +00:00
|
|
|
["invalid-status" as unknown as EventStatus],
|
|
|
|
])("return false for status %s", (status) => {
|
2022-04-21 16:14:10 +00:00
|
|
|
expect(canCancel(status)).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
2022-10-28 11:48:15 +00:00
|
|
|
|
|
|
|
describe("fetchInitialEvent", () => {
|
|
|
|
const ROOM_ID = "!roomId:example.org";
|
|
|
|
let room: Room;
|
|
|
|
let client: MatrixClient;
|
|
|
|
|
|
|
|
const NORMAL_EVENT = "$normalEvent";
|
|
|
|
const THREAD_ROOT = "$threadRoot";
|
|
|
|
const THREAD_REPLY = "$threadReply";
|
|
|
|
|
|
|
|
const events: Record<string, Partial<IEvent>> = {
|
|
|
|
[NORMAL_EVENT]: {
|
|
|
|
event_id: NORMAL_EVENT,
|
|
|
|
type: EventType.RoomMessage,
|
|
|
|
content: {
|
2022-12-12 11:24:14 +00:00
|
|
|
body: "Classic event",
|
|
|
|
msgtype: MsgType.Text,
|
2022-10-28 11:48:15 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
[THREAD_ROOT]: {
|
|
|
|
event_id: THREAD_ROOT,
|
|
|
|
type: EventType.RoomMessage,
|
|
|
|
content: {
|
2022-12-12 11:24:14 +00:00
|
|
|
body: "Thread root",
|
|
|
|
msgtype: "m.text",
|
2022-10-28 11:48:15 +00:00
|
|
|
},
|
|
|
|
unsigned: {
|
|
|
|
"m.relations": {
|
|
|
|
[RelationType.Thread]: {
|
|
|
|
latest_event: {
|
|
|
|
event_id: THREAD_REPLY,
|
|
|
|
type: EventType.RoomMessage,
|
|
|
|
content: {
|
|
|
|
"body": "Thread reply",
|
|
|
|
"msgtype": MsgType.Text,
|
|
|
|
"m.relates_to": {
|
|
|
|
event_id: "$threadRoot",
|
|
|
|
rel_type: RelationType.Thread,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
count: 1,
|
|
|
|
current_user_participated: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[THREAD_REPLY]: {
|
|
|
|
event_id: THREAD_REPLY,
|
|
|
|
type: EventType.RoomMessage,
|
|
|
|
content: {
|
|
|
|
"body": "Thread reply",
|
|
|
|
"msgtype": MsgType.Text,
|
|
|
|
"m.relates_to": {
|
|
|
|
event_id: THREAD_ROOT,
|
|
|
|
rel_type: RelationType.Thread,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.clearAllMocks();
|
|
|
|
|
|
|
|
stubClient();
|
2023-06-05 17:12:23 +00:00
|
|
|
client = MatrixClientPeg.safeGet();
|
2022-10-28 11:48:15 +00:00
|
|
|
|
2023-02-13 17:01:43 +00:00
|
|
|
room = new Room(ROOM_ID, client, client.getUserId()!, {
|
2022-10-28 11:48:15 +00:00
|
|
|
pendingEventOrdering: PendingEventOrdering.Detached,
|
|
|
|
});
|
|
|
|
|
2023-01-30 12:20:11 +00:00
|
|
|
jest.spyOn(client, "supportsThreads").mockReturnValue(true);
|
2022-10-28 11:48:15 +00:00
|
|
|
jest.spyOn(client, "getRoom").mockReturnValue(room);
|
|
|
|
jest.spyOn(client, "fetchRoomEvent").mockImplementation(async (roomId, eventId) => {
|
|
|
|
return events[eventId] ?? Promise.reject();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("returns null for unknown events", async () => {
|
|
|
|
expect(await fetchInitialEvent(client, room.roomId, "$UNKNOWN")).toBeNull();
|
|
|
|
expect(await fetchInitialEvent(client, room.roomId, NORMAL_EVENT)).toBeInstanceOf(MatrixEvent);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("creates a thread when needed", async () => {
|
|
|
|
await fetchInitialEvent(client, room.roomId, THREAD_REPLY);
|
|
|
|
expect(room.getThread(THREAD_ROOT)).toBeInstanceOf(Thread);
|
|
|
|
});
|
|
|
|
});
|
2022-11-29 14:55:48 +00:00
|
|
|
|
|
|
|
describe("findEditableEvent", () => {
|
|
|
|
it("should not explode when given empty events array", () => {
|
2022-12-12 11:24:14 +00:00
|
|
|
expect(
|
|
|
|
findEditableEvent({
|
|
|
|
events: [],
|
|
|
|
isForward: true,
|
2023-05-23 15:24:12 +00:00
|
|
|
matrixClient: mockClient,
|
2022-12-12 11:24:14 +00:00
|
|
|
}),
|
|
|
|
).toBeUndefined();
|
2022-11-29 14:55:48 +00:00
|
|
|
});
|
|
|
|
});
|
2022-12-12 15:03:56 +00:00
|
|
|
|
|
|
|
describe("highlightEvent", () => {
|
|
|
|
const eventId = "$zLg9jResFQmMO_UKFeWpgLgOgyWrL8qIgLgZ5VywrCQ";
|
|
|
|
|
|
|
|
it("should dispatch an action to view the event", () => {
|
|
|
|
highlightEvent(roomId, eventId);
|
|
|
|
expect(dis.dispatch).toHaveBeenCalledWith({
|
|
|
|
action: Action.ViewRoom,
|
|
|
|
event_id: eventId,
|
|
|
|
highlighted: true,
|
|
|
|
room_id: roomId,
|
|
|
|
metricsTrigger: undefined,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2022-04-21 16:14:10 +00:00
|
|
|
});
|