Skip to content

Commit

Permalink
feat(EMS-3063): no PDF - Your business - Turnover - Dynamic legend (#…
Browse files Browse the repository at this point in the history
…2467)

* feat(EMS-3063): made turnover legend dynamic with currency

* feat(EMS-3063): lint fix

* feat(EMS-3063): lint fix

* feat(EMS-3063): code and test improvements

* feat(EMS-3063): lint fix

* feat(EMS-3063): lint fix

---------

Co-authored-by: Zain Kassam <zkassam@ukexportfinance.gov.uk>
  • Loading branch information
Zainzzkk and Zain Kassam authored May 23, 2024
1 parent 5ef28f1 commit 2ef84f3
Show file tree
Hide file tree
Showing 15 changed files with 192 additions and 172 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* assertCopyWithCurrencyName
* Assert a selector with a currency name and optional question mark
* @param {String} pageTitle: Page title
* @param {String} currencyName: Currency name
* @param {String} currencyName: Currency name
* @param {Function} selector: Cypress selector
* @param {Boolean} withQuestionMark: Add a question mark to the expected text.
*/
const assertCopyWithCurrencyName = ({
pageTitle, currencyName, selector, withQuestionMark = false,
}) => {
let expected = `${pageTitle} ${currencyName}`;

if (withQuestionMark) {
expected += '?';
}

cy.checkText(selector, expected);
};

export default assertCopyWithCurrencyName;

This file was deleted.

2 changes: 1 addition & 1 deletion e2e-tests/commands/shared-commands/assertions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Cypress.Commands.add('assertLength', require('./assert-length'));
Cypress.Commands.add('assertErrorSummaryListLength', require('./assert-error-summary-list-length'));
Cypress.Commands.add('assertErrorSummaryListDoesNotExist', require('./assert-error-summary-list-does-not-exist'));

Cypress.Commands.add('assertHeadingWithCurrencyName', require('./assert-heading-with-currency-name'));
Cypress.Commands.add('assertCopyWithCurrencyName', require('./assert-copy-with-currency-name'));
Cypress.Commands.add('assertPrefix', require('./assert-prefix'));
Cypress.Commands.add('assertSuffix', require('./assert-suffix'));
Cypress.Commands.add('assertTextareaRendering', require('./assert-textarea-rendering'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const EXPORTER_BUSINESS_FIELDS = {
},
},
[ESTIMATED_ANNUAL_TURNOVER]: {
LEGEND: 'Estimated annual turnover for this current financial year',
LEGEND: 'Estimated annual turnover for this current financial year in',
PREFIX: SYMBOLS.GBP,
SUMMARY: {
TITLE: 'Estimated turnover this current financial year',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { field } from '../../../../../../../pages/shared';
import { field, heading } from '../../../../../../../pages/shared';
import { FIELD_VALUES } from '../../../../../../../constants';
import { PAGES } from '../../../../../../../content-strings';
import { POLICY as POLICY_FIELD_IDS } from '../../../../../../../constants/field-ids/insurance/policy';
Expand All @@ -10,22 +10,18 @@ const CONTENT_STRINGS = PAGES.INSURANCE.POLICY.MULTIPLE_CONTRACT_POLICY_EXPORT_V

const {
ROOT: INSURANCE_ROOT,
POLICY: {
MULTIPLE_CONTRACT_POLICY_EXPORT_VALUE,
MULTIPLE_CONTRACT_POLICY,
},
POLICY: { MULTIPLE_CONTRACT_POLICY_EXPORT_VALUE, MULTIPLE_CONTRACT_POLICY },
} = INSURANCE_ROUTES;

const {
EXPORT_VALUE: {
MULTIPLE: {
TOTAL_SALES_TO_BUYER,
MAXIMUM_BUYER_WILL_OWE,
},
MULTIPLE: { TOTAL_SALES_TO_BUYER, MAXIMUM_BUYER_WILL_OWE },
},
} = POLICY_FIELD_IDS;

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

const policyType = FIELD_VALUES.POLICY_TYPE.MULTIPLE;

Expand Down Expand Up @@ -69,9 +65,10 @@ context('Insurance - Policy - Multiple contract policy - Export value page - Alt
});

it('should render a heading with the alternative currency', () => {
cy.assertHeadingWithCurrencyName({
cy.assertCopyWithCurrencyName({
pageTitle: CONTENT_STRINGS.PAGE_TITLE,
currencyName: NON_STANDARD_CURRENCY_NAME,
selector: heading(),
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { field } from '../../../../../../../pages/shared';
import { field, heading } from '../../../../../../../pages/shared';
import { FIELD_VALUES } from '../../../../../../../constants';
import { PAGES } from '../../../../../../../content-strings';
import { POLICY as POLICY_FIELD_IDS } from '../../../../../../../constants/field-ids/insurance/policy';
Expand All @@ -10,22 +10,18 @@ const CONTENT_STRINGS = PAGES.INSURANCE.POLICY.MULTIPLE_CONTRACT_POLICY_EXPORT_V

const {
ROOT: INSURANCE_ROOT,
POLICY: {
MULTIPLE_CONTRACT_POLICY_EXPORT_VALUE,
MULTIPLE_CONTRACT_POLICY,
},
POLICY: { MULTIPLE_CONTRACT_POLICY_EXPORT_VALUE, MULTIPLE_CONTRACT_POLICY },
} = INSURANCE_ROUTES;

const {
EXPORT_VALUE: {
MULTIPLE: {
TOTAL_SALES_TO_BUYER,
MAXIMUM_BUYER_WILL_OWE,
},
MULTIPLE: { TOTAL_SALES_TO_BUYER, MAXIMUM_BUYER_WILL_OWE },
},
} = POLICY_FIELD_IDS;

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

const policyType = FIELD_VALUES.POLICY_TYPE.MULTIPLE;

Expand Down Expand Up @@ -68,9 +64,10 @@ context('Insurance - Policy - Multiple contract policy - Export value page - Non
});

it('should render a heading with the non-GBP currency', () => {
cy.assertHeadingWithCurrencyName({
cy.assertCopyWithCurrencyName({
pageTitle: CONTENT_STRINGS.PAGE_TITLE,
currencyName: USD.name,
selector: heading(),
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { field } from '../../../../../../../pages/shared';
import { field, heading } from '../../../../../../../pages/shared';
import { PAGES } from '../../../../../../../content-strings';
import { INSURANCE_ROUTES } from '../../../../../../../constants/routes/insurance';
import { POLICY as POLICY_FIELD_IDS } from '../../../../../../../constants/field-ids/insurance/policy';
Expand All @@ -18,7 +18,9 @@ const {
},
} = POLICY_FIELD_IDS;

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

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

Expand Down Expand Up @@ -59,9 +61,10 @@ context('Insurance - Policy - Single contract policy - Total contract value page
});

it('should render a heading with the alternative currency', () => {
cy.assertHeadingWithCurrencyName({
cy.assertCopyWithCurrencyName({
pageTitle: CONTENT_STRINGS.PAGE_TITLE,
currencyName: NON_STANDARD_CURRENCY_NAME,
selector: heading(),
withQuestionMark: true,
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { field } from '../../../../../../../pages/shared';
import { field, heading } from '../../../../../../../pages/shared';
import { PAGES } from '../../../../../../../content-strings';
import { INSURANCE_ROUTES } from '../../../../../../../constants/routes/insurance';
import { POLICY as POLICY_FIELD_IDS } from '../../../../../../../constants/field-ids/insurance/policy';
Expand All @@ -18,7 +18,9 @@ const {
},
} = POLICY_FIELD_IDS;

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

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

Expand Down Expand Up @@ -58,9 +60,10 @@ context('Insurance - Policy - Single contract policy - Total contract value page
});

it('should render a heading with the non-GBP currency', () => {
cy.assertHeadingWithCurrencyName({
cy.assertCopyWithCurrencyName({
pageTitle: CONTENT_STRINGS.PAGE_TITLE,
currencyName: USD.name,
selector: heading(),
withQuestionMark: true,
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
import { field, summaryList } from '../../../../../../pages/shared';
import { field as fieldSelector, summaryList } from '../../../../../../pages/shared';
import { GBP_CURRENCY_CODE } from '../../../../../../constants';
import { NON_STANDARD_CURRENCY_CODE } from '../../../../../../fixtures/currencies';
import { NON_STANDARD_CURRENCY_CODE, NON_STANDARD_CURRENCY_NAME } from '../../../../../../fixtures/currencies';
import { INSURANCE_FIELD_IDS } from '../../../../../../constants/field-ids/insurance';
import { EXPORTER_BUSINESS_FIELDS as FIELDS } from '../../../../../../content-strings/fields/insurance/business';
import { INSURANCE_ROUTES } from '../../../../../../constants/routes/insurance';
import formatCurrency from '../../../../../../helpers/format-currency';

const {
TURNOVER: {
ESTIMATED_ANNUAL_TURNOVER,
PERCENTAGE_TURNOVER,
},
TURNOVER: { ESTIMATED_ANNUAL_TURNOVER, PERCENTAGE_TURNOVER },
} = INSURANCE_FIELD_IDS.EXPORTER_BUSINESS;

const {
ROOT,
EXPORTER_BUSINESS: {
TURNOVER_CHANGE,
CHECK_YOUR_ANSWERS,
},
EXPORTER_BUSINESS: { TURNOVER_CHANGE, CHECK_YOUR_ANSWERS },
} = INSURANCE_ROUTES;

const baseUrl = Cypress.config('baseUrl');
Expand Down Expand Up @@ -70,7 +65,7 @@ context('Insurance - Your business - Change your answers - Turnover - As an expo

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

cy.keyboardInput(field(fieldId).input(), newAnswer);
cy.keyboardInput(fieldSelector(fieldId).input(), newAnswer);

cy.clickSubmitButton();
});
Expand Down Expand Up @@ -123,6 +118,19 @@ context('Insurance - Your business - Change your answers - Turnover - As an expo

cy.assertSummaryListRowValue(summaryList, fieldId, expectedValue);
});

it('should render the turnover legend with the alternative currency on the turnover page', () => {
summaryList.field(fieldId).changeLink().click();

const field = fieldSelector(ESTIMATED_ANNUAL_TURNOVER);

cy.assertCopyWithCurrencyName({
pageTitle: FIELDS.TURNOVER[ESTIMATED_ANNUAL_TURNOVER].LEGEND,
currencyName: NON_STANDARD_CURRENCY_NAME,
selector: field.legend(),
withQuestionMark: true,
});
});
});
});

Expand All @@ -147,7 +155,7 @@ context('Insurance - Your business - Change your answers - Turnover - As an expo

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

cy.keyboardInput(field(fieldId).input(), newAnswer);
cy.keyboardInput(fieldSelector(fieldId).input(), newAnswer);

cy.clickSubmitButton();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { field as fieldSelector } from '../../../../../../pages/shared';
import { INSURANCE_ROUTES } from '../../../../../../constants/routes/insurance';
import { EXPORTER_BUSINESS as FIELD_IDS } from '../../../../../../constants/field-ids/insurance/business';
import { EXPORTER_BUSINESS_FIELDS as FIELDS } from '../../../../../../content-strings/fields/insurance/business';
import { assertCurrencyFormFields } from '../../../../../../shared-test-assertions';
import { NON_STANDARD_CURRENCY_NAME } from '../../../../../../fixtures/currencies';

const {
TURNOVER: {
ESTIMATED_ANNUAL_TURNOVER,
},
TURNOVER: { ESTIMATED_ANNUAL_TURNOVER },
} = FIELD_IDS;

const {
ROOT,
EXPORTER_BUSINESS: {
TURNOVER_ROOT,
},
EXPORTER_BUSINESS: { TURNOVER_ROOT },
} = INSURANCE_ROUTES;

const baseUrl = Cypress.config('baseUrl');
Expand Down Expand Up @@ -50,4 +49,22 @@ context('Insurance - Your business - Turnover page - As an Exporter I want to ch

prefixAssertions();
});

describe('the currency should be included in the legend', () => {
beforeEach(() => {
// submit alternative currency form
cy.clickSubmitButton();
});

it('should render the turnover legend with the alternative currency', () => {
const field = fieldSelector(ESTIMATED_ANNUAL_TURNOVER);

cy.assertCopyWithCurrencyName({
pageTitle: FIELDS.TURNOVER[ESTIMATED_ANNUAL_TURNOVER].LEGEND,
currencyName: NON_STANDARD_CURRENCY_NAME,
selector: field.legend(),
withQuestionMark: true,
});
});
});
});
Loading

0 comments on commit 2ef84f3

Please sign in to comment.