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

🐛 small fixes when avatar name is blank #131

Merged
merged 1 commit into from
Jul 25, 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
10 changes: 9 additions & 1 deletion src/components/Avatar/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe("Avatar", () => {
color: "primary" | "gray",
size: "xl" | "lg" | "md" | "sm" | "xs",
isOn: boolean,
name: string,
name: string | null,
avatarUrl?: string,
) => {
return <Avatar color={color} isOn={isOn} name={name} avatarUrl={avatarUrl} size={size} />;
Expand All @@ -20,6 +20,14 @@ describe("Avatar", () => {
});
});

describe("when name is nil", () => {
it("renders", () => {
const { container } = render(component("primary", "xl", false, null));
// its render the component
expect(container).toBeTruthy();
});
});

describe("test the color props", () => {
it("test the primary color", () => {
const { container } = render(<Avatar color="primary" size="xl" name="marty mcfly" />);
Expand Down
7 changes: 5 additions & 2 deletions src/components/Avatar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { twMerge } from "tailwind-merge";
export interface AvatarType extends HTMLAttributes<any> {
color?: "primary" | "gray";
isOn?: boolean;
name: string;
name: string | null;
avatarUrl?: string;
border?: boolean;
size?: "xl" | "lg" | "md" | "sm" | "xs";
Expand Down Expand Up @@ -68,7 +68,10 @@ const Avatar = ({
const avatarClass = twMerge(avatarVariants({ color, size, border }), className);
const avatarOnlineClass = twMerge(avatarOnlineVariants({ size }), className);

const getInitials = (name: string) => {
const getInitials = (name: string | null) => {
if (!name) {
return "";
}
const nameWords = name.trim().split(" ");

if (nameWords.length === 1) {
Expand Down