diff --git a/package.json b/package.json index ecc49d2..f0c997f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mui-dt", - "version": "0.8.3", + "version": "0.9.0", "description": "Datatables for React using Material-UI", "main": "dist/index.js", "files": [ diff --git a/test/utils.test.js b/test/utils.test.js index 64bb5df..d2e2185 100644 --- a/test/utils.test.js +++ b/test/utils.test.js @@ -1,5 +1,5 @@ -import { assembleCSV } from "../src/utils"; -import { expect } from "chai"; +import { assembleCSV, getPageValue } from "../src/utils"; +import { expect, assert } from "chai"; describe("utils", () => { describe("assembleCSV", () => { @@ -63,4 +63,60 @@ import { expect } from "chai"; }); }); }); + + describe('getPageValue', () => { + it('returns the highest in bounds page value when page is out of bounds and count is greater than rowsPerPage', () => { + const count = 30; + const rowsPerPage = 10; + const page = 5; + + const actualResult = getPageValue(count, rowsPerPage, page); + assert.strictEqual(actualResult, 2); + }); + + it('returns the highest in bounds page value when page is in bounds and count is greater than rowsPerPage', () => { + const count = 30; + const rowsPerPage = 10; + const page = 1; + + const actualResult = getPageValue(count, rowsPerPage, page); + assert.strictEqual(actualResult, 1); + }); + + it('returns the highest in bounds page value when page is out of bounds and count is less than rowsPerPage', () => { + const count = 3; + const rowsPerPage = 10; + const page = 1; + + const actualResult = getPageValue(count, rowsPerPage, page); + assert.strictEqual(actualResult, 0); + }); + + it('returns the highest in bounds page value when page is in bounds and count is less than rowsPerPage', () => { + const count = 3; + const rowsPerPage = 10; + const page = 0; + + const actualResult = getPageValue(count, rowsPerPage, page); + assert.strictEqual(actualResult, 0); + }); + + it('returns the highest in bounds page value when page is out of bounds and count is equal to rowsPerPage', () => { + const count = 10; + const rowsPerPage = 10; + const page = 1; + + const actualResult = getPageValue(count, rowsPerPage, page); + assert.strictEqual(actualResult, 0); + }); + + it('returns the highest in bounds page value when page is in bounds and count is equal to rowsPerPage', () => { + const count = 10; + const rowsPerPage = 10; + const page = 0; + + const actualResult = getPageValue(count, rowsPerPage, page); + assert.strictEqual(actualResult, 0); + }); + }); }); \ No newline at end of file