-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
6,672 additions
and
10,416 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,4 @@ yarn-error.log* | |
#all src files except lib | ||
src/* | ||
!src/lib | ||
!src/__tests__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
language: node_js | ||
node_js: | ||
- "10" | ||
cache: | ||
directories: | ||
- node_modules | ||
script: | ||
- npm test | ||
- npm run build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* eslint-env jest */ | ||
|
||
import React from 'react'; | ||
import '@testing-library/jest-dom/extend-expect' | ||
import { render, fireEvent } from '@testing-library/react'; | ||
import Paginator from '../lib'; | ||
|
||
const pageLimit = 1; | ||
let currentPage = 1; | ||
const setCurrentPage = (page) => currentPage = page; | ||
let offset = 0 | ||
const setOffset = (point) => offset = point; | ||
|
||
test('renders correctly', () => { | ||
const { baseElement } = render(<Paginator | ||
totalRecords={5} | ||
pageLimit={pageLimit} | ||
pageNeighbours={2} | ||
setOffset={setOffset} | ||
currentPage={currentPage} | ||
setCurrentPage={setCurrentPage} | ||
/>); | ||
expect(baseElement).toMatchSnapshot(); | ||
}) | ||
|
||
test("correct number of pages show up when pages do not exceed the number of available blocks", () => { | ||
const { getAllByText } = render(<Paginator | ||
totalRecords={5} | ||
pageLimit={pageLimit} | ||
pageNeighbours={2} | ||
setOffset={setOffset} | ||
currentPage={currentPage} | ||
setCurrentPage={setCurrentPage} | ||
/>); | ||
const pages = getAllByText(/^[1-5]$/); | ||
expect(pages.length).toBe(5) | ||
}) | ||
|
||
test("correct number of pages show up when pages exceed the number of available blocks", () => { | ||
const { getAllByText } = render(<Paginator | ||
totalRecords={5} | ||
pageLimit={pageLimit} | ||
pageNeighbours={2} | ||
setOffset={setOffset} | ||
currentPage={currentPage} | ||
setCurrentPage={setCurrentPage} | ||
/>); | ||
const pages = getAllByText(/^[1-5]$/); | ||
expect(pages.length).toBe(5) | ||
}) | ||
|
||
test("correct number of pages show up with next button when pages exceed the number of available blocks", () => { | ||
const { queryByText } = render(<Paginator | ||
totalRecords={20} | ||
pageLimit={pageLimit} | ||
pageNeighbours={2} | ||
setOffset={setOffset} | ||
currentPage={currentPage} | ||
setCurrentPage={setCurrentPage} | ||
/>); | ||
const nextOrPrev = queryByText(/Next\s»/); | ||
expect(nextOrPrev).not.toBeNull(); | ||
}) | ||
|
||
test("correct number of pages show up with prev button when pages exceed the number of available blocks", () => { | ||
const { queryByText } = render(<Paginator | ||
totalRecords={20} | ||
pageLimit={pageLimit} | ||
pageNeighbours={2} | ||
setOffset={setOffset} | ||
currentPage={20} | ||
setCurrentPage={setCurrentPage} | ||
/>); | ||
const nextOrPrev = queryByText(/«\sPrev/); | ||
expect(nextOrPrev).not.toBeNull(); | ||
}) | ||
|
||
test("next and prev buttons show up when pages exceed the number of available blocks", () => { | ||
const { queryAllByText } = render(<Paginator | ||
totalRecords={20} | ||
pageLimit={pageLimit} | ||
pageNeighbours={2} | ||
setOffset={setOffset} | ||
currentPage={10} | ||
setCurrentPage={setCurrentPage} | ||
/>); | ||
const nextOrPrev = queryAllByText(/Next\s»|«\sPrev/); | ||
expect(nextOrPrev.length).toBe(2); | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`renders correctly 1`] = ` | ||
<body> | ||
<div> | ||
<ul | ||
class="react-hooks-paginator" | ||
> | ||
<li | ||
class="page-item active" | ||
> | ||
<button | ||
class="page-link" | ||
> | ||
1 | ||
</button> | ||
</li> | ||
<li | ||
class="page-item null" | ||
> | ||
<button | ||
class="page-link" | ||
> | ||
2 | ||
</button> | ||
</li> | ||
<li | ||
class="page-item null" | ||
> | ||
<button | ||
class="page-link" | ||
> | ||
3 | ||
</button> | ||
</li> | ||
<li | ||
class="page-item null" | ||
> | ||
<button | ||
class="page-link" | ||
> | ||
4 | ||
</button> | ||
</li> | ||
<li | ||
class="page-item null" | ||
> | ||
<button | ||
class="page-link" | ||
> | ||
5 | ||
</button> | ||
</li> | ||
</ul> | ||
</div> | ||
</body> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters