@@ -2,7 +2,6 @@ import {inject, async, ComponentFixture, TestBed} from '@angular/core/testing';
2
2
import { NgModule , Component , Directive , ViewChild , ViewContainerRef } from '@angular/core' ;
3
3
import { MdSnackBar , MdSnackBarModule } from './snack-bar' ;
4
4
import { OverlayContainer , MdLiveAnnouncer } from '../core' ;
5
- import { MdSnackBarConfig } from './snack-bar-config' ;
6
5
import { SimpleSnackBar } from './simple-snack-bar' ;
7
6
8
7
@@ -50,16 +49,33 @@ describe('MdSnackBar', () => {
50
49
} ) ;
51
50
52
51
it ( 'should have the role of alert' , ( ) => {
53
- let config = new MdSnackBarConfig ( testViewContainerRef ) ;
52
+ let config = { viewContainerRef : testViewContainerRef } ;
54
53
snackBar . open ( simpleMessage , simpleActionLabel , config ) ;
55
54
56
55
let containerElement = overlayContainerElement . querySelector ( 'snack-bar-container' ) ;
57
56
expect ( containerElement . getAttribute ( 'role' ) )
58
57
. toBe ( 'alert' , 'Expected snack bar container to have role="alert"' ) ;
59
58
} ) ;
60
59
60
+ it ( 'should open and close a snackbar without a ViewContainerRef' , async ( ( ) => {
61
+ let snackBarRef = snackBar . open ( 'Snack time!' , 'CHEW' ) ;
62
+ viewContainerFixture . detectChanges ( ) ;
63
+
64
+ let messageElement = overlayContainerElement . querySelector ( '.md-simple-snackbar-message' ) ;
65
+ expect ( messageElement . textContent )
66
+ . toBe ( 'Snack time!' , 'Expected snack bar to show a message without a ViewContainerRef' ) ;
67
+
68
+ snackBarRef . dismiss ( ) ;
69
+ viewContainerFixture . detectChanges ( ) ;
70
+
71
+ viewContainerFixture . whenStable ( ) . then ( ( ) => {
72
+ expect ( overlayContainerElement . childNodes . length )
73
+ . toBe ( 0 , 'Expected snack bar to be dismissed without a ViewContainerRef' ) ;
74
+ } ) ;
75
+ } ) ) ;
76
+
61
77
it ( 'should open a simple message with a button' , ( ) => {
62
- let config = new MdSnackBarConfig ( testViewContainerRef ) ;
78
+ let config = { viewContainerRef : testViewContainerRef } ;
63
79
let snackBarRef = snackBar . open ( simpleMessage , simpleActionLabel , config ) ;
64
80
65
81
viewContainerFixture . detectChanges ( ) ;
@@ -84,7 +100,7 @@ describe('MdSnackBar', () => {
84
100
} ) ;
85
101
86
102
it ( 'should open a simple message with no button' , ( ) => {
87
- let config = new MdSnackBarConfig ( testViewContainerRef ) ;
103
+ let config = { viewContainerRef : testViewContainerRef } ;
88
104
let snackBarRef = snackBar . open ( simpleMessage , null , config ) ;
89
105
90
106
viewContainerFixture . detectChanges ( ) ;
@@ -104,7 +120,7 @@ describe('MdSnackBar', () => {
104
120
} ) ;
105
121
106
122
it ( 'should dismiss the snack bar and remove itself from the view' , async ( ( ) => {
107
- let config = new MdSnackBarConfig ( testViewContainerRef ) ;
123
+ let config = { viewContainerRef : testViewContainerRef } ;
108
124
let dismissObservableCompleted = false ;
109
125
110
126
let snackBarRef = snackBar . open ( simpleMessage , null , config ) ;
@@ -127,7 +143,7 @@ describe('MdSnackBar', () => {
127
143
} ) ) ;
128
144
129
145
it ( 'should open a custom component' , ( ) => {
130
- let config = new MdSnackBarConfig ( testViewContainerRef ) ;
146
+ let config = { viewContainerRef : testViewContainerRef } ;
131
147
let snackBarRef = snackBar . openFromComponent ( BurritosNotification , config ) ;
132
148
133
149
expect ( snackBarRef . instance )
@@ -139,7 +155,7 @@ describe('MdSnackBar', () => {
139
155
} ) ;
140
156
141
157
it ( 'should set the animation state to visible on entry' , ( ) => {
142
- let config = new MdSnackBarConfig ( testViewContainerRef ) ;
158
+ let config = { viewContainerRef : testViewContainerRef } ;
143
159
let snackBarRef = snackBar . open ( simpleMessage , null , config ) ;
144
160
145
161
viewContainerFixture . detectChanges ( ) ;
@@ -148,7 +164,7 @@ describe('MdSnackBar', () => {
148
164
} ) ;
149
165
150
166
it ( 'should set the animation state to complete on exit' , ( ) => {
151
- let config = new MdSnackBarConfig ( testViewContainerRef ) ;
167
+ let config = { viewContainerRef : testViewContainerRef } ;
152
168
let snackBarRef = snackBar . open ( simpleMessage , null , config ) ;
153
169
snackBarRef . dismiss ( ) ;
154
170
@@ -159,15 +175,15 @@ describe('MdSnackBar', () => {
159
175
160
176
it ( `should set the old snack bar animation state to complete and the new snack bar animation
161
177
state to visible on entry of new snack bar` , async ( ( ) => {
162
- let config = new MdSnackBarConfig ( testViewContainerRef ) ;
178
+ let config = { viewContainerRef : testViewContainerRef } ;
163
179
let snackBarRef = snackBar . open ( simpleMessage , null , config ) ;
164
180
let dismissObservableCompleted = false ;
165
181
166
182
viewContainerFixture . detectChanges ( ) ;
167
183
expect ( snackBarRef . containerInstance . animationState )
168
184
. toBe ( 'visible' , `Expected the animation state would be 'visible'.` ) ;
169
185
170
- let config2 = new MdSnackBarConfig ( testViewContainerRef ) ;
186
+ let config2 = { viewContainerRef : testViewContainerRef } ;
171
187
let snackBarRef2 = snackBar . open ( simpleMessage , null , config2 ) ;
172
188
173
189
viewContainerFixture . detectChanges ( ) ;
@@ -185,7 +201,7 @@ describe('MdSnackBar', () => {
185
201
} ) ) ;
186
202
187
203
it ( 'should open a new snackbar after dismissing a previous snackbar' , async ( ( ) => {
188
- let config = new MdSnackBarConfig ( testViewContainerRef ) ;
204
+ let config = { viewContainerRef : testViewContainerRef } ;
189
205
let snackBarRef = snackBar . open ( simpleMessage , 'DISMISS' , config ) ;
190
206
viewContainerFixture . detectChanges ( ) ;
191
207
0 commit comments