2023-06-09 12:33:54 +00:00
|
|
|
/*
|
2024-09-09 13:57:16 +00:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2023-06-09 12:33:54 +00:00
|
|
|
Copyright 2023 Mikhail Aheichyk
|
|
|
|
Copyright 2023 Nordeck IT + Consulting GmbH.
|
|
|
|
|
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.
|
2023-06-09 12:33:54 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
import React from "react";
|
2024-10-14 16:11:58 +00:00
|
|
|
import { render, screen, RenderResult } from "jest-matrix-react";
|
2023-06-09 12:33:54 +00:00
|
|
|
import { mocked } from "jest-mock";
|
2023-08-09 07:18:41 +00:00
|
|
|
import { Room, MatrixClient, PendingEventOrdering } from "matrix-js-sdk/src/matrix";
|
2023-06-09 12:33:54 +00:00
|
|
|
|
2024-10-15 13:57:26 +00:00
|
|
|
import { RoomResultContextMenus } from "../../../../../../src/components/views/dialogs/spotlight/RoomResultContextMenus";
|
|
|
|
import { filterConsole, stubClient } from "../../../../../test-utils";
|
|
|
|
import { shouldShowComponent } from "../../../../../../src/customisations/helpers/UIComponents";
|
|
|
|
import { UIComponent } from "../../../../../../src/settings/UIFeature";
|
2023-06-09 12:33:54 +00:00
|
|
|
|
2024-10-15 13:57:26 +00:00
|
|
|
jest.mock("../../../../../../src/customisations/helpers/UIComponents", () => ({
|
2023-06-09 12:33:54 +00:00
|
|
|
shouldShowComponent: jest.fn(),
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe("RoomResultContextMenus", () => {
|
|
|
|
let client: MatrixClient;
|
|
|
|
let room: Room;
|
|
|
|
|
|
|
|
const renderRoomResultContextMenus = (): RenderResult => {
|
|
|
|
return render(<RoomResultContextMenus room={room} />);
|
|
|
|
};
|
|
|
|
|
|
|
|
filterConsole(
|
|
|
|
// irrelevant for this test
|
|
|
|
"Room !1:example.org does not have an m.room.create event",
|
|
|
|
);
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
client = stubClient();
|
|
|
|
room = new Room("!1:example.org", client, "@alice:example.org", {
|
|
|
|
pendingEventOrdering: PendingEventOrdering.Detached,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("does not render the room options context menu when UIComponent customisations disable room options", () => {
|
|
|
|
mocked(shouldShowComponent).mockReturnValue(false);
|
|
|
|
renderRoomResultContextMenus();
|
|
|
|
expect(shouldShowComponent).toHaveBeenCalledWith(UIComponent.RoomOptionsMenu);
|
|
|
|
expect(screen.queryByRole("button", { name: "Room options" })).not.toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("renders the room options context menu when UIComponent customisations enable room options", () => {
|
|
|
|
mocked(shouldShowComponent).mockReturnValue(true);
|
|
|
|
renderRoomResultContextMenus();
|
|
|
|
expect(shouldShowComponent).toHaveBeenCalledWith(UIComponent.RoomOptionsMenu);
|
|
|
|
expect(screen.queryByRole("button", { name: "Room options" })).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
});
|