mirror of https://github.com/vector-im/riot-web
Show "Invite" menu option if "UIComponent.sendInvites" is enabled. (#10363)
* Show "Invite" menu option if "UIComponent.sendInvites" is enabled. Signed-off-by: Mikhail Aheichyk <mikhail.aheichyk@nordeck.net> * Update test names Signed-off-by: Mikhail Aheichyk <mikhail.aheichyk@nordeck.net> --------- Signed-off-by: Mikhail Aheichyk <mikhail.aheichyk@nordeck.net> Co-authored-by: Mikhail Aheichyk <mikhail.aheichyk@nordeck.net>pull/28788/head^2
parent
d821323e5c
commit
68fa9aed9d
|
@ -50,6 +50,8 @@ import { KeyBindingAction } from "../../../accessibility/KeyboardShortcuts";
|
||||||
import SettingsStore from "../../../settings/SettingsStore";
|
import SettingsStore from "../../../settings/SettingsStore";
|
||||||
import DevtoolsDialog from "../dialogs/DevtoolsDialog";
|
import DevtoolsDialog from "../dialogs/DevtoolsDialog";
|
||||||
import { SdkContextClass } from "../../../contexts/SDKContext";
|
import { SdkContextClass } from "../../../contexts/SDKContext";
|
||||||
|
import { shouldShowComponent } from "../../../customisations/helpers/UIComponents";
|
||||||
|
import { UIComponent } from "../../../settings/UIFeature";
|
||||||
|
|
||||||
interface IProps extends IContextMenuProps {
|
interface IProps extends IContextMenuProps {
|
||||||
room: Room;
|
room: Room;
|
||||||
|
@ -113,7 +115,7 @@ const RoomContextMenu: React.FC<IProps> = ({ room, onFinished, ...props }) => {
|
||||||
videoRoomsEnabled && (room.isElementVideoRoom() || (elementCallVideoRoomsEnabled && room.isCallRoom()));
|
videoRoomsEnabled && (room.isElementVideoRoom() || (elementCallVideoRoomsEnabled && room.isCallRoom()));
|
||||||
|
|
||||||
let inviteOption: JSX.Element | undefined;
|
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 => {
|
const onInviteClick = (ev: ButtonEvent): void => {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
|
|
|
@ -38,6 +38,8 @@ import IconizedContextMenu, {
|
||||||
IconizedContextMenuOptionList,
|
IconizedContextMenuOptionList,
|
||||||
} from "../context_menus/IconizedContextMenu";
|
} from "../context_menus/IconizedContextMenu";
|
||||||
import { ButtonEvent } from "../elements/AccessibleButton";
|
import { ButtonEvent } from "../elements/AccessibleButton";
|
||||||
|
import { shouldShowComponent } from "../../../customisations/helpers/UIComponents";
|
||||||
|
import { UIComponent } from "../../../settings/UIFeature";
|
||||||
|
|
||||||
export interface RoomGeneralContextMenuProps extends IContextMenuProps {
|
export interface RoomGeneralContextMenuProps extends IContextMenuProps {
|
||||||
room: Room;
|
room: Room;
|
||||||
|
@ -119,7 +121,7 @@ export const RoomGeneralContextMenu: React.FC<RoomGeneralContextMenuProps> = ({
|
||||||
);
|
);
|
||||||
|
|
||||||
let inviteOption: JSX.Element | null = null;
|
let inviteOption: JSX.Element | null = null;
|
||||||
if (room.canInvite(cli.getUserId()!) && !isDm) {
|
if (room.canInvite(cli.getUserId()!) && !isDm && shouldShowComponent(UIComponent.InviteUsers)) {
|
||||||
inviteOption = (
|
inviteOption = (
|
||||||
<IconizedContextMenuOption
|
<IconizedContextMenuOption
|
||||||
onClick={wrapHandler(
|
onClick={wrapHandler(
|
||||||
|
|
|
@ -0,0 +1,86 @@
|
||||||
|
/*
|
||||||
|
Copyright 2023 Mikhail Aheichyk
|
||||||
|
Copyright 2023 Nordeck IT + Consulting GmbH.
|
||||||
|
|
||||||
|
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 { render, screen } from "@testing-library/react";
|
||||||
|
import React, { ComponentProps } from "react";
|
||||||
|
import { mocked } from "jest-mock";
|
||||||
|
import { MatrixClient, PendingEventOrdering } from "matrix-js-sdk/src/client";
|
||||||
|
import { Room } from "matrix-js-sdk/src/models/room";
|
||||||
|
|
||||||
|
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext";
|
||||||
|
import RoomContextMenu from "../../../../src/components/views/context_menus/RoomContextMenu";
|
||||||
|
import { shouldShowComponent } from "../../../../src/customisations/helpers/UIComponents";
|
||||||
|
import { stubClient } from "../../../test-utils";
|
||||||
|
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
||||||
|
import DMRoomMap from "../../../../src/utils/DMRoomMap";
|
||||||
|
|
||||||
|
jest.mock("../../../../src/customisations/helpers/UIComponents", () => ({
|
||||||
|
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<ComponentProps<typeof RoomContextMenu>> = {}) {
|
||||||
|
return render(
|
||||||
|
<MatrixClientContext.Provider value={mockClient}>
|
||||||
|
<RoomContextMenu room={room} onFinished={onFinished} {...props} />
|
||||||
|
</MatrixClientContext.Provider>,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
});
|
||||||
|
});
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
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 { mocked } from "jest-mock";
|
||||||
import { ReceiptType } from "matrix-js-sdk/src/@types/read_receipts";
|
import { ReceiptType } from "matrix-js-sdk/src/@types/read_receipts";
|
||||||
import { MatrixClient, PendingEventOrdering } from "matrix-js-sdk/src/client";
|
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 RoomListStore from "../../../../src/stores/room-list/RoomListStore";
|
||||||
import DMRoomMap from "../../../../src/utils/DMRoomMap";
|
import DMRoomMap from "../../../../src/utils/DMRoomMap";
|
||||||
import { mkMessage, stubClient } from "../../../test-utils/test-utils";
|
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", () => {
|
describe("RoomGeneralContextMenu", () => {
|
||||||
const ROOM_ID = "!123:matrix.org";
|
const ROOM_ID = "!123:matrix.org";
|
||||||
|
@ -93,6 +99,28 @@ describe("RoomGeneralContextMenu", () => {
|
||||||
expect(container).toMatchSnapshot();
|
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 () => {
|
it("marks the room as read", async () => {
|
||||||
const event = mkMessage({
|
const event = mkMessage({
|
||||||
event: true,
|
event: true,
|
||||||
|
|
Loading…
Reference in New Issue