@@ -60,43 +60,87 @@ describe('focus-restoration-controller', () => {
60
60
expect ( getDeepActiveElement ( ) ) . to . equal ( button2 ) ;
61
61
} ) ;
62
62
63
- it ( 'should not prevent scroll when restoring focus synchronously by default' , ( ) => {
64
- button1 . focus ( ) ;
65
- const spy = sinon . spy ( button2 , 'focus' ) ;
66
- controller . saveFocus ( button2 ) ;
67
- controller . restoreFocus ( ) ;
68
- expect ( spy ) . to . be . calledOnce ;
69
- expect ( spy . firstCall . args [ 0 ] ) . to . eql ( { preventScroll : false } ) ;
70
- } ) ;
63
+ describe ( 'preventScroll' , ( ) => {
64
+ it ( 'should not prevent scroll when restoring focus synchronously by default' , ( ) => {
65
+ button1 . focus ( ) ;
66
+ const spy = sinon . spy ( button2 , 'focus' ) ;
67
+ controller . saveFocus ( button2 ) ;
68
+ controller . restoreFocus ( ) ;
69
+ expect ( spy ) . to . be . calledOnce ;
70
+ expect ( spy . firstCall . args [ 0 ] ) . to . deep . include ( { preventScroll : false } ) ;
71
+ } ) ;
71
72
72
- it ( 'should prevent scroll when restoring focus synchronously with preventScroll' , ( ) => {
73
- button1 . focus ( ) ;
74
- const spy = sinon . spy ( button2 , 'focus' ) ;
75
- controller . saveFocus ( button2 ) ;
76
- controller . restoreFocus ( { preventScroll : true } ) ;
77
- expect ( spy ) . to . be . calledOnce ;
78
- expect ( spy . firstCall . args [ 0 ] ) . to . eql ( { preventScroll : true } ) ;
79
- } ) ;
73
+ it ( 'should prevent scroll when restoring focus synchronously with preventScroll' , ( ) => {
74
+ button1 . focus ( ) ;
75
+ const spy = sinon . spy ( button2 , 'focus' ) ;
76
+ controller . saveFocus ( button2 ) ;
77
+ controller . restoreFocus ( { preventScroll : true } ) ;
78
+ expect ( spy ) . to . be . calledOnce ;
79
+ expect ( spy . firstCall . args [ 0 ] ) . to . deep . include ( { preventScroll : true } ) ;
80
+ } ) ;
80
81
81
- it ( 'should not prevent scroll when restoring focus asynchronously by default' , async ( ) => {
82
- button1 . focus ( ) ;
83
- const spy = sinon . spy ( button2 , 'focus' ) ;
84
- controller . saveFocus ( button2 ) ;
85
- outsideClick ( ) ;
86
- controller . restoreFocus ( ) ;
87
- await aTimeout ( 0 ) ;
88
- expect ( spy ) . to . be . calledOnce ;
89
- expect ( spy . firstCall . args [ 0 ] ) . to . eql ( { preventScroll : false } ) ;
82
+ it ( 'should not prevent scroll when restoring focus asynchronously by default' , async ( ) => {
83
+ button1 . focus ( ) ;
84
+ const spy = sinon . spy ( button2 , 'focus' ) ;
85
+ controller . saveFocus ( button2 ) ;
86
+ outsideClick ( ) ;
87
+ controller . restoreFocus ( ) ;
88
+ await aTimeout ( 0 ) ;
89
+ expect ( spy ) . to . be . calledOnce ;
90
+ expect ( spy . firstCall . args [ 0 ] ) . to . deep . include ( { preventScroll : false } ) ;
91
+ } ) ;
92
+
93
+ it ( 'should prevent scroll when restoring focus asynchronously with preventScroll' , async ( ) => {
94
+ button1 . focus ( ) ;
95
+ const spy = sinon . spy ( button2 , 'focus' ) ;
96
+ controller . saveFocus ( button2 ) ;
97
+ outsideClick ( ) ;
98
+ controller . restoreFocus ( { preventScroll : true } ) ;
99
+ await aTimeout ( 0 ) ;
100
+ expect ( spy ) . to . be . calledOnce ;
101
+ expect ( spy . firstCall . args [ 0 ] ) . to . deep . include ( { preventScroll : true } ) ;
102
+ } ) ;
90
103
} ) ;
91
104
92
- it ( 'should prevent scroll when restoring focus asynchronously with preventScroll' , async ( ) => {
93
- button1 . focus ( ) ;
94
- const spy = sinon . spy ( button2 , 'focus' ) ;
95
- controller . saveFocus ( button2 ) ;
96
- outsideClick ( ) ;
97
- controller . restoreFocus ( { preventScroll : true } ) ;
98
- await aTimeout ( 0 ) ;
99
- expect ( spy ) . to . be . calledOnce ;
100
- expect ( spy . firstCall . args [ 0 ] ) . to . eql ( { preventScroll : true } ) ;
105
+ describe ( 'focusVisible' , ( ) => {
106
+ it ( 'should not set focusVisible when restoring focus synchronously by default' , ( ) => {
107
+ button1 . focus ( ) ;
108
+ const spy = sinon . spy ( button2 , 'focus' ) ;
109
+ controller . saveFocus ( button2 ) ;
110
+ controller . restoreFocus ( ) ;
111
+ expect ( spy ) . to . be . calledOnce ;
112
+ expect ( spy . firstCall . args [ 0 ] ) . to . deep . include ( { focusVisible : false } ) ;
113
+ } ) ;
114
+
115
+ it ( 'should set focusVisible when restoring focus synchronously with focusVisible' , ( ) => {
116
+ button1 . focus ( ) ;
117
+ const spy = sinon . spy ( button2 , 'focus' ) ;
118
+ controller . saveFocus ( button2 ) ;
119
+ controller . restoreFocus ( { focusVisible : true } ) ;
120
+ expect ( spy ) . to . be . calledOnce ;
121
+ expect ( spy . firstCall . args [ 0 ] ) . to . deep . include ( { focusVisible : true } ) ;
122
+ } ) ;
123
+
124
+ it ( 'should not set focusVisible when restoring focus asynchronously by default' , async ( ) => {
125
+ button1 . focus ( ) ;
126
+ const spy = sinon . spy ( button2 , 'focus' ) ;
127
+ controller . saveFocus ( button2 ) ;
128
+ outsideClick ( ) ;
129
+ controller . restoreFocus ( ) ;
130
+ await aTimeout ( 0 ) ;
131
+ expect ( spy ) . to . be . calledOnce ;
132
+ expect ( spy . firstCall . args [ 0 ] ) . to . deep . include ( { focusVisible : false } ) ;
133
+ } ) ;
134
+
135
+ it ( 'should set focusVisible when restoring focus asynchronously with focusVisible' , async ( ) => {
136
+ button1 . focus ( ) ;
137
+ const spy = sinon . spy ( button2 , 'focus' ) ;
138
+ controller . saveFocus ( button2 ) ;
139
+ outsideClick ( ) ;
140
+ controller . restoreFocus ( { focusVisible : true } ) ;
141
+ await aTimeout ( 0 ) ;
142
+ expect ( spy ) . to . be . calledOnce ;
143
+ expect ( spy . firstCall . args [ 0 ] ) . to . deep . include ( { focusVisible : true } ) ;
144
+ } ) ;
101
145
} ) ;
102
146
} ) ;
0 commit comments