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,62 @@ 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/body classes' , ( ) => {
773
+ expect ( labelElements [ 1 ] . nativeElement . classList ) . toContain ( 'hardcoded-label-class' ) ;
774
+ expect ( bodyElements [ 1 ] . nativeElement . classList ) . toContain ( 'hardcoded-body-class' ) ;
775
+ } ) ;
776
+
777
+ it ( 'should set classes as strings dynamically' , ( ) => {
778
+ expect ( labelElements [ 0 ] . nativeElement . classList ) . not . toContain ( 'custom-label-class' ) ;
779
+ expect ( bodyElements [ 0 ] . nativeElement . classList ) . not . toContain ( 'custom-body-class' ) ;
780
+
781
+ fixture . componentInstance . labelClassList = 'custom-label-class' ;
782
+ fixture . componentInstance . bodyClassList = 'custom-body-class' ;
783
+ fixture . detectChanges ( ) ;
784
+
785
+ expect ( labelElements [ 0 ] . nativeElement . classList ) . toContain ( 'custom-label-class' ) ;
786
+ expect ( bodyElements [ 0 ] . nativeElement . classList ) . toContain ( 'custom-body-class' ) ;
787
+
788
+ delete fixture . componentInstance . labelClassList ;
789
+ delete fixture . componentInstance . bodyClassList ;
790
+ fixture . detectChanges ( ) ;
791
+
792
+ expect ( labelElements [ 0 ] . nativeElement . classList ) . not . toContain ( 'custom-label-class' ) ;
793
+ expect ( bodyElements [ 0 ] . nativeElement . classList ) . not . toContain ( 'custom-body-class' ) ;
794
+ } ) ;
795
+
796
+ it ( 'should set classes as strings array dynamically' , ( ) => {
797
+ expect ( labelElements [ 0 ] . nativeElement . classList ) . not . toContain ( 'custom-label-class' ) ;
798
+ expect ( bodyElements [ 0 ] . nativeElement . classList ) . not . toContain ( 'custom-body-class' ) ;
799
+
800
+ fixture . componentInstance . labelClassList = [ 'custom-label-class' ] ;
801
+ fixture . componentInstance . bodyClassList = [ 'custom-body-class' ] ;
802
+ fixture . detectChanges ( ) ;
803
+
804
+ expect ( labelElements [ 0 ] . nativeElement . classList ) . toContain ( 'custom-label-class' ) ;
805
+ expect ( bodyElements [ 0 ] . nativeElement . classList ) . toContain ( 'custom-body-class' ) ;
806
+
807
+ delete fixture . componentInstance . labelClassList ;
808
+ delete fixture . componentInstance . bodyClassList ;
809
+ fixture . detectChanges ( ) ;
810
+
811
+ expect ( labelElements [ 0 ] . nativeElement . classList ) . not . toContain ( 'custom-label-class' ) ;
812
+ expect ( bodyElements [ 0 ] . nativeElement . classList ) . not . toContain ( 'custom-body-class' ) ;
813
+ } ) ;
814
+ } ) ;
815
+
759
816
/**
760
817
* Checks that the `selectedIndex` has been updated; checks that the label and body have their
761
818
* respective `active` classes
@@ -935,6 +992,7 @@ class SimpleTabsTestApp {
935
992
animationDone ( ) { }
936
993
}
937
994
995
+
938
996
@Component ( {
939
997
template : `
940
998
<mat-tab-group class="tab-group"
@@ -965,6 +1023,7 @@ class SimpleDynamicTabsTestApp {
965
1023
}
966
1024
}
967
1025
1026
+
968
1027
@Component ( {
969
1028
template : `
970
1029
<mat-tab-group class="tab-group" [(selectedIndex)]="selectedIndex">
@@ -990,8 +1049,8 @@ class BindedTabsTestApp {
990
1049
}
991
1050
}
992
1051
1052
+
993
1053
@Component ( {
994
- selector : 'test-app' ,
995
1054
template : `
996
1055
<mat-tab-group class="tab-group">
997
1056
<mat-tab>
@@ -1014,6 +1073,7 @@ class DisabledTabsTestApp {
1014
1073
isDisabled = false ;
1015
1074
}
1016
1075
1076
+
1017
1077
@Component ( {
1018
1078
template : `
1019
1079
<mat-tab-group class="tab-group">
@@ -1059,7 +1119,6 @@ class TabGroupWithSimpleApi {
1059
1119
1060
1120
1061
1121
@Component ( {
1062
- selector : 'nested-tabs' ,
1063
1122
template : `
1064
1123
<mat-tab-group>
1065
1124
<mat-tab label="One">Tab one content</mat-tab>
@@ -1077,8 +1136,8 @@ class NestedTabs {
1077
1136
@ViewChildren ( MatTabGroup ) groups : QueryList < MatTabGroup > ;
1078
1137
}
1079
1138
1139
+
1080
1140
@Component ( {
1081
- selector : 'template-tabs' ,
1082
1141
template : `
1083
1142
<mat-tab-group>
1084
1143
<mat-tab label="One">
@@ -1091,11 +1150,11 @@ class NestedTabs {
1091
1150
</mat-tab>
1092
1151
</mat-tab-group>
1093
1152
` ,
1094
- } )
1095
- class TemplateTabs { }
1153
+ } )
1154
+ class TemplateTabs { }
1096
1155
1097
1156
1098
- @Component ( {
1157
+ @Component ( {
1099
1158
template : `
1100
1159
<mat-tab-group>
1101
1160
<mat-tab [aria-label]="ariaLabel" [aria-labelledby]="ariaLabelledby"></mat-tab>
@@ -1160,6 +1219,7 @@ class TabGroupWithInkBarFitToContent {
1160
1219
fitInkBarToContent = true ;
1161
1220
}
1162
1221
1222
+
1163
1223
@Component ( {
1164
1224
template : `
1165
1225
<div style="height: 300px; background-color: aqua">
@@ -1202,3 +1262,22 @@ class TabGroupWithSpaceAbove {
1202
1262
} )
1203
1263
class NestedTabGroupWithLabel {
1204
1264
}
1265
+
1266
+
1267
+ @Component ( {
1268
+ template : `
1269
+ <mat-tab-group class="tab-group">
1270
+ <mat-tab label="Tab One" [labelClass]="labelClassList" [bodyClass]="bodyClassList">
1271
+ Tab one content
1272
+ </mat-tab>
1273
+ <mat-tab label="Tab Two" labelClass="hardcoded-label-class"
1274
+ bodyClass="hardcoded-body-class">
1275
+ Tab two content
1276
+ </mat-tab>
1277
+ </mat-tab-group>
1278
+ ` ,
1279
+ } )
1280
+ class TabsWithClassesTestApp {
1281
+ labelClassList ?: string | string [ ] ;
1282
+ bodyClassList ?: string | string [ ] ;
1283
+ }
0 commit comments