remove first page and last page of pagination
This commit is contained in:
parent
262dca0f8e
commit
bec071fdb9
@ -8,10 +8,8 @@ interface Props {
|
||||
}
|
||||
|
||||
export const labels = {
|
||||
first: '«',
|
||||
prev: '‹',
|
||||
next: '›',
|
||||
last: '»',
|
||||
}
|
||||
|
||||
const Pagination: React.FC<Props> = props => {
|
||||
@ -23,9 +21,6 @@ const Pagination: React.FC<Props> = props => {
|
||||
|
||||
return (
|
||||
<ul className="pagination">
|
||||
<PaginationItem disabled={page === 1} onClick={() => onChange(1)}>
|
||||
{labels.first}
|
||||
</PaginationItem>
|
||||
<PaginationItem disabled={page === 1} onClick={() => onChange(page - 1)}>
|
||||
{labels.prev}
|
||||
</PaginationItem>
|
||||
@ -86,12 +81,6 @@ const Pagination: React.FC<Props> = props => {
|
||||
>
|
||||
{labels.next}
|
||||
</PaginationItem>
|
||||
<PaginationItem
|
||||
disabled={page === totalPages}
|
||||
onClick={() => onChange(totalPages)}
|
||||
>
|
||||
{labels.last}
|
||||
</PaginationItem>
|
||||
</ul>
|
||||
)
|
||||
}
|
||||
|
@ -6,50 +6,8 @@ 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()
|
||||
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', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user