Skip to content

Commit fc92227

Browse files
author
Rachel Killackey
authored
Merge pull request #117 from LaunchPadLab/date-input-tests
Add tests for `DateInput`
2 parents 77b8143 + 006d97c commit fc92227

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@launchpadlab/lp-components",
3-
"version": "1.18.4",
3+
"version": "1.18.5",
44
"description": "Our Components",
55
"main": "lib/index.js",
66
"repository": "launchpadlab/lp-components",
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)