-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathgetUpdatedOffsetForIndex.jest.js
85 lines (78 loc) · 1.97 KB
/
getUpdatedOffsetForIndex.jest.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
import getUpdatedOffsetForIndex from './getUpdatedOffsetForIndex';
import {getCellMetadata} from './TestHelper';
describe('getUpdatedOffsetForIndex', () => {
function testHelper(
targetIndex,
currentOffset,
cellMetadata = getCellMetadata(),
) {
return getUpdatedOffsetForIndex({
cellOffset: cellMetadata[targetIndex].offset,
cellSize: cellMetadata[targetIndex].size,
containerSize: 50,
currentOffset,
});
}
it('should scroll to the beginning', () => {
expect(testHelper(0, 100)).toEqual(0);
});
it('should scroll forward to the middle', () => {
expect(testHelper(4, 0)).toEqual(20);
});
it('should scroll backward to the middle', () => {
expect(testHelper(2, 100)).toEqual(30);
});
it('should not scroll if an item is already visible', () => {
expect(testHelper(2, 20)).toEqual(20);
});
it('should scroll to the end', () => {
expect(testHelper(8, 0)).toEqual(110);
});
it('should honor specified :align values', () => {
expect(
getUpdatedOffsetForIndex({
align: 'auto',
cellOffset: 50,
cellSize: 10,
containerSize: 50,
currentOffset: 0,
}),
).toEqual(10);
expect(
getUpdatedOffsetForIndex({
align: 'start',
cellOffset: 50,
cellSize: 10,
containerSize: 50,
currentOffset: 0,
}),
).toEqual(50);
expect(
getUpdatedOffsetForIndex({
align: 'auto',
cellOffset: 50,
cellSize: 10,
containerSize: 50,
currentOffset: 100,
}),
).toEqual(50);
expect(
getUpdatedOffsetForIndex({
align: 'end',
cellOffset: 50,
cellSize: 10,
containerSize: 50,
currentOffset: 100,
}),
).toEqual(10);
expect(
getUpdatedOffsetForIndex({
align: 'center',
cellOffset: 50,
cellSize: 10,
containerSize: 50,
currentOffset: 100,
}),
).toEqual(30);
});
});