mirror of
https://github.com/nextui-org/nextui.git
synced 2025-12-08 19:26:11 +00:00
feat: tests added to user
This commit is contained in:
parent
a6d8b976c8
commit
083650d4c0
@ -12,7 +12,7 @@ import {useImage} from "@nextui-org/use-image";
|
||||
import {useAvatarGroupContext} from "./avatar-group-context";
|
||||
|
||||
export interface UseAvatarProps
|
||||
extends Omit<HTMLNextUIProps<"span", AvatarVariantProps>, "children" | "isFocusVisible"> {
|
||||
extends Omit<HTMLNextUIProps<"span", AvatarVariantProps>, "children"> {
|
||||
/**
|
||||
* Ref to the DOM node.
|
||||
*/
|
||||
@ -92,7 +92,9 @@ export function useAvatar(props: UseAvatarProps) {
|
||||
ref,
|
||||
src,
|
||||
name,
|
||||
icon,
|
||||
styles,
|
||||
fallback,
|
||||
alt = name,
|
||||
imgRef: imgRefProp,
|
||||
color = groupContext?.color ?? "neutral",
|
||||
@ -173,11 +175,13 @@ export function useAvatar(props: UseAvatarProps) {
|
||||
Component,
|
||||
src,
|
||||
alt,
|
||||
icon,
|
||||
name,
|
||||
domRef,
|
||||
imgRef,
|
||||
slots,
|
||||
styles,
|
||||
fallback,
|
||||
isImgLoaded,
|
||||
showFallback,
|
||||
ignoreFallback,
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import * as React from "react";
|
||||
import {render} from "@testing-library/react";
|
||||
import {Link} from "@nextui-org/link";
|
||||
|
||||
import {User} from "../src";
|
||||
|
||||
@ -17,11 +18,29 @@ describe("User", () => {
|
||||
expect(ref.current).not.toBeNull();
|
||||
});
|
||||
|
||||
it("should have the passed name", () => {
|
||||
const {container} = render(<User name="Test" />);
|
||||
const name = container.querySelector("span");
|
||||
|
||||
expect(name).toHaveTextContent("Test");
|
||||
});
|
||||
|
||||
it("should have the passed description", () => {
|
||||
const wrapper = render(
|
||||
<User description={<p data-testid="test-desc">Test Desc</p>} name="Test Name" />,
|
||||
);
|
||||
|
||||
expect(wrapper.getByTestId("test-desc")).toHaveTextContent("Test Desc");
|
||||
});
|
||||
|
||||
it("should support image and text", () => {
|
||||
const wrapper = render(
|
||||
<div>
|
||||
<User name="Text" text="User" />
|
||||
<User name="User test" src="https://avatars.githubusercontent.com/u/30373425?v=4" />
|
||||
<User avatarProps={{name: "User"}} name="User" />
|
||||
<User
|
||||
avatarProps={{src: "https://avatars.githubusercontent.com/u/30373425?v=4"}}
|
||||
name="User test"
|
||||
/>
|
||||
</div>,
|
||||
);
|
||||
|
||||
@ -40,20 +59,17 @@ describe("User", () => {
|
||||
});
|
||||
|
||||
it("should render link on user.link", () => {
|
||||
const {container} = render(
|
||||
<User name="User">
|
||||
<User.Link href="https://nextui.org">NextUI</User.Link>
|
||||
</User>,
|
||||
const wrapper = render(
|
||||
<User
|
||||
description={
|
||||
<Link data-testid="test-user-link" href="https://nextui.org">
|
||||
NextUI
|
||||
</Link>
|
||||
}
|
||||
name="User"
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(container.querySelector("a")).not.toBeNull();
|
||||
});
|
||||
|
||||
it("should pass alt attribute", () => {
|
||||
const {container} = render(
|
||||
<User alt="User" name="User" src="https://avatars.githubusercontent.com/u/30373425?v=4" />,
|
||||
);
|
||||
|
||||
expect(container.querySelector("img")?.getAttribute("alt")).toBe("User");
|
||||
expect(wrapper.getByTestId("test-user-link")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user