@@ -3,6 +3,8 @@ import Node from "../../common/__mocks__/Node";
3
3
import {
4
4
HEIGHT_UNIT ,
5
5
WIDTH_UNIT ,
6
+ MIN_UNIT ,
7
+ MAX_UNIT ,
6
8
DEFINE_CONTAINER_NAME
7
9
} from "../../common/src/constants" ;
8
10
@@ -71,10 +73,18 @@ test("should extract all styles", () => {
71
73
} ) ;
72
74
} ) ;
73
75
74
- test ( "should throw if container units are used on a container with width or height properties" , ( ) => {
75
- const errorMessageRegex = / ^ A c o n t a i n e r c a n n o t u s e c o n t a i n e r u n i t s f o r t h e f o l l o w i n g p r o p e r t i e s / ;
76
+ test ( "should extract all container unit styles" , ( ) => {
77
+ expect (
78
+ getStylesObjectFromNode (
79
+ new Node ( {
80
+ type : "rule" ,
81
+ selector : ".container"
82
+ } ) ,
83
+ true
84
+ )
85
+ ) . toEqual ( { } ) ;
76
86
77
- expect ( ( ) => {
87
+ expect (
78
88
getStylesObjectFromNode (
79
89
new Node ( {
80
90
type : "rule" ,
@@ -86,18 +96,76 @@ test("should throw if container units are used on a container with width or heig
86
96
name : DEFINE_CONTAINER_NAME
87
97
} )
88
98
)
99
+ . addNode (
100
+ new Node ( {
101
+ type : "decl" ,
102
+ prop : "height" ,
103
+ value : "42px"
104
+ } )
105
+ )
89
106
. addNode (
90
107
new Node ( {
91
108
type : "decl" ,
92
109
prop : "width" ,
110
+ value : "42px"
111
+ } )
112
+ )
113
+ . addNode (
114
+ new Node ( {
115
+ type : "decl" ,
116
+ prop : "font-size" ,
117
+ value : `5${ HEIGHT_UNIT } px`
118
+ } )
119
+ )
120
+ . addNode (
121
+ new Node ( {
122
+ type : "decl" ,
123
+ prop : "line-height" ,
93
124
value : `42${ WIDTH_UNIT } px`
94
125
} )
126
+ )
127
+ . addNode (
128
+ new Node ( {
129
+ type : "decl" ,
130
+ prop : "border" ,
131
+ value : "none"
132
+ } )
95
133
) ,
96
134
true ,
135
+ true
136
+ )
137
+ ) . toEqual ( {
138
+ fontSize : `5${ HEIGHT_UNIT } px` ,
139
+ lineHeight : `42${ WIDTH_UNIT } px`
140
+ } ) ;
141
+ } ) ;
142
+
143
+ test ( "should throw if with / height are using the wrong container units" , ( ) => {
144
+ expect ( ( ) => {
145
+ getStylesObjectFromNode (
146
+ new Node ( {
147
+ type : "rule" ,
148
+ selector : ".container"
149
+ } )
150
+ . addNode (
151
+ new Node ( {
152
+ type : "atrule" ,
153
+ name : DEFINE_CONTAINER_NAME
154
+ } )
155
+ )
156
+ . addNode (
157
+ new Node ( {
158
+ type : "decl" ,
159
+ prop : "width" ,
160
+ value : `42${ MIN_UNIT } px`
161
+ } )
162
+ ) ,
97
163
true ,
98
164
true
99
165
) ;
100
- } ) . toThrowError ( errorMessageRegex ) ;
166
+ } ) . toThrow (
167
+ `Width and height properties on containers cannot use ${ MIN_UNIT } or ${ MAX_UNIT } units.`
168
+ ) ;
101
169
102
170
expect ( ( ) => {
103
171
getStylesObjectFromNode (
@@ -115,28 +183,43 @@ test("should throw if container units are used on a container with width or heig
115
183
new Node ( {
116
184
type : "decl" ,
117
185
prop : "height" ,
118
- value : `42${ WIDTH_UNIT } px`
186
+ value : `42${ MIN_UNIT } px`
119
187
} )
120
188
) ,
121
189
true ,
122
- true ,
123
190
true
124
191
) ;
125
- } ) . toThrowError ( errorMessageRegex ) ;
126
- } ) ;
192
+ } ) . toThrow (
193
+ `Width and height properties on containers cannot use ${ MIN_UNIT } or ${ MAX_UNIT } units.`
194
+ ) ;
127
195
128
- test ( "should extract all container unit styles" , ( ) => {
129
- expect (
196
+ expect ( ( ) => {
130
197
getStylesObjectFromNode (
131
198
new Node ( {
132
199
type : "rule" ,
133
200
selector : ".container"
134
- } ) ,
201
+ } )
202
+ . addNode (
203
+ new Node ( {
204
+ type : "atrule" ,
205
+ name : DEFINE_CONTAINER_NAME
206
+ } )
207
+ )
208
+ . addNode (
209
+ new Node ( {
210
+ type : "decl" ,
211
+ prop : "width" ,
212
+ value : `42${ MAX_UNIT } px`
213
+ } )
214
+ ) ,
215
+ true ,
135
216
true
136
- )
137
- ) . toEqual ( { } ) ;
217
+ ) ;
218
+ } ) . toThrow (
219
+ `Width and height properties on containers cannot use ${ MIN_UNIT } or ${ MAX_UNIT } units.`
220
+ ) ;
138
221
139
- expect (
222
+ expect ( ( ) => {
140
223
getStylesObjectFromNode (
141
224
new Node ( {
142
225
type : "rule" ,
@@ -152,42 +235,61 @@ test("should extract all container unit styles", () => {
152
235
new Node ( {
153
236
type : "decl" ,
154
237
prop : "height" ,
155
- value : "42px"
238
+ value : `42 ${ MAX_UNIT } px`
156
239
} )
157
- )
240
+ ) ,
241
+ true ,
242
+ true
243
+ ) ;
244
+ } ) . toThrow (
245
+ `Width and height properties on containers cannot use ${ MIN_UNIT } or ${ MAX_UNIT } units.`
246
+ ) ;
247
+
248
+ expect ( ( ) => {
249
+ getStylesObjectFromNode (
250
+ new Node ( {
251
+ type : "rule" ,
252
+ selector : ".container"
253
+ } )
158
254
. addNode (
159
255
new Node ( {
160
- type : "decl" ,
161
- prop : "width" ,
162
- value : "42px"
256
+ type : "atrule" ,
257
+ name : DEFINE_CONTAINER_NAME
163
258
} )
164
259
)
165
260
. addNode (
166
261
new Node ( {
167
262
type : "decl" ,
168
- prop : "font-size " ,
169
- value : `5 ${ HEIGHT_UNIT } px`
263
+ prop : "height " ,
264
+ value : `42 ${ HEIGHT_UNIT } px`
170
265
} )
171
- )
266
+ ) ,
267
+ true ,
268
+ true
269
+ ) ;
270
+ } ) . toThrow ( `Containers cannot use ${ HEIGHT_UNIT } for the height property.` ) ;
271
+
272
+ expect ( ( ) => {
273
+ getStylesObjectFromNode (
274
+ new Node ( {
275
+ type : "rule" ,
276
+ selector : ".container"
277
+ } )
172
278
. addNode (
173
279
new Node ( {
174
- type : "decl" ,
175
- prop : "line-height" ,
176
- value : `42${ WIDTH_UNIT } px`
280
+ type : "atrule" ,
281
+ name : DEFINE_CONTAINER_NAME
177
282
} )
178
283
)
179
284
. addNode (
180
285
new Node ( {
181
286
type : "decl" ,
182
- prop : "border " ,
183
- value : "none"
287
+ prop : "width " ,
288
+ value : `42 ${ WIDTH_UNIT } px`
184
289
} )
185
290
) ,
186
291
true ,
187
292
true
188
- )
189
- ) . toEqual ( {
190
- fontSize : `5${ HEIGHT_UNIT } px` ,
191
- lineHeight : `42${ WIDTH_UNIT } px`
192
- } ) ;
293
+ ) ;
294
+ } ) . toThrow ( `Containers cannot use ${ WIDTH_UNIT } for the width property.` ) ;
193
295
} ) ;
0 commit comments