@@ -10,6 +10,7 @@ const html = `
10
10
<tab heading="tab0">tab0 content</tab>
11
11
<tab *ngFor="let tab of tabs"
12
12
[disabled]="tab.disabled"
13
+ [customClass]="tab.customClass"
13
14
[active]="tab.active"
14
15
[removable]="tab.removable"
15
16
(select)="_select($event)"
@@ -19,6 +20,10 @@ const html = `
19
20
</tabset>
20
21
` ;
21
22
23
+ function getTabItems ( nativeEl : HTMLElement ) : NodeListOf < Element > {
24
+ return nativeEl . querySelectorAll ( '.nav-item' ) ;
25
+ }
26
+
22
27
function getTabTitles ( nativeEl : HTMLElement ) : NodeListOf < Element > {
23
28
return nativeEl . querySelectorAll ( '.nav-link' ) ;
24
29
}
@@ -28,18 +33,18 @@ function getTabContent(nativeEl: HTMLElement): NodeListOf<Element> {
28
33
}
29
34
30
35
function expectActiveTabs ( nativeEl : HTMLElement , active : boolean [ ] ) : void {
31
- const tabTitles = getTabTitles ( nativeEl ) ;
36
+ const tabItems = getTabItems ( nativeEl ) ;
32
37
const tabContent = getTabContent ( nativeEl ) ;
33
38
34
- expect ( tabTitles . length ) . toBe ( active . length ) ;
39
+ expect ( tabItems . length ) . toBe ( active . length ) ;
35
40
expect ( tabContent . length ) . toBe ( active . length ) ;
36
41
37
42
for ( let i = 0 ; i < active . length ; i ++ ) {
38
43
if ( active [ i ] ) {
39
- expect ( tabTitles [ i ] . classList ) . toContain ( 'active' ) ;
44
+ expect ( tabItems [ i ] . classList ) . toContain ( 'active' ) ;
40
45
expect ( tabContent [ i ] . classList ) . toContain ( 'active' ) ;
41
46
} else {
42
- expect ( tabTitles [ i ] . classList ) . not . toContain ( 'active' ) ;
47
+ expect ( tabItems [ i ] . classList ) . not . toContain ( 'active' ) ;
43
48
expect ( tabContent [ i ] . classList ) . not . toContain ( 'active' ) ;
44
49
}
45
50
}
@@ -175,6 +180,31 @@ describe('Component: Tabs', () => {
175
180
heading : 'tab3'
176
181
} ) ) ;
177
182
} ) ;
183
+
184
+ it ( 'should set class on a tab item through [customClass]' , ( ) => {
185
+ const tabItems = getTabItems ( element ) ;
186
+
187
+ expect ( tabItems [ 1 ] . classList ) . toContain ( 'testCustomClass' ) ;
188
+ } ) ;
189
+
190
+ it ( 'should prevent interference of [customClass] and state classes' , ( ) => {
191
+ const tabItems = getTabItems ( element ) ;
192
+ const tabTitles = getTabTitles ( element ) ;
193
+
194
+ expect ( tabItems [ 1 ] . classList ) . toContain ( 'testCustomClass' ) ;
195
+
196
+ ( tabTitles [ 1 ] as HTMLAnchorElement ) . click ( ) ;
197
+ fixture . detectChanges ( ) ;
198
+ expect ( tabItems [ 1 ] . classList ) . toContain ( 'testCustomClass' ) ;
199
+ expectActiveTabs ( element , [ false , true , false , false ] ) ;
200
+
201
+ context . tabs [ 0 ] . customClass = 'otherCustomClass' ;
202
+ fixture . detectChanges ( ) ;
203
+
204
+ expect ( tabItems [ 1 ] . classList ) . not . toContain ( 'testCustomClass' ) ;
205
+ expect ( tabItems [ 1 ] . classList ) . toContain ( 'otherCustomClass' ) ;
206
+ expectActiveTabs ( element , [ false , true , false , false ] ) ;
207
+ } ) ;
178
208
} ) ;
179
209
180
210
@Component ( {
@@ -186,7 +216,7 @@ class TestTabsetComponent {
186
216
public isVertical :Boolean = false ;
187
217
public isJustified :Boolean = false ;
188
218
public tabs :any [ ] = [
189
- { title : 'tab1' , content : 'tab1 content' } ,
219
+ { title : 'tab1' , content : 'tab1 content' , customClass : 'testCustomClass' } ,
190
220
{ title : 'tab2' , content : 'tab2 content' , disabled : true } ,
191
221
{ title : 'tab3' , content : 'tab3 content' , removable : true }
192
222
] ;
0 commit comments