From a73f401a6c2adc431b851ca68eec5f0b4b0158b3 Mon Sep 17 00:00:00 2001 From: Tony Barnes Date: Fri, 11 Oct 2024 14:10:12 +0100 Subject: [PATCH] chore(EMS-3898): dry checkDateFieldValues command (#3170) --- ...y-contract-completion-date-field-values.js | 6 ++--- ...empty-requested-start-date-field-values.js | 6 ++--- .../assertions/check-date-field-values.js | 15 +++++++++++++ .../shared-commands/assertions/index.js | 1 + .../multiple-contract-policy.spec.js | 11 +++++++--- .../save-and-back.spec.js | 13 ++++++----- .../single-contract-policy.spec.js | 22 +++++++++++++------ 7 files changed, 52 insertions(+), 22 deletions(-) create mode 100644 e2e-tests/commands/shared-commands/assertions/check-date-field-values.js diff --git a/e2e-tests/commands/shared-commands/assertions/assert-empty-contract-completion-date-field-values.js b/e2e-tests/commands/shared-commands/assertions/assert-empty-contract-completion-date-field-values.js index cdcf25a9f5..2059b653cd 100644 --- a/e2e-tests/commands/shared-commands/assertions/assert-empty-contract-completion-date-field-values.js +++ b/e2e-tests/commands/shared-commands/assertions/assert-empty-contract-completion-date-field-values.js @@ -12,9 +12,9 @@ const { * Assert all CONTRACT_COMPLETION_DATE field values are empty. */ const assertEmptyContractCompletionDateFieldValues = () => { - field(CONTRACT_COMPLETION_DATE).dayInput().should('have.value', ''); - field(CONTRACT_COMPLETION_DATE).monthInput().should('have.value', ''); - field(CONTRACT_COMPLETION_DATE).yearInput().should('have.value', ''); + const selector = field(CONTRACT_COMPLETION_DATE); + + cy.checkDateFieldValues({ selector }); }; export default assertEmptyContractCompletionDateFieldValues; diff --git a/e2e-tests/commands/shared-commands/assertions/assert-empty-requested-start-date-field-values.js b/e2e-tests/commands/shared-commands/assertions/assert-empty-requested-start-date-field-values.js index 89d09ad720..111368913d 100644 --- a/e2e-tests/commands/shared-commands/assertions/assert-empty-requested-start-date-field-values.js +++ b/e2e-tests/commands/shared-commands/assertions/assert-empty-requested-start-date-field-values.js @@ -10,9 +10,9 @@ const { * Assert all REQUESTED_START_DATE field values are empty. */ const assertEmptyRequestedStartDateFieldValues = () => { - field(REQUESTED_START_DATE).dayInput().should('have.value', ''); - field(REQUESTED_START_DATE).monthInput().should('have.value', ''); - field(REQUESTED_START_DATE).yearInput().should('have.value', ''); + const selector = field(REQUESTED_START_DATE); + + cy.checkDateFieldValues({ selector }); }; export default assertEmptyRequestedStartDateFieldValues; diff --git a/e2e-tests/commands/shared-commands/assertions/check-date-field-values.js b/e2e-tests/commands/shared-commands/assertions/check-date-field-values.js new file mode 100644 index 0000000000..d2214034e1 --- /dev/null +++ b/e2e-tests/commands/shared-commands/assertions/check-date-field-values.js @@ -0,0 +1,15 @@ +/** + * checkDateFieldValues + * Check an date field's day, month and year input values + * @param {Function} selector: Cypress selector + * @param {String} day: Expected day value + * @param {String} month: Expected month value + * @param {String} year: Expected year value + */ +const checkDateFieldValues = ({ selector, day = '', month = '', year = '' }) => { + selector.dayInput().should('have.value', day); + selector.monthInput().should('have.value', month); + selector.yearInput().should('have.value', year); +}; + +export default checkDateFieldValues; diff --git a/e2e-tests/commands/shared-commands/assertions/index.js b/e2e-tests/commands/shared-commands/assertions/index.js index 9adfdce061..f3a78734bc 100644 --- a/e2e-tests/commands/shared-commands/assertions/index.js +++ b/e2e-tests/commands/shared-commands/assertions/index.js @@ -41,6 +41,7 @@ Cypress.Commands.add('checkTextAndValue', require('./check-text-and-value')); Cypress.Commands.add('checkTextareaValue', require('./check-textarea-value')); Cypress.Commands.add('checkTypeAttribute', require('./check-type-attribute')); Cypress.Commands.add('checkValue', require('./check-value')); +Cypress.Commands.add('checkDateFieldValues', require('./check-date-field-values')); Cypress.Commands.add('checkAuthenticatedHeader', require('./check-authenticated-header')); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/policy/multiple-contract-policy/multiple-contract-policy.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/policy/multiple-contract-policy/multiple-contract-policy.spec.js index 99e29658c0..e2cdddb76c 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/policy/multiple-contract-policy/multiple-contract-policy.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/policy/multiple-contract-policy/multiple-contract-policy.spec.js @@ -147,9 +147,14 @@ context('Insurance - Policy - Multiple contract policy page - As an exporter, I it('should have the submitted values', () => { cy.navigateToUrl(url); - fieldSelector(REQUESTED_START_DATE).dayInput().should('have.value', application.POLICY[REQUESTED_START_DATE].day); - fieldSelector(REQUESTED_START_DATE).monthInput().should('have.value', application.POLICY[REQUESTED_START_DATE].month); - fieldSelector(REQUESTED_START_DATE).yearInput().should('have.value', application.POLICY[REQUESTED_START_DATE].year); + const { day, month, year } = application.POLICY[REQUESTED_START_DATE]; + + cy.checkDateFieldValues({ + selector: fieldSelector(REQUESTED_START_DATE), + day, + month, + year, + }); cy.checkValue(fieldSelector(TOTAL_MONTHS_OF_COVER), application.POLICY[TOTAL_MONTHS_OF_COVER]); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/policy/single-contract-policy/save-and-back.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/policy/single-contract-policy/save-and-back.spec.js index 8db59ff354..6ded29db6f 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/policy/single-contract-policy/save-and-back.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/policy/single-contract-policy/save-and-back.spec.js @@ -89,9 +89,7 @@ context('Insurance - Policy - Single contract policy page - Save and go back', ( cy.startInsurancePolicySection({}); cy.clickSubmitButton(); - field.dayInput().should('have.value', ''); - field.monthInput().should('have.value', ''); - field.yearInput().should('have.value', ''); + cy.assertEmptyRequestedStartDateFieldValues({}); }); }); @@ -121,9 +119,12 @@ context('Insurance - Policy - Single contract policy page - Save and go back', ( cy.startInsurancePolicySection({}); cy.clickSubmitButton(); - field.dayInput().should('have.value', '1'); - field.monthInput().should('have.value', month); - field.yearInput().should('have.value', new Date(futureDate).getFullYear()); + cy.checkDateFieldValues({ + selector: field, + day: '1', + month, + year: new Date(futureDate).getFullYear(), + }); }); }); }); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/policy/single-contract-policy/single-contract-policy.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/policy/single-contract-policy/single-contract-policy.spec.js index 6f8d376c9b..2d2f9bc668 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/policy/single-contract-policy/single-contract-policy.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/policy/single-contract-policy/single-contract-policy.spec.js @@ -152,13 +152,21 @@ context('Insurance - Policy - Single contract policy page - As an exporter, I wa cy.navigateToUrl(`${INSURANCE_ROOT}/${referenceNumber}${SINGLE_CONTRACT_POLICY}`); - fieldSelector(REQUESTED_START_DATE).dayInput().should('have.value', application.POLICY[REQUESTED_START_DATE].day); - fieldSelector(REQUESTED_START_DATE).monthInput().should('have.value', application.POLICY[REQUESTED_START_DATE].month); - fieldSelector(REQUESTED_START_DATE).yearInput().should('have.value', application.POLICY[REQUESTED_START_DATE].year); - - fieldSelector(CONTRACT_COMPLETION_DATE).dayInput().should('have.value', application.POLICY[CONTRACT_COMPLETION_DATE].day); - fieldSelector(CONTRACT_COMPLETION_DATE).monthInput().should('have.value', application.POLICY[CONTRACT_COMPLETION_DATE].month); - fieldSelector(CONTRACT_COMPLETION_DATE).yearInput().should('have.value', application.POLICY[CONTRACT_COMPLETION_DATE].year); + const { POLICY } = application; + + cy.checkDateFieldValues({ + selector: fieldSelector(REQUESTED_START_DATE), + day: POLICY[REQUESTED_START_DATE].day, + month: POLICY[REQUESTED_START_DATE].month, + year: POLICY[REQUESTED_START_DATE].year, + }); + + cy.checkDateFieldValues({ + selector: fieldSelector(CONTRACT_COMPLETION_DATE), + day: POLICY[CONTRACT_COMPLETION_DATE].day, + month: POLICY[CONTRACT_COMPLETION_DATE].month, + year: POLICY[CONTRACT_COMPLETION_DATE].year, + }); const isoCode = application.POLICY[POLICY_CURRENCY_CODE];