@@ -6,7 +6,6 @@ import {OverlayPositionBuilder} from './overlay-position-builder';
6
6
import { ConnectedOverlayPositionChange } from './connected-position' ;
7
7
import { Scrollable } from '../scroll/scrollable' ;
8
8
import { Subscription } from 'rxjs/Subscription' ;
9
- import Spy = jasmine . Spy ;
10
9
import { ScrollDispatchModule } from '../scroll/index' ;
11
10
12
11
@@ -343,53 +342,65 @@ describe('ConnectedPositionStrategy', () => {
343
342
expect ( latestCall . args [ 0 ] instanceof ConnectedOverlayPositionChange )
344
343
. toBe ( true , `Expected strategy to emit an instance of ConnectedOverlayPositionChange.` ) ;
345
344
346
- it ( 'should pick the fallback position that shows the largest area of the element' , ( ) => {
347
- positionBuilder = new OverlayPositionBuilder ( viewportRuler ) ;
345
+ // If the strategy is re-applied and the initial position would now fit,
346
+ // the position change event should be emitted again.
347
+ originElement . style . top = '200px' ;
348
+ originElement . style . left = '200px' ;
349
+ strategy . apply ( overlayElement ) ;
348
350
349
- originElement . style . top = '200px' ;
350
- originElement . style . right = '25px' ;
351
- originRect = originElement . getBoundingClientRect ( ) ;
351
+ expect ( positionChangeHandler ) . toHaveBeenCalledTimes ( 2 ) ;
352
352
353
- strategy = positionBuilder . connectedTo (
354
- fakeElementRef ,
355
- { originX : 'end' , originY : 'center' } ,
356
- { overlayX : 'start' , overlayY : 'center' } )
357
- . withFallbackPosition (
358
- { originX : 'end' , originY : 'top' } ,
359
- { overlayX : 'start' , overlayY : 'bottom' } )
360
- . withFallbackPosition (
361
- { originX : 'end' , originY : 'top' } ,
362
- { overlayX : 'end' , overlayY : 'top' } ) ;
353
+ subscription . unsubscribe ( ) ;
354
+ } ) ;
363
355
364
- strategy . apply ( overlayElement ) ;
356
+ it ( 'should emit the onPositionChange event even if none of the positions fit' , ( ) => {
357
+ positionBuilder = new OverlayPositionBuilder ( viewportRuler ) ;
358
+ originElement . style . bottom = '25px' ;
359
+ originElement . style . right = '25px' ;
365
360
366
- let overlayRect = overlayElement . getBoundingClientRect ( ) ;
361
+ strategy = positionBuilder . connectedTo (
362
+ fakeElementRef ,
363
+ { originX : 'end' , originY : 'bottom' } ,
364
+ { overlayX : 'start' , overlayY : 'top' } )
365
+ . withFallbackPosition (
366
+ { originX : 'start' , originY : 'bottom' } ,
367
+ { overlayX : 'end' , overlayY : 'top' } ) ;
367
368
368
- expect ( Math . floor ( overlayRect . top ) ) . toBe ( Math . floor ( originRect . top ) ) ;
369
- expect ( Math . floor ( overlayRect . left ) ) . toBe ( Math . floor ( originRect . left ) ) ;
370
- } ) ;
369
+ const positionChangeHandler = jasmine . createSpy ( 'positionChangeHandler' ) ;
370
+ const subscription = strategy . onPositionChange . subscribe ( positionChangeHandler ) ;
371
371
372
- it ( 'should position a panel properly when rtl' , ( ) => {
373
- // must make the overlay longer than the origin to properly test attachment
374
- overlayElement . style . width = `500px` ;
375
- originRect = originElement . getBoundingClientRect ( ) ;
376
- strategy = positionBuilder . connectedTo (
377
- fakeElementRef ,
378
- { originX : 'start' , originY : 'bottom' } ,
379
- { overlayX : 'start' , overlayY : 'top' } )
380
- . withDirection ( 'rtl' ) ;
381
- originElement . style . top = '0' ;
382
- originElement . style . left = '0' ;
372
+ strategy . apply ( overlayElement ) ;
383
373
384
- // If the strategy is re-applied and the initial position would now fit,
385
- // the position change event should be emitted again.
386
- strategy . apply ( overlayElement ) ;
387
- expect ( positionChangeHandler ) . toHaveBeenCalledTimes ( 2 ) ;
374
+ expect ( positionChangeHandler ) . toHaveBeenCalled ( ) ;
388
375
389
- subscription . unsubscribe ( ) ;
390
- } ) ;
376
+ subscription . unsubscribe ( ) ;
391
377
} ) ;
392
378
379
+ it ( 'should pick the fallback position that shows the largest area of the element' , ( ) => {
380
+ positionBuilder = new OverlayPositionBuilder ( viewportRuler ) ;
381
+
382
+ originElement . style . top = '200px' ;
383
+ originElement . style . right = '25px' ;
384
+ originRect = originElement . getBoundingClientRect ( ) ;
385
+
386
+ strategy = positionBuilder . connectedTo (
387
+ fakeElementRef ,
388
+ { originX : 'end' , originY : 'center' } ,
389
+ { overlayX : 'start' , overlayY : 'center' } )
390
+ . withFallbackPosition (
391
+ { originX : 'end' , originY : 'top' } ,
392
+ { overlayX : 'start' , overlayY : 'bottom' } )
393
+ . withFallbackPosition (
394
+ { originX : 'end' , originY : 'top' } ,
395
+ { overlayX : 'end' , overlayY : 'top' } ) ;
396
+
397
+ strategy . apply ( overlayElement ) ;
398
+
399
+ let overlayRect = overlayElement . getBoundingClientRect ( ) ;
400
+
401
+ expect ( Math . floor ( overlayRect . top ) ) . toBe ( Math . floor ( originRect . top ) ) ;
402
+ expect ( Math . floor ( overlayRect . left ) ) . toBe ( Math . floor ( originRect . left ) ) ;
403
+ } ) ;
393
404
394
405
/**
395
406
* Run all tests for connecting the overlay to the origin such that first preferred
@@ -485,7 +496,7 @@ describe('ConnectedPositionStrategy', () => {
485
496
let strategy : ConnectedPositionStrategy ;
486
497
487
498
let scrollable : HTMLDivElement ;
488
- let positionChangeHandler : Spy ;
499
+ let positionChangeHandler : jasmine . Spy ;
489
500
let onPositionChangeSubscription : Subscription ;
490
501
let positionChange : ConnectedOverlayPositionChange ;
491
502
0 commit comments