|
| 1 | +/* |
| 2 | +Copyright 2024 The Matrix.org Foundation C.I.C. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +import React from "react"; |
| 18 | +import { MatrixClient, PendingEventOrdering, Room } from "matrix-js-sdk/src/matrix"; |
| 19 | +import { render } from "@testing-library/react"; |
| 20 | + |
| 21 | +import { stubClient } from "../../../test-utils"; |
| 22 | +import AppsDrawer from "../../../../src/components/views/rooms/AppsDrawer"; |
| 23 | +import SdkConfig from "../../../../src/SdkConfig"; |
| 24 | +import ResizeNotifier from "../../../../src/utils/ResizeNotifier"; |
| 25 | +import { WidgetLayoutStore } from "../../../../src/stores/widgets/WidgetLayoutStore"; |
| 26 | +import MatrixClientContext from "../../../../src/contexts/MatrixClientContext"; |
| 27 | + |
| 28 | +const ROOM_ID = "!room:id"; |
| 29 | + |
| 30 | +describe("AppsDrawer", () => { |
| 31 | + let client: MatrixClient; |
| 32 | + let room: Room; |
| 33 | + let dummyResizeNotifier: ResizeNotifier; |
| 34 | + |
| 35 | + beforeEach(async () => { |
| 36 | + client = stubClient(); |
| 37 | + room = new Room(ROOM_ID, client, client.getUserId()!, { |
| 38 | + pendingEventOrdering: PendingEventOrdering.Detached, |
| 39 | + }); |
| 40 | + dummyResizeNotifier = new ResizeNotifier(); |
| 41 | + }); |
| 42 | + |
| 43 | + afterEach(() => { |
| 44 | + jest.restoreAllMocks(); |
| 45 | + }); |
| 46 | + |
| 47 | + it("honours default_widget_container_height", () => { |
| 48 | + jest.spyOn(SdkConfig, "get").mockImplementation((key) => { |
| 49 | + if (!key) { |
| 50 | + return { |
| 51 | + default_widget_container_height: 500, |
| 52 | + }; |
| 53 | + } |
| 54 | + }); |
| 55 | + jest.spyOn(WidgetLayoutStore.instance, "getContainerWidgets").mockImplementation((room, container) => { |
| 56 | + if (container === "top") { |
| 57 | + return [ |
| 58 | + { |
| 59 | + id: "testwidget", |
| 60 | + creatorUserId: client.getUserId()!, |
| 61 | + type: "test", |
| 62 | + url: "https://nowhere.dummy/notawidget", |
| 63 | + }, |
| 64 | + ]; |
| 65 | + } |
| 66 | + return []; |
| 67 | + }); |
| 68 | + |
| 69 | + const { container } = render( |
| 70 | + <AppsDrawer |
| 71 | + userId={client.getUserId()!} |
| 72 | + room={room} |
| 73 | + resizeNotifier={dummyResizeNotifier} |
| 74 | + showApps={true} |
| 75 | + />, |
| 76 | + { |
| 77 | + wrapper: ({ ...rest }) => <MatrixClientContext.Provider value={client} {...rest} />, |
| 78 | + }, |
| 79 | + ); |
| 80 | + |
| 81 | + const appsDrawerResizer = container.getElementsByClassName("mx_AppsDrawer_resizer")[0] as HTMLElement; |
| 82 | + expect(appsDrawerResizer.style.height).toBe("500px"); |
| 83 | + }); |
| 84 | +}); |
0 commit comments