-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2745 from ppadti/test-pagination
Cypress test for pagination
- Loading branch information
Showing
7 changed files
with
186 additions
and
40 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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
47 changes: 47 additions & 0 deletions
47
frontend/src/__tests__/cypress/cypress/utils/pagination.ts
This file contains 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,47 @@ | ||
import { tablePagination } from '~/__tests__/cypress/cypress/pages/components/Pagination'; | ||
|
||
type PaginationProp = { | ||
totalItems: number; | ||
firstElement: string; | ||
paginationVariant: 'top' | 'bottom'; | ||
}; | ||
|
||
export const testPagination = ({ | ||
totalItems, | ||
firstElement, | ||
paginationVariant, | ||
}: PaginationProp): void => { | ||
const pagination = paginationVariant === 'top' ? tablePagination.top : tablePagination.bottom; | ||
|
||
// check for 10 per page | ||
pagination.findFirstButton().should('be.disabled'); | ||
pagination.findLastButton().click(); | ||
pagination.findInput().should('have.value', Math.ceil(totalItems / 10)); | ||
pagination.findLastButton().should('be.disabled'); | ||
pagination.findFirstButton().click(); | ||
pagination.findInput().should('have.value', '1'); | ||
pagination.findFirstButton().should('be.disabled'); | ||
|
||
pagination.findNextButton().click(); | ||
pagination.findInput().should('have.value', '2'); | ||
pagination.findNextButton().click(); | ||
pagination.findInput().should('have.value', '3'); | ||
|
||
pagination.findPreviousButton().click(); | ||
pagination.findInput().should('have.value', '2'); | ||
pagination.findPreviousButton().click(); | ||
pagination.findInput().should('have.value', '1'); | ||
|
||
// 20 per page | ||
pagination.selectToggleOption('20 per page'); | ||
pagination.findFirstButton().should('be.disabled'); | ||
cy.findByText(firstElement).should('exist'); | ||
pagination.findLastButton().click(); | ||
cy.findByText(firstElement).should('not.exist'); | ||
pagination.findInput().should('have.value', Math.ceil(totalItems / 20)); | ||
pagination.findLastButton().should('be.disabled'); | ||
pagination.findFirstButton().click(); | ||
pagination.findInput().should('have.value', '1'); | ||
pagination.findFirstButton().should('be.disabled'); | ||
pagination.selectToggleOption('10 per page'); | ||
}; |