2023-01-30 17:31:32 +03:00
|
|
|
/*
|
2024-09-09 16:57:16 +03:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2023-01-30 17:31:32 +03:00
|
|
|
Copyright 2023 The Matrix.org Foundation C.I.C.
|
|
|
|
|
2024-09-09 16:57:16 +03: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 17:31:32 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
import React from "react";
|
2024-10-14 19:11:58 +03:00
|
|
|
import { render, RenderResult, waitForElementToBeRemoved } from "jest-matrix-react";
|
2023-01-30 17:31:32 +03:00
|
|
|
import { EventType, MatrixEvent } from "matrix-js-sdk/src/matrix";
|
|
|
|
|
|
|
|
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
|
2024-10-15 16:57:26 +03:00
|
|
|
import { flushPromises, mkMessage, stubClient } from "../../../../test-utils";
|
|
|
|
import MessageEditHistoryDialog from "../../../../../src/components/views/dialogs/MessageEditHistoryDialog";
|
2023-01-30 17:31:32 +03:00
|
|
|
|
|
|
|
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 20:22:02 +03:00
|
|
|
await waitForElementToBeRemoved(() => result.queryByRole("progressbar"));
|
2023-01-30 17:31:32 +03:00
|
|
|
await flushPromises();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-04-21 13:50:42 +03:00
|
|
|
function mockEdits(...edits: { msg: string; ts?: number }[]) {
|
2023-01-30 17:31:32 +03:00
|
|
|
client.relations.mockImplementation(() =>
|
|
|
|
Promise.resolve({
|
|
|
|
events: edits.map(
|
|
|
|
(e) =>
|
|
|
|
new MatrixEvent({
|
|
|
|
type: EventType.RoomMessage,
|
|
|
|
room_id: roomId,
|
2023-08-21 22:38:59 +03:00
|
|
|
origin_server_ts: e.ts ?? 0,
|
2023-01-30 17:31:32 +03: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 18:23:35 +03:00
|
|
|
it("should support events with", async () => {
|
2023-01-30 17:31:32 +03: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();
|
|
|
|
});
|
|
|
|
});
|