@@ -882,6 +882,72 @@ export class SectionPickerSinonTests extends TestModule {
882882 done ( ) ;
883883 } ) ;
884884 } ) ;
885+
886+ test ( "onPopupToggle should move focus to first tree item when dropdown opens" , ( assert : QUnitAssert ) => {
887+ let done = assert . async ( ) ;
888+
889+ let clipperState = MockProps . getMockClipperState ( ) ;
890+ let mockNotebooks = MockProps . getMockNotebooks ( ) ;
891+ initializeClipperStorage ( JSON . stringify ( mockNotebooks ) , undefined , TestConstants . defaultUserInfoAsJsonString ) ;
892+
893+ let popupToggled = false ;
894+ let component = < SectionPicker
895+ onPopupToggle = { ( shouldNowBeOpen : boolean ) => { popupToggled = shouldNowBeOpen ; } }
896+ clipperState = { clipperState } /> ;
897+ let controllerInstance = MithrilUtils . mountToFixture ( component ) ;
898+
899+ // Open the dropdown
900+ MithrilUtils . simulateAction ( ( ) => {
901+ document . getElementById ( TestConstants . Ids . sectionLocationContainer ) . click ( ) ;
902+ } ) ;
903+
904+ // Wait for requestAnimationFrame to complete
905+ requestAnimationFrame ( ( ) => {
906+ let notebookList = document . getElementById ( "notebookList" ) ;
907+ ok ( notebookList , "Notebook list should be present when dropdown is open" ) ;
908+ if ( notebookList ) {
909+ let firstTreeItem = notebookList . querySelector ( "li[role='treeitem']" ) as HTMLElement ;
910+ ok ( firstTreeItem , "First tree item should exist in the notebook list" ) ;
911+ }
912+ ok ( popupToggled , "onPopupToggle should have been called with true" ) ;
913+ done ( ) ;
914+ } ) ;
915+ } ) ;
916+
917+ test ( "onPopupToggle should call onPopupToggle prop with false when dropdown closes" , ( assert : QUnitAssert ) => {
918+ let done = assert . async ( ) ;
919+
920+ let clipperState = MockProps . getMockClipperState ( ) ;
921+ let mockNotebooks = MockProps . getMockNotebooks ( ) ;
922+ let mockSection = {
923+ section : mockNotebooks [ 0 ] . sections [ 0 ] ,
924+ path : "Clipper Test > Full Page" ,
925+ parentId : mockNotebooks [ 0 ] . id
926+ } ;
927+ initializeClipperStorage ( JSON . stringify ( mockNotebooks ) , JSON . stringify ( mockSection ) , TestConstants . defaultUserInfoAsJsonString ) ;
928+
929+ let lastPopupState : boolean ;
930+ let component = < SectionPicker
931+ onPopupToggle = { ( shouldNowBeOpen : boolean ) => { lastPopupState = shouldNowBeOpen ; } }
932+ clipperState = { clipperState } /> ;
933+ let controllerInstance = MithrilUtils . mountToFixture ( component ) ;
934+
935+ // Open the dropdown first
936+ MithrilUtils . simulateAction ( ( ) => {
937+ document . getElementById ( TestConstants . Ids . sectionLocationContainer ) . click ( ) ;
938+ } ) ;
939+
940+ // Close the dropdown by clicking again
941+ MithrilUtils . simulateAction ( ( ) => {
942+ document . getElementById ( TestConstants . Ids . sectionLocationContainer ) . click ( ) ;
943+ } ) ;
944+
945+ // Wait for requestAnimationFrame to complete
946+ requestAnimationFrame ( ( ) => {
947+ strictEqual ( lastPopupState , false , "onPopupToggle should have been called with false when dropdown closes" ) ;
948+ done ( ) ;
949+ } ) ;
950+ } ) ;
885951 }
886952}
887953
0 commit comments