You've already forked isop-mirror
feat: add custom command to validate table columns in e2e tests
This commit is contained in:
@@ -24,14 +24,16 @@
|
||||
//
|
||||
// -- This will overwrite an existing command --
|
||||
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
|
||||
//
|
||||
// declare global {
|
||||
// namespace Cypress {
|
||||
// interface Chainable {
|
||||
// login(email: string, password: string): Chainable<void>
|
||||
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
|
||||
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
|
||||
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// Custom command to validate table columns
|
||||
Cypress.Commands.add('validateColumn', (columnName: string, validator: (value: string) => void) => {
|
||||
cy.contains('th', columnName).parent('tr').then(($headerRow) => {
|
||||
const colIndex = $headerRow.find('th').index(cy.$$(`th:contains("${columnName}")`)[0])
|
||||
|
||||
cy.get('tbody tr').each(($row) => {
|
||||
cy.wrap($row).find('td').eq(colIndex).invoke('text').then((cellText) => {
|
||||
validator(cellText as string)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
13
frontend/cypress/support/index.d.ts
vendored
Normal file
13
frontend/cypress/support/index.d.ts
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
/// <reference types="cypress" />
|
||||
|
||||
declare namespace Cypress {
|
||||
interface Chainable {
|
||||
/**
|
||||
* Custom command to validate all cells in a table column
|
||||
* @param columnName - The name of the column header to validate
|
||||
* @param validator - A function that receives the cell text and performs assertions
|
||||
* @example cy.validateColumn('Email', (email) => { expect(email).to.include('@') })
|
||||
*/
|
||||
validateColumn(columnName: string, validator: (value: string) => void): Chainable<void>
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user