2022-02-22 10:39:08 +00:00
|
|
|
/*
|
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import * as React from "react";
|
|
|
|
import { SearchResult } from "matrix-js-sdk/src/models/search-result";
|
|
|
|
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
|
|
|
|
import { EventType } from "matrix-js-sdk/src/@types/event";
|
2022-11-18 09:16:11 +00:00
|
|
|
import { render } from "@testing-library/react";
|
2022-12-13 15:09:15 +00:00
|
|
|
import { Room } from "matrix-js-sdk/src/models/room";
|
2022-02-22 10:39:08 +00:00
|
|
|
|
2022-12-13 15:09:15 +00:00
|
|
|
import { stubClient } from "../../../test-utils";
|
2022-03-02 21:09:24 +00:00
|
|
|
import SearchResultTile from "../../../../src/components/views/rooms/SearchResultTile";
|
2022-12-13 15:09:15 +00:00
|
|
|
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
|
|
|
|
|
|
|
const ROOM_ID = "!qPewotXpIctQySfjSy:localhost";
|
2022-02-22 10:39:08 +00:00
|
|
|
|
|
|
|
describe("SearchResultTile", () => {
|
|
|
|
beforeAll(() => {
|
2022-12-13 15:09:15 +00:00
|
|
|
stubClient();
|
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
|
|
|
|
const room = new Room(ROOM_ID, cli, "@bob:example.org");
|
|
|
|
jest.spyOn(cli, "getRoom").mockReturnValue(room);
|
2022-02-22 10:39:08 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Sets up appropriate callEventGrouper for m.call. events", () => {
|
2022-11-18 09:16:11 +00:00
|
|
|
const { container } = render(
|
2022-02-22 10:39:08 +00:00
|
|
|
<SearchResultTile
|
|
|
|
searchResult={SearchResult.fromJson(
|
|
|
|
{
|
|
|
|
rank: 0.00424866,
|
|
|
|
result: {
|
|
|
|
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",
|
2022-12-12 11:24:14 +00:00
|
|
|
},
|
2022-02-22 10:39:08 +00:00
|
|
|
event_id: "$144429830826TWwbB:localhost",
|
|
|
|
origin_server_ts: 1432735824653,
|
2022-12-13 15:09:15 +00:00
|
|
|
room_id: ROOM_ID,
|
2022-02-22 10:39:08 +00:00
|
|
|
sender: "@example:example.org",
|
|
|
|
type: "m.room.message",
|
|
|
|
unsigned: {
|
|
|
|
age: 1234,
|
2022-12-12 11:24:14 +00:00
|
|
|
},
|
2022-02-22 10:39:08 +00:00
|
|
|
},
|
|
|
|
context: {
|
|
|
|
end: "",
|
|
|
|
start: "",
|
|
|
|
profile_info: {},
|
|
|
|
events_before: [
|
2022-12-12 11:24:14 +00:00
|
|
|
{
|
2022-02-22 10:39:08 +00:00
|
|
|
type: EventType.CallInvite,
|
|
|
|
sender: "@user1:server",
|
2022-12-13 15:09:15 +00:00
|
|
|
room_id: ROOM_ID,
|
2022-02-22 10:39:08 +00:00
|
|
|
origin_server_ts: 1432735824652,
|
|
|
|
content: { call_id: "call.1" },
|
|
|
|
event_id: "$1:server",
|
2022-12-12 11:24:14 +00:00
|
|
|
},
|
|
|
|
],
|
2022-02-22 10:39:08 +00:00
|
|
|
events_after: [
|
2022-12-12 11:24:14 +00:00
|
|
|
{
|
2022-02-22 10:39:08 +00:00
|
|
|
type: EventType.CallAnswer,
|
|
|
|
sender: "@user2:server",
|
2022-12-13 15:09:15 +00:00
|
|
|
room_id: ROOM_ID,
|
2022-02-22 10:39:08 +00:00
|
|
|
origin_server_ts: 1432735824654,
|
|
|
|
content: { call_id: "call.1" },
|
|
|
|
event_id: "$2:server",
|
2022-12-12 11:24:14 +00:00
|
|
|
},
|
|
|
|
],
|
2022-02-22 10:39:08 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
(o) => new MatrixEvent(o),
|
|
|
|
)}
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
|
2022-11-18 09:16:11 +00:00
|
|
|
const tiles = container.querySelectorAll<HTMLElement>(".mx_EventTile");
|
2022-02-22 10:39:08 +00:00
|
|
|
expect(tiles.length).toEqual(2);
|
2022-11-18 09:16:11 +00:00
|
|
|
expect(tiles[0].dataset.eventId).toBe("$1:server");
|
|
|
|
expect(tiles[1].dataset.eventId).toBe("$144429830826TWwbB:localhost");
|
2022-02-22 10:39:08 +00:00
|
|
|
});
|
|
|
|
});
|