|
| 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