1
1
import React from 'react' ;
2
- import { mount } from 'enzyme' ;
2
+ import { mount , shallow } from 'enzyme' ;
3
3
import { expect } from 'chai' ;
4
4
import Select from '..' ;
5
5
@@ -20,7 +20,7 @@ describe('Select Accessibility tests', () => {
20
20
} ;
21
21
22
22
beforeEach ( ( ) => {
23
- wrappedComponent = mount ( < Select options = { data } /> ) ;
23
+ wrappedComponent = mount ( shallow ( < Select options = { data } /> ) . get ( 0 ) ) ;
24
24
} ) ;
25
25
26
26
afterEach ( ( ) => {
@@ -62,4 +62,27 @@ describe('Select Accessibility tests', () => {
62
62
} ) ;
63
63
expect ( simulatedValue ( ) ) . to . equal ( expectedValueAfterSelection ) ;
64
64
} ) ;
65
+
66
+ it ( 'Successfully navigates to last item through keypress' , ( ) => {
67
+ const expectedValueAfterKeyDown = 'item 3' ;
68
+ focusOnInput ( ) ;
69
+ wrappedComponent . find ( '#select' ) . simulate ( 'keydown' , {
70
+ keyCode : 38 ,
71
+ key : 'ArrowUp' ,
72
+ } ) ;
73
+ expect ( wrappedComponent . find ( '#select-dropdown span[data-react-active-item="active"]' ) . text ( ) ) . equals ( expectedValueAfterKeyDown ) ;
74
+ } ) ;
75
+
76
+ const simulateEvent = ( component , event ) => wrappedComponent . find ( component ) . simulate ( event ) ;
77
+
78
+ it ( 'Should toggle blockBlurEvent state properly on mouseenter and mouse leave' , ( ) => {
79
+ const expectedValueBefore = true ;
80
+ const expectedValueAfter = false ;
81
+ const actualValue = ( ) => wrappedComponent . state ( ) . blockOnBlur ;
82
+ focusOnInput ( ) ;
83
+ simulateEvent ( 'div#select-dropdown' , 'mouseenter' ) ;
84
+ expect ( actualValue ( ) ) . to . equal ( expectedValueBefore ) ;
85
+ simulateEvent ( 'div#select-dropdown' , 'mouseleave' ) ;
86
+ expect ( actualValue ( ) ) . to . equal ( expectedValueAfter ) ;
87
+ } ) ;
65
88
} ) ;
0 commit comments