File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,23 @@ describe('AutoComplete Accessibility tests', () => {
69
69
expect ( simulatedValue ( ) ) . to . equal ( expectedValueAfterKeyDown ) ;
70
70
} ) ;
71
71
72
+ it ( 'Successfully navigates to prev item in list when up arrow key is pressed.' , ( ) => {
73
+ const expectedValueBeforeKeyDown = 'inactive' ;
74
+ const expectedValueAfterKeyDown = 'active' ;
75
+ const childIndex = 2 ; // Child item index to navigate to.
76
+ const simulatedValue = ( ) => wrappedComponent . find ( '#autocomplete-list' ) . childAt ( ( childIndex - data . length ) + 1 ) . prop ( 'aria-label' ) ;
77
+
78
+ focusOnInput ( ) ;
79
+ expect ( simulatedValue ( ) ) . to . equal ( expectedValueBeforeKeyDown ) ;
80
+ for ( let i = childIndex ; i >= 0 ; i -= 1 ) {
81
+ wrappedComponent . find ( 'input' ) . simulate ( 'keydown' , {
82
+ keyCode : 38 ,
83
+ key : 'ArrowUp' ,
84
+ } ) ;
85
+ }
86
+ expect ( simulatedValue ( ) ) . to . equal ( expectedValueAfterKeyDown ) ;
87
+ } ) ;
88
+
72
89
it ( 'Successfully updates input through keyboard navigation.' , ( ) => {
73
90
const expectedValueBeforeSelection = '' ;
74
91
const expectedValueAfterSelection = 'item 2' ;
Original file line number Diff line number Diff line change 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 AutoComplete from '..' ;
5
5
@@ -16,7 +16,7 @@ describe('AutoComplete Edge Cases tests', () => {
16
16
17
17
beforeEach ( ( ) => {
18
18
// Mount root component before test.
19
- wrappedComponent = mount ( < AutoComplete data = { data } /> ) ;
19
+ wrappedComponent = mount ( shallow ( < AutoComplete data = { data } /> ) . get ( 0 ) ) ;
20
20
} ) ;
21
21
22
22
afterEach ( ( ) => {
@@ -34,4 +34,12 @@ describe('AutoComplete Edge Cases tests', () => {
34
34
wrappedComponent . find ( 'input' ) . simulate ( 'focus' ) ;
35
35
expect ( simulatedValue ( ) ) . equal ( expectedValue ) ;
36
36
} ) ;
37
+
38
+ it ( 'Shoud toggle blockOnBlur state on mouseneter and mountleave events' , ( ) => {
39
+ const actualValue = ( ) => wrappedComponent . state ( ) . blockOnBlur ;
40
+ wrappedComponent . find ( '#autocomplete-list' ) . simulate ( 'mouseenter' ) ;
41
+ expect ( actualValue ( ) ) . to . equal ( true ) ;
42
+ wrappedComponent . find ( '#autocomplete-list' ) . simulate ( 'mouseleave' ) ;
43
+ expect ( actualValue ( ) ) . to . equal ( false ) ;
44
+ } ) ;
37
45
} ) ;
You can’t perform that action at this time.
0 commit comments