Skip to content

Commit

Permalink
fix(user): avatar icon not shown in User component (#3387)
Browse files Browse the repository at this point in the history
* chore(deps): pnpm-lock.yaml

* fix(user): avoid passing user name to avatar component

* feat(changeset): add changeset

* feat(user): add avatar icon test cases
  • Loading branch information
wingkwong committed Jul 6, 2024
1 parent 3cdfb2a commit c5ab49a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/real-falcons-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nextui-org/user": patch
---

removed `name` from `avatarProps` in `use-user.ts` (#3369)
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");
});
});
1 change: 0 additions & 1 deletion packages/components/user/src/use-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export function useUser(props: UseUserProps) {

const avatarProps = {
isFocusable: false,
name: typeof name === "string" ? name : undefined,
...userAvatarProps,
};

Expand Down

0 comments on commit c5ab49a

Please sign in to comment.