@@ -450,6 +450,65 @@ export class SectionPickerTests extends TestModule {
450450 clock . restore ( ) ;
451451 done ( ) ;
452452 } ) ;
453+
454+ test ( "onPopupToggle should skip hidden items inside closed notebooks when navigating with Down arrow" , ( assert : QUnitAssert ) => {
455+ let done = assert . async ( ) ;
456+ let clock = sinon . useFakeTimers ( ) ;
457+
458+ let clipperState = MockProps . getMockClipperState ( ) ;
459+ initializeClipperStorage ( undefined , undefined ) ;
460+
461+ let component = < SectionPicker onPopupToggle = { ( ) => { } } clipperState = { clipperState } /> ;
462+ let controllerInstance = MithrilUtils . mountToFixture ( component ) ;
463+
464+ // Build a structure that mirrors the OneNotePicker DOM:
465+ // sectionPickerContainer
466+ // li.Notebook.Closed (notebook1, tabindex)
467+ // ul
468+ // li.Section (hiddenSection, tabindex) -- inside closed notebook
469+ // li.Notebook.Opened (notebook2, tabindex)
470+ let sectionPickerPopup = document . createElement ( "div" ) ;
471+ sectionPickerPopup . id = "sectionPickerContainer" ;
472+
473+ let notebook1 = document . createElement ( "li" ) ;
474+ notebook1 . className = "Notebook Closed" ;
475+ notebook1 . tabIndex = 70 ;
476+ let closedChildList = document . createElement ( "ul" ) ;
477+ let hiddenSection = document . createElement ( "li" ) ;
478+ hiddenSection . className = "Section" ;
479+ hiddenSection . tabIndex = 70 ;
480+ let hiddenSectionFocusCalled = false ;
481+ hiddenSection . focus = ( ) => { hiddenSectionFocusCalled = true ; } ;
482+ closedChildList . appendChild ( hiddenSection ) ;
483+ notebook1 . appendChild ( closedChildList ) ;
484+
485+ let notebook2FocusCalled = false ;
486+ let notebook2 = document . createElement ( "li" ) ;
487+ notebook2 . className = "Notebook Opened" ;
488+ notebook2 . tabIndex = 70 ;
489+ notebook2 . focus = ( ) => { notebook2FocusCalled = true ; } ;
490+
491+ sectionPickerPopup . appendChild ( notebook1 ) ;
492+ sectionPickerPopup . appendChild ( notebook2 ) ;
493+ document . body . appendChild ( sectionPickerPopup ) ;
494+
495+ controllerInstance . onPopupToggle ( true ) ;
496+ clock . tick ( 0 ) ;
497+
498+ // Press Down arrow from notebook1 — should jump to notebook2, skipping the hidden section inside notebook1
499+ notebook1 . focus ( ) ;
500+ let downKeyEvent = document . createEvent ( "KeyboardEvent" ) ;
501+ downKeyEvent . initEvent ( "keydown" , true , true ) ;
502+ Object . defineProperty ( downKeyEvent , "which" , { value : 40 } ) ;
503+ sectionPickerPopup . dispatchEvent ( downKeyEvent ) ;
504+
505+ ok ( ! hiddenSectionFocusCalled , "Hidden section inside a closed notebook should not receive focus" ) ;
506+ ok ( notebook2FocusCalled , "Down arrow from a closed notebook should move focus to the next visible notebook" ) ;
507+
508+ document . body . removeChild ( sectionPickerPopup ) ;
509+ clock . restore ( ) ;
510+ done ( ) ;
511+ } ) ;
453512 }
454513}
455514
0 commit comments