You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
portainer/app/react/components/form-components/FileUpload/FileUploadField.test.tsx

29 lines
773 B

import { fireEvent, render } from '@/react-tools/test-utils';
import { FileUploadField } from './FileUploadField';
test('render should make the file button clickable and fire onChange event after click', async () => {
const onClick = jest.fn();
const { findByText, findByLabelText } = render(
<FileUploadField
title="test button"
onChange={onClick}
inputId="file-field"
/>
);
const button = await findByText('test button');
expect(button).toBeVisible();
const input = await findByLabelText('file-input');
expect(input).not.toBeNull();
const mockFile = new File([], 'file.txt');
if (input) {
fireEvent.change(input, {
target: { files: [mockFile] },
});
}
expect(onClick).toHaveBeenCalledWith(mockFile);
});