Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ince-dbt committed Feb 6, 2025
1 parent 940d3bb commit 2900e0e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
assertPayload,
assertFieldTypeahead,
assertFieldError,
debugAndAssertFieldError,
assertLocalHeader,
assertBreadcrumbs,
assertFieldEmpty,
Expand Down Expand Up @@ -184,15 +185,15 @@ describe('Export pipeline create', () => {
ERROR_MESSAGES.destination_country,
false
)
assertFieldError(
debugAndAssertFieldError(
cy.get('[data-test="field-status"]'),
ERROR_MESSAGES.status
)
assertFieldError(
cy.get('[data-test="field-sector"]'),
ERROR_MESSAGES.sector
)
assertFieldError(
debugAndAssertFieldError(
cy.get('[data-test="field-status"]'),
ERROR_MESSAGES.status
)
Expand Down
22 changes: 22 additions & 0 deletions test/functional/cypress/support/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,27 @@ const assertFieldError = (element, errorMessage, hasHint = true) =>
.eq(hasHint ? 1 : 0)
.should('have.text', errorMessage)

/**
* Debug-friendly version of `assertFieldError`.
*/
const debugAndAssertFieldError = (element, errorMessage, hasHint = true) =>
element
.find('span')
.then(($spans) => {
cy.log(`Number of spans: ${$spans.length}`)
$spans.each((i, s) => cy.log(`Span #${i} text: "${Cypress.$(s).text()}"`))
const found = $spans.filter((_, s) =>
Cypress.$(s).text().includes(errorMessage)
)
expect(
found.length,
`No span found containing "${errorMessage}"`
).to.be.gt(0)
return found.first()
})
.then(($span) => cy.log(`Targeted span text: "${$span.text()}"`))
.should('contain.text', errorMessage)

const assertFieldErrorStrict = ({ inputName, errorMessage }) =>
cy
.get(`[data-test="field-${inputName}"]`)
Expand Down Expand Up @@ -1160,6 +1181,7 @@ module.exports = {
assertAPIRequest,
assertExactUrl,
assertFieldError,
debugAndAssertFieldError,
assertFieldErrorStrict,
assertTypeaheadValues,
assertLink,
Expand Down

0 comments on commit 2900e0e

Please sign in to comment.