@@ -2,7 +2,6 @@ import {inject, async, ComponentFixture, TestBed} from '@angular/core/testing';
22import { NgModule , Component , Directive , ViewChild , ViewContainerRef } from '@angular/core' ;
33import { MdSnackBar , MdSnackBarModule } from './snack-bar' ;
44import { OverlayContainer , MdLiveAnnouncer } from '../core' ;
5- import { MdSnackBarConfig } from './snack-bar-config' ;
65import { SimpleSnackBar } from './simple-snack-bar' ;
76
87
@@ -50,16 +49,33 @@ describe('MdSnackBar', () => {
5049 } ) ;
5150
5251 it ( 'should have the role of alert' , ( ) => {
53- let config = new MdSnackBarConfig ( testViewContainerRef ) ;
52+ let config = { viewContainerRef : testViewContainerRef } ;
5453 snackBar . open ( simpleMessage , simpleActionLabel , config ) ;
5554
5655 let containerElement = overlayContainerElement . querySelector ( 'snack-bar-container' ) ;
5756 expect ( containerElement . getAttribute ( 'role' ) )
5857 . toBe ( 'alert' , 'Expected snack bar container to have role="alert"' ) ;
5958 } ) ;
6059
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+
6177 it ( 'should open a simple message with a button' , ( ) => {
62- let config = new MdSnackBarConfig ( testViewContainerRef ) ;
78+ let config = { viewContainerRef : testViewContainerRef } ;
6379 let snackBarRef = snackBar . open ( simpleMessage , simpleActionLabel , config ) ;
6480
6581 viewContainerFixture . detectChanges ( ) ;
@@ -84,7 +100,7 @@ describe('MdSnackBar', () => {
84100 } ) ;
85101
86102 it ( 'should open a simple message with no button' , ( ) => {
87- let config = new MdSnackBarConfig ( testViewContainerRef ) ;
103+ let config = { viewContainerRef : testViewContainerRef } ;
88104 let snackBarRef = snackBar . open ( simpleMessage , null , config ) ;
89105
90106 viewContainerFixture . detectChanges ( ) ;
@@ -104,7 +120,7 @@ describe('MdSnackBar', () => {
104120 } ) ;
105121
106122 it ( 'should dismiss the snack bar and remove itself from the view' , async ( ( ) => {
107- let config = new MdSnackBarConfig ( testViewContainerRef ) ;
123+ let config = { viewContainerRef : testViewContainerRef } ;
108124 let dismissObservableCompleted = false ;
109125
110126 let snackBarRef = snackBar . open ( simpleMessage , null , config ) ;
@@ -127,7 +143,7 @@ describe('MdSnackBar', () => {
127143 } ) ) ;
128144
129145 it ( 'should open a custom component' , ( ) => {
130- let config = new MdSnackBarConfig ( testViewContainerRef ) ;
146+ let config = { viewContainerRef : testViewContainerRef } ;
131147 let snackBarRef = snackBar . openFromComponent ( BurritosNotification , config ) ;
132148
133149 expect ( snackBarRef . instance )
@@ -139,7 +155,7 @@ describe('MdSnackBar', () => {
139155 } ) ;
140156
141157 it ( 'should set the animation state to visible on entry' , ( ) => {
142- let config = new MdSnackBarConfig ( testViewContainerRef ) ;
158+ let config = { viewContainerRef : testViewContainerRef } ;
143159 let snackBarRef = snackBar . open ( simpleMessage , null , config ) ;
144160
145161 viewContainerFixture . detectChanges ( ) ;
@@ -148,7 +164,7 @@ describe('MdSnackBar', () => {
148164 } ) ;
149165
150166 it ( 'should set the animation state to complete on exit' , ( ) => {
151- let config = new MdSnackBarConfig ( testViewContainerRef ) ;
167+ let config = { viewContainerRef : testViewContainerRef } ;
152168 let snackBarRef = snackBar . open ( simpleMessage , null , config ) ;
153169 snackBarRef . dismiss ( ) ;
154170
@@ -159,15 +175,15 @@ describe('MdSnackBar', () => {
159175
160176 it ( `should set the old snack bar animation state to complete and the new snack bar animation
161177 state to visible on entry of new snack bar` , async ( ( ) => {
162- let config = new MdSnackBarConfig ( testViewContainerRef ) ;
178+ let config = { viewContainerRef : testViewContainerRef } ;
163179 let snackBarRef = snackBar . open ( simpleMessage , null , config ) ;
164180 let dismissObservableCompleted = false ;
165181
166182 viewContainerFixture . detectChanges ( ) ;
167183 expect ( snackBarRef . containerInstance . animationState )
168184 . toBe ( 'visible' , `Expected the animation state would be 'visible'.` ) ;
169185
170- let config2 = new MdSnackBarConfig ( testViewContainerRef ) ;
186+ let config2 = { viewContainerRef : testViewContainerRef } ;
171187 let snackBarRef2 = snackBar . open ( simpleMessage , null , config2 ) ;
172188
173189 viewContainerFixture . detectChanges ( ) ;
@@ -185,7 +201,7 @@ describe('MdSnackBar', () => {
185201 } ) ) ;
186202
187203 it ( 'should open a new snackbar after dismissing a previous snackbar' , async ( ( ) => {
188- let config = new MdSnackBarConfig ( testViewContainerRef ) ;
204+ let config = { viewContainerRef : testViewContainerRef } ;
189205 let snackBarRef = snackBar . open ( simpleMessage , 'DISMISS' , config ) ;
190206 viewContainerFixture . detectChanges ( ) ;
191207
0 commit comments