@@ -8,7 +8,6 @@ import { KeyCode } from '@cloudscape-design/test-utils-core/utils';
8
8
9
9
import '../../__a11y__/to-validate-a11y' ;
10
10
import Autosuggest , { AutosuggestProps } from '../../../lib/components/autosuggest' ;
11
- import { documentHasFocus } from '../../../lib/components/internal/utils/dom' ;
12
11
import createWrapper from '../../../lib/components/test-utils/dom' ;
13
12
14
13
import itemStyles from '../../../lib/components/internal/components/selectable-item/styles.css.js' ;
@@ -58,15 +57,8 @@ jest.mock('@cloudscape-design/component-toolkit/internal', () => {
58
57
warnOnce : jest . fn ( ) ,
59
58
} ;
60
59
} ) ;
61
-
62
- jest . mock ( '../../../lib/components/internal/utils/dom' , ( ) => ( {
63
- ...jest . requireActual ( '../../../lib/components/internal/utils/dom' ) ,
64
- documentHasFocus : jest . fn ( ( ) => true ) ,
65
- } ) ) ;
66
-
67
60
beforeEach ( ( ) => {
68
- ( warnOnce as jest . Mock ) . mockClear ( ) ;
69
- ( documentHasFocus as jest . Mock ) . mockClear ( ) ;
61
+ ( warnOnce as any ) . mockClear ( ) ;
70
62
} ) ;
71
63
72
64
test ( 'renders correct labels when focused' , ( ) => {
@@ -143,24 +135,21 @@ test('entered text option should not get screenreader override', () => {
143
135
) . toBeFalsy ( ) ;
144
136
} ) ;
145
137
146
- test ( 'should close dropdown on blur when document is in focus' , ( ) => {
147
- const { wrapper } = renderAutosuggest ( < Autosuggest enteredTextLabel = { v => v } value = "1" options = { defaultOptions } /> ) ;
138
+ test ( 'should not close dropdown when no realted target in blur' , ( ) => {
139
+ const { wrapper, container } = renderAutosuggest (
140
+ < div >
141
+ < Autosuggest enteredTextLabel = { v => v } value = "1" options = { defaultOptions } />
142
+ < button id = "focus-target" > focus target</ button >
143
+ </ div >
144
+ ) ;
148
145
wrapper . findNativeInput ( ) . focus ( ) ;
149
146
expect ( wrapper . findDropdown ( ) . findOpenDropdown ( ) ) . not . toBe ( null ) ;
150
147
151
- wrapper . findNativeInput ( ) . blur ( ) ;
152
- expect ( wrapper . findDropdown ( ) . findOpenDropdown ( ) ) . toBe ( null ) ;
153
- } ) ;
154
-
155
- test ( 'should not close dropdown on blur when document is not in focus' , ( ) => {
156
- ( documentHasFocus as jest . Mock ) . mockImplementation ( ( ) => false ) ;
157
-
158
- const { wrapper } = renderAutosuggest ( < Autosuggest enteredTextLabel = { v => v } value = "1" options = { defaultOptions } /> ) ;
159
- wrapper . findNativeInput ( ) . focus ( ) ;
148
+ document . body . focus ( ) ;
160
149
expect ( wrapper . findDropdown ( ) . findOpenDropdown ( ) ) . not . toBe ( null ) ;
161
150
162
- wrapper . findNativeInput ( ) . blur ( ) ;
163
- expect ( wrapper . findDropdown ( ) . findOpenDropdown ( ) ) . not . toBe ( null ) ;
151
+ createWrapper ( container ) . find ( '#focus-target' ) ! . focus ( ) ;
152
+ expect ( wrapper . findDropdown ( ) . findOpenDropdown ( ) ) . toBe ( null ) ;
164
153
} ) ;
165
154
166
155
it ( 'should warn if recoveryText is provided without associated handler' , ( ) => {
0 commit comments