-
Notifications
You must be signed in to change notification settings - Fork 4
fix: pagination visibility based on totalCount #929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
src/components/Common/PaginationControl/PaginationControl.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import { render, screen } from '@testing-library/react' | ||
| import { describe, test, expect, vi } from 'vitest' | ||
| import { PaginationControl } from './PaginationControl' | ||
| import type { PaginationControlProps } from './PaginationControlTypes' | ||
| import { ThemeProvider } from '@/contexts/ThemeProvider' | ||
| import { ComponentsProvider } from '@/contexts/ComponentAdapter/ComponentsProvider' | ||
| import { defaultComponents } from '@/contexts/ComponentAdapter/adapters/defaultComponentAdapter' | ||
|
|
||
| const basePaginationProps: PaginationControlProps = { | ||
| currentPage: 1, | ||
| totalPages: 3, | ||
| itemsPerPage: 5, | ||
| handleFirstPage: vi.fn(), | ||
| handlePreviousPage: vi.fn(), | ||
| handleNextPage: vi.fn(), | ||
| handleLastPage: vi.fn(), | ||
| handleItemsPerPageChange: vi.fn(), | ||
| } | ||
|
|
||
| const renderPaginationControl = (props: Partial<PaginationControlProps> = {}) => { | ||
| return render( | ||
| <ThemeProvider> | ||
| <ComponentsProvider value={defaultComponents}> | ||
| <PaginationControl {...basePaginationProps} {...props} /> | ||
| </ComponentsProvider> | ||
| </ThemeProvider>, | ||
| ) | ||
| } | ||
|
|
||
| describe('PaginationControl Visibility', () => { | ||
| describe('based on totalCount', () => { | ||
| test('hides when totalCount is 0 (empty state)', () => { | ||
| renderPaginationControl({ totalCount: 0 }) | ||
| expect(screen.queryByTestId('pagination-control')).not.toBeInTheDocument() | ||
| }) | ||
|
|
||
| test('hides when totalCount <= MINIMUM_PAGE_SIZE (5)', () => { | ||
| renderPaginationControl({ totalCount: 5 }) | ||
| expect(screen.queryByTestId('pagination-control')).not.toBeInTheDocument() | ||
| }) | ||
|
|
||
| test('hides when totalCount is 3 (less than min page size)', () => { | ||
| renderPaginationControl({ totalCount: 3 }) | ||
| expect(screen.queryByTestId('pagination-control')).not.toBeInTheDocument() | ||
| }) | ||
|
|
||
| test('shows when totalCount > MINIMUM_PAGE_SIZE', () => { | ||
| renderPaginationControl({ totalCount: 6 }) | ||
| expect(screen.getByTestId('pagination-control')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| test('shows when totalCount is undefined (server info unavailable)', () => { | ||
| renderPaginationControl({ totalCount: undefined }) | ||
| expect(screen.getByTestId('pagination-control')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| test('shows when totalCount is large', () => { | ||
| renderPaginationControl({ totalCount: 100 }) | ||
| expect(screen.getByTestId('pagination-control')).toBeInTheDocument() | ||
| }) | ||
| }) | ||
|
|
||
| describe('edge cases', () => { | ||
| test('shows pagination when totalCount > 5 even with totalPages = 1', () => { | ||
| renderPaginationControl({ totalCount: 10, totalPages: 1, itemsPerPage: 50 }) | ||
| expect(screen.getByTestId('pagination-control')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| test('hides when totalCount is exactly 5', () => { | ||
| renderPaginationControl({ totalCount: 5, totalPages: 1 }) | ||
| expect(screen.queryByTestId('pagination-control')).not.toBeInTheDocument() | ||
| }) | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recommend to update this to
renderWithProvidersinstead, that'll give you the needed providers out of the box