1
- import { fakeAsync , flushMicrotasks , inject } from '@angular/core/testing' ;
2
1
import { GlobalPositionStrategy } from './global-position-strategy' ;
3
2
import { OverlayRef } from '../overlay-ref' ;
4
3
@@ -19,11 +18,9 @@ describe('GlobalPositonStrategy', () => {
19
18
strategy . dispose ( ) ;
20
19
} ) ;
21
20
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' , ( ) => {
23
22
strategy . top ( '10px' ) . left ( '40px' ) . apply ( ) ;
24
23
25
- flushMicrotasks ( ) ;
26
-
27
24
let elementStyle = element . style ;
28
25
let parentStyle = ( element . parentNode as HTMLElement ) . style ;
29
26
@@ -34,13 +31,11 @@ describe('GlobalPositonStrategy', () => {
34
31
35
32
expect ( parentStyle . justifyContent ) . toBe ( 'flex-start' ) ;
36
33
expect ( parentStyle . alignItems ) . toBe ( 'flex-start' ) ;
37
- } ) ) ;
34
+ } ) ;
38
35
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' , ( ) => {
40
37
strategy . bottom ( '70px' ) . right ( '15em' ) . apply ( ) ;
41
38
42
- flushMicrotasks ( ) ;
43
-
44
39
let elementStyle = element . style ;
45
40
let parentStyle = ( element . parentNode as HTMLElement ) . style ;
46
41
@@ -51,14 +46,11 @@ describe('GlobalPositonStrategy', () => {
51
46
52
47
expect ( parentStyle . justifyContent ) . toBe ( 'flex-end' ) ;
53
48
expect ( parentStyle . alignItems ) . toBe ( 'flex-end' ) ;
54
- } ) ) ;
49
+ } ) ;
55
50
56
- it ( 'should overwrite previously applied positioning' , fakeAsyncTest ( ( ) => {
51
+ it ( 'should overwrite previously applied positioning' , ( ) => {
57
52
strategy . centerHorizontally ( ) . centerVertically ( ) . apply ( ) ;
58
- flushMicrotasks ( ) ;
59
-
60
53
strategy . top ( '10px' ) . left ( '40%' ) . apply ( ) ;
61
- flushMicrotasks ( ) ;
62
54
63
55
let elementStyle = element . style ;
64
56
let parentStyle = ( element . parentNode as HTMLElement ) . style ;
@@ -73,33 +65,27 @@ describe('GlobalPositonStrategy', () => {
73
65
74
66
strategy . bottom ( '70px' ) . right ( '15em' ) . apply ( ) ;
75
67
76
- flushMicrotasks ( ) ;
77
-
78
68
expect ( element . style . marginTop ) . toBe ( '' ) ;
79
69
expect ( element . style . marginLeft ) . toBe ( '' ) ;
80
70
expect ( element . style . marginBottom ) . toBe ( '70px' ) ;
81
71
expect ( element . style . marginRight ) . toBe ( '15em' ) ;
82
72
83
73
expect ( parentStyle . justifyContent ) . toBe ( 'flex-end' ) ;
84
74
expect ( parentStyle . alignItems ) . toBe ( 'flex-end' ) ;
85
- } ) ) ;
75
+ } ) ;
86
76
87
- it ( 'should center the element' , fakeAsyncTest ( ( ) => {
77
+ it ( 'should center the element' , ( ) => {
88
78
strategy . centerHorizontally ( ) . centerVertically ( ) . apply ( ) ;
89
79
90
- flushMicrotasks ( ) ;
91
-
92
80
let parentStyle = ( element . parentNode as HTMLElement ) . style ;
93
81
94
82
expect ( parentStyle . justifyContent ) . toBe ( 'center' ) ;
95
83
expect ( parentStyle . alignItems ) . toBe ( 'center' ) ;
96
- } ) ) ;
84
+ } ) ;
97
85
98
- it ( 'should center the element with an offset' , fakeAsyncTest ( ( ) => {
86
+ it ( 'should center the element with an offset' , ( ) => {
99
87
strategy . centerHorizontally ( '10px' ) . centerVertically ( '15px' ) . apply ( ) ;
100
88
101
- flushMicrotasks ( ) ;
102
-
103
89
let elementStyle = element . style ;
104
90
let parentStyle = ( element . parentNode as HTMLElement ) . style ;
105
91
@@ -108,74 +94,56 @@ describe('GlobalPositonStrategy', () => {
108
94
109
95
expect ( parentStyle . justifyContent ) . toBe ( 'center' ) ;
110
96
expect ( parentStyle . alignItems ) . toBe ( 'center' ) ;
111
- } ) ) ;
97
+ } ) ;
112
98
113
- it ( 'should make the element position: static' , fakeAsyncTest ( ( ) => {
99
+ it ( 'should make the element position: static' , ( ) => {
114
100
strategy . apply ( ) ;
115
101
116
- flushMicrotasks ( ) ;
117
-
118
102
expect ( element . style . position ) . toBe ( 'static' ) ;
119
- } ) ) ;
103
+ } ) ;
120
104
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`' , ( ) => {
122
106
strategy . apply ( ) ;
123
107
124
- flushMicrotasks ( ) ;
125
-
126
108
let parent = element . parentNode as HTMLElement ;
127
109
128
110
expect ( parent . classList . contains ( 'cdk-global-overlay-wrapper' ) ) . toBe ( true ) ;
129
- } ) ) ;
111
+ } ) ;
130
112
131
113
132
- it ( 'should remove the parent wrapper from the DOM' , fakeAsync ( ( ) => {
114
+ it ( 'should remove the parent wrapper from the DOM' , ( ) => {
133
115
strategy . apply ( ) ;
134
116
135
- flushMicrotasks ( ) ;
136
-
137
117
expect ( document . body . contains ( element . parentNode ! ) ) . toBe ( true ) ;
138
118
139
119
strategy . dispose ( ) ;
140
120
141
121
expect ( document . body . contains ( element . parentNode ! ) ) . toBe ( false ) ;
142
- } ) ) ;
122
+ } ) ;
143
123
144
- it ( 'should set the element width' , fakeAsync ( ( ) => {
124
+ it ( 'should set the element width' , ( ) => {
145
125
strategy . width ( '100px' ) . apply ( ) ;
146
126
147
- flushMicrotasks ( ) ;
148
-
149
127
expect ( element . style . width ) . toBe ( '100px' ) ;
150
- } ) ) ;
128
+ } ) ;
151
129
152
- it ( 'should set the element height' , fakeAsync ( ( ) => {
130
+ it ( 'should set the element height' , ( ) => {
153
131
strategy . height ( '100px' ) . apply ( ) ;
154
132
155
- flushMicrotasks ( ) ;
156
-
157
133
expect ( element . style . height ) . toBe ( '100px' ) ;
158
- } ) ) ;
134
+ } ) ;
159
135
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%' , ( ) => {
161
137
strategy . centerHorizontally ( ) . width ( '100%' ) . apply ( ) ;
162
138
163
- flushMicrotasks ( ) ;
164
-
165
139
expect ( element . style . marginLeft ) . toBe ( '0px' ) ;
166
140
expect ( ( element . parentNode as HTMLElement ) . style . justifyContent ) . toBe ( 'flex-start' ) ;
167
- } ) ) ;
141
+ } ) ;
168
142
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%' , ( ) => {
170
144
strategy . centerVertically ( ) . height ( '100%' ) . apply ( ) ;
171
145
172
- flushMicrotasks ( ) ;
173
-
174
146
expect ( element . style . marginTop ) . toBe ( '0px' ) ;
175
147
expect ( ( element . parentNode as HTMLElement ) . style . alignItems ) . toBe ( 'flex-start' ) ;
176
- } ) ) ;
148
+ } ) ;
177
149
} ) ;
178
-
179
- function fakeAsyncTest ( fn : ( ) => void ) {
180
- return inject ( [ ] , fakeAsync ( fn ) ) ;
181
- }
0 commit comments