@@ -9,6 +9,8 @@ import CvSideNavItems from '../CvSideNavItems.vue';
9
9
import CvSideNavMenu from '../CvSideNavMenu.vue' ;
10
10
import CvSideNavMenuItem from '../CvSideNavMenuItem.vue' ;
11
11
import CvSideNavLink from '../CvSideNavLink.vue' ;
12
+ import PanelFocusTestComponent from './PanelFocusTestComponent.vue' ;
13
+ import { nextTick } from 'vue' ;
12
14
13
15
const globalHeader = {
14
16
components : { CvHeaderGlobalAction } ,
@@ -101,6 +103,52 @@ describe('CvHeader', () => {
101
103
expect ( onResize . mock . calls . length ) . toBe ( 2 ) ;
102
104
} ) ;
103
105
106
+ it ( 'should allow user to focus between elements in the right panel' , async ( ) => {
107
+ const user = userEvent . setup ( ) ;
108
+ const component = render ( PanelFocusTestComponent ) ;
109
+
110
+ const testPanel = await component . findByTestId ( 'links-panel' ) ;
111
+ expect ( testPanel . getAttribute ( 'aria-hidden' ) ) . toBe ( 'true' ) ; // panel is closed
112
+
113
+ const actionButton = await component . findByTestId ( 'action-button' ) ;
114
+ await user . click ( actionButton ) ;
115
+
116
+ expect ( testPanel . getAttribute ( 'aria-hidden' ) ) . toBe ( 'false' ) ; // panel is open
117
+
118
+ const link1 = await component . findByTestId ( 'link-1' ) ;
119
+ const link2 = await component . findByTestId ( 'link-2' ) ;
120
+
121
+ link1 . focus ( ) ;
122
+ expect ( testPanel . getAttribute ( 'aria-hidden' ) ) . toBe ( 'false' ) ;
123
+
124
+ link2 . focus ( ) ;
125
+ expect ( testPanel . getAttribute ( 'aria-hidden' ) ) . toBe ( 'false' ) ;
126
+ } ) ;
127
+
128
+ it ( 'should close the right panel when focusing out of its elements' , async ( ) => {
129
+ const user = userEvent . setup ( ) ;
130
+ const component = render ( PanelFocusTestComponent ) ;
131
+
132
+ const testPanel = await component . findByTestId ( 'links-panel' ) ;
133
+ expect ( testPanel . getAttribute ( 'aria-hidden' ) ) . toBe ( 'true' ) ; // panel is closed
134
+
135
+ const actionButton = await component . findByTestId ( 'action-button' ) ;
136
+ await user . click ( actionButton ) ;
137
+
138
+ expect ( testPanel . getAttribute ( 'aria-hidden' ) ) . toBe ( 'false' ) ; // panel is open
139
+
140
+ const link1 = await component . findByTestId ( 'link-1' ) ;
141
+ link1 . focus ( ) ;
142
+ expect ( testPanel . getAttribute ( 'aria-hidden' ) ) . toBe ( 'false' ) ;
143
+
144
+ const outerInput = await component . findByTestId ( 'outer-input' ) ;
145
+ outerInput . focus ( ) ;
146
+
147
+ await nextTick ( ) ;
148
+
149
+ expect ( testPanel . getAttribute ( 'aria-hidden' ) ) . toBe ( 'true' ) ; // panel is closed
150
+ } ) ;
151
+
104
152
it ( 'CvHeader - side nav rail' , async ( ) => {
105
153
const result = render ( CvHeader , {
106
154
slots : {
0 commit comments