/
dom.js
40 lines (38 loc) · 1.24 KB
/
dom.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
describe('js/utils/dom', function() {
describe('getPositionInParent', function() {
it('should return 0,0 if el===parentEl', function() {
var el = {};
expect(ionic.DomUtil.getPositionInParent(el, el)).toEqual({
left: 0,
top: 0
});
});
it('should return 0,0 if el is null', function() {
expect(ionic.DomUtil.getPositionInParent(null, null)).toEqual({
left: 0,
top: 0
});
});
it('should return element offset{Top,Left} of el if el is parent\'s child', function() {
var parent = {};
var el = {parentNode: parent, offsetLeft: 3, offsetTop: 2};
expect(ionic.DomUtil.getPositionInParent(el, parent)).toEqual({
left: 3,
top: 2
});
});
it('should return added element offset{Top,Left} of all children up to parent', function() {
var parent = {};
var child1 = {parentNode: parent, offsetLeft: 5, offsetTop: 6};
var child2 = {parentNode: child1, offsetLeft: 10, offsetTop: 11};
expect(ionic.DomUtil.getPositionInParent(child1, parent)).toEqual({
left: 5,
top: 6
});
expect(ionic.DomUtil.getPositionInParent(child2, parent)).toEqual({
left: 15,
top: 17
});
});
});
});