Skip to content

Commit

Permalink
feat(user): add avatar icon test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
wingkwong committed Jul 1, 2024
1 parent 26d4580 commit 7b03382
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions packages/components/user/__tests__/user.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {render} from "@testing-library/react";
import {Link} from "@nextui-org/link";

import {User} from "../src";
import {AvatarIcon} from "../../avatar/src";

describe("User", () => {
it("should render correctly", () => {
Expand All @@ -20,9 +21,11 @@ describe("User", () => {

it("should have the passed name", () => {
const {container} = render(<User name="Test" />);
const name = container.querySelector("span");
const spans = container.querySelectorAll("span");

expect(name).toHaveTextContent("Test");
expect(spans).toHaveLength(4);

expect(spans[2]).toHaveTextContent("Test");
});

it("should have the passed description", () => {
Expand Down Expand Up @@ -72,4 +75,31 @@ describe("User", () => {

expect(wrapper.getByTestId("test-user-link")).toBeInTheDocument();
});

it("should render avatar icon", () => {
const {container} = render(
<User
avatarProps={{
icon: <AvatarIcon />,
}}
name="test"
/>,
);

expect(container.querySelector("svg")).toBeInTheDocument();
});

it("should display initials in avatar if name is specified", () => {
const {getByRole} = render(
<User
avatarProps={{
icon: <AvatarIcon />,
name: "WK",
}}
name="test"
/>,
);

expect(getByRole("img")).toHaveTextContent("WK");
});
});

0 comments on commit 7b03382

Please sign in to comment.