Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Migrating Grid.js to getDerivedStateFromProps #1053

Merged
merged 18 commits into from
May 6, 2018
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 26 additions & 13 deletions source/Grid/Grid.jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1561,8 +1561,8 @@ describe('Grid', () => {
rowHeight: 20,
}),
);
expect(grid._getEstimatedColumnSize(grid.props)).toEqual(100);
expect(grid._getEstimatedRowSize(grid.props)).toEqual(20);
expect(Grid._getEstimatedColumnSize(grid.props)).toEqual(100);
expect(Grid._getEstimatedRowSize(grid.props)).toEqual(20);
});

it('should estimate row and column sizes if actual sizes are functions', () => {
Expand All @@ -1574,8 +1574,8 @@ describe('Grid', () => {
rowHeight: () => 20,
}),
);
expect(grid._getEstimatedColumnSize(grid.props)).toEqual(150);
expect(grid._getEstimatedRowSize(grid.props)).toEqual(15);
expect(Grid._getEstimatedColumnSize(grid.props)).toEqual(150);
expect(Grid._getEstimatedRowSize(grid.props)).toEqual(15);
});
});

Expand Down Expand Up @@ -1950,11 +1950,19 @@ describe('Grid', () => {
width: 0,
}),
);
expect(grid._columnSizeAndPositionManager.getTotalSize()).toEqual(1500);
expect(grid._rowSizeAndPositionManager.getTotalSize()).toEqual(150);
expect(
grid.state.instanceProps.columnSizeAndPositionManager.getTotalSize(),
).toEqual(1500);
expect(
grid.state.instanceProps.rowSizeAndPositionManager.getTotalSize(),
).toEqual(150);
grid.measureAllCells();
expect(grid._columnSizeAndPositionManager.getTotalSize()).toEqual(1000);
expect(grid._rowSizeAndPositionManager.getTotalSize()).toEqual(200);
expect(
grid.state.instanceProps.columnSizeAndPositionManager.getTotalSize(),
).toEqual(1000);
expect(
grid.state.instanceProps.rowSizeAndPositionManager.getTotalSize(),
).toEqual(200);
});
});

Expand Down Expand Up @@ -2059,7 +2067,9 @@ describe('Grid', () => {
rendered.querySelector('.ReactVirtualized__Grid__innerScrollContainer')
.style.height,
).toEqual('2000px'); // 100 rows * 20px rowHeight
expect(grid._rowSizeAndPositionManager.getTotalSize()).toEqual(2000);
expect(
grid.state.instanceProps.rowSizeAndPositionManager.getTotalSize(),
).toEqual(2000);
});
});

Expand Down Expand Up @@ -2091,7 +2101,9 @@ describe('Grid', () => {
rendered.querySelector('.ReactVirtualized__Grid__innerScrollContainer')
.style.width,
).toEqual('2500px'); // 50 columns * 50px columnWidth
expect(grid._columnSizeAndPositionManager.getTotalSize()).toEqual(2500);
expect(
grid.state.instanceProps.columnSizeAndPositionManager.getTotalSize(),
).toEqual(2500);
});
});

Expand Down Expand Up @@ -2301,10 +2313,11 @@ describe('Grid', () => {
});

// cellRendererCalls[0] is the element at rowIndex 0
const firstProps = cellRendererCalls[1];
const secondProps = cellRendererCalls[2];
// only two calls. Since the scrollTop is updated in getDerivedStateFromProps
const firstProps = cellRendererCalls[0];
const secondProps = cellRendererCalls[1];

expect(cellRendererCalls.length).toEqual(3);
expect(cellRendererCalls.length).toEqual(2);
expect(firstProps.style).not.toBe(secondProps.style);
});

Expand Down
Loading