2023-02-01 21:57:48 +01:00
|
|
|
/*
|
|
|
|
Copyright 2023 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 React from "react";
|
2023-11-11 08:24:48 +01:00
|
|
|
import { render, fireEvent, screen } from "@testing-library/react";
|
|
|
|
import { EventType, MatrixEvent, Room, MatrixClient, JoinRule } from "matrix-js-sdk/src/matrix";
|
|
|
|
import { mocked, MockedObject } from "jest-mock";
|
2024-01-11 20:56:36 +01:00
|
|
|
import { TooltipProvider } from "@vector-im/compound-web";
|
2023-02-01 21:57:48 +01:00
|
|
|
|
|
|
|
import DMRoomMap from "../../../../src/utils/DMRoomMap";
|
|
|
|
import RoomSummaryCard from "../../../../src/components/views/right_panel/RoomSummaryCard";
|
|
|
|
import ShareDialog from "../../../../src/components/views/dialogs/ShareDialog";
|
|
|
|
import ExportDialog from "../../../../src/components/views/dialogs/ExportDialog";
|
|
|
|
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext";
|
|
|
|
import defaultDispatcher from "../../../../src/dispatcher/dispatcher";
|
|
|
|
import * as settingsHooks from "../../../../src/hooks/useSettings";
|
|
|
|
import Modal from "../../../../src/Modal";
|
|
|
|
import RightPanelStore from "../../../../src/stores/right-panel/RightPanelStore";
|
|
|
|
import { RightPanelPhases } from "../../../../src/stores/right-panel/RightPanelStorePhases";
|
2023-11-11 08:24:48 +01:00
|
|
|
import { flushPromises, getMockClientWithEventEmitter, mockClientMethodsUser } from "../../../test-utils";
|
2023-03-12 21:22:30 +01:00
|
|
|
import { PollHistoryDialog } from "../../../../src/components/views/dialogs/PollHistoryDialog";
|
2023-02-27 21:39:55 +01:00
|
|
|
import { RoomPermalinkCreator } from "../../../../src/utils/permalinks/Permalinks";
|
2023-10-20 15:30:37 +02:00
|
|
|
import { _t } from "../../../../src/languageHandler";
|
2023-11-16 04:25:34 +01:00
|
|
|
import SettingsStore from "../../../../src/settings/SettingsStore";
|
2023-12-14 12:10:01 +01:00
|
|
|
import { tagRoom } from "../../../../src/utils/room/tagRoom";
|
|
|
|
import { DefaultTagID } from "../../../../src/stores/room-list/models";
|
|
|
|
|
|
|
|
jest.mock("../../../../src/utils/room/tagRoom");
|
2023-02-01 21:57:48 +01:00
|
|
|
|
|
|
|
describe("<RoomSummaryCard />", () => {
|
|
|
|
const userId = "@alice:domain.org";
|
2023-11-11 08:24:48 +01:00
|
|
|
|
2023-02-01 21:57:48 +01:00
|
|
|
const roomId = "!room:domain.org";
|
2023-11-11 08:24:48 +01:00
|
|
|
let mockClient!: MockedObject<MatrixClient>;
|
|
|
|
let room!: Room;
|
|
|
|
|
|
|
|
const getComponent = (props = {}) => {
|
|
|
|
const defaultProps = {
|
|
|
|
room,
|
|
|
|
onClose: jest.fn(),
|
|
|
|
permalinkCreator: new RoomPermalinkCreator(room),
|
|
|
|
};
|
|
|
|
|
|
|
|
return render(<RoomSummaryCard {...defaultProps} {...props} />, {
|
2023-02-01 21:57:48 +01:00
|
|
|
wrapper: ({ children }) => (
|
2024-01-11 20:56:36 +01:00
|
|
|
<MatrixClientContext.Provider value={mockClient}>
|
|
|
|
<TooltipProvider>{children}</TooltipProvider>
|
|
|
|
</MatrixClientContext.Provider>
|
2023-02-01 21:57:48 +01:00
|
|
|
),
|
|
|
|
});
|
2023-11-11 08:24:48 +01:00
|
|
|
};
|
2023-02-01 21:57:48 +01:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2023-11-11 08:24:48 +01:00
|
|
|
mockClient = getMockClientWithEventEmitter({
|
|
|
|
...mockClientMethodsUser(userId),
|
|
|
|
getAccountData: jest.fn(),
|
|
|
|
isRoomEncrypted: jest.fn(),
|
|
|
|
getOrCreateFilter: jest.fn().mockResolvedValue({ filterId: 1 }),
|
|
|
|
getRoom: jest.fn(),
|
2023-12-14 12:10:01 +01:00
|
|
|
isGuest: jest.fn().mockReturnValue(false),
|
|
|
|
deleteRoomTag: jest.fn().mockResolvedValue({}),
|
|
|
|
setRoomTag: jest.fn().mockResolvedValue({}),
|
2023-11-11 08:24:48 +01:00
|
|
|
});
|
|
|
|
room = new Room(roomId, mockClient, userId);
|
|
|
|
const roomCreateEvent = new MatrixEvent({
|
|
|
|
type: "m.room.create",
|
|
|
|
room_id: roomId,
|
|
|
|
sender: userId,
|
|
|
|
content: {
|
|
|
|
creator: userId,
|
|
|
|
room_version: "5",
|
|
|
|
},
|
|
|
|
state_key: "",
|
|
|
|
});
|
|
|
|
room.currentState.setStateEvents([roomCreateEvent]);
|
2023-12-14 12:10:01 +01:00
|
|
|
room.updateMyMembership("join");
|
2023-11-11 08:24:48 +01:00
|
|
|
|
|
|
|
jest.spyOn(Modal, "createDialog");
|
|
|
|
jest.spyOn(RightPanelStore.instance, "pushCard");
|
|
|
|
jest.spyOn(settingsHooks, "useFeatureEnabled").mockReturnValue(false);
|
|
|
|
jest.spyOn(defaultDispatcher, "dispatch");
|
2023-02-01 21:57:48 +01:00
|
|
|
jest.clearAllMocks();
|
2023-05-23 17:24:12 +02:00
|
|
|
DMRoomMap.makeShared(mockClient);
|
2023-02-01 21:57:48 +01:00
|
|
|
|
|
|
|
mockClient.getRoom.mockReturnValue(room);
|
|
|
|
jest.spyOn(room, "isElementVideoRoom").mockRestore();
|
|
|
|
jest.spyOn(room, "isCallRoom").mockRestore();
|
2023-11-11 08:24:48 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
jest.restoreAllMocks();
|
2023-02-01 21:57:48 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it("renders the room summary", () => {
|
|
|
|
const { container } = getComponent();
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2023-10-20 15:30:37 +02:00
|
|
|
it("opens the search", async () => {
|
|
|
|
const onSearchClick = jest.fn();
|
|
|
|
const { getByLabelText } = getComponent({
|
|
|
|
onSearchClick,
|
|
|
|
});
|
|
|
|
|
|
|
|
const searchBtn = getByLabelText(_t("action|search"));
|
|
|
|
fireEvent.click(searchBtn);
|
|
|
|
expect(onSearchClick).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2023-02-01 21:57:48 +01:00
|
|
|
it("opens room file panel on button click", () => {
|
|
|
|
const { getByText } = getComponent();
|
|
|
|
|
|
|
|
fireEvent.click(getByText("Files"));
|
|
|
|
|
2023-11-11 08:24:48 +01:00
|
|
|
expect(RightPanelStore.instance.pushCard).toHaveBeenCalledWith({ phase: RightPanelPhases.FilePanel }, true);
|
2023-02-01 21:57:48 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it("opens room export dialog on button click", () => {
|
|
|
|
const { getByText } = getComponent();
|
|
|
|
|
2023-11-16 04:25:34 +01:00
|
|
|
fireEvent.click(getByText(_t("export_chat|title")));
|
2023-02-01 21:57:48 +01:00
|
|
|
|
2023-11-11 08:24:48 +01:00
|
|
|
expect(Modal.createDialog).toHaveBeenCalledWith(ExportDialog, { room });
|
2023-02-01 21:57:48 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it("opens share room dialog on button click", () => {
|
|
|
|
const { getByText } = getComponent();
|
|
|
|
|
2023-11-16 04:25:34 +01:00
|
|
|
fireEvent.click(getByText(_t("action|copy_link")));
|
2023-02-01 21:57:48 +01:00
|
|
|
|
2023-11-11 08:24:48 +01:00
|
|
|
expect(Modal.createDialog).toHaveBeenCalledWith(ShareDialog, { target: room });
|
2023-02-01 21:57:48 +01:00
|
|
|
});
|
|
|
|
|
2023-12-14 12:10:01 +01:00
|
|
|
it("opens invite dialog on button click", () => {
|
|
|
|
const { getByText } = getComponent();
|
|
|
|
|
|
|
|
fireEvent.click(getByText(_t("action|invite")));
|
|
|
|
|
|
|
|
expect(defaultDispatcher.dispatch).toHaveBeenCalledWith({ action: "view_invite", roomId: room.roomId });
|
|
|
|
});
|
|
|
|
|
|
|
|
it("fires favourite dispatch on button click", () => {
|
|
|
|
const { getByText } = getComponent();
|
|
|
|
|
|
|
|
fireEvent.click(getByText(_t("room|context_menu|favourite")));
|
|
|
|
|
|
|
|
expect(tagRoom).toHaveBeenCalledWith(room, DefaultTagID.Favourite);
|
|
|
|
});
|
|
|
|
|
2023-02-01 21:57:48 +01:00
|
|
|
it("opens room settings on button click", () => {
|
|
|
|
const { getByText } = getComponent();
|
|
|
|
|
2023-11-16 04:25:34 +01:00
|
|
|
fireEvent.click(getByText(_t("common|settings")));
|
2023-02-01 21:57:48 +01:00
|
|
|
|
2023-11-11 08:24:48 +01:00
|
|
|
expect(defaultDispatcher.dispatch).toHaveBeenCalledWith({ action: "open_room_settings" });
|
2023-02-01 21:57:48 +01:00
|
|
|
});
|
|
|
|
|
2023-11-16 04:25:34 +01:00
|
|
|
it("renders room members options when new room UI is not enabled", () => {
|
|
|
|
jest.spyOn(SettingsStore, "getValue").mockReturnValue(false);
|
|
|
|
const { getByText } = getComponent();
|
|
|
|
|
|
|
|
fireEvent.click(getByText(_t("common|people")));
|
|
|
|
|
|
|
|
expect(RightPanelStore.instance.pushCard).toHaveBeenCalledWith(
|
|
|
|
{ phase: RightPanelPhases.RoomMemberList },
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2023-02-01 21:57:48 +01:00
|
|
|
describe("pinning", () => {
|
|
|
|
it("renders pins options when pinning feature is enabled", () => {
|
2023-11-11 08:24:48 +01:00
|
|
|
mocked(settingsHooks.useFeatureEnabled).mockImplementation((feature) => feature === "feature_pinning");
|
2023-02-01 21:57:48 +01:00
|
|
|
const { getByText } = getComponent();
|
|
|
|
|
|
|
|
expect(getByText("Pinned")).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("poll history", () => {
|
2023-03-15 21:54:12 +01:00
|
|
|
it("renders poll history option", () => {
|
2023-02-01 21:57:48 +01:00
|
|
|
const { getByText } = getComponent();
|
|
|
|
|
2023-03-29 00:13:51 +02:00
|
|
|
expect(getByText("Poll history")).toBeInTheDocument();
|
2023-02-01 21:57:48 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it("opens poll history dialog on button click", () => {
|
2023-11-11 08:24:48 +01:00
|
|
|
const permalinkCreator = new RoomPermalinkCreator(room);
|
|
|
|
const { getByText } = getComponent({ permalinkCreator });
|
2023-02-01 21:57:48 +01:00
|
|
|
|
2023-03-29 00:13:51 +02:00
|
|
|
fireEvent.click(getByText("Poll history"));
|
2023-02-01 21:57:48 +01:00
|
|
|
|
2023-11-11 08:24:48 +01:00
|
|
|
expect(Modal.createDialog).toHaveBeenCalledWith(PollHistoryDialog, {
|
2023-02-27 21:39:55 +01:00
|
|
|
room,
|
|
|
|
matrixClient: mockClient,
|
2023-11-11 08:24:48 +01:00
|
|
|
permalinkCreator: permalinkCreator,
|
2023-02-27 21:39:55 +01:00
|
|
|
});
|
2023-02-01 21:57:48 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("video rooms", () => {
|
|
|
|
it("does not render irrelevant options for element video room", () => {
|
|
|
|
jest.spyOn(room, "isElementVideoRoom").mockReturnValue(true);
|
2023-11-11 08:24:48 +01:00
|
|
|
mocked(settingsHooks.useFeatureEnabled).mockImplementation(
|
2023-02-01 21:57:48 +01:00
|
|
|
(feature) => feature === "feature_video_rooms" || feature === "feature_pinning",
|
|
|
|
);
|
|
|
|
const { queryByText } = getComponent();
|
|
|
|
|
|
|
|
// options not rendered
|
|
|
|
expect(queryByText("Files")).not.toBeInTheDocument();
|
|
|
|
expect(queryByText("Pinned")).not.toBeInTheDocument();
|
|
|
|
expect(queryByText("Export chat")).not.toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("does not render irrelevant options for element call room", () => {
|
|
|
|
jest.spyOn(room, "isCallRoom").mockReturnValue(true);
|
2023-11-11 08:24:48 +01:00
|
|
|
mocked(settingsHooks.useFeatureEnabled).mockImplementation(
|
2023-02-01 21:57:48 +01:00
|
|
|
(feature) =>
|
|
|
|
feature === "feature_element_call_video_rooms" ||
|
|
|
|
feature === "feature_video_rooms" ||
|
|
|
|
feature === "feature_pinning",
|
|
|
|
);
|
|
|
|
const { queryByText } = getComponent();
|
|
|
|
|
|
|
|
// options not rendered
|
|
|
|
expect(queryByText("Files")).not.toBeInTheDocument();
|
|
|
|
expect(queryByText("Pinned")).not.toBeInTheDocument();
|
|
|
|
expect(queryByText("Export chat")).not.toBeInTheDocument();
|
|
|
|
});
|
|
|
|
});
|
2023-11-11 08:24:48 +01:00
|
|
|
|
|
|
|
describe("public room label", () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.spyOn(room.currentState, "getJoinRule").mockReturnValue(JoinRule.Public);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("does not show public room label for a DM", async () => {
|
|
|
|
mockClient.getAccountData.mockImplementation(
|
|
|
|
(eventType) =>
|
|
|
|
({
|
|
|
|
[EventType.Direct]: new MatrixEvent({
|
|
|
|
type: EventType.Direct,
|
|
|
|
content: {
|
|
|
|
"@bob:sesame.st": ["some-room-id"],
|
|
|
|
// this room is a DM with ernie
|
|
|
|
"@ernie:sesame.st": ["some-other-room-id", room.roomId],
|
|
|
|
},
|
|
|
|
}),
|
2024-01-02 19:56:39 +01:00
|
|
|
})[eventType],
|
2023-11-11 08:24:48 +01:00
|
|
|
);
|
|
|
|
getComponent();
|
|
|
|
|
|
|
|
await flushPromises();
|
|
|
|
|
|
|
|
expect(screen.queryByText("Public room")).not.toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("does not show public room label for non public room", async () => {
|
|
|
|
jest.spyOn(room.currentState, "getJoinRule").mockReturnValue(JoinRule.Invite);
|
|
|
|
getComponent();
|
|
|
|
|
|
|
|
await flushPromises();
|
|
|
|
|
|
|
|
expect(screen.queryByText("Public room")).not.toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("shows a public room label for a public room", async () => {
|
|
|
|
jest.spyOn(room.currentState, "getJoinRule").mockReturnValue(JoinRule.Public);
|
|
|
|
getComponent();
|
|
|
|
|
|
|
|
await flushPromises();
|
|
|
|
|
|
|
|
expect(screen.queryByText("Public room")).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
});
|
2023-02-01 21:57:48 +01:00
|
|
|
});
|