@@ -526,6 +526,9 @@ describe('Tab', () => {
526
526
const spyShow1 = spyOn ( tab1 , 'show' ) . and . callThrough ( )
527
527
const spyShow2 = spyOn ( tab2 , 'show' ) . and . callThrough ( )
528
528
const spyShow3 = spyOn ( tab3 , 'show' ) . and . callThrough ( )
529
+ const spyFocus1 = spyOn ( tabEl1 , 'focus' ) . and . callThrough ( )
530
+ const spyFocus2 = spyOn ( tabEl2 , 'focus' ) . and . callThrough ( )
531
+ const spyFocus3 = spyOn ( tabEl3 , 'focus' ) . and . callThrough ( )
529
532
530
533
const spyStop = spyOn ( Event . prototype , 'stopPropagation' ) . and . callThrough ( )
531
534
const spyPrevent = spyOn ( Event . prototype , 'preventDefault' ) . and . callThrough ( )
@@ -535,15 +538,18 @@ describe('Tab', () => {
535
538
536
539
tabEl1 . dispatchEvent ( keydown )
537
540
expect ( spyShow2 ) . toHaveBeenCalled ( )
541
+ expect ( spyFocus2 ) . toHaveBeenCalled ( )
538
542
539
543
keydown = createEvent ( 'keydown' )
540
544
keydown . key = 'ArrowDown'
541
545
542
546
tabEl2 . dispatchEvent ( keydown )
543
547
expect ( spyShow3 ) . toHaveBeenCalled ( )
548
+ expect ( spyFocus3 ) . toHaveBeenCalled ( )
544
549
545
550
tabEl3 . dispatchEvent ( keydown )
546
551
expect ( spyShow1 ) . toHaveBeenCalled ( )
552
+ expect ( spyFocus1 ) . toHaveBeenCalled ( )
547
553
548
554
expect ( spyStop ) . toHaveBeenCalledTimes ( 3 )
549
555
expect ( spyPrevent ) . toHaveBeenCalledTimes ( 3 )
@@ -557,12 +563,14 @@ describe('Tab', () => {
557
563
'</div>'
558
564
] . join ( '' )
559
565
560
- const tabEl = fixtureEl . querySelector ( '#tab1' )
566
+ const tabEl1 = fixtureEl . querySelector ( '#tab1' )
561
567
const tabEl2 = fixtureEl . querySelector ( '#tab2' )
562
- const tab = new Tab ( tabEl )
568
+ const tab1 = new Tab ( tabEl1 )
563
569
const tab2 = new Tab ( tabEl2 )
564
- const spyShow1 = spyOn ( tab , 'show' ) . and . callThrough ( )
570
+ const spyShow1 = spyOn ( tab1 , 'show' ) . and . callThrough ( )
565
571
const spyShow2 = spyOn ( tab2 , 'show' ) . and . callThrough ( )
572
+ const spyFocus1 = spyOn ( tabEl1 , 'focus' ) . and . callThrough ( )
573
+ const spyFocus2 = spyOn ( tabEl2 , 'focus' ) . and . callThrough ( )
566
574
567
575
const spyStop = spyOn ( Event . prototype , 'stopPropagation' ) . and . callThrough ( )
568
576
const spyPrevent = spyOn ( Event . prototype , 'preventDefault' ) . and . callThrough ( )
@@ -572,12 +580,14 @@ describe('Tab', () => {
572
580
573
581
tabEl2 . dispatchEvent ( keydown )
574
582
expect ( spyShow1 ) . toHaveBeenCalled ( )
583
+ expect ( spyFocus1 ) . toHaveBeenCalled ( )
575
584
576
585
keydown = createEvent ( 'keydown' )
577
586
keydown . key = 'ArrowUp'
578
587
579
- tabEl . dispatchEvent ( keydown )
588
+ tabEl1 . dispatchEvent ( keydown )
580
589
expect ( spyShow2 ) . toHaveBeenCalled ( )
590
+ expect ( spyFocus2 ) . toHaveBeenCalled ( )
581
591
582
592
expect ( spyStop ) . toHaveBeenCalledTimes ( 2 )
583
593
expect ( spyPrevent ) . toHaveBeenCalledTimes ( 2 )
@@ -605,6 +615,10 @@ describe('Tab', () => {
605
615
const spy2 = spyOn ( tab2 , 'show' ) . and . callThrough ( )
606
616
const spy3 = spyOn ( tab3 , 'show' ) . and . callThrough ( )
607
617
const spy4 = spyOn ( tab4 , 'show' ) . and . callThrough ( )
618
+ const spyFocus1 = spyOn ( tabEl , 'focus' ) . and . callThrough ( )
619
+ const spyFocus2 = spyOn ( tabEl2 , 'focus' ) . and . callThrough ( )
620
+ const spyFocus3 = spyOn ( tabEl3 , 'focus' ) . and . callThrough ( )
621
+ const spyFocus4 = spyOn ( tabEl4 , 'focus' ) . and . callThrough ( )
608
622
609
623
const keydown = createEvent ( 'keydown' )
610
624
keydown . key = 'ArrowRight'
@@ -614,6 +628,10 @@ describe('Tab', () => {
614
628
expect ( spy2 ) . not . toHaveBeenCalled ( )
615
629
expect ( spy3 ) . not . toHaveBeenCalled ( )
616
630
expect ( spy4 ) . toHaveBeenCalledTimes ( 1 )
631
+ expect ( spyFocus1 ) . not . toHaveBeenCalled ( )
632
+ expect ( spyFocus2 ) . not . toHaveBeenCalled ( )
633
+ expect ( spyFocus3 ) . not . toHaveBeenCalled ( )
634
+ expect ( spyFocus4 ) . toHaveBeenCalledTimes ( 1 )
617
635
} )
618
636
619
637
it ( 'if keydown event is left arrow and next element is disabled' , ( ) => {
@@ -638,6 +656,10 @@ describe('Tab', () => {
638
656
const spy2 = spyOn ( tab2 , 'show' ) . and . callThrough ( )
639
657
const spy3 = spyOn ( tab3 , 'show' ) . and . callThrough ( )
640
658
const spy4 = spyOn ( tab4 , 'show' ) . and . callThrough ( )
659
+ const spyFocus1 = spyOn ( tabEl , 'focus' ) . and . callThrough ( )
660
+ const spyFocus2 = spyOn ( tabEl2 , 'focus' ) . and . callThrough ( )
661
+ const spyFocus3 = spyOn ( tabEl3 , 'focus' ) . and . callThrough ( )
662
+ const spyFocus4 = spyOn ( tabEl4 , 'focus' ) . and . callThrough ( )
641
663
642
664
const keydown = createEvent ( 'keydown' )
643
665
keydown . key = 'ArrowLeft'
@@ -647,6 +669,10 @@ describe('Tab', () => {
647
669
expect ( spy3 ) . not . toHaveBeenCalled ( )
648
670
expect ( spy2 ) . not . toHaveBeenCalled ( )
649
671
expect ( spy1 ) . toHaveBeenCalledTimes ( 1 )
672
+ expect ( spyFocus4 ) . not . toHaveBeenCalled ( )
673
+ expect ( spyFocus3 ) . not . toHaveBeenCalled ( )
674
+ expect ( spyFocus2 ) . not . toHaveBeenCalled ( )
675
+ expect ( spyFocus1 ) . toHaveBeenCalledTimes ( 1 )
650
676
} )
651
677
} )
652
678
0 commit comments