tests.js
27.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
'use strict';
var cssstyle = require('../lib/CSSStyleDeclaration');
var { dashedToCamelCase } = require('../lib/parsers');
var dashedProperties = [
...require('../lib/allProperties'),
...require('../lib/allExtraProperties'),
];
var allowedProperties = dashedProperties.map(dashedToCamelCase);
var implementedProperties = Array.from(require('../lib/implementedProperties')).map(
dashedToCamelCase
);
var invalidProperties = implementedProperties.filter(function(property) {
return !allowedProperties.includes(property);
});
module.exports = {
'Verify Has Only Valid Properties Implemented': function(test) {
test.expect(1);
test.ok(
invalidProperties.length === 0,
invalidProperties.length +
' invalid properties implemented: ' +
Array.from(invalidProperties).join(', ')
);
test.done();
},
'Verify Has All Properties': function(test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(allowedProperties.length * 2);
allowedProperties.forEach(function(property) {
test.ok(style.__lookupGetter__(property), 'missing ' + property + ' property');
test.ok(style.__lookupSetter__(property), 'missing ' + property + ' property');
});
test.done();
},
'Verify Has All Dashed Properties': function(test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(dashedProperties.length * 2);
dashedProperties.forEach(function(property) {
test.ok(style.__lookupGetter__(property), 'missing ' + property + ' property');
test.ok(style.__lookupSetter__(property), 'missing ' + property + ' property');
});
test.done();
},
'Verify Has Functions': function(test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(6);
test.ok(typeof style.getPropertyValue === 'function', 'missing getPropertyValue()');
test.ok(typeof style.getPropertyCSSValue === 'function', 'missing getPropertyCSSValue()');
test.ok(typeof style.removeProperty === 'function', 'missing removeProperty()');
test.ok(typeof style.getPropertyPriority === 'function', 'missing getPropertyPriority()');
test.ok(typeof style.setProperty === 'function', 'missing setProperty()');
test.ok(typeof style.item === 'function', 'missing item()');
test.done();
},
'Verify Has Special Properties': function(test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(5);
test.ok(style.__lookupGetter__('cssText'), 'missing cssText getter');
test.ok(style.__lookupSetter__('cssText'), 'missing cssText setter');
test.ok(style.__lookupGetter__('length'), 'missing length getter');
test.ok(style.__lookupSetter__('length'), 'missing length setter');
test.ok(style.__lookupGetter__('parentRule'), 'missing parentRule getter');
test.done();
},
'Test From Style String': function(test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(8);
style.cssText = 'color: blue; background-color: red; width: 78%; height: 50vh;';
test.ok(4 === style.length, 'length is not 4');
test.ok(
'color: blue; background-color: red; width: 78%; height: 50vh;' === style.cssText,
'cssText is wrong'
);
test.ok('blue' === style.getPropertyValue('color'), "getPropertyValue('color') failed");
test.ok('color' === style.item(0), 'item(0) failed');
test.ok('background-color' === style[1], 'style[1] failed');
test.ok(
'red' === style.backgroundColor,
'style.backgroundColor failed with "' + style.backgroundColor + '"'
);
style.cssText = '';
test.ok('' === style.cssText, 'cssText is not empty');
test.ok(0 === style.length, 'length is not 0');
test.done();
},
'Test From Properties': function(test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(11);
style.color = 'blue';
test.ok(1 === style.length, 'length is not 1');
test.ok('color' === style[0], 'style[0] is not color');
test.ok('color: blue;' === style.cssText, 'cssText is wrong');
test.ok('color' === style.item(0), 'item(0) is not color');
test.ok('blue' === style.color, 'color is not blue');
style.backgroundColor = 'red';
test.ok(2 === style.length, 'length is not 2');
test.ok('color' === style[0], 'style[0] is not color');
test.ok('background-color' === style[1], 'style[1] is not background-color');
test.ok('color: blue; background-color: red;' === style.cssText, 'cssText is wrong');
test.ok('red' === style.backgroundColor, 'backgroundColor is not red');
style.removeProperty('color');
test.ok('background-color' === style[0], 'style[0] is not background-color');
test.done();
},
'Test Shorthand Properties': function(test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(11);
style.background = 'blue url(http://www.example.com/some_img.jpg)';
test.ok('blue' === style.backgroundColor, 'backgroundColor is not blue');
test.ok(
'url(http://www.example.com/some_img.jpg)' === style.backgroundImage,
'backgroundImage is wrong'
);
test.ok(
'blue url(http://www.example.com/some_img.jpg)' === style.background,
'background is different'
);
style.border = '0 solid black';
test.ok('0px' === style.borderWidth, 'borderWidth is not 0px');
test.ok('solid' === style.borderStyle, 'borderStyle is not solid');
test.ok('black' === style.borderColor, 'borderColor is not black');
test.ok('0px' === style.borderTopWidth, 'borderTopWidth is not 0px');
test.ok('solid' === style.borderLeftStyle, 'borderLeftStyle is not solid');
test.ok('black' === style.borderBottomColor, 'borderBottomColor is not black');
style.font = '12em monospace';
test.ok('12em' === style.fontSize, 'fontSize is not 12em');
test.ok('monospace' === style.fontFamily, 'fontFamily is not monospace');
test.done();
},
'Test width and height Properties and null and empty strings': function(test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(9);
style.height = 6;
test.ok('' === style.height, 'height does not remain unset');
style.width = 0;
test.ok('0px' === style.width, 'width is not 0px');
style.height = '34%';
test.ok('34%' === style.height, 'height is not 34%');
style.height = '100vh';
test.ok('100vh' === style.height, 'height is not 100vh');
style.height = '100vw';
test.ok('100vw' === style.height, 'height is not 100vw');
style.height = '';
test.ok(style.length === 1, 'length is not 1');
test.ok('width: 0px;' === style.cssText, 'cssText is not "width: 0px;"');
style.width = null;
test.ok(style.length === 0, 'length is not 0');
test.ok('' === style.cssText, 'cssText is not empty string');
test.done();
},
'Test Implicit Properties': function(test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(7);
style.borderWidth = 0;
test.ok(1 === style.length, 'length is not 1');
test.ok('0px' === style.borderWidth, 'borderWidth is not 0px');
test.ok('0px' === style.borderTopWidth, 'borderTopWidth is not 0px');
test.ok('0px' === style.borderBottomWidth, 'borderBottomWidth is not 0px');
test.ok('0px' === style.borderLeftWidth, 'borderLeftWidth is not 0px');
test.ok('0px' === style.borderRightWidth, 'borderRightWidth is not 0px');
test.ok(
'border-width: 0px;' === style.cssText,
'cssText is not "border-width: 0px", "' + style.cssText + '"'
);
test.done();
},
'Test Top, Left, Right, Bottom Properties': function(test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(6);
style.top = 0;
style.left = '0%';
style.right = '5em';
style.bottom = '12pt';
test.ok('0px' === style.top, 'top is not 0px');
test.ok('0%' === style.left, 'left is not 0%');
test.ok('5em' === style.right, 'right is not 5em');
test.ok('12pt' === style.bottom, 'bottom is not 12pt');
test.ok(4 === style.length, 'length is not 4');
test.ok(
'top: 0px; left: 0%; right: 5em; bottom: 12pt;' === style.cssText,
'text is not "top: 0px; left: 0%; right: 5em; bottom: 12pt;"'
);
test.done();
},
'Test Clear and Clip Properties': function(test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(10);
style.clear = 'none';
test.ok('none' === style.clear, 'clear is not none');
style.clear = 'lfet'; // intentionally wrong
test.ok('none' === style.clear, 'clear is not still none');
style.clear = 'left';
test.ok('left' === style.clear, 'clear is not left');
style.clear = 'right';
test.ok('right' === style.clear, 'clear is not right');
style.clear = 'both';
test.ok('both' === style.clear, 'clear is not both');
style.clip = 'elipse(5px, 10px)';
test.ok('' === style.clip, 'clip should not be set');
test.ok(1 === style.length, 'length is not 1');
style.clip = 'rect(0, 3Em, 2pt, 50%)';
test.ok(
'rect(0px, 3em, 2pt, 50%)' === style.clip,
'clip is not "rect(0px, 3em, 2pt, 50%)", "' + style.clip + '"'
);
test.ok(2 === style.length, 'length is not 2');
test.ok(
'clear: both; clip: rect(0px, 3em, 2pt, 50%);' === style.cssText,
'cssText is not "clear: both; clip: rect(0px, 3em, 2pt, 50%);"'
);
test.done();
},
'Test colors': function(test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(9);
style.color = 'rgba(0,0,0,0)';
test.ok('rgba(0, 0, 0, 0)' === style.color, 'color is not rgba(0, 0, 0, 0)');
style.color = 'rgba(5%, 10%, 20%, 0.4)';
test.ok('rgba(12, 25, 51, 0.4)' === style.color, 'color is not rgba(12, 25, 51, 0.4)');
style.color = 'rgb(33%, 34%, 33%)';
test.ok('rgb(84, 86, 84)' === style.color, 'color is not rgb(84, 86, 84)');
style.color = 'rgba(300, 200, 100, 1.5)';
test.ok('rgb(255, 200, 100)' === style.color, 'color is not rgb(255, 200, 100) ' + style.color);
style.color = 'hsla(0, 1%, 2%, 0.5)';
test.ok(
'hsla(0, 1%, 2%, 0.5)' === style.color,
'color is not hsla(0, 1%, 2%, 0.5) ' + style.color
);
style.color = 'hsl(0, 1%, 2%)';
test.ok('hsl(0, 1%, 2%)' === style.color, 'color is not hsl(0, 1%, 2%) ' + style.color);
style.color = 'rebeccapurple';
test.ok('rebeccapurple' === style.color, 'color is not rebeccapurple ' + style.color);
style.color = 'transparent';
test.ok('transparent' === style.color, 'color is not transparent ' + style.color);
style.color = 'currentcolor';
test.ok('currentcolor' === style.color, 'color is not currentcolor ' + style.color);
test.done();
},
'Test short hand properties with embedded spaces': function(test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(4);
style.background = 'rgb(0, 0, 0) url(/something/somewhere.jpg)';
test.ok(
'rgb(0, 0, 0)' === style.backgroundColor,
'backgroundColor is not rgb(0, 0, 0): ' + style.backgroundColor
);
test.ok(
'url(/something/somewhere.jpg)' === style.backgroundImage,
'backgroundImage is not url(/something/somewhere.jpg): ' + style.backgroundImage
);
test.ok(
'background: rgb(0, 0, 0) url(/something/somewhere.jpg);' === style.cssText,
'cssText is not correct: ' + style.cssText
);
style = new cssstyle.CSSStyleDeclaration();
style.border = ' 1px solid black ';
test.ok(
'1px solid black' === style.border,
'multiple spaces not properly parsed: ' + style.border
);
test.done();
},
'Setting shorthand properties to an empty string should clear all dependent properties': function(
test
) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(2);
style.borderWidth = '1px';
test.ok(
'border-width: 1px;' === style.cssText,
'cssText is not "border-width: 1px;": ' + style.cssText
);
style.border = '';
test.ok('' === style.cssText, 'cssText is not "": ' + style.cssText);
test.done();
},
'Setting implicit properties to an empty string should clear all dependent properties': function(
test
) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(2);
style.borderTopWidth = '1px';
test.ok(
'border-top-width: 1px;' === style.cssText,
'cssText is not "border-top-width: 1px;": ' + style.cssText
);
style.borderWidth = '';
test.ok('' === style.cssText, 'cssText is not "": ' + style.cssText);
test.done();
},
'Setting a shorthand property, whose shorthands are implicit properties, to an empty string should clear all dependent properties': function(
test
) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(4);
style.borderTopWidth = '1px';
test.ok(
'border-top-width: 1px;' === style.cssText,
'cssText is not "border-top-width: 1px;": ' + style.cssText
);
style.border = '';
test.ok('' === style.cssText, 'cssText is not "": ' + style.cssText);
style.borderTop = '1px solid black';
test.ok(
'border-top: 1px solid black;' === style.cssText,
'cssText is not "border-top: 1px solid black;": ' + style.cssText
);
style.border = '';
test.ok('' === style.cssText, 'cssText is not "": ' + style.cssText);
test.done();
},
'Setting border values to "none" should clear dependent values': function(test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(8);
style.borderTopWidth = '1px';
test.ok(
'border-top-width: 1px;' === style.cssText,
'cssText is not "border-top-width: 1px;": ' + style.cssText
);
style.border = 'none';
test.ok('' === style.cssText, 'cssText is not "": ' + style.cssText);
style.borderTopWidth = '1px';
test.ok(
'border-top-width: 1px;' === style.cssText,
'cssText is not "border-top-width: 1px;": ' + style.cssText
);
style.borderTopStyle = 'none';
test.ok('' === style.cssText, 'cssText is not "": ' + style.cssText);
style.borderTopWidth = '1px';
test.ok(
'border-top-width: 1px;' === style.cssText,
'cssText is not "border-top-width: 1px;": ' + style.cssText
);
style.borderTop = 'none';
test.ok('' === style.cssText, 'cssText is not "": ' + style.cssText);
style.borderTopWidth = '1px';
style.borderLeftWidth = '1px';
test.ok(
'border-top-width: 1px; border-left-width: 1px;' === style.cssText,
'cssText is not "border-top-width: 1px; border-left-width: 1px;": ' + style.cssText
);
style.borderTop = 'none';
test.ok(
'border-left-width: 1px;' === style.cssText,
'cssText is not "border-left-width: 1px;": ' + style.cssText
);
test.done();
},
'Setting border to 0 should be okay': function(test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(1);
style.border = 0;
test.ok('border: 0px;' === style.cssText, 'cssText is not "border: 0px;": ' + style.cssText);
test.done();
},
'Setting values implicit and shorthand properties via cssText and setProperty should propagate to dependent properties': function(
test
) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(4);
style.cssText = 'border: 1px solid black;';
test.ok(
'border: 1px solid black;' === style.cssText,
'cssText is not "border: 1px solid black;": ' + style.cssText
);
test.ok(
'1px solid black' === style.borderTop,
'borderTop is not "1px solid black": ' + style.borderTop
);
style.border = '';
test.ok('' === style.cssText, 'cssText is not "": ' + style.cssText);
style.setProperty('border', '1px solid black');
test.ok(
'border: 1px solid black;' === style.cssText,
'cssText is not "border: 1px solid black;": ' + style.cssText
);
test.done();
},
'Setting opacity should work': function(test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(3);
style.setProperty('opacity', 0.75);
test.ok(
'opacity: 0.75;' === style.cssText,
'cssText is not "opacity: 0.75;": ' + style.cssText
);
style.opacity = '0.50';
test.ok('opacity: 0.5;' === style.cssText, 'cssText is not "opacity: 0.5;": ' + style.cssText);
style.opacity = 1.0;
test.ok('opacity: 1;' === style.cssText, 'cssText is not "opacity: 1;": ' + style.cssText);
test.done();
},
'Width and height of auto should work': function(test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(4);
style.width = 'auto';
test.equal(style.cssText, 'width: auto;', 'cssText is not "width: auto;": ' + style.cssText);
test.equal(style.width, 'auto', 'width is not "auto": ' + style.width);
style = new cssstyle.CSSStyleDeclaration();
style.height = 'auto';
test.equal(style.cssText, 'height: auto;', 'cssText is not "height: auto;": ' + style.cssText);
test.equal(style.height, 'auto', 'height is not "auto": ' + style.height);
test.done();
},
'Padding and margin should set/clear shorthand properties': function(test) {
var style = new cssstyle.CSSStyleDeclaration();
var parts = ['Top', 'Right', 'Bottom', 'Left'];
var testParts = function(name, v, V) {
style[name] = v;
for (var i = 0; i < 4; i++) {
var part = name + parts[i];
test.equal(V[i], style[part], part + ' is not "' + V[i] + '": "' + style[part] + '"');
}
test.equal(v, style[name], name + ' is not "' + v + '": "' + style[name] + '"');
style[name] = '';
};
test.expect(50);
testParts('padding', '1px', ['1px', '1px', '1px', '1px']);
testParts('padding', '1px 2%', ['1px', '2%', '1px', '2%']);
testParts('padding', '1px 2px 3px', ['1px', '2px', '3px', '2px']);
testParts('padding', '1px 2px 3px 4px', ['1px', '2px', '3px', '4px']);
style.paddingTop = style.paddingRight = style.paddingBottom = style.paddingLeft = '1px';
testParts('padding', '', ['', '', '', '']);
testParts('margin', '1px', ['1px', '1px', '1px', '1px']);
testParts('margin', '1px auto', ['1px', 'auto', '1px', 'auto']);
testParts('margin', '1px 2% 3px', ['1px', '2%', '3px', '2%']);
testParts('margin', '1px 2px 3px 4px', ['1px', '2px', '3px', '4px']);
style.marginTop = style.marginRight = style.marginBottom = style.marginLeft = '1px';
testParts('margin', '', ['', '', '', '']);
test.done();
},
'Padding and margin shorthands should set main properties': function(test) {
var style = new cssstyle.CSSStyleDeclaration();
var parts = ['Top', 'Right', 'Bottom', 'Left'];
var testParts = function(name, v, V) {
var expect;
for (var i = 0; i < 4; i++) {
style[name] = v;
style[name + parts[i]] = V;
expect = v.split(/ /);
expect[i] = V;
expect = expect.join(' ');
test.equal(expect, style[name], name + ' is not "' + expect + '": "' + style[name] + '"');
}
};
test.expect(12);
testParts('padding', '1px 2px 3px 4px', '10px');
testParts('margin', '1px 2px 3px 4px', '10px');
testParts('margin', '1px 2px 3px 4px', 'auto');
test.done();
},
'Setting a value to 0 should return the string value': function(test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(1);
style.setProperty('fill-opacity', 0);
test.ok('0' === style.fillOpacity, 'fillOpacity is not "0": ' + style.fillOpacity);
test.done();
},
'onChange callback should be called when the cssText changes': function(test) {
var style = new cssstyle.CSSStyleDeclaration(function(cssText) {
test.ok('opacity: 0;' === cssText, 'cssText is not "opacity: 0;": ' + cssText);
test.done();
});
test.expect(1);
style.setProperty('opacity', 0);
},
'Setting float should work the same as cssFloat': function(test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(1);
style.float = 'left';
test.ok('left' === style.cssFloat, 'cssFloat is not "left": ' + style.cssFloat);
test.done();
},
'Setting improper css to cssText should not throw': function(test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(2);
style.cssText = 'color: ';
test.ok('' === style.cssText, "cssText wasn't cleared: " + style.cssText);
style.color = 'black';
style.cssText = 'float: ';
test.ok('' === style.cssText, "cssText wasn't cleared: " + style.cssText);
test.done();
},
'Make sure url parsing works with quotes': function(test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(3);
style.backgroundImage = 'url(http://some/url/here1.png)';
test.ok(
'url(http://some/url/here1.png)' === style.backgroundImage,
"background-image wasn't url(http://some/url/here1.png): " + style.backgroundImage
);
style.backgroundImage = "url('http://some/url/here2.png')";
test.ok(
'url(http://some/url/here2.png)' === style.backgroundImage,
"background-image wasn't url(http://some/url/here2.png): " + style.backgroundImage
);
style.backgroundImage = 'url("http://some/url/here3.png")';
test.ok(
'url(http://some/url/here3.png)' === style.backgroundImage,
"background-image wasn't url(http://some/url/here3.png): " + style.backgroundImage
);
test.done();
},
'Make sure setting 0 to a padding or margin works': function(test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(2);
style.padding = 0;
test.equal(style.cssText, 'padding: 0px;', 'padding is not 0px');
style.margin = '1em';
style.marginTop = '0';
test.equal(style.marginTop, '0px', 'margin-top is not 0px');
test.done();
},
'Make sure setting ex units to a padding or margin works': function(test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(2);
style.padding = '1ex';
test.equal(style.cssText, 'padding: 1ex;', 'padding is not 1ex');
style.margin = '1em';
style.marginTop = '0.5ex';
test.equal(style.marginTop, '0.5ex', 'margin-top is not 0.5ex');
test.done();
},
'Make sure setting null to background works': function(test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(2);
style.background = 'red';
test.equal(style.cssText, 'background: red;', 'background is not red');
style.background = null;
test.equal(style.cssText, '', 'cssText is not empty');
test.done();
},
'Flex properties should keep their values': function(test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(2);
style.flexDirection = 'column';
test.equal(style.cssText, 'flex-direction: column;', 'flex-direction is not column');
style.flexDirection = 'row';
test.equal(style.cssText, 'flex-direction: row;', 'flex-direction is not column');
test.done();
},
'Make sure camelCase properties are not assigned with `.setProperty()`': function(test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(1);
style.setProperty('fontSize', '12px');
test.equal(style.cssText, '', 'cssText is not empty');
test.done();
},
'Make sure casing is ignored in `.setProperty()`': function(test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(2);
style.setProperty('FoNt-SiZe', '12px');
test.equal(style.fontSize, '12px', 'font-size: 12px');
test.equal(style.getPropertyValue('font-size'), '12px', 'font-size: 12px');
test.done();
},
'Support non string entries in border-spacing': function(test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(1);
style.borderSpacing = 0;
test.equal(style.cssText, 'border-spacing: 0px;', 'border-spacing is not 0');
test.done();
},
'Float should be valid property for `.setProperty()`': function(test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(2);
style.setProperty('float', 'left');
test.equal(style.float, 'left');
test.equal(style.getPropertyValue('float'), 'left', 'float: left');
test.done();
},
'Make sure flex-shrink works': function(test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(3);
style.setProperty('flex-shrink', 0);
test.equal(style.getPropertyValue('flex-shrink'), '0', 'flex-shrink is not 0');
style.setProperty('flex-shrink', 1);
test.equal(style.getPropertyValue('flex-shrink'), '1', 'flex-shrink is not 1');
test.equal(style.cssText, 'flex-shrink: 1;', 'flex-shrink cssText is incorrect');
test.done();
},
'Make sure flex-grow works': function(test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(2);
style.setProperty('flex-grow', 2);
test.equal(style.getPropertyValue('flex-grow'), '2', 'flex-grow is not 2');
test.equal(style.cssText, 'flex-grow: 2;', 'flex-grow cssText is incorrect');
test.done();
},
'Make sure flex-basis works': function(test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(5);
style.setProperty('flex-basis', 0);
test.equal(style.getPropertyValue('flex-basis'), '0px', 'flex-basis is not 0px');
style.setProperty('flex-basis', '250px');
test.equal(style.getPropertyValue('flex-basis'), '250px', 'flex-basis is not 250px');
style.setProperty('flex-basis', '10em');
test.equal(style.getPropertyValue('flex-basis'), '10em', 'flex-basis is not 10em');
style.setProperty('flex-basis', '30%');
test.equal(style.getPropertyValue('flex-basis'), '30%', 'flex-basis is not 30%');
test.equal(style.cssText, 'flex-basis: 30%;', 'flex-basis cssText is incorrect');
test.done();
},
'Make sure shorthand flex works': function(test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(19);
style.setProperty('flex', 'none');
test.equal(style.getPropertyValue('flex-grow'), '0', 'flex-grow is not 0 if flex: none;');
test.equal(style.getPropertyValue('flex-shrink'), '0', 'flex-shrink is not 0 if flex: none;');
test.equal(
style.getPropertyValue('flex-basis'),
'auto',
'flex-basis is not `auto` if flex: none;'
);
style.removeProperty('flex');
style.removeProperty('flex-basis');
style.setProperty('flex', 'auto');
test.equal(style.getPropertyValue('flex-grow'), '', 'flex-grow is not empty if flex: auto;');
test.equal(
style.getPropertyValue('flex-shrink'),
'',
'flex-shrink is not empty if flex: auto;'
);
test.equal(
style.getPropertyValue('flex-basis'),
'auto',
'flex-basis is not `auto` if flex: auto;'
);
style.removeProperty('flex');
style.setProperty('flex', '0 1 250px');
test.equal(style.getPropertyValue('flex'), '0 1 250px', 'flex value is not `0 1 250px`');
test.equal(style.getPropertyValue('flex-grow'), '0', 'flex-grow is not 0');
test.equal(style.getPropertyValue('flex-shrink'), '1', 'flex-shrink is not 1');
test.equal(style.getPropertyValue('flex-basis'), '250px', 'flex-basis is not 250px');
style.removeProperty('flex');
style.setProperty('flex', '2');
test.equal(style.getPropertyValue('flex-grow'), '2', 'flex-grow is not 2');
test.equal(style.getPropertyValue('flex-shrink'), '', 'flex-shrink is not empty');
test.equal(style.getPropertyValue('flex-basis'), '', 'flex-basis is not empty');
style.removeProperty('flex');
style.setProperty('flex', '20%');
test.equal(style.getPropertyValue('flex-grow'), '', 'flex-grow is not empty');
test.equal(style.getPropertyValue('flex-shrink'), '', 'flex-shrink is not empty');
test.equal(style.getPropertyValue('flex-basis'), '20%', 'flex-basis is not 20%');
style.removeProperty('flex');
style.setProperty('flex', '2 2');
test.equal(style.getPropertyValue('flex-grow'), '2', 'flex-grow is not 2');
test.equal(style.getPropertyValue('flex-shrink'), '2', 'flex-shrink is not 2');
test.equal(style.getPropertyValue('flex-basis'), '', 'flex-basis is not empty');
style.removeProperty('flex');
test.done();
},
};