1
1
import { LEFT_ARROW } from '@angular/cdk/keycodes' ;
2
2
import { dispatchFakeEvent , dispatchKeyboardEvent } from '../../cdk/testing/private' ;
3
- import { Component , OnInit , QueryList , ViewChild , ViewChildren } from '@angular/core' ;
3
+ import { Component , DebugElement , OnInit , QueryList , ViewChild , ViewChildren } from '@angular/core' ;
4
4
import {
5
5
waitForAsync ,
6
6
ComponentFixture ,
@@ -40,6 +40,7 @@ describe('MDC-based MatTabGroup', () => {
40
40
TabGroupWithIndirectDescendantTabs ,
41
41
TabGroupWithSpaceAbove ,
42
42
NestedTabGroupWithLabel ,
43
+ TabsWithClassesTestApp ,
43
44
] ,
44
45
} ) ;
45
46
@@ -420,11 +421,16 @@ describe('MDC-based MatTabGroup', () => {
420
421
421
422
expect ( tab . getAttribute ( 'aria-label' ) ) . toBe ( 'Fruit' ) ;
422
423
expect ( tab . hasAttribute ( 'aria-labelledby' ) ) . toBe ( false ) ;
424
+
425
+ fixture . componentInstance . ariaLabel = 'Veggie' ;
426
+ fixture . detectChanges ( ) ;
427
+ expect ( tab . getAttribute ( 'aria-label' ) ) . toBe ( 'Veggie' ) ;
423
428
} ) ;
424
429
} ) ;
425
430
426
431
describe ( 'disable tabs' , ( ) => {
427
432
let fixture : ComponentFixture < DisabledTabsTestApp > ;
433
+
428
434
beforeEach ( ( ) => {
429
435
fixture = TestBed . createComponent ( DisabledTabsTestApp ) ;
430
436
} ) ;
@@ -780,6 +786,62 @@ describe('MDC-based MatTabGroup', () => {
780
786
} ) ) ;
781
787
} ) ;
782
788
789
+ describe ( 'tabs with custom css classes' , ( ) => {
790
+ let fixture : ComponentFixture < TabsWithClassesTestApp > ;
791
+ let labelElements : DebugElement [ ] ;
792
+ let bodyElements : DebugElement [ ] ;
793
+
794
+ beforeEach ( ( ) => {
795
+ fixture = TestBed . createComponent ( TabsWithClassesTestApp ) ;
796
+ fixture . detectChanges ( ) ;
797
+ labelElements = fixture . debugElement . queryAll ( By . css ( '.mdc-tab' ) ) ;
798
+ bodyElements = fixture . debugElement . queryAll ( By . css ( 'mat-tab-body' ) ) ;
799
+ } ) ;
800
+
801
+ it ( 'should apply label/body classes' , ( ) => {
802
+ expect ( labelElements [ 1 ] . nativeElement . classList ) . toContain ( 'hardcoded-label-class' ) ;
803
+ expect ( bodyElements [ 1 ] . nativeElement . classList ) . toContain ( 'hardcoded-body-class' ) ;
804
+ } ) ;
805
+
806
+ it ( 'should set classes as strings dynamically' , ( ) => {
807
+ expect ( labelElements [ 0 ] . nativeElement . classList ) . not . toContain ( 'custom-label-class' ) ;
808
+ expect ( bodyElements [ 0 ] . nativeElement . classList ) . not . toContain ( 'custom-body-class' ) ;
809
+
810
+ fixture . componentInstance . labelClassList = 'custom-label-class' ;
811
+ fixture . componentInstance . bodyClassList = 'custom-body-class' ;
812
+ fixture . detectChanges ( ) ;
813
+
814
+ expect ( labelElements [ 0 ] . nativeElement . classList ) . toContain ( 'custom-label-class' ) ;
815
+ expect ( bodyElements [ 0 ] . nativeElement . classList ) . toContain ( 'custom-body-class' ) ;
816
+
817
+ delete fixture . componentInstance . labelClassList ;
818
+ delete fixture . componentInstance . bodyClassList ;
819
+ fixture . detectChanges ( ) ;
820
+
821
+ expect ( labelElements [ 0 ] . nativeElement . classList ) . not . toContain ( 'custom-label-class' ) ;
822
+ expect ( bodyElements [ 0 ] . nativeElement . classList ) . not . toContain ( 'custom-body-class' ) ;
823
+ } ) ;
824
+
825
+ it ( 'should set classes as strings array dynamically' , ( ) => {
826
+ expect ( labelElements [ 0 ] . nativeElement . classList ) . not . toContain ( 'custom-label-class' ) ;
827
+ expect ( bodyElements [ 0 ] . nativeElement . classList ) . not . toContain ( 'custom-body-class' ) ;
828
+
829
+ fixture . componentInstance . labelClassList = [ 'custom-label-class' ] ;
830
+ fixture . componentInstance . bodyClassList = [ 'custom-body-class' ] ;
831
+ fixture . detectChanges ( ) ;
832
+
833
+ expect ( labelElements [ 0 ] . nativeElement . classList ) . toContain ( 'custom-label-class' ) ;
834
+ expect ( bodyElements [ 0 ] . nativeElement . classList ) . toContain ( 'custom-body-class' ) ;
835
+
836
+ delete fixture . componentInstance . labelClassList ;
837
+ delete fixture . componentInstance . bodyClassList ;
838
+ fixture . detectChanges ( ) ;
839
+
840
+ expect ( labelElements [ 0 ] . nativeElement . classList ) . not . toContain ( 'custom-label-class' ) ;
841
+ expect ( bodyElements [ 0 ] . nativeElement . classList ) . not . toContain ( 'custom-body-class' ) ;
842
+ } ) ;
843
+ } ) ;
844
+
783
845
/**
784
846
* Checks that the `selectedIndex` has been updated; checks that the label and body have their
785
847
* respective `active` classes
@@ -1014,7 +1076,6 @@ class BindedTabsTestApp {
1014
1076
}
1015
1077
1016
1078
@Component ( {
1017
- selector : 'test-app' ,
1018
1079
template : `
1019
1080
<mat-tab-group class="tab-group">
1020
1081
<mat-tab>
@@ -1080,7 +1141,6 @@ class TabGroupWithSimpleApi {
1080
1141
}
1081
1142
1082
1143
@Component ( {
1083
- selector : 'nested-tabs' ,
1084
1144
template : `
1085
1145
<mat-tab-group>
1086
1146
<mat-tab label="One">Tab one content</mat-tab>
@@ -1099,7 +1159,6 @@ class NestedTabs {
1099
1159
}
1100
1160
1101
1161
@Component ( {
1102
- selector : 'template-tabs' ,
1103
1162
template : `
1104
1163
<mat-tab-group>
1105
1164
<mat-tab label="One">
@@ -1215,3 +1274,21 @@ class TabGroupWithSpaceAbove {
1215
1274
` ,
1216
1275
} )
1217
1276
class NestedTabGroupWithLabel { }
1277
+
1278
+ @Component ( {
1279
+ template : `
1280
+ <mat-tab-group class="tab-group">
1281
+ <mat-tab label="Tab One" [labelClass]="labelClassList" [bodyClass]="bodyClassList">
1282
+ Tab one content
1283
+ </mat-tab>
1284
+ <mat-tab label="Tab Two" labelClass="hardcoded-label-class"
1285
+ bodyClass="hardcoded-body-class">
1286
+ Tab two content
1287
+ </mat-tab>
1288
+ </mat-tab-group>
1289
+ ` ,
1290
+ } )
1291
+ class TabsWithClassesTestApp {
1292
+ labelClassList ?: string | string [ ] ;
1293
+ bodyClassList ?: string | string [ ] ;
1294
+ }
0 commit comments