@@ -13,28 +13,45 @@ describe('GlobalPositonStrategy', () => {
13
13
beforeEach ( ( ) => {
14
14
element = document . createElement ( 'div' ) ;
15
15
strategy = new GlobalPositionStrategy ( ) ;
16
+ document . body . appendChild ( element ) ;
16
17
} ) ;
17
18
18
- it ( 'should set explicit (top, left) position to the element' , fakeAsyncTest ( ( ) => {
19
- strategy . top ( '10px' ) . left ( '40%' ) . apply ( element ) ;
19
+ afterEach ( ( ) => {
20
+ strategy . dispose ( ) ;
21
+ } ) ;
22
+
23
+ it ( 'should position the element to the (top, left) with an offset' , fakeAsyncTest ( ( ) => {
24
+ strategy . top ( '10px' ) . left ( '40px' ) . apply ( element ) ;
20
25
21
26
flushMicrotasks ( ) ;
22
27
23
- expect ( element . style . top ) . toBe ( '10px' ) ;
24
- expect ( element . style . left ) . toBe ( '40%' ) ;
25
- expect ( element . style . bottom ) . toBe ( '' ) ;
26
- expect ( element . style . right ) . toBe ( '' ) ;
28
+ let elementStyle = element . style ;
29
+ let parentStyle = ( element . parentNode as HTMLElement ) . style ;
30
+
31
+ expect ( elementStyle . marginTop ) . toBe ( '10px' ) ;
32
+ expect ( elementStyle . marginLeft ) . toBe ( '40px' ) ;
33
+ expect ( elementStyle . marginBottom ) . toBe ( '' ) ;
34
+ expect ( elementStyle . marginRight ) . toBe ( '' ) ;
35
+
36
+ expect ( parentStyle . justifyContent ) . toBe ( 'flex-start' ) ;
37
+ expect ( parentStyle . alignItems ) . toBe ( 'flex-start' ) ;
27
38
} ) ) ;
28
39
29
- it ( 'should set explicit (bottom, right) position to the element ' , fakeAsyncTest ( ( ) => {
40
+ it ( 'should position the element to the (bottom, right) with an offset ' , fakeAsyncTest ( ( ) => {
30
41
strategy . bottom ( '70px' ) . right ( '15em' ) . apply ( element ) ;
31
42
32
43
flushMicrotasks ( ) ;
33
44
34
- expect ( element . style . top ) . toBe ( '' ) ;
35
- expect ( element . style . left ) . toBe ( '' ) ;
36
- expect ( element . style . bottom ) . toBe ( '70px' ) ;
37
- expect ( element . style . right ) . toBe ( '15em' ) ;
45
+ let elementStyle = element . style ;
46
+ let parentStyle = ( element . parentNode as HTMLElement ) . style ;
47
+
48
+ expect ( elementStyle . marginTop ) . toBe ( '' ) ;
49
+ expect ( elementStyle . marginLeft ) . toBe ( '' ) ;
50
+ expect ( elementStyle . marginBottom ) . toBe ( '70px' ) ;
51
+ expect ( elementStyle . marginRight ) . toBe ( '15em' ) ;
52
+
53
+ expect ( parentStyle . justifyContent ) . toBe ( 'flex-end' ) ;
54
+ expect ( parentStyle . alignItems ) . toBe ( 'flex-end' ) ;
38
55
} ) ) ;
39
56
40
57
it ( 'should overwrite previously applied positioning' , fakeAsyncTest ( ( ) => {
@@ -44,61 +61,85 @@ describe('GlobalPositonStrategy', () => {
44
61
strategy . top ( '10px' ) . left ( '40%' ) . apply ( element ) ;
45
62
flushMicrotasks ( ) ;
46
63
47
- expect ( element . style . top ) . toBe ( '10px' ) ;
48
- expect ( element . style . left ) . toBe ( '40%' ) ;
49
- expect ( element . style . bottom ) . toBe ( '' ) ;
50
- expect ( element . style . right ) . toBe ( '' ) ;
51
- expect ( element . style . transform ) . not . toContain ( 'translate' ) ;
64
+ let elementStyle = element . style ;
65
+ let parentStyle = ( element . parentNode as HTMLElement ) . style ;
66
+
67
+ expect ( elementStyle . marginTop ) . toBe ( '10px' ) ;
68
+ expect ( elementStyle . marginLeft ) . toBe ( '40%' ) ;
69
+ expect ( elementStyle . marginBottom ) . toBe ( '' ) ;
70
+ expect ( elementStyle . marginRight ) . toBe ( '' ) ;
71
+
72
+ expect ( parentStyle . justifyContent ) . toBe ( 'flex-start' ) ;
73
+ expect ( parentStyle . alignItems ) . toBe ( 'flex-start' ) ;
52
74
53
75
strategy . bottom ( '70px' ) . right ( '15em' ) . apply ( element ) ;
54
76
55
77
flushMicrotasks ( ) ;
56
78
57
- expect ( element . style . top ) . toBe ( '' ) ;
58
- expect ( element . style . left ) . toBe ( '' ) ;
59
- expect ( element . style . bottom ) . toBe ( '70px' ) ;
60
- expect ( element . style . right ) . toBe ( '15em' ) ;
61
- expect ( element . style . transform ) . not . toContain ( 'translate' ) ;
79
+ expect ( element . style . marginTop ) . toBe ( '' ) ;
80
+ expect ( element . style . marginLeft ) . toBe ( '' ) ;
81
+ expect ( element . style . marginBottom ) . toBe ( '70px' ) ;
82
+ expect ( element . style . marginRight ) . toBe ( '15em' ) ;
83
+
84
+ expect ( parentStyle . justifyContent ) . toBe ( 'flex-end' ) ;
85
+ expect ( parentStyle . alignItems ) . toBe ( 'flex-end' ) ;
62
86
} ) ) ;
63
87
64
88
it ( 'should center the element' , fakeAsyncTest ( ( ) => {
65
89
strategy . centerHorizontally ( ) . centerVertically ( ) . apply ( element ) ;
66
90
67
91
flushMicrotasks ( ) ;
68
92
69
- expect ( element . style . top ) . toBe ( '50%' ) ;
70
- expect ( element . style . left ) . toBe ( '50%' ) ;
71
- expect ( element . style . transform ) . toContain ( 'translateX(-50%) ') ;
72
- expect ( element . style . transform ) . toContain ( 'translateY(-50%) ') ;
93
+ let parentStyle = ( element . parentNode as HTMLElement ) . style ;
94
+
95
+ expect ( parentStyle . justifyContent ) . toBe ( 'center ') ;
96
+ expect ( parentStyle . alignItems ) . toBe ( 'center ') ;
73
97
} ) ) ;
74
98
75
99
it ( 'should center the element with an offset' , fakeAsyncTest ( ( ) => {
76
100
strategy . centerHorizontally ( '10px' ) . centerVertically ( '15px' ) . apply ( element ) ;
77
101
78
102
flushMicrotasks ( ) ;
79
103
80
- expect ( element . style . top ) . toBe ( '50%' ) ;
81
- expect ( element . style . left ) . toBe ( '50%' ) ;
82
- expect ( element . style . transform ) . toContain ( 'translateX(-50%)' ) ;
83
- expect ( element . style . transform ) . toContain ( 'translateX(10px)' ) ;
84
- expect ( element . style . transform ) . toContain ( 'translateY(-50%)' ) ;
85
- expect ( element . style . transform ) . toContain ( 'translateY(15px)' ) ;
104
+ let elementStyle = element . style ;
105
+ let parentStyle = ( element . parentNode as HTMLElement ) . style ;
106
+
107
+ expect ( elementStyle . marginLeft ) . toBe ( '10px' ) ;
108
+ expect ( elementStyle . marginTop ) . toBe ( '15px' ) ;
109
+
110
+ expect ( parentStyle . justifyContent ) . toBe ( 'center' ) ;
111
+ expect ( parentStyle . alignItems ) . toBe ( 'center' ) ;
112
+ } ) ) ;
113
+
114
+ it ( 'should make the element position: static' , fakeAsyncTest ( ( ) => {
115
+ strategy . apply ( element ) ;
116
+
117
+ flushMicrotasks ( ) ;
118
+
119
+ expect ( element . style . position ) . toBe ( 'static' ) ;
86
120
} ) ) ;
87
121
88
- it ( 'should default the element to position: absolute ' , fakeAsyncTest ( ( ) => {
122
+ it ( 'should wrap the element in a `md-global-overlay-wrapper` ' , fakeAsyncTest ( ( ) => {
89
123
strategy . apply ( element ) ;
90
124
91
125
flushMicrotasks ( ) ;
92
126
93
- expect ( element . style . position ) . toBe ( 'absolute' ) ;
127
+ let parent = element . parentNode as HTMLElement ;
128
+
129
+ expect ( parent . classList . contains ( 'md-global-overlay-wrapper' ) ) . toBe ( true ) ;
94
130
} ) ) ;
95
131
96
- it ( 'should make the element position: fixed' , fakeAsyncTest ( ( ) => {
97
- strategy . fixed ( ) . apply ( element ) ;
132
+
133
+ it ( 'should remove the parent wrapper from the DOM' , fakeAsync ( ( ) => {
134
+ strategy . apply ( element ) ;
98
135
99
136
flushMicrotasks ( ) ;
100
137
101
- expect ( element . style . position ) . toBe ( 'fixed' ) ;
138
+ expect ( document . body . contains ( element . parentNode ) ) . toBe ( true ) ;
139
+
140
+ strategy . dispose ( ) ;
141
+
142
+ expect ( document . body . contains ( element . parentNode ) ) . toBe ( false ) ;
102
143
} ) ) ;
103
144
104
145
it ( 'should set the element width' , fakeAsync ( ( ) => {
@@ -122,17 +163,17 @@ describe('GlobalPositonStrategy', () => {
122
163
123
164
flushMicrotasks ( ) ;
124
165
125
- expect ( element . style . left ) . toBe ( '0px' ) ;
126
- expect ( element . style . transform ) . toBe ( '' ) ;
166
+ expect ( element . style . marginLeft ) . toBe ( '0px' ) ;
167
+ expect ( ( element . parentNode as HTMLElement ) . style . justifyContent ) . toBe ( 'flex-start ' ) ;
127
168
} ) ) ;
128
169
129
170
it ( 'should reset the vertical position and offset when the height is 100%' , fakeAsync ( ( ) => {
130
171
strategy . centerVertically ( ) . height ( '100%' ) . apply ( element ) ;
131
172
132
173
flushMicrotasks ( ) ;
133
174
134
- expect ( element . style . top ) . toBe ( '0px' ) ;
135
- expect ( element . style . transform ) . toBe ( '' ) ;
175
+ expect ( element . style . marginTop ) . toBe ( '0px' ) ;
176
+ expect ( ( element . parentNode as HTMLElement ) . style . alignItems ) . toBe ( 'flex-start ' ) ;
136
177
} ) ) ;
137
178
} ) ;
138
179
0 commit comments