Skip to content

Commit

Permalink
fix(EMS-3385): no PDF - policy - nullify data when changing policy ty…
Browse files Browse the repository at this point in the history
…pe (#2500)

* fix(EMS-3385): no pdf - policy - nullify data when changing type of policy

* fix(EMS-3385): no pdf - policy - nullify data when changing type of policy

* fix(EMS-3385): no pdf - policy - nullify data when changing type of policy

* fix(EMS-3385): add missing documentation

* fix(EMS-3385): no pdf - policy - nullify data when changing type of policy

* fix(EMS-3385): improve unit test

* fix(EMS-3385): linting issues
  • Loading branch information
ttbarnes authored Jun 4, 2024
1 parent d7dd2b4 commit 55424cf
Show file tree
Hide file tree
Showing 34 changed files with 802 additions and 252 deletions.
6 changes: 1 addition & 5 deletions e2e-tests/commands/insurance/assert-currency-form-fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ const {
* @param {String} currency - Currency string
* @return {Function} radio
*/
const currencyRadio = ({
fieldId,
currency,
alternativeCurrencyFieldId = ALTERNATIVE_CURRENCY_CODE,
}) => {
const currencyRadio = ({ fieldId, currency, alternativeCurrencyFieldId = ALTERNATIVE_CURRENCY_CODE }) => {
if (currency) {
const { option } = radios(fieldId, currency);
return option;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {

/**
* changePolicyTypeToMultipleAndSubmitContractPolicyForm
* 1) Change policy type to multiple and submit the "contract policy" form.
* Change policy type to multiple and submit the "multiple contract policy" form.
*/
const changePolicyTypeToMultipleAndSubmitContractPolicyForm = () => {
summaryList.field(POLICY_TYPE).changeLink().click();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { summaryList } from '../../pages/shared';
import { typeOfPolicyPage } from '../../pages/insurance/policy';
import { POLICY as FIELD_IDS } from '../../constants/field-ids/insurance/policy';

const {
TYPE_OF_POLICY: { POLICY_TYPE },
} = FIELD_IDS;

/**
* changePolicyTypeToSingleAndSubmitContractPolicyForm
* Change policy type to single and submit the "single contract policy" form.
*/
const changePolicyTypeToSingleAndSubmitContractPolicyForm = () => {
summaryList.field(POLICY_TYPE).changeLink().click();

typeOfPolicyPage[POLICY_TYPE].single.label().click();
cy.clickSubmitButton();

cy.completeAndSubmitSingleContractPolicyForm({});
};

export default changePolicyTypeToSingleAndSubmitContractPolicyForm;
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { radios } from '../../../pages/shared';
import { INSURANCE_FIELD_IDS } from '../../../constants/field-ids/insurance';
import { checkAutocompleteInput } from '../../../shared-test-assertions/autocomplete-assertions';
import {
EUR,
GBP,
JPY,
USD,
} from '../../../fixtures/currencies';

const {
CURRENCY: { CURRENCY_CODE, ALTERNATIVE_CURRENCY_CODE },
} = INSURANCE_FIELD_IDS;

/**
* assertCurrencyFormFieldsAreEmpty
* Assert that all "currency" form fields are empty:
* - 4x default options.
* - "alternative currency" option
* - "alternative currency" conditional autocomplete input.
*/
const assertCurrencyFormFieldsAreEmpty = () => {
const fieldId = CURRENCY_CODE;

const { option: option1 } = radios(fieldId, EUR.isoCode);
const { option: option2 } = radios(fieldId, GBP.isoCode);
const { option: option3 } = radios(fieldId, USD.isoCode);
const { option: option4 } = radios(fieldId, JPY.isoCode);
const { option: option5 } = radios(ALTERNATIVE_CURRENCY_CODE);

cy.assertRadioOptionIsNotChecked(option1.input());
cy.assertRadioOptionIsNotChecked(option2.input());
cy.assertRadioOptionIsNotChecked(option3.input());
cy.assertRadioOptionIsNotChecked(option4.input());
cy.assertRadioOptionIsNotChecked(option5.input());

cy.clickAlternativeCurrencyRadioOption();

checkAutocompleteInput.checkEmptyResults();
};

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

const {
CONTRACT_POLICY: {
SINGLE: { CONTRACT_COMPLETION_DATE },
},
} = FIELD_IDS;

/**
* assertEmptyContractCompletionDateFieldValues
* 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', '');
};

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

const {
CONTRACT_POLICY: { REQUESTED_START_DATE },
} = FIELD_IDS;

/**
* assertEmptyRequestedStartDateFieldValues
* 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', '');
};

export default assertEmptyRequestedStartDateFieldValues;
4 changes: 4 additions & 0 deletions e2e-tests/commands/shared-commands/assertions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Cypress.Commands.add('assertNoRadioOptionIsNotChecked', require('./assert-no-rad
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('assertCopyWithCurrencyName', require('./assert-copy-with-currency-name'));
Cypress.Commands.add('assertPrefix', require('./assert-prefix'));
Expand Down Expand Up @@ -84,4 +85,7 @@ Cypress.Commands.add('assertEmptyAgentServiceFieldValues', require('./assert-emp
Cypress.Commands.add('assertAgentChargesFieldValues', require('./assert-agent-charges-field-values'));
Cypress.Commands.add('assertEmptyAgentChargesFieldValues', require('./assert-empty-agent-charges-field-values'));

Cypress.Commands.add('assertEmptyContractCompletionDateFieldValues', require('./assert-empty-contract-completion-date-field-values'));
Cypress.Commands.add('assertEmptyRequestedStartDateFieldValues', require('./assert-empty-requested-start-date-field-values'));

Cypress.Commands.add('submitAndAssertChangeAnswersPageUrl', require('./submit-and-assert-change-answers-page-url'));
2 changes: 2 additions & 0 deletions e2e-tests/constants/field-ids/insurance/policy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,5 @@ export const POLICY = {
FINANCIAL_ADDRESS: 'bankAddress',
LOSS_PAYEE_FINANCIAL_ADDRESS: 'lossPayee.bankAddress',
};

export default POLICY;
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ const {
START,
ACCOUNT: {
CREATE: {
CONFIRM_EMAIL, VERIFY_EMAIL, VERIFY_EMAIL_EXPIRED_LINK, CONFIRM_EMAIL_RESENT,
CONFIRM_EMAIL,
VERIFY_EMAIL,
VERIFY_EMAIL_EXPIRED_LINK,
CONFIRM_EMAIL_RESENT,
},
},
} = ROUTES;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { field, summaryList } from '../../../../../../../pages/shared';
import { FIELD_VALUES } from '../../../../../../../constants';
import FIELD_IDS from '../../../../../../../constants/field-ids/insurance/policy';
import { INSURANCE_ROUTES } from '../../../../../../../constants/routes/insurance';

const {
POLICY_TYPE: { MULTIPLE },
} = FIELD_VALUES;

const {
ROOT,
POLICY: { CHECK_YOUR_ANSWERS, MULTIPLE_CONTRACT_POLICY, MULTIPLE_CONTRACT_POLICY_EXPORT_VALUE },
} = INSURANCE_ROUTES;

const {
TYPE_OF_POLICY: { POLICY_TYPE },
CONTRACT_POLICY: {
MULTIPLE: { TOTAL_MONTHS_OF_COVER },
},
EXPORT_VALUE: {
MULTIPLE: { TOTAL_SALES_TO_BUYER, MAXIMUM_BUYER_WILL_OWE },
},
} = FIELD_IDS;

const baseUrl = Cypress.config('baseUrl');

context('Insurance - Policy - Change your answers - Policy type - multiple to single, then back to multiple', () => {
let referenceNumber;
let checkYourAnswersUrl;
let exportValueUrl;

before(() => {
cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => {
referenceNumber = refNumber;

cy.completePolicySection({ policyType: MULTIPLE });

const applicationRouteUrl = `${ROOT}/${referenceNumber}`;

checkYourAnswersUrl = `${baseUrl}${applicationRouteUrl}${CHECK_YOUR_ANSWERS}`;
exportValueUrl = `${baseUrl}${applicationRouteUrl}${MULTIPLE_CONTRACT_POLICY_EXPORT_VALUE}`;

cy.assertUrl(checkYourAnswersUrl);
});
});

beforeEach(() => {
cy.saveSession();

cy.navigateToUrl(checkYourAnswersUrl);

cy.changePolicyTypeToSingleAndSubmitContractPolicyForm();
cy.completeAndSubmitTotalContractValueForm({});

summaryList.field(POLICY_TYPE).changeLink().click();

cy.completeAndSubmitPolicyTypeForm({ policyType: MULTIPLE });
});

after(() => {
cy.deleteApplication(referenceNumber);
});

it(`should have empty field values when going back to ${MULTIPLE_CONTRACT_POLICY} and ${MULTIPLE_CONTRACT_POLICY_EXPORT_VALUE}`, () => {
cy.assertEmptyRequestedStartDateFieldValues();

field(TOTAL_MONTHS_OF_COVER).input().should('have.value', '');

cy.assertCurrencyFormFieldsAreEmpty();

cy.navigateToUrl(exportValueUrl);

field(TOTAL_SALES_TO_BUYER).input().should('have.value', '');
field(MAXIMUM_BUYER_WILL_OWE).input().should('have.value', '');
});
});
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import { summaryList } from '../../../../../../../pages/shared';
import { typeOfPolicyPage } from '../../../../../../../pages/insurance/policy';
import { FIELD_VALUES } from '../../../../../../../constants';
import { INSURANCE_FIELD_IDS } from '../../../../../../../constants/field-ids/insurance';
import { INSURANCE_ROUTES } from '../../../../../../../constants/routes/insurance';
import checkSummaryList from '../../../../../../../commands/insurance/check-policy-summary-list';

const {
ROOT,
POLICY: {
CHECK_YOUR_ANSWERS,
TYPE_OF_POLICY_CHANGE,
SINGLE_CONTRACT_POLICY_TOTAL_CONTRACT_VALUE_CHANGE,
},
POLICY: { CHECK_YOUR_ANSWERS, TYPE_OF_POLICY_CHANGE, SINGLE_CONTRACT_POLICY_TOTAL_CONTRACT_VALUE_CHANGE },
} = INSURANCE_ROUTES;

const {
Expand Down Expand Up @@ -73,12 +68,7 @@ context('Insurance - Policy - Change your answers - Policy type - multiple to si
beforeEach(() => {
cy.navigateToUrl(checkYourAnswersUrl);

summaryList.field(POLICY_TYPE).changeLink().click();

typeOfPolicyPage[POLICY_TYPE].single.label().click();
cy.clickSubmitButton();

cy.completeAndSubmitSingleContractPolicyForm({});
cy.changePolicyTypeToSingleAndSubmitContractPolicyForm();
});

it(`should redirect to ${SINGLE_CONTRACT_POLICY_TOTAL_CONTRACT_VALUE_CHANGE} because the policy type has changed`, () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { field, summaryList } from '../../../../../../../pages/shared';
import { FIELD_VALUES } from '../../../../../../../constants';
import { INSURANCE_ROUTES } from '../../../../../../../constants/routes/insurance';
import FIELD_IDS from '../../../../../../../constants/field-ids/insurance/policy';

const {
POLICY_TYPE: { SINGLE },
} = FIELD_VALUES;

const {
ROOT,
POLICY: { CHECK_YOUR_ANSWERS, SINGLE_CONTRACT_POLICY, SINGLE_CONTRACT_POLICY_TOTAL_CONTRACT_VALUE },
} = INSURANCE_ROUTES;

const {
TYPE_OF_POLICY: { POLICY_TYPE },
CONTRACT_POLICY: {
SINGLE: { TOTAL_CONTRACT_VALUE },
},
} = FIELD_IDS;

const baseUrl = Cypress.config('baseUrl');

context('Insurance - Policy - Change your answers - Policy type - single to multiple, then back to single', () => {
let referenceNumber;
let checkYourAnswersUrl;
let totalContractValueUrl;

before(() => {
cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => {
referenceNumber = refNumber;

cy.completePolicySection({});

const applicationRouteUrl = `${ROOT}/${referenceNumber}`;

checkYourAnswersUrl = `${baseUrl}${applicationRouteUrl}${CHECK_YOUR_ANSWERS}`;
totalContractValueUrl = `${baseUrl}${applicationRouteUrl}${SINGLE_CONTRACT_POLICY_TOTAL_CONTRACT_VALUE}`;

cy.assertUrl(checkYourAnswersUrl);
});
});

beforeEach(() => {
cy.saveSession();

cy.navigateToUrl(checkYourAnswersUrl);

cy.changePolicyTypeToMultipleAndSubmitContractPolicyForm();
cy.completeAndSubmitExportValueForm();

summaryList.field(POLICY_TYPE).changeLink().click();

cy.completeAndSubmitPolicyTypeForm({ policyType: SINGLE });
});

after(() => {
cy.deleteApplication(referenceNumber);
});

it(`should have empty field values when going back to ${SINGLE_CONTRACT_POLICY} and ${SINGLE_CONTRACT_POLICY_TOTAL_CONTRACT_VALUE}`, () => {
cy.assertEmptyRequestedStartDateFieldValues();
cy.assertEmptyContractCompletionDateFieldValues();

cy.assertCurrencyFormFieldsAreEmpty();

cy.navigateToUrl(totalContractValueUrl);

field(TOTAL_CONTRACT_VALUE).input().should('have.value', '');
});
});
Loading

0 comments on commit 55424cf

Please sign in to comment.