Skip to content

Commit

Permalink
feat(EMS-4011-4022): policy - change your answers - broker address (#…
Browse files Browse the repository at this point in the history
…3482)

* feat(EMS-4011-4120): policy - change your answers - broker address

* feat(EMS-4011-4120): policy - change your answers - broker address

* chore(EMS-4011-4120): update e2e tests

* feat(EMS-4011-4120): policy - change your answers - broker based in uk

* chore(e2e): align test descriptions

* feat(EMS-4011-4120): update e2e tests

* feat(EMS-4011-4120): update 'different address ur' to handle change routes

* fix(EMS-4011): broker summary list address field mapping

* feat(EMS-4011-4120): fix typos

* chore(mocks): update ui mock broker data

* chore(docs): remove unnecessary comments

* feat(EMS-4011-4120): address todo comments

* feat(EMS-4011-4120): update e2e test

* feat(EMS-4011-4120): create brokerDetailsDataChangeFlags helper function

* feat(EMS-4011-4120): address todo comment

* feat(EMS-4011-4120): refactor/extract broker details redirection logic

* chore(EMS-4011): fix linting issue

* feat(EMS-4011-4120): minor code edits
  • Loading branch information
ttbarnes authored Jan 21, 2025
1 parent b958d11 commit 08883af
Show file tree
Hide file tree
Showing 72 changed files with 1,213 additions and 384 deletions.
1 change: 0 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@
"venv",
"VNET",
"vnets",
"WOGAN",
"XLSX",
"eg9qxlqw4edxa8b5mwbybsrfp",
"mzwp337piamg1mei7fqh1o73s",
Expand Down
30 changes: 19 additions & 11 deletions e2e-tests/commands/insurance/check-policy-summary-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,29 +233,37 @@ const checkPolicySummaryList = {

cy.assertSummaryListRow(summaryList, fieldId, expectedKey, expectedValue, expectedChangeLinkText);
},
[BROKER_ADDRESSES.SELECT_THE_ADDRESS]: () => {
[BROKER_ADDRESSES.SELECT_THE_ADDRESS]: ({ shouldRender = true, expectedValue = EXPECTED_TREASURY_SINGLE_LINE_STRING }) => {
const fieldId = BROKER_ADDRESSES.SELECT_THE_ADDRESS;

const expectedKey = FIELDS.BROKER_ADDRESSES[fieldId].SUMMARY.TITLE;
if (shouldRender) {
const expectedKey = FIELDS.BROKER_ADDRESSES[fieldId].SUMMARY.TITLE;

const row = summaryList.field(fieldId);
const row = summaryList.field(fieldId);

cy.checkText(row.key(), expectedKey);
cy.checkText(row.key(), expectedKey);

row.value().contains(EXPECTED_TREASURY_SINGLE_LINE_STRING);
row.value().contains(expectedValue);

const expectedLineBreaks = 4;
const expectedLineBreaks = 4;

cy.assertLength(row.valueHtmlLineBreak(), expectedLineBreaks);
cy.assertLength(row.valueHtmlLineBreak(), expectedLineBreaks);
} else {
cy.assertSummaryListRowDoesNotExist(summaryList, fieldId);
}
},
[BROKER_MANUAL_ADDRESS.FULL_ADDRESS]: () => {
[BROKER_MANUAL_ADDRESS.FULL_ADDRESS]: ({ shouldRender = true }) => {
const fieldId = BROKER_MANUAL_ADDRESS.FULL_ADDRESS;

const { expectedKey, expectedChangeLinkText } = getSummaryListField(fieldId, FIELDS.BROKER_MANUAL_ADDRESS);
if (shouldRender) {
const { expectedKey, expectedChangeLinkText } = getSummaryListField(fieldId, FIELDS.BROKER_MANUAL_ADDRESS);

const expectedValue = application.BROKER[fieldId];
const expectedValue = application.BROKER[fieldId];

cy.assertSummaryListRow(summaryList, fieldId, expectedKey, expectedValue, expectedChangeLinkText);
cy.assertSummaryListRow(summaryList, fieldId, expectedKey, expectedValue, expectedChangeLinkText);
} else {
cy.assertSummaryListRowDoesNotExist(summaryList, fieldId);
}
},
[BROKER_DETAILS.EMAIL]: () => {
const fieldId = BROKER_DETAILS.NAME;
Expand Down
2 changes: 2 additions & 0 deletions e2e-tests/constants/routes/insurance/policy/broker.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const BROKER_ROUTES = {
BROKER_ADDRESSES_CHANGE: `${BROKER_ADDRESSES_ROOT}/change`,
BROKER_ADDRESSES_CHECK_AND_CHANGE: `${BROKER_ADDRESSES_ROOT}/check-and-change`,
BROKER_CONFIRM_ADDRESS_ROOT,
BROKER_CONFIRM_ADDRESS_CHANGE: `${BROKER_CONFIRM_ADDRESS_ROOT}/change`,
BROKER_CONFIRM_ADDRESS_CHECK_AND_CHANGE: `${BROKER_CONFIRM_ADDRESS_ROOT}/check-and-change`,
BROKER_ZERO_ADDRESSES_ROOT,
BROKER_MANUAL_ADDRESS_ROOT,
BROKER_MANUAL_ADDRESS_SAVE_AND_BACK: `${BROKER_MANUAL_ADDRESS_ROOT}/save-and-back`,
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/fixtures/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ const application = {
[USING_BROKER]: true,
[NAME]: 'Mock broker name',
[EMAIL]: Cypress.env('GOV_NOTIFY_EMAIL_RECIPIENT_1'),
[BROKER_FULL_ADDRESS]: 'Mock broker address',
[BROKER_FULL_ADDRESS]: 'Mock full broker address',
[BUILDING_NUMBER_OR_NAME]: '1',
[POSTCODE]: VALID_POSTCODES.WITH_SPACE,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { APPLICATION } from '../../../../../../../constants';

context(
'Insurance - submit an application - Multiple policy type with a broker - based in UK - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application',
'Insurance - submit an application - Multiple policy type with a broker - Based in UK - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application',
() => {
let referenceNumber;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { APPLICATION } from '../../../../../../../constants';

context(
'Insurance - submit an application - Multiple policy type with a broker - not based in UK - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application',
'Insurance - submit an application - Multiple policy type with a broker - Not based in UK - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application',
() => {
let referenceNumber;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { APPLICATION, BUILDING_NAMES, VALID_POSTCODES } from '../../../../../../../constants';

context(
'Insurance - submit an application - Multiple policy type with a broker - based in UK - Building as a name - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application',
'Insurance - submit an application - Multiple policy type with a broker - Based in UK - Building as a name - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application',
() => {
let referenceNumber;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { APPLICATION, VALID_POSTCODES } from '../../../../../../../constants';

context(
'Insurance - submit an application - Multiple policy type with a broker - based in UK - Building as a number - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application',
'Insurance - submit an application - Multiple policy type with a broker - Based in UK - Building as a number - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application',
() => {
let referenceNumber;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
context(
'Insurance - submit an application - Single policy type with a broker - based in UK - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application',
'Insurance - submit an application - Single policy type with a broker - Based in UK - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application',
() => {
let referenceNumber;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
context(
'Insurance - submit an application - Single policy type with a broker - not based in UK - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application',
'Insurance - submit an application - Single policy type with a broker - Not based in UK - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application',
() => {
let referenceNumber;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BUILDING_NAMES, VALID_POSTCODES } from '../../../../../../../constants';

context(
'Insurance - submit an application - Single policy type with a broker - based in UK - Building as a name - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application',
'Insurance - submit an application - Single policy type with a broker - Based in UK - Building as a name - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application',
() => {
let referenceNumber;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { VALID_POSTCODES } from '../../../../../../../constants';

context(
'Insurance - submit an application - Single policy type with a broker - based in UK - Building as a number - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application',
'Insurance - submit an application - Single policy type with a broker - Based in UK - Building as a number - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application',
() => {
let referenceNumber;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,17 @@ context('Insurance - Change your answers - Policy - Broker - No to yes - As an e
summaryList.field(FIELD_ID).changeLink().click();

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

cy.assertChangeAnswersPageUrl({ referenceNumber, route: TYPE_OF_POLICY, fieldId: FIELD_ID });
});

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

// TODO: EMS-3975
// checkSummaryList.BROKER[FULL_ADDRESS]();
// checkSummaryList.BROKER[FULL_ADDRESS]({});

checkSummaryList.BROKER[EMAIL]();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const {

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

context('Insurance - Check your answers - Policy - Multiple contract policy - Broker - based in UK - Summary List', () => {
context('Insurance - Check your answers - Policy - Multiple contract policy - Broker - Based in UK - Summary List', () => {
let url;
let referenceNumber;

Expand Down Expand Up @@ -54,11 +54,11 @@ context('Insurance - Check your answers - Policy - Multiple contract policy - Br
});

it(`should render a ${NAME} summary list row`, () => {
checkSummaryList.BROKER[NAME]({});
checkSummaryList.BROKER[NAME]();
});

it(`should render a ${SELECT_THE_ADDRESS} summary list row`, () => {
checkSummaryList.BROKER[SELECT_THE_ADDRESS]();
checkSummaryList.BROKER[SELECT_THE_ADDRESS]({});
});

it(`should render a ${EMAIL} summary list row`, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const {

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

context('Insurance - Check your answers - Policy - Multiple contract policy - Broker - not based in UK - Summary List', () => {
context('Insurance - Check your answers - Policy - Multiple contract policy - Broker - Not based in UK - Summary List', () => {
let url;
let referenceNumber;

Expand Down Expand Up @@ -44,6 +44,6 @@ context('Insurance - Check your answers - Policy - Multiple contract policy - Br
});

it(`should render a ${FULL_ADDRESS} summary list row`, () => {
checkSummaryList.BROKER[FULL_ADDRESS]();
checkSummaryList.BROKER[FULL_ADDRESS]({});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const {

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

context('Insurance - Check your answers - Policy - Single contract policy - Broker - not based in UK - Summary List', () => {
context('Insurance - Check your answers - Policy - Single contract policy - Broker - Not based in UK - Summary List', () => {
let url;
let referenceNumber;

Expand Down Expand Up @@ -54,11 +54,11 @@ context('Insurance - Check your answers - Policy - Single contract policy - Brok
});

it(`should render a ${NAME} summary list row`, () => {
checkSummaryList.BROKER[NAME]({});
checkSummaryList.BROKER[NAME]();
});

it(`should render a ${SELECT_THE_ADDRESS} summary list row`, () => {
checkSummaryList.BROKER[SELECT_THE_ADDRESS]();
checkSummaryList.BROKER[SELECT_THE_ADDRESS]({});
});

it(`should render a ${EMAIL} summary list row`, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const {

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

context('Insurance - Check your answers - Policy - Single contract policy - Broker - not based in UK - Summary List', () => {
context('Insurance - Check your answers - Policy - Single contract policy - Broker - Not based in UK - Summary List', () => {
let url;
let referenceNumber;

Expand Down Expand Up @@ -54,11 +54,11 @@ context('Insurance - Check your answers - Policy - Single contract policy - Brok
});

it(`should render a ${NAME} summary list row`, () => {
checkSummaryList.BROKER[NAME]({});
checkSummaryList.BROKER[NAME]();
});

it(`should render a ${FULL_ADDRESS} summary list row`, () => {
checkSummaryList.BROKER[FULL_ADDRESS]();
checkSummaryList.BROKER[FULL_ADDRESS]({});
});

it(`should render a ${EMAIL} summary list row`, () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
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_CONFIRM_ADDRESS_CHANGE, CHECK_YOUR_ANSWERS },
} = INSURANCE_ROUTES;

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

context(
'Insurance - Policy - Change your answers - Broker address - Based in UK to Not based in UK - 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('when clicking the `change` link', () => {
it(`should redirect to ${BROKER_CONFIRM_ADDRESS_CHANGE}`, () => {
cy.navigateToUrl(checkYourAnswersUrl);

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

cy.assertChangeAnswersPageUrl({ referenceNumber, route: BROKER_CONFIRM_ADDRESS_CHANGE, fieldId: SELECT_THE_ADDRESS });
});
});

describe('after changing the answer from no to yes and completing (now required) non UK broker address field', () => {
beforeEach(() => {
cy.navigateToUrl(checkYourAnswersUrl);
});

it(`should redirect to ${CHECK_YOUR_ANSWERS}`, () => {
summaryList.field(NAME).changeLink().click();

cy.completeAndSubmitBrokerDetailsForm({ isBasedInUk: false });
cy.completeAndSubmitBrokerManualAddressForm({});

cy.assertChangeAnswersPageUrl({ referenceNumber, route: CHECK_YOUR_ANSWERS, fieldId: NAME });
});

it(`should render the new ${FULL_ADDRESS} answer and related fields`, () => {
checkSummaryList[USING_BROKER]({ usingBroker: true });
checkSummaryList.BROKER[NAME]();
checkSummaryList.BROKER[EMAIL]();

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

it(`should NOT render ${SELECT_THE_ADDRESS} field`, () => {
checkSummaryList.BROKER[SELECT_THE_ADDRESS]({ shouldRender: false });
});
});
},
);
Loading

0 comments on commit 08883af

Please sign in to comment.