Skip to content

Commit 8fe6e51

Browse files
authored
Merge branch 'master' into labeled-field-docs
2 parents 4d6a5a0 + fc92227 commit 8fe6e51

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react'
2+
import { mount } from 'enzyme'
3+
import { DateInput } from '../../../src/'
4+
5+
const name = 'name.of.field'
6+
const value = '2020-01-01'
7+
const onChange = jest.fn()
8+
const input = { name, value, onChange }
9+
const error = 'input error'
10+
11+
test('DateInput renders the error message when provided', () => {
12+
const props = { input, meta: { invalid: true, touched: true, error } }
13+
const wrapper = mount(<DateInput { ...props }/>)
14+
expect(wrapper.find('.error-message').text()).toBe(error)
15+
})
16+
17+
test('DateInput updates the value on change', () => {
18+
const props = { input, meta: {} }
19+
const wrapper = mount(<DateInput { ...props }/>)
20+
expect(wrapper.find('input').props().value).toEqual('01/01/2020')
21+
22+
const newValue = '2020-02-02'
23+
wrapper.find('input').simulate('change', { target: { value: newValue } })
24+
expect(wrapper.find('input').props().value).toEqual(newValue)
25+
})
26+
27+
test('DateInput sets the placeholder text correctly', () => {
28+
const props = { input, meta: {}, placeholderText: 'Test Placeholder' }
29+
const wrapper = mount(<DateInput { ...props }/>)
30+
expect(wrapper.find('input').props().placeholder).toEqual('Test Placeholder')
31+
})
32+

0 commit comments

Comments
 (0)