Skip to content

Commit

Permalink
test(avatar): add test for initials placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
iamargentum committed Oct 11, 2022
1 parent 744042e commit 922eb83
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 14 additions & 2 deletions src/lib/components/Avatar/Avatar.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { Avatar } from '.';
import { Flowbite } from '../Flowbite';
import type { CustomFlowbiteTheme } from '../Flowbite/FlowbiteTheme';

describe.concurrent('Components / Avatar', () => {
describe.concurrent('Theme', () => {
describe('Components / Avatar', () => {
describe('Theme', () => {
it('should use custom classes', () => {
const theme: CustomFlowbiteTheme = {
avatar: {
Expand All @@ -23,6 +23,18 @@ describe.concurrent('Components / Avatar', () => {
expect(img()).toHaveClass('h-64 w-64');
});
});
describe('Placeholder', () => {
it('should display placeholder initials', () => {
render(
<Flowbite>
<Avatar placeholderInitials="RR" />
</Flowbite>,
);

expect(initialsPlaceholder()).toHaveTextContent('RR');
});
});
});

const img = () => screen.getByTestId('flowbite-avatar-img');
const initialsPlaceholder = () => screen.getByTestId('flowbite-avatar-initials-placeholder');
4 changes: 3 additions & 1 deletion src/lib/components/Avatar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ const AvatarComponent: FC<AvatarProps> = ({
bordered && theme.bordered,
)}
>
<span className={classNames(theme.initials.text)}>{placeholderInitials}</span>
<span className={classNames(theme.initials.text)} data-testid="flowbite-avatar-initials-placeholder">
{placeholderInitials}
</span>
</div>
) : (
<div
Expand Down

0 comments on commit 922eb83

Please sign in to comment.