2023-01-30 22:31:32 +08:00
|
|
|
/*
|
2024-09-09 21:57:16 +08:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2023-01-30 22:31:32 +08:00
|
|
|
Copyright 2023 The Matrix.org Foundation C.I.C.
|
|
|
|
|
2024-09-09 21:57:16 +08:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2023-01-30 22:31:32 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
import React from "react";
|
2024-08-07 01:22:02 +08:00
|
|
|
import { render, RenderResult, waitForElementToBeRemoved } from "@testing-library/react";
|
2023-01-30 22:31:32 +08:00
|
|
|
import { EventType, MatrixEvent } from "matrix-js-sdk/src/matrix";
|
|
|
|
|
|
|
|
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
|
|
|
|
import { flushPromises, mkMessage, stubClient } from "../../../test-utils";
|
|
|
|
import MessageEditHistoryDialog from "../../../../src/components/views/dialogs/MessageEditHistoryDialog";
|
|
|
|
|
|
|
|
describe("<MessageEditHistory />", () => {
|
|
|
|
const roomId = "!aroom:example.com";
|
|
|
|
let client: jest.Mocked<MatrixClient>;
|
|
|
|
let event: MatrixEvent;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
client = stubClient() as jest.Mocked<MatrixClient>;
|
|
|
|
event = mkMessage({
|
|
|
|
event: true,
|
|
|
|
user: "@user:example.com",
|
|
|
|
room: "!room:example.com",
|
|
|
|
msg: "My Great Message",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
async function renderComponent(): Promise<RenderResult> {
|
|
|
|
const result = render(<MessageEditHistoryDialog mxEvent={event} onFinished={jest.fn()} />);
|
2024-08-07 01:22:02 +08:00
|
|
|
await waitForElementToBeRemoved(() => result.queryByRole("progressbar"));
|
2023-01-30 22:31:32 +08:00
|
|
|
await flushPromises();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-04-21 18:50:42 +08:00
|
|
|
function mockEdits(...edits: { msg: string; ts?: number }[]) {
|
2023-01-30 22:31:32 +08:00
|
|
|
client.relations.mockImplementation(() =>
|
|
|
|
Promise.resolve({
|
|
|
|
events: edits.map(
|
|
|
|
(e) =>
|
|
|
|
new MatrixEvent({
|
|
|
|
type: EventType.RoomMessage,
|
|
|
|
room_id: roomId,
|
2023-08-22 03:38:59 +08:00
|
|
|
origin_server_ts: e.ts ?? 0,
|
2023-01-30 22:31:32 +08:00
|
|
|
content: {
|
|
|
|
body: e.msg,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
it("should match the snapshot", async () => {
|
|
|
|
mockEdits({ msg: "My Great Massage", ts: 1234 });
|
|
|
|
|
|
|
|
const { container } = await renderComponent();
|
|
|
|
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2023-03-01 23:23:35 +08:00
|
|
|
it("should support events with", async () => {
|
2023-01-30 22:31:32 +08:00
|
|
|
mockEdits(
|
|
|
|
{ msg: "My Great Massage", ts: undefined },
|
|
|
|
{ msg: "My Great Massage?", ts: undefined },
|
|
|
|
{ msg: "My Great Missage", ts: undefined },
|
|
|
|
);
|
|
|
|
|
|
|
|
const { container } = await renderComponent();
|
|
|
|
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|