This commit is contained in:
Allen 2018-08-11 13:32:44 +08:00 committed by GitHub
parent 3ec849bd94
commit 528be5c058
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 3 deletions

View File

@ -40,8 +40,8 @@ export default ExtendBase =>
let from = ((currPage - pageStartIndex) * currSizePerPage);
from = dataSize === 0 ? 0 : from + 1;
let to = Math.min((currSizePerPage * (currPage + offset) - 1), dataSize);
if (to >= dataSize) to -= 1;
let to = Math.min(currSizePerPage * (currPage + offset), dataSize);
if (to > dataSize) to = dataSize;
return [from, to];
}

View File

@ -119,7 +119,34 @@ describe('PageResolver', () => {
it('should return correct array with from and to value', () => {
const instance = wrapper.instance();
expect(instance.calculateFromTo()).toEqual([1, props.currSizePerPage - 1]);
expect(instance.calculateFromTo()).toEqual([1, props.currSizePerPage]);
});
describe('if data is empty', () => {
beforeEach(() => {
props.dataSize = 87;
props.currPage = 9;
const mockElement = React.createElement(MockComponent, props, null);
wrapper = shallow(mockElement);
});
it('should return correct array with from and to value', () => {
const instance = wrapper.instance();
expect(instance.calculateFromTo()).toEqual([81, props.dataSize]);
});
});
describe('if current page is last page', () => {
beforeEach(() => {
props.dataSize = 0;
const mockElement = React.createElement(MockComponent, props, null);
wrapper = shallow(mockElement);
});
it('should return correct array with from and to value', () => {
const instance = wrapper.instance();
expect(instance.calculateFromTo()).toEqual([0, 0]);
});
});
});