Skip to content

Commit

Permalink
style(EMS-3835-3836): export contract - check your answers - currency…
Browse files Browse the repository at this point in the history
… code (#3119)

* style(EMS-3835-3836): export contract - check your answers - fixed sum currency code

* style(EMS-3835-3836): export contract - check your answers - fixed sum currency code
  • Loading branch information
ttbarnes authored Sep 26, 2024
1 parent bdccbd2 commit e46af91
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 15 deletions.
13 changes: 13 additions & 0 deletions e2e-tests/commands/insurance/check-export-contract-summary-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,19 @@ const checkExportContractSummaryList = {
cy.assertSummaryListRowDoesNotExist(summaryList, fieldId);
}
},
[FIXED_SUM_CURRENCY_CODE]: ({ shouldRender = false }) => {
const fieldId = FIXED_SUM_CURRENCY_CODE;

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

const expectedValue = application.EXPORT_CONTRACT.AGENT_CHARGES[fieldId];

cy.assertSummaryListRow(summaryList, fieldId, expectedKey, expectedValue, expectedChangeLinkText);
} else {
cy.assertSummaryListRowDoesNotExist(summaryList, fieldId);
}
},
[FIXED_SUM_AMOUNT]: ({ shouldRender = false, agentChargeFixedSumAmount }) => {
const fieldId = FIXED_SUM_AMOUNT;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ export const EXPORT_CONTRACT_FIELDS = {
},
[CURRENCY_CODE]: {
LEGEND: 'What currency is the agent charging you in?',
SUMMARY: {
TITLE: "Currency of the agent's charge",
FORM_TITLE: EXPORT_CONTRACT_FORM_TITLES.AGENT,
},
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const {
USING_AGENT,
AGENT_DETAILS: { NAME, FULL_ADDRESS, COUNTRY_CODE },
AGENT_SERVICE: { IS_CHARGING, SERVICE_DESCRIPTION },
AGENT_CHARGES: { FIXED_SUM_AMOUNT, PERCENTAGE_CHARGE, PAYABLE_COUNTRY_CODE },
AGENT_CHARGES: { FIXED_SUM_AMOUNT, FIXED_SUM_CURRENCY_CODE, PERCENTAGE_CHARGE, PAYABLE_COUNTRY_CODE },
} = FIELD_IDS;

/**
Expand Down Expand Up @@ -68,6 +68,10 @@ const assertFullyPopulatedExportContractSummaryListRows = ({ agentChargeMethodFi
});

if (agentChargeMethodFixedSum) {
it(`should render a ${FIXED_SUM_CURRENCY_CODE} summary list row`, () => {
checkSummaryList[FIXED_SUM_CURRENCY_CODE]({ shouldRender: true });
});

it(`should render a ${FIXED_SUM_AMOUNT} summary list row`, () => {
checkSummaryList[FIXED_SUM_AMOUNT]({ shouldRender: true, agentChargeFixedSumAmount });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const {
USING_AGENT,
AGENT_DETAILS: { NAME, FULL_ADDRESS, COUNTRY_CODE },
AGENT_SERVICE: { IS_CHARGING, SERVICE_DESCRIPTION },
AGENT_CHARGES: { FIXED_SUM_AMOUNT, PERCENTAGE_CHARGE, PAYABLE_COUNTRY_CODE },
AGENT_CHARGES: { FIXED_SUM_AMOUNT, FIXED_SUM_CURRENCY_CODE, PERCENTAGE_CHARGE, PAYABLE_COUNTRY_CODE },
} = FIELD_IDS;

const { OPEN_TENDER } = FIELDS.HOW_WAS_THE_CONTRACT_AWARDED[AWARD_METHOD].OPTIONS;
Expand Down Expand Up @@ -72,6 +72,10 @@ const assertMinimalExportContractSummaryListRows = ({ awardMethodValue = OPEN_TE
checkSummaryList[IS_CHARGING]({ shouldRender: false });
});

it(`should NOT render a ${FIXED_SUM_CURRENCY_CODE} summary list row`, () => {
checkSummaryList[FIXED_SUM_CURRENCY_CODE]({ shouldRender: false });
});

it(`should NOT render a ${FIXED_SUM_AMOUNT} summary list row`, () => {
checkSummaryList[FIXED_SUM_AMOUNT]({ shouldRender: false });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ export const EXPORT_CONTRACT_FIELDS = {
},
[CURRENCY_CODE]: {
LEGEND: 'What currency is the agent charging you in?',
SUMMARY: {
TITLE: "Currency of the agent's charge",
FORM_TITLE: EXPORT_CONTRACT_FORM_TITLES.AGENT,
},
},
},
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import agentChargesFields from '.';
import { EXPORT_CONTRACT_FIELDS as FIELDS } from '../../../../../content-strings/fields/insurance';
import FIELD_IDS from '../../../../../constants/field-ids/insurance/export-contract';
import FIELD_IDS from '../../../../../constants/field-ids/insurance';
import { EXPORT_CONTRACT as EXPORT_CONTRACT_ROUTES } from '../../../../../constants/routes/insurance/export-contract';
import fieldGroupItem from '../../../generate-field-group-item';
import getFieldById from '../../../../get-field-by-id';
Expand All @@ -13,12 +13,21 @@ import { transformEmptyDecimalsToWholeNumber } from '../../../../number';
import { mockExportContractAgentService, mockCountries, referenceNumber } from '../../../../../test-mocks';

const {
AGENT_SERVICE: { IS_CHARGING },
AGENT_CHARGES: { FIXED_SUM_AMOUNT, FIXED_SUM_CURRENCY_CODE, PERCENTAGE_CHARGE, PAYABLE_COUNTRY_CODE },
CURRENCY: { CURRENCY_CODE },
EXPORT_CONTRACT: {
AGENT_SERVICE: { IS_CHARGING },
AGENT_CHARGES: { FIXED_SUM_AMOUNT, FIXED_SUM_CURRENCY_CODE, PERCENTAGE_CHARGE, PAYABLE_COUNTRY_CODE },
},
} = FIELD_IDS;

const { AGENT_SERVICE_CHANGE, AGENT_SERVICE_CHECK_AND_CHANGE } = EXPORT_CONTRACT_ROUTES;
const { AGENT_CHARGES_CHANGE, AGENT_CHARGES_CHECK_AND_CHANGE } = EXPORT_CONTRACT_ROUTES;
const {
AGENT_CHARGES_CURRENCY_CHANGE,
AGENT_CHARGES_CURRENCY_CHECK_AND_CHANGE,
AGENT_CHARGES_CHANGE,
AGENT_CHARGES_CHECK_AND_CHANGE,
AGENT_SERVICE_CHANGE,
AGENT_SERVICE_CHECK_AND_CHANGE,
} = EXPORT_CONTRACT_ROUTES;

describe('server/helpers/summary-lists/export-contract/agent-fields/agent-charges', () => {
const mockAnswersChargingTrue = {
Expand Down Expand Up @@ -78,6 +87,21 @@ describe('server/helpers/summary-lists/export-contract/agent-fields/agent-charge
},
mapYesNoField(mockAnswers[IS_CHARGING]),
),
fieldGroupItem(
{
field: getFieldById(FIELDS.AGENT_CHARGES, CURRENCY_CODE),
data: mockAnswers.charge,
href: generateChangeLink(
AGENT_CHARGES_CURRENCY_CHANGE,
AGENT_CHARGES_CURRENCY_CHECK_AND_CHANGE,
`#${FIXED_SUM_CURRENCY_CODE}-label`,
referenceNumber,
checkAndChange,
),
renderChangeLink: true,
},
mockAnswers.charge[FIXED_SUM_CURRENCY_CODE],
),
fieldGroupItem(
{
field: getFieldById(FIELDS.AGENT_CHARGES, FIXED_SUM_AMOUNT),
Expand Down Expand Up @@ -125,6 +149,21 @@ describe('server/helpers/summary-lists/export-contract/agent-fields/agent-charge
},
mapYesNoField(mockAnswers[IS_CHARGING]),
),
fieldGroupItem(
{
field: getFieldById(FIELDS.AGENT_CHARGES, CURRENCY_CODE),
data: mockAnswers.charge,
href: generateChangeLink(
AGENT_CHARGES_CURRENCY_CHANGE,
AGENT_CHARGES_CURRENCY_CHECK_AND_CHANGE,
`#${FIXED_SUM_CURRENCY_CODE}-label`,
referenceNumber,
checkAndChange,
),
renderChangeLink: true,
},
mockAnswers.charge[FIXED_SUM_CURRENCY_CODE],
),
fieldGroupItem(
{
field: getFieldById(FIELDS.AGENT_CHARGES, FIXED_SUM_AMOUNT),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EXPORT_CONTRACT_FIELDS as FIELDS } from '../../../../../content-strings/fields/insurance';
import FIELD_IDS from '../../../../../constants/field-ids/insurance/export-contract';
import FIELD_IDS from '../../../../../constants/field-ids/insurance';
import { EXPORT_CONTRACT as EXPORT_CONTRACT_ROUTES } from '../../../../../constants/routes/insurance/export-contract';
import fieldGroupItem from '../../../generate-field-group-item';
import getFieldById from '../../../../get-field-by-id';
Expand All @@ -12,12 +12,21 @@ import { transformEmptyDecimalsToWholeNumber, numberHasDecimalPlaces } from '../
import { ApplicationExportContractAgentService, Country } from '../../../../../../types';

const {
AGENT_SERVICE: { IS_CHARGING },
AGENT_CHARGES: { FIXED_SUM_AMOUNT, FIXED_SUM_CURRENCY_CODE, PERCENTAGE_CHARGE, PAYABLE_COUNTRY_CODE },
CURRENCY: { CURRENCY_CODE },
EXPORT_CONTRACT: {
AGENT_SERVICE: { IS_CHARGING },
AGENT_CHARGES: { FIXED_SUM_AMOUNT, FIXED_SUM_CURRENCY_CODE, PERCENTAGE_CHARGE, PAYABLE_COUNTRY_CODE },
},
} = FIELD_IDS;

const { AGENT_SERVICE_CHANGE, AGENT_SERVICE_CHECK_AND_CHANGE } = EXPORT_CONTRACT_ROUTES;
const { AGENT_CHARGES_CHANGE, AGENT_CHARGES_CHECK_AND_CHANGE } = EXPORT_CONTRACT_ROUTES;
const {
AGENT_CHARGES_CURRENCY_CHANGE,
AGENT_CHARGES_CURRENCY_CHECK_AND_CHANGE,
AGENT_CHARGES_CHANGE,
AGENT_CHARGES_CHECK_AND_CHANGE,
AGENT_SERVICE_CHANGE,
AGENT_SERVICE_CHECK_AND_CHANGE,
} = EXPORT_CONTRACT_ROUTES;

/**
* agentChargesFields
Expand All @@ -29,7 +38,7 @@ const { AGENT_CHARGES_CHANGE, AGENT_CHARGES_CHECK_AND_CHANGE } = EXPORT_CONTRACT
* @returns {Array<SummaryListItemData>} Agent charges fields
*/
const agentChargesFields = (answers: ApplicationExportContractAgentService, referenceNumber: number, countries: Array<Country>, checkAndChange?: boolean) => {
const fields = [
let fields = [
fieldGroupItem(
{
field: getFieldById(FIELDS.AGENT_SERVICE, IS_CHARGING),
Expand All @@ -54,7 +63,23 @@ const agentChargesFields = (answers: ApplicationExportContractAgentService, refe
*/
const decimalPlaces = numberHasDecimalPlaces(answer) ? 2 : 0;

fields.push(
fields = [
...fields,
fieldGroupItem(
{
field: getFieldById(FIELDS.AGENT_CHARGES, CURRENCY_CODE),
data: answers.charge,
href: generateChangeLink(
AGENT_CHARGES_CURRENCY_CHANGE,
AGENT_CHARGES_CURRENCY_CHECK_AND_CHANGE,
`#${FIXED_SUM_CURRENCY_CODE}-label`,
referenceNumber,
checkAndChange,
),
renderChangeLink: true,
},
answers.charge[FIXED_SUM_CURRENCY_CODE],
),
fieldGroupItem(
{
field: getFieldById(FIELDS.AGENT_CHARGES, FIXED_SUM_AMOUNT),
Expand All @@ -64,7 +89,7 @@ const agentChargesFields = (answers: ApplicationExportContractAgentService, refe
},
formatCurrency(Number(answer), answers.charge[FIXED_SUM_CURRENCY_CODE], decimalPlaces),
),
);
];
}

if (answers.charge[PERCENTAGE_CHARGE]) {
Expand Down

0 comments on commit e46af91

Please sign in to comment.