@@ -2,18 +2,20 @@ import { Component } from '@angular/core';
2
2
import { ComponentFixture , fakeAsync , TestBed , tick } from '@angular/core/testing' ;
3
3
import { TabModule } from './tab.module' ;
4
4
5
- const TABS : any [ ] = [
5
+ const TABS = [
6
6
{
7
7
heading : 'tab1' ,
8
8
content : 'tab1 content' ,
9
9
active : true ,
10
- icon : '<img src="./assets/images/icon_tabbar.png">' ,
10
+ iconClassName : '' ,
11
+ icon : './assets/images/icon_tabbar.png' ,
11
12
badge : 8 ,
12
13
} ,
13
14
{
14
15
heading : 'tab2' ,
15
16
content : 'tab2 content' ,
16
17
active : false ,
18
+ iconClassName : '' ,
17
19
icon : '<img src="./assets/images/icon_tabbar.png">' ,
18
20
badge : 'dot' ,
19
21
} ,
@@ -26,6 +28,7 @@ const navbar_html = `
26
28
[heading]="item.heading"
27
29
[disabled]="item.disabled"
28
30
[active]="item.active"
31
+ [iconClassName]="item.iconClassName"
29
32
[icon]="item.icon"
30
33
[badge]="item.badge"
31
34
(select)="_select($event)"
@@ -39,6 +42,7 @@ const tabbar_html = `
39
42
[heading]="item.heading"
40
43
[disabled]="item.disabled"
41
44
[active]="item.active"
45
+ [iconClassName]="item.iconClassName"
42
46
[icon]="item.icon"
43
47
[badge]="item.badge"
44
48
(select)="_select($event)"
@@ -51,8 +55,8 @@ function getItems(nativeEl: HTMLElement): NodeListOf<Element> {
51
55
return nativeEl . querySelectorAll ( '.weui-navbar__item' ) ;
52
56
}
53
57
54
- function getItemsByTabbar ( nativeEl : HTMLElement ) : NodeListOf < Element > {
55
- return nativeEl . querySelectorAll ( '.weui-tabbar__item' ) ;
58
+ function getItemsByTabbar ( nativeEl : HTMLElement , index : number ) : HTMLElement {
59
+ return nativeEl . querySelectorAll ( '.weui-tabbar__item' ) [ index ] as HTMLElement ;
56
60
}
57
61
58
62
function getContents ( nativeEl : HTMLElement ) : NodeListOf < Element > {
@@ -79,7 +83,7 @@ function expectActiveTabs(nativeEl: HTMLElement, action: boolean[]): void {
79
83
describe ( 'Component: Tabs' , ( ) => {
80
84
let fixture : ComponentFixture < TestTabComponent > ;
81
85
let context : TestTabComponent ;
82
- let el : any ;
86
+ let el : HTMLElement ;
83
87
84
88
describe ( '[Navbar]' , ( ) => {
85
89
beforeEach ( fakeAsync ( ( ) => {
@@ -160,15 +164,27 @@ describe('Component: Tabs', () => {
160
164
} ) ) ;
161
165
162
166
it ( 'should set tab has icon' , ( ) => {
163
- expect ( ( getItemsByTabbar ( el ) [ 0 ] as HTMLElement ) . querySelector ( '.weui-tabbar__icon' ) ) . not . toBeNull ( ) ;
167
+ expect ( getItemsByTabbar ( el , 0 ) . querySelector ( '.weui-tabbar__icon' ) ) . not . toBeNull ( ) ;
164
168
} ) ;
165
169
166
170
it ( 'should set tab badge number value' , ( ) => {
167
- expect ( ( getItemsByTabbar ( el ) [ 0 ] as HTMLElement ) . querySelector ( '.weui-badge' ) ! . innerHTML ) . toBe ( '8' ) ;
171
+ expect ( getItemsByTabbar ( el , 0 ) . querySelector ( '.weui-badge' ) ! . innerHTML ) . toBe ( '8' ) ;
168
172
} ) ;
169
173
170
174
it ( 'should set tab badge dot value' , ( ) => {
171
- expect ( ( getItemsByTabbar ( el ) [ 1 ] as HTMLElement ) . querySelector ( '.weui-badge' ) ! . classList ) . toContain ( 'weui-badge_dot' ) ;
175
+ expect ( getItemsByTabbar ( el , 1 ) . querySelector ( '.weui-badge' ) ! . classList ) . toContain ( 'weui-badge_dot' ) ;
176
+ } ) ;
177
+
178
+ it ( 'should be support valid image url' , ( ) => {
179
+ context . tabs = [ { icon : '1.jpg' } ] ;
180
+ fixture . detectChanges ( ) ;
181
+ expect ( getItemsByTabbar ( el , 0 ) . querySelector ( '.weui-tabbar__icon' ) ) . not . toBeNull ( ) ;
182
+ } ) ;
183
+
184
+ it ( '#iconClassName' , ( ) => {
185
+ context . tabs = [ { iconClassName : 'aaa' } ] ;
186
+ fixture . detectChanges ( ) ;
187
+ expect ( getItemsByTabbar ( el , 0 ) . querySelector ( '.weui-tabbar__icon' ) ! . classList ) . toContain ( 'aaa' ) ;
172
188
} ) ;
173
189
} ) ;
174
190
} ) ;
0 commit comments