-
Notifications
You must be signed in to change notification settings - Fork 227
/
index.test.tsx
748 lines (672 loc) · 22.4 KB
/
index.test.tsx
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
import * as React from 'react';
import * as td from 'testdouble';
import {assert} from 'chai';
import {mount, shallow} from 'enzyme';
import TextField, {
HelperText,
Input,
} from '../../../packages/text-field';
import {coerceForTesting} from '../helpers/types';
import {InputProps} from '../../../packages/text-field/Input'; // eslint-disable-line no-unused-vars
/* eslint-disable */
import FloatingLabel from '../../../packages/floating-label';
/* eslint-enable */
suite('Text Field');
test('classNames adds classes', () => {
const wrapper = mount(
<TextField label='my label' className='test-class-name'>
<Input />
</TextField>
);
const textField = wrapper.find('.mdc-text-field');
assert.equal(textField.length, 1);
assert.isTrue(textField.hasClass('test-class-name'));
});
test('classNames get outlined class when prop.outlined is true', () => {
const wrapper = mount(
<TextField label='my label' outlined>
<Input />
</TextField>
);
const textField = wrapper.find('.mdc-text-field--outlined');
assert.equal(textField.length, 1);
});
test('classNames get outlinetextaread class when prop.textarea is true', () => {
const wrapper = mount(
<TextField label='my label' textarea>
<Input />
</TextField>
);
const textField = wrapper.find('.mdc-text-field--textarea');
assert.equal(textField.length, 1);
});
test('classNames get fullwidth class when prop.fullWidth is true', () => {
const wrapper = mount(
<TextField label='my label' fullWidth>
<Input />
</TextField>
);
const textField = wrapper.find('.mdc-text-field--fullwidth');
assert.equal(textField.length, 1);
});
test('classNames get disabled class when prop.disabled is true on the input', () => {
const wrapper = mount(
<TextField label='my label'>
<Input disabled />
</TextField>
);
const textField = wrapper.find('.mdc-text-field--disabled');
assert.equal(textField.length, 1);
});
test('classNames get trailingIcon class when prop.trailingIcon is passed an icon element', () => {
const wrapper = mount(
<TextField label='my label' trailingIcon={<i />}>
<Input />
</TextField>
);
const textField = wrapper.find('.mdc-text-field--with-trailing-icon');
assert.equal(textField.length, 1);
});
test('classNames get leadingIcon class when prop.leadingIcon is passed an icon element', () => {
const wrapper = mount(
<TextField label='my label' leadingIcon={<i />}>
<Input />
</TextField>
);
const textField = wrapper.find('.mdc-text-field--with-leading-icon');
assert.equal(textField.length, 1);
});
test('classNames get dense class when prop.dense is true', () => {
const wrapper = mount(
<TextField label='my label' dense>
<Input />
</TextField>
);
const textField = wrapper.find('.mdc-text-field--dense');
assert.equal(textField.length, 1);
});
test('style prop adds style attribute', () => {
const wrapper = mount(
<TextField label='my label' style={{backgroundColor: 'red'}}>
<Input />
</TextField>
);
const textField = wrapper.find('.mdc-text-field[style]');
assert.equal(textField.length, 1);
});
test('#componentDidMount creates foundation', () => {
const wrapper = shallow<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input />
</TextField>
);
assert.exists(wrapper.state().foundation);
});
test('#componentDidUpdate does not call setValue if another property updates', () => {
const wrapper = shallow<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input />
</TextField>
);
wrapper.state().foundation.setValue = td.func();
wrapper.setState({dir: 'rtl'});
td.verify(wrapper.state().foundation.setValue(td.matchers.isA(String)), {
times: 0,
});
});
test('#adapter.addClass adds class to state.classList', () => {
const wrapper = shallow<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input />
</TextField>
);
wrapper.state().foundation.adapter_.addClass('test-class-name');
assert.isTrue(wrapper.state().classList.has('test-class-name'));
});
test('#adapter.removeClass removes class from state.classList', () => {
const wrapper = shallow<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input />
</TextField>
);
const classList = new Set();
classList.add('test-class-name');
wrapper.setState({classList});
wrapper.state().foundation.adapter_.removeClass('test-class-name');
assert.isFalse(wrapper.state().classList.has('test-class-name'));
});
test('#adapter.removeClass removes class from state.classList', () => {
const wrapper = shallow<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input />
</TextField>
);
const classList = new Set();
classList.add('test-class-name');
wrapper.setState({classList});
assert.isTrue(
wrapper.state().foundation.adapter_.hasClass('test-class-name')
);
});
test('#adapter.isFocused returns true if state.isFocused updates to true', () => {
const wrapper = mount<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input />
</TextField>
);
wrapper.setState({isFocused: true});
assert.isTrue(wrapper.state().foundation.adapter_.isFocused());
});
test('#adapter.isRtl returns true props.isRtl if is true', () => {
const wrapper = shallow<TextField<HTMLInputElement>>(
<TextField isRtl label='my label'>
<Input />
</TextField>
);
assert.isTrue(wrapper.state().foundation.adapter_.isRtl());
});
test('#adapter.isRtl returns false props.isRtl if is false', () => {
const wrapper = mount<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input />
</TextField>
);
assert.isFalse(wrapper.state().foundation.adapter_.isRtl());
});
test('#adapter.input.getNativeInput.validity.valid returns false for invalid input with email pattern', () => {
const wrapper = mount<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input value='123' pattern='[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$' />
</TextField>
);
const valid = wrapper.state().foundation.adapter_.getNativeInput().validity
.valid;
assert.isFalse(valid);
});
test('#adapter.input.getNativeInput.validity.valid returns false for required field with no value', () => {
const wrapper = mount<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input value='' required />
</TextField>
);
const valid = wrapper.state().foundation.adapter_.getNativeInput().validity
.valid;
assert.isFalse(valid);
});
test('#adapter.input.getNativeInput.validity.valid returns true for required field with value', () => {
const wrapper = mount<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input value='value' required />
</TextField>
);
const valid = wrapper.state().foundation.adapter_.getNativeInput().validity
.valid;
assert.isTrue(valid);
});
test('#adapter.input.getNativeInput.validity.valid returns true for valid email', () => {
const wrapper = mount<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input
value='chevy@gmail.com'
pattern='[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$'
/>
</TextField>
);
const valid = wrapper.state().foundation.adapter_.getNativeInput().validity
.valid;
assert.isTrue(valid);
});
test('#get adapter.input.value returns state.value', () => {
const wrapper = shallow<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input />
</TextField>
);
wrapper.setState({value: '123'});
const value = wrapper.state().foundation.adapter_.getNativeInput().value;
assert.equal(value, '123');
});
test('#adapter.label.shakeLabel calls floatingLabelElement shake', () => {
const wrapper = shallow<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input />
</TextField>
);
wrapper.instance().floatingLabelElement = td.object({
current: td.object({
shake: td.func(),
}),
}) as React.RefObject<FloatingLabel>;
wrapper.state().foundation.adapter_.shakeLabel(true);
td.verify(wrapper.instance().floatingLabelElement.current!.shake(), {
times: 1,
});
});
test('#adapter.label.shakeLabel does not call floatingLabelElement shake if false is passed', () => {
const wrapper = shallow<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input />
</TextField>
);
wrapper.instance().floatingLabelElement = coerceForTesting<React.RefObject<FloatingLabel>>(td.object({
current: td.object({
shake: td.func(),
}),
}));
wrapper.state().foundation.adapter_.shakeLabel(false);
td.verify(wrapper.instance().floatingLabelElement.current!.shake(), {
times: 0,
});
});
test('#adapter.label.floatLabel updates state.labelIsFloated to true', () => {
const wrapper = shallow<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input />
</TextField>
);
wrapper.state().foundation.adapter_.floatLabel(true);
assert.isTrue(wrapper.state().labelIsFloated);
});
test('#adapter.label.floatLabel updates state.labelIsFloated to false', () => {
const wrapper = shallow<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input />
</TextField>
);
wrapper.setState({labelIsFloated: true});
wrapper.state().foundation.adapter_.floatLabel(false);
assert.isFalse(wrapper.state().labelIsFloated);
});
test('#adapter.label.hasLabel returns true if label exists', () => {
const wrapper = shallow<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input />
</TextField>
);
assert.isTrue(wrapper.state().foundation.adapter_.hasLabel());
});
test('#adapter.label.getLabelWidth returns offsetWidth of labelElement', () => {
const div = document.createElement('div');
document.body.appendChild(div);
const wrapper = mount<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input />
</TextField>,
{attachTo: div}
);
const labelElement = wrapper.instance().floatingLabelElement.current!.labelElement_;
assert.equal(wrapper.state().foundation.adapter_.getLabelWidth(), labelElement.current!.offsetWidth);
document.body.removeChild(div);
});
test('#adapter.label.getLabelWidth returns state.initialLabelWidth', () => {
const wrapper = shallow<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input />
</TextField>
);
wrapper.setState({initialLabelWidth: 88});
assert.equal(wrapper.state().foundation.adapter_.getLabelWidth(), 88);
});
test('#adapter.lineRipple.activeLineRipple sets state.activeLineRipple to true', () => {
const wrapper = shallow<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input />
</TextField>
);
wrapper.state().foundation.adapter_.activateLineRipple();
assert.isTrue(wrapper.state().activeLineRipple);
});
test('#adapter.lineRipple.deactivateLineRipple sets state.activeLineRipple to false', () => {
const wrapper = shallow<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input />
</TextField>
);
wrapper.setState({activeLineRipple: true});
wrapper.state().foundation.adapter_.deactivateLineRipple();
assert.isFalse(wrapper.state().activeLineRipple);
});
test('#adapter.lineRipple.setLineRippleTransformOrigin sets state.lineRippleCenter', () => {
const wrapper = shallow<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input />
</TextField>
);
wrapper.state().foundation.adapter_.setLineRippleTransformOrigin(123);
assert.equal(wrapper.state().lineRippleCenter, 123);
});
test('#adapter.notchedOutline.notchOutline sets state.outlineIsNotched to true', () => {
const wrapper = shallow<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input />
</TextField>
);
wrapper.state().foundation.adapter_.notchOutline();
assert.isTrue(wrapper.state().outlineIsNotched);
});
test('#adapter.notchedOutline.notchOutline sets state.notchedLabelWidth', () => {
const wrapper = shallow<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input />
</TextField>
);
wrapper.state().foundation.adapter_.notchOutline(90);
assert.equal(wrapper.state().notchedLabelWidth, 90);
});
test('#adapter.notchedOutline.closeOutline sets state.outlineIsNotched to false', () => {
const wrapper = shallow<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input />
</TextField>
);
wrapper.state().foundation.adapter_.closeOutline();
assert.isFalse(wrapper.state().outlineIsNotched);
});
test('#adapter.notchedOutline.hasOutline returns true if props.outlined is set', () => {
const wrapper = shallow<TextField<HTMLInputElement>>(
<TextField label='my label' outlined>
<Input />
</TextField>
);
const hasOutline = wrapper.state().foundation.adapter_.hasOutline();
assert.isTrue(hasOutline);
});
test('#adapter.helperText.showToScreenReader toggles state.showHelperTextToScreenReader', () => {
const wrapper = shallow<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input />
</TextField>
);
wrapper.state().foundation.helperText_.showToScreenReader();
assert.isTrue(wrapper.state().showHelperTextToScreenReader);
});
test('#adapter.helperText.setValidity sets isValid to true', () => {
const wrapper = shallow<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input />
</TextField>
);
wrapper.state().foundation.helperText_.setValidity(true);
assert.isTrue(wrapper.state().isValid);
});
test('#events.onClick triggers #foundation.handleTextFieldInteraction', () => {
const wrapper = shallow<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input />
</TextField>
);
wrapper.state().foundation.handleTextFieldInteraction = td.func();
wrapper.simulate('click');
td.verify(wrapper.state().foundation.handleTextFieldInteraction(), {
times: 1,
});
});
test('#events.onKeyDown triggers #foundation.handleTextFieldInteraction', () => {
const wrapper = shallow<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input />
</TextField>
);
wrapper.state().foundation.handleTextFieldInteraction = td.func();
wrapper.simulate('keyDown');
td.verify(wrapper.state().foundation.handleTextFieldInteraction(), {
times: 1,
});
});
test('renders leadingIcon if passed as prop', () => {
const wrapper = shallow(<TextField label='my label'
leadingIcon={<i className='test-class-name-icon' />}
><Input /></TextField>);
assert.equal(wrapper.find('.test-class-name-icon').length, 1);
});
test('does not render leadingIcon if no leadingIcon prop is passed', () => {
const wrapper = shallow(
<TextField label='my label'>
<Input />
</TextField>
);
assert.equal(wrapper.find('.test-class-name-icon').length, 0);
});
test('onLeadingIconSelect is passed to leadingIcon if passed as prop', () => {
const onSelect = () => 'select';
const wrapper = shallow<TextField<HTMLInputElement>>(
<TextField
label='my label'
onLeadingIconSelect={onSelect}
leadingIcon={<i className='test-class-name-icon' />}
><Input /></TextField>
);
const leadingIcon = wrapper.find('.test-class-name-icon').parent().props();
assert.isFunction(leadingIcon.onSelect);
assert.strictEqual(leadingIcon.onSelect, onSelect);
});
test('onLeadingIconSelect is not passed to leadingIcon if not passed as prop', () => {
const wrapper = shallow<TextField<HTMLInputElement>>(
<TextField
label='my label'
leadingIcon={<i className='test-class-name-icon' />}
><Input /></TextField>
);
const leadingIcon = wrapper.find('.test-class-name-icon').parent().props();
assert.isNotFunction(leadingIcon.onSelect);
assert.isUndefined(leadingIcon.onSelect);
});
test('renders trailingIcon if passed as prop', () => {
const wrapper = shallow(<TextField label='my label'
trailingIcon={<i className='test-class-name-icon' />}
><Input /></TextField>);
assert.equal(wrapper.find('.test-class-name-icon').length, 1);
});
test('does not render trailingIcon if no trailingIcon prop is passed', () => {
const wrapper = shallow(
<TextField label='my label'>
<Input />
</TextField>
);
assert.equal(wrapper.find('.test-class-name-icon').length, 0);
});
test('onTrailingIconSelect is passed to trailingIcon if passed as prop', () => {
const onSelect = () => 'select';
const wrapper = shallow<TextField<HTMLInputElement>>(
<TextField
label='my label'
onTrailingIconSelect={onSelect}
trailingIcon={<i className='test-class-name-icon' />}
><Input /></TextField>
);
const trailingIcon = wrapper.find('.test-class-name-icon').parent().props();
assert.isFunction(trailingIcon.onSelect);
assert.strictEqual(trailingIcon.onSelect, onSelect);
});
test('onTrailingIconSelect is not passed to trailingIcon if not passed as prop', () => {
const wrapper = shallow<TextField<HTMLInputElement>>(
<TextField
label='my label'
trailingIcon={<i className='test-class-name-icon' />}
><Input /></TextField>
);
const trailingIcon = wrapper.find('.test-class-name-icon').parent().props();
assert.isNotFunction(trailingIcon.onSelect);
assert.isUndefined(trailingIcon.onSelect);
});
test('renders label if label is passed as prop', () => {
const wrapper = mount(
<TextField label='my label'>
<Input />
</TextField>
);
assert.equal(wrapper.find('.mdc-floating-label').length, 1);
});
test('does not render label if fullWidth is passed as prop', () => {
const wrapper = mount(
<TextField label='my label' fullWidth>
<Input />
</TextField>
);
assert.equal(wrapper.find('.mdc-floating-label').length, 0);
});
test('renders notchedOutline if notchedOutline prop is passed', () => {
const wrapper = mount(
<TextField label='my label' outlined>
<Input />
</TextField>
);
assert.equal(wrapper.find('.mdc-notched-outline').length, 1);
});
test('renders line ripple', () => {
const wrapper = mount(
<TextField label='my label'>
<Input />
</TextField>
);
assert.equal(wrapper.find('.mdc-line-ripple').length, 1);
});
test('does not render line ripple if outlined variant', () => {
const wrapper = mount(
<TextField label='my label' outlined>
<Input />
</TextField>
);
assert.equal(wrapper.find('.mdc-line-ripple').length, 0);
});
test('does not render line ripple if textarea variant', () => {
const wrapper = mount(
<TextField label='my label' textarea>
<Input />
</TextField>
);
assert.equal(wrapper.find('.mdc-line-ripple').length, 0);
});
test('does not render line ripple if fullWidth variant', () => {
const wrapper = mount(
<TextField label='my label' fullWidth>
<Input />
</TextField>
);
assert.equal(wrapper.find('.mdc-line-ripple').length, 0);
});
test('renders helperText if helperText prop is passed', () => {
const helperText = <HelperText>my helper text</HelperText>;
const wrapper = mount(
<TextField label='my label' helperText={helperText}>
<Input />
</TextField>
);
assert.equal(wrapper.find('.mdc-text-field-helper-text').length, 1);
assert.equal(wrapper.find('.mdc-text-field').length, 1);
});
test('renders textarea if textarea variant', () => {
const wrapper = mount(
<TextField label='my label' textarea>
<Input />
</TextField>
);
assert.equal(wrapper.find('textarea').length, 1);
});
test('does not render input if there is no foundation', () => {
const wrapper = shallow(
<TextField label='my label'>
<Input />
</TextField>,
{disableLifecycleMethods: true}
);
assert.equal(wrapper.find(Input).length, 0);
});
test('renders input after foundation is created', () => {
const wrapper = shallow(
<TextField label='my label'>
<Input />
</TextField>,
{disableLifecycleMethods: true}
);
wrapper.setState({foundation: {}});
assert.equal(wrapper.find(Input).length, 1);
});
test('#inputProps.handleFocusChange updates state.isFocused', () => {
const wrapper = shallow<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input />
</TextField>
);
wrapper
.instance()
.inputProps(coerceForTesting<React.ReactElement<InputProps<HTMLInputElement>>>({}))
.handleFocusChange(true);
assert.isTrue(wrapper.state().isFocused);
});
test('#inputProps.handleValueChange updates state.value', () => {
const wrapper = shallow<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input />
</TextField>
);
wrapper
.instance()
.inputProps(coerceForTesting<React.ReactElement<InputProps<HTMLInputElement>>>({}))
.handleValueChange('meow', coerceForTesting<() => void>(td.func()));
assert.equal(wrapper.state().value, 'meow');
});
test('#inputProps.handleValueChange calls cb after state is set', () => {
const wrapper = shallow<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input />
</TextField>
);
const callback = td.func();
wrapper
.instance()
.inputProps(coerceForTesting<React.ReactElement<InputProps<HTMLInputElement>>>({}))
.handleValueChange('meow', coerceForTesting<() => void>(callback));
td.verify(callback(), {times: 1});
});
test('#inputProps.setDisabled updates state.disabled', () => {
const wrapper = shallow<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input />
</TextField>
);
wrapper
.instance()
.inputProps(coerceForTesting<React.ReactElement<InputProps<HTMLInputElement>>>({}))
.setDisabled(true);
assert.isTrue(wrapper.state().disabled);
});
test('#inputProps.setInputId updates state.disabled', () => {
const wrapper = shallow<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input />
</TextField>
);
wrapper
.instance()
.inputProps(coerceForTesting<React.ReactElement<InputProps<HTMLInputElement>>>({}))
.setInputId('my-id');
assert.equal(wrapper.state().inputId, 'my-id');
});
test('passing a ref to the <Input /> should return the instance of the Input', () => {
let inputInstance;
const inputRef = (input: any) => inputInstance = input;
const wrapper = mount<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input ref={inputRef} />
</TextField>
);
assert.equal(
wrapper
.childAt(0)
.childAt(0)
.instance(),
inputInstance
);
});
test('#componentWillUnmount destroys foundation', () => {
const wrapper = shallow<TextField<HTMLInputElement>>(
<TextField label='my label'>
<Input />
</TextField>
);
const foundation = wrapper.state().foundation;
foundation.destroy = td.func();
wrapper.unmount();
td.verify(foundation.destroy(), {times: 1});
});