forked from jsoendermann/rn-section-list-get-item-layout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.spec.js
55 lines (46 loc) · 1.59 KB
/
index.spec.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
const sectionListGetItemLayout = require('./dist').default
test('Empty sections', () => {
const getItemLayout = sectionListGetItemLayout({
getItemHeight: () => 2,
getSeparatorHeight: () => 23,
getSectionHeaderHeight: () => 41,
getSectionFooterHeight: () => 61,
})
const data = [{ data: [] }, { data: [] }, { data: [null] }]
expect(getItemLayout(data, 0)).toEqual({ length: 41, offset: 0, index: 0 })
expect(getItemLayout(data, 1)).toEqual({ length: 61, offset: 41, index: 1 })
expect(getItemLayout(data, 5)).toEqual({
length: 2,
offset: 41 * 3 + 61 * 2,
index: 5,
})
expect(getItemLayout(data, 6)).toEqual({
length: 61,
offset: 41 * 3 + 61 * 2 + 2,
index: 6,
})
})
test('Multiple rows in one section', () => {
const getItemLayout = sectionListGetItemLayout({
getItemHeight: () => 2,
getSeparatorHeight: () => 23,
getSectionHeaderHeight: () => 41,
getSectionFooterHeight: () => 61,
})
const data = [{ data: [null, null, null] }]
expect(getItemLayout(data, 2)).toEqual({
length: 2,
offset: 41 + 2 + 23,
index: 2,
})
})
test('Calling sectionListGetItemLayout with only getItemHeight', () => {
const getItemLayout = sectionListGetItemLayout({
getItemHeight: () => 1,
})
const data = [{ data: [null, null] }]
expect(getItemLayout(data, 0)).toEqual({ length: 0, offset: 0, index: 0 })
expect(getItemLayout(data, 1)).toEqual({ length: 1, offset: 0, index: 1 })
expect(getItemLayout(data, 2)).toEqual({ length: 1, offset: 1, index: 2 })
expect(getItemLayout(data, 3)).toEqual({ length: 0, offset: 2, index: 3 })
})