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('MatTabGroup', () => {
41
41
TabGroupWithIndirectDescendantTabs ,
42
42
TabGroupWithSpaceAbove ,
43
43
NestedTabGroupWithLabel ,
44
+ TabsWithClassesTestApp ,
44
45
] ,
45
46
} ) ;
46
47
@@ -408,6 +409,7 @@ describe('MatTabGroup', () => {
408
409
409
410
describe ( 'disable tabs' , ( ) => {
410
411
let fixture : ComponentFixture < DisabledTabsTestApp > ;
412
+
411
413
beforeEach ( ( ) => {
412
414
fixture = TestBed . createComponent ( DisabledTabsTestApp ) ;
413
415
} ) ;
@@ -481,7 +483,6 @@ describe('MatTabGroup', () => {
481
483
expect ( tabs [ 0 ] . origin ) . toBeLessThan ( 0 ) ;
482
484
} ) ) ;
483
485
484
-
485
486
it ( 'should update selected index if the last tab removed while selected' , fakeAsync ( ( ) => {
486
487
const component : MatTabGroup =
487
488
fixture . debugElement . query ( By . css ( 'mat-tab-group' ) ) ! . componentInstance ;
@@ -499,7 +500,6 @@ describe('MatTabGroup', () => {
499
500
expect ( component . selectedIndex ) . toBe ( numberOfTabs - 2 ) ;
500
501
} ) ) ;
501
502
502
-
503
503
it ( 'should maintain the selected tab if a new tab is added' , ( ) => {
504
504
fixture . detectChanges ( ) ;
505
505
const component : MatTabGroup =
@@ -516,7 +516,6 @@ describe('MatTabGroup', () => {
516
516
expect ( component . _tabs . toArray ( ) [ 2 ] . isActive ) . toBe ( true ) ;
517
517
} ) ;
518
518
519
-
520
519
it ( 'should maintain the selected tab if a tab is removed' , ( ) => {
521
520
// Select the second tab.
522
521
fixture . componentInstance . selectedIndex = 1 ;
@@ -564,7 +563,6 @@ describe('MatTabGroup', () => {
564
563
565
564
expect ( fixture . componentInstance . handleSelection ) . not . toHaveBeenCalled ( ) ;
566
565
} ) ) ;
567
-
568
566
} ) ;
569
567
570
568
describe ( 'async tabs' , ( ) => {
@@ -756,6 +754,100 @@ describe('MatTabGroup', () => {
756
754
} ) ) ;
757
755
} ) ;
758
756
757
+ describe ( 'tabs with custom css classes' , ( ) => {
758
+ let fixture : ComponentFixture < TabsWithClassesTestApp > ;
759
+
760
+ beforeEach ( ( ) => {
761
+ fixture = TestBed . createComponent ( TabsWithClassesTestApp ) ;
762
+ } ) ;
763
+
764
+ it ( 'should apply label classes' , ( ) => {
765
+ fixture . detectChanges ( ) ;
766
+
767
+ const labelElements = fixture . debugElement
768
+ . queryAll ( By . css ( '.mat-tab-label.hardcoded.label.classes' ) ) ;
769
+ expect ( labelElements . length ) . toBe ( 1 ) ;
770
+ } ) ;
771
+
772
+ it ( 'should apply body classes' , ( ) => {
773
+ fixture . detectChanges ( ) ;
774
+
775
+ const bodyElements = fixture . debugElement
776
+ . queryAll ( By . css ( 'mat-tab-body.hardcoded.body.classes' ) ) ;
777
+ expect ( bodyElements . length ) . toBe ( 1 ) ;
778
+ } ) ;
779
+
780
+ it ( 'should set classes as strings dynamically' , ( ) => {
781
+ fixture . detectChanges ( ) ;
782
+ let labelElements : DebugElement [ ] ;
783
+ let bodyElements : DebugElement [ ] ;
784
+
785
+ labelElements = fixture . debugElement
786
+ . queryAll ( By . css ( '.mat-tab-label.custom-label-class.one-more-label-class' ) ) ;
787
+ bodyElements = fixture . debugElement
788
+ . queryAll ( By . css ( 'mat-tab-body.custom-body-class.one-more-body-class' ) ) ;
789
+ expect ( labelElements . length ) . toBe ( 0 ) ;
790
+ expect ( bodyElements . length ) . toBe ( 0 ) ;
791
+
792
+ fixture . componentInstance . labelClassList = 'custom-label-class one-more-label-class' ;
793
+ fixture . componentInstance . bodyClassList = 'custom-body-class one-more-body-class' ;
794
+ fixture . detectChanges ( ) ;
795
+
796
+ labelElements = fixture . debugElement
797
+ . queryAll ( By . css ( '.mat-tab-label.custom-label-class.one-more-label-class' ) ) ;
798
+ bodyElements = fixture . debugElement
799
+ . queryAll ( By . css ( 'mat-tab-body.custom-body-class.one-more-body-class' ) ) ;
800
+ expect ( labelElements . length ) . toBe ( 2 ) ;
801
+ expect ( bodyElements . length ) . toBe ( 2 ) ;
802
+
803
+ delete fixture . componentInstance . labelClassList ;
804
+ delete fixture . componentInstance . bodyClassList ;
805
+ fixture . detectChanges ( ) ;
806
+
807
+ labelElements = fixture . debugElement
808
+ . queryAll ( By . css ( '.mat-tab-label.custom-label-class.one-more-label-class' ) ) ;
809
+ bodyElements = fixture . debugElement
810
+ . queryAll ( By . css ( 'mat-tab-body.custom-body-class.one-more-body-class' ) ) ;
811
+ expect ( labelElements . length ) . toBe ( 0 ) ;
812
+ expect ( bodyElements . length ) . toBe ( 0 ) ;
813
+ } ) ;
814
+
815
+ it ( 'should set classes as strings array dynamically' , ( ) => {
816
+ fixture . detectChanges ( ) ;
817
+ let labelElements : DebugElement [ ] ;
818
+ let bodyElements : DebugElement [ ] ;
819
+
820
+ labelElements = fixture . debugElement
821
+ . queryAll ( By . css ( '.mat-tab-label.custom-label-class.one-more-label-class' ) ) ;
822
+ bodyElements = fixture . debugElement
823
+ . queryAll ( By . css ( 'mat-tab-body.custom-body-class.one-more-body-class' ) ) ;
824
+ expect ( labelElements . length ) . toBe ( 0 ) ;
825
+ expect ( bodyElements . length ) . toBe ( 0 ) ;
826
+
827
+ fixture . componentInstance . labelClassList = [ 'custom-label-class' , 'one-more-label-class' ] ;
828
+ fixture . componentInstance . bodyClassList = [ 'custom-body-class' , 'one-more-body-class' ] ;
829
+ fixture . detectChanges ( ) ;
830
+
831
+ labelElements = fixture . debugElement
832
+ . queryAll ( By . css ( '.mat-tab-label.custom-label-class.one-more-label-class' ) ) ;
833
+ bodyElements = fixture . debugElement
834
+ . queryAll ( By . css ( 'mat-tab-body.custom-body-class.one-more-body-class' ) ) ;
835
+ expect ( labelElements . length ) . toBe ( 2 ) ;
836
+ expect ( bodyElements . length ) . toBe ( 2 ) ;
837
+
838
+ delete fixture . componentInstance . labelClassList ;
839
+ delete fixture . componentInstance . bodyClassList ;
840
+ fixture . detectChanges ( ) ;
841
+
842
+ labelElements = fixture . debugElement
843
+ . queryAll ( By . css ( '.mat-tab-label.custom-label-class.one-more-label-class' ) ) ;
844
+ bodyElements = fixture . debugElement
845
+ . queryAll ( By . css ( 'mat-tab-body.custom-body-class.one-more-body-class' ) ) ;
846
+ expect ( labelElements . length ) . toBe ( 0 ) ;
847
+ expect ( bodyElements . length ) . toBe ( 0 ) ;
848
+ } ) ;
849
+ } ) ;
850
+
759
851
/**
760
852
* Checks that the `selectedIndex` has been updated; checks that the label and body have their
761
853
* respective `active` classes
@@ -881,6 +973,7 @@ class SimpleTabsTestApp {
881
973
animationDone ( ) { }
882
974
}
883
975
976
+
884
977
@Component ( {
885
978
template : `
886
979
<mat-tab-group class="tab-group"
@@ -911,6 +1004,7 @@ class SimpleDynamicTabsTestApp {
911
1004
}
912
1005
}
913
1006
1007
+
914
1008
@Component ( {
915
1009
template : `
916
1010
<mat-tab-group class="tab-group" [(selectedIndex)]="selectedIndex">
@@ -936,8 +1030,8 @@ class BindedTabsTestApp {
936
1030
}
937
1031
}
938
1032
1033
+
939
1034
@Component ( {
940
- selector : 'test-app' ,
941
1035
template : `
942
1036
<mat-tab-group class="tab-group">
943
1037
<mat-tab>
@@ -960,6 +1054,7 @@ class DisabledTabsTestApp {
960
1054
isDisabled = false ;
961
1055
}
962
1056
1057
+
963
1058
@Component ( {
964
1059
template : `
965
1060
<mat-tab-group class="tab-group">
@@ -1023,6 +1118,7 @@ class NestedTabs {
1023
1118
@ViewChildren ( MatTabGroup ) groups : QueryList < MatTabGroup > ;
1024
1119
}
1025
1120
1121
+
1026
1122
@Component ( {
1027
1123
selector : 'template-tabs' ,
1028
1124
template : `
@@ -1037,11 +1133,11 @@ class NestedTabs {
1037
1133
</mat-tab>
1038
1134
</mat-tab-group>
1039
1135
` ,
1040
- } )
1041
- class TemplateTabs { }
1136
+ } )
1137
+ class TemplateTabs { }
1042
1138
1043
1139
1044
- @Component ( {
1140
+ @Component ( {
1045
1141
template : `
1046
1142
<mat-tab-group>
1047
1143
<mat-tab [aria-label]="ariaLabel" [aria-labelledby]="ariaLabelledby"></mat-tab>
@@ -1093,6 +1189,7 @@ class TabGroupWithIndirectDescendantTabs {
1093
1189
@ViewChild ( MatTabGroup ) tabGroup : MatTabGroup ;
1094
1190
}
1095
1191
1192
+
1096
1193
@Component ( {
1097
1194
template : `
1098
1195
<div style="height: 300px; background-color: aqua">
@@ -1135,3 +1232,31 @@ class TabGroupWithSpaceAbove {
1135
1232
} )
1136
1233
class NestedTabGroupWithLabel {
1137
1234
}
1235
+
1236
+
1237
+ @Component ( {
1238
+ template : `
1239
+ <mat-tab-group class="tab-group">
1240
+ <mat-tab label="Tab One">
1241
+ Tab one content
1242
+ </mat-tab>
1243
+ <mat-tab label="Tab Two" [class]="labelClassList">
1244
+ Tab two content
1245
+ </mat-tab>
1246
+ <mat-tab label="Tab Three" [bodyClass]="bodyClassList">
1247
+ Tab three content
1248
+ </mat-tab>
1249
+ <mat-tab label="Tab Four" [class]="labelClassList" [bodyClass]="bodyClassList">
1250
+ Tab four content
1251
+ </mat-tab>
1252
+ <mat-tab label="Tab Five" class="hardcoded label classes" bodyClass="hardcoded body classes">
1253
+ Tab five content
1254
+ </mat-tab>
1255
+ </mat-tab-group>
1256
+ ` ,
1257
+ } )
1258
+ class TabsWithClassesTestApp {
1259
+ @ViewChildren ( MatTab ) tabs : QueryList < MatTab > ;
1260
+ labelClassList ?: string | string [ ] ;
1261
+ bodyClassList ?: string | string [ ] ;
1262
+ }
0 commit comments