1- import { async , ComponentFixture , TestBed , fakeAsync , tick } from '@angular/core/testing' ;
1+ import { async , ComponentFixture , fakeAsync , TestBed , tick } from '@angular/core/testing' ;
22import { MdTabsModule } from '../index' ;
33import { MdTabNavBar } from './tab-nav-bar' ;
44import { Component , ViewChild } from '@angular/core' ;
55import { By } from '@angular/platform-browser' ;
66import { ViewportRuler } from '../../core/overlay/position/viewport-ruler' ;
77import { FakeViewportRuler } from '../../core/overlay/position/fake-viewport-ruler' ;
8- import { dispatchMouseEvent , dispatchFakeEvent } from '../../core/testing/dispatch-events' ;
9- import { LayoutDirection , Dir } from '../../core/rtl/dir' ;
8+ import { dispatchFakeEvent , dispatchMouseEvent } from '../../core/testing/dispatch-events' ;
9+ import { Dir , LayoutDirection } from '../../core/rtl/dir' ;
1010import { Subject } from 'rxjs/Subject' ;
1111
1212
@@ -37,20 +37,19 @@ describe('MdTabNavBar', () => {
3737
3838 beforeEach ( ( ) => {
3939 fixture = TestBed . createComponent ( SimpleTabNavBarTestApp ) ;
40+ fixture . detectChanges ( ) ;
4041 } ) ;
4142
4243 it ( 'should change active index on click' , ( ) => {
43- let component = fixture . debugElement . componentInstance ;
44-
4544 // select the second link
4645 let tabLink = fixture . debugElement . queryAll ( By . css ( 'a' ) ) [ 1 ] ;
4746 tabLink . nativeElement . click ( ) ;
48- expect ( component . activeIndex ) . toBe ( 1 ) ;
47+ expect ( fixture . componentInstance . activeIndex ) . toBe ( 1 ) ;
4948
5049 // select the third link
5150 tabLink = fixture . debugElement . queryAll ( By . css ( 'a' ) ) [ 2 ] ;
5251 tabLink . nativeElement . click ( ) ;
53- expect ( component . activeIndex ) . toBe ( 2 ) ;
52+ expect ( fixture . componentInstance . activeIndex ) . toBe ( 2 ) ;
5453 } ) ;
5554
5655 it ( 'should re-align the ink bar when the direction changes' , ( ) => {
@@ -64,6 +63,31 @@ describe('MdTabNavBar', () => {
6463 expect ( inkBar . alignToElement ) . toHaveBeenCalled ( ) ;
6564 } ) ;
6665
66+ it ( 'should re-align the ink bar when the tabs list change' , ( ) => {
67+ const inkBar = fixture . componentInstance . tabNavBar . _inkBar ;
68+
69+ spyOn ( inkBar , 'alignToElement' ) ;
70+
71+ fixture . componentInstance . tabs = [ 1 , 2 , 3 , 4 ] ;
72+ fixture . detectChanges ( ) ;
73+
74+ expect ( inkBar . alignToElement ) . toHaveBeenCalled ( ) ;
75+ } ) ;
76+
77+ it ( 'should re-align the ink bar when the tab labels change the width' , done => {
78+ const inkBar = fixture . componentInstance . tabNavBar . _inkBar ;
79+
80+ const spy = spyOn ( inkBar , 'alignToElement' ) . and . callFake ( ( ) => {
81+ expect ( spy . calls . any ( ) ) . toBe ( true ) ;
82+ done ( ) ;
83+ } ) ;
84+
85+ fixture . componentInstance . label = 'label change' ;
86+ fixture . detectChanges ( ) ;
87+
88+ expect ( spy . calls . any ( ) ) . toBe ( false ) ;
89+ } ) ;
90+
6791 it ( 'should re-align the ink bar when the window is resized' , fakeAsync ( ( ) => {
6892 const inkBar = fixture . componentInstance . tabNavBar . _inkBar ;
6993
@@ -97,15 +121,21 @@ describe('MdTabNavBar', () => {
97121 selector : 'test-app' ,
98122 template : `
99123 <nav md-tab-nav-bar>
100- <a md-tab-link [active]="activeIndex === 0" (click)="activeIndex = 0">Tab One</a>
101- <a md-tab-link [active]="activeIndex === 1" (click)="activeIndex = 1">Tab Two</a>
102- <a md-tab-link [active]="activeIndex === 2" (click)="activeIndex = 2">Tab Three</a>
124+ <a md-tab-link
125+ *ngFor="let tab of tabs; let index = index"
126+ [active]="activeIndex === index"
127+ (click)="activeIndex = index">
128+ Tab link {{label}}
129+ </a>
103130 </nav>
104131 `
105132} )
106133class SimpleTabNavBarTestApp {
107134 @ViewChild ( MdTabNavBar ) tabNavBar : MdTabNavBar ;
108135
136+ label = '' ;
137+ tabs = [ 0 , 1 , 2 ] ;
138+
109139 activeIndex = 0 ;
110140}
111141
0 commit comments