mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2025-10-16 11:55:39 +00:00
* updated test for pagination fix * suspected bug in page.js Local pagination aligning returns start page when eg editing cell locally. This results in state change, too. Not really getting the purpose of the original idea. Please consider this modification. It only checks if page fits in the data size range. As I saw, this alignment only affects local pagination, not remote. * modified fix w/ pageStartIndex I forgot to mind pageStartIndex
76 lines
2.0 KiB
JavaScript
76 lines
2.0 KiB
JavaScript
|
|
import { getByCurrPage, alignPage } from '../src/page';
|
|
|
|
describe('Page Functions', () => {
|
|
let data;
|
|
const params = [
|
|
// [page, sizePerPage, pageStartIndex]
|
|
[1, 10, 1],
|
|
[1, 25, 1],
|
|
[1, 30, 1],
|
|
[3, 30, 1],
|
|
[4, 30, 1],
|
|
[10, 10, 1],
|
|
[0, 10, 0],
|
|
[1, 10, 0],
|
|
[9, 10, 0]
|
|
];
|
|
|
|
describe('getByCurrPage', () => {
|
|
beforeEach(() => {
|
|
data = [];
|
|
for (let i = 0; i < 100; i += 1) {
|
|
data.push({ id: i, name: `test_name${i}` });
|
|
}
|
|
});
|
|
|
|
it('should always return correct data', () => {
|
|
params.forEach(([page, sizePerPage, pageStartIndex]) => {
|
|
const rows = getByCurrPage(data, page, sizePerPage, pageStartIndex);
|
|
expect(rows).toBeDefined();
|
|
expect(Array.isArray(rows)).toBeTruthy();
|
|
expect(rows.every(row => !!row)).toBeTruthy();
|
|
});
|
|
});
|
|
|
|
it('should return empty array when data is empty', () => {
|
|
data = [];
|
|
params.forEach(([page, sizePerPage, pageStartIndex]) => {
|
|
const rows = getByCurrPage(data, page, sizePerPage, pageStartIndex);
|
|
expect(rows).toHaveLength(0);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('alignPage', () => {
|
|
const pageStartIndex = 1;
|
|
const sizePerPage = 10;
|
|
const page = 3;
|
|
describe('if the page does not fit the pages interval calculated from the length of store.data', () => {
|
|
beforeEach(() => {
|
|
data = [];
|
|
for (let i = 0; i < 15; i += 1) {
|
|
data.push({ id: i, name: `test_name${i}` });
|
|
}
|
|
});
|
|
|
|
it('should return pageStartIndex argument', () => {
|
|
expect(alignPage(data, page, sizePerPage, pageStartIndex)).toEqual(pageStartIndex);
|
|
});
|
|
});
|
|
|
|
describe('if the length of store.data is large than the end page index', () => {
|
|
beforeEach(() => {
|
|
data = [];
|
|
for (let i = 0; i < 30; i += 1) {
|
|
data.push({ id: i, name: `test_name${i}` });
|
|
}
|
|
});
|
|
|
|
it('should return current page', () => {
|
|
expect(alignPage(data, page, sizePerPage, pageStartIndex)).toEqual(page);
|
|
});
|
|
});
|
|
});
|
|
});
|