@@ -491,6 +491,62 @@ describe('Key managers', () => {
491
491
expect ( keyManager . activeItem ) . toBeFalsy ( ) ;
492
492
} ) ) ;
493
493
494
+ it ( 'should start looking for matches after the active item' , fakeAsync ( ( ) => {
495
+ itemList . items = [
496
+ new FakeFocusable ( 'Bilbo' ) ,
497
+ new FakeFocusable ( 'Frodo' ) ,
498
+ new FakeFocusable ( 'Pippin' ) ,
499
+ new FakeFocusable ( 'Boromir' ) ,
500
+ new FakeFocusable ( 'Aragorn' )
501
+ ] ;
502
+
503
+ keyManager . setActiveItem ( 1 ) ;
504
+ keyManager . onKeydown ( createKeyboardEvent ( 'keydown' , 66 , undefined , 'b' ) ) ;
505
+ tick ( debounceInterval ) ;
506
+
507
+ expect ( keyManager . activeItem ) . toBe ( itemList . items [ 3 ] ) ;
508
+ } ) ) ;
509
+
510
+ it ( 'should wrap back around if there were no matches after the active item' , fakeAsync ( ( ) => {
511
+ itemList . items = [
512
+ new FakeFocusable ( 'Bilbo' ) ,
513
+ new FakeFocusable ( 'Frodo' ) ,
514
+ new FakeFocusable ( 'Pippin' ) ,
515
+ new FakeFocusable ( 'Boromir' ) ,
516
+ new FakeFocusable ( 'Aragorn' )
517
+ ] ;
518
+
519
+ keyManager . setActiveItem ( 3 ) ;
520
+ keyManager . onKeydown ( createKeyboardEvent ( 'keydown' , 66 , undefined , 'b' ) ) ;
521
+ tick ( debounceInterval ) ;
522
+
523
+ expect ( keyManager . activeItem ) . toBe ( itemList . items [ 0 ] ) ;
524
+ } ) ) ;
525
+
526
+ it ( 'should wrap back around if the last item is active' , fakeAsync ( ( ) => {
527
+ keyManager . setActiveItem ( 2 ) ;
528
+ keyManager . onKeydown ( createKeyboardEvent ( 'keydown' , 79 , undefined , 'o' ) ) ;
529
+ tick ( debounceInterval ) ;
530
+
531
+ expect ( keyManager . activeItem ) . toBe ( itemList . items [ 0 ] ) ;
532
+ } ) ) ;
533
+
534
+ it ( 'should be able to select the first item' , fakeAsync ( ( ) => {
535
+ keyManager . setActiveItem ( - 1 ) ;
536
+ keyManager . onKeydown ( createKeyboardEvent ( 'keydown' , 79 , undefined , 'o' ) ) ;
537
+ tick ( debounceInterval ) ;
538
+
539
+ expect ( keyManager . activeItem ) . toBe ( itemList . items [ 0 ] ) ;
540
+ } ) ) ;
541
+
542
+ it ( 'should not do anything if there is no match' , fakeAsync ( ( ) => {
543
+ keyManager . setActiveItem ( 1 ) ;
544
+ keyManager . onKeydown ( createKeyboardEvent ( 'keydown' , 87 , undefined , 'w' ) ) ;
545
+ tick ( debounceInterval ) ;
546
+
547
+ expect ( keyManager . activeItem ) . toBe ( itemList . items [ 1 ] ) ;
548
+ } ) ) ;
549
+
494
550
} ) ;
495
551
496
552
} ) ;
0 commit comments