Skip to content

Commit

Permalink
feat(EMS-4054): improve e2e test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ttbarnes committed Jan 16, 2025
1 parent cfdb159 commit f585908
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { ORDNANCE_SURVEY_EXAMPLES } from './ordnance-survey-examples';

const { TREASURY } = ORDNANCE_SURVEY_EXAMPLES;
const { TREASURY, WESTMINSTER_BRIDGE_STREET } = ORDNANCE_SURVEY_EXAMPLES;

const { UNDERGROUND_STATION } = WESTMINSTER_BRIDGE_STREET;

export const EXPECTED_TREASURY_SINGLE_LINE_STRING = `${TREASURY.ADDRESS_LINE_1}${TREASURY.ADDRESS_LINE_2}${TREASURY.TOWN}${TREASURY.POSTCODE}`;
export const EXPECTED_TREASURY_MULTI_LINE_STRING = `${TREASURY.ADDRESS_LINE_1}\n${TREASURY.ADDRESS_LINE_2}\n${TREASURY.TOWN}\n${TREASURY.POSTCODE}`;

export const EXPECTED_UNDERGROUND_STATION_SINGLE_LINE_STRING = `${UNDERGROUND_STATION.ADDRESS_LINE_1}${UNDERGROUND_STATION.ADDRESS_LINE_2}${UNDERGROUND_STATION.TOWN}${UNDERGROUND_STATION.POSTCODE}`;
export const EXPECTED_UNDERGROUND_STATION_MULTI_LINE_STRING = `${UNDERGROUND_STATION.ADDRESS_LINE_1}\n${UNDERGROUND_STATION.ADDRESS_LINE_2}\n${UNDERGROUND_STATION.TOWN}\n${UNDERGROUND_STATION.POSTCODE}`;
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@ import { headingCaption } from '../../../../../../partials';
import { insetTextHtml, insetTextHtmlLineBreak } from '../../../../../../pages/shared';
import { brokerConfirmAddressPage } from '../../../../../../pages/insurance/policy';
import { BUTTONS, PAGES } from '../../../../../../content-strings';
import { EXPECTED_SINGLE_LINE_STRING } from '../../../../../../constants';
import {
ADDRESS_LOOKUP_INPUT_EXAMPLES,
EXPECTED_TREASURY_SINGLE_LINE_STRING,
EXPECTED_UNDERGROUND_STATION_SINGLE_LINE_STRING,
ORDNANCE_SURVEY_EXAMPLES,
} from '../../../../../../constants';
import { INSURANCE_ROUTES } from '../../../../../../constants/routes/insurance';
import { POLICY as POLICY_FIELD_IDS } from '../../../../../../constants/field-ids/insurance/policy';

const { TREASURY, WESTMINSTER_BRIDGE_STREET } = ADDRESS_LOOKUP_INPUT_EXAMPLES;
const { UNDERGROUND_STATION } = ORDNANCE_SURVEY_EXAMPLES.WESTMINSTER_BRIDGE_STREET;

const CONTENT_STRINGS = PAGES.INSURANCE.POLICY.BROKER_CONFIRM_ADDRESS;

const {
Expand All @@ -31,15 +39,19 @@ context(
cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => {
referenceNumber = refNumber;

// TODO: EMS-3981
// go to the page we want to test.
// cy.completeAndSubmitPolicyForms({ stopSubmittingAfter: 'brokerDetails', usingBroker: true });
cy.completeAndSubmitPolicyForms({
stopSubmittingAfter: 'brokerDetails',
usingBroker: true,
isBasedInUk: true,
postcode: TREASURY.POSTCODE,
buildingNumberOrName: TREASURY.BUILDING_NAME,
});

url = `${baseUrl}${ROOT}/${referenceNumber}${BROKER_CONFIRM_ADDRESS_ROOT}`;
lossPayeeUrl = `${baseUrl}${ROOT}/${referenceNumber}${LOSS_PAYEE_ROOT}`;
brokerDetailsUrl = `${baseUrl}${ROOT}/${referenceNumber}${BROKER_DETAILS_ROOT}`;

cy.navigateToUrl(url);
cy.assertUrl(url);
});
});
Expand All @@ -56,7 +68,7 @@ context(
cy.corePageChecks({
pageTitle: CONTENT_STRINGS.PAGE_TITLE,
currentHref: `${ROOT}/${referenceNumber}${BROKER_CONFIRM_ADDRESS_ROOT}`,
backLink: `${ROOT}/${referenceNumber}${BROKER_CONFIRM_ADDRESS_ROOT}#`,
backLink: `${ROOT}/${referenceNumber}${BROKER_DETAILS_ROOT}`,
submitButtonCopy: BUTTONS.USE_THIS_ADDRESS,
});
});
Expand All @@ -66,22 +78,53 @@ context(
cy.navigateToUrl(url);
});

it('renders a heading caption', () => {
it('should render a heading caption', () => {
cy.checkText(headingCaption(), CONTENT_STRINGS.HEADING_CAPTION);
});

// TODO: EMS-3981
it.skip(`renders ${FULL_ADDRESS} exactly as they were submitted, with line break elements`, () => {
describe('inset text', () => {
/**
* Cypress text assertion does not pick up HTML characters such as <br/>.
* NOTE: Cypress text assertion does not pick up HTML characters such as <br/>.
* Therefore, we have to assert the text without line breaks
* and instead, assert the line breaks separately.
* and instead, assert the line breaks separately via the following commands:
* cy.assertLength(insetTextHtmlLineBreak() expectedLineBreaks);
*/
cy.checkText(insetTextHtml(), EXPECTED_SINGLE_LINE_STRING);

const expectedLineBreaks = 3;
describe('when an address is entered manually', () => {
it(`should render ${FULL_ADDRESS} exactly as submitted, with line break elements`, () => {
cy.checkText(insetTextHtml(), EXPECTED_TREASURY_SINGLE_LINE_STRING);

const expectedLineBreaks = 4;

cy.assertLength(insetTextHtmlLineBreak(), expectedLineBreaks);
});
});

describe('when an address is obtained from Ordnance Survey', () => {
beforeEach(() => {
cy.navigateToUrl(url);

cy.assertLength(insetTextHtmlLineBreak(), expectedLineBreaks);
brokerConfirmAddressPage.useDifferentAddressLink().click();

cy.completeAndSubmitBrokerDetailsForm({
isBasedInUk: true,
postcode: WESTMINSTER_BRIDGE_STREET.POSTCODE,
buildingNumberOrName: WESTMINSTER_BRIDGE_STREET.BUILDING_NAME,
});

const optionValue = `${UNDERGROUND_STATION.ADDRESS_LINE_1} ${UNDERGROUND_STATION.ADDRESS_LINE_2}`;

cy.completeAndSubmitBrokerAddressesForm({ optionValue });
});

it('should render the address with line break elements', () => {
cy.checkText(insetTextHtml(), EXPECTED_UNDERGROUND_STATION_SINGLE_LINE_STRING);

const expectedLineBreaks = 4;

cy.assertLength(insetTextHtmlLineBreak(), expectedLineBreaks);
});
});
});

describe('`use a different address` link', () => {
Expand Down

0 comments on commit f585908

Please sign in to comment.