diff --git a/src/components/views/context_menus/RoomContextMenu.tsx b/src/components/views/context_menus/RoomContextMenu.tsx index bad72b2bb3..5c2b0c3884 100644 --- a/src/components/views/context_menus/RoomContextMenu.tsx +++ b/src/components/views/context_menus/RoomContextMenu.tsx @@ -50,6 +50,8 @@ import { KeyBindingAction } from "../../../accessibility/KeyboardShortcuts"; import SettingsStore from "../../../settings/SettingsStore"; import DevtoolsDialog from "../dialogs/DevtoolsDialog"; import { SdkContextClass } from "../../../contexts/SDKContext"; +import { shouldShowComponent } from "../../../customisations/helpers/UIComponents"; +import { UIComponent } from "../../../settings/UIFeature"; interface IProps extends IContextMenuProps { room: Room; @@ -113,7 +115,7 @@ const RoomContextMenu: React.FC = ({ room, onFinished, ...props }) => { videoRoomsEnabled && (room.isElementVideoRoom() || (elementCallVideoRoomsEnabled && room.isCallRoom())); let inviteOption: JSX.Element | undefined; - if (room.canInvite(cli.getUserId()!) && !isDm) { + if (room.canInvite(cli.getUserId()!) && !isDm && shouldShowComponent(UIComponent.InviteUsers)) { const onInviteClick = (ev: ButtonEvent): void => { ev.preventDefault(); ev.stopPropagation(); diff --git a/src/components/views/context_menus/RoomGeneralContextMenu.tsx b/src/components/views/context_menus/RoomGeneralContextMenu.tsx index 9b0cadb923..9cac6f4615 100644 --- a/src/components/views/context_menus/RoomGeneralContextMenu.tsx +++ b/src/components/views/context_menus/RoomGeneralContextMenu.tsx @@ -38,6 +38,8 @@ import IconizedContextMenu, { IconizedContextMenuOptionList, } from "../context_menus/IconizedContextMenu"; import { ButtonEvent } from "../elements/AccessibleButton"; +import { shouldShowComponent } from "../../../customisations/helpers/UIComponents"; +import { UIComponent } from "../../../settings/UIFeature"; export interface RoomGeneralContextMenuProps extends IContextMenuProps { room: Room; @@ -119,7 +121,7 @@ export const RoomGeneralContextMenu: React.FC = ({ ); let inviteOption: JSX.Element | null = null; - if (room.canInvite(cli.getUserId()!) && !isDm) { + if (room.canInvite(cli.getUserId()!) && !isDm && shouldShowComponent(UIComponent.InviteUsers)) { inviteOption = ( ({ + shouldShowComponent: jest.fn(), +})); + +describe("RoomContextMenu", () => { + const ROOM_ID = "!123:matrix.org"; + + let room: Room; + let mockClient: MatrixClient; + + let onFinished: () => void; + + beforeEach(() => { + jest.clearAllMocks(); + + stubClient(); + mockClient = mocked(MatrixClientPeg.get()); + + room = new Room(ROOM_ID, mockClient, mockClient.getUserId() ?? "", { + pendingEventOrdering: PendingEventOrdering.Detached, + }); + + const dmRoomMap = { + getUserIdForRoomId: jest.fn(), + } as unknown as DMRoomMap; + DMRoomMap.setShared(dmRoomMap); + + onFinished = jest.fn(); + }); + + function getComponent(props: Partial> = {}) { + return render( + + + , + ); + } + + it("does not render invite menu item when UIComponent customisations disable invite", () => { + jest.spyOn(room, "canInvite").mockReturnValue(true); + mocked(shouldShowComponent).mockReturnValue(false); + + getComponent(); + + expect(screen.queryByRole("menuitem", { name: "Invite" })).not.toBeInTheDocument(); + }); + + it("renders invite menu item when UIComponent customisations enable invite", () => { + jest.spyOn(room, "canInvite").mockReturnValue(true); + mocked(shouldShowComponent).mockReturnValue(true); + + getComponent(); + + expect(screen.getByRole("menuitem", { name: "Invite" })).toBeInTheDocument(); + }); +}); diff --git a/test/components/views/context_menus/RoomGeneralContextMenu-test.tsx b/test/components/views/context_menus/RoomGeneralContextMenu-test.tsx index c3962e10ff..cadf067ef5 100644 --- a/test/components/views/context_menus/RoomGeneralContextMenu-test.tsx +++ b/test/components/views/context_menus/RoomGeneralContextMenu-test.tsx @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { fireEvent, getByLabelText, render } from "@testing-library/react"; +import { fireEvent, getByLabelText, render, screen } from "@testing-library/react"; import { mocked } from "jest-mock"; import { ReceiptType } from "matrix-js-sdk/src/@types/read_receipts"; import { MatrixClient, PendingEventOrdering } from "matrix-js-sdk/src/client"; @@ -32,6 +32,12 @@ import { DefaultTagID } from "../../../../src/stores/room-list/models"; import RoomListStore from "../../../../src/stores/room-list/RoomListStore"; import DMRoomMap from "../../../../src/utils/DMRoomMap"; import { mkMessage, stubClient } from "../../../test-utils/test-utils"; +import { shouldShowComponent } from "../../../../src/customisations/helpers/UIComponents"; +import { UIComponent } from "../../../../src/settings/UIFeature"; + +jest.mock("../../../../src/customisations/helpers/UIComponents", () => ({ + shouldShowComponent: jest.fn(), +})); describe("RoomGeneralContextMenu", () => { const ROOM_ID = "!123:matrix.org"; @@ -93,6 +99,28 @@ describe("RoomGeneralContextMenu", () => { expect(container).toMatchSnapshot(); }); + it("does not render invite menu item when UIComponent customisations disable room invite", () => { + room.updateMyMembership("join"); + jest.spyOn(room, "canInvite").mockReturnValue(true); + mocked(shouldShowComponent).mockReturnValue(false); + + getComponent({}); + + expect(shouldShowComponent).toHaveBeenCalledWith(UIComponent.InviteUsers); + expect(screen.queryByRole("menuitem", { name: "Invite" })).not.toBeInTheDocument(); + }); + + it("renders invite menu item when UIComponent customisations enables room invite", () => { + room.updateMyMembership("join"); + jest.spyOn(room, "canInvite").mockReturnValue(true); + mocked(shouldShowComponent).mockReturnValue(true); + + getComponent({}); + + expect(shouldShowComponent).toHaveBeenCalledWith(UIComponent.InviteUsers); + expect(screen.getByRole("menuitem", { name: "Invite" })).toBeInTheDocument(); + }); + it("marks the room as read", async () => { const event = mkMessage({ event: true,