@@ -13,7 +13,8 @@ describe('MdTabGroup', () => {
1313 declarations : [
1414 SimpleTabsTestApp ,
1515 AsyncTabsTestApp ,
16- DisabledTabsTestApp
16+ DisabledTabsTestApp ,
17+ TabGroupWithSimpleApi ,
1718 ] ,
1819 } ) ;
1920
@@ -241,6 +242,37 @@ describe('MdTabGroup', () => {
241242 } ) ) ;
242243 } ) ;
243244
245+ describe ( 'with simple api' , ( ) => {
246+ let fixture : ComponentFixture < TabGroupWithSimpleApi > ;
247+ let tabGroup : MdTabGroup ;
248+
249+ beforeEach ( ( ) => {
250+ fixture = TestBed . createComponent ( TabGroupWithSimpleApi ) ;
251+ fixture . detectChanges ( ) ;
252+
253+ tabGroup =
254+ fixture . debugElement . query ( By . directive ( MdTabGroup ) ) . componentInstance as MdTabGroup ;
255+ } ) ;
256+
257+ it ( 'should support a tab-group with the simple api' , ( ) => {
258+ expect ( getSelectedLabel ( fixture ) . textContent ) . toMatch ( 'Junk food' ) ;
259+ expect ( getSelectedContent ( fixture ) . textContent ) . toMatch ( 'Pizza, fries' ) ;
260+
261+ tabGroup . selectedIndex = 2 ;
262+ fixture . detectChanges ( ) ;
263+
264+ expect ( getSelectedLabel ( fixture ) . textContent ) . toMatch ( 'Fruit' ) ;
265+ expect ( getSelectedContent ( fixture ) . textContent ) . toMatch ( 'Apples, grapes' ) ;
266+
267+ fixture . componentInstance . otherLabel = 'Chips' ;
268+ fixture . componentInstance . otherContent = 'Salt, vinegar' ;
269+ fixture . detectChanges ( ) ;
270+
271+ expect ( getSelectedLabel ( fixture ) . textContent ) . toMatch ( 'Chips' ) ;
272+ expect ( getSelectedContent ( fixture ) . textContent ) . toMatch ( 'Salt, vinegar' ) ;
273+ } ) ;
274+ } ) ;
275+
244276 /**
245277 * Checks that the `selectedIndex` has been updated; checks that the label and body have the
246278 * `md-tab-active` class
@@ -260,26 +292,33 @@ describe('MdTabGroup', () => {
260292 . query ( By . css ( `#${ tabLabelElement . id } ` ) ) . nativeElement ;
261293 expect ( tabContentElement . classList . contains ( 'md-tab-active' ) ) . toBe ( true ) ;
262294 }
295+
296+ function getSelectedLabel ( fixture : ComponentFixture < any > ) : HTMLElement {
297+ return fixture . nativeElement . querySelector ( '.md-tab-label.md-tab-active' ) ;
298+ }
299+
300+ function getSelectedContent ( fixture : ComponentFixture < any > ) : HTMLElement {
301+ return fixture . nativeElement . querySelector ( '.md-tab-body.md-tab-active' ) ;
302+ }
263303} ) ;
264304
265305@Component ( {
266- selector : 'test-app' ,
267306 template : `
268307 <md-tab-group class="tab-group"
269308 [(selectedIndex)]="selectedIndex"
270309 (focusChange)="handleFocus($event)"
271310 (selectChange)="handleSelection($event)">
272311 <md-tab>
273312 <template md-tab-label>Tab One</template>
274- <template md-tab-content> Tab one content</template>
313+ Tab one content
275314 </md-tab>
276315 <md-tab>
277316 <template md-tab-label>Tab Two</template>
278- <template md-tab-content> Tab two content</template>
317+ Tab two content
279318 </md-tab>
280319 <md-tab>
281320 <template md-tab-label>Tab Three</template>
282- <template md-tab-content> Tab three content</template>
321+ Tab three content
283322 </md-tab>
284323 </md-tab-group>
285324 `
@@ -302,28 +341,27 @@ class SimpleTabsTestApp {
302341 <md-tab-group class="tab-group">
303342 <md-tab>
304343 <template md-tab-label>Tab One</template>
305- <template md-tab-content> Tab one content</template>
344+ Tab one content
306345 </md-tab>
307346 <md-tab disabled>
308347 <template md-tab-label>Tab Two</template>
309- <template md-tab-content> Tab two content</template>
348+ Tab two content
310349 </md-tab>
311350 <md-tab>
312351 <template md-tab-label>Tab Three</template>
313- <template md-tab-content> Tab three content</template>
352+ Tab three content
314353 </md-tab>
315354 </md-tab-group>
316355 ` ,
317356} )
318357class DisabledTabsTestApp { }
319358
320359@Component ( {
321- selector : 'test-app' ,
322360 template : `
323361 <md-tab-group class="tab-group">
324362 <md-tab *ngFor="let tab of tabs | async">
325363 <template md-tab-label>{{ tab.label }}</template>
326- <template md-tab-content> {{ tab.content }}</template>
364+ {{ tab.content }}
327365 </md-tab>
328366 </md-tab-group>
329367 `
@@ -343,3 +381,18 @@ class AsyncTabsTestApp {
343381 } ) ;
344382 }
345383}
384+
385+
386+ @Component ( {
387+ template : `
388+ <md-tab-group>
389+ <md-tab label="Junk food"> Pizza, fries </md-tab>
390+ <md-tab label="Vegetables"> Broccoli, spinach </md-tab>
391+ <md-tab [label]="otherLabel"> {{otherContent}} </md-tab>
392+ </md-tab-group>
393+ `
394+ } )
395+ class TabGroupWithSimpleApi {
396+ otherLabel = 'Fruit' ;
397+ otherContent = 'Apples, grapes' ;
398+ }
0 commit comments