16
16
17
17
import { assert } from 'chai' ;
18
18
import bel from 'bel' ;
19
- import lolex from 'lolex' ;
20
19
import td from 'testdouble' ;
21
20
22
21
import { verifyDefaultAdapter } from '../helpers/foundation' ;
@@ -39,10 +38,10 @@ function setupHookTest() {
39
38
return { foundation, mockAdapter, nativeInput} ;
40
39
}
41
40
42
- // Shims Object.getOwnPropertyDescriptor for the checkbox 's WebIDL attributes. Used to test
41
+ // Shims Object.getOwnPropertyDescriptor for the input 's WebIDL attributes. Used to test
43
42
// the behavior of overridding WebIDL properties in different browser environments. For example,
44
43
// in Safari WebIDL attributes don't return get/set in descriptors.
45
- function withMockCheckboxDescriptorReturning ( descriptor , runTests ) {
44
+ function withMockInputDescriptorReturning ( descriptor , runTests ) {
46
45
const originalDesc = Object . getOwnPropertyDescriptor ( Object , 'getOwnPropertyDescriptor' ) ;
47
46
const mockGetOwnPropertyDescriptor = td . func ( '.getOwnPropertyDescriptor' ) ;
48
47
@@ -214,7 +213,7 @@ test('#init does not add mdc-textfield__label--float-above class if the input do
214
213
215
214
test ( '#init handles case when WebIDL attrs cannot be overridden (Safari)' , ( ) => {
216
215
const { foundation, nativeInput} = setupHookTest ( ) ;
217
- withMockCheckboxDescriptorReturning ( DESC_UNDEFINED , ( ) => {
216
+ withMockInputDescriptorReturning ( DESC_UNDEFINED , ( ) => {
218
217
assert . doesNotThrow ( ( ) => {
219
218
foundation . init ( ) ;
220
219
nativeInput . value = nativeInput . value + '_' ;
@@ -224,14 +223,14 @@ test('#init handles case when WebIDL attrs cannot be overridden (Safari)', () =>
224
223
225
224
test ( '#init handles case when property descriptors are not returned at all (Android Browser)' , ( ) => {
226
225
const { foundation} = setupHookTest ( ) ;
227
- withMockCheckboxDescriptorReturning ( undefined , ( ) => {
226
+ withMockInputDescriptorReturning ( undefined , ( ) => {
228
227
assert . doesNotThrow ( ( ) => foundation . init ( ) ) ;
229
228
} ) ;
230
229
} ) ;
231
230
232
231
test ( '#destroy handles case when WebIDL attrs cannot be overridden (Safari)' , ( ) => {
233
232
const { foundation} = setupHookTest ( ) ;
234
- withMockCheckboxDescriptorReturning ( DESC_UNDEFINED , ( ) => {
233
+ withMockInputDescriptorReturning ( DESC_UNDEFINED , ( ) => {
235
234
assert . doesNotThrow ( ( ) => foundation . init ( ) , 'init sanity check' ) ;
236
235
assert . doesNotThrow ( ( ) => foundation . destroy ( ) ) ;
237
236
} ) ;
@@ -543,32 +542,33 @@ test('interacting with text field does not emit custom events if input is disabl
543
542
td . verify ( mockAdapter . notifyIconAction ( ) , { times : 0 } ) ;
544
543
} ) ;
545
544
546
- test ( '"value" property change hook removes mdc-textfield__label--float-above class ' , ( ) => {
545
+ test ( '"value" property change hook works properly ' , ( ) => {
547
546
const { foundation, mockAdapter, nativeInput} = setupHookTest ( ) ;
548
- const clock = lolex . install ( ) ;
547
+ let inputValue = '' ;
549
548
550
- withMockCheckboxDescriptorReturning ( {
551
- get : ( ) => { } ,
552
- set : ( ) => { } ,
549
+ withMockInputDescriptorReturning ( {
550
+ get : ( ) => inputValue ,
551
+ set : ( value ) => inputValue = value ,
553
552
enumerable : false ,
554
553
configurable : true ,
555
554
} , ( ) => {
556
- nativeInput . value = '_' ;
557
555
foundation . init ( ) ;
556
+
557
+ nativeInput . value = '_' ;
558
+ td . verify ( mockAdapter . addClassToLabel ( cssClasses . LABEL_FLOAT_ABOVE ) ) ;
559
+
558
560
nativeInput . value = '' ;
559
561
td . verify ( mockAdapter . removeClassFromLabel ( cssClasses . LABEL_FLOAT_ABOVE ) ) ;
560
562
} ) ;
561
-
562
- clock . uninstall ( ) ;
563
563
} ) ;
564
564
565
565
test ( '"value" property change hook does nothing if input is focused' , ( ) => {
566
566
const { foundation, mockAdapter, nativeInput} = setupHookTest ( ) ;
567
- const clock = lolex . install ( ) ;
567
+ let inputValue = '' ;
568
568
569
- withMockCheckboxDescriptorReturning ( {
570
- get : ( ) => { } ,
571
- set : ( ) => { } ,
569
+ withMockInputDescriptorReturning ( {
570
+ get : ( ) => inputValue ,
571
+ set : ( value ) => inputValue = value ,
572
572
enumerable : false ,
573
573
configurable : true ,
574
574
} , ( ) => {
@@ -578,9 +578,12 @@ test('"value" property change hook does nothing if input is focused', () => {
578
578
} ) ;
579
579
foundation . init ( ) ;
580
580
focus ( ) ;
581
+ td . verify ( mockAdapter . addClassToLabel ( cssClasses . LABEL_FLOAT_ABOVE ) , { times : 1 } ) ;
582
+
583
+ nativeInput . value = '_' ;
584
+ td . verify ( mockAdapter . addClassToLabel ( cssClasses . LABEL_FLOAT_ABOVE ) , { times : 1 } ) ;
585
+
581
586
nativeInput . value = '' ;
582
587
td . verify ( mockAdapter . removeClassFromLabel ( cssClasses . LABEL_FLOAT_ABOVE ) , { times : 0 } ) ;
583
588
} ) ;
584
-
585
- clock . uninstall ( ) ;
586
589
} ) ;
0 commit comments