@@ -7,11 +7,14 @@ import {
77 OverlayRef ,
88 createOverlayRef ,
99 createGlobalPositionStrategy ,
10+ GlobalPositionStrategy ,
11+ OverlayContainer ,
1012} from '../index' ;
1113
1214describe ( 'GlobalPositonStrategy' , ( ) => {
1315 let overlayRef : OverlayRef ;
1416 let injector : Injector ;
17+ let portal : ComponentPortal < BlankPortal > ;
1518
1619 beforeEach ( ( ) => {
1720 injector = TestBed . inject ( Injector ) ;
@@ -25,7 +28,7 @@ describe('GlobalPositonStrategy', () => {
2528 } ) ;
2629
2730 function attachOverlay ( config : OverlayConfig ) : OverlayRef {
28- const portal = new ComponentPortal ( BlankPortal ) ;
31+ portal = new ComponentPortal ( BlankPortal ) ;
2932 overlayRef = createOverlayRef ( injector , config ) ;
3033 overlayRef . attach ( portal ) ;
3134 TestBed . inject ( ApplicationRef ) . tick ( ) ;
@@ -469,6 +472,50 @@ describe('GlobalPositonStrategy', () => {
469472 expect ( elementStyle . marginRight ) . toBe ( '' ) ;
470473 expect ( parentStyle . justifyContent ) . toBe ( 'flex-end' ) ;
471474 } ) ;
475+
476+ describe ( 'DOM location' , ( ) => {
477+ let positionStrategy : GlobalPositionStrategy ;
478+ let containerElement : HTMLElement ;
479+
480+ beforeEach ( ( ) => {
481+ containerElement = TestBed . inject ( OverlayContainer ) . getContainerElement ( ) ;
482+ positionStrategy = createGlobalPositionStrategy ( injector ) ;
483+ } ) ;
484+
485+ it ( 'should place the overlay inside the overlay container by default' , ( ) => {
486+ attachOverlay ( { positionStrategy, usePopover : false } ) ;
487+ expect ( containerElement . contains ( overlayRef . hostElement ) ) . toBe ( true ) ;
488+ expect ( overlayRef . hostElement . getAttribute ( 'popover' ) ) . toBeFalsy ( ) ;
489+ } ) ;
490+
491+ it ( 'should be able to opt into placing the overlay inside a popover element' , ( ) => {
492+ if ( ! ( 'showPopover' in document . body ) ) {
493+ return ;
494+ }
495+
496+ attachOverlay ( { positionStrategy, usePopover : true } ) ;
497+
498+ expect ( containerElement . contains ( overlayRef . hostElement ) ) . toBe ( false ) ;
499+ expect ( document . body . lastChild ) . toBe ( overlayRef . hostElement ) ;
500+ expect ( overlayRef . hostElement . getAttribute ( 'popover' ) ) . toBe ( 'manual' ) ;
501+ } ) ;
502+
503+ it ( 'should re-attach the popover at the end of the body' , ( ) => {
504+ if ( ! ( 'showPopover' in document . body ) ) {
505+ return ;
506+ }
507+
508+ attachOverlay ( { positionStrategy, usePopover : true } ) ;
509+ expect ( document . body . lastChild ) . toBe ( overlayRef . hostElement ) ;
510+
511+ overlayRef . detach ( ) ;
512+ TestBed . inject ( ApplicationRef ) . tick ( ) ;
513+ expect ( overlayRef . hostElement . parentNode ) . toBeFalsy ( ) ;
514+
515+ overlayRef . attach ( portal ) ;
516+ expect ( document . body . lastChild ) . toBe ( overlayRef . hostElement ) ;
517+ } ) ;
518+ } ) ;
472519} ) ;
473520
474521@Component ( {
0 commit comments