1
- import { ApplicationRef , Component } from '@angular/core' ;
1
+ import { ApplicationRef , Component , Injector } from '@angular/core' ;
2
2
import { TestBed } from '@angular/core/testing' ;
3
3
import { filter , take } from 'rxjs/operators' ;
4
4
import { ComponentPortal } from '../../portal' ;
5
5
import { dispatchFakeEvent , dispatchMouseEvent } from '../../testing/private' ;
6
- import { Overlay , OverlayModule } from '../index' ;
6
+ import { createOverlayRef } from '../index' ;
7
7
import { OverlayOutsideClickDispatcher } from './overlay-outside-click-dispatcher' ;
8
8
9
9
describe ( 'OverlayOutsideClickDispatcher' , ( ) => {
10
10
let appRef : ApplicationRef ;
11
11
let outsideClickDispatcher : OverlayOutsideClickDispatcher ;
12
- let overlay : Overlay ;
12
+ let injector : Injector ;
13
13
14
14
beforeEach ( ( ) => {
15
- TestBed . configureTestingModule ( { imports : [ OverlayModule , TestComponent ] } ) ;
16
15
appRef = TestBed . inject ( ApplicationRef ) ;
17
16
outsideClickDispatcher = TestBed . inject ( OverlayOutsideClickDispatcher ) ;
18
- overlay = TestBed . inject ( Overlay ) ;
17
+ injector = TestBed . inject ( Injector ) ;
19
18
} ) ;
20
19
21
20
it ( 'should track overlays in order as they are attached and detached' , ( ) => {
22
- const overlayOne = overlay . create ( ) ;
23
- const overlayTwo = overlay . create ( ) ;
21
+ const overlayOne = createOverlayRef ( injector ) ;
22
+ const overlayTwo = createOverlayRef ( injector ) ;
24
23
25
24
outsideClickDispatcher . add ( overlayOne ) ;
26
25
outsideClickDispatcher . add ( overlayTwo ) ;
@@ -50,9 +49,9 @@ describe('OverlayOutsideClickDispatcher', () => {
50
49
} ) ;
51
50
52
51
it ( 'should dispatch mouse click events to the attached overlays' , ( ) => {
53
- const overlayOne = overlay . create ( ) ;
52
+ const overlayOne = createOverlayRef ( injector ) ;
54
53
overlayOne . attach ( new ComponentPortal ( TestComponent ) ) ;
55
- const overlayTwo = overlay . create ( ) ;
54
+ const overlayTwo = createOverlayRef ( injector ) ;
56
55
overlayTwo . attach ( new ComponentPortal ( TestComponent ) ) ;
57
56
58
57
const overlayOneSpy = jasmine . createSpy ( 'overlayOne mouse click event spy' ) ;
@@ -77,9 +76,9 @@ describe('OverlayOutsideClickDispatcher', () => {
77
76
} ) ;
78
77
79
78
it ( 'should dispatch auxiliary button click events to the attached overlays' , ( ) => {
80
- const overlayOne = overlay . create ( ) ;
79
+ const overlayOne = createOverlayRef ( injector ) ;
81
80
overlayOne . attach ( new ComponentPortal ( TestComponent ) ) ;
82
- const overlayTwo = overlay . create ( ) ;
81
+ const overlayTwo = createOverlayRef ( injector ) ;
83
82
overlayTwo . attach ( new ComponentPortal ( TestComponent ) ) ;
84
83
85
84
const overlayOneSpy = jasmine . createSpy ( 'overlayOne auxiliary click event spy' ) ;
@@ -104,7 +103,7 @@ describe('OverlayOutsideClickDispatcher', () => {
104
103
} ) ;
105
104
106
105
it ( 'should dispatch mouse click events to the attached overlays even when propagation is stopped' , ( ) => {
107
- const overlayRef = overlay . create ( ) ;
106
+ const overlayRef = createOverlayRef ( injector ) ;
108
107
overlayRef . attach ( new ComponentPortal ( TestComponent ) ) ;
109
108
const spy = jasmine . createSpy ( 'overlay mouse click event spy' ) ;
110
109
overlayRef . outsidePointerEvents ( ) . subscribe ( spy ) ;
@@ -123,7 +122,7 @@ describe('OverlayOutsideClickDispatcher', () => {
123
122
} ) ;
124
123
125
124
it ( 'should dispose of the global click event handler correctly' , ( ) => {
126
- const overlayRef = overlay . create ( ) ;
125
+ const overlayRef = createOverlayRef ( injector ) ;
127
126
const body = document . body ;
128
127
129
128
spyOn ( body , 'addEventListener' ) ;
@@ -145,8 +144,8 @@ describe('OverlayOutsideClickDispatcher', () => {
145
144
} ) ;
146
145
147
146
it ( 'should not add the same overlay to the stack multiple times' , ( ) => {
148
- const overlayOne = overlay . create ( ) ;
149
- const overlayTwo = overlay . create ( ) ;
147
+ const overlayOne = createOverlayRef ( injector ) ;
148
+ const overlayTwo = createOverlayRef ( injector ) ;
150
149
151
150
outsideClickDispatcher . add ( overlayOne ) ;
152
151
outsideClickDispatcher . add ( overlayTwo ) ;
@@ -160,7 +159,7 @@ describe('OverlayOutsideClickDispatcher', () => {
160
159
161
160
it ( 'should dispatch the click event when click is on an element outside the overlay' , ( ) => {
162
161
const portal = new ComponentPortal ( TestComponent ) ;
163
- const overlayRef = overlay . create ( ) ;
162
+ const overlayRef = createOverlayRef ( injector ) ;
164
163
overlayRef . attach ( portal ) ;
165
164
const button = document . createElement ( 'button' ) ;
166
165
document . body . appendChild ( button ) ;
@@ -177,7 +176,7 @@ describe('OverlayOutsideClickDispatcher', () => {
177
176
178
177
it ( 'should not dispatch the click event when click is on an element inside the overlay' , ( ) => {
179
178
const portal = new ComponentPortal ( TestComponent ) ;
180
- const overlayRef = overlay . create ( ) ;
179
+ const overlayRef = createOverlayRef ( injector ) ;
181
180
overlayRef . attach ( portal ) ;
182
181
183
182
const spy = jasmine . createSpy ( 'overlay mouse click event spy' ) ;
@@ -194,7 +193,7 @@ describe('OverlayOutsideClickDispatcher', () => {
194
193
'released outside of it' ,
195
194
( ) => {
196
195
const portal = new ComponentPortal ( TestComponent ) ;
197
- const overlayRef = overlay . create ( ) ;
196
+ const overlayRef = createOverlayRef ( injector ) ;
198
197
overlayRef . attach ( portal ) ;
199
198
const context = document . createElement ( 'div' ) ;
200
199
document . body . appendChild ( context ) ;
@@ -216,7 +215,7 @@ describe('OverlayOutsideClickDispatcher', () => {
216
215
'released inside of it' ,
217
216
( ) => {
218
217
const portal = new ComponentPortal ( TestComponent ) ;
219
- const overlayRef = overlay . create ( ) ;
218
+ const overlayRef = createOverlayRef ( injector ) ;
220
219
overlayRef . attach ( portal ) ;
221
220
222
221
const spy = jasmine . createSpy ( 'overlay mouse click event spy' ) ;
@@ -235,7 +234,7 @@ describe('OverlayOutsideClickDispatcher', () => {
235
234
'released outside of it' ,
236
235
( ) => {
237
236
const portal = new ComponentPortal ( TestComponent ) ;
238
- const overlayRef = overlay . create ( ) ;
237
+ const overlayRef = createOverlayRef ( injector ) ;
239
238
overlayRef . attach ( portal ) ;
240
239
const context = document . createElement ( 'div' ) ;
241
240
document . body . appendChild ( context ) ;
@@ -257,7 +256,7 @@ describe('OverlayOutsideClickDispatcher', () => {
257
256
'released inside of it' ,
258
257
( ) => {
259
258
const portal = new ComponentPortal ( TestComponent ) ;
260
- const overlayRef = overlay . create ( ) ;
259
+ const overlayRef = createOverlayRef ( injector ) ;
261
260
overlayRef . attach ( portal ) ;
262
261
const context = document . createElement ( 'div' ) ;
263
262
document . body . appendChild ( context ) ;
@@ -276,7 +275,7 @@ describe('OverlayOutsideClickDispatcher', () => {
276
275
277
276
it ( 'should dispatch an event when a context menu is triggered outside the overlay' , ( ) => {
278
277
const portal = new ComponentPortal ( TestComponent ) ;
279
- const overlayRef = overlay . create ( ) ;
278
+ const overlayRef = createOverlayRef ( injector ) ;
280
279
overlayRef . attach ( portal ) ;
281
280
const context = document . createElement ( 'div' ) ;
282
281
document . body . appendChild ( context ) ;
@@ -293,7 +292,7 @@ describe('OverlayOutsideClickDispatcher', () => {
293
292
294
293
it ( 'should not dispatch an event when a context menu is triggered inside the overlay' , ( ) => {
295
294
const portal = new ComponentPortal ( TestComponent ) ;
296
- const overlayRef = overlay . create ( ) ;
295
+ const overlayRef = createOverlayRef ( injector ) ;
297
296
overlayRef . attach ( portal ) ;
298
297
299
298
const spy = jasmine . createSpy ( 'overlay contextmenu spy' ) ;
@@ -306,11 +305,11 @@ describe('OverlayOutsideClickDispatcher', () => {
306
305
} ) ;
307
306
308
307
it ( 'should not throw an error when closing out related components via the outsidePointerEvents emitter on background click' , ( ) => {
309
- const firstOverlayRef = overlay . create ( ) ;
308
+ const firstOverlayRef = createOverlayRef ( injector ) ;
310
309
firstOverlayRef . attach ( new ComponentPortal ( TestComponent ) ) ;
311
- const secondOverlayRef = overlay . create ( ) ;
310
+ const secondOverlayRef = createOverlayRef ( injector ) ;
312
311
secondOverlayRef . attach ( new ComponentPortal ( TestComponent ) ) ;
313
- const thirdOverlayRef = overlay . create ( ) ;
312
+ const thirdOverlayRef = createOverlayRef ( injector ) ;
314
313
thirdOverlayRef . attach ( new ComponentPortal ( TestComponent ) ) ;
315
314
316
315
const spy = jasmine . createSpy ( 'background click handler spy' ) . and . callFake ( ( ) => {
@@ -338,7 +337,7 @@ describe('OverlayOutsideClickDispatcher', () => {
338
337
describe ( 'change detection behavior' , ( ) => {
339
338
it ( 'should not run change detection if there is no portal attached to the overlay' , ( ) => {
340
339
spyOn ( appRef , 'tick' ) ;
341
- const overlayRef = overlay . create ( ) ;
340
+ const overlayRef = createOverlayRef ( injector ) ;
342
341
outsideClickDispatcher . add ( overlayRef ) ;
343
342
344
343
const context = document . createElement ( 'div' ) ;
@@ -353,7 +352,7 @@ describe('OverlayOutsideClickDispatcher', () => {
353
352
it ( 'should not run change detection if the click was made outside the overlay but there are no `outsidePointerEvents` observers' , ( ) => {
354
353
spyOn ( appRef , 'tick' ) ;
355
354
const portal = new ComponentPortal ( TestComponent ) ;
356
- const overlayRef = overlay . create ( ) ;
355
+ const overlayRef = createOverlayRef ( injector ) ;
357
356
overlayRef . attach ( portal ) ;
358
357
outsideClickDispatcher . add ( overlayRef ) ;
359
358
@@ -368,7 +367,7 @@ describe('OverlayOutsideClickDispatcher', () => {
368
367
it ( 'should not run change detection if the click was made inside the overlay and there are `outsidePointerEvents` observers' , ( ) => {
369
368
spyOn ( appRef , 'tick' ) ;
370
369
const portal = new ComponentPortal ( TestComponent ) ;
371
- const overlayRef = overlay . create ( ) ;
370
+ const overlayRef = createOverlayRef ( injector ) ;
372
371
overlayRef . attach ( portal ) ;
373
372
outsideClickDispatcher . add ( overlayRef ) ;
374
373
@@ -399,7 +398,7 @@ describe('OverlayOutsideClickDispatcher', () => {
399
398
renders = 0 ;
400
399
expect ( renders ) . toEqual ( 0 ) ;
401
400
const portal = new ComponentPortal ( TestComponent ) ;
402
- const overlayRef = overlay . create ( ) ;
401
+ const overlayRef = createOverlayRef ( injector ) ;
403
402
overlayRef . attach ( portal ) ;
404
403
outsideClickDispatcher . add ( overlayRef ) ;
405
404
@@ -421,8 +420,5 @@ describe('OverlayOutsideClickDispatcher', () => {
421
420
} ) ;
422
421
} ) ;
423
422
424
- @Component ( {
425
- template : 'Hello' ,
426
- imports : [ OverlayModule ] ,
427
- } )
423
+ @Component ( { template : 'Hello' } )
428
424
class TestComponent { }
0 commit comments