diff --git a/packages/grafana-ui/src/components/Pagination/Pagination.test.tsx b/packages/grafana-ui/src/components/Pagination/Pagination.test.tsx index a0bfec245cf..721782e18c3 100644 --- a/packages/grafana-ui/src/components/Pagination/Pagination.test.tsx +++ b/packages/grafana-ui/src/components/Pagination/Pagination.test.tsx @@ -16,4 +16,16 @@ describe('Pagination component', () => { expect(screen.getAllByRole('button')).toHaveLength(9); expect(screen.getAllByTestId('pagination-ellipsis-icon')).toHaveLength(2); }); + it('should only render the page number if number of pages is 0', () => { + render( {}} />); + expect(screen.getAllByRole('button')).toHaveLength(2); + expect(screen.getAllByRole('button')[1]).toBeEnabled(); + expect(screen.getByText('8')).toBeVisible(); + }); + it('should disable the next page button if hasNextPage is false', () => { + render( {}} hasNextPage={false} />); + expect(screen.getAllByRole('button')).toHaveLength(2); + expect(screen.getAllByRole('button')[0]).toBeEnabled(); + expect(screen.getAllByRole('button')[1]).toBeDisabled(); + }); }); diff --git a/packages/grafana-ui/src/components/Pagination/Pagination.tsx b/packages/grafana-ui/src/components/Pagination/Pagination.tsx index 4ac6c009f83..d5aa5018159 100644 --- a/packages/grafana-ui/src/components/Pagination/Pagination.tsx +++ b/packages/grafana-ui/src/components/Pagination/Pagination.tsx @@ -132,7 +132,7 @@ export const Pagination = ({ size="sm" variant="secondary" onClick={() => onNavigate(currentPage + 1)} - disabled={!hasNextPage || currentPage === numberOfPages} + disabled={hasNextPage === false || currentPage === numberOfPages} >