|
| 1 | +/* |
| 2 | +Copyright 2025 New Vector Ltd. |
| 3 | +SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial |
| 4 | +Please see LICENSE files in the repository root for full details. |
| 5 | +*/ |
| 6 | + |
| 7 | +import React from "react"; |
| 8 | +import { render } from "jest-matrix-react"; |
| 9 | + |
| 10 | +import { ElementWebBuiltinsApi } from "../../../src/modules/BuiltinsApi"; |
| 11 | +import { stubClient } from "../../test-utils/test-utils"; |
| 12 | + |
| 13 | +jest.mock("../../../src/components/views/avatars/RoomAvatar", () => { |
| 14 | + const Avatar: React.FC<{ room: { roomId: string }; size: string }> = ({ room, size }) => { |
| 15 | + return ( |
| 16 | + <div> |
| 17 | + Avatar, {room.roomId}, {size} |
| 18 | + </div> |
| 19 | + ); |
| 20 | + }; |
| 21 | + return { |
| 22 | + __esModule: true, |
| 23 | + default: Avatar, |
| 24 | + }; |
| 25 | +}); |
| 26 | + |
| 27 | +describe("ElementWebBuiltinsApi", () => { |
| 28 | + it("returns the RoomView component thats been set", () => { |
| 29 | + const builtinsApi = new ElementWebBuiltinsApi(); |
| 30 | + const sentinel = {}; |
| 31 | + builtinsApi.setRoomViewComponent(sentinel as any); |
| 32 | + expect(builtinsApi.getRoomViewComponent()).toBe(sentinel); |
| 33 | + }); |
| 34 | + |
| 35 | + it("returns rendered RoomView component", () => { |
| 36 | + const builtinsApi = new ElementWebBuiltinsApi(); |
| 37 | + const RoomView = () => <div>hello world</div>; |
| 38 | + builtinsApi.setRoomViewComponent(RoomView as any); |
| 39 | + const { container } = render(<> {builtinsApi.renderRoomView("!foo:m.org")}</>); |
| 40 | + expect(container).toHaveTextContent("hello world"); |
| 41 | + }); |
| 42 | + |
| 43 | + it("returns rendered RoomAvatar component", () => { |
| 44 | + stubClient(); |
| 45 | + const builtinsApi = new ElementWebBuiltinsApi(); |
| 46 | + const { container } = render(<> {builtinsApi.renderRoomAvatar("!foo:m.org", "50")}</>); |
| 47 | + expect(container).toHaveTextContent("Avatar"); |
| 48 | + expect(container).toHaveTextContent("!foo:m.org"); |
| 49 | + expect(container).toHaveTextContent("50"); |
| 50 | + }); |
| 51 | +}); |
0 commit comments