From 11f45f5413c4ce3d2d8ab8ec8591fe082388ce2b Mon Sep 17 00:00:00 2001 From: Dominik Henneke Date: Fri, 26 Jan 2024 15:54:48 +0100 Subject: [PATCH] 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 * Add tests to check if the message button is correctly hidden by the customisations Signed-off-by: Dominik Henneke * Use the testing-library instead of enzyme Signed-off-by: Dominik Henneke * Fix type error Signed-off-by: Dominik Henneke * Smaller test change, prettier Signed-off-by: Mikhail Aheichyk --------- Signed-off-by: Dominik Henneke Signed-off-by: Mikhail Aheichyk Co-authored-by: Mikhail Aheichyk Co-authored-by: maheichyk --- src/components/views/right_panel/UserInfo.tsx | 3 +- .../views/right_panel/UserInfo-test.tsx | 36 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/components/views/right_panel/UserInfo.tsx b/src/components/views/right_panel/UserInfo.tsx index b2587fe5398..a339a1ebce0 100644 --- a/src/components/views/right_panel/UserInfo.tsx +++ b/src/components/views/right_panel/UserInfo.tsx @@ -521,7 +521,8 @@ export const UserOptionsSection: React.FC<{ ); - const directMessageButton = isMe ? null : ; + const directMessageButton = + isMe || !shouldShowComponent(UIComponent.CreateRooms) ? null : ; return (
diff --git a/test/components/views/right_panel/UserInfo-test.tsx b/test/components/views/right_panel/UserInfo-test.tsx index eddba91f6ac..4be9c4b6a9c 100644 --- a/test/components/views/right_panel/UserInfo-test.tsx +++ b/test/components/views/right_panel/UserInfo-test.tsx @@ -62,6 +62,8 @@ import { E2EStatus } from "../../../../src/utils/ShieldUtils"; import { DirectoryMember, startDmOnFirstMessage } from "../../../../src/utils/direct-messages"; import { clearAllModals, flushPromises } from "../../../test-utils"; import ErrorDialog from "../../../../src/components/views/dialogs/ErrorDialog"; +import { shouldShowComponent } from "../../../../src/customisations/helpers/UIComponents"; +import { UIComponent } from "../../../../src/settings/UIFeature"; jest.mock("../../../../src/utils/direct-messages", () => ({ ...jest.requireActual("../../../../src/utils/direct-messages"), @@ -88,6 +90,13 @@ jest.mock("../../../../src/utils/DMRoomMap", () => { }; }); +jest.mock("../../../../src/customisations/helpers/UIComponents", () => { + const original = jest.requireActual("../../../../src/customisations/helpers/UIComponents"); + return { + shouldShowComponent: jest.fn().mockImplementation(original.shouldShowComponent), + }; +}); + const defaultRoomId = "!fkfk"; const defaultUserId = "@user:example.com"; const defaultUser = new User(defaultUserId); @@ -325,6 +334,33 @@ describe("", () => { // will not return true, so we expect to see the noCommonMethod error from VerificationPanel expect(screen.getByText(/try with a different client/i)).toBeInTheDocument(); }); + + it("renders the message button", () => { + render( + + + , + ); + + screen.getByRole("button", { name: "Message" }); + }); + + it("hides the message button if the visibility customisation hides all create room features", () => { + mocked(shouldShowComponent).withImplementation( + (component) => { + return component !== UIComponent.CreateRooms; + }, + () => { + render( + + + , + ); + + expect(screen.queryByRole("button", { name: "Message" })).toBeNull(); + }, + ); + }); }); describe("with crypto enabled", () => {