-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
143 lines (127 loc) · 4.08 KB
/
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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
'use strict'
const test = require('tape')
const Infinitely = require('.')
test('Infinitely', t => {
t.test('no rows', t => {
const rows = []
const inner = document.createElement('div')
const outer = document.createElement('div')
const render = () => {}
const view = new Infinitely({ rows, inner, outer, render })
t.ok(view)
t.end()
})
t.test('.rowHeight', t => {
const rows = [{ height: 13 }]
const inner = document.createElement('div')
const outer = document.createElement('div')
let render = row => {
const el = document.createElement('div')
el.style.height = `${row.height}px`
return el
}
document.body.appendChild(inner)
const view = new Infinitely({ rows, inner, outer, render })
t.equal(view.rowHeight, 13)
t.end()
})
t.test('.numPages', t => {
let rows = Array(123)
const inner = document.createElement('div')
const outer = document.createElement('div')
const render = () => {
const el = document.createElement('div')
el.style.height = '13px'
return el
}
const page = 100
document.body.appendChild(inner)
const view = new Infinitely({ rows, inner, outer, render, page })
t.equal(view.numPages, Math.ceil(rows.length / page))
rows = Array(23)
view.setRows(rows)
t.equal(view.numPages, Math.ceil(rows.length / page))
t.end()
})
t.test('inner height', t => {
let rows = Array(123)
const inner = document.createElement('div')
const outer = document.createElement('div')
const render = () => {
const el = document.createElement('div')
el.style.height = '13px'
return el
}
document.body.appendChild(inner)
const view = new Infinitely({ rows, inner, outer, render })
t.equal(inner.style.height, `${13 * rows.length}px`)
rows = Array(23)
view.setRows(rows)
t.equal(inner.style.height, `${13 * rows.length}px`)
t.end()
})
t.test('.pageHeight', t => {
const rows = [{ height: 13 }]
const inner = document.createElement('div')
const outer = document.createElement('div')
const render = row => {
const el = document.createElement('div')
el.style.height = `${row.height}px`
return el
}
document.body.appendChild(inner)
const page = 100
const view = new Infinitely({ rows, inner, outer, render, page })
t.equal(view.pageHeight, page * rows[0].height)
rows[0].height = 14
view.setRows(rows)
t.equal(view.pageHeight, page * rows[0].height)
t.end()
})
t.test('.padding', t => {
const rows = [{ height: 13 }]
const inner = document.createElement('div')
const outer = document.createElement('div')
const render = row => {
const el = document.createElement('div')
el.style.height = `${row.height}px`
return el
}
document.body.appendChild(inner)
const padding = 50
const view = new Infinitely({ rows, inner, outer, render, padding })
t.equal(view.padding, padding * rows[0].height)
rows[0].height = 14
view.setRows(rows)
t.equal(view.padding, padding * rows[0].height)
t.end()
})
t.test('.createNewPage(i)', t => {
const rows = []
const inner = document.createElement('div')
const outer = document.createElement('div')
const render = row => document.createElement('div')
const view = new Infinitely({ rows, inner, outer, render })
const page = view.createNewPage(0)
t.equal(page.tagName, 'DIV')
t.equal(page.style.position, 'absolute')
t.equal(page.style.width, '100%')
t.ok(inner.contains(page))
view.debug = true
const debugPage = view.createNewPage(0)
t.ok(debugPage.style.backgroundColor)
t.end()
})
t.test('.getAvailablePage(i)', t => {
const rows = []
const inner = document.createElement('div')
const outer = document.createElement('div')
const render = row => document.createElement('div')
const view = new Infinitely({ rows, inner, outer, render })
view.pagesAvailable.push(view.createNewPage(0))
const page = view.getAvailablePage(1)
t.ok(inner.contains(page))
t.end()
})
t.end()
})