7
7
* @flow
8
8
*/
9
9
10
- import { createEventTarget } from 'react-interactions/events/src/dom/testing-library' ;
10
+ import { createEventTarget } from 'react-interactions/events/src/dom/event- testing-library' ;
11
11
12
12
let React ;
13
13
let ReactFeatureFlags ;
14
14
let FocusContain ;
15
15
let tabbableScopeQuery ;
16
16
17
+ function tabNext ( target ) {
18
+ target . keydown ( { key : 'Tab' } ) ;
19
+ target . keyup ( { key : 'Tab' } ) ;
20
+ }
21
+
22
+ function tabPrevious ( target ) {
23
+ target . keydown ( { key : 'Tab' , shiftKey : true } ) ;
24
+ target . keyup ( { key : 'Tab' , shiftKey : true } ) ;
25
+ }
26
+
17
27
describe ( 'FocusContain' , ( ) => {
18
28
beforeEach ( ( ) => {
19
29
jest . resetModules ( ) ;
@@ -59,13 +69,13 @@ describe('FocusContain', () => {
59
69
60
70
ReactDOM . render ( < Test /> , container ) ;
61
71
expect ( document . activeElement ) . toBe ( inputRef . current ) ;
62
- createEventTarget ( document . activeElement ) . tabNext ( ) ;
72
+ tabNext ( createEventTarget ( document . activeElement ) ) ;
63
73
expect ( document . activeElement ) . toBe ( buttonRef . current ) ;
64
- createEventTarget ( document . activeElement ) . tabNext ( ) ;
74
+ tabNext ( createEventTarget ( document . activeElement ) ) ;
65
75
expect ( document . activeElement ) . toBe ( divRef . current ) ;
66
- createEventTarget ( document . activeElement ) . tabNext ( ) ;
76
+ tabNext ( createEventTarget ( document . activeElement ) ) ;
67
77
expect ( document . activeElement ) . toBe ( button2Ref . current ) ;
68
- createEventTarget ( document . activeElement ) . tabPrevious ( ) ;
78
+ tabPrevious ( createEventTarget ( document . activeElement ) ) ;
69
79
expect ( document . activeElement ) . toBe ( divRef . current ) ;
70
80
} ) ;
71
81
@@ -90,15 +100,15 @@ describe('FocusContain', () => {
90
100
91
101
ReactDOM . render ( < Test /> , container ) ;
92
102
buttonRef . current . focus ( ) ;
93
- createEventTarget ( document . activeElement ) . tabNext ( ) ;
103
+ tabNext ( createEventTarget ( document . activeElement ) ) ;
94
104
expect ( document . activeElement ) . toBe ( button2Ref . current ) ;
95
- createEventTarget ( document . activeElement ) . tabNext ( ) ;
105
+ tabNext ( createEventTarget ( document . activeElement ) ) ;
96
106
expect ( document . activeElement ) . toBe ( buttonRef . current ) ;
97
- createEventTarget ( document . activeElement ) . tabNext ( ) ;
107
+ tabNext ( createEventTarget ( document . activeElement ) ) ;
98
108
expect ( document . activeElement ) . toBe ( button2Ref . current ) ;
99
- createEventTarget ( document . activeElement ) . tabPrevious ( ) ;
109
+ tabPrevious ( createEventTarget ( document . activeElement ) ) ;
100
110
expect ( document . activeElement ) . toBe ( buttonRef . current ) ;
101
- createEventTarget ( document . activeElement ) . tabPrevious ( ) ;
111
+ tabPrevious ( createEventTarget ( document . activeElement ) ) ;
102
112
expect ( document . activeElement ) . toBe ( button2Ref . current ) ;
103
113
// Focus should be restored to the contained area
104
114
const rAF = window . requestAnimationFrame ;
@@ -132,15 +142,15 @@ describe('FocusContain', () => {
132
142
133
143
ReactDOM . render ( < Test /> , container ) ;
134
144
expect ( document . activeElement ) . toBe ( buttonRef . current ) ;
135
- createEventTarget ( document . activeElement ) . tabNext ( ) ;
145
+ tabNext ( createEventTarget ( document . activeElement ) ) ;
136
146
expect ( document . activeElement ) . toBe ( button2Ref . current ) ;
137
- createEventTarget ( document . activeElement ) . tabNext ( ) ;
147
+ tabNext ( createEventTarget ( document . activeElement ) ) ;
138
148
expect ( document . activeElement ) . toBe ( button3Ref . current ) ;
139
- createEventTarget ( document . activeElement ) . tabNext ( ) ;
149
+ tabNext ( createEventTarget ( document . activeElement ) ) ;
140
150
expect ( document . activeElement ) . toBe ( button4Ref . current ) ;
141
- createEventTarget ( document . activeElement ) . tabPrevious ( ) ;
151
+ tabPrevious ( createEventTarget ( document . activeElement ) ) ;
142
152
expect ( document . activeElement ) . toBe ( button3Ref . current ) ;
143
- createEventTarget ( document . activeElement ) . tabPrevious ( ) ;
153
+ tabPrevious ( createEventTarget ( document . activeElement ) ) ;
144
154
expect ( document . activeElement ) . toBe ( button2Ref . current ) ;
145
155
} ) ;
146
156
@@ -167,13 +177,13 @@ describe('FocusContain', () => {
167
177
168
178
ReactDOM . render ( < Test /> , container ) ;
169
179
expect ( document . activeElement ) . toBe ( button2Ref . current ) ;
170
- createEventTarget ( document . activeElement ) . tabNext ( ) ;
180
+ tabNext ( createEventTarget ( document . activeElement ) ) ;
171
181
expect ( document . activeElement ) . toBe ( button3Ref . current ) ;
172
- createEventTarget ( document . activeElement ) . tabNext ( ) ;
182
+ tabNext ( createEventTarget ( document . activeElement ) ) ;
173
183
expect ( document . activeElement ) . toBe ( button2Ref . current ) ;
174
- createEventTarget ( document . activeElement ) . tabPrevious ( ) ;
184
+ tabPrevious ( createEventTarget ( document . activeElement ) ) ;
175
185
expect ( document . activeElement ) . toBe ( button3Ref . current ) ;
176
- createEventTarget ( document . activeElement ) . tabPrevious ( ) ;
186
+ tabPrevious ( createEventTarget ( document . activeElement ) ) ;
177
187
expect ( document . activeElement ) . toBe ( button2Ref . current ) ;
178
188
} ) ;
179
189
@@ -213,15 +223,15 @@ describe('FocusContain', () => {
213
223
ReactDOM . render ( < Test /> , container ) ;
214
224
buttonRef . current . focus ( ) ;
215
225
expect ( document . activeElement ) . toBe ( buttonRef . current ) ;
216
- createEventTarget ( document . activeElement ) . tabNext ( ) ;
226
+ tabNext ( createEventTarget ( document . activeElement ) ) ;
217
227
expect ( document . activeElement ) . toBe ( button2Ref . current ) ;
218
- createEventTarget ( document . activeElement ) . tabNext ( ) ;
228
+ tabNext ( createEventTarget ( document . activeElement ) ) ;
219
229
expect ( document . activeElement ) . toBe ( button3Ref . current ) ;
220
- createEventTarget ( document . activeElement ) . tabNext ( ) ;
230
+ tabNext ( createEventTarget ( document . activeElement ) ) ;
221
231
expect ( document . activeElement ) . toBe ( button4Ref . current ) ;
222
- createEventTarget ( document . activeElement ) . tabPrevious ( ) ;
232
+ tabPrevious ( createEventTarget ( document . activeElement ) ) ;
223
233
expect ( document . activeElement ) . toBe ( button3Ref . current ) ;
224
- createEventTarget ( document . activeElement ) . tabPrevious ( ) ;
234
+ tabPrevious ( createEventTarget ( document . activeElement ) ) ;
225
235
expect ( document . activeElement ) . toBe ( button2Ref . current ) ;
226
236
} ) ;
227
237
} ) ;
0 commit comments