Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 68fa9ae

Browse files
maheichykMikhail Aheichyk
and
Mikhail Aheichyk
authored
Show "Invite" menu option if "UIComponent.sendInvites" is enabled. (#10363)
* Show "Invite" menu option if "UIComponent.sendInvites" is enabled. Signed-off-by: Mikhail Aheichyk <[email protected]> * Update test names Signed-off-by: Mikhail Aheichyk <[email protected]> --------- Signed-off-by: Mikhail Aheichyk <[email protected]> Co-authored-by: Mikhail Aheichyk <[email protected]>
1 parent d821323 commit 68fa9ae

File tree

4 files changed

+121
-3
lines changed

4 files changed

+121
-3
lines changed

Diff for: src/components/views/context_menus/RoomContextMenu.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ import { KeyBindingAction } from "../../../accessibility/KeyboardShortcuts";
5050
import SettingsStore from "../../../settings/SettingsStore";
5151
import DevtoolsDialog from "../dialogs/DevtoolsDialog";
5252
import { SdkContextClass } from "../../../contexts/SDKContext";
53+
import { shouldShowComponent } from "../../../customisations/helpers/UIComponents";
54+
import { UIComponent } from "../../../settings/UIFeature";
5355

5456
interface IProps extends IContextMenuProps {
5557
room: Room;
@@ -113,7 +115,7 @@ const RoomContextMenu: React.FC<IProps> = ({ room, onFinished, ...props }) => {
113115
videoRoomsEnabled && (room.isElementVideoRoom() || (elementCallVideoRoomsEnabled && room.isCallRoom()));
114116

115117
let inviteOption: JSX.Element | undefined;
116-
if (room.canInvite(cli.getUserId()!) && !isDm) {
118+
if (room.canInvite(cli.getUserId()!) && !isDm && shouldShowComponent(UIComponent.InviteUsers)) {
117119
const onInviteClick = (ev: ButtonEvent): void => {
118120
ev.preventDefault();
119121
ev.stopPropagation();

Diff for: src/components/views/context_menus/RoomGeneralContextMenu.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ import IconizedContextMenu, {
3838
IconizedContextMenuOptionList,
3939
} from "../context_menus/IconizedContextMenu";
4040
import { ButtonEvent } from "../elements/AccessibleButton";
41+
import { shouldShowComponent } from "../../../customisations/helpers/UIComponents";
42+
import { UIComponent } from "../../../settings/UIFeature";
4143

4244
export interface RoomGeneralContextMenuProps extends IContextMenuProps {
4345
room: Room;
@@ -119,7 +121,7 @@ export const RoomGeneralContextMenu: React.FC<RoomGeneralContextMenuProps> = ({
119121
);
120122

121123
let inviteOption: JSX.Element | null = null;
122-
if (room.canInvite(cli.getUserId()!) && !isDm) {
124+
if (room.canInvite(cli.getUserId()!) && !isDm && shouldShowComponent(UIComponent.InviteUsers)) {
123125
inviteOption = (
124126
<IconizedContextMenuOption
125127
onClick={wrapHandler(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
Copyright 2023 Mikhail Aheichyk
3+
Copyright 2023 Nordeck IT + Consulting GmbH.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
import { render, screen } from "@testing-library/react";
19+
import React, { ComponentProps } from "react";
20+
import { mocked } from "jest-mock";
21+
import { MatrixClient, PendingEventOrdering } from "matrix-js-sdk/src/client";
22+
import { Room } from "matrix-js-sdk/src/models/room";
23+
24+
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext";
25+
import RoomContextMenu from "../../../../src/components/views/context_menus/RoomContextMenu";
26+
import { shouldShowComponent } from "../../../../src/customisations/helpers/UIComponents";
27+
import { stubClient } from "../../../test-utils";
28+
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
29+
import DMRoomMap from "../../../../src/utils/DMRoomMap";
30+
31+
jest.mock("../../../../src/customisations/helpers/UIComponents", () => ({
32+
shouldShowComponent: jest.fn(),
33+
}));
34+
35+
describe("RoomContextMenu", () => {
36+
const ROOM_ID = "!123:matrix.org";
37+
38+
let room: Room;
39+
let mockClient: MatrixClient;
40+
41+
let onFinished: () => void;
42+
43+
beforeEach(() => {
44+
jest.clearAllMocks();
45+
46+
stubClient();
47+
mockClient = mocked(MatrixClientPeg.get());
48+
49+
room = new Room(ROOM_ID, mockClient, mockClient.getUserId() ?? "", {
50+
pendingEventOrdering: PendingEventOrdering.Detached,
51+
});
52+
53+
const dmRoomMap = {
54+
getUserIdForRoomId: jest.fn(),
55+
} as unknown as DMRoomMap;
56+
DMRoomMap.setShared(dmRoomMap);
57+
58+
onFinished = jest.fn();
59+
});
60+
61+
function getComponent(props: Partial<ComponentProps<typeof RoomContextMenu>> = {}) {
62+
return render(
63+
<MatrixClientContext.Provider value={mockClient}>
64+
<RoomContextMenu room={room} onFinished={onFinished} {...props} />
65+
</MatrixClientContext.Provider>,
66+
);
67+
}
68+
69+
it("does not render invite menu item when UIComponent customisations disable invite", () => {
70+
jest.spyOn(room, "canInvite").mockReturnValue(true);
71+
mocked(shouldShowComponent).mockReturnValue(false);
72+
73+
getComponent();
74+
75+
expect(screen.queryByRole("menuitem", { name: "Invite" })).not.toBeInTheDocument();
76+
});
77+
78+
it("renders invite menu item when UIComponent customisations enable invite", () => {
79+
jest.spyOn(room, "canInvite").mockReturnValue(true);
80+
mocked(shouldShowComponent).mockReturnValue(true);
81+
82+
getComponent();
83+
84+
expect(screen.getByRole("menuitem", { name: "Invite" })).toBeInTheDocument();
85+
});
86+
});

Diff for: test/components/views/context_menus/RoomGeneralContextMenu-test.tsx

+29-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import { fireEvent, getByLabelText, render } from "@testing-library/react";
17+
import { fireEvent, getByLabelText, render, screen } from "@testing-library/react";
1818
import { mocked } from "jest-mock";
1919
import { ReceiptType } from "matrix-js-sdk/src/@types/read_receipts";
2020
import { MatrixClient, PendingEventOrdering } from "matrix-js-sdk/src/client";
@@ -32,6 +32,12 @@ import { DefaultTagID } from "../../../../src/stores/room-list/models";
3232
import RoomListStore from "../../../../src/stores/room-list/RoomListStore";
3333
import DMRoomMap from "../../../../src/utils/DMRoomMap";
3434
import { mkMessage, stubClient } from "../../../test-utils/test-utils";
35+
import { shouldShowComponent } from "../../../../src/customisations/helpers/UIComponents";
36+
import { UIComponent } from "../../../../src/settings/UIFeature";
37+
38+
jest.mock("../../../../src/customisations/helpers/UIComponents", () => ({
39+
shouldShowComponent: jest.fn(),
40+
}));
3541

3642
describe("RoomGeneralContextMenu", () => {
3743
const ROOM_ID = "!123:matrix.org";
@@ -93,6 +99,28 @@ describe("RoomGeneralContextMenu", () => {
9399
expect(container).toMatchSnapshot();
94100
});
95101

102+
it("does not render invite menu item when UIComponent customisations disable room invite", () => {
103+
room.updateMyMembership("join");
104+
jest.spyOn(room, "canInvite").mockReturnValue(true);
105+
mocked(shouldShowComponent).mockReturnValue(false);
106+
107+
getComponent({});
108+
109+
expect(shouldShowComponent).toHaveBeenCalledWith(UIComponent.InviteUsers);
110+
expect(screen.queryByRole("menuitem", { name: "Invite" })).not.toBeInTheDocument();
111+
});
112+
113+
it("renders invite menu item when UIComponent customisations enables room invite", () => {
114+
room.updateMyMembership("join");
115+
jest.spyOn(room, "canInvite").mockReturnValue(true);
116+
mocked(shouldShowComponent).mockReturnValue(true);
117+
118+
getComponent({});
119+
120+
expect(shouldShowComponent).toHaveBeenCalledWith(UIComponent.InviteUsers);
121+
expect(screen.getByRole("menuitem", { name: "Invite" })).toBeInTheDocument();
122+
});
123+
96124
it("marks the room as read", async () => {
97125
const event = mkMessage({
98126
event: true,

0 commit comments

Comments
 (0)