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

Commit

Permalink
Hide the "Message" button in the sidebar if the CreateRooms component…
Browse files Browse the repository at this point in the history
…s 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]>
  • Loading branch information
3 people authored Jan 26, 2024
1 parent 38f791b commit 11f45f5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/components/views/right_panel/UserInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,8 @@ export const UserOptionsSection: React.FC<{
</AccessibleButton>
);

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

return (
<div className="mx_UserInfo_container">
Expand Down
36 changes: 36 additions & 0 deletions test/components/views/right_panel/UserInfo-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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);
Expand Down Expand Up @@ -325,6 +334,33 @@ describe("<UserInfo />", () => {
// 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(
<MatrixClientContext.Provider value={mockClient}>
<UserInfo {...defaultProps} />
</MatrixClientContext.Provider>,
);

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(
<MatrixClientContext.Provider value={mockClient}>
<UserInfo {...defaultProps} />
</MatrixClientContext.Provider>,
);

expect(screen.queryByRole("button", { name: "Message" })).toBeNull();
},
);
});
});

describe("with crypto enabled", () => {
Expand Down

0 comments on commit 11f45f5

Please sign in to comment.