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

* 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
This commit is contained in:
աӄա 2024-07-06 15:21:51 +08:00 committed by GitHub
parent 3cdfb2afca
commit c5ab49afa4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 37 additions and 3 deletions

View File

@ -0,0 +1,5 @@
---
"@nextui-org/user": patch
---
removed `name` from `avatarProps` in `use-user.ts` (#3369)

View File

@ -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", () => {
@ -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", () => {
@ -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");
});
});

View File

@ -66,7 +66,6 @@ export function useUser(props: UseUserProps) {
const avatarProps = {
isFocusable: false,
name: typeof name === "string" ? name : undefined,
...userAvatarProps,
};