remove first page and last page of pagination

This commit is contained in:
Pig Fang 2020-04-26 17:52:18 +08:00
parent 262dca0f8e
commit bec071fdb9
2 changed files with 0 additions and 53 deletions

View File

@ -8,10 +8,8 @@ interface Props {
} }
export const labels = { export const labels = {
first: '«',
prev: '', prev: '',
next: '', next: '',
last: '»',
} }
const Pagination: React.FC<Props> = props => { const Pagination: React.FC<Props> = props => {
@ -23,9 +21,6 @@ const Pagination: React.FC<Props> = props => {
return ( return (
<ul className="pagination"> <ul className="pagination">
<PaginationItem disabled={page === 1} onClick={() => onChange(1)}>
{labels.first}
</PaginationItem>
<PaginationItem disabled={page === 1} onClick={() => onChange(page - 1)}> <PaginationItem disabled={page === 1} onClick={() => onChange(page - 1)}>
{labels.prev} {labels.prev}
</PaginationItem> </PaginationItem>
@ -86,12 +81,6 @@ const Pagination: React.FC<Props> = props => {
> >
{labels.next} {labels.next}
</PaginationItem> </PaginationItem>
<PaginationItem
disabled={page === totalPages}
onClick={() => onChange(totalPages)}
>
{labels.last}
</PaginationItem>
</ul> </ul>
) )
} }

View File

@ -6,50 +6,8 @@ test('hide when total pages is invalid', () => {
const { queryByText } = render( const { queryByText } = render(
<Pagination page={1} totalPages={0} onChange={() => {}} />, <Pagination page={1} totalPages={0} onChange={() => {}} />,
) )
expect(queryByText(labels.first)).not.toBeInTheDocument()
expect(queryByText(labels.prev)).not.toBeInTheDocument() expect(queryByText(labels.prev)).not.toBeInTheDocument()
expect(queryByText(labels.next)).not.toBeInTheDocument() expect(queryByText(labels.next)).not.toBeInTheDocument()
expect(queryByText(labels.last)).not.toBeInTheDocument()
})
describe('first page', () => {
it('enabled', () => {
const mock = jest.fn()
const { getByText } = render(
<Pagination page={2} totalPages={3} onChange={mock} />,
)
fireEvent.click(getByText(labels.first))
expect(mock).toBeCalledWith(1)
})
it('disabled', () => {
const mock = jest.fn()
const { getByText } = render(
<Pagination page={1} totalPages={3} onChange={mock} />,
)
fireEvent.click(getByText(labels.first))
expect(mock).not.toBeCalled()
})
})
describe('last page', () => {
it('enabled', () => {
const mock = jest.fn()
const { getByText } = render(
<Pagination page={2} totalPages={3} onChange={mock} />,
)
fireEvent.click(getByText(labels.last))
expect(mock).toBeCalledWith(3)
})
it('disabled', () => {
const mock = jest.fn()
const { getByText } = render(
<Pagination page={3} totalPages={3} onChange={mock} />,
)
fireEvent.click(getByText(labels.last))
expect(mock).not.toBeCalled()
})
}) })
describe('previous page', () => { describe('previous page', () => {