2023-01-30 14:31:32 +00:00
|
|
|
/*
|
2024-09-09 13:57:16 +00:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2023-01-30 14:31:32 +00:00
|
|
|
Copyright 2023 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.
|
2023-01-30 14:31:32 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
import React from "react";
|
2024-08-06 17:22:02 +00:00
|
|
|
import { render, RenderResult, waitForElementToBeRemoved } from "@testing-library/react";
|
2023-01-30 14:31:32 +00: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-06 17:22:02 +00:00
|
|
|
await waitForElementToBeRemoved(() => result.queryByRole("progressbar"));
|
2023-01-30 14:31:32 +00:00
|
|
|
await flushPromises();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-04-21 10:50:42 +00:00
|
|
|
function mockEdits(...edits: { msg: string; ts?: number }[]) {
|
2023-01-30 14:31:32 +00:00
|
|
|
client.relations.mockImplementation(() =>
|
|
|
|
Promise.resolve({
|
|
|
|
events: edits.map(
|
|
|
|
(e) =>
|
|
|
|
new MatrixEvent({
|
|
|
|
type: EventType.RoomMessage,
|
|
|
|
room_id: roomId,
|
2023-08-21 19:38:59 +00:00
|
|
|
origin_server_ts: e.ts ?? 0,
|
2023-01-30 14:31:32 +00: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 15:23:35 +00:00
|
|
|
it("should support events with", async () => {
|
2023-01-30 14:31:32 +00: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();
|
|
|
|
});
|
|
|
|
});
|