@@ -147,6 +147,24 @@ describe('Overlay', () => {
147
147
expect ( spy ) . toHaveBeenCalled ( ) ;
148
148
} ) ;
149
149
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
+
150
168
it ( 'should emit when an overlay is detached' , ( ) => {
151
169
let overlayRef = overlay . create ( ) ;
152
170
let spy = jasmine . createSpy ( 'detachments spy' ) ;
@@ -158,6 +176,18 @@ describe('Overlay', () => {
158
176
expect ( spy ) . toHaveBeenCalled ( ) ;
159
177
} ) ;
160
178
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
+
161
191
it ( 'should emit and complete the observables when an overlay is disposed' , ( ) => {
162
192
let overlayRef = overlay . create ( ) ;
163
193
let disposeSpy = jasmine . createSpy ( 'dispose spy' ) ;
@@ -175,6 +205,19 @@ describe('Overlay', () => {
175
205
expect ( detachCompleteSpy ) . toHaveBeenCalled ( ) ;
176
206
} ) ;
177
207
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
+
178
221
describe ( 'positioning' , ( ) => {
179
222
let state : OverlayState ;
180
223
@@ -421,7 +464,10 @@ describe('OverlayContainer theming', () => {
421
464
} ) ;
422
465
423
466
/** Simple component for testing ComponentPortal. */
424
- @Component ( { template : '<p>Pizza</p>' } )
467
+ @Component ( {
468
+ selector : 'pizza' ,
469
+ template : '<p>Pizza</p>'
470
+ } )
425
471
class PizzaMsg { }
426
472
427
473
0 commit comments