forked from ionic-team/ionic-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscrollView.unit.js
More file actions
85 lines (70 loc) · 2.29 KB
/
scrollView.unit.js
File metadata and controls
85 lines (70 loc) · 2.29 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
describe('Scroll View', function() {
var sc;
beforeEach(function() {
sc = document.createElement('scroll-content');
s = document.createElement('scroll');
sc.appendChild(s);
});
it('Should init', function() {
var sv = new ionic.views.Scroll({
el: sc
});
});
it('Should have Y and not X scroll and bars by default', function() {
var sv = new ionic.views.Scroll({
el: sc,
});
expect(sv.options.scrollingX).toBe(false);
expect(sc.children[1].classList.contains('scroll-bar')).toBe(true);
expect(sc.children[2]).toBe(undefined);
});
it('Should enable scrollbars', function() {
var sv = new ionic.views.Scroll({
el: sc,
scrollbarsX: true,
scrollingX: true,
scrollbarsY: true,
scrollingY: true
});
expect(sc.children[1].classList.contains('scroll-bar')).toBe(true);
expect(sc.children[2].classList.contains('scroll-bar')).toBe(true);
});
it('Should shrink on scrollChildIntoView if not already', function() {
ionic.Platform.setPlatform('ios');
var input = document.createElement('input');
s.appendChild(input);
document.body.appendChild(sc);
var sv = new ionic.views.Scroll({
el: sc
});
sc.style.height = "500px";
sc.style.display = "block";
var _scrollGetBoundingClientRect = sc.getBoundingClientRect;
var _RAF = ionic.requestAnimationFrame;
sc.getBoundingClientRect = function(){
return { bottom: 520 };
};
ionic.requestAnimationFrame = function(cb){ cb(); };
var details = {
target: input,
elementTop: 500,
elementBottom: 510,
keyboardHeight: 300,
viewportHeight: 568,
windowHeight: 268,
isElementUnderKeyboard: true
};
spyOn(sv, 'resize');
expect(sv.isShrunkForKeyboard).toBeUndefined();
ionic.trigger('scrollChildIntoView', details, true);
expect(sv.resize).toHaveBeenCalled();
expect(sv.isShrunkForKeyboard).toBe(true);
expect(sc.style.height).toEqual("248px");
expect(sc.style.overflow).toEqual("visible");
ionic.trigger('scrollChildIntoView', details, true);
//already shrunk, so shouldn't resize again
expect(sv.resize.calls.length).toBe(1);
ionic.requestAnimationFrame = _RAF;
sc.getBoundingClientRect = _scrollGetBoundingClientRect;
});
});