forked from reactstrap/reactstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomInput.spec.js
228 lines (188 loc) · 9.04 KB
/
CustomInput.spec.js
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
import React from 'react';
import { shallow, mount } from 'enzyme';
import { CustomInput } from '../';
describe('Custom Inputs', () => {
describe('CustomCheckbox', () => {
it('should render an optional label', () => {
const checkbox = mount(<CustomInput type="checkbox" label="Yo!" />);
expect(checkbox.find('label').text()).toBe('Yo!');
});
it('should render children in the outer div', () => {
const checkbox = shallow(<CustomInput type="checkbox" />);
expect(checkbox.type()).toBe('div');
});
it('should render an input with the type of checkbox', () => {
const checkbox = mount(<CustomInput type="checkbox" />);
expect(checkbox.find('input').prop('type')).toBe('checkbox');
});
it('should pass id to both the input and label nodes', () => {
const checkbox = mount(<CustomInput type="checkbox" id="yo" />);
expect(checkbox.find('input').prop('id')).toBe('yo');
expect(checkbox.find('label').prop('htmlFor')).toBe('yo');
});
it('should pass classNames to the outer div', () => {
const checkbox = mount(<CustomInput type="checkbox" className="yo" />);
expect(checkbox.find('.custom-control').prop('className').indexOf('yo') > -1).toBeTruthy();
});
it('should add class is-invalid when invalid is true', () => {
const checkbox = mount(<CustomInput type="checkbox" invalid />);
expect(checkbox.find('input').prop('className').indexOf('is-invalid') > -1).toBeTruthy();
});
it('should add class is-valid when valid is true', () => {
const checkbox = mount(<CustomInput type="checkbox" valid />);
expect(checkbox.find('input').prop('className').indexOf('is-valid') > -1).toBeTruthy();
});
it('should pass all other props to the input node', () => {
const checkbox = mount(<CustomInput type="checkbox" data-testprop="yo" />);
expect(checkbox.find('input').prop('data-testprop')).toBe('yo');
});
it('should reference innerRef to the input node', () => {
const ref = React.createRef();
mount(<CustomInput type="checkbox" innerRef={ref} />);
expect(ref.current).not.toBeNull();
expect(ref.current).toBeInstanceOf(HTMLInputElement);
});
});
describe('CustomRadio', () => {
it('should render an optional label', () => {
const radio = mount(<CustomInput type="radio" label="Yo!" />);
expect(radio.find('label').text()).toBe('Yo!');
});
it('should render children in the outer div', () => {
const radio = shallow(<CustomInput type="radio" />);
expect(radio.type()).toBe('div');
});
it('should render an input with the type of radio', () => {
const radio = mount(<CustomInput type="radio" />);
expect(radio.find('input').prop('type')).toBe('radio');
});
it('should add class is-invalid when invalid is true', () => {
const radio = mount(<CustomInput type="radio" invalid />);
expect(radio.find('input').prop('className').indexOf('is-invalid') > -1).toBeTruthy();
});
it('should add class is-valid when valid is true', () => {
const radio = mount(<CustomInput type="radio" valid />);
expect(radio.find('input').prop('className').indexOf('is-valid') > -1).toBeTruthy();
});
it('should pass id to both the input and label nodes', () => {
const radio = mount(<CustomInput type="radio" id="yo" />);
expect(radio.find('input').prop('id')).toBe('yo');
expect(radio.find('label').prop('htmlFor')).toBe('yo');
});
it('should pass classNames to the outer div', () => {
const radio = mount(<CustomInput type="radio" className="yo" />);
expect(radio.find('.custom-control').prop('className').indexOf('yo') > -1).toBeTruthy();
});
it('should pass all other props to the input node', () => {
const radio = mount(<CustomInput type="radio" data-testprop="yo" />);
expect(radio.find('input').prop('data-testprop')).toBe('yo');
});
it('should reference innerRef to the input node', () => {
const ref = React.createRef();
mount(<CustomInput type="radio" innerRef={ref} />);
expect(ref.current).not.toBeNull();
expect(ref.current).toBeInstanceOf(HTMLInputElement);
});
});
describe('CustomSelect', () => {
it('should render children in the outer div', () => {
const select = shallow(<CustomInput type="select" />);
expect(select.type()).toBe('select');
});
it('should add class is-invalid when invalid is true', () => {
const select = mount(<CustomInput type="select" invalid />);
expect(select.find('select').prop('className').indexOf('is-invalid') > -1).toBeTruthy();
});
it('should add class is-valid when valid is true', () => {
const select = mount(<CustomInput type="select" valid />);
expect(select.find('select').prop('className').indexOf('is-valid') > -1).toBeTruthy();
});
it('should add the size class when bsSize is provided', () => {
const select = mount(<CustomInput type="select" bsSize="lg" />);
expect(select.find('select').prop('className').indexOf('custom-select-lg') > -1).toBeTruthy();
});
it('should pass classNames to the outer div', () => {
const select = mount(<CustomInput type="select" className="yo" />);
expect(select.find('.custom-select').prop('className').indexOf('yo') > -1).toBeTruthy();
});
it('should pass all other props to the input node', () => {
const select = mount(<CustomInput type="select" data-testprop="yo" />);
expect(select.find('select').prop('data-testprop')).toBe('yo');
});
it('should reference innerRef to the select node', () => {
const ref = React.createRef();
mount(<CustomInput type="select" innerRef={ref} />);
expect(ref.current).not.toBeNull();
expect(ref.current).toBeInstanceOf(HTMLSelectElement);
});
});
describe('CustomFile', () => {
it('should render children in the outer div', () => {
const file = shallow(<CustomInput type="file" />);
expect(file.type()).toBe('div');
});
it('should add class is-invalid when invalid is true', () => {
const file = mount(<CustomInput type="file" invalid />);
expect(file.find('input').prop('className').indexOf('is-invalid') > -1).toBeTruthy();
});
it('should add class is-valid when valid is true', () => {
const file = mount(<CustomInput type="file" valid />);
expect(file.find('input').prop('className').indexOf('is-valid') > -1).toBeTruthy();
});
it('should render an input with the type of file', () => {
const file = mount(<CustomInput type="file" />);
expect(file.find('input').prop('type')).toBe('file');
});
it('should pass id to both the input and label nodes', () => {
const file = mount(<CustomInput type="file" id="yo" />);
expect(file.find('input').prop('id')).toBe('yo');
expect(file.find('label').prop('htmlFor')).toBe('yo');
});
it('should pass classNames to the outer div', () => {
const file = mount(<CustomInput type="file" className="yo" />);
expect(file.find('.custom-file').prop('className').indexOf('yo') > -1).toBeTruthy();
});
it('should set the label when provided', () => {
const file = mount(<CustomInput type="file" label="yo" />);
expect(file.find('label').text()).toBe('yo');
});
it('should pass all other props to the input node', () => {
const file = mount(<CustomInput type="file" data-testprop="yo" />);
expect(file.find('input').prop('data-testprop')).toBe('yo');
});
it('should reference innerRef to the input node', () => {
const ref = React.createRef();
mount(<CustomInput type="file" innerRef={ref} />);
expect(ref.current).not.toBeNull();
expect(ref.current).toBeInstanceOf(HTMLInputElement);
});
});
describe('CustomRange', () => {
it('should render children in the outer div', () => {
const range = shallow(<CustomInput type="range" />);
expect(range.type()).toBe('input');
});
it('should add class is-invalid when invalid is true', () => {
const range = mount(<CustomInput type="range" invalid />);
expect(range.find('input').prop('className').indexOf('is-invalid') > -1).toBeTruthy();
});
it('should add class is-valid when valid is true', () => {
const range = mount(<CustomInput type="range" valid />);
expect(range.find('input').prop('className').indexOf('is-valid') > -1).toBeTruthy();
});
it('should render an input with the type of range', () => {
const range = mount(<CustomInput type="range" />);
expect(range.find('input').prop('type')).toBe('range');
});
it('should pass all other props to the input node', () => {
const range = mount(<CustomInput type="range" data-testprop="yo" />);
expect(range.find('input').prop('data-testprop')).toBe('yo');
});
it('should reference innerRef to the input node', () => {
const ref = React.createRef();
mount(<CustomInput type="range" innerRef={ref} />);
expect(ref.current).not.toBeNull();
expect(ref.current).toBeInstanceOf(HTMLInputElement);
});
});
});