forked from prototypejs/prototype
/
layout_test.js
82 lines (60 loc) · 2.94 KB
/
layout_test.js
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
function isDisplayed(element) {
var originalElement = element;
while (element && element.parentNode) {
var display = element.getStyle('display');
if (display === 'none') {
return false;
}
element = $(element.parentNode);
}
return true;
}
new Test.Unit.Runner({
setup: function() {
},
'test layout on absolutely-positioned elements': function() {
var layout = $('box1').getLayout();
this.assertEqual(242, layout.get('width'), 'width' );
this.assertEqual(555, layout.get('height'), 'height');
this.assertEqual(3, layout.get('border-left'), 'border-left');
this.assertEqual(10, layout.get('padding-top'), 'padding-top');
this.assertEqual(1020, layout.get('top'), 'top');
this.assertEqual(25, layout.get('left'), 'left');
},
'test layout on elements with display: none and exact width': function() {
var layout = $('box2').getLayout();
this.assert(!isDisplayed($('box3')), 'box should be hidden');
this.assertEqual(500, layout.get('width'), 'width');
this.assertEqual(3, layout.get('border-right'), 'border-right');
this.assertEqual(10, layout.get('padding-bottom'), 'padding-bottom');
this.assert(!isDisplayed($('box3')), 'box should still be hidden');
},
'test layout on elements with display: none and width: auto': function() {
var layout = $('box3').getLayout();
this.assert(!isDisplayed($('box3')), 'box should be hidden');
this.assertEqual(364, layout.get('width'), 'width');
this.assertEqual(400, layout.get('margin-box-width'), 'margin-box-width');
this.assertEqual(3, layout.get('border-right'), 'border-top');
this.assertEqual(10, layout.get('padding-bottom'), 'padding-right');
// Ensure that we cleaned up after ourselves.
this.assert(!isDisplayed($('box3')), 'box should still be hidden');
},
'test layout on elements with display: none ancestors': function() {
var layout = $('box4').getLayout();
this.assert(!isDisplayed($('box4')), 'box should be hidden');
// Width and height values are nonsensical for deeply-hidden elements.
this.assertEqual(0, layout.get('width'), 'width of a deeply-hidden element should be 0');
this.assertEqual(0, layout.get('margin-box-height'), 'height of a deeply-hidden element should be 0');
// But we can still get meaningful values for other measurements.
this.assertEqual(0, layout.get('border-right'), 'border-top');
this.assertEqual(13, layout.get('padding-bottom'), 'padding-right');
// Ensure that we cleaned up after ourselves.
this.assert(!isDisplayed($('box3')), 'box should still be hidden');
},
'test positioning on absolutely-positioned elements': function() {
var layout = $('box5').getLayout();
this.assertEqual(30, layout.get('top'), 'top');
this.assertEqual(60, layout.get('right'), 'right (percentage value)');
this.assertEqual(340, layout.get('left'), 'left');
}
});