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' , ( ) => {
@@ -409,6 +409,7 @@ describe('MDC-based MatTabGroup', () => {
409
409
410
410
describe ( 'disable tabs' , ( ) => {
411
411
let fixture : ComponentFixture < DisabledTabsTestApp > ;
412
+
412
413
beforeEach ( ( ) => {
413
414
fixture = TestBed . createComponent ( DisabledTabsTestApp ) ;
414
415
} ) ;
@@ -482,7 +483,6 @@ describe('MDC-based MatTabGroup', () => {
482
483
expect ( tabs [ 0 ] . origin ) . toBeLessThan ( 0 ) ;
483
484
} ) ) ;
484
485
485
-
486
486
it ( 'should update selected index if the last tab removed while selected' , fakeAsync ( ( ) => {
487
487
const component : MatTabGroup =
488
488
fixture . debugElement . query ( By . css ( 'mat-tab-group' ) ) . componentInstance ;
@@ -500,7 +500,6 @@ describe('MDC-based MatTabGroup', () => {
500
500
expect ( component . selectedIndex ) . toBe ( numberOfTabs - 2 ) ;
501
501
} ) ) ;
502
502
503
-
504
503
it ( 'should maintain the selected tab if a new tab is added' , ( ) => {
505
504
fixture . detectChanges ( ) ;
506
505
const component : MatTabGroup =
@@ -517,7 +516,6 @@ describe('MDC-based MatTabGroup', () => {
517
516
expect ( component . _tabs . toArray ( ) [ 2 ] . isActive ) . toBe ( true ) ;
518
517
} ) ;
519
518
520
-
521
519
it ( 'should maintain the selected tab if a tab is removed' , ( ) => {
522
520
// Select the second tab.
523
521
fixture . componentInstance . selectedIndex = 1 ;
@@ -565,7 +563,6 @@ describe('MDC-based MatTabGroup', () => {
565
563
566
564
expect ( fixture . componentInstance . handleSelection ) . not . toHaveBeenCalled ( ) ;
567
565
} ) ) ;
568
-
569
566
} ) ;
570
567
571
568
describe ( 'async tabs' , ( ) => {
@@ -756,6 +753,100 @@ describe('MDC-based MatTabGroup', () => {
756
753
} ) ) ;
757
754
} ) ;
758
755
756
+ describe ( 'tabs with custom css classes' , ( ) => {
757
+ let fixture : ComponentFixture < TabsWithClassesTestApp > ;
758
+
759
+ beforeEach ( ( ) => {
760
+ fixture = TestBed . createComponent ( TabsWithClassesTestApp ) ;
761
+ } ) ;
762
+
763
+ it ( 'should apply label classes' , ( ) => {
764
+ fixture . detectChanges ( ) ;
765
+
766
+ const labelElements = fixture . debugElement
767
+ . queryAll ( By . css ( '.mdc-tab.hardcoded.label.classes' ) ) ;
768
+ expect ( labelElements . length ) . toBe ( 1 ) ;
769
+ } ) ;
770
+
771
+ it ( 'should apply body classes' , ( ) => {
772
+ fixture . detectChanges ( ) ;
773
+
774
+ const bodyElements = fixture . debugElement
775
+ . queryAll ( By . css ( 'mat-tab-body.hardcoded.body.classes' ) ) ;
776
+ expect ( bodyElements . length ) . toBe ( 1 ) ;
777
+ } ) ;
778
+
779
+ it ( 'should set classes as strings dynamically' , ( ) => {
780
+ fixture . detectChanges ( ) ;
781
+ let labelElements : DebugElement [ ] ;
782
+ let bodyElements : DebugElement [ ] ;
783
+
784
+ labelElements = fixture . debugElement
785
+ . queryAll ( By . css ( '.mdc-tab.custom-label-class.one-more-label-class' ) ) ;
786
+ bodyElements = fixture . debugElement
787
+ . queryAll ( By . css ( 'mat-tab-body.custom-body-class.one-more-body-class' ) ) ;
788
+ expect ( labelElements . length ) . toBe ( 0 ) ;
789
+ expect ( bodyElements . length ) . toBe ( 0 ) ;
790
+
791
+ fixture . componentInstance . labelClassList = 'custom-label-class one-more-label-class' ;
792
+ fixture . componentInstance . bodyClassList = 'custom-body-class one-more-body-class' ;
793
+ fixture . detectChanges ( ) ;
794
+
795
+ labelElements = fixture . debugElement
796
+ . queryAll ( By . css ( '.mdc-tab.custom-label-class.one-more-label-class' ) ) ;
797
+ bodyElements = fixture . debugElement
798
+ . queryAll ( By . css ( 'mat-tab-body.custom-body-class.one-more-body-class' ) ) ;
799
+ expect ( labelElements . length ) . toBe ( 2 ) ;
800
+ expect ( bodyElements . length ) . toBe ( 2 ) ;
801
+
802
+ delete fixture . componentInstance . labelClassList ;
803
+ delete fixture . componentInstance . bodyClassList ;
804
+ fixture . detectChanges ( ) ;
805
+
806
+ labelElements = fixture . debugElement
807
+ . queryAll ( By . css ( '.mdc-tab.custom-label-class.one-more-label-class' ) ) ;
808
+ bodyElements = fixture . debugElement
809
+ . queryAll ( By . css ( 'mat-tab-body.custom-body-class.one-more-body-class' ) ) ;
810
+ expect ( labelElements . length ) . toBe ( 0 ) ;
811
+ expect ( bodyElements . length ) . toBe ( 0 ) ;
812
+ } ) ;
813
+
814
+ it ( 'should set classes as strings array dynamically' , ( ) => {
815
+ fixture . detectChanges ( ) ;
816
+ let labelElements : DebugElement [ ] ;
817
+ let bodyElements : DebugElement [ ] ;
818
+
819
+ labelElements = fixture . debugElement
820
+ . queryAll ( By . css ( '.mdc-tab.custom-label-class.one-more-label-class' ) ) ;
821
+ bodyElements = fixture . debugElement
822
+ . queryAll ( By . css ( 'mat-tab-body.custom-body-class.one-more-body-class' ) ) ;
823
+ expect ( labelElements . length ) . toBe ( 0 ) ;
824
+ expect ( bodyElements . length ) . toBe ( 0 ) ;
825
+
826
+ fixture . componentInstance . labelClassList = [ 'custom-label-class' , 'one-more-label-class' ] ;
827
+ fixture . componentInstance . bodyClassList = [ 'custom-body-class' , 'one-more-body-class' ] ;
828
+ fixture . detectChanges ( ) ;
829
+
830
+ labelElements = fixture . debugElement
831
+ . queryAll ( By . css ( '.mdc-tab.custom-label-class.one-more-label-class' ) ) ;
832
+ bodyElements = fixture . debugElement
833
+ . queryAll ( By . css ( 'mat-tab-body.custom-body-class.one-more-body-class' ) ) ;
834
+ expect ( labelElements . length ) . toBe ( 2 ) ;
835
+ expect ( bodyElements . length ) . toBe ( 2 ) ;
836
+
837
+ delete fixture . componentInstance . labelClassList ;
838
+ delete fixture . componentInstance . bodyClassList ;
839
+ fixture . detectChanges ( ) ;
840
+
841
+ labelElements = fixture . debugElement
842
+ . queryAll ( By . css ( '.mdc-tab.custom-label-class.one-more-label-class' ) ) ;
843
+ bodyElements = fixture . debugElement
844
+ . queryAll ( By . css ( 'mat-tab-body.custom-body-class.one-more-body-class' ) ) ;
845
+ expect ( labelElements . length ) . toBe ( 0 ) ;
846
+ expect ( bodyElements . length ) . toBe ( 0 ) ;
847
+ } ) ;
848
+ } ) ;
849
+
759
850
/**
760
851
* Checks that the `selectedIndex` has been updated; checks that the label and body have their
761
852
* respective `active` classes
@@ -935,6 +1026,7 @@ class SimpleTabsTestApp {
935
1026
animationDone ( ) { }
936
1027
}
937
1028
1029
+
938
1030
@Component ( {
939
1031
template : `
940
1032
<mat-tab-group class="tab-group"
@@ -965,6 +1057,7 @@ class SimpleDynamicTabsTestApp {
965
1057
}
966
1058
}
967
1059
1060
+
968
1061
@Component ( {
969
1062
template : `
970
1063
<mat-tab-group class="tab-group" [(selectedIndex)]="selectedIndex">
@@ -990,8 +1083,8 @@ class BindedTabsTestApp {
990
1083
}
991
1084
}
992
1085
1086
+
993
1087
@Component ( {
994
- selector : 'test-app' ,
995
1088
template : `
996
1089
<mat-tab-group class="tab-group">
997
1090
<mat-tab>
@@ -1014,6 +1107,7 @@ class DisabledTabsTestApp {
1014
1107
isDisabled = false ;
1015
1108
}
1016
1109
1110
+
1017
1111
@Component ( {
1018
1112
template : `
1019
1113
<mat-tab-group class="tab-group">
@@ -1059,7 +1153,6 @@ class TabGroupWithSimpleApi {
1059
1153
1060
1154
1061
1155
@Component ( {
1062
- selector : 'nested-tabs' ,
1063
1156
template : `
1064
1157
<mat-tab-group>
1065
1158
<mat-tab label="One">Tab one content</mat-tab>
@@ -1077,8 +1170,8 @@ class NestedTabs {
1077
1170
@ViewChildren ( MatTabGroup ) groups : QueryList < MatTabGroup > ;
1078
1171
}
1079
1172
1173
+
1080
1174
@Component ( {
1081
- selector : 'template-tabs' ,
1082
1175
template : `
1083
1176
<mat-tab-group>
1084
1177
<mat-tab label="One">
@@ -1091,11 +1184,11 @@ class NestedTabs {
1091
1184
</mat-tab>
1092
1185
</mat-tab-group>
1093
1186
` ,
1094
- } )
1095
- class TemplateTabs { }
1187
+ } )
1188
+ class TemplateTabs { }
1096
1189
1097
1190
1098
- @Component ( {
1191
+ @Component ( {
1099
1192
template : `
1100
1193
<mat-tab-group>
1101
1194
<mat-tab [aria-label]="ariaLabel" [aria-labelledby]="ariaLabelledby"></mat-tab>
@@ -1160,6 +1253,7 @@ class TabGroupWithInkBarFitToContent {
1160
1253
fitInkBarToContent = true ;
1161
1254
}
1162
1255
1256
+
1163
1257
@Component ( {
1164
1258
template : `
1165
1259
<div style="height: 300px; background-color: aqua">
@@ -1202,3 +1296,31 @@ class TabGroupWithSpaceAbove {
1202
1296
} )
1203
1297
class NestedTabGroupWithLabel {
1204
1298
}
1299
+
1300
+
1301
+ @Component ( {
1302
+ template : `
1303
+ <mat-tab-group class="tab-group">
1304
+ <mat-tab label="Tab One">
1305
+ Tab one content
1306
+ </mat-tab>
1307
+ <mat-tab label="Tab Two" [class]="labelClassList">
1308
+ Tab two content
1309
+ </mat-tab>
1310
+ <mat-tab label="Tab Three" [bodyClass]="bodyClassList">
1311
+ Tab three content
1312
+ </mat-tab>
1313
+ <mat-tab label="Tab Four" [class]="labelClassList" [bodyClass]="bodyClassList">
1314
+ Tab four content
1315
+ </mat-tab>
1316
+ <mat-tab label="Tab Five" class="hardcoded label classes" bodyClass="hardcoded body classes">
1317
+ Tab five content
1318
+ </mat-tab>
1319
+ </mat-tab-group>
1320
+ ` ,
1321
+ } )
1322
+ class TabsWithClassesTestApp {
1323
+ @ViewChildren ( MatTab ) tabs : QueryList < MatTab > ;
1324
+ labelClassList ?: string | string [ ] ;
1325
+ bodyClassList ?: string | string [ ] ;
1326
+ }
0 commit comments