|
| 1 | +/* |
| 2 | +Copyright 2022 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 | +import React from "react"; |
| 17 | +import { render } from "@testing-library/react"; |
| 18 | + |
| 19 | +import AvatarSetting from "../../../../src/components/views/settings/AvatarSetting"; |
| 20 | + |
| 21 | +describe("<AvatarSetting />", () => { |
| 22 | + it("renders avatar with specified alt text", async () => { |
| 23 | + const { queryByAltText } = render( |
| 24 | + <AvatarSetting |
| 25 | + avatarName="Peter Fox" |
| 26 | + avatarAltText="Avatar of Peter Fox" |
| 27 | + avatarUrl="https://avatar.fictional/my-avatar" |
| 28 | + />, |
| 29 | + ); |
| 30 | + |
| 31 | + const imgElement = queryByAltText("Avatar of Peter Fox"); |
| 32 | + expect(imgElement).toBeInTheDocument(); |
| 33 | + }); |
| 34 | + |
| 35 | + it("renders avatar with remove button", async () => { |
| 36 | + const { queryByText } = render( |
| 37 | + <AvatarSetting |
| 38 | + avatarName="Peter Fox" |
| 39 | + avatarAltText="Avatar of Peter Fox" |
| 40 | + avatarUrl="https://avatar.fictional/my-avatar" |
| 41 | + removeAvatar={jest.fn()} |
| 42 | + />, |
| 43 | + ); |
| 44 | + |
| 45 | + const removeButton = queryByText("Remove"); |
| 46 | + expect(removeButton).toBeInTheDocument(); |
| 47 | + }); |
| 48 | + |
| 49 | + it("renders avatar without remove button", async () => { |
| 50 | + const { queryByText } = render(<AvatarSetting avatarName="Peter Fox" avatarAltText="Avatar of Peter Fox" />); |
| 51 | + |
| 52 | + const removeButton = queryByText("Remove"); |
| 53 | + expect(removeButton).toBeNull(); |
| 54 | + }); |
| 55 | +}); |
0 commit comments