@@ -93,7 +93,7 @@ describe('MatButtonToggle with forms', () => {
93
93
buttonToggleDebugElements = fixture . debugElement . queryAll ( By . directive ( MatButtonToggle ) ) ;
94
94
buttonToggleInstances = buttonToggleDebugElements . map ( debugEl => debugEl . componentInstance ) ;
95
95
buttonToggleLabels = buttonToggleDebugElements . map (
96
- debugEl => debugEl . query ( By . css ( 'label ' ) ) . nativeElement ) ;
96
+ debugEl => debugEl . query ( By . css ( 'button ' ) ) . nativeElement ) ;
97
97
98
98
fixture . detectChanges ( ) ;
99
99
} ) ) ;
@@ -243,7 +243,7 @@ describe('MatButtonToggle without forms', () => {
243
243
buttonToggleNativeElements = buttonToggleDebugElements
244
244
. map ( debugEl => debugEl . nativeElement ) ;
245
245
246
- buttonToggleLabelElements = fixture . debugElement . queryAll ( By . css ( 'label ' ) )
246
+ buttonToggleLabelElements = fixture . debugElement . queryAll ( By . css ( 'button ' ) )
247
247
. map ( debugEl => debugEl . nativeElement ) ;
248
248
249
249
buttonToggleInstances = buttonToggleDebugElements . map ( debugEl => debugEl . componentInstance ) ;
@@ -338,7 +338,7 @@ describe('MatButtonToggle without forms', () => {
338
338
buttonToggleLabelElements [ 0 ] . click ( ) ;
339
339
fixture . detectChanges ( ) ;
340
340
tick ( ) ;
341
- expect ( changeSpy ) . toHaveBeenCalled ( ) ;
341
+ expect ( changeSpy ) . toHaveBeenCalledTimes ( 1 ) ;
342
342
343
343
buttonToggleLabelElements [ 0 ] . click ( ) ;
344
344
fixture . detectChanges ( ) ;
@@ -446,7 +446,7 @@ describe('MatButtonToggle without forms', () => {
446
446
buttonToggleDebugElements = fixture . debugElement . queryAll ( By . directive ( MatButtonToggle ) ) ;
447
447
buttonToggleNativeElements = buttonToggleDebugElements
448
448
. map ( debugEl => debugEl . nativeElement ) ;
449
- buttonToggleLabelElements = fixture . debugElement . queryAll ( By . css ( 'label ' ) )
449
+ buttonToggleLabelElements = fixture . debugElement . queryAll ( By . css ( 'button ' ) )
450
450
. map ( debugEl => debugEl . nativeElement ) ;
451
451
buttonToggleInstances = buttonToggleDebugElements . map ( debugEl => debugEl . componentInstance ) ;
452
452
} ) ) ;
@@ -462,7 +462,7 @@ describe('MatButtonToggle without forms', () => {
462
462
it ( 'should check a button toggle when clicked' , ( ) => {
463
463
expect ( buttonToggleInstances . every ( buttonToggle => ! buttonToggle . checked ) ) . toBe ( true ) ;
464
464
465
- let nativeCheckboxLabel = buttonToggleDebugElements [ 0 ] . query ( By . css ( 'label ' ) ) . nativeElement ;
465
+ let nativeCheckboxLabel = buttonToggleDebugElements [ 0 ] . query ( By . css ( 'button ' ) ) . nativeElement ;
466
466
467
467
nativeCheckboxLabel . click ( ) ;
468
468
@@ -486,9 +486,9 @@ describe('MatButtonToggle without forms', () => {
486
486
} ) ;
487
487
488
488
it ( 'should check a button toggle upon interaction with underlying native checkbox' , ( ) => {
489
- let nativeCheckboxInput = buttonToggleDebugElements [ 0 ] . query ( By . css ( 'input ' ) ) . nativeElement ;
489
+ let nativeCheckboxButton = buttonToggleDebugElements [ 0 ] . query ( By . css ( 'button ' ) ) . nativeElement ;
490
490
491
- nativeCheckboxInput . click ( ) ;
491
+ nativeCheckboxButton . click ( ) ;
492
492
fixture . detectChanges ( ) ;
493
493
494
494
expect ( groupInstance . value ) . toEqual ( [ 'eggs' ] ) ;
@@ -568,7 +568,8 @@ describe('MatButtonToggle without forms', () => {
568
568
569
569
buttonToggleDebugElement = fixture . debugElement . query ( By . directive ( MatButtonToggle ) ) ;
570
570
buttonToggleNativeElement = buttonToggleDebugElement . nativeElement ;
571
- buttonToggleLabelElement = fixture . debugElement . query ( By . css ( 'label' ) ) . nativeElement ;
571
+ buttonToggleLabelElement = fixture . debugElement
572
+ . query ( By . css ( '.mat-button-toggle-label-content' ) ) . nativeElement ;
572
573
buttonToggleInstance = buttonToggleDebugElement . componentInstance ;
573
574
} ) ) ;
574
575
@@ -607,66 +608,77 @@ describe('MatButtonToggle without forms', () => {
607
608
} ) ) ;
608
609
609
610
it ( 'should focus on underlying input element when focus() is called' , ( ) => {
610
- let nativeRadioInput = buttonToggleDebugElement . query ( By . css ( 'input ' ) ) . nativeElement ;
611
- expect ( document . activeElement ) . not . toBe ( nativeRadioInput ) ;
611
+ let nativeButton = buttonToggleDebugElement . query ( By . css ( 'button ' ) ) . nativeElement ;
612
+ expect ( document . activeElement ) . not . toBe ( nativeButton ) ;
612
613
613
614
buttonToggleInstance . focus ( ) ;
614
615
fixture . detectChanges ( ) ;
615
616
616
- expect ( document . activeElement ) . toBe ( nativeRadioInput ) ;
617
+ expect ( document . activeElement ) . toBe ( nativeButton ) ;
617
618
} ) ;
618
619
619
620
it ( 'should not assign a name to the underlying input if one is not passed in' , ( ) => {
620
- expect ( buttonToggleNativeElement . querySelector ( 'input ' ) ! . getAttribute ( 'name' ) ) . toBeFalsy ( ) ;
621
+ expect ( buttonToggleNativeElement . querySelector ( 'button ' ) ! . getAttribute ( 'name' ) ) . toBeFalsy ( ) ;
621
622
} ) ;
622
623
624
+ it ( 'should have correct aria-pressed attribute' , ( ) => {
625
+ expect ( buttonToggleNativeElement . querySelector ( 'button' ) ! . getAttribute ( 'aria-pressed' ) )
626
+ . toBe ( 'false' ) ;
627
+
628
+ buttonToggleLabelElement . click ( ) ;
629
+
630
+ fixture . detectChanges ( ) ;
631
+
632
+ expect ( buttonToggleNativeElement . querySelector ( 'button' ) ! . getAttribute ( 'aria-pressed' ) )
633
+ . toBe ( 'true' ) ;
634
+ } )
623
635
} ) ;
624
636
625
637
describe ( 'aria-label handling ' , ( ) => {
626
638
it ( 'should not set the aria-label attribute if none is provided' , ( ) => {
627
639
let fixture = TestBed . createComponent ( StandaloneButtonToggle ) ;
628
640
let checkboxDebugElement = fixture . debugElement . query ( By . directive ( MatButtonToggle ) ) ;
629
641
let checkboxNativeElement = checkboxDebugElement . nativeElement ;
630
- let inputElement = checkboxNativeElement . querySelector ( 'input ' ) as HTMLInputElement ;
642
+ let buttonElement = checkboxNativeElement . querySelector ( 'button ' ) as HTMLButtonElement ;
631
643
632
644
fixture . detectChanges ( ) ;
633
- expect ( inputElement . hasAttribute ( 'aria-label' ) ) . toBe ( false ) ;
645
+ expect ( buttonElement . hasAttribute ( 'aria-label' ) ) . toBe ( false ) ;
634
646
} ) ;
635
647
636
648
it ( 'should use the provided aria-label' , ( ) => {
637
649
let fixture = TestBed . createComponent ( ButtonToggleWithAriaLabel ) ;
638
650
let checkboxDebugElement = fixture . debugElement . query ( By . directive ( MatButtonToggle ) ) ;
639
651
let checkboxNativeElement = checkboxDebugElement . nativeElement ;
640
- let inputElement = checkboxNativeElement . querySelector ( 'input ' ) as HTMLInputElement ;
652
+ let buttonElement = checkboxNativeElement . querySelector ( 'button ' ) as HTMLButtonElement ;
641
653
642
654
fixture . detectChanges ( ) ;
643
- expect ( inputElement . getAttribute ( 'aria-label' ) ) . toBe ( 'Super effective' ) ;
655
+ expect ( buttonElement . getAttribute ( 'aria-label' ) ) . toBe ( 'Super effective' ) ;
644
656
} ) ;
645
657
} ) ;
646
658
647
659
describe ( 'with provided aria-labelledby ' , ( ) => {
648
660
let checkboxDebugElement : DebugElement ;
649
661
let checkboxNativeElement : HTMLElement ;
650
- let inputElement : HTMLInputElement ;
662
+ let buttonElement : HTMLButtonElement ;
651
663
652
664
it ( 'should use the provided aria-labelledby' , ( ) => {
653
665
let fixture = TestBed . createComponent ( ButtonToggleWithAriaLabelledby ) ;
654
666
checkboxDebugElement = fixture . debugElement . query ( By . directive ( MatButtonToggle ) ) ;
655
667
checkboxNativeElement = checkboxDebugElement . nativeElement ;
656
- inputElement = checkboxNativeElement . querySelector ( 'input ' ) as HTMLInputElement ;
668
+ buttonElement = checkboxNativeElement . querySelector ( 'button ' ) as HTMLButtonElement ;
657
669
658
670
fixture . detectChanges ( ) ;
659
- expect ( inputElement . getAttribute ( 'aria-labelledby' ) ) . toBe ( 'some-id' ) ;
671
+ expect ( buttonElement . getAttribute ( 'aria-labelledby' ) ) . toBe ( 'some-id' ) ;
660
672
} ) ;
661
673
662
674
it ( 'should not assign aria-labelledby if none is provided' , ( ) => {
663
675
let fixture = TestBed . createComponent ( StandaloneButtonToggle ) ;
664
676
checkboxDebugElement = fixture . debugElement . query ( By . directive ( MatButtonToggle ) ) ;
665
677
checkboxNativeElement = checkboxDebugElement . nativeElement ;
666
- inputElement = checkboxNativeElement . querySelector ( 'input ' ) as HTMLInputElement ;
678
+ buttonElement = checkboxNativeElement . querySelector ( 'button ' ) as HTMLButtonElement ;
667
679
668
680
fixture . detectChanges ( ) ;
669
- expect ( inputElement . getAttribute ( 'aria-labelledby' ) ) . toBe ( null ) ;
681
+ expect ( buttonElement . getAttribute ( 'aria-labelledby' ) ) . toBe ( null ) ;
670
682
} ) ;
671
683
} ) ;
672
684
0 commit comments