@@ -370,6 +370,86 @@ export class SectionPickerTests extends TestModule {
370370 clock . restore ( ) ;
371371 done ( ) ;
372372 } ) ;
373+
374+ test ( "onPopupToggle should enable Down arrow key to move focus to the next item in the popup" , ( assert : QUnitAssert ) => {
375+ let done = assert . async ( ) ;
376+ let clock = sinon . useFakeTimers ( ) ;
377+
378+ let clipperState = MockProps . getMockClipperState ( ) ;
379+ initializeClipperStorage ( undefined , undefined ) ;
380+
381+ let component = < SectionPicker onPopupToggle = { ( ) => { } } clipperState = { clipperState } /> ;
382+ let controllerInstance = MithrilUtils . mountToFixture ( component ) ;
383+
384+ // Create a fake popup with two items
385+ let sectionPickerPopup = document . createElement ( "div" ) ;
386+ sectionPickerPopup . id = "sectionPickerContainer" ;
387+ let firstItem = document . createElement ( "li" ) ;
388+ firstItem . tabIndex = 70 ;
389+ let secondItemFocusCalled = false ;
390+ let secondItem = document . createElement ( "li" ) ;
391+ secondItem . tabIndex = 70 ;
392+ secondItem . focus = ( ) => { secondItemFocusCalled = true ; } ;
393+ sectionPickerPopup . appendChild ( firstItem ) ;
394+ sectionPickerPopup . appendChild ( secondItem ) ;
395+ document . body . appendChild ( sectionPickerPopup ) ;
396+
397+ controllerInstance . onPopupToggle ( true ) ;
398+ clock . tick ( 0 ) ;
399+
400+ // Simulate focus on first item and press Down arrow
401+ firstItem . focus ( ) ;
402+ let downKeyEvent = document . createEvent ( "KeyboardEvent" ) ;
403+ downKeyEvent . initEvent ( "keydown" , true , true ) ;
404+ Object . defineProperty ( downKeyEvent , "which" , { value : 40 } ) ;
405+ sectionPickerPopup . dispatchEvent ( downKeyEvent ) ;
406+
407+ ok ( secondItemFocusCalled , "Down arrow key should move focus to the next item in the popup" ) ;
408+
409+ document . body . removeChild ( sectionPickerPopup ) ;
410+ clock . restore ( ) ;
411+ done ( ) ;
412+ } ) ;
413+
414+ test ( "onPopupToggle should enable Up arrow key to move focus to the previous item in the popup" , ( assert : QUnitAssert ) => {
415+ let done = assert . async ( ) ;
416+ let clock = sinon . useFakeTimers ( ) ;
417+
418+ let clipperState = MockProps . getMockClipperState ( ) ;
419+ initializeClipperStorage ( undefined , undefined ) ;
420+
421+ let component = < SectionPicker onPopupToggle = { ( ) => { } } clipperState = { clipperState } /> ;
422+ let controllerInstance = MithrilUtils . mountToFixture ( component ) ;
423+
424+ // Create a fake popup with two items
425+ let sectionPickerPopup = document . createElement ( "div" ) ;
426+ sectionPickerPopup . id = "sectionPickerContainer" ;
427+ let firstItemFocusCalled = false ;
428+ let firstItem = document . createElement ( "li" ) ;
429+ firstItem . tabIndex = 70 ;
430+ firstItem . focus = ( ) => { firstItemFocusCalled = true ; } ;
431+ let secondItem = document . createElement ( "li" ) ;
432+ secondItem . tabIndex = 70 ;
433+ sectionPickerPopup . appendChild ( firstItem ) ;
434+ sectionPickerPopup . appendChild ( secondItem ) ;
435+ document . body . appendChild ( sectionPickerPopup ) ;
436+
437+ controllerInstance . onPopupToggle ( true ) ;
438+ clock . tick ( 0 ) ;
439+
440+ // Simulate focus on second item and press Up arrow
441+ secondItem . focus ( ) ;
442+ let upKeyEvent = document . createEvent ( "KeyboardEvent" ) ;
443+ upKeyEvent . initEvent ( "keydown" , true , true ) ;
444+ Object . defineProperty ( upKeyEvent , "which" , { value : 38 } ) ;
445+ sectionPickerPopup . dispatchEvent ( upKeyEvent ) ;
446+
447+ ok ( firstItemFocusCalled , "Up arrow key should move focus to the previous item in the popup" ) ;
448+
449+ document . body . removeChild ( sectionPickerPopup ) ;
450+ clock . restore ( ) ;
451+ done ( ) ;
452+ } ) ;
373453 }
374454}
375455
0 commit comments