2022-07-20 16:07:06 +03:00
|
|
|
|
/*
|
2024-09-09 16:57:16 +03:00
|
|
|
|
Copyright 2024 New Vector Ltd.
|
|
|
|
|
Copyright 2015-2022 The Matrix.org Foundation C.I.C.
|
2022-07-20 16:07:06 +03:00
|
|
|
|
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
|
|
|
|
|
|
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.
|
2022-07-20 16:07:06 +03:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import React from "react";
|
2024-10-14 19:11:58 +03:00
|
|
|
|
import { render, screen } from "jest-matrix-react";
|
2022-07-20 16:07:06 +03:00
|
|
|
|
import { MatrixClient, Room } from "matrix-js-sdk/src/matrix";
|
|
|
|
|
|
2024-10-15 16:57:26 +03:00
|
|
|
|
import { LocalRoom } from "../../../../../src/models/LocalRoom";
|
|
|
|
|
import { filterConsole, mkRoomMemberJoinEvent, mkThirdPartyInviteEvent, stubClient } from "../../../../test-utils";
|
|
|
|
|
import RoomContext from "../../../../../src/contexts/RoomContext";
|
|
|
|
|
import MatrixClientContext from "../../../../../src/contexts/MatrixClientContext";
|
|
|
|
|
import NewRoomIntro from "../../../../../src/components/views/rooms/NewRoomIntro";
|
|
|
|
|
import { IRoomState } from "../../../../../src/components/structures/RoomView";
|
|
|
|
|
import DMRoomMap from "../../../../../src/utils/DMRoomMap";
|
|
|
|
|
import { DirectoryMember } from "../../../../../src/utils/direct-messages";
|
2022-07-20 16:07:06 +03:00
|
|
|
|
|
|
|
|
|
const renderNewRoomIntro = (client: MatrixClient, room: Room | LocalRoom) => {
|
|
|
|
|
render(
|
|
|
|
|
<MatrixClientContext.Provider value={client}>
|
|
|
|
|
<RoomContext.Provider value={{ room, roomId: room.roomId } as unknown as IRoomState}>
|
|
|
|
|
<NewRoomIntro />
|
|
|
|
|
</RoomContext.Provider>
|
|
|
|
|
</MatrixClientContext.Provider>,
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
describe("NewRoomIntro", () => {
|
|
|
|
|
let client: MatrixClient;
|
|
|
|
|
const roomId = "!room:example.com";
|
|
|
|
|
const userId = "@user:example.com";
|
|
|
|
|
|
2023-03-06 14:08:04 +03:00
|
|
|
|
filterConsole("Room !room:example.com does not have an m.room.create event");
|
|
|
|
|
|
|
|
|
|
beforeAll(() => {
|
|
|
|
|
client = stubClient();
|
2023-05-23 18:24:12 +03:00
|
|
|
|
DMRoomMap.makeShared(client);
|
2022-07-20 16:07:06 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("for a DM Room", () => {
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
jest.spyOn(DMRoomMap.shared(), "getUserIdForRoomId").mockReturnValue(userId);
|
2023-02-13 20:01:43 +03:00
|
|
|
|
const room = new Room(roomId, client, client.getUserId()!);
|
2022-09-06 10:54:53 +03:00
|
|
|
|
room.name = "test_room";
|
|
|
|
|
renderNewRoomIntro(client, room);
|
2022-07-20 16:07:06 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should render the expected intro", () => {
|
2022-09-06 10:54:53 +03:00
|
|
|
|
const expected = `This is the beginning of your direct message history with test_room.`;
|
|
|
|
|
screen.getByText((id, element) => element?.tagName === "SPAN" && element?.textContent === expected);
|
2022-07-20 16:07:06 +03:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2023-03-06 14:08:04 +03:00
|
|
|
|
it("should render as expected for a DM room with a single third-party invite", () => {
|
|
|
|
|
const room = new Room(roomId, client, client.getSafeUserId());
|
|
|
|
|
room.currentState.setStateEvents([
|
|
|
|
|
mkRoomMemberJoinEvent(client.getSafeUserId(), room.roomId),
|
|
|
|
|
mkThirdPartyInviteEvent(client.getSafeUserId(), "user@example.com", room.roomId),
|
|
|
|
|
]);
|
|
|
|
|
jest.spyOn(DMRoomMap.shared(), "getUserIdForRoomId").mockReturnValue(userId);
|
|
|
|
|
jest.spyOn(DMRoomMap.shared(), "getRoomIds").mockReturnValue(new Set([room.roomId]));
|
|
|
|
|
renderNewRoomIntro(client, room);
|
|
|
|
|
|
|
|
|
|
expect(screen.getByText("Once everyone has joined, you’ll be able to chat")).toBeInTheDocument();
|
|
|
|
|
expect(
|
|
|
|
|
screen.queryByText(
|
|
|
|
|
"Only the two of you are in this conversation, unless either of you invites anyone to join.",
|
|
|
|
|
),
|
|
|
|
|
).not.toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
2022-07-20 16:07:06 +03:00
|
|
|
|
describe("for a DM LocalRoom", () => {
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
jest.spyOn(DMRoomMap.shared(), "getUserIdForRoomId").mockReturnValue(userId);
|
2023-02-13 20:01:43 +03:00
|
|
|
|
const localRoom = new LocalRoom(roomId, client, client.getUserId()!);
|
2022-09-06 10:54:53 +03:00
|
|
|
|
localRoom.name = "test_room";
|
2022-07-20 16:07:06 +03:00
|
|
|
|
localRoom.targets.push(new DirectoryMember({ user_id: userId }));
|
|
|
|
|
renderNewRoomIntro(client, localRoom);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should render the expected intro", () => {
|
2022-09-06 10:54:53 +03:00
|
|
|
|
const expected = `Send your first message to invite test_room to chat`;
|
|
|
|
|
screen.getByText((id, element) => element?.tagName === "SPAN" && element?.textContent === expected);
|
2022-07-20 16:07:06 +03:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|