Skip to content

Commit

Permalink
chore: add ability to clear error state and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shan8851 committed Jan 15, 2025
1 parent fa4d4c4 commit b849a9e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/core/components/forms/inputFileAvatar/inputFileAvatar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,26 @@ describe('<InputFileAvatar /> component', () => {
expect(previewImg).toBeInTheDocument();
expect(previewImg.src).toEqual(value.url);
});

it('renders the cancel button when error is present and clears error on button click', async () => {
const user = userEvent.setup();
const onChange = jest.fn();

const { rerender } = render(
createTestComponent({
onChange,
value: { error: InputFileAvatarError.WRONG_DIMENSION },
}),
);

const cancelButton = await screen.findByRole('button');
expect(cancelButton).toBeInTheDocument();

await user.click(cancelButton);

expect(onChange).toHaveBeenCalledWith(undefined);

rerender(createTestComponent({ onChange }));
expect(screen.queryByRole('button')).not.toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ export const InputFileAvatar: React.FC<IInputFileAvatarProps> = (props) => {
<InputContainer id={randomId} useCustomWrapper={true} {...containerProps}>
<div {...getRootProps()} className={inputAvatarClassNames}>
<input {...getInputProps()} id={randomId} />
{value?.url ? (

{value?.url || value?.error ? (
<div className="relative">
<Avatar src={value.url} size="lg" className="cursor-pointer" data-testid="avatar" />
<button
Expand Down

0 comments on commit b849a9e

Please sign in to comment.