@@ -3,55 +3,86 @@ import {TestBed, async, ComponentFixture} from '@angular/core/testing';
33import { By } from '@angular/platform-browser' ;
44import { MdToolbarModule } from './index' ;
55
6-
76describe ( 'MdToolbar' , ( ) => {
87
9- let fixture : ComponentFixture < TestApp > ;
10- let testComponent : TestApp ;
11- let toolbarElement : HTMLElement ;
12-
138 beforeEach ( async ( ( ) => {
149 TestBed . configureTestingModule ( {
1510 imports : [ MdToolbarModule ] ,
16- declarations : [ TestApp ] ,
11+ declarations : [ ToolbarWithDefaultFirstRow , ToolbarWithoutDefaultFirstRow ] ,
1712 } ) ;
1813
1914 TestBed . compileComponents ( ) ;
2015 } ) ) ;
2116
22- beforeEach ( ( ) => {
23- fixture = TestBed . createComponent ( TestApp ) ;
24- testComponent = fixture . debugElement . componentInstance ;
25- toolbarElement = fixture . debugElement . query ( By . css ( 'md-toolbar' ) ) . nativeElement ;
26- } ) ;
17+ describe ( 'with default first row' , ( ) => {
18+ let fixture : ComponentFixture < ToolbarWithDefaultFirstRow > ;
19+ let testComponent : ToolbarWithDefaultFirstRow ;
20+ let toolbarElement : HTMLElement ;
21+ let toolbarRowElements : HTMLElement [ ] ;
22+
23+ beforeEach ( ( ) => {
24+ fixture = TestBed . createComponent ( ToolbarWithDefaultFirstRow ) ;
25+ testComponent = fixture . debugElement . componentInstance ;
26+ toolbarElement = fixture . debugElement . query ( By . css ( '.mat-toolbar' ) ) . nativeElement ;
27+ toolbarRowElements = fixture . debugElement . queryAll ( By . css ( '.mat-toolbar-row' ) )
28+ . map ( rowDebugElement => rowDebugElement . nativeElement ) ;
29+ } ) ;
2730
28- it ( 'should apply class based on color attribute' , ( ) => {
29- testComponent . toolbarColor = 'primary' ;
30- fixture . detectChanges ( ) ;
31+ it ( 'should apply class based on color attribute' , ( ) => {
32+ testComponent . toolbarColor = 'primary' ;
33+ fixture . detectChanges ( ) ;
3134
32- expect ( toolbarElement . classList . contains ( 'mat-primary' ) ) . toBe ( true ) ;
35+ expect ( toolbarElement . classList . contains ( 'mat-primary' ) ) . toBe ( true ) ;
3336
34- testComponent . toolbarColor = 'accent' ;
35- fixture . detectChanges ( ) ;
37+ testComponent . toolbarColor = 'accent' ;
38+ fixture . detectChanges ( ) ;
3639
37- expect ( toolbarElement . classList . contains ( 'mat-primary' ) ) . toBe ( false ) ;
38- expect ( toolbarElement . classList . contains ( 'mat-accent' ) ) . toBe ( true ) ;
40+ expect ( toolbarElement . classList . contains ( 'mat-primary' ) ) . toBe ( false ) ;
41+ expect ( toolbarElement . classList . contains ( 'mat-accent' ) ) . toBe ( true ) ;
42+
43+ testComponent . toolbarColor = 'warn' ;
44+ fixture . detectChanges ( ) ;
45+
46+ expect ( toolbarElement . classList . contains ( 'mat-accent' ) ) . toBe ( false ) ;
47+ expect ( toolbarElement . classList . contains ( 'mat-warn' ) ) . toBe ( true ) ;
48+ } ) ;
3949
40- testComponent . toolbarColor = 'warn' ;
41- fixture . detectChanges ( ) ;
50+ it ( 'should set the toolbar role on the host' , ( ) => {
51+ expect ( toolbarElement . getAttribute ( 'role' ) ) . toBe ( 'toolbar' ) ;
52+ } ) ;
4253
43- expect ( toolbarElement . classList . contains ( 'mat-accent' ) ) . toBe ( false ) ;
44- expect ( toolbarElement . classList . contains ( 'mat-warn' ) ) . toBe ( true ) ;
54+ it ( 'should generate a default first row if content is projected' , ( ) => {
55+ expect ( toolbarRowElements . length )
56+ . toBe ( 2 , 'Expected a default first row and a second row to be present.' ) ;
57+ } ) ;
4558 } ) ;
4659
47- it ( 'should set the toolbar role on the host' , ( ) => {
48- expect ( toolbarElement . getAttribute ( 'role' ) ) . toBe ( 'toolbar' ) ;
60+ describe ( 'without default first row' , ( ) => {
61+
62+ it ( 'should not generate a default first row if no content is projected' , ( ) => {
63+ const fixture = TestBed . createComponent ( ToolbarWithoutDefaultFirstRow ) ;
64+
65+ expect ( fixture . debugElement . queryAll ( By . css ( '.mat-toolbar-row' ) ) . length )
66+ . toBe ( 2 , 'Expected one toolbar row to be present while no content is projected.' ) ;
67+ } ) ;
4968 } ) ;
5069
70+
5171} ) ;
5272
5373
54- @Component ( { template : `<md-toolbar [color]="toolbarColor">Test Toolbar</md-toolbar>` } )
55- class TestApp {
74+ @Component ( { template : `
75+ <md-toolbar [color]="toolbarColor">
76+ First Row
77+ <md-toolbar-row>Second Row</md-toolbar-row>
78+ </md-toolbar>` } )
79+ class ToolbarWithDefaultFirstRow {
5680 toolbarColor : string ;
5781}
82+
83+ @Component ( { template : `
84+ <md-toolbar [color]="toolbarColor">
85+ <md-toolbar-row>First Row</md-toolbar-row>
86+ </md-toolbar>
87+ ` } )
88+ class ToolbarWithoutDefaultFirstRow { }
0 commit comments