@@ -270,6 +270,7 @@ describe('URL sanitization', () => {
270270 expect ( wrapper . findDownloadLink ( ) ) . toBeFalsy ( ) ;
271271 } ) ;
272272 } ) ;
273+
273274 describe ( 'a11y' , ( ) => {
274275 test ( 'task list expandable section should have aria-label joining task title and total step label' , ( ) => {
275276 const tutorials = getTutorials ( ) ;
@@ -293,5 +294,55 @@ describe('URL sanitization', () => {
293294 'LEARN_MORE_ABOUT_TUTORIA'
294295 ) ;
295296 } ) ;
297+
298+ test ( 'header has correct accessibility attributes' , ( ) => {
299+ const { container } = renderTutorialPanelWithContext ( ) ;
300+ const wrapper = createWrapper ( container ) . findTutorialPanel ( ) ! ;
301+ const headerRegion = wrapper . find ( '[role="region"]' ) ! . getElement ( ) ;
302+ expect ( headerRegion ) . toHaveAttribute ( 'tabIndex' , '-1' ) ;
303+ expect ( headerRegion ) . toHaveAttribute ( 'role' , 'region' ) ;
304+ expect ( headerRegion ) . toHaveAttribute ( 'aria-labelledby' ) ;
305+
306+ const ariaLabelledBy = headerRegion . getAttribute ( 'aria-labelledby' ) ;
307+ const headingElement = wrapper . find ( `#${ ariaLabelledBy } ` ) ! . getElement ( ) ;
308+ expect ( headingElement ) . toBeInTheDocument ( ) ;
309+ expect ( headingElement . textContent ) . toBe ( i18nStrings . tutorialListTitle ) ;
310+ } ) ;
311+
312+ test ( 'focus returns to header when exiting tutorial' , ( ) => {
313+ const mockFocus = jest . fn ( ) ;
314+ const tutorials = getTutorials ( ) ;
315+ const originalFocus = HTMLElement . prototype . focus ;
316+ HTMLElement . prototype . focus = mockFocus ;
317+
318+ const { container, context, rerender } = renderTutorialPanelWithContext (
319+ { } ,
320+ {
321+ currentTutorial : tutorials [ 0 ] ,
322+ }
323+ ) ;
324+
325+ const wrapper = createWrapper ( container ) . findTutorialPanel ( ) ! ;
326+ wrapper . findDismissButton ( ) ! . click ( ) ;
327+ expect ( context . onExitTutorial ) . toHaveBeenCalledTimes ( 1 ) ;
328+ rerender (
329+ < HotspotContext . Provider value = { { ...context , currentTutorial : null } } >
330+ < TutorialPanel
331+ i18nStrings = { i18nStrings }
332+ downloadUrl = "DOWNLOAD_URL"
333+ onFeedbackClick = { ( ) => { } }
334+ tutorials = { tutorials }
335+ />
336+ </ HotspotContext . Provider >
337+ ) ;
338+
339+ const wrapperAfterExit = createWrapper ( container ) . findTutorialPanel ( ) ! ;
340+ const headerRegion = wrapperAfterExit . find ( '[role="region"]' ) ! . getElement ( ) ;
341+
342+ expect ( mockFocus ) . toHaveBeenCalledTimes ( 1 ) ;
343+ expect ( mockFocus . mock . instances [ 0 ] ) . toBe ( headerRegion ) ;
344+
345+ HTMLElement . prototype . focus = originalFocus ;
346+ } ) ;
296347 } ) ;
297348} ) ;
0 commit comments