1- import { fakeAsync , flushMicrotasks , inject } from '@angular/core/testing' ;
21import { GlobalPositionStrategy } from './global-position-strategy' ;
32import { OverlayRef } from '../overlay-ref' ;
43
@@ -19,11 +18,9 @@ describe('GlobalPositonStrategy', () => {
1918 strategy . dispose ( ) ;
2019 } ) ;
2120
22- it ( 'should position the element to the (top, left) with an offset' , fakeAsyncTest ( ( ) => {
21+ it ( 'should position the element to the (top, left) with an offset' , ( ) => {
2322 strategy . top ( '10px' ) . left ( '40px' ) . apply ( ) ;
2423
25- flushMicrotasks ( ) ;
26-
2724 let elementStyle = element . style ;
2825 let parentStyle = ( element . parentNode as HTMLElement ) . style ;
2926
@@ -34,13 +31,11 @@ describe('GlobalPositonStrategy', () => {
3431
3532 expect ( parentStyle . justifyContent ) . toBe ( 'flex-start' ) ;
3633 expect ( parentStyle . alignItems ) . toBe ( 'flex-start' ) ;
37- } ) ) ;
34+ } ) ;
3835
39- it ( 'should position the element to the (bottom, right) with an offset' , fakeAsyncTest ( ( ) => {
36+ it ( 'should position the element to the (bottom, right) with an offset' , ( ) => {
4037 strategy . bottom ( '70px' ) . right ( '15em' ) . apply ( ) ;
4138
42- flushMicrotasks ( ) ;
43-
4439 let elementStyle = element . style ;
4540 let parentStyle = ( element . parentNode as HTMLElement ) . style ;
4641
@@ -51,14 +46,11 @@ describe('GlobalPositonStrategy', () => {
5146
5247 expect ( parentStyle . justifyContent ) . toBe ( 'flex-end' ) ;
5348 expect ( parentStyle . alignItems ) . toBe ( 'flex-end' ) ;
54- } ) ) ;
49+ } ) ;
5550
56- it ( 'should overwrite previously applied positioning' , fakeAsyncTest ( ( ) => {
51+ it ( 'should overwrite previously applied positioning' , ( ) => {
5752 strategy . centerHorizontally ( ) . centerVertically ( ) . apply ( ) ;
58- flushMicrotasks ( ) ;
59-
6053 strategy . top ( '10px' ) . left ( '40%' ) . apply ( ) ;
61- flushMicrotasks ( ) ;
6254
6355 let elementStyle = element . style ;
6456 let parentStyle = ( element . parentNode as HTMLElement ) . style ;
@@ -73,33 +65,27 @@ describe('GlobalPositonStrategy', () => {
7365
7466 strategy . bottom ( '70px' ) . right ( '15em' ) . apply ( ) ;
7567
76- flushMicrotasks ( ) ;
77-
7868 expect ( element . style . marginTop ) . toBe ( '' ) ;
7969 expect ( element . style . marginLeft ) . toBe ( '' ) ;
8070 expect ( element . style . marginBottom ) . toBe ( '70px' ) ;
8171 expect ( element . style . marginRight ) . toBe ( '15em' ) ;
8272
8373 expect ( parentStyle . justifyContent ) . toBe ( 'flex-end' ) ;
8474 expect ( parentStyle . alignItems ) . toBe ( 'flex-end' ) ;
85- } ) ) ;
75+ } ) ;
8676
87- it ( 'should center the element' , fakeAsyncTest ( ( ) => {
77+ it ( 'should center the element' , ( ) => {
8878 strategy . centerHorizontally ( ) . centerVertically ( ) . apply ( ) ;
8979
90- flushMicrotasks ( ) ;
91-
9280 let parentStyle = ( element . parentNode as HTMLElement ) . style ;
9381
9482 expect ( parentStyle . justifyContent ) . toBe ( 'center' ) ;
9583 expect ( parentStyle . alignItems ) . toBe ( 'center' ) ;
96- } ) ) ;
84+ } ) ;
9785
98- it ( 'should center the element with an offset' , fakeAsyncTest ( ( ) => {
86+ it ( 'should center the element with an offset' , ( ) => {
9987 strategy . centerHorizontally ( '10px' ) . centerVertically ( '15px' ) . apply ( ) ;
10088
101- flushMicrotasks ( ) ;
102-
10389 let elementStyle = element . style ;
10490 let parentStyle = ( element . parentNode as HTMLElement ) . style ;
10591
@@ -108,74 +94,56 @@ describe('GlobalPositonStrategy', () => {
10894
10995 expect ( parentStyle . justifyContent ) . toBe ( 'center' ) ;
11096 expect ( parentStyle . alignItems ) . toBe ( 'center' ) ;
111- } ) ) ;
97+ } ) ;
11298
113- it ( 'should make the element position: static' , fakeAsyncTest ( ( ) => {
99+ it ( 'should make the element position: static' , ( ) => {
114100 strategy . apply ( ) ;
115101
116- flushMicrotasks ( ) ;
117-
118102 expect ( element . style . position ) . toBe ( 'static' ) ;
119- } ) ) ;
103+ } ) ;
120104
121- it ( 'should wrap the element in a `cdk-global-overlay-wrapper`' , fakeAsyncTest ( ( ) => {
105+ it ( 'should wrap the element in a `cdk-global-overlay-wrapper`' , ( ) => {
122106 strategy . apply ( ) ;
123107
124- flushMicrotasks ( ) ;
125-
126108 let parent = element . parentNode as HTMLElement ;
127109
128110 expect ( parent . classList . contains ( 'cdk-global-overlay-wrapper' ) ) . toBe ( true ) ;
129- } ) ) ;
111+ } ) ;
130112
131113
132- it ( 'should remove the parent wrapper from the DOM' , fakeAsync ( ( ) => {
114+ it ( 'should remove the parent wrapper from the DOM' , ( ) => {
133115 strategy . apply ( ) ;
134116
135- flushMicrotasks ( ) ;
136-
137117 expect ( document . body . contains ( element . parentNode ! ) ) . toBe ( true ) ;
138118
139119 strategy . dispose ( ) ;
140120
141121 expect ( document . body . contains ( element . parentNode ! ) ) . toBe ( false ) ;
142- } ) ) ;
122+ } ) ;
143123
144- it ( 'should set the element width' , fakeAsync ( ( ) => {
124+ it ( 'should set the element width' , ( ) => {
145125 strategy . width ( '100px' ) . apply ( ) ;
146126
147- flushMicrotasks ( ) ;
148-
149127 expect ( element . style . width ) . toBe ( '100px' ) ;
150- } ) ) ;
128+ } ) ;
151129
152- it ( 'should set the element height' , fakeAsync ( ( ) => {
130+ it ( 'should set the element height' , ( ) => {
153131 strategy . height ( '100px' ) . apply ( ) ;
154132
155- flushMicrotasks ( ) ;
156-
157133 expect ( element . style . height ) . toBe ( '100px' ) ;
158- } ) ) ;
134+ } ) ;
159135
160- it ( 'should reset the horizontal position and offset when the width is 100%' , fakeAsync ( ( ) => {
136+ it ( 'should reset the horizontal position and offset when the width is 100%' , ( ) => {
161137 strategy . centerHorizontally ( ) . width ( '100%' ) . apply ( ) ;
162138
163- flushMicrotasks ( ) ;
164-
165139 expect ( element . style . marginLeft ) . toBe ( '0px' ) ;
166140 expect ( ( element . parentNode as HTMLElement ) . style . justifyContent ) . toBe ( 'flex-start' ) ;
167- } ) ) ;
141+ } ) ;
168142
169- it ( 'should reset the vertical position and offset when the height is 100%' , fakeAsync ( ( ) => {
143+ it ( 'should reset the vertical position and offset when the height is 100%' , ( ) => {
170144 strategy . centerVertically ( ) . height ( '100%' ) . apply ( ) ;
171145
172- flushMicrotasks ( ) ;
173-
174146 expect ( element . style . marginTop ) . toBe ( '0px' ) ;
175147 expect ( ( element . parentNode as HTMLElement ) . style . alignItems ) . toBe ( 'flex-start' ) ;
176- } ) ) ;
148+ } ) ;
177149} ) ;
178-
179- function fakeAsyncTest ( fn : ( ) => void ) {
180- return inject ( [ ] , fakeAsync ( fn ) ) ;
181- }
0 commit comments