forked from bvaughn/react-virtualized
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSectionManager.jest.js
78 lines (73 loc) · 2.33 KB
/
SectionManager.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
import SectionManager from './SectionManager';
import {CELLS, SECTION_SIZE} from './TestData';
function initSectionManager() {
const sectionManager = new SectionManager(SECTION_SIZE);
CELLS.forEach((cellMetadatum, index) => {
sectionManager.registerCell({
cellMetadatum,
index,
});
});
return sectionManager;
}
function verifySections(
sectionManager,
sizeAndPosition,
expectedSizeAndPositionInfos,
) {
const sections = sectionManager.getSections(sizeAndPosition);
expect(sections.length).toEqual(expectedSizeAndPositionInfos.length);
expectedSizeAndPositionInfos.forEach(sizeAndPosition => {
const match = sections.find(
section =>
section.x === sizeAndPosition.x && section.y === sizeAndPosition.y,
);
expect(!!match).toEqual(true);
});
}
describe('SectionManager', () => {
it('creates the appropriate number of Sections', () => {
const sectionManager = initSectionManager();
expect(sectionManager.getTotalSectionCount()).toEqual(6);
});
it('returns the proper Sections based on the specified area', () => {
const sectionManager = initSectionManager();
verifySections(sectionManager, {x: 0, y: 0, width: 1, height: 1}, [
{x: 0, y: 0},
]);
verifySections(sectionManager, {x: 1, y: 1, width: 1, height: 1}, [
{x: 0, y: 0},
]);
verifySections(sectionManager, {x: 0, y: 0, width: 4, height: 4}, [
{x: 0, y: 0},
{x: 2, y: 0},
{x: 0, y: 2},
{x: 2, y: 2},
]);
verifySections(sectionManager, {x: 4, y: 0, width: 2, height: 3}, [
{x: 4, y: 0},
{x: 4, y: 2},
]);
});
it('assigns cells to the appropriate sections', () => {
const sectionManager = initSectionManager();
expect(
sectionManager.getCellIndices({x: 0, y: 0, width: 2, height: 2}),
).toEqual([0]);
expect(
sectionManager.getCellIndices({x: 2, y: 0, width: 2, height: 2}),
).toEqual([1, 2, 3]);
expect(
sectionManager.getCellIndices({x: 4, y: 0, width: 2, height: 2}),
).toEqual([6]);
expect(
sectionManager.getCellIndices({x: 0, y: 2, width: 2, height: 2}),
).toEqual([4]);
expect(
sectionManager.getCellIndices({x: 2, y: 2, width: 2, height: 2}),
).toEqual([3, 4, 5]);
expect(
sectionManager.getCellIndices({x: 4, y: 2, width: 2, height: 2}),
).toEqual([7, 8, 9]);
});
});