@@ -7,7 +7,7 @@ import {ConnectedOverlayPositionChange} from './connected-position';
77import { CdkScrollable } from '@angular/cdk/scrolling' ;
88import { Subscription } from 'rxjs/Subscription' ;
99import { ScrollDispatchModule } from '@angular/cdk/scrolling' ;
10- import { OverlayRef } from '../overlay-ref ' ;
10+ import { OverlayRef , OverlayContainer , OverlayModule } from '../index ' ;
1111
1212
1313// Default width and height of the overlay and origin panels throughout these tests.
@@ -19,18 +19,25 @@ const DEFAULT_WIDTH = 60;
1919// for tests on CI (both SauceLabs and Browserstack).
2020
2121describe ( 'ConnectedPositionStrategy' , ( ) => {
22-
22+ let overlayContainer : OverlayContainer ;
23+ let overlayContainerElement : HTMLElement ;
2324 let viewportRuler : ViewportRuler ;
2425
2526 beforeEach ( ( ) => TestBed . configureTestingModule ( {
26- imports : [ ScrollDispatchModule ] ,
27+ imports : [ ScrollDispatchModule , OverlayModule ] ,
2728 providers : [ VIEWPORT_RULER_PROVIDER ]
2829 } ) ) ;
2930
30- beforeEach ( inject ( [ ViewportRuler ] , ( _ruler : ViewportRuler ) => {
31- viewportRuler = _ruler ;
31+ beforeEach ( inject ( [ ViewportRuler , OverlayContainer ] , ( r : ViewportRuler , oc : OverlayContainer ) => {
32+ viewportRuler = r ;
33+ overlayContainer = oc ;
34+ overlayContainerElement = oc . getContainerElement ( ) ;
3235 } ) ) ;
3336
37+ afterEach ( ( ) => {
38+ overlayContainer . ngOnDestroy ( ) ;
39+ } ) ;
40+
3441 describe ( 'with origin on document body' , ( ) => {
3542 const ORIGIN_HEIGHT = DEFAULT_HEIGHT ;
3643 const ORIGIN_WIDTH = DEFAULT_WIDTH ;
@@ -39,7 +46,6 @@ describe('ConnectedPositionStrategy', () => {
3946
4047 let originElement : HTMLElement ;
4148 let overlayElement : HTMLElement ;
42- let overlayContainerElement : HTMLElement ;
4349 let strategy : ConnectedPositionStrategy ;
4450 let fakeElementRef : ElementRef ;
4551 let positionBuilder : OverlayPositionBuilder ;
@@ -51,10 +57,8 @@ describe('ConnectedPositionStrategy', () => {
5157 beforeEach ( ( ) => {
5258 // The origin and overlay elements need to be in the document body in order to have geometry.
5359 originElement = createPositionedBlockElement ( ) ;
54- overlayContainerElement = createOverlayContainer ( ) ;
5560 overlayElement = createPositionedBlockElement ( ) ;
5661 document . body . appendChild ( originElement ) ;
57- document . body . appendChild ( overlayContainerElement ) ;
5862 overlayContainerElement . appendChild ( overlayElement ) ;
5963
6064 fakeElementRef = new FakeElementRef ( originElement ) ;
@@ -63,7 +67,6 @@ describe('ConnectedPositionStrategy', () => {
6367
6468 afterEach ( ( ) => {
6569 document . body . removeChild ( originElement ) ;
66- document . body . removeChild ( overlayContainerElement ) ;
6770
6871 // Reset the origin geometry after each test so we don't accidently keep state between tests.
6972 originRect = null ;
@@ -559,7 +562,6 @@ describe('ConnectedPositionStrategy', () => {
559562
560563 describe ( 'onPositionChange with scrollable view properties' , ( ) => {
561564 let overlayElement : HTMLElement ;
562- let overlayContainerElement : HTMLElement ;
563565 let strategy : ConnectedPositionStrategy ;
564566
565567 let scrollable : HTMLDivElement ;
@@ -569,9 +571,7 @@ describe('ConnectedPositionStrategy', () => {
569571
570572 beforeEach ( ( ) => {
571573 // Set up the overlay
572- overlayContainerElement = createOverlayContainer ( ) ;
573574 overlayElement = createPositionedBlockElement ( ) ;
574- document . body . appendChild ( overlayContainerElement ) ;
575575 overlayContainerElement . appendChild ( overlayElement ) ;
576576
577577 // Set up the origin
@@ -601,7 +601,6 @@ describe('ConnectedPositionStrategy', () => {
601601 afterEach ( ( ) => {
602602 onPositionChangeSubscription . unsubscribe ( ) ;
603603 document . body . removeChild ( scrollable ) ;
604- document . body . removeChild ( overlayContainerElement ) ;
605604 } ) ;
606605
607606 it ( 'should not have origin or overlay clipped or out of view without scroll' , ( ) => {
@@ -663,18 +662,15 @@ describe('ConnectedPositionStrategy', () => {
663662 describe ( 'positioning properties' , ( ) => {
664663 let originElement : HTMLElement ;
665664 let overlayElement : HTMLElement ;
666- let overlayContainerElement : HTMLElement ;
667665 let strategy : ConnectedPositionStrategy ;
668666 let fakeElementRef : ElementRef ;
669667 let positionBuilder : OverlayPositionBuilder ;
670668
671669 beforeEach ( ( ) => {
672670 // The origin and overlay elements need to be in the document body in order to have geometry.
673671 originElement = createPositionedBlockElement ( ) ;
674- overlayContainerElement = createOverlayContainer ( ) ;
675672 overlayElement = createPositionedBlockElement ( ) ;
676673 document . body . appendChild ( originElement ) ;
677- document . body . appendChild ( overlayContainerElement ) ;
678674 overlayContainerElement . appendChild ( overlayElement ) ;
679675
680676 fakeElementRef = new FakeElementRef ( originElement ) ;
@@ -683,7 +679,6 @@ describe('ConnectedPositionStrategy', () => {
683679
684680 afterEach ( ( ) => {
685681 document . body . removeChild ( originElement ) ;
686- document . body . removeChild ( overlayContainerElement ) ;
687682 } ) ;
688683
689684 describe ( 'in ltr' , ( ) => {
@@ -791,13 +786,6 @@ function createBlockElement() {
791786 return element ;
792787}
793788
794- /** Creates the wrapper for all of the overlays. */
795- function createOverlayContainer ( ) {
796- let element = document . createElement ( 'div' ) ;
797- element . classList . add ( 'cdk-overlay-container' ) ;
798- return element ;
799- }
800-
801789/** Creates an overflow container with a set height and width with margin. */
802790function createOverflowContainerElement ( ) {
803791 let element = document . createElement ( 'div' ) ;
0 commit comments