diff --git a/src/Button/UploadButton/UploadButton.spec.tsx b/src/Button/UploadButton/UploadButton.spec.tsx index ee354cc298..94affb1f81 100644 --- a/src/Button/UploadButton/UploadButton.spec.tsx +++ b/src/Button/UploadButton/UploadButton.spec.tsx @@ -1,36 +1,48 @@ -import TestUtil from '../../Util/TestUtil'; +import { fireEvent,render, screen } from '@testing-library/react'; +import * as React from 'react'; + import UploadButton from './UploadButton'; describe('', () => { it('is defined', () => { - expect(UploadButton).not.toBeUndefined(); + expect(UploadButton).toBeDefined(); }); it('can be rendered', () => { - const wrapper = TestUtil.mountComponent(UploadButton); - expect(wrapper).not.toBeUndefined(); + const { container } = render(); + expect(container).toBeVisible(); }); - it('renders an inputfield', () => { - const wrapper = TestUtil.mountComponent(UploadButton); - expect(wrapper.find('input').length).toBe(1); - }); + it('applies inputProps to the input field', () => { + render( + + ); - it('applies inputProps to the inputfield', () => { - const wrapper = TestUtil.mountComponent(UploadButton, {inputProps: {multiple: true}}); - expect(wrapper.find('input[multiple=true]').length).toBe(1); + expect(screen.getByRole('test')).toBeInTheDocument(); }); - it('renders a simplebutton if no children are given', () => { - const wrapper = TestUtil.mountComponent(UploadButton); - expect(wrapper.find('button').length).toBe(1); + it('renders a simple button if no children are given', () => { + render(); + expect(screen.getByRole('button')).toBeInTheDocument(); }); it('calls a given click callback method onChange', () => { const onChange = jest.fn(); - const wrapper = TestUtil.mountComponent(UploadButton, {onChange}); - wrapper.find('input').simulate('change'); + render( + + ); + + fireEvent.change(screen.getByRole('test')); + expect(onChange).toHaveBeenCalledTimes(1); }); - }); diff --git a/src/Button/UploadButton/UploadButton.tsx b/src/Button/UploadButton/UploadButton.tsx index 97bcc9aad2..eea5f16564 100644 --- a/src/Button/UploadButton/UploadButton.tsx +++ b/src/Button/UploadButton/UploadButton.tsx @@ -5,7 +5,7 @@ import * as React from 'react'; import { CSS_PREFIX } from '../../constants'; import SimpleButton, { SimpleButtonProps } from '../SimpleButton/SimpleButton'; -interface BaseProps { +export type OwnProps = { /** * The className which should be added. */ @@ -18,55 +18,45 @@ interface BaseProps { * The onChange handler for the upload input field. */ onChange?: (event: React.ChangeEvent) => void; -} +}; -export type UploadButtonProps = BaseProps & SimpleButtonProps; +export type UploadButtonProps = OwnProps & SimpleButtonProps; /** - * Class representing an upload button. Can be used as wrapper if children + * Component representing an upload button. Can be used as wrapper if children * are given. Otherwise a Simplebutton will be rendered. * * To use a text with the UploadButton provide a SimpleButton as children. * * This automatically supports uploads via drag and drop from the operating * system. - * - * @class The UploadButton - * @extends React.Component */ -class UploadButton extends React.Component { - - /** - * The className added to this component. - * @private - */ - _className = `${CSS_PREFIX}uploadbutton`; - - /** - * The render function. - */ - render() { - const { - className, - children, - onChange, - inputProps, - ...passThroughProps - } = this.props; - - const finalClassName = className - ? `${className} ${this._className}` - : this._className; - - const button = ; - - return ( -
- {children || button} - -
- ); - } -} +const UploadButton: React.FC = ({ + className, + children, + onChange, + inputProps, + ...passThroughProps +}) => { + + const finalClassName = className + ? `${className} ${CSS_PREFIX}uploadbutton` + : `${CSS_PREFIX}uploadbutton`; + + const button = ; + + return ( +
+ {children || button} + +
+ ); +}; export default UploadButton;