forked from bvaughn/react-virtualized
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculateSizeAndPositionDataAndUpdateScrollOffset.jest.js
More file actions
75 lines (66 loc) · 2.49 KB
/
calculateSizeAndPositionDataAndUpdateScrollOffset.jest.js
File metadata and controls
75 lines (66 loc) · 2.49 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
import calculateSizeAndPositionDataAndUpdateScrollOffset from './calculateSizeAndPositionDataAndUpdateScrollOffset'
describe('calculateSizeAndPositionDataAndUpdateScrollOffset', () => {
function helper ({
cellCount = 100,
cellSize = 10,
computeMetadataCallbackProps = {},
nextCellsCount = 100,
nextCellSize = 10,
nextScrollToIndex,
scrollToIndex
} = {}) {
const computeMetadataCallbackCalls = []
const updateScrollOffsetForScrollToIndexCalls = []
calculateSizeAndPositionDataAndUpdateScrollOffset({
cellCount,
cellSize,
computeMetadataCallback: params => computeMetadataCallbackCalls.push(params),
computeMetadataCallbackProps,
nextCellsCount,
nextCellSize,
nextScrollToIndex,
scrollToIndex,
updateScrollOffsetForScrollToIndex: params => updateScrollOffsetForScrollToIndexCalls.push(params)
})
return {
computeMetadataCallbackCalls,
updateScrollOffsetForScrollToIndexCalls
}
}
it('should call :computeMetadataCallback if :cellCount has changed', () => {
const { computeMetadataCallbackCalls } = helper({
cellCount: 100,
nextCellsCount: 200
})
expect(computeMetadataCallbackCalls.length).toEqual(1)
})
it('should call :computeMetadataCallback if numeric :cellSize has changed', () => {
const { computeMetadataCallbackCalls } = helper({
cellSize: 10,
nextCellSize: 20
})
expect(computeMetadataCallbackCalls.length).toEqual(1)
})
it('should not call :computeMetadataCallback if :cellSize callback has changed', () => {
const { computeMetadataCallbackCalls } = helper({
cellSize: () => {},
nextCellSize: () => {}
})
expect(computeMetadataCallbackCalls.length).toEqual(0)
})
it('should not call :updateScrollOffsetForScrollToIndex if :scrollToIndex is not specified', () => {
const { updateScrollOffsetForScrollToIndexCalls } = helper()
expect(updateScrollOffsetForScrollToIndexCalls.length).toEqual(0)
})
it('should not call :updateScrollOffsetForScrollToIndex if :scrollToIndex has also changed', () => {
const { updateScrollOffsetForScrollToIndexCalls } = helper({
scrollToIndex: 10,
nextScrollToIndex: 20
})
expect(updateScrollOffsetForScrollToIndexCalls.length).toEqual(0)
})
it('should not call :computeMetadataCallback if the above conditions are not true', () => {
const { computeMetadataCallbackCalls } = helper()
expect(computeMetadataCallbackCalls.length).toEqual(0)
})
})