Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(EMS-4117-4118): policy - change your answers - broker data mapping #3491

Merged
merged 9 commits into from
Jan 21, 2025
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { summaryList } from '../../../../../../../pages/shared';
import { POLICY as POLICY_FIELD_IDS } from '../../../../../../../constants/field-ids/insurance/policy';
import { INSURANCE_ROUTES } from '../../../../../../../constants/routes/insurance';
import checkSummaryList from '../../../../../../../commands/insurance/check-policy-summary-list';

const {
USING_BROKER,
BROKER_DETAILS: { NAME, EMAIL },
BROKER_ADDRESSES: { SELECT_THE_ADDRESS },
BROKER_MANUAL_ADDRESS: { FULL_ADDRESS },
} = POLICY_FIELD_IDS;

const {
ROOT,
POLICY: { BROKER_DETAILS_ROOT, CHECK_YOUR_ANSWERS },
} = INSURANCE_ROUTES;

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

context('Insurance - Policy - Change your answers - Broker based in UK - No to yes - As an exporter, I want to change my answers to the broker section', () => {
let referenceNumber;
let checkYourAnswersUrl;

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

cy.completePolicySection({ usingBroker: true, brokerIsBasedInUk: false });

checkYourAnswersUrl = `${baseUrl}${ROOT}/${referenceNumber}${CHECK_YOUR_ANSWERS}`;
});
});

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

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

describe('after changing the answer from no to yes', () => {
before(() => {
cy.navigateToUrl(checkYourAnswersUrl);

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

cy.completeAndSubmitBrokerDetailsForm({ isBasedInUk: true });

// submit the "confirm broker address" form
cy.clickSubmitButton();
});

it(`should redirect to ${CHECK_YOUR_ANSWERS}`, () => {
cy.assertChangeAnswersPageUrl({ referenceNumber, route: CHECK_YOUR_ANSWERS, fieldId: NAME });
});

it('should render new broker details summary list rows', () => {
cy.navigateToUrl(checkYourAnswersUrl);

checkSummaryList[USING_BROKER]({ usingBroker: true });

checkSummaryList.BROKER[NAME]();

checkSummaryList.BROKER[EMAIL]();

checkSummaryList.BROKER[SELECT_THE_ADDRESS]({ shouldRender: true });
});

it(`should NOT render a ${FULL_ADDRESS} summary list row`, () => {
cy.navigateToUrl(checkYourAnswersUrl);

checkSummaryList.BROKER[FULL_ADDRESS]({ shouldRender: false });
});

describe(`when going back to ${BROKER_DETAILS_ROOT}`, () => {
beforeEach(() => {
cy.navigateToUrl(checkYourAnswersUrl);

summaryList.field(NAME).changeLink().click();
});

it('should retain the existing values', () => {
cy.assertBrokerDetailsFieldValues({ isBasedInUk: true });
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import { summaryList } from '../../../../../../../pages/shared';
import { POLICY as POLICY_FIELD_IDS } from '../../../../../../../constants/field-ids/insurance/policy';
import { INSURANCE_ROUTES } from '../../../../../../../constants/routes/insurance';
import checkSummaryList from '../../../../../../../commands/insurance/check-policy-summary-list';

const {
USING_BROKER,
BROKER_DETAILS: { NAME, EMAIL, POSTCODE, BUILDING_NUMBER_OR_NAME },
BROKER_ADDRESSES: { SELECT_THE_ADDRESS },
BROKER_MANUAL_ADDRESS: { FULL_ADDRESS },
} = POLICY_FIELD_IDS;

const {
ROOT,
POLICY: { BROKER_DETAILS_ROOT, CHECK_YOUR_ANSWERS },
} = INSURANCE_ROUTES;

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

context('Insurance - Policy - Change your answers - Broker based in UK - Yes to no - As an exporter, I want to change my answers to the broker section', () => {
let referenceNumber;
let checkYourAnswersUrl;

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

cy.completePolicySection({ usingBroker: true, brokerIsBasedInUk: true });

checkYourAnswersUrl = `${baseUrl}${ROOT}/${referenceNumber}${CHECK_YOUR_ANSWERS}`;
});
});

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

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

describe('after changing the answer from yes to no', () => {
before(() => {
cy.navigateToUrl(checkYourAnswersUrl);

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

cy.completeAndSubmitBrokerDetailsForm({ isBasedInUk: false });

cy.completeAndSubmitBrokerManualAddressForm({});
});

it(`should redirect to ${CHECK_YOUR_ANSWERS}`, () => {
cy.assertChangeAnswersPageUrl({ referenceNumber, route: CHECK_YOUR_ANSWERS, fieldId: NAME });
});

it('should render new broker details summary list rows', () => {
cy.navigateToUrl(checkYourAnswersUrl);

checkSummaryList[USING_BROKER]({ usingBroker: true });

checkSummaryList.BROKER[NAME]();

checkSummaryList.BROKER[EMAIL]();

checkSummaryList.BROKER[FULL_ADDRESS]({ shouldRender: true });
});

it(`should NOT render a ${SELECT_THE_ADDRESS} summary list row`, () => {
cy.navigateToUrl(checkYourAnswersUrl);

checkSummaryList.BROKER[SELECT_THE_ADDRESS]({ shouldRender: false });
});

describe(`when going back to ${BROKER_DETAILS_ROOT}`, () => {
beforeEach(() => {
cy.navigateToUrl(checkYourAnswersUrl);

summaryList.field(NAME).changeLink().click();
});

it('should retain the existing values', () => {
cy.assertBrokerDetailsFieldValues({ isBasedInUk: false });
});

it('should have empty conditional `yes` field values', () => {
cy.clickYesRadioInput();

cy.assertEmptyFieldValue(POSTCODE);
cy.assertEmptyFieldValue(BUILDING_NUMBER_OR_NAME);
});
});
});

describe(`when changing the answer again from no to yes and going back to ${BROKER_DETAILS_ROOT}`, () => {
beforeEach(() => {
cy.navigateToUrl(checkYourAnswersUrl);

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

cy.completeAndSubmitBrokerDetailsForm({ isBasedInUk: true });

cy.clickBackLink();
});

it('should retain the submitted values', () => {
cy.assertBrokerDetailsFieldValues({ isBasedInUk: true });
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const {
const baseUrl = Cypress.config('baseUrl');

context(
'Insurance - Policy - Change your answers - Broker - No to yes - Based in UK - As an exporter, I want to change my answers to the broker section',
'Insurance - Policy - Change your answers - Using a broker - No to yes - Based in UK - As an exporter, I want to change my answers to the broker section',
() => {
let referenceNumber;
let checkYourAnswersUrl;
Expand Down Expand Up @@ -69,11 +69,12 @@ context(

it(`should render new ${FIELD_ID} answer and broker details fields`, () => {
checkSummaryList[FIELD_ID]({ usingBroker: true });
checkSummaryList.BROKER[NAME]();

checkSummaryList.BROKER[SELECT_THE_ADDRESS]({});
checkSummaryList.BROKER[NAME]();

checkSummaryList.BROKER[EMAIL]();

checkSummaryList.BROKER[SELECT_THE_ADDRESS]({});
});
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const {
const baseUrl = Cypress.config('baseUrl');

context(
'Insurance - Policy - Change your answers - Broker - No to yes - Not based in UK - As an exporter, I want to change my answers to the broker section',
'Insurance - Policy - Change your answers - Using a broker - No to yes - Not based in UK - As an exporter, I want to change my answers to the broker section',
() => {
let referenceNumber;
let checkYourAnswersUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ import { FIELD_VALUES } from '../../../../../../../constants';

const {
USING_BROKER: FIELD_ID,
BROKER_DETAILS: { NAME, EMAIL },
BROKER_DETAILS: { NAME, EMAIL, POSTCODE, BUILDING_NUMBER_OR_NAME },
BROKER_ADDRESSES: { SELECT_THE_ADDRESS },
BROKER_MANUAL_ADDRESS: { FULL_ADDRESS },
} = POLICY_FIELD_IDS;

const {
ROOT,
POLICY: { BROKER_CHANGE, BROKER_DETAILS_ROOT, CHECK_YOUR_ANSWERS },
POLICY: { BROKER_CHANGE, BROKER_DETAILS_ROOT, BROKER_MANUAL_ADDRESS_ROOT, CHECK_YOUR_ANSWERS },
} = INSURANCE_ROUTES;

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

context('Insurance - Policy - Change your answers - Broker - Yes to no - As an exporter, I want to change my answers to the broker section', () => {
context('Insurance - Policy - Change your answers - Using a broker - Yes to no - As an exporter, I want to change my answers to the broker section', () => {
let referenceNumber;
let checkYourAnswersUrl;

Expand Down Expand Up @@ -77,14 +77,47 @@ context('Insurance - Policy - Change your answers - Broker - Yes to no - As an e
cy.assertSummaryListRowDoesNotExist(summaryList, FULL_ADDRESS);
});

describe(`when changing the answer again from no to yes and going back to ${BROKER_DETAILS_ROOT}`, () => {
it('should have empty field values', () => {
describe('when changing the answer again from no to yes', () => {
beforeEach(() => {
cy.navigateToUrl(checkYourAnswersUrl);

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

cy.completeAndSubmitBrokerForm({ usingBroker: true });
});

describe(`when going back to ${BROKER_DETAILS_ROOT}`, () => {
it('should have empty field values', () => {
cy.assertEmptyFieldValue(NAME);
cy.assertEmptyFieldValue(EMAIL);

cy.assertUncheckedYesNoRadios();

cy.clickYesRadioInput();

cy.assertEmptyFieldValue(POSTCODE);
cy.assertEmptyFieldValue(BUILDING_NUMBER_OR_NAME);
});
});

describe(`after completing (now required) broker fields and going back to ${BROKER_MANUAL_ADDRESS_ROOT}`, () => {
beforeEach(() => {
cy.navigateToUrl(checkYourAnswersUrl);

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

cy.completeAndSubmitBrokerForm({ usingBroker: true });

cy.completeAndSubmitBrokerDetailsForm({
buildingNumberOrName: '123456789',
});

cy.clickZeroAddressesEntryManuallyLink();
});

cy.assertEmptyFieldValue(NAME);
cy.assertEmptyFieldValue(EMAIL);
it('should have empty field values', () => {
cy.assertEmptyTextareaFieldValue(FULL_ADDRESS);
});
});
});
});
Expand Down
Loading
Loading