|
| 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