Factor out MessageEvent.from() usage (#9882)

* Factor out `MessageEvent.from()` usage

The class/function is disappearing from the events-sdk, at least in this form.

* Manually create contents for events used by cypress

The utility function is out of range of the calling code at runtime, for some reason.

* Run prettier

* Maybe this will fix the build
This commit is contained in:
Travis Ralston 2023-01-10 09:20:10 -07:00 committed by GitHub
parent 34f0229d75
commit c09ca7b4ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 127 additions and 61 deletions

View file

@ -17,7 +17,6 @@ limitations under the License.
import { render, RenderResult, waitFor, screen } from "@testing-library/react";
// eslint-disable-next-line deprecate/import
import { mount, ReactWrapper } from "enzyme";
import { MessageEvent } from "matrix-events-sdk";
import { ReceiptType } from "matrix-js-sdk/src/@types/read_receipts";
import {
EventTimelineSet,
@ -48,6 +47,7 @@ import SettingsStore from "../../../src/settings/SettingsStore";
import { isCallEvent } from "../../../src/components/structures/LegacyCallEventGrouper";
import { flushPromises, mkMembership, mkRoom, stubClient } from "../../test-utils";
import { mkThread } from "../../test-utils/threads";
import { createMessageEventContent } from "../../test-utils/events";
const newReceipt = (eventId: string, userId: string, readTs: number, fullyReadTs: number): MatrixEvent => {
const receiptContent = {
@ -89,8 +89,8 @@ const mockEvents = (room: Room, count = 2): MatrixEvent[] => {
room_id: room.roomId,
event_id: `${room.roomId}_event_${index}`,
type: EventType.RoomMessage,
user_id: "userId",
content: MessageEvent.from(`Event${index}`).serialize().content,
sender: "userId",
content: createMessageEventContent("`Event${index}`"),
}),
);
}
@ -125,13 +125,15 @@ describe("TimelinePanel", () => {
event_id: "ev0",
sender: "@u2:m.org",
origin_server_ts: 111,
...MessageEvent.from("hello 1").serialize(),
type: EventType.RoomMessage,
content: createMessageEventContent("hello 1"),
});
const ev1 = new MatrixEvent({
event_id: "ev1",
sender: "@u2:m.org",
origin_server_ts: 222,
...MessageEvent.from("hello 2").serialize(),
type: EventType.RoomMessage,
content: createMessageEventContent("hello 2"),
});
const roomId = "#room:example.com";
@ -385,24 +387,24 @@ describe("TimelinePanel", () => {
room_id: room.roomId,
event_id: "event_reply_1",
type: EventType.RoomMessage,
user_id: "userId",
content: MessageEvent.from(`ReplyEvent1`).serialize().content,
sender: "userId",
content: createMessageEventContent("ReplyEvent1"),
});
reply2 = new MatrixEvent({
room_id: room.roomId,
event_id: "event_reply_2",
type: EventType.RoomMessage,
user_id: "userId",
content: MessageEvent.from(`ReplyEvent2`).serialize().content,
sender: "userId",
content: createMessageEventContent("ReplyEvent2"),
});
root = new MatrixEvent({
room_id: room.roomId,
event_id: "event_root_1",
type: EventType.RoomMessage,
user_id: "userId",
content: MessageEvent.from(`RootEvent`).serialize().content,
sender: "userId",
content: createMessageEventContent("RootEvent"),
});
const eventMap: { [key: string]: MatrixEvent } = {