@@ -48,15 +48,13 @@ function ToolbarWithToggle({ navigationOptions = {} }) {
48
48
49
49
describe ( 'useArrowKeyNavigation' , ( ) => {
50
50
let container ;
51
- let toolbar ;
52
51
53
52
beforeEach ( ( ) => {
54
53
container = document . createElement ( 'div' ) ;
55
54
const button = document . createElement ( 'button' ) ;
56
55
button . setAttribute ( 'data-testid' , 'outside-button' ) ;
57
56
container . append ( button ) ;
58
57
document . body . append ( container ) ;
59
- toolbar = renderToolbar ( ) ;
60
58
} ) ;
61
59
62
60
afterEach ( ( ) => {
@@ -98,6 +96,7 @@ describe('useArrowKeyNavigation', () => {
98
96
{ forwardKey : 'ArrowDown' , backKey : 'ArrowUp' } ,
99
97
] . forEach ( ( { forwardKey, backKey } ) => {
100
98
it ( 'should move focus and tab stop between elements when arrow keys are pressed' , ( ) => {
99
+ const toolbar = renderToolbar ( ) ;
101
100
const steps = [
102
101
// Test navigating forwards.
103
102
[ forwardKey , 'Italic' ] ,
@@ -381,12 +380,23 @@ describe('useArrowKeyNavigation', () => {
381
380
container ,
382
381
) ,
383
382
) ;
383
+ const toggleToolbar = ( ) => findElementByTestId ( 'toggle' ) . click ( ) ;
384
384
385
385
// No button should be initially focused
386
386
assert . equal ( document . activeElement , document . body ) ;
387
387
388
- // Once we toggle the list open , the first item will be focused
389
- findElementByTestId ( 'toggle' ) . click ( ) ;
388
+ // Once we open the toolbar , the first item will be focused
389
+ toggleToolbar ( ) ;
390
390
await waitFor ( ( ) => document . activeElement === findElementByTestId ( 'bold' ) ) ;
391
+
392
+ // If we then focus another toolbar item, then close the toolbar and open it
393
+ // again, that same element should be focused again
394
+ pressKey ( 'ArrowDown' ) ; // "italic" is focused
395
+ pressKey ( 'ArrowDown' ) ; // "underline" is focused
396
+ toggleToolbar ( ) ; // Close toolbar
397
+ toggleToolbar ( ) ; // Open toolbar again
398
+ await waitFor (
399
+ ( ) => document . activeElement === findElementByTestId ( 'underline' ) ,
400
+ ) ;
391
401
} ) ;
392
402
} ) ;
0 commit comments