Skip to content

Commit

Permalink
Merge branch 'main-iterations' into chore/EMS-3894
Browse files Browse the repository at this point in the history
  • Loading branch information
ttbarnes committed Oct 10, 2024
2 parents 2c7762e + e3fa1ae commit e7c3f8d
Show file tree
Hide file tree
Showing 24 changed files with 586 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { EXPORT_CONTRACT_FIELDS as FIELDS } from '../../content-strings/fields/i
import formatCurrency from '../../helpers/format-currency';
import application from '../../fixtures/application';
import COUNTRIES from '../../fixtures/countries';
import { GBP } from '../../fixtures/currencies';

const {
CURRENCY: { CURRENCY_CODE },
Expand Down Expand Up @@ -232,7 +233,7 @@ const checkExportContractSummaryList = {
if (shouldRender) {
const { expectedKey, expectedChangeLinkText } = getSummaryListField(summaryListFieldId, FIELDS.AGENT_CHARGES);

const expectedValue = application.EXPORT_CONTRACT.AGENT_CHARGES[FIXED_SUM_CURRENCY_CODE];
const expectedValue = GBP.name;

cy.assertSummaryListRow(summaryList, summaryListFieldId, expectedKey, expectedValue, expectedChangeLinkText);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { radios } from '../../pages/shared';
import { INSURANCE_FIELD_IDS } from '../../constants/field-ids/insurance';
import { NON_STANDARD_CURRENCY_CODE } from '../../fixtures/currencies';

const { CURRENCY_CODE } = INSURANCE_FIELD_IDS.CURRENCY;

Expand All @@ -18,7 +19,7 @@ const completeAndSubmitAlternativeCurrencyForm = ({ isoCode, alternativeCurrency
}

if (alternativeCurrency) {
cy.clickAlternativeCurrencyRadioAndSubmitCurrency({ currency: isoCode });
cy.clickAlternativeCurrencyRadioAndSubmitCurrency({ currency: NON_STANDARD_CURRENCY_CODE });
}

if (!isoCode && !alternativeCurrency) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import { summaryList } from '../../../../../../../../pages/shared';
import { INSURANCE_FIELD_IDS } from '../../../../../../../../constants/field-ids/insurance';
import { INSURANCE_ROUTES } from '../../../../../../../../constants/routes/insurance';
import application from '../../../../../../../../fixtures/application';
import { EUR, NON_STANDARD_CURRENCY_CODE, NON_STANDARD_CURRENCY_NAME, SYMBOLS } from '../../../../../../../../fixtures/currencies';
import formatCurrency from '../../../../../../../../helpers/format-currency';

const {
ROOT,
CHECK_YOUR_ANSWERS: { EXPORT_CONTRACT },
} = INSURANCE_ROUTES;

const {
CURRENCY: { CURRENCY_CODE },
EXPORT_CONTRACT: {
AGENT_CHARGES: { FIXED_SUM_AMOUNT },
},
} = INSURANCE_FIELD_IDS;

const currencyAssertion = {
row: summaryList.field(CURRENCY_CODE),
expected: '',
};

const amountAssertion = {
row: summaryList.field(FIXED_SUM_AMOUNT),
expected: '',
};

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

context(
'Insurance - Change your answers - Export contract - Summary list - Currency of agent charges - Alternative currency - As an exporter, I want to change my answers to the export contract section',
() => {
let referenceNumber;
let checkYourAnswersUrl;

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

cy.completePrepareApplicationSinglePolicyType({
referenceNumber,
isUsingAgent: true,
agentIsCharging: true,
agentChargeMethodFixedSum: true,
});

cy.clickTaskCheckAnswers();

// To get past previous "Check your answers" pages
cy.completeAndSubmitMultipleCheckYourAnswers({ count: 3 });

checkYourAnswersUrl = `${baseUrl}${ROOT}/${referenceNumber}${EXPORT_CONTRACT}`;

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

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

cy.navigateToUrl(checkYourAnswersUrl);
});

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

describe(`changing ${CURRENCY_CODE} to an alternative currency (${NON_STANDARD_CURRENCY_CODE})`, () => {
beforeEach(() => {
cy.navigateToUrl(checkYourAnswersUrl);

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

cy.completeAndSubmitAlternativeCurrencyForm({ alternativeCurrency: true });
});

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

it(`should render the new answer for ${CURRENCY_CODE} and ${FIXED_SUM_AMOUNT}`, () => {
currencyAssertion.expected = NON_STANDARD_CURRENCY_NAME;

cy.checkText(currencyAssertion.row.value(), currencyAssertion.expected);

amountAssertion.expected = formatCurrency(application.EXPORT_CONTRACT.AGENT_CHARGES[FIXED_SUM_AMOUNT], NON_STANDARD_CURRENCY_CODE);

cy.checkText(amountAssertion.row.value(), amountAssertion.expected);
});
});

describe(`changing ${CURRENCY_CODE} from an alternative currency to ${SYMBOLS.EUR}`, () => {
const currencyCode = EUR.isoCode;

beforeEach(() => {
cy.navigateToUrl(checkYourAnswersUrl);

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

cy.completeAndSubmitAlternativeCurrencyForm({ isoCode: currencyCode });
});

it(`should render the new answer for ${CURRENCY_CODE} and ${FIXED_SUM_AMOUNT}`, () => {
currencyAssertion.expected = EUR.name;

cy.checkText(currencyAssertion.row.value(), currencyAssertion.expected);

amountAssertion.expected = formatCurrency(application.EXPORT_CONTRACT.AGENT_CHARGES[FIXED_SUM_AMOUNT], currencyCode);

cy.checkText(amountAssertion.row.value(), amountAssertion.expected);
});
});
},
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { summaryList } from '../../../../../../../../pages/shared';
import { INSURANCE_FIELD_IDS } from '../../../../../../../../constants/field-ids/insurance';
import { INSURANCE_ROUTES } from '../../../../../../../../constants/routes/insurance';
import { USD } from '../../../../../../../../fixtures/currencies';

const {
ROOT,
CHECK_YOUR_ANSWERS: { EXPORT_CONTRACT },
EXPORT_CONTRACT: { AGENT_CHARGES_CURRENCY_CHECK_AND_CHANGE },
} = INSURANCE_ROUTES;

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

const getFieldVariables = (fieldId, referenceNumber) => ({
changeLink: summaryList.field(fieldId).changeLink,
checkYourAnswersRoute: EXPORT_CONTRACT,
fieldId,
newValueInput: '',
referenceNumber,
route: AGENT_CHARGES_CURRENCY_CHECK_AND_CHANGE,
summaryList,
});

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

context('Insurance - Change your answers - Export contract - Summary list - Currency of agent charges', () => {
let referenceNumber;
let url;

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

cy.completePrepareApplicationSinglePolicyType({
referenceNumber,
isUsingAgent: true,
agentIsCharging: true,
agentChargeMethodFixedSum: true,
});

cy.clickTaskCheckAnswers();

// To get past previous "Check your answers" pages
cy.completeAndSubmitMultipleCheckYourAnswers({ count: 3 });

url = `${baseUrl}${ROOT}/${referenceNumber}${EXPORT_CONTRACT}`;

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

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

cy.navigateToUrl(url);
});

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

describe(CURRENCY_CODE, () => {
const fieldId = CURRENCY_CODE;

const fieldVariables = {
...getFieldVariables(fieldId, referenceNumber),
newValueInput: USD.isoCode,
newValue: USD.name,
};

describe('when clicking the `change` link', () => {
beforeEach(() => {
cy.navigateToUrl(url);
});

it(`should redirect to ${AGENT_CHARGES_CURRENCY_CHECK_AND_CHANGE}`, () => {
cy.navigateToUrl(url);

cy.checkChangeLinkUrl(fieldVariables, referenceNumber);
});
});

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

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

cy.changeAnswerRadioField(fieldVariables);
});

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

it('should render the new answer', () => {
cy.checkChangeAnswerRendered({ fieldVariables });
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const NEW_COUNTRY_INPUT = XAD.NAME;
const baseUrl = Cypress.config('baseUrl');

context(
'Insurance - Export contract - Change your answers - About goods or services - As an exporter, I want to change my answers to the type of policy section',
'Insurance - Export contract - Change your answers - About goods or services - As an exporter, I want to change my answers to the export contract section',
() => {
let referenceNumber;
let checkYourAnswersUrl;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import { summaryList } from '../../../../../../../pages/shared';
import { INSURANCE_FIELD_IDS } from '../../../../../../../constants/field-ids/insurance';
import { INSURANCE_ROUTES } from '../../../../../../../constants/routes/insurance';
import application from '../../../../../../../fixtures/application';
import { EUR, NON_STANDARD_CURRENCY_CODE, NON_STANDARD_CURRENCY_NAME, SYMBOLS } from '../../../../../../../fixtures/currencies';
import formatCurrency from '../../../../../../../helpers/format-currency';

const {
ROOT,
EXPORT_CONTRACT: { CHECK_YOUR_ANSWERS },
} = INSURANCE_ROUTES;

const {
CURRENCY: { CURRENCY_CODE },
EXPORT_CONTRACT: {
AGENT_CHARGES: { FIXED_SUM_AMOUNT },
},
} = INSURANCE_FIELD_IDS;

const currencyAssertion = {
row: summaryList.field(CURRENCY_CODE),
expected: '',
};

const amountAssertion = {
row: summaryList.field(FIXED_SUM_AMOUNT),
expected: '',
};

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

context(
'Insurance - Export contract - Change your answers - Currency of agent charges - Alternative currency - As an exporter, I want to change my answers to the export contract section',
() => {
let referenceNumber;
let checkYourAnswersUrl;

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

cy.completeExportContractSection({
isUsingAgent: true,
agentIsCharging: true,
agentChargeMethodFixedSum: true,
});

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

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

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

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

describe(`changing ${CURRENCY_CODE} to an alternative currency (${NON_STANDARD_CURRENCY_CODE})`, () => {
beforeEach(() => {
cy.navigateToUrl(checkYourAnswersUrl);

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

cy.completeAndSubmitAlternativeCurrencyForm({ alternativeCurrency: true });
});

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

it(`should render the new answer for ${CURRENCY_CODE} and ${FIXED_SUM_AMOUNT}`, () => {
currencyAssertion.expected = NON_STANDARD_CURRENCY_NAME;

cy.checkText(currencyAssertion.row.value(), currencyAssertion.expected);

amountAssertion.expected = formatCurrency(application.EXPORT_CONTRACT.AGENT_CHARGES[FIXED_SUM_AMOUNT], NON_STANDARD_CURRENCY_CODE);

cy.checkText(amountAssertion.row.value(), amountAssertion.expected);
});
});

describe(`changing ${CURRENCY_CODE} from an alternative currency to ${SYMBOLS.EUR}`, () => {
const currencyCode = EUR.isoCode;

beforeEach(() => {
cy.navigateToUrl(checkYourAnswersUrl);

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

cy.completeAndSubmitAlternativeCurrencyForm({ isoCode: currencyCode });
});

it(`should render the new answer for ${CURRENCY_CODE} and ${FIXED_SUM_AMOUNT}`, () => {
currencyAssertion.expected = EUR.name;

cy.checkText(currencyAssertion.row.value(), currencyAssertion.expected);

amountAssertion.expected = formatCurrency(application.EXPORT_CONTRACT.AGENT_CHARGES[FIXED_SUM_AMOUNT], currencyCode);

cy.checkText(amountAssertion.row.value(), amountAssertion.expected);
});
});
},
);
Loading

0 comments on commit e7c3f8d

Please sign in to comment.