@@ -3,55 +3,105 @@ import {TestBed, async, ComponentFixture} from '@angular/core/testing';
3
3
import { By } from '@angular/platform-browser' ;
4
4
import { MdToolbarModule } from './index' ;
5
5
6
-
7
6
describe ( 'MdToolbar' , ( ) => {
8
7
9
- let fixture : ComponentFixture < TestApp > ;
10
- let testComponent : TestApp ;
11
- let toolbarElement : HTMLElement ;
12
-
13
8
beforeEach ( async ( ( ) => {
14
9
TestBed . configureTestingModule ( {
15
10
imports : [ MdToolbarModule ] ,
16
- declarations : [ TestApp ] ,
11
+ declarations : [ ToolbarSingleRow , ToolbarMultipleRows , ToolbarMixedRowModes ] ,
17
12
} ) ;
18
13
19
14
TestBed . compileComponents ( ) ;
20
15
} ) ) ;
21
16
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 ( ) ;
27
31
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 ) ;
31
33
32
- expect ( toolbarElement . classList . contains ( 'mat-primary' ) ) . toBe ( true ) ;
34
+ testComponent . toolbarColor = 'accent' ;
35
+ fixture . detectChanges ( ) ;
33
36
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 ) ;
36
39
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
+ } ) ;
39
46
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
+ } ) ;
42
50
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
+ } ) ;
45
55
} ) ;
46
56
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
+ } ) ;
49
73
} ) ;
50
74
51
75
} ) ;
52
76
53
77
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 {
56
86
toolbarColor : string ;
57
87
}
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