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

fix(EMS-3439): no PDF - Eligibility - Check your answers - Special characters #2632

Merged
merged 5 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { format } from 'date-fns';
import { summaryList } from '../../pages/shared';
import { COMPANIES_HOUSE_NUMBER, DATE_FORMAT } from '../../constants';
import { COMPANIES_HOUSE_NUMBER, COMPANIES_HOUSE_NUMBER_SPECIAL_CHARACTERS_NAME, DATE_FORMAT } from '../../constants';
import { INSURANCE_FIELD_IDS } from '../../constants/field-ids/insurance';
import { FIELDS } from '../../content-strings';
import mockCompanies from '../../fixtures/companies';
Expand All @@ -23,10 +23,14 @@ const assertCompaniesHouseSummaryList = {

cy.checkText(summaryList.field(COMPANY_NUMBER).value(), mockCompany[COMPANY_NUMBER]);
},
name: () => {
name: ({ differentCompanyWithSpecialCharacters = false }) => {
cy.checkText(summaryList.field(COMPANY_NAME).key(), FIELDS[COMPANY_NAME].SUMMARY.TITLE);

cy.checkText(summaryList.field(COMPANY_NAME).value(), mockCompany[COMPANY_NAME]);
if (differentCompanyWithSpecialCharacters) {
cy.checkText(summaryList.field(COMPANY_NAME).value(), mockCompanies[COMPANIES_HOUSE_NUMBER_SPECIAL_CHARACTERS_NAME][COMPANY_NAME]);
} else {
cy.checkText(summaryList.field(COMPANY_NAME).value(), mockCompany[COMPANY_NAME]);
}
},
address: () => {
cy.checkText(summaryList.field(COMPANY_ADDRESS).key(), FIELDS[COMPANY_ADDRESS].SUMMARY.TITLE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { FIELD_IDS, FIELD_VALUES } from '../../constants';
import { FIELD_IDS, FIELD_VALUES, COMPANIES_HOUSE_NUMBER_SPECIAL_CHARACTERS_NAME } from '../../constants';
import { summaryList } from '../../pages/shared';
import { FIELDS_ELIGIBILITY as FIELDS } from '../../content-strings/fields/insurance/eligibility';
import application, { country } from '../../fixtures/application';
import getSummaryListField from './get-summary-list-field';
import mockCompanies from '../../fixtures/companies';

const { COMPANY } = application;

Expand All @@ -19,7 +20,7 @@ const {

const { COMPANY_NAME } = FIELD_IDS.INSURANCE.COMPANIES_HOUSE;

const checkYourAnswersEligibilitySummaryList = ({
const checkYourAnswersEligibilitySummaryList = {
[BUYER_COUNTRY]: () => {
const fieldId = BUYER_COUNTRY;

Expand Down Expand Up @@ -68,19 +69,28 @@ const checkYourAnswersEligibilitySummaryList = ({

cy.assertSummaryListRow(summaryList, fieldId, expectedKey, expectedValue, expectedChangeLinkText);
},
[COMPANY_NAME]: () => {
[COMPANY_NAME]: ({ differentCompanyWithSpecialCharacters = false }) => {
const fieldId = COMPANY_NAME;

const { expectedKey } = getSummaryListField(fieldId, FIELDS);
const expectedValue = COMPANY[COMPANY_NAME];

let expectedValue = COMPANY[COMPANY_NAME];

if (differentCompanyWithSpecialCharacters) {
expectedValue = mockCompanies[COMPANIES_HOUSE_NUMBER_SPECIAL_CHARACTERS_NAME][COMPANY_NAME];
}

cy.assertSummaryListRow(summaryList, fieldId, expectedKey, expectedValue);
},
[COMPANIES_HOUSE_NUMBER]: () => {
[COMPANIES_HOUSE_NUMBER]: ({ differentCompanyWithSpecialCharacters = false }) => {
const fieldId = COMPANIES_HOUSE_NUMBER;

const { expectedKey, expectedChangeLinkText } = getSummaryListField(fieldId, FIELDS);
const expectedValue = COMPANY[COMPANIES_HOUSE_NUMBER];
let expectedValue = COMPANY[COMPANIES_HOUSE_NUMBER];

if (differentCompanyWithSpecialCharacters) {
expectedValue = mockCompanies[COMPANIES_HOUSE_NUMBER_SPECIAL_CHARACTERS_NAME][COMPANIES_HOUSE_NUMBER];
}

cy.assertSummaryListRow(summaryList, fieldId, expectedKey, expectedValue, expectedChangeLinkText);
},
Expand All @@ -92,6 +102,6 @@ const checkYourAnswersEligibilitySummaryList = ({

cy.assertSummaryListRow(summaryList, fieldId, expectedKey, expectedValue, expectedChangeLinkText);
},
});
};

export default checkYourAnswersEligibilitySummaryList;
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import completeAndSubmitBuyerCountryForm from '../forms';
import { COMPANIES_HOUSE_NUMBER } from '../../constants/examples';

/**
* completeAndSubmitAllInsuranceEligibilityAnswers
* completes and submits insurance eligibility answers until the check your answers page
* @param {String} companyNumber: companies house number - defaults to COMPANIES_HOUSE_NUMBER
*/
const completeAndSubmitAllInsuranceEligibilityAnswers = () => {
const completeAndSubmitAllInsuranceEligibilityAnswers = ({ companyNumber = COMPANIES_HOUSE_NUMBER }) => {
Zainzzkk marked this conversation as resolved.
Show resolved Hide resolved
cy.completeStartForm();
cy.completeCheckIfEligibleForm();
cy.completeExporterLocationForm();
cy.completeCompaniesHouseNumberForm();
cy.completeAndSubmitCompaniesHouseSearchForm({});
cy.completeAndSubmitCompaniesHouseSearchForm({ companyNumber });
cy.completeEligibilityCompanyDetailsForm();
completeAndSubmitBuyerCountryForm({});
cy.completeAndSubmitTotalValueInsuredForm({});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const COMPANIES_HOUSE_NUMBER = '08989898';
export const COMPANIES_HOUSE_NUMBER_SPECIAL_CHARACTERS_NAME = '00947741';
export const COMPANIES_HOUSE_NUMBER_NO_LEADING_ZERO = '8989898';
export const COMPANIES_HOUSE_NUMBER_WITH_SPACES = ' 08989898 ';
export const COMPANIES_HOUSE_NUMBER_MULTIPLE_SIC_CODES = '01003142';
Expand Down
14 changes: 8 additions & 6 deletions e2e-tests/fixtures/companies.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
COMPANIES_HOUSE_NUMBER,
COMPANIES_HOUSE_NUMBER_SPECIAL_CHARACTERS_NAME,
COMPANIES_HOUSE_NUMBER_NO_SIC_CODE,
COMPANIES_HOUSE_NUMBER_MULTIPLE_SIC_CODES,
COMPANIES_HOUSE_NUMBER_NO_FINANCIAL_YEAR_END_DATE,
Expand Down Expand Up @@ -38,12 +39,18 @@ const baseCompany = {
[FINANCIAL_YEAR_END_DATE]: '2023-07-31T00:00:00.000Z',
};

const companyNameSpecialCharacter = {
[COMPANY_NUMBER]: COMPANIES_HOUSE_NUMBER_SPECIAL_CHARACTERS_NAME,
[COMPANY_NAME]: 'STEVENS, FOX & CO. LIMITED',
};

const mockCompanies = {
[COMPANIES_HOUSE_NUMBER]: {
...baseCompany,
companyNumber: COMPANIES_HOUSE_NUMBER,
[FINANCIAL_YEAR_END_DATE]: baseCompany[FINANCIAL_YEAR_END_DATE],
},
[COMPANIES_HOUSE_NUMBER_SPECIAL_CHARACTERS_NAME]: companyNameSpecialCharacter,
[COMPANIES_HOUSE_NUMBER_NO_SIC_CODE]: {
...baseCompany,
companyNumber: COMPANIES_HOUSE_NUMBER_NO_SIC_CODE,
Expand All @@ -54,12 +61,7 @@ const mockCompanies = {
...baseCompany,
companyNumber: COMPANIES_HOUSE_NUMBER_MULTIPLE_SIC_CODES,
[FINANCIAL_YEAR_END_DATE]: baseCompany[FINANCIAL_YEAR_END_DATE],
sicCodes: [
mockSicCodes[1].code,
mockSicCodes[2].code,
mockSicCodes[3].code,
mockSicCodes[4].code,
],
sicCodes: [mockSicCodes[1].code, mockSicCodes[2].code, mockSicCodes[3].code, mockSicCodes[4].code],
industrySectorNames: [
mockSicCodes[1][INDUSTRY_SECTOR_NAME],
mockSicCodes[2][INDUSTRY_SECTOR_NAME],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,66 +16,69 @@ const oldCountry = country.NAME;
const newCountry = XAD.NAME;
const baseUrl = Cypress.config('baseUrl');

context('Insurance - Eligibility - Change your answers - Buyer country - As an exporter, I want to change my answers to the eligibility buyer country section', () => {
const url = `${baseUrl}${CHECK_YOUR_ANSWERS}`;
context(
'Insurance - Eligibility - Change your answers - Buyer country - As an exporter, I want to change my answers to the eligibility buyer country section',
() => {
const url = `${baseUrl}${CHECK_YOUR_ANSWERS}`;

before(() => {
cy.navigateToUrl(START);
before(() => {
cy.navigateToUrl(START);

cy.completeAndSubmitAllInsuranceEligibilityAnswers();
cy.completeAndSubmitAllInsuranceEligibilityAnswers({});

cy.assertUrl(url);
});
cy.assertUrl(url);
});

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

const fieldId = BUYER_COUNTRY;
const fieldId = BUYER_COUNTRY;

describe('when clicking the `change` link', () => {
it(`should redirect to ${BUYER_COUNTRY_CHANGE}`, () => {
cy.navigateToUrl(url);
describe('when clicking the `change` link', () => {
it(`should redirect to ${BUYER_COUNTRY_CHANGE}`, () => {
cy.navigateToUrl(url);

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

cy.assertChangeAnswersPageUrl({ route: BUYER_COUNTRY_CHANGE, fieldId, isInsuranceEligibility: true });
cy.assertChangeAnswersPageUrl({ route: BUYER_COUNTRY_CHANGE, fieldId, isInsuranceEligibility: true });
});
});
});

describe('form submission without changing the answer', () => {
beforeEach(() => {
cy.navigateToUrl(url);
describe('form submission without changing the answer', () => {
beforeEach(() => {
cy.navigateToUrl(url);

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

cy.clickSubmitButton();
});
cy.clickSubmitButton();
});

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

it('should render the same answer', () => {
cy.assertSummaryListRowValue(summaryList, fieldId, oldCountry);
it('should render the same answer', () => {
cy.assertSummaryListRowValue(summaryList, fieldId, oldCountry);
});
});
});

describe('form submission with a new answer', () => {
beforeEach(() => {
cy.navigateToUrl(url);
describe('form submission with a new answer', () => {
beforeEach(() => {
cy.navigateToUrl(url);

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

completeAndSubmitBuyerCountryForm({ countryName: newCountry });
});
completeAndSubmitBuyerCountryForm({ countryName: newCountry });
});

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

it('should render the new answer', () => {
cy.assertSummaryListRowValue(summaryList, fieldId, newCountry);
it('should render the new answer', () => {
cy.assertSummaryListRowValue(summaryList, fieldId, newCountry);
});
});
});
});
},
);
Loading
Loading