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

Commit 11f45f5

Browse files
dhennekeMikhail Aheichykmaheichyk
authored
Hide the "Message" button in the sidebar if the CreateRooms components should not be shown (#9271)
* Hide the "Message" button in the sidebar if the CreateRooms components should not be shown Signed-off-by: Dominik Henneke <[email protected]> * Add tests to check if the message button is correctly hidden by the customisations Signed-off-by: Dominik Henneke <[email protected]> * Use the testing-library instead of enzyme Signed-off-by: Dominik Henneke <[email protected]> * Fix type error Signed-off-by: Dominik Henneke <[email protected]> * Smaller test change, prettier Signed-off-by: Mikhail Aheichyk <[email protected]> --------- Signed-off-by: Dominik Henneke <[email protected]> Signed-off-by: Mikhail Aheichyk <[email protected]> Co-authored-by: Mikhail Aheichyk <[email protected]> Co-authored-by: maheichyk <[email protected]>
1 parent 38f791b commit 11f45f5

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/components/views/right_panel/UserInfo.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,8 @@ export const UserOptionsSection: React.FC<{
521521
</AccessibleButton>
522522
);
523523

524-
const directMessageButton = isMe ? null : <MessageButton member={member} />;
524+
const directMessageButton =
525+
isMe || !shouldShowComponent(UIComponent.CreateRooms) ? null : <MessageButton member={member} />;
525526

526527
return (
527528
<div className="mx_UserInfo_container">

test/components/views/right_panel/UserInfo-test.tsx

+36
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ import { E2EStatus } from "../../../../src/utils/ShieldUtils";
6262
import { DirectoryMember, startDmOnFirstMessage } from "../../../../src/utils/direct-messages";
6363
import { clearAllModals, flushPromises } from "../../../test-utils";
6464
import ErrorDialog from "../../../../src/components/views/dialogs/ErrorDialog";
65+
import { shouldShowComponent } from "../../../../src/customisations/helpers/UIComponents";
66+
import { UIComponent } from "../../../../src/settings/UIFeature";
6567

6668
jest.mock("../../../../src/utils/direct-messages", () => ({
6769
...jest.requireActual("../../../../src/utils/direct-messages"),
@@ -88,6 +90,13 @@ jest.mock("../../../../src/utils/DMRoomMap", () => {
8890
};
8991
});
9092

93+
jest.mock("../../../../src/customisations/helpers/UIComponents", () => {
94+
const original = jest.requireActual("../../../../src/customisations/helpers/UIComponents");
95+
return {
96+
shouldShowComponent: jest.fn().mockImplementation(original.shouldShowComponent),
97+
};
98+
});
99+
91100
const defaultRoomId = "!fkfk";
92101
const defaultUserId = "@user:example.com";
93102
const defaultUser = new User(defaultUserId);
@@ -325,6 +334,33 @@ describe("<UserInfo />", () => {
325334
// will not return true, so we expect to see the noCommonMethod error from VerificationPanel
326335
expect(screen.getByText(/try with a different client/i)).toBeInTheDocument();
327336
});
337+
338+
it("renders the message button", () => {
339+
render(
340+
<MatrixClientContext.Provider value={mockClient}>
341+
<UserInfo {...defaultProps} />
342+
</MatrixClientContext.Provider>,
343+
);
344+
345+
screen.getByRole("button", { name: "Message" });
346+
});
347+
348+
it("hides the message button if the visibility customisation hides all create room features", () => {
349+
mocked(shouldShowComponent).withImplementation(
350+
(component) => {
351+
return component !== UIComponent.CreateRooms;
352+
},
353+
() => {
354+
render(
355+
<MatrixClientContext.Provider value={mockClient}>
356+
<UserInfo {...defaultProps} />
357+
</MatrixClientContext.Provider>,
358+
);
359+
360+
expect(screen.queryByRole("button", { name: "Message" })).toBeNull();
361+
},
362+
);
363+
});
328364
});
329365

330366
describe("with crypto enabled", () => {

0 commit comments

Comments
 (0)