From c5ab49afa4b34ff52a7dc95fcc1709f5e3fdaf0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D5=A1=D3=84=D5=A1?= Date: Sat, 6 Jul 2024 15:21:51 +0800 Subject: [PATCH] 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 --- .changeset/real-falcons-care.md | 5 +++ .../components/user/__tests__/user.test.tsx | 34 +++++++++++++++++-- packages/components/user/src/use-user.ts | 1 - 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 .changeset/real-falcons-care.md diff --git a/.changeset/real-falcons-care.md b/.changeset/real-falcons-care.md new file mode 100644 index 0000000000..f989a4e360 --- /dev/null +++ b/.changeset/real-falcons-care.md @@ -0,0 +1,5 @@ +--- +"@nextui-org/user": patch +--- + +removed `name` from `avatarProps` in `use-user.ts` (#3369) diff --git a/packages/components/user/__tests__/user.test.tsx b/packages/components/user/__tests__/user.test.tsx index 702fa0404f..932fcbb523 100644 --- a/packages/components/user/__tests__/user.test.tsx +++ b/packages/components/user/__tests__/user.test.tsx @@ -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(); - 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( + , + }} + name="test" + />, + ); + + expect(container.querySelector("svg")).toBeInTheDocument(); + }); + + it("should display initials in avatar if name is specified", () => { + const {getByRole} = render( + , + name: "WK", + }} + name="test" + />, + ); + + expect(getByRole("img")).toHaveTextContent("WK"); + }); }); diff --git a/packages/components/user/src/use-user.ts b/packages/components/user/src/use-user.ts index 2d481e7686..a7782aece7 100644 --- a/packages/components/user/src/use-user.ts +++ b/packages/components/user/src/use-user.ts @@ -66,7 +66,6 @@ export function useUser(props: UseUserProps) { const avatarProps = { isFocusable: false, - name: typeof name === "string" ? name : undefined, ...userAvatarProps, };