@@ -3,55 +3,105 @@ 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 : [ ToolbarSingleRow , ToolbarMultipleRows , ToolbarMixedRowModes ] ,
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 single row' , ( ) => {
18+ let fixture : ComponentFixture < ToolbarSingleRow > ;
19+ let testComponent : ToolbarSingleRow ;
20+ let toolbarElement : HTMLElement ;
21+
22+ beforeEach ( ( ) => {
23+ fixture = TestBed . createComponent ( ToolbarSingleRow ) ;
24+ testComponent = fixture . debugElement . componentInstance ;
25+ toolbarElement = fixture . debugElement . query ( By . css ( '.mat-toolbar' ) ) . nativeElement ;
26+ } ) ;
27+
28+ it ( 'should apply class based on color attribute' , ( ) => {
29+ testComponent . toolbarColor = 'primary' ;
30+ fixture . detectChanges ( ) ;
2731
28- it ( 'should apply class based on color attribute' , ( ) => {
29- testComponent . toolbarColor = 'primary' ;
30- fixture . detectChanges ( ) ;
32+ expect ( toolbarElement . classList . contains ( 'mat-primary' ) ) . toBe ( true ) ;
3133
32- expect ( toolbarElement . classList . contains ( 'mat-primary' ) ) . toBe ( true ) ;
34+ testComponent . toolbarColor = 'accent' ;
35+ fixture . detectChanges ( ) ;
3336
34- testComponent . toolbarColor = 'accent' ;
35- fixture . detectChanges ( ) ;
37+ expect ( toolbarElement . classList . contains ( 'mat-primary' ) ) . toBe ( false ) ;
38+ expect ( toolbarElement . classList . contains ( 'mat-accent' ) ) . toBe ( true ) ;
3639
37- expect ( toolbarElement . classList . contains ( 'mat-primary' ) ) . toBe ( false ) ;
38- expect ( toolbarElement . classList . contains ( 'mat-accent' ) ) . toBe ( true ) ;
40+ testComponent . toolbarColor = 'warn' ;
41+ fixture . detectChanges ( ) ;
42+
43+ expect ( toolbarElement . classList . contains ( 'mat-accent' ) ) . toBe ( false ) ;
44+ expect ( toolbarElement . classList . contains ( 'mat-warn' ) ) . toBe ( true ) ;
45+ } ) ;
3946
40- testComponent . toolbarColor = 'warn' ;
41- fixture . detectChanges ( ) ;
47+ it ( 'should set the toolbar role on the host' , ( ) => {
48+ expect ( toolbarElement . getAttribute ( 'role' ) ) . toBe ( 'toolbar' ) ;
49+ } ) ;
4250
43- expect ( toolbarElement . classList . contains ( 'mat-accent' ) ) . toBe ( false ) ;
44- expect ( toolbarElement . classList . contains ( 'mat-warn' ) ) . toBe ( true ) ;
51+ it ( 'should not wrap the first row contents inside of a generated element' , ( ) => {
52+ expect ( toolbarElement . firstElementChild ! . tagName ) . toBe ( 'SPAN' ,
53+ 'Expected the <span> element of the first row to be a direct child of the toolbar' ) ;
54+ } ) ;
4555 } ) ;
4656
47- it ( 'should set the toolbar role on the host' , ( ) => {
48- expect ( toolbarElement . getAttribute ( 'role' ) ) . toBe ( 'toolbar' ) ;
57+ describe ( 'with multiple rows' , ( ) => {
58+
59+ it ( 'should project each toolbar-row element inside of the toolbar' , ( ) => {
60+ const fixture = TestBed . createComponent ( ToolbarMultipleRows ) ;
61+ fixture . detectChanges ( ) ;
62+
63+ expect ( fixture . debugElement . queryAll ( By . css ( '.mat-toolbar > .mat-toolbar-row' ) ) . length )
64+ . toBe ( 2 , 'Expected one toolbar row to be present while no content is projected.' ) ;
65+ } ) ;
66+
67+ it ( 'should throw an error if different toolbar modes are mixed' , ( ) => {
68+ expect ( ( ) => {
69+ const fixture = TestBed . createComponent ( ToolbarMixedRowModes ) ;
70+ fixture . detectChanges ( ) ;
71+ } ) . toThrowError ( / a t t e m p t i n g t o c o m b i n e d i f f e r e n t / i) ;
72+ } ) ;
4973 } ) ;
5074
5175} ) ;
5276
5377
54- @Component ( { template : `<md-toolbar [color]="toolbarColor">Test Toolbar</md-toolbar>` } )
55- class TestApp {
78+ @Component ( {
79+ template : `
80+ <md-toolbar [color]="toolbarColor">
81+ <span>First Row</span>
82+ </md-toolbar>
83+ `
84+ } )
85+ class ToolbarSingleRow {
5686 toolbarColor : string ;
5787}
88+
89+ @Component ( {
90+ template : `
91+ <md-toolbar>
92+ <md-toolbar-row>First Row</md-toolbar-row>
93+ <md-toolbar-row>Second Row</md-toolbar-row>
94+ </md-toolbar>
95+ `
96+ } )
97+ class ToolbarMultipleRows { }
98+
99+ @Component ( {
100+ template : `
101+ <md-toolbar>
102+ First Row
103+ <md-toolbar-row>Second Row</md-toolbar-row>
104+ </md-toolbar>
105+ `
106+ } )
107+ class ToolbarMixedRowModes { }
0 commit comments