@@ -7,6 +7,7 @@ import {ConnectedOverlayPositionChange} from './connected-position';
7
7
import { Scrollable } from '../scroll/scrollable' ;
8
8
import { Subscription } from 'rxjs/Subscription' ;
9
9
import { ScrollDispatchModule } from '../scroll/index' ;
10
+ import { OverlayRef } from '../overlay-ref' ;
10
11
11
12
12
13
// Default width and height of the overlay and origin panels throughout these tests.
@@ -142,7 +143,8 @@ describe('ConnectedPositionStrategy', () => {
142
143
{ originX : 'start' , originY : 'bottom' } ,
143
144
{ overlayX : 'start' , overlayY : 'top' } ) ;
144
145
145
- strategy . apply ( overlayElement ) ;
146
+ strategy . attach ( fakeOverlayRef ( overlayElement ) ) ;
147
+ strategy . apply ( ) ;
146
148
147
149
let overlayRect = overlayElement . getBoundingClientRect ( ) ;
148
150
expect ( Math . floor ( overlayRect . top ) ) . toBe ( Math . floor ( originRect . bottom ) ) ;
@@ -166,7 +168,8 @@ describe('ConnectedPositionStrategy', () => {
166
168
{ originX : 'end' , originY : 'center' } ,
167
169
{ overlayX : 'start' , overlayY : 'center' } ) ;
168
170
169
- strategy . apply ( overlayElement ) ;
171
+ strategy . attach ( fakeOverlayRef ( overlayElement ) ) ;
172
+ strategy . apply ( ) ;
170
173
171
174
let overlayRect = overlayElement . getBoundingClientRect ( ) ;
172
175
expect ( Math . floor ( overlayRect . top ) ) . toBe ( Math . floor ( originCenterY - ( OVERLAY_HEIGHT / 2 ) ) ) ;
@@ -188,7 +191,8 @@ describe('ConnectedPositionStrategy', () => {
188
191
{ originX : 'end' , originY : 'top' } ,
189
192
{ overlayX : 'end' , overlayY : 'bottom' } ) ;
190
193
191
- strategy . apply ( overlayElement ) ;
194
+ strategy . attach ( fakeOverlayRef ( overlayElement ) ) ;
195
+ strategy . apply ( ) ;
192
196
193
197
let overlayRect = overlayElement . getBoundingClientRect ( ) ;
194
198
expect ( Math . floor ( overlayRect . bottom ) ) . toBe ( Math . floor ( originRect . top ) ) ;
@@ -210,7 +214,8 @@ describe('ConnectedPositionStrategy', () => {
210
214
{ originX : 'start' , originY : 'bottom' } ,
211
215
{ overlayX : 'end' , overlayY : 'top' } ) ;
212
216
213
- strategy . apply ( overlayElement ) ;
217
+ strategy . attach ( fakeOverlayRef ( overlayElement ) ) ;
218
+ strategy . apply ( ) ;
214
219
215
220
let overlayRect = overlayElement . getBoundingClientRect ( ) ;
216
221
@@ -234,7 +239,8 @@ describe('ConnectedPositionStrategy', () => {
234
239
{ overlayX : 'start' , overlayY : 'bottom' } ) ;
235
240
236
241
// This should apply the fallback position, as the original position won't fit.
237
- strategy . apply ( overlayElement ) ;
242
+ strategy . attach ( fakeOverlayRef ( overlayElement ) ) ;
243
+ strategy . apply ( ) ;
238
244
239
245
// Now make the overlay small enough to fit in the first preferred position.
240
246
overlayElement . style . height = '15px' ;
@@ -260,7 +266,8 @@ describe('ConnectedPositionStrategy', () => {
260
266
{ originX : 'start' , originY : 'top' } ,
261
267
{ overlayX : 'start' , overlayY : 'bottom' } ) ;
262
268
263
- strategy . apply ( overlayElement ) ;
269
+ strategy . attach ( fakeOverlayRef ( overlayElement ) ) ;
270
+ strategy . apply ( ) ;
264
271
strategy . recalculateLastPosition ( ) ;
265
272
266
273
let overlayRect = overlayElement . getBoundingClientRect ( ) ;
@@ -279,7 +286,8 @@ describe('ConnectedPositionStrategy', () => {
279
286
{ overlayX : 'start' , overlayY : 'top' } )
280
287
. withDirection ( 'rtl' ) ;
281
288
282
- strategy . apply ( overlayElement ) ;
289
+ strategy . attach ( fakeOverlayRef ( overlayElement ) ) ;
290
+ strategy . apply ( ) ;
283
291
284
292
let overlayRect = overlayElement . getBoundingClientRect ( ) ;
285
293
expect ( Math . floor ( overlayRect . top ) ) . toBe ( Math . floor ( originRect . bottom ) ) ;
@@ -294,7 +302,8 @@ describe('ConnectedPositionStrategy', () => {
294
302
{ overlayX : 'start' , overlayY : 'top' } ) ;
295
303
296
304
strategy . withOffsetX ( 10 ) ;
297
- strategy . apply ( overlayElement ) ;
305
+ strategy . attach ( fakeOverlayRef ( overlayElement ) ) ;
306
+ strategy . apply ( ) ;
298
307
299
308
let overlayRect = overlayElement . getBoundingClientRect ( ) ;
300
309
expect ( Math . floor ( overlayRect . top ) ) . toBe ( Math . floor ( originRect . top ) ) ;
@@ -309,7 +318,8 @@ describe('ConnectedPositionStrategy', () => {
309
318
{ overlayX : 'start' , overlayY : 'top' } ) ;
310
319
311
320
strategy . withOffsetY ( 50 ) ;
312
- strategy . apply ( overlayElement ) ;
321
+ strategy . attach ( fakeOverlayRef ( overlayElement ) ) ;
322
+ strategy . apply ( ) ;
313
323
314
324
let overlayRect = overlayElement . getBoundingClientRect ( ) ;
315
325
expect ( Math . floor ( overlayRect . top ) ) . toBe ( Math . floor ( originRect . top + 50 ) ) ;
@@ -334,7 +344,8 @@ describe('ConnectedPositionStrategy', () => {
334
344
const positionChangeHandler = jasmine . createSpy ( 'positionChangeHandler' ) ;
335
345
const subscription = strategy . onPositionChange . subscribe ( positionChangeHandler ) ;
336
346
337
- strategy . apply ( overlayElement ) ;
347
+ strategy . attach ( fakeOverlayRef ( overlayElement ) ) ;
348
+ strategy . apply ( ) ;
338
349
339
350
const latestCall = positionChangeHandler . calls . mostRecent ( ) ;
340
351
@@ -346,7 +357,8 @@ describe('ConnectedPositionStrategy', () => {
346
357
// the position change event should be emitted again.
347
358
originElement . style . top = '200px' ;
348
359
originElement . style . left = '200px' ;
349
- strategy . apply ( overlayElement ) ;
360
+ strategy . attach ( fakeOverlayRef ( overlayElement ) ) ;
361
+ strategy . apply ( ) ;
350
362
351
363
expect ( positionChangeHandler ) . toHaveBeenCalledTimes ( 2 ) ;
352
364
@@ -369,7 +381,8 @@ describe('ConnectedPositionStrategy', () => {
369
381
const positionChangeHandler = jasmine . createSpy ( 'positionChangeHandler' ) ;
370
382
const subscription = strategy . onPositionChange . subscribe ( positionChangeHandler ) ;
371
383
372
- strategy . apply ( overlayElement ) ;
384
+ strategy . attach ( fakeOverlayRef ( overlayElement ) ) ;
385
+ strategy . apply ( ) ;
373
386
374
387
expect ( positionChangeHandler ) . toHaveBeenCalled ( ) ;
375
388
@@ -394,7 +407,8 @@ describe('ConnectedPositionStrategy', () => {
394
407
{ originX : 'end' , originY : 'top' } ,
395
408
{ overlayX : 'end' , overlayY : 'top' } ) ;
396
409
397
- strategy . apply ( overlayElement ) ;
410
+ strategy . attach ( fakeOverlayRef ( overlayElement ) ) ;
411
+ strategy . apply ( ) ;
398
412
399
413
let overlayRect = overlayElement . getBoundingClientRect ( ) ;
400
414
@@ -415,7 +429,8 @@ describe('ConnectedPositionStrategy', () => {
415
429
{ originX : 'start' , originY : 'bottom' } ,
416
430
{ overlayX : 'start' , overlayY : 'top' } ) ;
417
431
418
- strategy . apply ( overlayElement ) ;
432
+ strategy . attach ( fakeOverlayRef ( overlayElement ) ) ;
433
+ strategy . apply ( ) ;
419
434
420
435
let overlayRect = overlayElement . getBoundingClientRect ( ) ;
421
436
expect ( Math . floor ( overlayRect . top ) ) . toBe ( Math . floor ( originRect ! . bottom ) ) ;
@@ -428,7 +443,8 @@ describe('ConnectedPositionStrategy', () => {
428
443
{ originX : 'end' , originY : 'center' } ,
429
444
{ overlayX : 'start' , overlayY : 'center' } ) ;
430
445
431
- strategy . apply ( overlayElement ) ;
446
+ strategy . attach ( fakeOverlayRef ( overlayElement ) ) ;
447
+ strategy . apply ( ) ;
432
448
433
449
let overlayRect = overlayElement . getBoundingClientRect ( ) ;
434
450
expect ( Math . floor ( overlayRect . top ) ) . toBe ( Math . floor ( originCenterY ! - ( OVERLAY_HEIGHT / 2 ) ) ) ;
@@ -441,7 +457,8 @@ describe('ConnectedPositionStrategy', () => {
441
457
{ originX : 'start' , originY : 'bottom' } ,
442
458
{ overlayX : 'end' , overlayY : 'top' } ) ;
443
459
444
- strategy . apply ( overlayElement ) ;
460
+ strategy . attach ( fakeOverlayRef ( overlayElement ) ) ;
461
+ strategy . apply ( ) ;
445
462
446
463
let overlayRect = overlayElement . getBoundingClientRect ( ) ;
447
464
@@ -455,7 +472,8 @@ describe('ConnectedPositionStrategy', () => {
455
472
{ originX : 'end' , originY : 'top' } ,
456
473
{ overlayX : 'end' , overlayY : 'bottom' } ) ;
457
474
458
- strategy . apply ( overlayElement ) ;
475
+ strategy . attach ( fakeOverlayRef ( overlayElement ) ) ;
476
+ strategy . apply ( ) ;
459
477
460
478
let overlayRect = overlayElement . getBoundingClientRect ( ) ;
461
479
expect ( Math . round ( overlayRect . bottom ) ) . toBe ( Math . round ( originRect ! . top ) ) ;
@@ -468,7 +486,8 @@ describe('ConnectedPositionStrategy', () => {
468
486
{ originX : 'center' , originY : 'bottom' } ,
469
487
{ overlayX : 'center' , overlayY : 'top' } ) ;
470
488
471
- strategy . apply ( overlayElement ) ;
489
+ strategy . attach ( fakeOverlayRef ( overlayElement ) ) ;
490
+ strategy . apply ( ) ;
472
491
473
492
let overlayRect = overlayElement . getBoundingClientRect ( ) ;
474
493
expect ( Math . floor ( overlayRect . top ) ) . toBe ( Math . floor ( originRect ! . bottom ) ) ;
@@ -481,7 +500,8 @@ describe('ConnectedPositionStrategy', () => {
481
500
{ originX : 'center' , originY : 'center' } ,
482
501
{ overlayX : 'center' , overlayY : 'center' } ) ;
483
502
484
- strategy . apply ( overlayElement ) ;
503
+ strategy . attach ( fakeOverlayRef ( overlayElement ) ) ;
504
+ strategy . apply ( ) ;
485
505
486
506
let overlayRect = overlayElement . getBoundingClientRect ( ) ;
487
507
expect ( Math . floor ( overlayRect . top ) ) . toBe ( Math . floor ( originRect ! . top ) ) ;
@@ -526,7 +546,7 @@ describe('ConnectedPositionStrategy', () => {
526
546
527
547
strategy . withScrollableContainers ( [
528
548
new Scrollable ( new FakeElementRef ( scrollable ) , null ! , null ! , null ! ) ] ) ;
529
-
549
+ strategy . attach ( fakeOverlayRef ( overlayElement ) ) ;
530
550
positionChangeHandler = jasmine . createSpy ( 'positionChangeHandler' ) ;
531
551
onPositionChangeSubscription = strategy . onPositionChange . subscribe ( positionChangeHandler ) ;
532
552
} ) ;
@@ -538,7 +558,7 @@ describe('ConnectedPositionStrategy', () => {
538
558
} ) ;
539
559
540
560
it ( 'should not have origin or overlay clipped or out of view without scroll' , ( ) => {
541
- strategy . apply ( overlayElement ) ;
561
+ strategy . apply ( ) ;
542
562
543
563
expect ( positionChangeHandler ) . toHaveBeenCalled ( ) ;
544
564
positionChange = positionChangeHandler . calls . mostRecent ( ) . args [ 0 ] ;
@@ -552,7 +572,7 @@ describe('ConnectedPositionStrategy', () => {
552
572
553
573
it ( 'should evaluate if origin is clipped if scrolled slightly down' , ( ) => {
554
574
scrollable . scrollTop = 10 ; // Clip the origin by 10 pixels
555
- strategy . apply ( overlayElement ) ;
575
+ strategy . apply ( ) ;
556
576
557
577
expect ( positionChangeHandler ) . toHaveBeenCalled ( ) ;
558
578
positionChange = positionChangeHandler . calls . mostRecent ( ) . args [ 0 ] ;
@@ -566,7 +586,7 @@ describe('ConnectedPositionStrategy', () => {
566
586
567
587
it ( 'should evaluate if origin is out of view and overlay is clipped if scrolled enough' , ( ) => {
568
588
scrollable . scrollTop = 31 ; // Origin is 30 pixels, move out of view and clip the overlay 1px
569
- strategy . apply ( overlayElement ) ;
589
+ strategy . apply ( ) ;
570
590
571
591
expect ( positionChangeHandler ) . toHaveBeenCalled ( ) ;
572
592
positionChange = positionChangeHandler . calls . mostRecent ( ) . args [ 0 ] ;
@@ -580,7 +600,7 @@ describe('ConnectedPositionStrategy', () => {
580
600
581
601
it ( 'should evaluate the overlay and origin are both out of the view' , ( ) => {
582
602
scrollable . scrollTop = 61 ; // Scroll by overlay height + origin height + 1px buffer
583
- strategy . apply ( overlayElement ) ;
603
+ strategy . apply ( ) ;
584
604
585
605
expect ( positionChangeHandler ) . toHaveBeenCalled ( ) ;
586
606
positionChange = positionChangeHandler . calls . mostRecent ( ) . args [ 0 ] ;
@@ -626,7 +646,8 @@ describe('ConnectedPositionStrategy', () => {
626
646
{ originX : 'start' , originY : 'top' } ,
627
647
{ overlayX : 'start' , overlayY : 'top' } ) ;
628
648
629
- strategy . apply ( overlayElement ) ;
649
+ strategy . attach ( fakeOverlayRef ( overlayElement ) ) ;
650
+ strategy . apply ( ) ;
630
651
expect ( overlayElement . style . left ) . toBeTruthy ( ) ;
631
652
expect ( overlayElement . style . right ) . toBeFalsy ( ) ;
632
653
} ) ;
@@ -637,7 +658,8 @@ describe('ConnectedPositionStrategy', () => {
637
658
{ originX : 'end' , originY : 'top' } ,
638
659
{ overlayX : 'end' , overlayY : 'top' } ) ;
639
660
640
- strategy . apply ( overlayElement ) ;
661
+ strategy . attach ( fakeOverlayRef ( overlayElement ) ) ;
662
+ strategy . apply ( ) ;
641
663
expect ( overlayElement . style . right ) . toBeTruthy ( ) ;
642
664
expect ( overlayElement . style . left ) . toBeFalsy ( ) ;
643
665
} ) ;
@@ -653,7 +675,8 @@ describe('ConnectedPositionStrategy', () => {
653
675
)
654
676
. withDirection ( 'rtl' ) ;
655
677
656
- strategy . apply ( overlayElement ) ;
678
+ strategy . attach ( fakeOverlayRef ( overlayElement ) ) ;
679
+ strategy . apply ( ) ;
657
680
expect ( overlayElement . style . right ) . toBeTruthy ( ) ;
658
681
expect ( overlayElement . style . left ) . toBeFalsy ( ) ;
659
682
} ) ;
@@ -665,7 +688,8 @@ describe('ConnectedPositionStrategy', () => {
665
688
{ overlayX : 'end' , overlayY : 'top' }
666
689
) . withDirection ( 'rtl' ) ;
667
690
668
- strategy . apply ( overlayElement ) ;
691
+ strategy . attach ( fakeOverlayRef ( overlayElement ) ) ;
692
+ strategy . apply ( ) ;
669
693
expect ( overlayElement . style . left ) . toBeTruthy ( ) ;
670
694
expect ( overlayElement . style . right ) . toBeFalsy ( ) ;
671
695
} ) ;
@@ -679,7 +703,8 @@ describe('ConnectedPositionStrategy', () => {
679
703
{ overlayX : 'start' , overlayY : 'top' }
680
704
) ;
681
705
682
- strategy . apply ( overlayElement ) ;
706
+ strategy . attach ( fakeOverlayRef ( overlayElement ) ) ;
707
+ strategy . apply ( ) ;
683
708
expect ( overlayElement . style . top ) . toBeTruthy ( ) ;
684
709
expect ( overlayElement . style . bottom ) . toBeFalsy ( ) ;
685
710
} ) ;
@@ -691,7 +716,8 @@ describe('ConnectedPositionStrategy', () => {
691
716
{ overlayX : 'start' , overlayY : 'bottom' }
692
717
) ;
693
718
694
- strategy . apply ( overlayElement ) ;
719
+ strategy . attach ( fakeOverlayRef ( overlayElement ) ) ;
720
+ strategy . apply ( ) ;
695
721
expect ( overlayElement . style . bottom ) . toBeTruthy ( ) ;
696
722
expect ( overlayElement . style . top ) . toBeFalsy ( ) ;
697
723
} ) ;
@@ -741,3 +767,7 @@ function createOverflowContainerElement() {
741
767
class FakeElementRef implements ElementRef {
742
768
constructor ( public nativeElement : HTMLElement ) { }
743
769
}
770
+
771
+ function fakeOverlayRef ( overlayElement : HTMLElement ) {
772
+ return { overlayElement} as OverlayRef ;
773
+ }
0 commit comments