Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(user): avatar icon not shown in User component #3387

Merged
merged 6 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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