-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdropdown-checkbox-group.test.js
More file actions
62 lines (59 loc) · 1.83 KB
/
dropdown-checkbox-group.test.js
File metadata and controls
62 lines (59 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import React from 'react'
import { mount } from 'enzyme'
import { DropdownCheckboxGroup } from '../../../src/'
test('DropdownCheckboxGroup adds value to array when unselected option clicked', () => {
const onChange = jest.fn()
const TOGGLED_OPTION = 'TOGGLED_OPTION'
const props = {
input: {
name: 'test',
value: [],
onChange,
},
meta: {},
options: [TOGGLED_OPTION]
}
const wrapper = mount(<DropdownCheckboxGroup { ...props } />)
wrapper.find('input').simulate('change')
const newValue = onChange.mock.calls[0][0]
expect(newValue).toEqual([TOGGLED_OPTION])
})
test('DropdownCheckboxGroup removes value to array when selected option clicked', () => {
const onChange = jest.fn()
const TOGGLED_OPTION = 'TOGGLED_OPTION'
const props = {
input: {
name: 'test',
value: [TOGGLED_OPTION],
onChange,
},
meta: {},
options: [TOGGLED_OPTION]
}
const wrapper = mount(<DropdownCheckboxGroup { ...props } />)
wrapper.find('input').simulate('change')
const newValue = onChange.mock.calls[0][0]
expect(newValue).toEqual([])
})
test('DropdownCheckboxGroup allows custom selected option formatting', () => {
const selectedOptionsDisplayFormatter = (values) => {
return values.length ? values.join('; ') : 'Empty'
}
const onChange = jest.fn()
const TOGGLED_OPTION = 'TOGGLED_OPTION'
const props = {
input: {
name: 'test',
value: [],
onChange,
},
meta: {},
options: [TOGGLED_OPTION],
selectedOptionsDisplayFormatter,
}
const wrapper = mount(<DropdownCheckboxGroup { ...props } />)
wrapper.find('input').simulate('change')
const newValues = onChange.mock.calls[0]
const displayOptionsHtml = wrapper.find('.select-input').innerHTML
expect(displayOptionsHtml).toEqual(`<p>${selectedOptionsDisplayFormatter(newValues)}</p>`)
})