pull.js
2.78 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
import BScroll from 'scroll/index'
import { dispatchTouchStart, dispatchTouchMove, dispatchTouchEnd } from '../../utils/event'
describe('BScroll - pull', () => {
let scroll
let scroller
let scrollOptions = {
bindToWrapper: true,
probeType: 3,
pullDownRefresh: {
threshold: 90,
stop: 30
},
pullUpLoad: {
threshold: 0,
txt: 'There is no more data'
}
}
beforeEach(() => {
const wrapper = document.createElement('div')
const list = document.createElement('ul')
scroller = document.createElement('div')
scroller.appendChild(list)
wrapper.appendChild(scroller)
document.body.appendChild(wrapper)
wrapper.style.height = '500px'
wrapper.style.overflow = 'hidden'
// wrapper.style.position = 'relative'
let listHTML = ''
list.style.margin = '0'
for (let i = 0; i < 100; i++) {
listHTML += `<li>${i}</li>`
}
list.innerHTML = listHTML
scroll = new BScroll(wrapper, scrollOptions)
})
it('pulldown event', () => {
const pullingDownHandler = sinon.spy()
scroll.on('pullingDown', pullingDownHandler)
const wrapper = scroll.wrapper
dispatchTouchStart(wrapper, {
pageX: 50,
pageY: 50
})
dispatchTouchMove(wrapper, {
pageX: 50,
pageY: 400
})
dispatchTouchEnd(wrapper, {
pageX: 50,
pageY: 400
})
expect(pullingDownHandler)
.to.be.calledOnce
})
it('pulling down and reset', (done) => {
scroll.on('pullingDown', () => {
setTimeout(() => {
scroll.finishPullDown()
console.log('222', scroll.relativeY)
expect(scroll.y)
.to.equal(0)
done()
}, 500)
})
const wrapper = scroll.wrapper
dispatchTouchStart(wrapper, {
pageX: 50,
pageY: 50
})
dispatchTouchMove(wrapper, {
pageX: 50,
pageY: 400
})
dispatchTouchEnd(wrapper, {
pageX: 50,
pageY: 400
})
})
it('pullup event', () => {
const pullingUpHandler = sinon.spy()
scroll.on('pullingUp', () => {
pullingUpHandler()
setTimeout(() => {
scroll.finishPullUp()
}, 500)
})
const wrapper = scroll.wrapper
dispatchTouchStart(wrapper, {
pageX: 50,
pageY: 100
})
dispatchTouchMove(wrapper, {
pageX: 50,
pageY: -2300
})
dispatchTouchEnd(wrapper, {
pageX: 50,
pageY: -2300
})
dispatchTouchStart(wrapper, {
pageX: 50,
pageY: -2300
})
dispatchTouchMove(wrapper, {
pageX: 50,
pageY: -2500
})
dispatchTouchStart(wrapper, {
pageX: 50,
pageY: -2800
})
expect(pullingUpHandler)
.to.be.calledOnce
})
afterEach(() => {
if (scroll) {
document.body.removeChild(scroll.wrapper)
scroll.destroy()
}
})
})