feat: add custom command to validate table columns in e2e tests

This commit is contained in:
2025-11-17 17:07:58 +01:00
parent 5b9d7bedf5
commit 32ef3753b2
3 changed files with 42 additions and 63 deletions

View File

@@ -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
View 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>
}
}