Skip to content

Commit

Permalink
chore(EMS-3898): dry checkDateFieldValues command (#3170)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttbarnes authored Oct 11, 2024
1 parent 9b59589 commit a73f401
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
@@ -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;
1 change: 1 addition & 0 deletions e2e-tests/commands/shared-commands/assertions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({});
});
});

Expand Down Expand Up @@ -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(),
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down

0 comments on commit a73f401

Please sign in to comment.