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 <dominik.henneke@nordeck.net> * Add tests to check if the message button is correctly hidden by the customisations Signed-off-by: Dominik Henneke <dominik.henneke@nordeck.net> * Use the testing-library instead of enzyme Signed-off-by: Dominik Henneke <dominik.henneke@nordeck.net> * Fix type error Signed-off-by: Dominik Henneke <dominik.henneke@nordeck.net> * Smaller test change, prettier Signed-off-by: Mikhail Aheichyk <mikhail.aheichyk@nordeck.net> --------- Signed-off-by: Dominik Henneke <dominik.henneke@nordeck.net> Signed-off-by: Mikhail Aheichyk <mikhail.aheichyk@nordeck.net> Co-authored-by: Mikhail Aheichyk <mikhail.aheichyk@nordeck.net> Co-authored-by: maheichyk <mikhail.aheichyk@gmail.com>
This commit is contained in:
parent
38f791b79d
commit
11f45f5413
2 changed files with 38 additions and 1 deletions
|
@ -521,7 +521,8 @@ export const UserOptionsSection: React.FC<{
|
||||||
</AccessibleButton>
|
</AccessibleButton>
|
||||||
);
|
);
|
||||||
|
|
||||||
const directMessageButton = isMe ? null : <MessageButton member={member} />;
|
const directMessageButton =
|
||||||
|
isMe || !shouldShowComponent(UIComponent.CreateRooms) ? null : <MessageButton member={member} />;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mx_UserInfo_container">
|
<div className="mx_UserInfo_container">
|
||||||
|
|
|
@ -62,6 +62,8 @@ import { E2EStatus } from "../../../../src/utils/ShieldUtils";
|
||||||
import { DirectoryMember, startDmOnFirstMessage } from "../../../../src/utils/direct-messages";
|
import { DirectoryMember, startDmOnFirstMessage } from "../../../../src/utils/direct-messages";
|
||||||
import { clearAllModals, flushPromises } from "../../../test-utils";
|
import { clearAllModals, flushPromises } from "../../../test-utils";
|
||||||
import ErrorDialog from "../../../../src/components/views/dialogs/ErrorDialog";
|
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.mock("../../../../src/utils/direct-messages", () => ({
|
||||||
...jest.requireActual("../../../../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 defaultRoomId = "!fkfk";
|
||||||
const defaultUserId = "@user:example.com";
|
const defaultUserId = "@user:example.com";
|
||||||
const defaultUser = new User(defaultUserId);
|
const defaultUser = new User(defaultUserId);
|
||||||
|
@ -325,6 +334,33 @@ describe("<UserInfo />", () => {
|
||||||
// will not return true, so we expect to see the noCommonMethod error from VerificationPanel
|
// will not return true, so we expect to see the noCommonMethod error from VerificationPanel
|
||||||
expect(screen.getByText(/try with a different client/i)).toBeInTheDocument();
|
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", () => {
|
describe("with crypto enabled", () => {
|
||||||
|
|
Loading…
Reference in a new issue