3 name: Element.Dimensions
9 describe('Element.Dimensions', function(){
11 var div, relDiv, absDiv, scrollDiv, tallDiv;
13 beforeEach(function(){
14 div = new Element('div', {
15 id: 'ElementDimensionsTest',
21 border: '1px solid black',
30 }).inject($(document.body));
32 relDiv = new Element('div', {
38 border: '1px solid green',
47 absDiv = new Element('div', {
53 border: '1px solid red',
62 scrollDiv = new Element('div', {
72 }).inject($(document.body));
74 tallDiv = new Element('div', {
83 describe('Element.getSize', function(){
85 it('should measure the width and height of the element', function(){
86 expect(div.getSize().x).toEqual(108);
87 expect(div.getSize().y).toEqual(108);
92 describe('Element.getPosition', function(){
94 it('should measure the x and y position of the element', function(){
95 expect(div.getPosition()).toEqual({x: 102, y: 102});
98 it('should measure the x and y position of the element relative to another', function(){
99 expect(relDiv.getPosition(div)).toEqual({x: 8, y: 8});
104 describe('Element.getCoordinates', function(){
106 it('should return the coordinates relative to parent', function(){
107 expect(absDiv.getCoordinates(relDiv)).toEqual({left:15, top:15, width:22, height:22, right:37, bottom:37});
112 describe('Element.getScrollSize', function(){
114 it('should return the scrollSize', function(){
115 expect(scrollDiv.getScrollSize()).toEqual({x:200, y:200});
120 describe('Element.scrollTo', function(){
122 it('should scroll the element', function(){
123 expect(scrollDiv.scrollTo(20, 20).getScroll()).toEqual({x:20, y:20});
128 afterEach(function(){
129 [div, relDiv, absDiv, scrollDiv, tallDiv].each(function(el){
136 describe('Element.getOffsetParent', function(){
138 var container, offsetParent, wrapper, child, table, td;
140 beforeEach(function(){
141 container = new Element('div');
143 offsetParent = new Element('div', {
144 styles: {position: 'relative'}
145 }).inject(container);
147 wrapper = new Element('div', {
149 }).inject(offsetParent);
151 child = new Element('div').inject(wrapper);
153 table = new Element('table').inject(offsetParent);
155 td = new Element('td').inject(new Element('tr').inject(table));
157 container.inject(document.body);
161 it('Should return the right offsetParent', function(){
163 expect(child.getOffsetParent()).toEqual(offsetParent);
167 it('Should return body for elements with body as offsetParent', function(){
169 expect(offsetParent.getOffsetParent()).toEqual(document.body);
173 it('Should return a table element for td-elements', function(){
175 expect(td.getOffsetParent()).toEqual(table);
179 it('Should return a td element for elements with position:static inside a td', function(){
183 expect(child.getOffsetParent()).toEqual(td);
187 it('Should not return a td element for elements with a position other than static inside a td', function(){
189 child.setStyle('position', 'absolute');
191 expect(child.getOffsetParent()).toEqual(offsetParent);
195 it('Should return null for elements with position:fixed', function(){
197 table.setStyle('position', 'fixed');
199 expect(table.getOffsetParent()).toBeNull();
203 it('Should return null for the body element', function(){
205 expect($(document.body).getOffsetParent()).toBeNull();
209 afterEach(function(){