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 ,
@@ -41,6 +41,7 @@ describe('MDC-based MatTabGroup', () => {
41
41
TabGroupWithIndirectDescendantTabs ,
42
42
TabGroupWithSpaceAbove ,
43
43
NestedTabGroupWithLabel ,
44
+ TabsWithClassesTestApp ,
44
45
] ,
45
46
} ) ;
46
47
@@ -364,7 +365,6 @@ describe('MDC-based MatTabGroup', () => {
364
365
365
366
expect ( contentElements . map ( e => e . getAttribute ( 'tabindex' ) ) ) . toEqual ( [ '1' , null , null ] ) ;
366
367
} ) ;
367
-
368
368
} ) ;
369
369
370
370
describe ( 'aria labelling' , ( ) => {
@@ -404,11 +404,16 @@ describe('MDC-based MatTabGroup', () => {
404
404
405
405
expect ( tab . getAttribute ( 'aria-label' ) ) . toBe ( 'Fruit' ) ;
406
406
expect ( tab . hasAttribute ( 'aria-labelledby' ) ) . toBe ( false ) ;
407
+
408
+ fixture . componentInstance . ariaLabel = 'Veggie' ;
409
+ fixture . detectChanges ( ) ;
410
+ expect ( tab . getAttribute ( 'aria-label' ) ) . toBe ( 'Veggie' ) ;
407
411
} ) ;
408
412
} ) ;
409
413
410
414
describe ( 'disable tabs' , ( ) => {
411
415
let fixture : ComponentFixture < DisabledTabsTestApp > ;
416
+
412
417
beforeEach ( ( ) => {
413
418
fixture = TestBed . createComponent ( DisabledTabsTestApp ) ;
414
419
} ) ;
@@ -482,7 +487,6 @@ describe('MDC-based MatTabGroup', () => {
482
487
expect ( tabs [ 0 ] . origin ) . toBeLessThan ( 0 ) ;
483
488
} ) ) ;
484
489
485
-
486
490
it ( 'should update selected index if the last tab removed while selected' , fakeAsync ( ( ) => {
487
491
const component : MatTabGroup =
488
492
fixture . debugElement . query ( By . css ( 'mat-tab-group' ) ) . componentInstance ;
@@ -500,7 +504,6 @@ describe('MDC-based MatTabGroup', () => {
500
504
expect ( component . selectedIndex ) . toBe ( numberOfTabs - 2 ) ;
501
505
} ) ) ;
502
506
503
-
504
507
it ( 'should maintain the selected tab if a new tab is added' , ( ) => {
505
508
fixture . detectChanges ( ) ;
506
509
const component : MatTabGroup =
@@ -517,7 +520,6 @@ describe('MDC-based MatTabGroup', () => {
517
520
expect ( component . _tabs . toArray ( ) [ 2 ] . isActive ) . toBe ( true ) ;
518
521
} ) ;
519
522
520
-
521
523
it ( 'should maintain the selected tab if a tab is removed' , ( ) => {
522
524
// Select the second tab.
523
525
fixture . componentInstance . selectedIndex = 1 ;
@@ -565,7 +567,6 @@ describe('MDC-based MatTabGroup', () => {
565
567
566
568
expect ( fixture . componentInstance . handleSelection ) . not . toHaveBeenCalled ( ) ;
567
569
} ) ) ;
568
-
569
570
} ) ;
570
571
571
572
describe ( 'async tabs' , ( ) => {
@@ -756,6 +757,77 @@ describe('MDC-based MatTabGroup', () => {
756
757
} ) ) ;
757
758
} ) ;
758
759
760
+ describe ( 'tabs with custom css classes' , ( ) => {
761
+ let fixture : ComponentFixture < TabsWithClassesTestApp > ;
762
+ let labelElements : DebugElement [ ] ;
763
+ let bodyElements : DebugElement [ ] ;
764
+
765
+ beforeEach ( ( ) => {
766
+ fixture = TestBed . createComponent ( TabsWithClassesTestApp ) ;
767
+ fixture . detectChanges ( ) ;
768
+ labelElements = fixture . debugElement . queryAll ( By . css ( '.mdc-tab' ) ) ;
769
+ bodyElements = fixture . debugElement . queryAll ( By . css ( 'mat-tab-body' ) ) ;
770
+ } ) ;
771
+
772
+ it ( 'should apply label classes' , ( ) => {
773
+ expect ( labelElements [ 4 ] . nativeElement . classList ) . toContain ( 'hardcoded-label-class' ) ;
774
+ } ) ;
775
+
776
+ it ( 'should apply body classes' , ( ) => {
777
+ expect ( bodyElements [ 4 ] . nativeElement . classList ) . toContain ( 'hardcoded-body-class' ) ;
778
+ } ) ;
779
+
780
+ it ( 'should set classes as strings dynamically' , ( ) => {
781
+ expect ( labelElements [ 1 ] . nativeElement . classList ) . not . toContain ( 'custom-label-class' ) ;
782
+ expect ( labelElements [ 3 ] . nativeElement . classList ) . not . toContain ( 'custom-label-class' ) ;
783
+ expect ( bodyElements [ 2 ] . nativeElement . classList ) . not . toContain ( 'custom-body-class' ) ;
784
+ expect ( bodyElements [ 3 ] . nativeElement . classList ) . not . toContain ( 'custom-body-class' ) ;
785
+
786
+ fixture . componentInstance . labelClassList = 'custom-label-class' ;
787
+ fixture . componentInstance . bodyClassList = 'custom-body-class' ;
788
+ fixture . detectChanges ( ) ;
789
+
790
+ expect ( labelElements [ 1 ] . nativeElement . classList ) . toContain ( 'custom-label-class' ) ;
791
+ expect ( labelElements [ 3 ] . nativeElement . classList ) . toContain ( 'custom-label-class' ) ;
792
+ expect ( bodyElements [ 2 ] . nativeElement . classList ) . toContain ( 'custom-body-class' ) ;
793
+ expect ( bodyElements [ 3 ] . nativeElement . classList ) . toContain ( 'custom-body-class' ) ;
794
+
795
+ delete fixture . componentInstance . labelClassList ;
796
+ delete fixture . componentInstance . bodyClassList ;
797
+ fixture . detectChanges ( ) ;
798
+
799
+ expect ( labelElements [ 1 ] . nativeElement . classList ) . not . toContain ( 'custom-label-class' ) ;
800
+ expect ( labelElements [ 3 ] . nativeElement . classList ) . not . toContain ( 'custom-label-class' ) ;
801
+ expect ( bodyElements [ 2 ] . nativeElement . classList ) . not . toContain ( 'custom-body-class' ) ;
802
+ expect ( bodyElements [ 3 ] . nativeElement . classList ) . not . toContain ( 'custom-body-class' ) ;
803
+ } ) ;
804
+
805
+ it ( 'should set classes as strings array dynamically' , ( ) => {
806
+ expect ( labelElements [ 1 ] . nativeElement . classList ) . not . toContain ( 'custom-label-class' ) ;
807
+ expect ( labelElements [ 3 ] . nativeElement . classList ) . not . toContain ( 'custom-label-class' ) ;
808
+ expect ( bodyElements [ 2 ] . nativeElement . classList ) . not . toContain ( 'custom-body-class' ) ;
809
+ expect ( bodyElements [ 3 ] . nativeElement . classList ) . not . toContain ( 'custom-body-class' ) ;
810
+
811
+ fixture . componentInstance . labelClassList = [ 'custom-label-class' ] ;
812
+ fixture . componentInstance . bodyClassList = [ 'custom-body-class' ] ;
813
+ fixture . detectChanges ( ) ;
814
+
815
+ expect ( labelElements [ 1 ] . nativeElement . classList ) . toContain ( 'custom-label-class' ) ;
816
+ expect ( labelElements [ 3 ] . nativeElement . classList ) . toContain ( 'custom-label-class' ) ;
817
+ expect ( bodyElements [ 2 ] . nativeElement . classList ) . toContain ( 'custom-body-class' ) ;
818
+ expect ( bodyElements [ 3 ] . nativeElement . classList ) . toContain ( 'custom-body-class' ) ;
819
+
820
+ delete fixture . componentInstance . labelClassList ;
821
+ delete fixture . componentInstance . bodyClassList ;
822
+ fixture . detectChanges ( ) ;
823
+
824
+ expect ( labelElements [ 1 ] . nativeElement . classList ) . not . toContain ( 'custom-label-class' ) ;
825
+ expect ( labelElements [ 3 ] . nativeElement . classList ) . not . toContain ( 'custom-label-class' ) ;
826
+ expect ( bodyElements [ 2 ] . nativeElement . classList ) . not . toContain ( 'custom-body-class' ) ;
827
+ expect ( bodyElements [ 3 ] . nativeElement . classList ) . not . toContain ( 'custom-body-class' ) ;
828
+ } ) ;
829
+ } ) ;
830
+
759
831
/**
760
832
* Checks that the `selectedIndex` has been updated; checks that the label and body have their
761
833
* respective `active` classes
@@ -935,6 +1007,7 @@ class SimpleTabsTestApp {
935
1007
animationDone ( ) { }
936
1008
}
937
1009
1010
+
938
1011
@Component ( {
939
1012
template : `
940
1013
<mat-tab-group class="tab-group"
@@ -965,6 +1038,7 @@ class SimpleDynamicTabsTestApp {
965
1038
}
966
1039
}
967
1040
1041
+
968
1042
@Component ( {
969
1043
template : `
970
1044
<mat-tab-group class="tab-group" [(selectedIndex)]="selectedIndex">
@@ -990,8 +1064,8 @@ class BindedTabsTestApp {
990
1064
}
991
1065
}
992
1066
1067
+
993
1068
@Component ( {
994
- selector : 'test-app' ,
995
1069
template : `
996
1070
<mat-tab-group class="tab-group">
997
1071
<mat-tab>
@@ -1014,6 +1088,7 @@ class DisabledTabsTestApp {
1014
1088
isDisabled = false ;
1015
1089
}
1016
1090
1091
+
1017
1092
@Component ( {
1018
1093
template : `
1019
1094
<mat-tab-group class="tab-group">
@@ -1059,7 +1134,6 @@ class TabGroupWithSimpleApi {
1059
1134
1060
1135
1061
1136
@Component ( {
1062
- selector : 'nested-tabs' ,
1063
1137
template : `
1064
1138
<mat-tab-group>
1065
1139
<mat-tab label="One">Tab one content</mat-tab>
@@ -1077,8 +1151,8 @@ class NestedTabs {
1077
1151
@ViewChildren ( MatTabGroup ) groups : QueryList < MatTabGroup > ;
1078
1152
}
1079
1153
1154
+
1080
1155
@Component ( {
1081
- selector : 'template-tabs' ,
1082
1156
template : `
1083
1157
<mat-tab-group>
1084
1158
<mat-tab label="One">
@@ -1091,11 +1165,11 @@ class NestedTabs {
1091
1165
</mat-tab>
1092
1166
</mat-tab-group>
1093
1167
` ,
1094
- } )
1095
- class TemplateTabs { }
1168
+ } )
1169
+ class TemplateTabs { }
1096
1170
1097
1171
1098
- @Component ( {
1172
+ @Component ( {
1099
1173
template : `
1100
1174
<mat-tab-group>
1101
1175
<mat-tab [aria-label]="ariaLabel" [aria-labelledby]="ariaLabelledby"></mat-tab>
@@ -1160,6 +1234,7 @@ class TabGroupWithInkBarFitToContent {
1160
1234
fitInkBarToContent = true ;
1161
1235
}
1162
1236
1237
+
1163
1238
@Component ( {
1164
1239
template : `
1165
1240
<div style="height: 300px; background-color: aqua">
@@ -1202,3 +1277,31 @@ class TabGroupWithSpaceAbove {
1202
1277
} )
1203
1278
class NestedTabGroupWithLabel {
1204
1279
}
1280
+
1281
+
1282
+ @Component ( {
1283
+ template : `
1284
+ <mat-tab-group class="tab-group">
1285
+ <mat-tab label="Tab One">
1286
+ Tab one content
1287
+ </mat-tab>
1288
+ <mat-tab label="Tab Two" [labelClass]="labelClassList">
1289
+ Tab two content
1290
+ </mat-tab>
1291
+ <mat-tab label="Tab Three" [bodyClass]="bodyClassList">
1292
+ Tab three content
1293
+ </mat-tab>
1294
+ <mat-tab label="Tab Four" [labelClass]="labelClassList" [bodyClass]="bodyClassList">
1295
+ Tab four content
1296
+ </mat-tab>
1297
+ <mat-tab label="Tab Five" labelClass="hardcoded-label-class"
1298
+ bodyClass="hardcoded-body-class">
1299
+ Tab five content
1300
+ </mat-tab>
1301
+ </mat-tab-group>
1302
+ ` ,
1303
+ } )
1304
+ class TabsWithClassesTestApp {
1305
+ labelClassList ?: string | string [ ] ;
1306
+ bodyClassList ?: string | string [ ] ;
1307
+ }
0 commit comments