hide pagination when total pages is invalid

This commit is contained in:
Pig Fang 2020-02-10 17:52:36 +08:00
parent 89055fe192
commit 9dca4c1585
2 changed files with 14 additions and 0 deletions

View File

@ -17,6 +17,10 @@ export const labels = {
const Pagination: React.FC<Props> = props => {
const { page, totalPages, onChange } = props
if (totalPages < 1) {
return null
}
return (
<ul className="pagination">
<PaginationItem disabled={page === 1} onClick={() => onChange(1)}>

View File

@ -2,6 +2,16 @@ import React from 'react'
import { render, fireEvent } from '@testing-library/react'
import Pagination, { labels } from '@/components/Pagination'
test('hide when total pages is invalid', () => {
const { queryByText } = render(
<Pagination page={1} totalPages={0} onChange={() => {}} />,
)
expect(queryByText(labels.first)).not.toBeInTheDocument()
expect(queryByText(labels.prev)).not.toBeInTheDocument()
expect(queryByText(labels.next)).not.toBeInTheDocument()
expect(queryByText(labels.last)).not.toBeInTheDocument()
})
describe('first page', () => {
it('enabled', () => {
const mock = jest.fn()