@@ -16,6 +16,7 @@ import {OverlayContainer} from '../core';
1616import { MdSnackBarConfig } from './snack-bar-config' ;
1717import { SimpleSnackBar } from './simple-snack-bar' ;
1818
19+ // TODO(josephperrott): Update tests to mock waiting for time to complete for animations.
1920
2021describe ( 'MdSnackBar' , ( ) => {
2122 let snackBar : MdSnackBar ;
@@ -56,7 +57,6 @@ describe('MdSnackBar', () => {
5657 snackBar . open ( simpleMessage , simpleActionLabel , config ) ;
5758
5859 let containerElement = overlayContainerElement . querySelector ( 'snack-bar-container' ) ;
59-
6060 expect ( containerElement . getAttribute ( 'role' ) )
6161 . toBe ( 'alert' , 'Expected snack bar container to have role="alert"' ) ;
6262 } ) ;
@@ -120,10 +120,11 @@ describe('MdSnackBar', () => {
120120 . toBeGreaterThan ( 0 , 'Expected overlay container element to have at least one child' ) ;
121121
122122 snackBarRef . dismiss ( ) ;
123-
124- expect ( dismissed ) . toBeTruthy ( 'Expected the snack bar to be dismissed' ) ;
125- expect ( overlayContainerElement . childElementCount )
126- . toBe ( 0 , 'Expected the overlay container element to have no child elements' ) ;
123+ snackBarRef . afterDismissed ( ) . subscribe ( null , null , ( ) => {
124+ expect ( dismissed ) . toBeTruthy ( 'Expected the snack bar to be dismissed' ) ;
125+ expect ( overlayContainerElement . childElementCount )
126+ . toBe ( 0 , 'Expected the overlay container element to have no child elements' ) ;
127+ } ) ;
127128 } ) ;
128129
129130 it ( 'should open a custom component' , ( ) => {
@@ -136,7 +137,46 @@ describe('MdSnackBar', () => {
136137 expect ( overlayContainerElement . textContent )
137138 . toBe ( 'Burritos are on the way.' ,
138139 `Expected the overlay text content to be 'Burritos are on the way'` ) ;
140+ } ) ;
141+
142+ it ( 'should set the animation state to visible on entry' , ( ) => {
143+ let config = new MdSnackBarConfig ( testViewContainerRef ) ;
144+ let snackBarRef = snackBar . open ( simpleMessage , null , config ) ;
145+
146+ viewContainerFixture . detectChanges ( ) ;
147+ expect ( snackBarRef . containerInstance . animationState )
148+ . toBe ( 'visible' , `Expected the animation state would be 'visible'.` ) ;
149+ } ) ;
150+
151+ it ( 'should set the animation state to complete on exit' , ( ) => {
152+ let config = new MdSnackBarConfig ( testViewContainerRef ) ;
153+ let snackBarRef = snackBar . open ( simpleMessage , null , config ) ;
154+ snackBarRef . dismiss ( ) ;
139155
156+ viewContainerFixture . detectChanges ( ) ;
157+ expect ( snackBarRef . containerInstance . animationState )
158+ . toBe ( 'complete' , `Expected the animation state would be 'complete'.` ) ;
159+ } ) ;
160+
161+ it ( `should set the old snack bar animation state to complete and the new snack bar animation
162+ state to visible on entry of new snack bar` , ( ) => {
163+ let config = new MdSnackBarConfig ( testViewContainerRef ) ;
164+ let snackBarRef = snackBar . open ( simpleMessage , null , config ) ;
165+
166+ viewContainerFixture . detectChanges ( ) ;
167+ expect ( snackBarRef . containerInstance . animationState )
168+ . toBe ( 'visible' , `Expected the animation state would be 'visible'.` ) ;
169+
170+ let config2 = new MdSnackBarConfig ( testViewContainerRef ) ;
171+ let snackBarRef2 = snackBar . open ( simpleMessage , null , config2 ) ;
172+
173+ viewContainerFixture . detectChanges ( ) ;
174+ snackBarRef . afterDismissed ( ) . subscribe ( null , null , ( ) => {
175+ expect ( snackBarRef . containerInstance . animationState )
176+ . toBe ( 'complete' , `Expected the animation state would be 'complete'.` ) ;
177+ expect ( snackBarRef2 . containerInstance . animationState )
178+ . toBe ( 'visible' , `Expected the animation state would be 'visible'.` ) ;
179+ } ) ;
140180 } ) ;
141181} ) ;
142182
0 commit comments