@@ -33,6 +33,7 @@ describe('FlexibleConnectedPositionStrategy', () => {
3333 let overlayRef : OverlayRef ;
3434 let viewport : ViewportRuler ;
3535 let injector : Injector ;
36+ let portal : ComponentPortal < TestOverlay > ;
3637
3738 beforeEach ( ( ) => {
3839 injector = TestBed . inject ( Injector ) ;
@@ -50,7 +51,8 @@ describe('FlexibleConnectedPositionStrategy', () => {
5051
5152 function attachOverlay ( config : OverlayConfig ) {
5253 overlayRef = createOverlayRef ( injector , config ) ;
53- overlayRef . attach ( new ComponentPortal ( TestOverlay ) ) ;
54+ portal = new ComponentPortal ( TestOverlay ) ;
55+ overlayRef . attach ( portal ) ;
5456 TestBed . inject ( ApplicationRef ) . tick ( ) ;
5557 }
5658
@@ -125,7 +127,7 @@ describe('FlexibleConnectedPositionStrategy', () => {
125127 origin . remove ( ) ;
126128 } ) ;
127129
128- it ( 'should for the virtual keyboard offset when positioning the overlay' , ( ) => {
130+ it ( 'should account for the virtual keyboard offset when positioning the overlay' , ( ) => {
129131 const originElement = createPositionedBlockElement ( ) ;
130132 document . body . appendChild ( originElement ) ;
131133
@@ -2951,6 +2953,70 @@ describe('FlexibleConnectedPositionStrategy', () => {
29512953 expect ( overlayClassList ) . toContain ( 'custom-panel-class' ) ;
29522954 } ) ;
29532955 } ) ;
2956+
2957+ describe ( 'DOM location' , ( ) => {
2958+ let positionStrategy : FlexibleConnectedPositionStrategy ;
2959+ let containerElement : HTMLElement ;
2960+ let originElement : HTMLElement ;
2961+
2962+ beforeEach ( ( ) => {
2963+ containerElement = overlayContainer . getContainerElement ( ) ;
2964+ originElement = createPositionedBlockElement ( ) ;
2965+ document . body . appendChild ( originElement ) ;
2966+
2967+ positionStrategy = createFlexibleConnectedPositionStrategy (
2968+ injector ,
2969+ originElement ,
2970+ ) . withPositions ( [
2971+ {
2972+ overlayX : 'start' ,
2973+ overlayY : 'top' ,
2974+ originX : 'start' ,
2975+ originY : 'bottom' ,
2976+ } ,
2977+ ] ) ;
2978+ } ) ;
2979+
2980+ afterEach ( ( ) => {
2981+ originElement . remove ( ) ;
2982+ } ) ;
2983+
2984+ it ( 'should place the overlay inside the overlay container by default' , ( ) => {
2985+ attachOverlay ( { positionStrategy} ) ;
2986+ expect ( containerElement . contains ( overlayRef . hostElement ) ) . toBe ( true ) ;
2987+ expect ( overlayRef . hostElement . getAttribute ( 'popover' ) ) . toBeFalsy ( ) ;
2988+ } ) ;
2989+
2990+ it ( 'should be able to opt into placing the overlay inside an adjacent popover element' , ( ) => {
2991+ if ( ! ( 'showPopover' in document . body ) ) {
2992+ return ;
2993+ }
2994+
2995+ positionStrategy . asPopover ( true ) ;
2996+ attachOverlay ( { positionStrategy} ) ;
2997+
2998+ expect ( containerElement . contains ( overlayRef . hostElement ) ) . toBe ( false ) ;
2999+ expect ( originElement . nextElementSibling ) . toBe ( overlayRef . hostElement ) ;
3000+ expect ( overlayRef . hostElement . getAttribute ( 'popover' ) ) . toBe ( 'manual' ) ;
3001+ } ) ;
3002+
3003+ it ( 'should re-attach the popover next to the origin element' , ( ) => {
3004+ if ( ! ( 'showPopover' in document . body ) ) {
3005+ return ;
3006+ }
3007+
3008+ positionStrategy . asPopover ( true ) ;
3009+ attachOverlay ( { positionStrategy} ) ;
3010+ expect ( originElement . nextElementSibling ) . toBe ( overlayRef . hostElement ) ;
3011+
3012+ overlayRef . detach ( ) ;
3013+ TestBed . inject ( ApplicationRef ) . tick ( ) ;
3014+ expect ( overlayRef . hostElement . parentNode ) . toBeFalsy ( ) ;
3015+
3016+ overlayRef . attach ( portal ) ;
3017+ expect ( originElement . nextElementSibling ) . toBe ( overlayRef . hostElement ) ;
3018+ } ) ;
3019+ } ) ;
29543020} ) ;
29553021
29563022/** Creates an absolutely positioned, display: block element with a default size. */
0 commit comments