Skip to content

Commit a332a0b

Browse files
author
Mikhail Aheichyk
committed
Show room create button in RoomSublist if "UIComponent.roomCreation" is enabled
Signed-off-by: Mikhail Aheichyk <[email protected]>
1 parent 4c2b5df commit a332a0b

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

Diff for: src/components/views/rooms/RoomSublist.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ import SettingsStore from "../../../settings/SettingsStore";
5555
import { SlidingSyncManager } from "../../../SlidingSyncManager";
5656
import NotificationBadge from "./NotificationBadge";
5757
import RoomTile from "./RoomTile";
58+
import { shouldShowComponent } from "../../../customisations/helpers/UIComponents";
59+
import { UIComponent } from "../../../settings/UIFeature";
5860

5961
const SHOW_N_BUTTON_HEIGHT = 28; // As defined by CSS
6062
const RESIZE_HANDLE_HEIGHT = 4; // As defined by CSS
@@ -661,7 +663,7 @@ export default class RoomSublist extends React.Component<IProps, IState> {
661663
);
662664

663665
let addRoomButton: JSX.Element | undefined;
664-
if (this.props.AuxButtonComponent) {
666+
if (this.props.AuxButtonComponent && shouldShowComponent(UIComponent.CreateRooms)) {
665667
const AuxButtonComponent = this.props.AuxButtonComponent;
666668
addRoomButton = <AuxButtonComponent tabIndex={tabIndex} />;
667669
}

Diff for: test/components/views/rooms/RoomSublist-test.tsx

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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, RenderResult, screen } from "@testing-library/react";
19+
import { ComponentProps } from "react";
20+
import React from "react";
21+
import { EventEmitter } from "events";
22+
import { mocked } from "jest-mock";
23+
24+
import RoomSublist, { IAuxButtonProps } from "../../../../src/components/views/rooms/RoomSublist";
25+
import { DefaultTagID } from "../../../../src/stores/room-list/models";
26+
import ResizeNotifier from "../../../../src/utils/ResizeNotifier";
27+
import AccessibleButton from "../../../../src/components/views/elements/AccessibleButton";
28+
import { shouldShowComponent } from "../../../../src/customisations/helpers/UIComponents";
29+
import { UIComponent } from "../../../../src/settings/UIFeature";
30+
31+
jest.mock("../../../../src/customisations/helpers/UIComponents", () => ({
32+
shouldShowComponent: jest.fn(),
33+
}));
34+
35+
const AuxButton: React.FC<IAuxButtonProps> = ({ tabIndex }) => {
36+
return <AccessibleButton onClick={jest.fn()}>Add room</AccessibleButton>;
37+
};
38+
39+
describe("RoomSublist", () => {
40+
function renderComponent(props: Partial<ComponentProps<typeof RoomSublist>> = {}): RenderResult {
41+
return render(
42+
<RoomSublist
43+
forRooms={true}
44+
startAsHidden={false}
45+
label="Rooms"
46+
AuxButtonComponent={AuxButton}
47+
isMinimized={false}
48+
tagId={DefaultTagID.Untagged}
49+
resizeNotifier={new EventEmitter() as unknown as ResizeNotifier}
50+
alwaysVisible={true}
51+
{...props}
52+
/>,
53+
);
54+
}
55+
56+
it("does not render when UIComponent customisations disable room creation", () => {
57+
mocked(shouldShowComponent).mockReturnValue(false);
58+
59+
renderComponent();
60+
61+
expect(shouldShowComponent).toHaveBeenCalledWith(UIComponent.CreateRooms);
62+
expect(screen.queryByRole("button", { name: "Add room" })).not.toBeInTheDocument();
63+
});
64+
65+
it("renders when UIComponent customisations enable room creation", () => {
66+
mocked(shouldShowComponent).mockReturnValue(true);
67+
68+
renderComponent();
69+
70+
expect(shouldShowComponent).toHaveBeenCalledWith(UIComponent.CreateRooms);
71+
expect(screen.getByRole("button", { name: "Add room" })).toBeInTheDocument();
72+
});
73+
});

0 commit comments

Comments
 (0)