@@ -147,6 +147,24 @@ describe('Overlay', () => {
147147 expect ( spy ) . toHaveBeenCalled ( ) ;
148148 } ) ;
149149
150+ it ( 'should emit the attachment event after everything is added to the DOM' , ( ) => {
151+ let state = new OverlayState ( ) ;
152+
153+ state . hasBackdrop = true ;
154+
155+ let overlayRef = overlay . create ( state ) ;
156+
157+ overlayRef . attachments ( ) . subscribe ( ( ) => {
158+ expect ( overlayContainerElement . querySelector ( 'pizza' ) )
159+ . toBeTruthy ( 'Expected the overlay to have been attached.' ) ;
160+
161+ expect ( overlayContainerElement . querySelector ( '.cdk-overlay-backdrop' ) )
162+ . toBeTruthy ( 'Expected the backdrop to have been attached.' ) ;
163+ } ) ;
164+
165+ overlayRef . attach ( componentPortal ) ;
166+ } ) ;
167+
150168 it ( 'should emit when an overlay is detached' , ( ) => {
151169 let overlayRef = overlay . create ( ) ;
152170 let spy = jasmine . createSpy ( 'detachments spy' ) ;
@@ -158,6 +176,18 @@ describe('Overlay', () => {
158176 expect ( spy ) . toHaveBeenCalled ( ) ;
159177 } ) ;
160178
179+ it ( 'should emit the detachment event after the overlay is removed from the DOM' , ( ) => {
180+ let overlayRef = overlay . create ( ) ;
181+
182+ overlayRef . detachments ( ) . subscribe ( ( ) => {
183+ expect ( overlayContainerElement . querySelector ( 'pizza' ) )
184+ . toBeFalsy ( 'Expected the overlay to have been detached.' ) ;
185+ } ) ;
186+
187+ overlayRef . attach ( componentPortal ) ;
188+ overlayRef . detach ( ) ;
189+ } ) ;
190+
161191 it ( 'should emit and complete the observables when an overlay is disposed' , ( ) => {
162192 let overlayRef = overlay . create ( ) ;
163193 let disposeSpy = jasmine . createSpy ( 'dispose spy' ) ;
@@ -175,6 +205,19 @@ describe('Overlay', () => {
175205 expect ( detachCompleteSpy ) . toHaveBeenCalled ( ) ;
176206 } ) ;
177207
208+ it ( 'should complete the attachment observable before the detachment one' , ( ) => {
209+ let overlayRef = overlay . create ( ) ;
210+ let callbackOrder = [ ] ;
211+
212+ overlayRef . attachments ( ) . subscribe ( null , null , ( ) => callbackOrder . push ( 'attach' ) ) ;
213+ overlayRef . detachments ( ) . subscribe ( null , null , ( ) => callbackOrder . push ( 'detach' ) ) ;
214+
215+ overlayRef . attach ( componentPortal ) ;
216+ overlayRef . dispose ( ) ;
217+
218+ expect ( callbackOrder ) . toEqual ( [ 'attach' , 'detach' ] ) ;
219+ } ) ;
220+
178221 describe ( 'positioning' , ( ) => {
179222 let state : OverlayState ;
180223
@@ -421,7 +464,10 @@ describe('OverlayContainer theming', () => {
421464} ) ;
422465
423466/** Simple component for testing ComponentPortal. */
424- @Component ( { template : '<p>Pizza</p>' } )
467+ @Component ( {
468+ selector : 'pizza' ,
469+ template : '<p>Pizza</p>'
470+ } )
425471class PizzaMsg { }
426472
427473
0 commit comments