@@ -4,6 +4,7 @@ import {By} from '@angular/platform-browser';
4
4
import { ConnectedOverlayDirective , OverlayModule } from './overlay-directives' ;
5
5
import { OverlayContainer } from './overlay-container' ;
6
6
import { ConnectedPositionStrategy } from './position/connected-position-strategy' ;
7
+ import { ConnectedOverlayPositionChange } from './position/connected-position' ;
7
8
8
9
9
10
describe ( 'Overlay directives' , ( ) => {
@@ -110,18 +111,6 @@ describe('Overlay directives', () => {
110
111
expect ( backdrop . classList ) . toContain ( 'md-test-class' ) ;
111
112
} ) ;
112
113
113
- it ( 'should emit backdropClick appropriately' , ( ) => {
114
- fixture . componentInstance . hasBackdrop = true ;
115
- fixture . componentInstance . isOpen = true ;
116
- fixture . detectChanges ( ) ;
117
-
118
- const backdrop = overlayContainerElement . querySelector ( '.md-overlay-backdrop' ) as HTMLElement ;
119
- backdrop . click ( ) ;
120
- fixture . detectChanges ( ) ;
121
-
122
- expect ( fixture . componentInstance . backdropClicked ) . toBe ( true ) ;
123
- } ) ;
124
-
125
114
it ( 'should set the offsetX' , ( ) => {
126
115
const trigger = fixture . debugElement . query ( By . css ( 'button' ) ) . nativeElement ;
127
116
const startX = trigger . getBoundingClientRect ( ) . left ;
@@ -154,15 +143,42 @@ describe('Overlay directives', () => {
154
143
155
144
} ) ;
156
145
146
+ describe ( 'outputs' , ( ) => {
147
+ it ( 'should emit backdropClick appropriately' , ( ) => {
148
+ fixture . componentInstance . hasBackdrop = true ;
149
+ fixture . componentInstance . isOpen = true ;
150
+ fixture . detectChanges ( ) ;
151
+
152
+ const backdrop = overlayContainerElement . querySelector ( '.md-overlay-backdrop' ) as HTMLElement ;
153
+ backdrop . click ( ) ;
154
+ fixture . detectChanges ( ) ;
155
+
156
+ expect ( fixture . componentInstance . backdropClicked ) . toBe ( true ) ;
157
+ } ) ;
158
+
159
+ it ( 'should emit positionChange appropriately' , ( ) => {
160
+ expect ( fixture . componentInstance . positionChangeHandler ) . not . toHaveBeenCalled ( ) ;
161
+ fixture . componentInstance . isOpen = true ;
162
+ fixture . detectChanges ( ) ;
163
+
164
+ expect ( fixture . componentInstance . positionChangeHandler ) . toHaveBeenCalled ( ) ;
165
+ expect ( fixture . componentInstance . positionChangeHandler . calls . mostRecent ( ) . args [ 0 ] )
166
+ . toEqual ( jasmine . any ( ConnectedOverlayPositionChange ) ,
167
+ `Expected directive to emit an instance of ConnectedOverlayPositionChange.` ) ;
168
+ } ) ;
169
+
170
+ } ) ;
171
+
157
172
} ) ;
158
173
159
174
160
175
@Component ( {
161
176
template : `
162
177
<button overlay-origin #trigger="overlayOrigin">Toggle menu</button>
163
178
<template connected-overlay [origin]="trigger" [open]="isOpen" [width]="width" [height]="height"
164
- [hasBackdrop]="hasBackdrop" backdropClass="md-test-class"
165
- (backdropClick)="backdropClicked=true" [offsetX]="offsetX" [offsetY]="offsetY">
179
+ [hasBackdrop]="hasBackdrop" backdropClass="md-test-class"
180
+ (backdropClick)="backdropClicked=true" [offsetX]="offsetX" [offsetY]="offsetY"
181
+ (positionChange)="positionChangeHandler($event)">
166
182
<p>Menu content</p>
167
183
</template>` ,
168
184
} )
@@ -174,6 +190,7 @@ class ConnectedOverlayDirectiveTest {
174
190
offsetY : number = 0 ;
175
191
hasBackdrop : boolean ;
176
192
backdropClicked = false ;
193
+ positionChangeHandler = jasmine . createSpy ( 'positionChangeHandler' ) ;
177
194
178
195
@ViewChild ( ConnectedOverlayDirective ) connectedOverlayDirective : ConnectedOverlayDirective ;
179
196
}
0 commit comments