2022-02-22 10:39:08 +00:00
|
|
|
/*
|
2024-09-09 13:57:16 +00:00
|
|
|
Copyright 2024 New Vector Ltd.
|
|
|
|
Copyright 2022, 2023 The Matrix.org Foundation C.I.C.
|
2022-02-22 10:39:08 +00:00
|
|
|
|
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-02-22 10:39:08 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
import * as React from "react";
|
2023-08-08 10:12:12 +00:00
|
|
|
import { MatrixEvent, Room, EventType } from "matrix-js-sdk/src/matrix";
|
2024-10-14 16:11:58 +00:00
|
|
|
import { render, type RenderResult } from "jest-matrix-react";
|
2022-02-22 10:39:08 +00:00
|
|
|
|
2024-10-15 13:57:26 +00:00
|
|
|
import { stubClient } from "../../../../test-utils";
|
|
|
|
import SearchResultTile from "../../../../../src/components/views/rooms/SearchResultTile";
|
|
|
|
import { MatrixClientPeg } from "../../../../../src/MatrixClientPeg";
|
2022-12-13 15:09:15 +00:00
|
|
|
|
|
|
|
const ROOM_ID = "!qPewotXpIctQySfjSy:localhost";
|
2022-02-22 10:39:08 +00:00
|
|
|
|
2023-01-30 14:31:32 +00:00
|
|
|
type Props = React.ComponentPropsWithoutRef<typeof SearchResultTile>;
|
|
|
|
|
2022-02-22 10:39:08 +00:00
|
|
|
describe("SearchResultTile", () => {
|
|
|
|
beforeAll(() => {
|
2022-12-13 15:09:15 +00:00
|
|
|
stubClient();
|
2023-06-05 17:12:23 +00:00
|
|
|
const cli = MatrixClientPeg.safeGet();
|
2022-12-13 15:09:15 +00:00
|
|
|
|
|
|
|
const room = new Room(ROOM_ID, cli, "@bob:example.org");
|
|
|
|
jest.spyOn(cli, "getRoom").mockReturnValue(room);
|
2022-02-22 10:39:08 +00:00
|
|
|
});
|
|
|
|
|
2023-01-30 14:31:32 +00:00
|
|
|
function renderComponent(props: Partial<Props>): RenderResult {
|
|
|
|
return render(<SearchResultTile timeline={[]} ourEventsIndexes={[1]} {...props} />);
|
|
|
|
}
|
|
|
|
|
2022-02-22 10:39:08 +00:00
|
|
|
it("Sets up appropriate callEventGrouper for m.call. events", () => {
|
2023-01-30 14:31:32 +00:00
|
|
|
const { container } = renderComponent({
|
|
|
|
timeline: [
|
|
|
|
new MatrixEvent({
|
|
|
|
type: EventType.CallInvite,
|
|
|
|
sender: "@user1:server",
|
|
|
|
room_id: ROOM_ID,
|
|
|
|
origin_server_ts: 1432735824652,
|
|
|
|
content: { call_id: "call.1" },
|
|
|
|
event_id: "$1:server",
|
|
|
|
}),
|
|
|
|
new MatrixEvent({
|
|
|
|
content: {
|
|
|
|
body: "This is an example text message",
|
|
|
|
format: "org.matrix.custom.html",
|
|
|
|
formatted_body: "<b>This is an example text message</b>",
|
|
|
|
msgtype: "m.text",
|
|
|
|
},
|
|
|
|
event_id: "$144429830826TWwbB:localhost",
|
|
|
|
origin_server_ts: 1432735824653,
|
|
|
|
room_id: ROOM_ID,
|
|
|
|
sender: "@example:example.org",
|
|
|
|
type: "m.room.message",
|
|
|
|
unsigned: {
|
|
|
|
age: 1234,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
new MatrixEvent({
|
|
|
|
type: EventType.CallAnswer,
|
|
|
|
sender: "@user2:server",
|
|
|
|
room_id: ROOM_ID,
|
|
|
|
origin_server_ts: 1432735824654,
|
|
|
|
content: { call_id: "call.1" },
|
|
|
|
event_id: "$2:server",
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
const tiles = container.querySelectorAll<HTMLElement>(".mx_EventTile");
|
|
|
|
expect(tiles.length).toEqual(2);
|
|
|
|
expect(tiles[0]!.dataset.eventId).toBe("$1:server");
|
|
|
|
expect(tiles[1]!.dataset.eventId).toBe("$144429830826TWwbB:localhost");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("supports events with missing timestamps", () => {
|
|
|
|
const { container } = renderComponent({
|
|
|
|
timeline: [...Array(20)].map(
|
|
|
|
(_, i) =>
|
2023-01-05 11:37:58 +00:00
|
|
|
new MatrixEvent({
|
2023-01-30 14:31:32 +00:00
|
|
|
type: EventType.RoomMessage,
|
2023-01-05 11:37:58 +00:00
|
|
|
sender: "@user1:server",
|
|
|
|
room_id: ROOM_ID,
|
2023-01-30 14:31:32 +00:00
|
|
|
content: { body: `Message #${i}` },
|
|
|
|
event_id: `$${i}:server`,
|
2023-08-21 19:38:59 +00:00
|
|
|
origin_server_ts: i,
|
2023-01-05 11:37:58 +00:00
|
|
|
}),
|
2023-01-30 14:31:32 +00:00
|
|
|
),
|
|
|
|
});
|
2022-02-22 10:39:08 +00:00
|
|
|
|
2023-10-16 14:14:04 +00:00
|
|
|
const separators = container.querySelectorAll(".mx_TimelineSeparator");
|
2023-01-30 14:31:32 +00:00
|
|
|
// One separator is always rendered at the top, we don't want any
|
|
|
|
// between messages.
|
|
|
|
expect(separators.length).toBe(1);
|
2022-02-22 10:39:08 +00:00
|
|
|
});
|
|
|
|
});
|