-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3748 from terrestris/refactor-upload-button
Refactor `UploadButton` to function component
- Loading branch information
Showing
2 changed files
with
60 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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('<UploadButton />', () => { | ||
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(<UploadButton />); | ||
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( | ||
<UploadButton | ||
inputProps={{ | ||
role: 'test' | ||
}} | ||
/> | ||
); | ||
|
||
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(<UploadButton />); | ||
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( | ||
<UploadButton | ||
onChange={onChange} | ||
inputProps={{ | ||
role: 'test' | ||
}} | ||
/> | ||
); | ||
|
||
fireEvent.change(screen.getByRole('test')); | ||
|
||
expect(onChange).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters