Skip to content

Commit

Permalink
fix (AutoComplete): fixes #103
Browse files Browse the repository at this point in the history
  • Loading branch information
jannikbuschke committed Apr 1, 2020
1 parent e91ba38 commit 058e8a2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/auto-complete/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { render, fireEvent, waitForDomChange } from '@testing-library/react'
import Form from '../form/form'
import AutoComplete from './index'
import { act } from 'react-dom/test-utils'
import { ResetButton } from '../reset-button'

const TestAutoComplete = () => {
return (
Expand All @@ -18,6 +19,7 @@ const TestAutoComplete = () => {
{ value: '2', text: 'Third Item' },
]}
/>
<ResetButton data-testid='reset' />
</Form>
</Formik>
)
Expand All @@ -44,3 +46,20 @@ test('sets key as input to key value', async () => {
})
expect(uat).toHaveValue('1')
})

test('resets value', async () => {
const { getByRole, getByTestId } = render(<TestAutoComplete />)
const uat = getByRole('combobox')
await act(async () => {
fireEvent.change(uat, { target: { name: 'field', value: 'search value' } })
await waitForDomChange()
})
expect(uat).toHaveValue('search value')

await act(async () => {
fireEvent.click(getByTestId('reset'))
await waitForDomChange()
})

expect(uat).toHaveValue('hello')
})
2 changes: 1 addition & 1 deletion src/auto-complete/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const AutoComplete = ({
<Field name={name} validate={validate} fast={fast}>
{({ field: { value }, form }: FieldProps) => (
<$AutoComplete
defaultValue={value}
value={value}
onChange={(value, option) => {
form.setFieldValue(name, value != null ? value.valueOf() : value)
onChange && onChange(value, option)
Expand Down

0 comments on commit 058e8a2

Please sign in to comment.