forked from reactstrap/reactstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInput.spec.js
More file actions
220 lines (154 loc) · 7.93 KB
/
Copy pathInput.spec.js
File metadata and controls
220 lines (154 loc) · 7.93 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
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
import React from 'react';
import { shallow } from 'enzyme';
import { Input } from '../';
describe('Input', () => {
it('should render with "input" tag when no type is provided', () => {
const wrapper = shallow(<Input>Yo!</Input>);
expect(wrapper.type()).toBe('input');
});
it('should render with "select" tag when type is "select"', () => {
const wrapper = shallow(<Input type="select">Yo!</Input>);
expect(wrapper.type()).toBe('select');
});
it('should render with "textarea" tag when type is "textarea"', () => {
const wrapper = shallow(<Input type="textarea">Yo!</Input>);
expect(wrapper.type()).toBe('textarea');
});
it('should render with "p" tag when plaintext prop is truthy', () => {
const wrapper = shallow(<Input type="select" plaintext />);
expect(wrapper.type()).toBe('p');
});
it('should render with "form-control-plaintext" class when plaintext prop is truthy', () => {
const wrapper = shallow(<Input type="select" plaintext />);
expect(wrapper.hasClass('form-control-plaintext')).toBe(true);
});
it('should not render with "form-control" class when plaintext prop is truthy', () => {
const wrapper = shallow(<Input type="select" plaintext />);
expect(wrapper.hasClass('form-control')).toBe(false);
});
it('should render with custom tag when plaintext prop is truthy and tag is provided', () => {
const wrapper = shallow(<Input type="select" plaintext tag="div" />);
expect(wrapper.type()).toBe('div');
});
it('should render with custom tag when plaintext prop is not truthy and tag is provided', () => {
const wrapper = shallow(<Input tag="div" />);
expect(wrapper.type()).toBe('div');
});
it('should render with "input" tag when type is not a special case', () => {
const wrapper = shallow(<Input type="email" />);
expect(wrapper.type()).toBe('input');
});
it('should render children', () => {
const wrapper = shallow(<Input>Yo!</Input>);
expect(wrapper.text()).toBe('Yo!');
});
it('should render with "is-invalid" class when state is "danger" [DEPRECATED]', () => {
const wrapper = shallow(<Input state="danger" />);
expect(wrapper.hasClass('is-invalid')).toBe(true);
});
it('should render with "is-valid" class when state is "success" [DEPRECATED]', () => {
const wrapper = shallow(<Input state="success" />);
expect(wrapper.hasClass('is-valid')).toBe(true);
});
it('should not render with "is-valid" nor "is-invalid" class when state is "warning" [DEPRECATED]', () => {
const wrapper = shallow(<Input state="warning" />);
expect(wrapper.hasClass('is-valid')).toBe(false);
expect(wrapper.hasClass('is-invalid')).toBe(false);
});
it('should not render with "is-invalid" class when valid is false', () => {
const wrapper = shallow(<Input valid={false} />);
expect(wrapper.hasClass('is-invalid')).toBe(false);
});
it('should not render with "is-valid" class when invalid is false', () => {
const wrapper = shallow(<Input invalid={false} />);
expect(wrapper.hasClass('is-valid')).toBe(false);
});
it('should render with "is-invalid" class when invalid is true', () => {
const wrapper = shallow(<Input invalid />);
expect(wrapper.hasClass('is-invalid')).toBe(true);
});
it('should render with "is-valid" class when valid is true', () => {
const wrapper = shallow(<Input valid />);
expect(wrapper.hasClass('is-valid')).toBe(true);
});
it('should render with "form-control-${size}" class when size is "lg" or "sm"', () => {
const wrapper = shallow(<Input size="lg" />);
expect(wrapper.hasClass('form-control-lg')).toBe(true);
});
it('should render with "form-control" class when size is nor "lg" nor "sm"', () => {
const wrapper = shallow(<Input size="5" />);
expect(wrapper.hasClass('form-control-sm')).toBe(false);
expect(wrapper.hasClass('form-control-lg')).toBe(false);
expect(wrapper.hasClass('form-control')).toBe(true);
});
it('should render with "form-control-${bsSize}" class when bsSize is provided', () => {
const wrapper = shallow(<Input bsSize="sm" />);
expect(wrapper.hasClass('form-control-sm')).toBe(true);
});
it('should render with "form-control" class by default', () => {
const wrapper = shallow(<Input />);
expect(wrapper.hasClass('form-control')).toBe(true);
});
it('should not render with "form-control-file" nor "form-control-plaintext" nor "form-check-input" class by default', () => {
const wrapper = shallow(<Input />);
expect(wrapper.hasClass('form-control-file')).toBe(false);
expect(wrapper.hasClass('form-control-plaintext')).toBe(false);
expect(wrapper.hasClass('form-check-input')).toBe(false);
});
it('should not render with "form-control" nor "form-control-plaintext" nor "form-check-input" class when type is file', () => {
const wrapper = shallow(<Input type="file" />);
expect(wrapper.hasClass('form-control')).toBe(false);
expect(wrapper.hasClass('form-control-plaintext')).toBe(false);
expect(wrapper.hasClass('form-check-input')).toBe(false);
});
it('should not render with "form-control-file" nor "form-control" nor "form-check-input" class when plaintext prop is truthy', () => {
const wrapper = shallow(<Input type="file" plaintext />);
expect(wrapper.hasClass('form-control-file')).toBe(false);
expect(wrapper.hasClass('form-control')).toBe(false);
expect(wrapper.hasClass('form-check-input')).toBe(false);
});
it('should not render with "form-control-file" nor "form-control" nor "form-check-input" class when static prop is truthy [DEPRECATED]', () => {
const wrapper = shallow(<Input type="file" static />);
expect(wrapper.hasClass('form-control-file')).toBe(false);
expect(wrapper.hasClass('form-control')).toBe(false);
expect(wrapper.hasClass('form-check-input')).toBe(false);
});
it('should not render with "form-control-file" nor "form-control-plaintext" nor "form-control" class when type is radio', () => {
const wrapper = shallow(<Input type="radio" />);
expect(wrapper.hasClass('form-control-file')).toBe(false);
expect(wrapper.hasClass('form-control-plaintext')).toBe(false);
expect(wrapper.hasClass('form-control')).toBe(false);
});
it('should not render with "form-control-file" nor "form-control-plaintext" nor "form-control" class when type is checkbox', () => {
const wrapper = shallow(<Input type="checkbox" />);
expect(wrapper.hasClass('form-control-file')).toBe(false);
expect(wrapper.hasClass('form-control-plaintext')).toBe(false);
expect(wrapper.hasClass('form-control')).toBe(false);
});
it('should render with "form-check-input" class when type is checkbox', () => {
const wrapper = shallow(<Input type="checkbox" />);
expect(wrapper.hasClass('form-check-input')).toBe(true);
});
it('should render with "form-check-input" class when type is radio', () => {
const wrapper = shallow(<Input type="radio" />);
expect(wrapper.hasClass('form-check-input')).toBe(true);
});
it('should not render with "form-check-input" nor "form-control" class when type is checkbox and addon is truthy', () => {
const wrapper = shallow(<Input addon type="checkbox" />);
expect(wrapper.hasClass('form-check-input')).toBe(false);
expect(wrapper.hasClass('form-control')).toBe(false);
});
it('should not render with "form-check-input" nor "form-control" class when type is radio and addon is truthy', () => {
const wrapper = shallow(<Input addon type="radio" />);
expect(wrapper.hasClass('form-check-input')).toBe(false);
expect(wrapper.hasClass('form-control')).toBe(false);
});
it('should render with "form-control-file" class when type is file', () => {
const wrapper = shallow(<Input type="file" />);
expect(wrapper.hasClass('form-control-file')).toBe(true);
});
it('should render additional classes', () => {
const wrapper = shallow(<Input className="other">Yo!</Input>);
expect(wrapper.hasClass('other')).toBe(true);
});
});