Skip to content
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@internxt/ui",
"version": "0.0.23",
"version": "0.0.24",
"description": "Library of Internxt components",
"repository": {
"type": "git",
Expand Down
8 changes: 6 additions & 2 deletions src/components/avatar/__test__/Avatar.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import { describe, expect, it } from 'vitest';
import { render } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import { Avatar } from '../';

const FULL_NAME = 'My Internxt';
Expand All @@ -12,6 +11,11 @@ describe('Avatar component', () => {
expect(avatarComponent).toMatchSnapshot();
});

it('Avatar with fullname as null should render correctly with empty letters', () => {
const avatarComponent = render(<Avatar diameter={80} fullName={null as any} />);
expect(avatarComponent).toMatchSnapshot();
});

it('Avatar with avatar (user image profile) should render correctly', () => {
const avatarComponent = render(<Avatar fullName={FULL_NAME} diameter={80} src={IMAGE_SRC} />);
expect(avatarComponent).toMatchSnapshot();
Expand Down
75 changes: 75 additions & 0 deletions src/components/avatar/__test__/__snapshots__/Avatar.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,81 @@ exports[`Avatar component > Avatar with full name (first letters) should render
}
`;

exports[`Avatar component > Avatar with fullname as null should render correctly with empty letters 1`] = `
{
"asFragment": [Function],
"baseElement": <body>
<div>
<div
class=" flex shrink-0 select-none items-center justify-center rounded-full bg-primary/20 font-medium text-primary dark:bg-primary/75 dark:text-white"
style="width: 80px; height: 80px; font-size: 38.095238095238095px;"
>
<p />
</div>
</div>
</body>,
"container": <div>
<div
class=" flex shrink-0 select-none items-center justify-center rounded-full bg-primary/20 font-medium text-primary dark:bg-primary/75 dark:text-white"
style="width: 80px; height: 80px; font-size: 38.095238095238095px;"
>
<p />
</div>
</div>,
"debug": [Function],
"findAllByAltText": [Function],
"findAllByDisplayValue": [Function],
"findAllByLabelText": [Function],
"findAllByPlaceholderText": [Function],
"findAllByRole": [Function],
"findAllByTestId": [Function],
"findAllByText": [Function],
"findAllByTitle": [Function],
"findByAltText": [Function],
"findByDisplayValue": [Function],
"findByLabelText": [Function],
"findByPlaceholderText": [Function],
"findByRole": [Function],
"findByTestId": [Function],
"findByText": [Function],
"findByTitle": [Function],
"getAllByAltText": [Function],
"getAllByDisplayValue": [Function],
"getAllByLabelText": [Function],
"getAllByPlaceholderText": [Function],
"getAllByRole": [Function],
"getAllByTestId": [Function],
"getAllByText": [Function],
"getAllByTitle": [Function],
"getByAltText": [Function],
"getByDisplayValue": [Function],
"getByLabelText": [Function],
"getByPlaceholderText": [Function],
"getByRole": [Function],
"getByTestId": [Function],
"getByText": [Function],
"getByTitle": [Function],
"queryAllByAltText": [Function],
"queryAllByDisplayValue": [Function],
"queryAllByLabelText": [Function],
"queryAllByPlaceholderText": [Function],
"queryAllByRole": [Function],
"queryAllByTestId": [Function],
"queryAllByText": [Function],
"queryAllByTitle": [Function],
"queryByAltText": [Function],
"queryByDisplayValue": [Function],
"queryByLabelText": [Function],
"queryByPlaceholderText": [Function],
"queryByRole": [Function],
"queryByTestId": [Function],
"queryByText": [Function],
"queryByTitle": [Function],
"rerender": [Function],
"unmount": [Function],
}
`;

exports[`Avatar component > Base Avatar should render correctly 1`] = `
{
"asFragment": [Function],
Expand Down
11 changes: 10 additions & 1 deletion src/components/avatar/components/DefaultAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,16 @@ export default function DefaultAvatar({
}

function nameToInitials(fullName: string) {
const namesArray = fullName.trim().split(' ');
if (!fullName) {
return '';
}

const trimmedName = fullName?.trim();

if (!trimmedName) {
return '';
}
const namesArray = trimmedName.split(' ');
if (namesArray.length === 1) return `${namesArray[0].charAt(0)}`;
else {
const first = namesArray[0].charAt(0);
Expand Down