From da6cc641a5f6e5e7639ed3314cb248e2c3f79277 Mon Sep 17 00:00:00 2001 From: Kristina Durivage Date: Mon, 29 Dec 2025 19:10:26 -0600 Subject: [PATCH] Add tests --- .../src/components/Pagination/Pagination.test.tsx | 12 ++++++++++++ .../src/components/Pagination/Pagination.tsx | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) 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} >