@@ -13,7 +13,8 @@ describe('MdTabGroup', () => {
13
13
declarations : [
14
14
SimpleTabsTestApp ,
15
15
AsyncTabsTestApp ,
16
- DisabledTabsTestApp
16
+ DisabledTabsTestApp ,
17
+ TabGroupWithSimpleApi ,
17
18
] ,
18
19
} ) ;
19
20
@@ -241,6 +242,37 @@ describe('MdTabGroup', () => {
241
242
} ) ) ;
242
243
} ) ;
243
244
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
+
244
276
/**
245
277
* Checks that the `selectedIndex` has been updated; checks that the label and body have the
246
278
* `md-tab-active` class
@@ -260,26 +292,33 @@ describe('MdTabGroup', () => {
260
292
. query ( By . css ( `#${ tabLabelElement . id } ` ) ) . nativeElement ;
261
293
expect ( tabContentElement . classList . contains ( 'md-tab-active' ) ) . toBe ( true ) ;
262
294
}
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
+ }
263
303
} ) ;
264
304
265
305
@Component ( {
266
- selector : 'test-app' ,
267
306
template : `
268
307
<md-tab-group class="tab-group"
269
308
[(selectedIndex)]="selectedIndex"
270
309
(focusChange)="handleFocus($event)"
271
310
(selectChange)="handleSelection($event)">
272
311
<md-tab>
273
312
<template md-tab-label>Tab One</template>
274
- <template md-tab-content> Tab one content</template>
313
+ Tab one content
275
314
</md-tab>
276
315
<md-tab>
277
316
<template md-tab-label>Tab Two</template>
278
- <template md-tab-content> Tab two content</template>
317
+ Tab two content
279
318
</md-tab>
280
319
<md-tab>
281
320
<template md-tab-label>Tab Three</template>
282
- <template md-tab-content> Tab three content</template>
321
+ Tab three content
283
322
</md-tab>
284
323
</md-tab-group>
285
324
`
@@ -302,28 +341,27 @@ class SimpleTabsTestApp {
302
341
<md-tab-group class="tab-group">
303
342
<md-tab>
304
343
<template md-tab-label>Tab One</template>
305
- <template md-tab-content> Tab one content</template>
344
+ Tab one content
306
345
</md-tab>
307
346
<md-tab disabled>
308
347
<template md-tab-label>Tab Two</template>
309
- <template md-tab-content> Tab two content</template>
348
+ Tab two content
310
349
</md-tab>
311
350
<md-tab>
312
351
<template md-tab-label>Tab Three</template>
313
- <template md-tab-content> Tab three content</template>
352
+ Tab three content
314
353
</md-tab>
315
354
</md-tab-group>
316
355
` ,
317
356
} )
318
357
class DisabledTabsTestApp { }
319
358
320
359
@Component ( {
321
- selector : 'test-app' ,
322
360
template : `
323
361
<md-tab-group class="tab-group">
324
362
<md-tab *ngFor="let tab of tabs | async">
325
363
<template md-tab-label>{{ tab.label }}</template>
326
- <template md-tab-content> {{ tab.content }}</template>
364
+ {{ tab.content }}
327
365
</md-tab>
328
366
</md-tab-group>
329
367
`
@@ -343,3 +381,18 @@ class AsyncTabsTestApp {
343
381
} ) ;
344
382
}
345
383
}
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