@@ -167,6 +167,23 @@ describe('Overlay directives', () => {
167
167
`Expected directive to emit an instance of ConnectedOverlayPositionChange.` ) ;
168
168
} ) ;
169
169
170
+ it ( 'should emit attach and detach appropriately' , ( ) => {
171
+ expect ( fixture . componentInstance . attachHandler ) . not . toHaveBeenCalled ( ) ;
172
+ expect ( fixture . componentInstance . detachHandler ) . not . toHaveBeenCalled ( ) ;
173
+ fixture . componentInstance . isOpen = true ;
174
+ fixture . detectChanges ( ) ;
175
+
176
+ expect ( fixture . componentInstance . attachHandler ) . toHaveBeenCalled ( ) ;
177
+ expect ( fixture . componentInstance . attachResult )
178
+ . toEqual ( jasmine . any ( HTMLElement ) ,
179
+ `Expected pane to be populated with HTML elements when attach was called.` ) ;
180
+ expect ( fixture . componentInstance . detachHandler ) . not . toHaveBeenCalled ( ) ;
181
+
182
+ fixture . componentInstance . isOpen = false ;
183
+ fixture . detectChanges ( ) ;
184
+ expect ( fixture . componentInstance . detachHandler ) . toHaveBeenCalled ( ) ;
185
+ } ) ;
186
+
170
187
} ) ;
171
188
172
189
} ) ;
@@ -178,7 +195,8 @@ describe('Overlay directives', () => {
178
195
<template connected-overlay [origin]="trigger" [open]="isOpen" [width]="width" [height]="height"
179
196
[hasBackdrop]="hasBackdrop" backdropClass="md-test-class"
180
197
(backdropClick)="backdropClicked=true" [offsetX]="offsetX" [offsetY]="offsetY"
181
- (positionChange)="positionChangeHandler($event)">
198
+ (positionChange)="positionChangeHandler($event)" (attach)="attachHandler()"
199
+ (detach)="detachHandler()">
182
200
<p>Menu content</p>
183
201
</template>` ,
184
202
} )
@@ -191,6 +209,12 @@ class ConnectedOverlayDirectiveTest {
191
209
hasBackdrop : boolean ;
192
210
backdropClicked = false ;
193
211
positionChangeHandler = jasmine . createSpy ( 'positionChangeHandler' ) ;
212
+ attachHandler = jasmine . createSpy ( 'attachHandler' ) . and . callFake ( ( ) => {
213
+ this . attachResult =
214
+ this . connectedOverlayDirective . overlayRef . overlayElement . querySelector ( 'p' ) as HTMLElement ;
215
+ } ) ;
216
+ detachHandler = jasmine . createSpy ( 'detachHandler' ) ;
217
+ attachResult : HTMLElement ;
194
218
195
219
@ViewChild ( ConnectedOverlayDirective ) connectedOverlayDirective : ConnectedOverlayDirective ;
196
220
}
0 commit comments