Skip to content

Commit

Permalink
chore(EMS-2656): iterations - E2E - text and value cypress command (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Zainzzkk authored Jul 25, 2024
1 parent cc628a9 commit c61bde3
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
import { field as fieldSelector } from '../../../pages/shared';
import { INSURANCE_FIELD_IDS } from '../../../constants/field-ids/insurance';

const {
POLICY: {
DIFFERENT_NAME_ON_POLICY: { POSITION },
},
ACCOUNT: { FIRST_NAME, LAST_NAME, EMAIL },
} = INSURANCE_FIELD_IDS;

/**
* assertDifferentNameOnPolicyFieldValues
* Assert all field values in the "different name on policy" form.
Expand All @@ -16,11 +6,12 @@ const {
* @param {String} expectedEmail: Email
* @param {String} expectedPosition: Position
*/
const assertDifferentNameOnPolicyFieldValues = ({ expectedFirstName = '', expectedLastName = '', expectedEmail = '', expectedPosition = '' }) => {
cy.checkValue(fieldSelector(FIRST_NAME), expectedFirstName);
cy.checkValue(fieldSelector(LAST_NAME), expectedLastName);
cy.checkValue(fieldSelector(EMAIL), expectedEmail);
cy.checkValue(fieldSelector(POSITION), expectedPosition);
};
const assertDifferentNameOnPolicyFieldValues = ({ expectedFirstName = '', expectedLastName = '', expectedEmail = '', expectedPosition = '' }) =>
cy.assertNameEmailAndPositionFields({
expectedFirstName,
expectedLastName,
expectedEmail,
expectedPosition,
});

export default assertDifferentNameOnPolicyFieldValues;
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { field } from '../../../pages/shared';
import { INSURANCE_FIELD_IDS } from '../../../constants/field-ids/insurance';

const {
POLICY: {
DIFFERENT_NAME_ON_POLICY: { POSITION },
},
ACCOUNT: { FIRST_NAME, LAST_NAME, EMAIL },
} = INSURANCE_FIELD_IDS;

/**
* assertNameEmailAndPositionFields
* Asserts FIRST_NAME, LAST_NAME, EMAIL and POSITION fields' values.
* @param {String} expectedFirstName: First name
* @param {String} expectedLastName: Last name
* @param {String} expectedEmail: Email address
* @param {String} expectedPosition: Position
*/
const assertNameEmailAndPositionFields = ({ expectedFirstName, expectedLastName, expectedEmail, expectedPosition }) => {
cy.checkValue(field(FIRST_NAME), expectedFirstName);
cy.checkValue(field(LAST_NAME), expectedLastName);
cy.checkValue(field(EMAIL), expectedEmail);
cy.checkValue(field(POSITION), expectedPosition);
};

export default assertNameEmailAndPositionFields;
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
* @param {Object} currency
*/
const checkCurrencyOption = (selector, currency) => {
cy.checkText(selector.label(), `${currency.name} (${currency.isoCode})`);
cy.checkValue(selector, currency.isoCode);
const textValue = `${currency.name} (${currency.isoCode})`;

cy.checkTextAndValue({
textSelector: selector.label(),
expectedText: textValue,
valueSelector: selector,
expectedValue: currency.isoCode,
});
};

export default checkCurrencyOption;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* checkTextAndValue
* Check the text and value of an element
* @param {Function} textSelector: Cypress selector for text
* @param {String} expectedText: Expected text
* @param {Function} selector: Cypress selector for value
* @param {String} expectedValue: Expected value
*/
const checkTextAndValue = ({ textSelector, expectedText, valueSelector, expectedValue }) => {
cy.checkText(textSelector, expectedText);
cy.checkValue(valueSelector, expectedValue);
};

export default checkTextAndValue;
2 changes: 2 additions & 0 deletions e2e-tests/commands/shared-commands/assertions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Cypress.Commands.add('assertLength', require('./assert-length'));
Cypress.Commands.add('assertErrorSummaryListLength', require('./assert-error-summary-list-length'));
Cypress.Commands.add('assertErrorSummaryListDoesNotExist', require('./assert-error-summary-list-does-not-exist'));
Cypress.Commands.add('assertCurrencyFormFieldsAreEmpty', require('./assert-currency-form-fields-are-empty'));
Cypress.Commands.add('assertNameEmailAndPositionFields', require('./assert-name-email-and-position-fields'));

Cypress.Commands.add('assertCopyWithCurrencyName', require('./assert-copy-with-currency-name'));
Cypress.Commands.add('assertPrefix', require('./assert-prefix'));
Expand All @@ -36,6 +37,7 @@ Cypress.Commands.add('checkEmailFieldRendering', require('./check-email-field-re
Cypress.Commands.add('checkIntroText', require('./check-intro-text'));
Cypress.Commands.add('checkLink', require('./check-link'));
Cypress.Commands.add('checkText', require('./check-text'));
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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,12 @@ context('Insurance - Buyer country page - as an exporter, I want to check if UKE

const expectedValue = COUNTRY_NAME;

cy.checkValue(autoCompleteField(FIELD_ID), expectedValue);

cy.checkText(autoCompleteField(FIELD_ID).results(), expectedValue);
cy.checkTextAndValue({
textSelector: autoCompleteField(FIELD_ID).results(),
expectedText: expectedValue,
valueSelector: autoCompleteField(FIELD_ID),
expectedValue,
});
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,12 @@ context(

const expectedValue = COUNTRY_NAME;

cy.checkValue(autoCompleteField(FIELD_ID), expectedValue);

cy.checkText(autoCompleteField(FIELD_ID).results(), expectedValue);
cy.checkTextAndValue({
textSelector: autoCompleteField(FIELD_ID).results(),
expectedText: expectedValue,
valueSelector: autoCompleteField(FIELD_ID),
expectedValue,
});
});
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ context('Insurance - Policy - Different name on policy - Save and go back', () =
it('should have the all inputs as empty when going back to the page after submission', () => {
cy.navigateToUrl(url);

cy.checkValue(field(FIRST_NAME), '');
cy.checkValue(field(LAST_NAME), '');
cy.checkValue(field(EMAIL), '');
cy.checkValue(field(POSITION), '');
cy.assertNameEmailAndPositionFields({
expectedFirstName: '',
expectedLastName: '',
expectedEmail: '',
expectedPosition: '',
});
});
});

Expand All @@ -93,10 +95,12 @@ context('Insurance - Policy - Different name on policy - Save and go back', () =
it('should have the originally submitted answers populated when going back to the page after submission', () => {
cy.navigateToUrl(url);

cy.checkValue(field(FIRST_NAME), POLICY_CONTACT[FIRST_NAME]);
cy.checkValue(field(LAST_NAME), POLICY_CONTACT[LAST_NAME]);
cy.checkValue(field(EMAIL), '');
cy.checkValue(field(POSITION), '');
cy.assertNameEmailAndPositionFields({
expectedFirstName: POLICY_CONTACT[FIRST_NAME],
expectedLastName: POLICY_CONTACT[LAST_NAME],
expectedEmail: '',
expectedPosition: '',
});
});
});

Expand All @@ -119,10 +123,12 @@ context('Insurance - Policy - Different name on policy - Save and go back', () =
it('should have the originally submitted answers populated when going back to the page after submission', () => {
cy.navigateToUrl(url);

cy.checkValue(field(FIRST_NAME), POLICY_CONTACT[FIRST_NAME]);
cy.checkValue(field(LAST_NAME), POLICY_CONTACT[LAST_NAME]);
cy.checkValue(field(EMAIL), POLICY_CONTACT[EMAIL]);
cy.checkValue(field(POSITION), POLICY_CONTACT[POSITION]);
cy.assertNameEmailAndPositionFields({
expectedFirstName: POLICY_CONTACT[FIRST_NAME],
expectedLastName: POLICY_CONTACT[LAST_NAME],
expectedEmail: POLICY_CONTACT[EMAIL],
expectedPosition: POLICY_CONTACT[POSITION],
});
});

it('should have the originally submitted answers populated when going back to the page through policy and exports flow', () => {
Expand All @@ -131,10 +137,12 @@ context('Insurance - Policy - Different name on policy - Save and go back', () =
// go through 4 policy forms.
cy.clickSubmitButtonMultipleTimes({ count: 4 });

cy.checkValue(field(FIRST_NAME), POLICY_CONTACT[FIRST_NAME]);
cy.checkValue(field(LAST_NAME), POLICY_CONTACT[LAST_NAME]);
cy.checkValue(field(EMAIL), POLICY_CONTACT[EMAIL]);
cy.checkValue(field(POSITION), POLICY_CONTACT[POSITION]);
cy.assertNameEmailAndPositionFields({
expectedFirstName: POLICY_CONTACT[FIRST_NAME],
expectedLastName: POLICY_CONTACT[LAST_NAME],
expectedEmail: POLICY_CONTACT[EMAIL],
expectedPosition: POLICY_CONTACT[POSITION],
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ context(

const expectedValue = NEW_COUNTRY_INPUT;

cy.checkValue(autoCompleteField(FIELD_ID), expectedValue);

cy.checkText(autoCompleteField(FIELD_ID).results(), expectedValue);
cy.checkTextAndValue({
textSelector: autoCompleteField(FIELD_ID).results(),
expectedText: expectedValue,
valueSelector: autoCompleteField(FIELD_ID),
expectedValue,
});
});
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ context(

const expectedValue = NEW_COUNTRY_INPUT;

cy.checkValue(autoCompleteField(FIELD_ID), expectedValue);

cy.checkText(autoCompleteField(FIELD_ID).results(), expectedValue);
cy.checkTextAndValue({
textSelector: autoCompleteField(FIELD_ID).results(),
expectedText: expectedValue,
valueSelector: autoCompleteField(FIELD_ID),
expectedValue,
});
});
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,12 @@ context('Buyer country page - as an exporter, I want to check if UKEF issue cred
it('should prepopulate the field when going back to the page via back link', () => {
cy.clickBackLink();

cy.checkValue(field, supportedCountryName);

cy.checkText(field.results(), supportedCountryName);
cy.checkTextAndValue({
textSelector: field.results(),
expectedText: supportedCountryName,
valueSelector: field,
expectedValue: supportedCountryName,
});
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,12 @@ const assertCurrencyFormFields = ({
cy.checkCurrencyOption(option4, JPY);

// Alternative currency
cy.checkText(option5.label(), alternativeCurrencyText);
cy.checkValue(option5, alternativeCurrencyFieldId);
cy.checkTextAndValue({
textSelector: option5.label(),
expectedText: alternativeCurrencyText,
valueSelector: option5,
expectedValue: alternativeCurrencyFieldId,
});
},
gbpCurrencyCheckedByDefault,
assertGbpCurrencyCheckedByDefault: () => {
Expand Down

0 comments on commit c61bde3

Please sign in to comment.