From e9151a9928d4ebdf0dfdc7f0f77924cac7f05a2a Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Sat, 14 Dec 2024 13:13:50 +0000 Subject: [PATCH 1/9] feat(EMS-4038): declarations - modern slavery - conditional radios --- .../field-ids/insurance/declarations/index.js | 5 +++ .../fields/insurance/declarations/index.js | 12 +++++++ src/api/.keystone/config.js | 19 +++++++++- .../field-ids/insurance/declarations/index.ts | 5 +++ .../fields/insurance/declarations/index.ts | 12 +++++++ .../field-ids/insurance/declarations/index.ts | 16 +++++++++ .../fields/insurance/declarations/index.ts | 12 +++++++ .../declarations/modern-slavery/index.test.ts | 15 +++++++- .../declarations/modern-slavery/index.ts | 15 +++++++- .../insurance/declarations/modern-slavery.njk | 35 +++---------------- .../insurance/code-of-conduct-hint.njk | 2 +- .../aware-of-existing-slavery.njk | 28 +++++++++++++++ .../cannot-adhere-to-all-requirements.njk | 28 +++++++++++++++ .../offenses-or-investigations.njk | 28 +++++++++++++++ .../has-no-offenses-or-investigations.njk | 16 +++++++++ .../is-not-aware-of-existing-slavery.njk | 16 +++++++++ .../will-adhere-to-all-requirements.njk | 16 +++++++++ 17 files changed, 246 insertions(+), 34 deletions(-) create mode 100644 src/ui/templates/partials/insurance/declarations/modern-slavery/conditional-reasons/aware-of-existing-slavery.njk create mode 100644 src/ui/templates/partials/insurance/declarations/modern-slavery/conditional-reasons/cannot-adhere-to-all-requirements.njk create mode 100644 src/ui/templates/partials/insurance/declarations/modern-slavery/conditional-reasons/offenses-or-investigations.njk create mode 100644 src/ui/templates/partials/insurance/declarations/modern-slavery/has-no-offenses-or-investigations.njk create mode 100644 src/ui/templates/partials/insurance/declarations/modern-slavery/is-not-aware-of-existing-slavery.njk create mode 100644 src/ui/templates/partials/insurance/declarations/modern-slavery/will-adhere-to-all-requirements.njk diff --git a/e2e-tests/constants/field-ids/insurance/declarations/index.js b/e2e-tests/constants/field-ids/insurance/declarations/index.js index d03cb2a9fa..5d2251cbd0 100644 --- a/e2e-tests/constants/field-ids/insurance/declarations/index.js +++ b/e2e-tests/constants/field-ids/insurance/declarations/index.js @@ -8,5 +8,10 @@ export const DECLARATIONS = { WILL_ADHERE_TO_ALL_REQUIREMENTS: 'willAdhereToAllRequirements', HAS_NO_OFFENSES_OR_INVESTIGATIONS: 'hasNoOffensesOrInvestigations', IS_NOT_AWARE_OF_EXISTING_SLAVERY: 'isNotAwareOfExistingSlavery', + CONDITIONAL_REASONS: { + CANNOT_ADHERE_TO_ALL_REQUIREMENTS: 'cannotAdhereToAllRequirements', + OFFENSES_OR_INVESTIGATIONS: 'offensesOrInvestigations', + AWARE_OF_EXISTING_SLAVERY: 'awareOfExistingSlavery', + }, }, }; diff --git a/e2e-tests/content-strings/fields/insurance/declarations/index.js b/e2e-tests/content-strings/fields/insurance/declarations/index.js index 56d7293996..6d28648bc7 100644 --- a/e2e-tests/content-strings/fields/insurance/declarations/index.js +++ b/e2e-tests/content-strings/fields/insurance/declarations/index.js @@ -12,6 +12,10 @@ export const DECLARATIONS_FIELDS = { VERSION: '1', LABEL: 'Do you adhere to, and intend to continue to adhere to, all requirements that apply to you as set out in the Modern Slavery Act 2015, including reporting obligations, and all applicable legislation relating to the prevention of modern slavery in every country that you operate in?', + CONDITIONAL_REASON: { + LABEL: + 'If you have a turnover of more than £36 million enter full details why you cannot. Include all information relating to the type of Modern Slavery that exists or has existed, and/or any investigation or enforcement action, and any actions taken by you in connection with this.', + }, }, ], }, @@ -21,6 +25,10 @@ export const DECLARATIONS_FIELDS = { VERSION: '1', LABEL: 'Do you confirm you are not currently under investigation and have not been fined, convicted or found guilty of any offences under the Modern Slavery Act 2015, or under any applicable similar laws or regulations relating to the prevention of modern slavery or any similar infringement of human rights in any jurisdiction?', + CONDITIONAL_REASON: { + LABEL: + 'Enter full details why you cannot. Include all information relating to the type of Modern Slavery that exists or has existed, and/or any investigation or enforcement action, and any actions taken by you in connection with this.', + }, }, ], }, @@ -30,6 +38,10 @@ export const DECLARATIONS_FIELDS = { VERSION: '1', LABEL: 'To the best of your knowledge, can you confirm you are not aware of the existence of Modern Slavery in respect of yourself, the export contract (s), your immediate holding company or your supply chain, in each case, at present or in the past 2 years.', + CONDITIONAL_REASON: { + LABEL: + 'Enter full details why you cannot. Include all information relating to the type of Modern Slavery that exists or has existed, and/or any investigation or enforcement action, and any actions taken by you in connection with this.', + }, }, ], }, diff --git a/src/api/.keystone/config.js b/src/api/.keystone/config.js index 39c8d541c7..46652e5d17 100644 --- a/src/api/.keystone/config.js +++ b/src/api/.keystone/config.js @@ -497,6 +497,11 @@ var DECLARATIONS = { WILL_ADHERE_TO_ALL_REQUIREMENTS: 'willAdhereToAllRequirements', HAS_NO_OFFENSES_OR_INVESTIGATIONS: 'hasNoOffensesOrInvestigations', IS_NOT_AWARE_OF_EXISTING_SLAVERY: 'isNotAwareOfExistingSlavery', + CONDITIONAL_REASONS: { + CANNOT_ADHERE_TO_ALL_REQUIREMENTS: 'cannotAdhereToAllRequirements', + OFFENSES_OR_INVESTIGATIONS: 'offensesOrInvestigations', + AWARE_OF_EXISTING_SLAVERY: 'awareOfExistingSlavery', + }, }, }; var declarations_default = DECLARATIONS; @@ -6335,6 +6340,10 @@ var DECLARATIONS_FIELDS = { VERSION: '1', LABEL: 'Do you adhere to, and intend to continue to adhere to, all requirements that apply to you as set out in the Modern Slavery Act 2015, including reporting obligations, and all applicable legislation relating to the prevention of modern slavery in every country that you operate in?', + CONDITIONAL_REASON: { + LABEL: + 'If you have a turnover of more than \xA336 million enter full details why you cannot. Include all information relating to the type of Modern Slavery that exists or has existed, and/or any investigation or enforcement action, and any actions taken by you in connection with this.', + }, }, ], }, @@ -6344,6 +6353,10 @@ var DECLARATIONS_FIELDS = { VERSION: '1', LABEL: 'Do you confirm you are not currently under investigation and have not been fined, convicted or found guilty of any offences under the Modern Slavery Act 2015, or under any applicable similar laws or regulations relating to the prevention of modern slavery or any similar infringement of human rights in any jurisdiction?', + CONDITIONAL_REASON: { + LABEL: + 'Enter full details why you cannot. Include all information relating to the type of Modern Slavery that exists or has existed, and/or any investigation or enforcement action, and any actions taken by you in connection with this.', + }, }, ], }, @@ -6352,7 +6365,11 @@ var DECLARATIONS_FIELDS = { { VERSION: '1', LABEL: - 'To the best of your knowledge, can you confirm you are not aware of the existence of Modern Slavery\xA0 in respect of yourself, the export contract (s), your immediate holding company or your supply chain, in each case, \xA0at present or in the past 2 years.', + 'To the best of your knowledge, can you confirm you are not aware of the existence of Modern Slavery in respect of yourself, the export contract (s), your immediate holding company or your supply chain, in each case, at present or in the past 2 years.', + CONDITIONAL_REASON: { + LABEL: + 'Enter full details why you cannot. Include all information relating to the type of Modern Slavery that exists or has existed, and/or any investigation or enforcement action, and any actions taken by you in connection with this.', + }, }, ], }, diff --git a/src/api/constants/field-ids/insurance/declarations/index.ts b/src/api/constants/field-ids/insurance/declarations/index.ts index 9d56656620..6bcb7626b3 100644 --- a/src/api/constants/field-ids/insurance/declarations/index.ts +++ b/src/api/constants/field-ids/insurance/declarations/index.ts @@ -8,6 +8,11 @@ const DECLARATIONS = { WILL_ADHERE_TO_ALL_REQUIREMENTS: 'willAdhereToAllRequirements', HAS_NO_OFFENSES_OR_INVESTIGATIONS: 'hasNoOffensesOrInvestigations', IS_NOT_AWARE_OF_EXISTING_SLAVERY: 'isNotAwareOfExistingSlavery', + CONDITIONAL_REASONS: { + CANNOT_ADHERE_TO_ALL_REQUIREMENTS: 'cannotAdhereToAllRequirements', + OFFENSES_OR_INVESTIGATIONS: 'offensesOrInvestigations', + AWARE_OF_EXISTING_SLAVERY: 'awareOfExistingSlavery', + }, }, }; diff --git a/src/api/content-strings/fields/insurance/declarations/index.ts b/src/api/content-strings/fields/insurance/declarations/index.ts index c684d360f9..7b9b087da6 100644 --- a/src/api/content-strings/fields/insurance/declarations/index.ts +++ b/src/api/content-strings/fields/insurance/declarations/index.ts @@ -39,6 +39,10 @@ export const DECLARATIONS_FIELDS = { VERSION: '1', LABEL: 'Do you adhere to, and intend to continue to adhere to, all requirements that apply to you as set out in the Modern Slavery Act 2015, including reporting obligations, and all applicable legislation relating to the prevention of modern slavery in every country that you operate in?', + CONDITIONAL_REASON: { + LABEL: + 'If you have a turnover of more than £36 million enter full details why you cannot. Include all information relating to the type of Modern Slavery that exists or has existed, and/or any investigation or enforcement action, and any actions taken by you in connection with this.', + }, }, ], }, @@ -48,6 +52,10 @@ export const DECLARATIONS_FIELDS = { VERSION: '1', LABEL: 'Do you confirm you are not currently under investigation and have not been fined, convicted or found guilty of any offences under the Modern Slavery Act 2015, or under any applicable similar laws or regulations relating to the prevention of modern slavery or any similar infringement of human rights in any jurisdiction?', + CONDITIONAL_REASON: { + LABEL: + 'Enter full details why you cannot. Include all information relating to the type of Modern Slavery that exists or has existed, and/or any investigation or enforcement action, and any actions taken by you in connection with this.', + }, }, ], }, @@ -57,6 +65,10 @@ export const DECLARATIONS_FIELDS = { VERSION: '1', LABEL: 'To the best of your knowledge, can you confirm you are not aware of the existence of Modern Slavery in respect of yourself, the export contract (s), your immediate holding company or your supply chain, in each case, at present or in the past 2 years.', + CONDITIONAL_REASON: { + LABEL: + 'Enter full details why you cannot. Include all information relating to the type of Modern Slavery that exists or has existed, and/or any investigation or enforcement action, and any actions taken by you in connection with this.', + }, }, ], }, diff --git a/src/ui/server/constants/field-ids/insurance/declarations/index.ts b/src/ui/server/constants/field-ids/insurance/declarations/index.ts index 9d56656620..e643bfa830 100644 --- a/src/ui/server/constants/field-ids/insurance/declarations/index.ts +++ b/src/ui/server/constants/field-ids/insurance/declarations/index.ts @@ -8,7 +8,23 @@ const DECLARATIONS = { WILL_ADHERE_TO_ALL_REQUIREMENTS: 'willAdhereToAllRequirements', HAS_NO_OFFENSES_OR_INVESTIGATIONS: 'hasNoOffensesOrInvestigations', IS_NOT_AWARE_OF_EXISTING_SLAVERY: 'isNotAwareOfExistingSlavery', + CONDITIONAL_REASONS: { + CANNOT_ADHERE_TO_ALL_REQUIREMENTS: 'cannotAdhereToAllRequirements', + OFFENSES_OR_INVESTIGATIONS: 'offensesOrInvestigations', + AWARE_OF_EXISTING_SLAVERY: 'awareOfExistingSlavery', + }, }, }; export default DECLARATIONS; + +// with declarationModernSlaveryReason being a new table + +// willAdhereToAllRequirements +// declarationModernSlaveryReason.cannotAdhereToAllRequirements + +// hasNoOffensesOrInvestigations +// declarationModernSlaveryReason.offensesOrInvestigations + +// isNotAwareOfExistingSlavery +// declarationModernSlaveryReason.awareOfExistingSlavery diff --git a/src/ui/server/content-strings/fields/insurance/declarations/index.ts b/src/ui/server/content-strings/fields/insurance/declarations/index.ts index 1347a0ba1a..0442052554 100644 --- a/src/ui/server/content-strings/fields/insurance/declarations/index.ts +++ b/src/ui/server/content-strings/fields/insurance/declarations/index.ts @@ -10,6 +10,10 @@ export const DECLARATIONS_FIELDS = { VERSION: '1', LABEL: 'Do you adhere to, and intend to continue to adhere to, all requirements that apply to you as set out in the Modern Slavery Act 2015, including reporting obligations, and all applicable legislation relating to the prevention of modern slavery in every country that you operate in?', + CONDITIONAL_REASON: { + LABEL: + 'If you have a turnover of more than £36 million enter full details why you cannot. Include all information relating to the type of Modern Slavery that exists or has existed, and/or any investigation or enforcement action, and any actions taken by you in connection with this.', + }, }, ], }, @@ -19,6 +23,10 @@ export const DECLARATIONS_FIELDS = { VERSION: '1', LABEL: 'Do you confirm you are not currently under investigation and have not been fined, convicted or found guilty of any offences under the Modern Slavery Act 2015, or under any applicable similar laws or regulations relating to the prevention of modern slavery or any similar infringement of human rights in any jurisdiction?', + CONDITIONAL_REASON: { + LABEL: + 'Enter full details why you cannot. Include all information relating to the type of Modern Slavery that exists or has existed, and/or any investigation or enforcement action, and any actions taken by you in connection with this.', + }, }, ], }, @@ -28,6 +36,10 @@ export const DECLARATIONS_FIELDS = { VERSION: '1', LABEL: 'To the best of your knowledge, can you confirm you are not aware of the existence of Modern Slavery in respect of yourself, the export contract (s), your immediate holding company or your supply chain, in each case, at present or in the past 2 years.', + CONDITIONAL_REASON: { + LABEL: + 'Enter full details why you cannot. Include all information relating to the type of Modern Slavery that exists or has existed, and/or any investigation or enforcement action, and any actions taken by you in connection with this.', + }, }, ], }, diff --git a/src/ui/server/controllers/insurance/declarations/modern-slavery/index.test.ts b/src/ui/server/controllers/insurance/declarations/modern-slavery/index.test.ts index 63e5857f68..8d67b70453 100644 --- a/src/ui/server/controllers/insurance/declarations/modern-slavery/index.test.ts +++ b/src/ui/server/controllers/insurance/declarations/modern-slavery/index.test.ts @@ -7,7 +7,8 @@ import getUserNameFromSession from '../../../../helpers/get-user-name-from-sessi import { Request, Response } from '../../../../../types'; import { mockReq, mockRes, referenceNumber } from '../../../../test-mocks'; -const { WILL_ADHERE_TO_ALL_REQUIREMENTS, HAS_NO_OFFENSES_OR_INVESTIGATIONS, IS_NOT_AWARE_OF_EXISTING_SLAVERY } = DECLARATIONS_FIELD_IDS.MODERN_SLAVERY; +const { WILL_ADHERE_TO_ALL_REQUIREMENTS, HAS_NO_OFFENSES_OR_INVESTIGATIONS, IS_NOT_AWARE_OF_EXISTING_SLAVERY, CONDITIONAL_REASONS } = + DECLARATIONS_FIELD_IDS.MODERN_SLAVERY; const { MODERN_SLAVERY } = DECLARATIONS.LATEST_DECLARATIONS; @@ -61,14 +62,26 @@ describe('controllers/insurance/declarations/modern-slavery', () => { WILL_ADHERE_TO_ALL_REQUIREMENTS: { ID: WILL_ADHERE_TO_ALL_REQUIREMENTS, ...MODERN_SLAVERY.WILL_ADHERE_TO_ALL_REQUIREMENTS, + CONDITIONAL_REASON: { + ID: CONDITIONAL_REASONS.CANNOT_ADHERE_TO_ALL_REQUIREMENTS, + ...MODERN_SLAVERY.WILL_ADHERE_TO_ALL_REQUIREMENTS.CONDITIONAL_REASON, + }, }, HAS_NO_OFFENSES_OR_INVESTIGATIONS: { ID: HAS_NO_OFFENSES_OR_INVESTIGATIONS, ...MODERN_SLAVERY.HAS_NO_OFFENSES_OR_INVESTIGATIONS, + CONDITIONAL_REASON: { + ID: CONDITIONAL_REASONS.OFFENSES_OR_INVESTIGATIONS, + ...MODERN_SLAVERY.HAS_NO_OFFENSES_OR_INVESTIGATIONS.CONDITIONAL_REASON, + }, }, IS_NOT_AWARE_OF_EXISTING_SLAVERY: { ID: IS_NOT_AWARE_OF_EXISTING_SLAVERY, ...MODERN_SLAVERY.IS_NOT_AWARE_OF_EXISTING_SLAVERY, + CONDITIONAL_REASON: { + ID: CONDITIONAL_REASONS.AWARE_OF_EXISTING_SLAVERY, + ...MODERN_SLAVERY.IS_NOT_AWARE_OF_EXISTING_SLAVERY.CONDITIONAL_REASON, + }, }, }, SAVE_AND_BACK_URL: `${INSURANCE_ROOT}/${referenceNumber}#`, diff --git a/src/ui/server/controllers/insurance/declarations/modern-slavery/index.ts b/src/ui/server/controllers/insurance/declarations/modern-slavery/index.ts index 411b90b932..4027f52a46 100644 --- a/src/ui/server/controllers/insurance/declarations/modern-slavery/index.ts +++ b/src/ui/server/controllers/insurance/declarations/modern-slavery/index.ts @@ -5,7 +5,8 @@ import insuranceCorePageVariables from '../../../../helpers/page-variables/core/ import getUserNameFromSession from '../../../../helpers/get-user-name-from-session'; import { Request, Response } from '../../../../../types'; -const { WILL_ADHERE_TO_ALL_REQUIREMENTS, HAS_NO_OFFENSES_OR_INVESTIGATIONS, IS_NOT_AWARE_OF_EXISTING_SLAVERY } = DECLARATIONS_FIELD_IDS.MODERN_SLAVERY; +const { WILL_ADHERE_TO_ALL_REQUIREMENTS, HAS_NO_OFFENSES_OR_INVESTIGATIONS, IS_NOT_AWARE_OF_EXISTING_SLAVERY, CONDITIONAL_REASONS } = + DECLARATIONS_FIELD_IDS.MODERN_SLAVERY; const { MODERN_SLAVERY } = DECLARATIONS.LATEST_DECLARATIONS; @@ -22,14 +23,26 @@ export const pageVariables = (referenceNumber: number) => ({ WILL_ADHERE_TO_ALL_REQUIREMENTS: { ID: WILL_ADHERE_TO_ALL_REQUIREMENTS, ...MODERN_SLAVERY.WILL_ADHERE_TO_ALL_REQUIREMENTS, + CONDITIONAL_REASON: { + ID: CONDITIONAL_REASONS.CANNOT_ADHERE_TO_ALL_REQUIREMENTS, + ...MODERN_SLAVERY.WILL_ADHERE_TO_ALL_REQUIREMENTS.CONDITIONAL_REASON, + }, }, HAS_NO_OFFENSES_OR_INVESTIGATIONS: { ID: HAS_NO_OFFENSES_OR_INVESTIGATIONS, ...MODERN_SLAVERY.HAS_NO_OFFENSES_OR_INVESTIGATIONS, + CONDITIONAL_REASON: { + ID: CONDITIONAL_REASONS.OFFENSES_OR_INVESTIGATIONS, + ...MODERN_SLAVERY.HAS_NO_OFFENSES_OR_INVESTIGATIONS.CONDITIONAL_REASON, + }, }, IS_NOT_AWARE_OF_EXISTING_SLAVERY: { ID: IS_NOT_AWARE_OF_EXISTING_SLAVERY, ...MODERN_SLAVERY.IS_NOT_AWARE_OF_EXISTING_SLAVERY, + CONDITIONAL_REASON: { + ID: CONDITIONAL_REASONS.AWARE_OF_EXISTING_SLAVERY, + ...MODERN_SLAVERY.IS_NOT_AWARE_OF_EXISTING_SLAVERY.CONDITIONAL_REASON, + }, }, }, SAVE_AND_BACK_URL: `${INSURANCE_ROOT}/${referenceNumber}#`, diff --git a/src/ui/templates/insurance/declarations/modern-slavery.njk b/src/ui/templates/insurance/declarations/modern-slavery.njk index aaef59e6c4..cac7d45b76 100644 --- a/src/ui/templates/insurance/declarations/modern-slavery.njk +++ b/src/ui/templates/insurance/declarations/modern-slavery.njk @@ -1,7 +1,6 @@ {% extends 'index.njk' %} {% from "govuk/components/back-link/macro.njk" import govukBackLink %} {% from 'govuk/components/error-summary/macro.njk' import govukErrorSummary %} -{% import '../../components/yes-no-radio-buttons.njk' as yesNoRadioButtons %} {% import '../../components/form-buttons.njk' as formButtons %} {% block pageTitle %} @@ -41,35 +40,11 @@ {{ CONTENT_STRINGS.INTRO.IF_YOU_SAY_NO }}

- {{ yesNoRadioButtons.render({ - fieldId: FIELDS.WILL_ADHERE_TO_ALL_REQUIREMENTS.ID, - legendText: FIELDS.WILL_ADHERE_TO_ALL_REQUIREMENTS.LABEL, - legendClass: 'govuk-fieldset__legend--s', - legendSpan: true, - errorMessage: validationErrors.errorList[FIELDS.WILL_ADHERE_TO_ALL_REQUIREMENTS.ID], - dataCyLegend: FIELDS.WILL_ADHERE_TO_ALL_REQUIREMENTS.ID + '-legend', - horizontalRadios: HORIZONTAL_RADIOS - }) }} - - {{ yesNoRadioButtons.render({ - fieldId: FIELDS.HAS_NO_OFFENSES_OR_INVESTIGATIONS.ID, - legendText: FIELDS.HAS_NO_OFFENSES_OR_INVESTIGATIONS.LABEL, - legendClass: 'govuk-fieldset__legend--s', - legendSpan: true, - errorMessage: validationErrors.errorList[FIELDS.HAS_NO_OFFENSES_OR_INVESTIGATIONS.ID], - dataCyLegend: FIELDS.HAS_NO_OFFENSES_OR_INVESTIGATIONS.ID + '-legend', - horizontalRadios: HORIZONTAL_RADIOS - }) }} - - {{ yesNoRadioButtons.render({ - fieldId: FIELDS.IS_NOT_AWARE_OF_EXISTING_SLAVERY.ID, - legendText: FIELDS.IS_NOT_AWARE_OF_EXISTING_SLAVERY.LABEL, - legendClass: 'govuk-fieldset__legend--s', - legendSpan: true, - errorMessage: validationErrors.errorList[FIELDS.IS_NOT_AWARE_OF_EXISTING_SLAVERY.ID], - dataCyLegend: FIELDS.IS_NOT_AWARE_OF_EXISTING_SLAVERY.ID + '-legend', - horizontalRadios: HORIZONTAL_RADIOS - }) }} + {% include "partials/insurance/declarations/modern-slavery/will-adhere-to-all-requirements.njk" %} + + {% include "partials/insurance/declarations/modern-slavery/has-no-offenses-or-investigations.njk" %} + + {% include "partials/insurance/declarations/modern-slavery/is-not-aware-of-existing-slavery.njk" %} diff --git a/src/ui/templates/partials/insurance/code-of-conduct-hint.njk b/src/ui/templates/partials/insurance/code-of-conduct-hint.njk index b4fc0212b6..d9cce547cb 100644 --- a/src/ui/templates/partials/insurance/code-of-conduct-hint.njk +++ b/src/ui/templates/partials/insurance/code-of-conduct-hint.njk @@ -1,4 +1,4 @@

{{ FIELDS.HINT.INTRO }} {{ FIELDS.HINT.LINK.TEXT }}. -

\ No newline at end of file +

diff --git a/src/ui/templates/partials/insurance/declarations/modern-slavery/conditional-reasons/aware-of-existing-slavery.njk b/src/ui/templates/partials/insurance/declarations/modern-slavery/conditional-reasons/aware-of-existing-slavery.njk new file mode 100644 index 0000000000..067f5e2108 --- /dev/null +++ b/src/ui/templates/partials/insurance/declarations/modern-slavery/conditional-reasons/aware-of-existing-slavery.njk @@ -0,0 +1,28 @@ +{% from "govuk/components/character-count/macro.njk" import govukCharacterCount %} + +{# maxlength: FIELDS.IS_NOT_AWARE_OF_EXISTING_SLAVERY.CONDITIONAL_REASON.MAXIMUM, #} + +{% set fieldId = FIELDS.IS_NOT_AWARE_OF_EXISTING_SLAVERY.CONDITIONAL_REASON.ID %} +{% set label = FIELDS.IS_NOT_AWARE_OF_EXISTING_SLAVERY.CONDITIONAL_REASON.LABEL %} + +{{ govukCharacterCount({ + name: fieldId, + id: fieldId, + maxlength: 123, + value: submittedValues[fieldId], + label: { + text: label, + attributes: { + 'data-cy': fieldId + '-label' + } + }, + errorMessage: validationErrors.errorList[fieldId] and { + text: validationErrors.errorList[fieldId].text, + attributes: { + "data-cy": fieldId + "-error-message" + } + }, + attributes: { + 'data-cy': fieldId + } +}) }} diff --git a/src/ui/templates/partials/insurance/declarations/modern-slavery/conditional-reasons/cannot-adhere-to-all-requirements.njk b/src/ui/templates/partials/insurance/declarations/modern-slavery/conditional-reasons/cannot-adhere-to-all-requirements.njk new file mode 100644 index 0000000000..6e6b957e11 --- /dev/null +++ b/src/ui/templates/partials/insurance/declarations/modern-slavery/conditional-reasons/cannot-adhere-to-all-requirements.njk @@ -0,0 +1,28 @@ +{% from "govuk/components/character-count/macro.njk" import govukCharacterCount %} + +{# maxlength: FIELDS.WILL_ADHERE_TO_ALL_REQUIREMENTS.CONDITIONAL_REASON.MAXIMUM, #} + +{% set fieldId = FIELDS.WILL_ADHERE_TO_ALL_REQUIREMENTS.CONDITIONAL_REASON.ID %} +{% set label = FIELDS.WILL_ADHERE_TO_ALL_REQUIREMENTS.CONDITIONAL_REASON.LABEL %} + +{{ govukCharacterCount({ + name: fieldId, + id: fieldId, + maxlength: 123, + value: submittedValues[fieldId], + label: { + text: label, + attributes: { + 'data-cy': fieldId + '-label' + } + }, + errorMessage: validationErrors.errorList[fieldId] and { + text: validationErrors.errorList[fieldId].text, + attributes: { + "data-cy": fieldId + "-error-message" + } + }, + attributes: { + 'data-cy': fieldId + } +}) }} diff --git a/src/ui/templates/partials/insurance/declarations/modern-slavery/conditional-reasons/offenses-or-investigations.njk b/src/ui/templates/partials/insurance/declarations/modern-slavery/conditional-reasons/offenses-or-investigations.njk new file mode 100644 index 0000000000..cb1f27415c --- /dev/null +++ b/src/ui/templates/partials/insurance/declarations/modern-slavery/conditional-reasons/offenses-or-investigations.njk @@ -0,0 +1,28 @@ +{% from "govuk/components/character-count/macro.njk" import govukCharacterCount %} + +{# maxlength: FIELDS.HAS_NO_OFFENSES_OR_INVESTIGATIONS.CONDITIONAL_REASON.MAXIMUM, #} + +{% set fieldId = FIELDS.HAS_NO_OFFENSES_OR_INVESTIGATIONS.CONDITIONAL_REASON.ID %} +{% set label = FIELDS.HAS_NO_OFFENSES_OR_INVESTIGATIONS.CONDITIONAL_REASON.LABEL %} + +{{ govukCharacterCount({ + name: fieldId, + id: fieldId, + maxlength: 123, + value: submittedValues[fieldId], + label: { + text: label, + attributes: { + 'data-cy': fieldId + '-label' + } + }, + errorMessage: validationErrors.errorList[fieldId] and { + text: validationErrors.errorList[fieldId].text, + attributes: { + "data-cy": fieldId + "-error-message" + } + }, + attributes: { + 'data-cy': fieldId + } +}) }} diff --git a/src/ui/templates/partials/insurance/declarations/modern-slavery/has-no-offenses-or-investigations.njk b/src/ui/templates/partials/insurance/declarations/modern-slavery/has-no-offenses-or-investigations.njk new file mode 100644 index 0000000000..9bed637c01 --- /dev/null +++ b/src/ui/templates/partials/insurance/declarations/modern-slavery/has-no-offenses-or-investigations.njk @@ -0,0 +1,16 @@ +{% import '../../../../components/yes-no-radio-buttons.njk' as yesNoRadioButtons %} + +{% set conditionalNoHtml %} + {% include "partials/insurance/declarations/modern-slavery/conditional-reasons/offenses-or-investigations.njk" %} +{% endset %} + +{{ yesNoRadioButtons.render({ + fieldId: FIELDS.HAS_NO_OFFENSES_OR_INVESTIGATIONS.ID, + legendText: FIELDS.HAS_NO_OFFENSES_OR_INVESTIGATIONS.LABEL, + legendClass: 'govuk-fieldset__legend--s', + legendSpan: true, + errorMessage: validationErrors.errorList[FIELDS.HAS_NO_OFFENSES_OR_INVESTIGATIONS.ID], + dataCyLegend: FIELDS.HAS_NO_OFFENSES_OR_INVESTIGATIONS.ID + '-legend', + horizontalRadios: HORIZONTAL_RADIOS, + conditionalNoHtml: conditionalNoHtml +}) }} diff --git a/src/ui/templates/partials/insurance/declarations/modern-slavery/is-not-aware-of-existing-slavery.njk b/src/ui/templates/partials/insurance/declarations/modern-slavery/is-not-aware-of-existing-slavery.njk new file mode 100644 index 0000000000..38c8cc73ff --- /dev/null +++ b/src/ui/templates/partials/insurance/declarations/modern-slavery/is-not-aware-of-existing-slavery.njk @@ -0,0 +1,16 @@ +{% import '../../../../components/yes-no-radio-buttons.njk' as yesNoRadioButtons %} + +{% set conditionalNoHtml %} + {% include "partials/insurance/declarations/modern-slavery/conditional-reasons/aware-of-existing-slavery.njk" %} +{% endset %} + +{{ yesNoRadioButtons.render({ + fieldId: FIELDS.IS_NOT_AWARE_OF_EXISTING_SLAVERY.ID, + legendText: FIELDS.IS_NOT_AWARE_OF_EXISTING_SLAVERY.LABEL, + legendClass: 'govuk-fieldset__legend--s', + legendSpan: true, + errorMessage: validationErrors.errorList[FIELDS.IS_NOT_AWARE_OF_EXISTING_SLAVERY.ID], + dataCyLegend: FIELDS.IS_NOT_AWARE_OF_EXISTING_SLAVERY.ID + '-legend', + horizontalRadios: HORIZONTAL_RADIOS, + conditionalNoHtml: conditionalNoHtml +}) }} diff --git a/src/ui/templates/partials/insurance/declarations/modern-slavery/will-adhere-to-all-requirements.njk b/src/ui/templates/partials/insurance/declarations/modern-slavery/will-adhere-to-all-requirements.njk new file mode 100644 index 0000000000..121643e97e --- /dev/null +++ b/src/ui/templates/partials/insurance/declarations/modern-slavery/will-adhere-to-all-requirements.njk @@ -0,0 +1,16 @@ +{% import '../../../../components/yes-no-radio-buttons.njk' as yesNoRadioButtons %} + +{% set conditionalNoHtml %} + {% include "partials/insurance/declarations/modern-slavery/conditional-reasons/cannot-adhere-to-all-requirements.njk" %} +{% endset %} + +{{ yesNoRadioButtons.render({ + fieldId: FIELDS.WILL_ADHERE_TO_ALL_REQUIREMENTS.ID, + legendText: FIELDS.WILL_ADHERE_TO_ALL_REQUIREMENTS.LABEL, + legendClass: 'govuk-fieldset__legend--s', + legendSpan: true, + errorMessage: validationErrors.errorList[FIELDS.WILL_ADHERE_TO_ALL_REQUIREMENTS.ID], + dataCyLegend: FIELDS.WILL_ADHERE_TO_ALL_REQUIREMENTS.ID + '-legend', + horizontalRadios: HORIZONTAL_RADIOS, + conditionalNoHtml: conditionalNoHtml +}) }} From 00225ff0af5d4b06f88c277cedbba9d6dfe146b1 Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Sat, 14 Dec 2024 13:25:45 +0000 Subject: [PATCH 2/9] feat(EMS-4038): declarations - modern slavery - conditional radios - e2e tests --- .../modern-slavery-radios.spec.js | 209 ++++++++++++++++++ .../modern-slavery/modern-slavery.spec.js | 123 +---------- 2 files changed, 210 insertions(+), 122 deletions(-) create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/modern-slavery-radios.spec.js diff --git a/e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/modern-slavery-radios.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/modern-slavery-radios.spec.js new file mode 100644 index 0000000000..5fb56810b5 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/modern-slavery-radios.spec.js @@ -0,0 +1,209 @@ +import { field as fieldSelector, yesRadio, noRadio } from '../../../../../../pages/shared'; +import { DECLARATIONS_FIELDS as FIELDS } from '../../../../../../content-strings/fields/insurance/declarations'; +import { FIELD_VALUES } from '../../../../../../constants'; +import { DECLARATIONS as DECLARATIONS_FIELD_IDS } from '../../../../../../constants/field-ids/insurance/declarations'; +import { INSURANCE_ROUTES } from '../../../../../../constants/routes/insurance'; + +const { + ROOT: INSURANCE_ROOT, + DECLARATIONS: { MODERN_SLAVERY }, +} = INSURANCE_ROUTES; + +const { + MODERN_SLAVERY: { + WILL_ADHERE_TO_ALL_REQUIREMENTS, + HAS_NO_OFFENSES_OR_INVESTIGATIONS, + IS_NOT_AWARE_OF_EXISTING_SLAVERY, + CONDITIONAL_REASONS: { CANNOT_ADHERE_TO_ALL_REQUIREMENTS, OFFENSES_OR_INVESTIGATIONS, AWARE_OF_EXISTING_SLAVERY }, + }, +} = DECLARATIONS_FIELD_IDS; + +const baseUrl = Cypress.config('baseUrl'); + +context('Insurance - Declarations - Modern slavery page - radios - TODO EMS-4023', () => { + let referenceNumber; + let url; + + before(() => { + cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => { + referenceNumber = refNumber; + + url = `${baseUrl}${INSURANCE_ROOT}/${referenceNumber}${MODERN_SLAVERY}`; + + cy.navigateToUrl(url); + cy.assertUrl(url); + }); + }); + + beforeEach(() => { + cy.saveSession(); + + cy.navigateToUrl(url); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + describe(WILL_ADHERE_TO_ALL_REQUIREMENTS, () => { + const fieldId = WILL_ADHERE_TO_ALL_REQUIREMENTS; + const conditionalFieldId = CANNOT_ADHERE_TO_ALL_REQUIREMENTS; + + const fieldStrings = FIELDS.MODERN_SLAVERY[fieldId].VERSIONS[0]; + + it('should render a legend', () => { + cy.checkText(fieldSelector(fieldId).legend(), fieldStrings.LABEL); + }); + + describe('`yes` radio', () => { + const selector = yesRadio(); + + it('should render a label', () => { + cy.checkText(selector.label().first(), FIELD_VALUES.YES); + + cy.checkRadioInputYesAriaLabel(fieldStrings.LABEL); + }); + + it('should render an input', () => { + selector.input().first().should('exist'); + }); + }); + + describe('`no` radio', () => { + const selector = noRadio(); + + it('should render a label', () => { + cy.checkText(selector.label().first(), FIELD_VALUES.NO); + + cy.checkRadioInputNoAriaLabel(fieldStrings.LABEL); + }); + + it('should render an input', () => { + selector.input().first().should('exist'); + }); + }); + + it(`should NOT display conditional "${conditionalFieldId}" field`, () => { + fieldSelector(conditionalFieldId).textarea().should('not.be.visible'); + }); + + it(`should display conditional "${conditionalFieldId}" field when selecting the ${fieldId} radio`, () => { + cy.clickNoRadioInput(0); + + cy.assertTextareaRendering({ + fieldId: conditionalFieldId, + expectedLabel: fieldStrings.CONDITIONAL_REASON.LABEL, + // maximumCharacters: MAXIMUM, + maximumCharacters: 123, + }); + }); + }); + + describe(HAS_NO_OFFENSES_OR_INVESTIGATIONS, () => { + const fieldId = HAS_NO_OFFENSES_OR_INVESTIGATIONS; + const conditionalFieldId = OFFENSES_OR_INVESTIGATIONS; + + const fieldStrings = FIELDS.MODERN_SLAVERY[fieldId].VERSIONS[0]; + + it('should render a legend', () => { + cy.checkText(fieldSelector(fieldId).legend(), fieldStrings.LABEL); + }); + + describe('`yes` radio', () => { + const selector = yesRadio(); + + it('should render a label', () => { + cy.checkText(selector.label().eq(1), FIELD_VALUES.YES); + + cy.checkRadioInputYesAriaLabel(fieldStrings.LABEL, 1); + }); + + it('should render an input', () => { + selector.input().eq(1).should('exist'); + }); + }); + + describe('`no` radio', () => { + const selector = noRadio(); + + it('should render a label', () => { + cy.checkText(selector.label().first(), FIELD_VALUES.NO); + + cy.checkRadioInputNoAriaLabel(fieldStrings.LABEL, 1); + }); + + it('should render an input', () => { + selector.input().first().should('exist'); + }); + }); + + it(`should NOT display conditional "${conditionalFieldId}" field`, () => { + fieldSelector(conditionalFieldId).textarea().should('not.be.visible'); + }); + + it(`should display conditional "${conditionalFieldId}" field when selecting the ${fieldId} radio`, () => { + cy.clickNoRadioInput(1); + + cy.assertTextareaRendering({ + fieldId: conditionalFieldId, + expectedLabel: fieldStrings.CONDITIONAL_REASON.LABEL, + // maximumCharacters: MAXIMUM, + maximumCharacters: 123, + }); + }); + }); + + describe(IS_NOT_AWARE_OF_EXISTING_SLAVERY, () => { + const fieldId = IS_NOT_AWARE_OF_EXISTING_SLAVERY; + const conditionalFieldId = AWARE_OF_EXISTING_SLAVERY; + + const fieldStrings = FIELDS.MODERN_SLAVERY[fieldId].VERSIONS[0]; + + it('should render a legend', () => { + cy.checkText(fieldSelector(fieldId).legend(), fieldStrings.LABEL); + }); + + describe('`yes` radio', () => { + const selector = yesRadio(); + + it('should render a label', () => { + cy.checkText(selector.label().eq(1), FIELD_VALUES.YES); + + cy.checkRadioInputYesAriaLabel(fieldStrings.LABEL, 2); + }); + + it('should render an input', () => { + selector.input().eq(1).should('exist'); + }); + }); + + describe('`no` radio', () => { + const selector = noRadio(); + + it('should render a label', () => { + cy.checkText(selector.label().first(), FIELD_VALUES.NO); + + cy.checkRadioInputNoAriaLabel(fieldStrings.LABEL, 2); + }); + + it('should render an input', () => { + selector.input().first().should('exist'); + }); + }); + + it(`should NOT display conditional "${conditionalFieldId}" field`, () => { + fieldSelector(conditionalFieldId).textarea().should('not.be.visible'); + }); + + it(`should display conditional "${conditionalFieldId}" field when selecting the ${fieldId} radio`, () => { + cy.clickNoRadioInput(2); + + cy.assertTextareaRendering({ + fieldId: conditionalFieldId, + expectedLabel: fieldStrings.CONDITIONAL_REASON.LABEL, + // maximumCharacters: MAXIMUM, + maximumCharacters: 123, + }); + }); + }); +}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/modern-slavery.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/modern-slavery.spec.js index 61588dceee..991fc34b0d 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/modern-slavery.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/modern-slavery.spec.js @@ -1,9 +1,6 @@ -import { field as fieldSelector, headingCaption, yesRadio, noRadio } from '../../../../../../pages/shared'; +import { headingCaption } from '../../../../../../pages/shared'; import { modernSlaveryPage } from '../../../../../../pages/insurance/declarations'; import { PAGES } from '../../../../../../content-strings'; -import { DECLARATIONS_FIELDS as FIELDS } from '../../../../../../content-strings/fields/insurance/declarations'; -import { FIELD_VALUES } from '../../../../../../constants'; -import { DECLARATIONS as DECLARATIONS_FIELD_IDS } from '../../../../../../constants/field-ids/insurance/declarations'; import { INSURANCE_ROUTES } from '../../../../../../constants/routes/insurance'; const CONTENT_STRINGS = PAGES.INSURANCE.DECLARATIONS.MODERN_SLAVERY; @@ -13,10 +10,6 @@ const { DECLARATIONS: { MODERN_SLAVERY }, } = INSURANCE_ROUTES; -const { - MODERN_SLAVERY: { WILL_ADHERE_TO_ALL_REQUIREMENTS, HAS_NO_OFFENSES_OR_INVESTIGATIONS, IS_NOT_AWARE_OF_EXISTING_SLAVERY }, -} = DECLARATIONS_FIELD_IDS; - const { intro: { answerTheQuestions, guidingPrinciplesLink, ifYouSayNo }, } = modernSlaveryPage; @@ -76,119 +69,5 @@ context('Insurance - Declarations - Modern slavery page - TODO EMS-4023', () => cy.checkText(ifYouSayNo(), CONTENT_STRINGS.INTRO.IF_YOU_SAY_NO); }); }); - - describe(WILL_ADHERE_TO_ALL_REQUIREMENTS, () => { - const fieldId = WILL_ADHERE_TO_ALL_REQUIREMENTS; - - const fieldStrings = FIELDS.MODERN_SLAVERY[fieldId].VERSIONS[0]; - - it('should render a legend', () => { - cy.checkText(fieldSelector(fieldId).legend(), fieldStrings.LABEL); - }); - - describe('`yes` radio', () => { - const selector = yesRadio(); - - it('should render a label', () => { - cy.checkText(selector.label().first(), FIELD_VALUES.YES); - - cy.checkRadioInputYesAriaLabel(fieldStrings.LABEL); - }); - - it('should render an input', () => { - selector.input().first().should('exist'); - }); - }); - - describe('`no` radio', () => { - const selector = noRadio(); - - it('should render a label', () => { - cy.checkText(selector.label().first(), FIELD_VALUES.NO); - - cy.checkRadioInputNoAriaLabel(fieldStrings.LABEL); - }); - - it('should render an input', () => { - selector.input().first().should('exist'); - }); - }); - }); - - describe(HAS_NO_OFFENSES_OR_INVESTIGATIONS, () => { - const fieldId = HAS_NO_OFFENSES_OR_INVESTIGATIONS; - - const fieldStrings = FIELDS.MODERN_SLAVERY[fieldId].VERSIONS[0]; - - it('should render a legend', () => { - cy.checkText(fieldSelector(fieldId).legend(), fieldStrings.LABEL); - }); - - describe('`yes` radio', () => { - const selector = yesRadio(); - - it('should render a label', () => { - cy.checkText(selector.label().eq(1), FIELD_VALUES.YES); - - cy.checkRadioInputYesAriaLabel(fieldStrings.LABEL, 1); - }); - - it('should render an input', () => { - selector.input().eq(1).should('exist'); - }); - }); - - describe('`no` radio', () => { - const selector = noRadio(); - - it('should render a label', () => { - cy.checkText(selector.label().first(), FIELD_VALUES.NO); - - cy.checkRadioInputNoAriaLabel(fieldStrings.LABEL, 1); - }); - - it('should render an input', () => { - selector.input().first().should('exist'); - }); - }); - }); - - describe(IS_NOT_AWARE_OF_EXISTING_SLAVERY, () => { - const fieldId = IS_NOT_AWARE_OF_EXISTING_SLAVERY; - - const fieldStrings = FIELDS.MODERN_SLAVERY[fieldId].VERSIONS[0]; - - it('should render a legend', () => { - cy.checkText(fieldSelector(fieldId).legend(), fieldStrings.LABEL); - }); - - describe('`yes` radio', () => { - const selector = yesRadio(); - - it('should render a label', () => { - cy.checkText(selector.label().eq(1), FIELD_VALUES.YES); - - cy.checkRadioInputYesAriaLabel(fieldStrings.LABEL, 2); - }); - - it('should render an input', () => { - selector.input().eq(1).should('exist'); - }); - }); - - describe('`no` radio', () => { - const selector = noRadio(); - - it('should render a label', () => { - cy.checkText(selector.label().first(), FIELD_VALUES.NO); - - cy.checkRadioInputNoAriaLabel(fieldStrings.LABEL, 2); - }); - - it('should render an input', () => { - selector.input().first().should('exist'); - }); - }); - }); }); }); From f126841d32f04b0e47102a842da9571f8f21f9e8 Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Sat, 14 Dec 2024 13:36:34 +0000 Subject: [PATCH 3/9] feat(EMS-4038): declarations - modern slavery - conditional maximums --- e2e-tests/constants/validation.js | 5 +++++ .../fields/insurance/declarations/index.js | 4 ++++ .../modern-slavery/modern-slavery-radios.spec.js | 11 ++++------- src/api/.keystone/config.js | 8 ++++++++ src/api/constants/validation.ts | 5 +++++ .../fields/insurance/declarations/index.ts | 4 ++++ src/ui/server/constants/validation.ts | 5 +++++ .../fields/insurance/declarations/index.ts | 4 ++++ .../conditional-reasons/aware-of-existing-slavery.njk | 5 ++--- .../cannot-adhere-to-all-requirements.njk | 5 ++--- .../offenses-or-investigations.njk | 5 ++--- 11 files changed, 45 insertions(+), 16 deletions(-) diff --git a/e2e-tests/constants/validation.js b/e2e-tests/constants/validation.js index 4ac4562225..562faa67a3 100644 --- a/e2e-tests/constants/validation.js +++ b/e2e-tests/constants/validation.js @@ -45,6 +45,11 @@ export const MAXIMUM_CHARACTERS = { COMPANY_DIFFERENT_TRADING_NAME: 200, CONNECTION_WITH_BUYER_DESCRIPTION: 1000, CREDIT_PERIOD_WITH_BUYER: 1000, + DECLARATIONS: { + MODERN_SLAVERY: { + CONDITIONAL_REASON: 1000, + }, + }, DECLINED_BY_PRIVATE_MARKET_DESCRIPTION: 1000, DIFFERENT_NAME_ON_POLICY_POSITION: 50, DIFFERENT_NAME_ON_POLICY: 50, diff --git a/e2e-tests/content-strings/fields/insurance/declarations/index.js b/e2e-tests/content-strings/fields/insurance/declarations/index.js index 6d28648bc7..de1b053396 100644 --- a/e2e-tests/content-strings/fields/insurance/declarations/index.js +++ b/e2e-tests/content-strings/fields/insurance/declarations/index.js @@ -1,3 +1,4 @@ +import { MAXIMUM_CHARACTERS } from '../../../../constants'; import { DECLARATIONS as DECLARATIONS_FIELDS_IDS } from '../../../../constants/field-ids/insurance/declarations'; const { @@ -15,6 +16,7 @@ export const DECLARATIONS_FIELDS = { CONDITIONAL_REASON: { LABEL: 'If you have a turnover of more than £36 million enter full details why you cannot. Include all information relating to the type of Modern Slavery that exists or has existed, and/or any investigation or enforcement action, and any actions taken by you in connection with this.', + MAXIMUM: MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON, }, }, ], @@ -28,6 +30,7 @@ export const DECLARATIONS_FIELDS = { CONDITIONAL_REASON: { LABEL: 'Enter full details why you cannot. Include all information relating to the type of Modern Slavery that exists or has existed, and/or any investigation or enforcement action, and any actions taken by you in connection with this.', + MAXIMUM: MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON, }, }, ], @@ -41,6 +44,7 @@ export const DECLARATIONS_FIELDS = { CONDITIONAL_REASON: { LABEL: 'Enter full details why you cannot. Include all information relating to the type of Modern Slavery that exists or has existed, and/or any investigation or enforcement action, and any actions taken by you in connection with this.', + MAXIMUM: MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON, }, }, ], diff --git a/e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/modern-slavery-radios.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/modern-slavery-radios.spec.js index 5fb56810b5..a5a178cb3e 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/modern-slavery-radios.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/modern-slavery-radios.spec.js @@ -1,6 +1,6 @@ import { field as fieldSelector, yesRadio, noRadio } from '../../../../../../pages/shared'; import { DECLARATIONS_FIELDS as FIELDS } from '../../../../../../content-strings/fields/insurance/declarations'; -import { FIELD_VALUES } from '../../../../../../constants'; +import { FIELD_VALUES, MAXIMUM_CHARACTERS } from '../../../../../../constants'; import { DECLARATIONS as DECLARATIONS_FIELD_IDS } from '../../../../../../constants/field-ids/insurance/declarations'; import { INSURANCE_ROUTES } from '../../../../../../constants/routes/insurance'; @@ -93,8 +93,7 @@ context('Insurance - Declarations - Modern slavery page - radios - TODO EMS-4023 cy.assertTextareaRendering({ fieldId: conditionalFieldId, expectedLabel: fieldStrings.CONDITIONAL_REASON.LABEL, - // maximumCharacters: MAXIMUM, - maximumCharacters: 123, + maximumCharacters: MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON, }); }); }); @@ -147,8 +146,7 @@ context('Insurance - Declarations - Modern slavery page - radios - TODO EMS-4023 cy.assertTextareaRendering({ fieldId: conditionalFieldId, expectedLabel: fieldStrings.CONDITIONAL_REASON.LABEL, - // maximumCharacters: MAXIMUM, - maximumCharacters: 123, + maximumCharacters: MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON, }); }); }); @@ -201,8 +199,7 @@ context('Insurance - Declarations - Modern slavery page - radios - TODO EMS-4023 cy.assertTextareaRendering({ fieldId: conditionalFieldId, expectedLabel: fieldStrings.CONDITIONAL_REASON.LABEL, - // maximumCharacters: MAXIMUM, - maximumCharacters: 123, + maximumCharacters: MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON, }); }); }); diff --git a/src/api/.keystone/config.js b/src/api/.keystone/config.js index 46652e5d17..ea7ed085d9 100644 --- a/src/api/.keystone/config.js +++ b/src/api/.keystone/config.js @@ -971,6 +971,11 @@ var MAXIMUM_CHARACTERS = { COMPANY_DIFFERENT_TRADING_NAME: 200, CONNECTION_WITH_BUYER_DESCRIPTION: 1e3, CREDIT_PERIOD_WITH_BUYER: 1e3, + DECLARATIONS: { + MODERN_SLAVERY: { + CONDITIONAL_REASON: 1e3, + }, + }, DECLINED_BY_PRIVATE_MARKET_DESCRIPTION: 1e3, DIFFERENT_NAME_ON_POLICY_POSITION: 50, DIFFERENT_NAME_ON_POLICY: 50, @@ -6343,6 +6348,7 @@ var DECLARATIONS_FIELDS = { CONDITIONAL_REASON: { LABEL: 'If you have a turnover of more than \xA336 million enter full details why you cannot. Include all information relating to the type of Modern Slavery that exists or has existed, and/or any investigation or enforcement action, and any actions taken by you in connection with this.', + MAXIMUM: MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON, }, }, ], @@ -6356,6 +6362,7 @@ var DECLARATIONS_FIELDS = { CONDITIONAL_REASON: { LABEL: 'Enter full details why you cannot. Include all information relating to the type of Modern Slavery that exists or has existed, and/or any investigation or enforcement action, and any actions taken by you in connection with this.', + MAXIMUM: MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON, }, }, ], @@ -6369,6 +6376,7 @@ var DECLARATIONS_FIELDS = { CONDITIONAL_REASON: { LABEL: 'Enter full details why you cannot. Include all information relating to the type of Modern Slavery that exists or has existed, and/or any investigation or enforcement action, and any actions taken by you in connection with this.', + MAXIMUM: MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON, }, }, ], diff --git a/src/api/constants/validation.ts b/src/api/constants/validation.ts index 4ac4562225..562faa67a3 100644 --- a/src/api/constants/validation.ts +++ b/src/api/constants/validation.ts @@ -45,6 +45,11 @@ export const MAXIMUM_CHARACTERS = { COMPANY_DIFFERENT_TRADING_NAME: 200, CONNECTION_WITH_BUYER_DESCRIPTION: 1000, CREDIT_PERIOD_WITH_BUYER: 1000, + DECLARATIONS: { + MODERN_SLAVERY: { + CONDITIONAL_REASON: 1000, + }, + }, DECLINED_BY_PRIVATE_MARKET_DESCRIPTION: 1000, DIFFERENT_NAME_ON_POLICY_POSITION: 50, DIFFERENT_NAME_ON_POLICY: 50, diff --git a/src/api/content-strings/fields/insurance/declarations/index.ts b/src/api/content-strings/fields/insurance/declarations/index.ts index 7b9b087da6..4055eb7243 100644 --- a/src/api/content-strings/fields/insurance/declarations/index.ts +++ b/src/api/content-strings/fields/insurance/declarations/index.ts @@ -1,3 +1,4 @@ +import { MAXIMUM_CHARACTERS } from '../../../../constants'; import INSURANCE_FIELD_IDS from '../../../../constants/field-ids/insurance'; const { @@ -42,6 +43,7 @@ export const DECLARATIONS_FIELDS = { CONDITIONAL_REASON: { LABEL: 'If you have a turnover of more than £36 million enter full details why you cannot. Include all information relating to the type of Modern Slavery that exists or has existed, and/or any investigation or enforcement action, and any actions taken by you in connection with this.', + MAXIMUM: MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON, }, }, ], @@ -55,6 +57,7 @@ export const DECLARATIONS_FIELDS = { CONDITIONAL_REASON: { LABEL: 'Enter full details why you cannot. Include all information relating to the type of Modern Slavery that exists or has existed, and/or any investigation or enforcement action, and any actions taken by you in connection with this.', + MAXIMUM: MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON, }, }, ], @@ -68,6 +71,7 @@ export const DECLARATIONS_FIELDS = { CONDITIONAL_REASON: { LABEL: 'Enter full details why you cannot. Include all information relating to the type of Modern Slavery that exists or has existed, and/or any investigation or enforcement action, and any actions taken by you in connection with this.', + MAXIMUM: MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON, }, }, ], diff --git a/src/ui/server/constants/validation.ts b/src/ui/server/constants/validation.ts index 4ac4562225..562faa67a3 100644 --- a/src/ui/server/constants/validation.ts +++ b/src/ui/server/constants/validation.ts @@ -45,6 +45,11 @@ export const MAXIMUM_CHARACTERS = { COMPANY_DIFFERENT_TRADING_NAME: 200, CONNECTION_WITH_BUYER_DESCRIPTION: 1000, CREDIT_PERIOD_WITH_BUYER: 1000, + DECLARATIONS: { + MODERN_SLAVERY: { + CONDITIONAL_REASON: 1000, + }, + }, DECLINED_BY_PRIVATE_MARKET_DESCRIPTION: 1000, DIFFERENT_NAME_ON_POLICY_POSITION: 50, DIFFERENT_NAME_ON_POLICY: 50, diff --git a/src/ui/server/content-strings/fields/insurance/declarations/index.ts b/src/ui/server/content-strings/fields/insurance/declarations/index.ts index 0442052554..4649ee195b 100644 --- a/src/ui/server/content-strings/fields/insurance/declarations/index.ts +++ b/src/ui/server/content-strings/fields/insurance/declarations/index.ts @@ -1,3 +1,4 @@ +import { MAXIMUM_CHARACTERS } from '../../../../constants/validation'; import DECLARATIONS_FIELDS_IDS from '../../../../constants/field-ids/insurance/declarations'; const { WILL_ADHERE_TO_ALL_REQUIREMENTS, HAS_NO_OFFENSES_OR_INVESTIGATIONS, IS_NOT_AWARE_OF_EXISTING_SLAVERY } = DECLARATIONS_FIELDS_IDS.MODERN_SLAVERY; @@ -13,6 +14,7 @@ export const DECLARATIONS_FIELDS = { CONDITIONAL_REASON: { LABEL: 'If you have a turnover of more than £36 million enter full details why you cannot. Include all information relating to the type of Modern Slavery that exists or has existed, and/or any investigation or enforcement action, and any actions taken by you in connection with this.', + MAXIMUM: MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON, }, }, ], @@ -26,6 +28,7 @@ export const DECLARATIONS_FIELDS = { CONDITIONAL_REASON: { LABEL: 'Enter full details why you cannot. Include all information relating to the type of Modern Slavery that exists or has existed, and/or any investigation or enforcement action, and any actions taken by you in connection with this.', + MAXIMUM: MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON, }, }, ], @@ -39,6 +42,7 @@ export const DECLARATIONS_FIELDS = { CONDITIONAL_REASON: { LABEL: 'Enter full details why you cannot. Include all information relating to the type of Modern Slavery that exists or has existed, and/or any investigation or enforcement action, and any actions taken by you in connection with this.', + MAXIMUM: MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON, }, }, ], diff --git a/src/ui/templates/partials/insurance/declarations/modern-slavery/conditional-reasons/aware-of-existing-slavery.njk b/src/ui/templates/partials/insurance/declarations/modern-slavery/conditional-reasons/aware-of-existing-slavery.njk index 067f5e2108..377256f4df 100644 --- a/src/ui/templates/partials/insurance/declarations/modern-slavery/conditional-reasons/aware-of-existing-slavery.njk +++ b/src/ui/templates/partials/insurance/declarations/modern-slavery/conditional-reasons/aware-of-existing-slavery.njk @@ -1,14 +1,13 @@ {% from "govuk/components/character-count/macro.njk" import govukCharacterCount %} -{# maxlength: FIELDS.IS_NOT_AWARE_OF_EXISTING_SLAVERY.CONDITIONAL_REASON.MAXIMUM, #} - {% set fieldId = FIELDS.IS_NOT_AWARE_OF_EXISTING_SLAVERY.CONDITIONAL_REASON.ID %} {% set label = FIELDS.IS_NOT_AWARE_OF_EXISTING_SLAVERY.CONDITIONAL_REASON.LABEL %} +{% set maxLength = FIELDS.IS_NOT_AWARE_OF_EXISTING_SLAVERY.CONDITIONAL_REASON.MAXIMUM %} {{ govukCharacterCount({ name: fieldId, id: fieldId, - maxlength: 123, + maxlength: maxLength, value: submittedValues[fieldId], label: { text: label, diff --git a/src/ui/templates/partials/insurance/declarations/modern-slavery/conditional-reasons/cannot-adhere-to-all-requirements.njk b/src/ui/templates/partials/insurance/declarations/modern-slavery/conditional-reasons/cannot-adhere-to-all-requirements.njk index 6e6b957e11..543aeb03c5 100644 --- a/src/ui/templates/partials/insurance/declarations/modern-slavery/conditional-reasons/cannot-adhere-to-all-requirements.njk +++ b/src/ui/templates/partials/insurance/declarations/modern-slavery/conditional-reasons/cannot-adhere-to-all-requirements.njk @@ -1,14 +1,13 @@ {% from "govuk/components/character-count/macro.njk" import govukCharacterCount %} -{# maxlength: FIELDS.WILL_ADHERE_TO_ALL_REQUIREMENTS.CONDITIONAL_REASON.MAXIMUM, #} - {% set fieldId = FIELDS.WILL_ADHERE_TO_ALL_REQUIREMENTS.CONDITIONAL_REASON.ID %} {% set label = FIELDS.WILL_ADHERE_TO_ALL_REQUIREMENTS.CONDITIONAL_REASON.LABEL %} +{% set maxLength = FIELDS.WILL_ADHERE_TO_ALL_REQUIREMENTS.CONDITIONAL_REASON.MAXIMUM %} {{ govukCharacterCount({ name: fieldId, id: fieldId, - maxlength: 123, + maxlength: maxLength, value: submittedValues[fieldId], label: { text: label, diff --git a/src/ui/templates/partials/insurance/declarations/modern-slavery/conditional-reasons/offenses-or-investigations.njk b/src/ui/templates/partials/insurance/declarations/modern-slavery/conditional-reasons/offenses-or-investigations.njk index cb1f27415c..00b5482701 100644 --- a/src/ui/templates/partials/insurance/declarations/modern-slavery/conditional-reasons/offenses-or-investigations.njk +++ b/src/ui/templates/partials/insurance/declarations/modern-slavery/conditional-reasons/offenses-or-investigations.njk @@ -1,14 +1,13 @@ {% from "govuk/components/character-count/macro.njk" import govukCharacterCount %} -{# maxlength: FIELDS.HAS_NO_OFFENSES_OR_INVESTIGATIONS.CONDITIONAL_REASON.MAXIMUM, #} - {% set fieldId = FIELDS.HAS_NO_OFFENSES_OR_INVESTIGATIONS.CONDITIONAL_REASON.ID %} {% set label = FIELDS.HAS_NO_OFFENSES_OR_INVESTIGATIONS.CONDITIONAL_REASON.LABEL %} +{% set maxLength = FIELDS.HAS_NO_OFFENSES_OR_INVESTIGATIONS.CONDITIONAL_REASON.MAXIMUM %} {{ govukCharacterCount({ name: fieldId, id: fieldId, - maxlength: 123, + maxlength: maxLength, value: submittedValues[fieldId], label: { text: label, From 4a2d98bf45f492abdcf4797f50eb72f97a579880 Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Sat, 14 Dec 2024 13:37:05 +0000 Subject: [PATCH 4/9] chore(EMS-4038): remove commented code --- .../field-ids/insurance/declarations/index.ts | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/ui/server/constants/field-ids/insurance/declarations/index.ts b/src/ui/server/constants/field-ids/insurance/declarations/index.ts index e643bfa830..6bcb7626b3 100644 --- a/src/ui/server/constants/field-ids/insurance/declarations/index.ts +++ b/src/ui/server/constants/field-ids/insurance/declarations/index.ts @@ -17,14 +17,3 @@ const DECLARATIONS = { }; export default DECLARATIONS; - -// with declarationModernSlaveryReason being a new table - -// willAdhereToAllRequirements -// declarationModernSlaveryReason.cannotAdhereToAllRequirements - -// hasNoOffensesOrInvestigations -// declarationModernSlaveryReason.offensesOrInvestigations - -// isNotAwareOfExistingSlavery -// declarationModernSlaveryReason.awareOfExistingSlavery From 03d616d788885b765c2abeb4c2b8cbf0d2ed30eb Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Sat, 14 Dec 2024 15:53:24 +0000 Subject: [PATCH 5/9] feat(EMS-4024): declarations - modern slavery - form validation --- ...complete-and-submit-modern-slavery-form.js | 23 ++++ ...-modern-slavery-form-conditional-fields.js | 24 +++++ .../complete-modern-slavery-form.js | 40 +++++++ .../form/submit-and-assert-radio-errors.js | 23 ++-- e2e-tests/content-strings/error-messages.js | 25 +++++ .../modern-slavery-radios.spec.js | 14 +-- ...dern-slavery-validation-empty-form.spec.js | 87 +++++++++++++++ ...-has-no-offenses-or-investigations.spec.js | 100 ++++++++++++++++++ ...n-is-not-aware-of-existing-slavery.spec.js | 100 ++++++++++++++++++ ...on-will-adhere-to-all-requirements.spec.js | 100 ++++++++++++++++++ .../cypress/support/declarations/index.js | 8 ++ .../server/content-strings/error-messages.ts | 25 +++++ .../declarations/modern-slavery/index.test.ts | 72 ++++++++++++- .../declarations/modern-slavery/index.ts | 51 ++++++++- .../modern-slavery/validation/index.test.ts | 15 +++ .../modern-slavery/validation/index.ts | 7 ++ .../aware-of-existing-slavery/index.test.ts | 57 ++++++++++ .../aware-of-existing-slavery/index.ts | 36 +++++++ .../index.test.ts | 57 ++++++++++ .../index.ts | 36 +++++++ .../offenses-or-investigations/index.test.ts | 57 ++++++++++ .../offenses-or-investigations/index.ts | 36 +++++++ .../index.test.ts | 29 +++++ .../index.ts | 26 +++++ .../modern-slavery/validation/rules/index.ts | 20 ++++ .../index.test.ts | 29 +++++ .../is-not-aware-of-existing-slavery/index.ts | 26 +++++ .../index.test.ts | 29 +++++ .../will-adhere-to-all-requirements/index.ts | 27 +++++ .../insurance/declarations/index.test.ts | 5 +- .../routes/insurance/declarations/index.ts | 3 +- src/ui/server/routes/insurance/index.test.ts | 2 +- .../has-no-offenses-or-investigations.njk | 11 +- .../is-not-aware-of-existing-slavery.njk | 11 +- .../will-adhere-to-all-requirements.njk | 11 +- 35 files changed, 1181 insertions(+), 41 deletions(-) create mode 100644 e2e-tests/commands/insurance/declarations/complete-and-submit-modern-slavery-form.js create mode 100644 e2e-tests/commands/insurance/declarations/complete-modern-slavery-form-conditional-fields.js create mode 100644 e2e-tests/commands/insurance/declarations/complete-modern-slavery-form.js create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/validation/modern-slavery-validation-empty-form.spec.js create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/validation/modern-slavery-validation-has-no-offenses-or-investigations.spec.js create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/validation/modern-slavery-validation-is-not-aware-of-existing-slavery.spec.js create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/validation/modern-slavery-validation-will-adhere-to-all-requirements.spec.js create mode 100644 src/ui/server/controllers/insurance/declarations/modern-slavery/validation/index.test.ts create mode 100644 src/ui/server/controllers/insurance/declarations/modern-slavery/validation/index.ts create mode 100644 src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/aware-of-existing-slavery/index.test.ts create mode 100644 src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/aware-of-existing-slavery/index.ts create mode 100644 src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/cannot-adhere-to-all-requirements/index.test.ts create mode 100644 src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/cannot-adhere-to-all-requirements/index.ts create mode 100644 src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/offenses-or-investigations/index.test.ts create mode 100644 src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/offenses-or-investigations/index.ts create mode 100644 src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/has-no-offenses-or-investigations/index.test.ts create mode 100644 src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/has-no-offenses-or-investigations/index.ts create mode 100644 src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/index.ts create mode 100644 src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/is-not-aware-of-existing-slavery/index.test.ts create mode 100644 src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/is-not-aware-of-existing-slavery/index.ts create mode 100644 src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/will-adhere-to-all-requirements/index.test.ts create mode 100644 src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/will-adhere-to-all-requirements/index.ts diff --git a/e2e-tests/commands/insurance/declarations/complete-and-submit-modern-slavery-form.js b/e2e-tests/commands/insurance/declarations/complete-and-submit-modern-slavery-form.js new file mode 100644 index 0000000000..9a81a844b9 --- /dev/null +++ b/e2e-tests/commands/insurance/declarations/complete-and-submit-modern-slavery-form.js @@ -0,0 +1,23 @@ +const completeAndSubmitModernSlaveryForm = ({ + willAdhereToAllRequirements, + hasNoOffensesOrInvestigations, + isNotAwareOfExistingSlavery, + conditionalFields = { + cannotAdhereToAllRequirements: '', + offensesOrInvestigations: '', + awareOfExistingSlavery: '', + }, +}) => { + cy.completeModernSlaveryForm({ + willAdhereToAllRequirements, + hasNoOffensesOrInvestigations, + isNotAwareOfExistingSlavery, + conditionalFields, + }); + + cy.clickSubmitButton(); +}; + +// TODO: update other declration commands functions to have a function name + +export default completeAndSubmitModernSlaveryForm; diff --git a/e2e-tests/commands/insurance/declarations/complete-modern-slavery-form-conditional-fields.js b/e2e-tests/commands/insurance/declarations/complete-modern-slavery-form-conditional-fields.js new file mode 100644 index 0000000000..bafc5f24de --- /dev/null +++ b/e2e-tests/commands/insurance/declarations/complete-modern-slavery-form-conditional-fields.js @@ -0,0 +1,24 @@ +import { autoCompleteField } from '../../../pages/shared'; +import { DECLARATIONS as DECLARATIONS_FIELD_IDS } from '../../../constants/field-ids/insurance/declarations'; + +const { + MODERN_SLAVERY: { + CONDITIONAL_REASONS: { CANNOT_ADHERE_TO_ALL_REQUIREMENTS, OFFENSES_OR_INVESTIGATIONS, AWARE_OF_EXISTING_SLAVERY }, + }, +} = DECLARATIONS_FIELD_IDS; + +const completeModernSlaveryFormConditionalFields = ({ cannotAdhereToAllRequirements, offensesOrInvestigations, awareOfExistingSlavery }) => { + if (cannotAdhereToAllRequirements) { + cy.keyboardInput(autoCompleteField(CANNOT_ADHERE_TO_ALL_REQUIREMENTS).input(), cannotAdhereToAllRequirements); + } + + if (offensesOrInvestigations) { + cy.keyboardInput(autoCompleteField(OFFENSES_OR_INVESTIGATIONS).input(), offensesOrInvestigations); + } + + if (awareOfExistingSlavery) { + cy.keyboardInput(autoCompleteField(AWARE_OF_EXISTING_SLAVERY).input(), awareOfExistingSlavery); + } +}; + +export default completeModernSlaveryFormConditionalFields; diff --git a/e2e-tests/commands/insurance/declarations/complete-modern-slavery-form.js b/e2e-tests/commands/insurance/declarations/complete-modern-slavery-form.js new file mode 100644 index 0000000000..7075a033b5 --- /dev/null +++ b/e2e-tests/commands/insurance/declarations/complete-modern-slavery-form.js @@ -0,0 +1,40 @@ +const completeModernSlaveryForm = ({ + willAdhereToAllRequirements = true, + hasNoOffensesOrInvestigations = true, + isNotAwareOfExistingSlavery = true, + conditionalFields = { + cannotAdhereToAllRequirements: '', + offensesOrInvestigations: '', + awareOfExistingSlavery: '', + }, +}) => { + if (willAdhereToAllRequirements) { + cy.clickYesRadioInput(0); + } + + if (willAdhereToAllRequirements === false) { + cy.clickNoRadioInput(0); + } + + if (hasNoOffensesOrInvestigations) { + cy.clickYesRadioInput(1); + } + + if (hasNoOffensesOrInvestigations === false) { + cy.clickNoRadioInput(1); + } + + if (isNotAwareOfExistingSlavery) { + cy.clickYesRadioInput(2); + } + + if (isNotAwareOfExistingSlavery === false) { + cy.clickNoRadioInput(2); + } + + cy.completeModernSlaveryFormConditionalFields(conditionalFields); +}; + +// TODO: update other declration commands functions to have a function name + +export default completeModernSlaveryForm; diff --git a/e2e-tests/commands/shared-commands/form/submit-and-assert-radio-errors.js b/e2e-tests/commands/shared-commands/form/submit-and-assert-radio-errors.js index d89b16cf91..fd9ccc3e13 100644 --- a/e2e-tests/commands/shared-commands/form/submit-and-assert-radio-errors.js +++ b/e2e-tests/commands/shared-commands/form/submit-and-assert-radio-errors.js @@ -1,25 +1,20 @@ -import { errorSummaryListItems, errorSummaryListItemLinks } from '../../../partials'; - /** * @param {Object} field: Cypress selector. * @param {Number} errorIndex: Index of error. Defaults to 0. * @param {Number} expectedErrorsCount: Expected total amount of errors in the errors summary. Defaults to 1. * @param {Number} expectedErrorMessage: Expected error message. + * @param {Boolean} fieldShouldGainFocus: Input should gain focus after clicking the summary list error. Defaults to true */ -const submitAndAssertRadioErrors = ({ field, errorIndex = 0, expectedErrorsCount = 1, expectedErrorMessage }) => { +const submitAndAssertRadioErrors = ({ field, errorIndex = 0, expectedErrorsCount = 1, expectedErrorMessage, fieldShouldGainFocus = true }) => { cy.clickSubmitButton(); - cy.checkErrorSummaryListHeading(); - - cy.assertErrorSummaryListLength(expectedErrorsCount); - - cy.checkText(errorSummaryListItems().eq(errorIndex), expectedErrorMessage); - - errorSummaryListItemLinks().eq(errorIndex).click(); - - field.input().should('have.focus'); - - cy.checkText(field.errorMessage(), `Error: ${expectedErrorMessage}`); + cy.assertFieldErrors({ + field, + errorIndex, + errorSummaryLength: expectedErrorsCount, + errorMessage: expectedErrorMessage, + fieldShouldGainFocus, + }); }; export default submitAndAssertRadioErrors; diff --git a/e2e-tests/content-strings/error-messages.js b/e2e-tests/content-strings/error-messages.js index d890545b85..3afe9fab62 100644 --- a/e2e-tests/content-strings/error-messages.js +++ b/e2e-tests/content-strings/error-messages.js @@ -546,6 +546,31 @@ export const ERROR_MESSAGES = { [FIELD_IDS.INSURANCE.DECLARATIONS.AGREE_CONFIRMATION_ACKNOWLEDGEMENTS]: { IS_EMPTY: 'Confirm that you have read and accept the confirmation and acknowledgements', }, + MODERN_SLAVERY: { + [FIELD_IDS.INSURANCE.DECLARATIONS.MODERN_SLAVERY.WILL_ADHERE_TO_ALL_REQUIREMENTS]: { + IS_EMPTY: 'Select if you adhere to all the requirements of the Modern Slavery Act 2015', + }, + [FIELD_IDS.INSURANCE.DECLARATIONS.MODERN_SLAVERY.HAS_NO_OFFENSES_OR_INVESTIGATIONS]: { + IS_EMPTY: 'Select if you are under investigation or been fine, convicted or found guilty or not', + }, + [FIELD_IDS.INSURANCE.DECLARATIONS.MODERN_SLAVERY.IS_NOT_AWARE_OF_EXISTING_SLAVERY]: { + IS_EMPTY: 'Select if you are or are not aware of Modern Slavery in respect of yourself, the export contract, holding company or supply chain', + }, + CONDITIONAL_REASONS: { + [FIELD_IDS.INSURANCE.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASONS.CANNOT_ADHERE_TO_ALL_REQUIREMENTS]: { + IS_EMPTY: 'Enter full details of why you cannot confirm', + ABOVE_MAXIMUM: `The explanation of why you cannot confirm cannot be more than ${MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON} characters`, + }, + [FIELD_IDS.INSURANCE.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASONS.OFFENSES_OR_INVESTIGATIONS]: { + IS_EMPTY: 'Enter full details of why you cannot confirm', + ABOVE_MAXIMUM: `The explanation of why you cannot confirm cannot be more than ${MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON} characters`, + }, + [FIELD_IDS.INSURANCE.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASONS.AWARE_OF_EXISTING_SLAVERY]: { + IS_EMPTY: 'Enter full details of why you cannot confirm', + ABOVE_MAXIMUM: `The explanation of why you cannot confirm cannot be more than ${MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON} characters`, + }, + }, + }, }, }, }; diff --git a/e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/modern-slavery-radios.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/modern-slavery-radios.spec.js index a5a178cb3e..999761ac9a 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/modern-slavery-radios.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/modern-slavery-radios.spec.js @@ -18,6 +18,8 @@ const { }, } = DECLARATIONS_FIELD_IDS; +const { YES, NO } = FIELD_VALUES; + const baseUrl = Cypress.config('baseUrl'); context('Insurance - Declarations - Modern slavery page - radios - TODO EMS-4023', () => { @@ -59,7 +61,7 @@ context('Insurance - Declarations - Modern slavery page - radios - TODO EMS-4023 const selector = yesRadio(); it('should render a label', () => { - cy.checkText(selector.label().first(), FIELD_VALUES.YES); + cy.checkText(selector.label().first(), YES); cy.checkRadioInputYesAriaLabel(fieldStrings.LABEL); }); @@ -73,7 +75,7 @@ context('Insurance - Declarations - Modern slavery page - radios - TODO EMS-4023 const selector = noRadio(); it('should render a label', () => { - cy.checkText(selector.label().first(), FIELD_VALUES.NO); + cy.checkText(selector.label().first(), NO); cy.checkRadioInputNoAriaLabel(fieldStrings.LABEL); }); @@ -112,7 +114,7 @@ context('Insurance - Declarations - Modern slavery page - radios - TODO EMS-4023 const selector = yesRadio(); it('should render a label', () => { - cy.checkText(selector.label().eq(1), FIELD_VALUES.YES); + cy.checkText(selector.label().eq(1), YES); cy.checkRadioInputYesAriaLabel(fieldStrings.LABEL, 1); }); @@ -126,7 +128,7 @@ context('Insurance - Declarations - Modern slavery page - radios - TODO EMS-4023 const selector = noRadio(); it('should render a label', () => { - cy.checkText(selector.label().first(), FIELD_VALUES.NO); + cy.checkText(selector.label().first(), NO); cy.checkRadioInputNoAriaLabel(fieldStrings.LABEL, 1); }); @@ -165,7 +167,7 @@ context('Insurance - Declarations - Modern slavery page - radios - TODO EMS-4023 const selector = yesRadio(); it('should render a label', () => { - cy.checkText(selector.label().eq(1), FIELD_VALUES.YES); + cy.checkText(selector.label().eq(1), YES); cy.checkRadioInputYesAriaLabel(fieldStrings.LABEL, 2); }); @@ -179,7 +181,7 @@ context('Insurance - Declarations - Modern slavery page - radios - TODO EMS-4023 const selector = noRadio(); it('should render a label', () => { - cy.checkText(selector.label().first(), FIELD_VALUES.NO); + cy.checkText(selector.label().first(), NO); cy.checkRadioInputNoAriaLabel(fieldStrings.LABEL, 2); }); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/validation/modern-slavery-validation-empty-form.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/validation/modern-slavery-validation-empty-form.spec.js new file mode 100644 index 0000000000..e95c7f06d7 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/validation/modern-slavery-validation-empty-form.spec.js @@ -0,0 +1,87 @@ +import { yesRadio } from '../../../../../../../pages/shared'; +import { ERROR_MESSAGES } from '../../../../../../../content-strings'; +import { DECLARATIONS as DECLARATIONS_FIELD_IDS } from '../../../../../../../constants/field-ids/insurance/declarations'; +import { INSURANCE_ROUTES } from '../../../../../../../constants/routes/insurance'; + +const { + ROOT: INSURANCE_ROOT, + DECLARATIONS: { MODERN_SLAVERY }, +} = INSURANCE_ROUTES; + +const { + MODERN_SLAVERY: { WILL_ADHERE_TO_ALL_REQUIREMENTS, HAS_NO_OFFENSES_OR_INVESTIGATIONS, IS_NOT_AWARE_OF_EXISTING_SLAVERY }, +} = DECLARATIONS_FIELD_IDS; + +const ERROR_STRINGS = ERROR_MESSAGES.INSURANCE.DECLARATIONS.MODERN_SLAVERY; + +const baseUrl = Cypress.config('baseUrl'); + +context('Insurance - Declarations - Modern slavery page - validation - empty form', () => { + let referenceNumber; + let url; + + before(() => { + cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => { + referenceNumber = refNumber; + + url = `${baseUrl}${INSURANCE_ROOT}/${referenceNumber}${MODERN_SLAVERY}`; + + cy.navigateToUrl(url); + cy.assertUrl(url); + }); + }); + + beforeEach(() => { + cy.saveSession(); + + cy.navigateToUrl(url); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + describe('when submitting an empty form', () => { + const expectedErrorsCount = 3; + + beforeEach(() => { + cy.navigateToUrl(url); + + cy.clickSubmitButton(); + }); + + it(`should render ${WILL_ADHERE_TO_ALL_REQUIREMENTS} validation error`, () => { + cy.submitAndAssertRadioErrors({ + errorIndex: 0, + field: yesRadio(WILL_ADHERE_TO_ALL_REQUIREMENTS), + expectedErrorsCount, + expectedErrorMessage: ERROR_STRINGS[WILL_ADHERE_TO_ALL_REQUIREMENTS].IS_EMPTY, + fieldShouldGainFocus: true, + }); + }); + + it(`should render ${HAS_NO_OFFENSES_OR_INVESTIGATIONS} validation error`, () => { + cy.submitAndAssertRadioErrors({ + errorIndex: 1, + field: yesRadio(HAS_NO_OFFENSES_OR_INVESTIGATIONS), + expectedErrorsCount, + expectedErrorMessage: ERROR_STRINGS[HAS_NO_OFFENSES_OR_INVESTIGATIONS].IS_EMPTY, + fieldShouldGainFocus: true, + }); + }); + + it(`should render ${IS_NOT_AWARE_OF_EXISTING_SLAVERY} validation error`, () => { + cy.submitAndAssertRadioErrors({ + errorIndex: 2, + field: yesRadio(IS_NOT_AWARE_OF_EXISTING_SLAVERY), + expectedErrorsCount, + expectedErrorMessage: ERROR_STRINGS[IS_NOT_AWARE_OF_EXISTING_SLAVERY].IS_EMPTY, + fieldShouldGainFocus: true, + }); + }); + }); + + // TODO + // TODO + // TODO: submit all as no +}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/validation/modern-slavery-validation-has-no-offenses-or-investigations.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/validation/modern-slavery-validation-has-no-offenses-or-investigations.spec.js new file mode 100644 index 0000000000..8a2091f836 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/validation/modern-slavery-validation-has-no-offenses-or-investigations.spec.js @@ -0,0 +1,100 @@ +import { autoCompleteField } from '../../../../../../../pages/shared'; +import { ERROR_MESSAGES } from '../../../../../../../content-strings'; +import { MAXIMUM_CHARACTERS } from '../../../../../../../constants'; +import { DECLARATIONS as DECLARATIONS_FIELD_IDS } from '../../../../../../../constants/field-ids/insurance/declarations'; +import { INSURANCE_ROUTES } from '../../../../../../../constants/routes/insurance'; + +const { + ROOT: INSURANCE_ROOT, + DECLARATIONS: { MODERN_SLAVERY }, +} = INSURANCE_ROUTES; + +const { + MODERN_SLAVERY: { + HAS_NO_OFFENSES_OR_INVESTIGATIONS, + CONDITIONAL_REASONS: { OFFENSES_OR_INVESTIGATIONS }, + }, +} = DECLARATIONS_FIELD_IDS; + +const ERROR_STRINGS = ERROR_MESSAGES.INSURANCE.DECLARATIONS.MODERN_SLAVERY; + +const MAXIMUM = MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON; + +const reasonOverMaximum = 'a'.repeat(MAXIMUM + 1); + +const fieldId = HAS_NO_OFFENSES_OR_INVESTIGATIONS; +const conditionalFieldId = OFFENSES_OR_INVESTIGATIONS; + +const baseUrl = Cypress.config('baseUrl'); + +context(`Insurance - Declarations - Modern slavery page - validation - ${fieldId}`, () => { + let referenceNumber; + let url; + + before(() => { + cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => { + referenceNumber = refNumber; + + url = `${baseUrl}${INSURANCE_ROOT}/${referenceNumber}${MODERN_SLAVERY}`; + + cy.navigateToUrl(url); + cy.assertUrl(url); + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + describe(`when ${fieldId} is 'no', but ${conditionalFieldId} is not provided`, () => { + it(`should render a ${conditionalFieldId} validation error`, () => { + cy.navigateToUrl(url); + + cy.completeAndSubmitModernSlaveryForm({ + hasNoOffensesOrInvestigations: false, + }); + + cy.assertFieldErrors({ + field: autoCompleteField(conditionalFieldId), + errorIndex: 0, + errorSummaryLength: 1, + errorMessage: ERROR_STRINGS.CONDITIONAL_REASONS[conditionalFieldId].IS_EMPTY, + }); + }); + }); + + describe(`when ${fieldId} is 'no', but ${conditionalFieldId} is over ${MAXIMUM} characters`, () => { + beforeEach(() => { + cy.navigateToUrl(url); + + cy.completeAndSubmitModernSlaveryForm({ + hasNoOffensesOrInvestigations: false, + conditionalFields: { + offensesOrInvestigations: reasonOverMaximum, + }, + }); + }); + + it(`should render a ${conditionalFieldId} validation error`, () => { + cy.assertFieldErrors({ + field: autoCompleteField(conditionalFieldId), + errorIndex: 0, + errorSummaryLength: 1, + errorMessage: ERROR_STRINGS.CONDITIONAL_REASONS[conditionalFieldId].ABOVE_MAXIMUM, + }); + }); + + it('should retain the submitted value', () => { + cy.checkTextareaValue({ + fieldId: conditionalFieldId, + expectedValue: reasonOverMaximum, + }); + + cy.assertNoRadioOptionIsChecked(); + }); + }); +}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/validation/modern-slavery-validation-is-not-aware-of-existing-slavery.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/validation/modern-slavery-validation-is-not-aware-of-existing-slavery.spec.js new file mode 100644 index 0000000000..f0155b317e --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/validation/modern-slavery-validation-is-not-aware-of-existing-slavery.spec.js @@ -0,0 +1,100 @@ +import { autoCompleteField } from '../../../../../../../pages/shared'; +import { ERROR_MESSAGES } from '../../../../../../../content-strings'; +import { MAXIMUM_CHARACTERS } from '../../../../../../../constants'; +import { DECLARATIONS as DECLARATIONS_FIELD_IDS } from '../../../../../../../constants/field-ids/insurance/declarations'; +import { INSURANCE_ROUTES } from '../../../../../../../constants/routes/insurance'; + +const { + ROOT: INSURANCE_ROOT, + DECLARATIONS: { MODERN_SLAVERY }, +} = INSURANCE_ROUTES; + +const { + MODERN_SLAVERY: { + IS_NOT_AWARE_OF_EXISTING_SLAVERY, + CONDITIONAL_REASONS: { AWARE_OF_EXISTING_SLAVERY }, + }, +} = DECLARATIONS_FIELD_IDS; + +const ERROR_STRINGS = ERROR_MESSAGES.INSURANCE.DECLARATIONS.MODERN_SLAVERY; + +const MAXIMUM = MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON; + +const reasonOverMaximum = 'a'.repeat(MAXIMUM + 1); + +const fieldId = IS_NOT_AWARE_OF_EXISTING_SLAVERY; +const conditionalFieldId = AWARE_OF_EXISTING_SLAVERY; + +const baseUrl = Cypress.config('baseUrl'); + +context(`Insurance - Declarations - Modern slavery page - validation - ${fieldId}`, () => { + let referenceNumber; + let url; + + before(() => { + cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => { + referenceNumber = refNumber; + + url = `${baseUrl}${INSURANCE_ROOT}/${referenceNumber}${MODERN_SLAVERY}`; + + cy.navigateToUrl(url); + cy.assertUrl(url); + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + describe(`when ${fieldId} is 'no', but ${conditionalFieldId} is not provided`, () => { + it(`should render a ${conditionalFieldId} validation error`, () => { + cy.navigateToUrl(url); + + cy.completeAndSubmitModernSlaveryForm({ + isNotAwareOfExistingSlavery: false, + }); + + cy.assertFieldErrors({ + field: autoCompleteField(conditionalFieldId), + errorIndex: 0, + errorSummaryLength: 1, + errorMessage: ERROR_STRINGS.CONDITIONAL_REASONS[conditionalFieldId].IS_EMPTY, + }); + }); + }); + + describe(`when ${fieldId} is 'no', but ${conditionalFieldId} is over ${MAXIMUM} characters`, () => { + beforeEach(() => { + cy.navigateToUrl(url); + + cy.completeAndSubmitModernSlaveryForm({ + isNotAwareOfExistingSlavery: false, + conditionalFields: { + awareOfExistingSlavery: reasonOverMaximum, + }, + }); + }); + + it(`should render a ${conditionalFieldId} validation error`, () => { + cy.assertFieldErrors({ + field: autoCompleteField(conditionalFieldId), + errorIndex: 0, + errorSummaryLength: 1, + errorMessage: ERROR_STRINGS.CONDITIONAL_REASONS[conditionalFieldId].ABOVE_MAXIMUM, + }); + }); + + it('should retain the submitted value', () => { + cy.checkTextareaValue({ + fieldId: conditionalFieldId, + expectedValue: reasonOverMaximum, + }); + + cy.assertNoRadioOptionIsChecked(); + }); + }); +}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/validation/modern-slavery-validation-will-adhere-to-all-requirements.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/validation/modern-slavery-validation-will-adhere-to-all-requirements.spec.js new file mode 100644 index 0000000000..6dfb6496ac --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/validation/modern-slavery-validation-will-adhere-to-all-requirements.spec.js @@ -0,0 +1,100 @@ +import { autoCompleteField } from '../../../../../../../pages/shared'; +import { ERROR_MESSAGES } from '../../../../../../../content-strings'; +import { MAXIMUM_CHARACTERS } from '../../../../../../../constants'; +import { DECLARATIONS as DECLARATIONS_FIELD_IDS } from '../../../../../../../constants/field-ids/insurance/declarations'; +import { INSURANCE_ROUTES } from '../../../../../../../constants/routes/insurance'; + +const { + ROOT: INSURANCE_ROOT, + DECLARATIONS: { MODERN_SLAVERY }, +} = INSURANCE_ROUTES; + +const { + MODERN_SLAVERY: { + WILL_ADHERE_TO_ALL_REQUIREMENTS, + CONDITIONAL_REASONS: { CANNOT_ADHERE_TO_ALL_REQUIREMENTS }, + }, +} = DECLARATIONS_FIELD_IDS; + +const ERROR_STRINGS = ERROR_MESSAGES.INSURANCE.DECLARATIONS.MODERN_SLAVERY; + +const MAXIMUM = MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON; + +const reasonOverMaximum = 'a'.repeat(MAXIMUM + 1); + +const fieldId = WILL_ADHERE_TO_ALL_REQUIREMENTS; +const conditionalFieldId = CANNOT_ADHERE_TO_ALL_REQUIREMENTS; + +const baseUrl = Cypress.config('baseUrl'); + +context(`Insurance - Declarations - Modern slavery page - validation - ${fieldId}`, () => { + let referenceNumber; + let url; + + before(() => { + cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => { + referenceNumber = refNumber; + + url = `${baseUrl}${INSURANCE_ROOT}/${referenceNumber}${MODERN_SLAVERY}`; + + cy.navigateToUrl(url); + cy.assertUrl(url); + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + describe(`when ${fieldId} is 'no', but ${conditionalFieldId} is not provided`, () => { + it(`should render a ${conditionalFieldId} validation error`, () => { + cy.navigateToUrl(url); + + cy.completeAndSubmitModernSlaveryForm({ + willAdhereToAllRequirements: false, + }); + + cy.assertFieldErrors({ + field: autoCompleteField(conditionalFieldId), + errorIndex: 0, + errorSummaryLength: 1, + errorMessage: ERROR_STRINGS.CONDITIONAL_REASONS[conditionalFieldId].IS_EMPTY, + }); + }); + }); + + describe(`when ${fieldId} is 'no', but ${conditionalFieldId} is over ${MAXIMUM} characters`, () => { + beforeEach(() => { + cy.navigateToUrl(url); + + cy.completeAndSubmitModernSlaveryForm({ + willAdhereToAllRequirements: false, + conditionalFields: { + cannotAdhereToAllRequirements: reasonOverMaximum, + }, + }); + }); + + it(`should render a ${conditionalFieldId} validation error`, () => { + cy.assertFieldErrors({ + field: autoCompleteField(conditionalFieldId), + errorIndex: 0, + errorSummaryLength: 1, + errorMessage: ERROR_STRINGS.CONDITIONAL_REASONS[conditionalFieldId].ABOVE_MAXIMUM, + }); + }); + + it('should retain the submitted value', () => { + cy.checkTextareaValue({ + fieldId: conditionalFieldId, + expectedValue: reasonOverMaximum, + }); + + cy.assertNoRadioOptionIsChecked(); + }); + }); +}); diff --git a/e2e-tests/insurance/cypress/support/declarations/index.js b/e2e-tests/insurance/cypress/support/declarations/index.js index 8c4464abea..fc283c6111 100644 --- a/e2e-tests/insurance/cypress/support/declarations/index.js +++ b/e2e-tests/insurance/cypress/support/declarations/index.js @@ -11,6 +11,14 @@ Cypress.Commands.add( 'completeAndSubmitDeclarationAntiBriberyExportingWithCodeOfConduct', require('../../../../commands/insurance/declarations/complete-and-submit-anti-bribery-exporting-with-code-of-conduct-form'), ); + +Cypress.Commands.add('completeModernSlaveryForm', require('../../../../commands/insurance/declarations/complete-modern-slavery-form')); +Cypress.Commands.add('completeAndSubmitModernSlaveryForm', require('../../../../commands/insurance/declarations/complete-and-submit-modern-slavery-form')); +Cypress.Commands.add( + 'completeModernSlaveryFormConditionalFields', + require('../../../../commands/insurance/declarations/complete-modern-slavery-form-conditional-fields'), +); + Cypress.Commands.add( 'completeAndSubmitDeclarationConfirmationAndAcknowledgements', require('../../../../commands/insurance/declarations/complete-and-submit-confirmation-and-acknowledgements-form'), diff --git a/src/ui/server/content-strings/error-messages.ts b/src/ui/server/content-strings/error-messages.ts index 377d0c5b66..88408246d9 100644 --- a/src/ui/server/content-strings/error-messages.ts +++ b/src/ui/server/content-strings/error-messages.ts @@ -550,6 +550,31 @@ export const ERROR_MESSAGES = { [FIELD_IDS.INSURANCE.DECLARATIONS.AGREE_CONFIRMATION_ACKNOWLEDGEMENTS]: { IS_EMPTY: 'Confirm that you have read and accept the confirmation and acknowledgements', }, + MODERN_SLAVERY: { + [FIELD_IDS.INSURANCE.DECLARATIONS.MODERN_SLAVERY.WILL_ADHERE_TO_ALL_REQUIREMENTS]: { + IS_EMPTY: 'Select if you adhere to all the requirements of the Modern Slavery Act 2015', + }, + [FIELD_IDS.INSURANCE.DECLARATIONS.MODERN_SLAVERY.HAS_NO_OFFENSES_OR_INVESTIGATIONS]: { + IS_EMPTY: 'Select if you are under investigation or been fine, convicted or found guilty or not', + }, + [FIELD_IDS.INSURANCE.DECLARATIONS.MODERN_SLAVERY.IS_NOT_AWARE_OF_EXISTING_SLAVERY]: { + IS_EMPTY: 'Select if you are or are not aware of Modern Slavery in respect of yourself, the export contract, holding company or supply chain', + }, + CONDITIONAL_REASONS: { + [FIELD_IDS.INSURANCE.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASONS.CANNOT_ADHERE_TO_ALL_REQUIREMENTS]: { + IS_EMPTY: 'Enter full details of why you cannot confirm', + ABOVE_MAXIMUM: `The explanation of why you cannot confirm cannot be more than ${MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON} characters`, + }, + [FIELD_IDS.INSURANCE.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASONS.OFFENSES_OR_INVESTIGATIONS]: { + IS_EMPTY: 'Enter full details of why you cannot confirm', + ABOVE_MAXIMUM: `The explanation of why you cannot confirm cannot be more than ${MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON} characters`, + }, + [FIELD_IDS.INSURANCE.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASONS.AWARE_OF_EXISTING_SLAVERY]: { + IS_EMPTY: 'Enter full details of why you cannot confirm', + ABOVE_MAXIMUM: `The explanation of why you cannot confirm cannot be more than ${MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON} characters`, + }, + }, + }, }, }, } as ErrorMessage; diff --git a/src/ui/server/controllers/insurance/declarations/modern-slavery/index.test.ts b/src/ui/server/controllers/insurance/declarations/modern-slavery/index.test.ts index 8d67b70453..715f4603f1 100644 --- a/src/ui/server/controllers/insurance/declarations/modern-slavery/index.test.ts +++ b/src/ui/server/controllers/insurance/declarations/modern-slavery/index.test.ts @@ -1,9 +1,12 @@ -import { pageVariables, PAGE_CONTENT_STRINGS, HTML_FLAGS, TEMPLATE, FIELD_IDS, get } from '.'; +import { pageVariables, PAGE_CONTENT_STRINGS, HTML_FLAGS, TEMPLATE, FIELD_IDS, get, post } from '.'; import { PAGES } from '../../../../content-strings'; import { TEMPLATES, ROUTES, DECLARATIONS } from '../../../../constants'; import DECLARATIONS_FIELD_IDS from '../../../../constants/field-ids/insurance/declarations'; import insuranceCorePageVariables from '../../../../helpers/page-variables/core/insurance'; import getUserNameFromSession from '../../../../helpers/get-user-name-from-session'; +import constructPayload from '../../../../helpers/construct-payload'; +import generateValidationErrors from './validation'; +import { sanitiseData } from '../../../../helpers/sanitise-data'; import { Request, Response } from '../../../../../types'; import { mockReq, mockRes, referenceNumber } from '../../../../test-mocks'; @@ -12,7 +15,7 @@ const { WILL_ADHERE_TO_ALL_REQUIREMENTS, HAS_NO_OFFENSES_OR_INVESTIGATIONS, IS_N const { MODERN_SLAVERY } = DECLARATIONS.LATEST_DECLARATIONS; -const { INSURANCE_ROOT, PROBLEM_WITH_SERVICE } = ROUTES.INSURANCE; +const { INSURANCE_ROOT, ALL_SECTIONS, PROBLEM_WITH_SERVICE } = ROUTES.INSURANCE; describe('controllers/insurance/declarations/modern-slavery', () => { let req: Request; @@ -47,7 +50,14 @@ describe('controllers/insurance/declarations/modern-slavery', () => { describe('FIELD_IDS', () => { it('should have the correct FIELD_IDS', () => { - const expected = [WILL_ADHERE_TO_ALL_REQUIREMENTS, HAS_NO_OFFENSES_OR_INVESTIGATIONS, IS_NOT_AWARE_OF_EXISTING_SLAVERY]; + const expected = [ + WILL_ADHERE_TO_ALL_REQUIREMENTS, + HAS_NO_OFFENSES_OR_INVESTIGATIONS, + IS_NOT_AWARE_OF_EXISTING_SLAVERY, + CONDITIONAL_REASONS.CANNOT_ADHERE_TO_ALL_REQUIREMENTS, + CONDITIONAL_REASONS.OFFENSES_OR_INVESTIGATIONS, + CONDITIONAL_REASONS.AWARE_OF_EXISTING_SLAVERY, + ]; expect(FIELD_IDS).toEqual(expected); }); @@ -120,4 +130,60 @@ describe('controllers/insurance/declarations/modern-slavery', () => { }); }); }); + + describe('post', () => { + const validBody = { + [WILL_ADHERE_TO_ALL_REQUIREMENTS]: 'true', + [HAS_NO_OFFENSES_OR_INVESTIGATIONS]: 'true', + [IS_NOT_AWARE_OF_EXISTING_SLAVERY]: 'true', + }; + + describe('when there are no validation errors', () => { + beforeEach(() => { + req.body = validBody; + }); + + it(`should redirect to ${ALL_SECTIONS}`, () => { + post(req, res); + + const expected = `${INSURANCE_ROOT}/${referenceNumber}${ALL_SECTIONS}`; + + expect(res.redirect).toHaveBeenCalledWith(expected); + }); + }); + + describe('when there are validation errors', () => { + it('should render template with validation errors from constructPayload function', () => { + post(req, res); + + const payload = constructPayload(req.body, FIELD_IDS); + + const expectedVariables = { + ...insuranceCorePageVariables({ + PAGE_CONTENT_STRINGS, + BACK_LINK: req.headers.referer, + HTML_FLAGS, + }), + ...pageVariables(referenceNumber), + userName: getUserNameFromSession(req.session.user), + validationErrors: generateValidationErrors(payload), + submittedValues: sanitiseData(payload), + }; + + expect(res.render).toHaveBeenCalledWith(TEMPLATE, expectedVariables); + }); + }); + + describe('when there is no application', () => { + beforeEach(() => { + delete res.locals.application; + }); + + it(`should redirect to ${PROBLEM_WITH_SERVICE}`, () => { + post(req, res); + + expect(res.redirect).toHaveBeenCalledWith(PROBLEM_WITH_SERVICE); + }); + }); + }); }); diff --git a/src/ui/server/controllers/insurance/declarations/modern-slavery/index.ts b/src/ui/server/controllers/insurance/declarations/modern-slavery/index.ts index 4027f52a46..58aebee5a6 100644 --- a/src/ui/server/controllers/insurance/declarations/modern-slavery/index.ts +++ b/src/ui/server/controllers/insurance/declarations/modern-slavery/index.ts @@ -3,6 +3,9 @@ import DECLARATIONS_FIELD_IDS from '../../../../constants/field-ids/insurance/de import { PAGES } from '../../../../content-strings'; import insuranceCorePageVariables from '../../../../helpers/page-variables/core/insurance'; import getUserNameFromSession from '../../../../helpers/get-user-name-from-session'; +import constructPayload from '../../../../helpers/construct-payload'; +import generateValidationErrors from './validation'; +import { sanitiseData } from '../../../../helpers/sanitise-data'; import { Request, Response } from '../../../../../types'; const { WILL_ADHERE_TO_ALL_REQUIREMENTS, HAS_NO_OFFENSES_OR_INVESTIGATIONS, IS_NOT_AWARE_OF_EXISTING_SLAVERY, CONDITIONAL_REASONS } = @@ -10,7 +13,7 @@ const { WILL_ADHERE_TO_ALL_REQUIREMENTS, HAS_NO_OFFENSES_OR_INVESTIGATIONS, IS_N const { MODERN_SLAVERY } = DECLARATIONS.LATEST_DECLARATIONS; -const { INSURANCE_ROOT, PROBLEM_WITH_SERVICE } = ROUTES.INSURANCE; +const { INSURANCE_ROOT, ALL_SECTIONS, PROBLEM_WITH_SERVICE } = ROUTES.INSURANCE; /** * pageVariables @@ -60,7 +63,14 @@ export const HTML_FLAGS = { export const TEMPLATE = TEMPLATES.INSURANCE.DECLARATIONS.MODERN_SLAVERY; -export const FIELD_IDS = [WILL_ADHERE_TO_ALL_REQUIREMENTS, HAS_NO_OFFENSES_OR_INVESTIGATIONS, IS_NOT_AWARE_OF_EXISTING_SLAVERY]; +export const FIELD_IDS = [ + WILL_ADHERE_TO_ALL_REQUIREMENTS, + HAS_NO_OFFENSES_OR_INVESTIGATIONS, + IS_NOT_AWARE_OF_EXISTING_SLAVERY, + CONDITIONAL_REASONS.CANNOT_ADHERE_TO_ALL_REQUIREMENTS, + CONDITIONAL_REASONS.OFFENSES_OR_INVESTIGATIONS, + CONDITIONAL_REASONS.AWARE_OF_EXISTING_SLAVERY, +]; /** * get @@ -86,3 +96,40 @@ export const get = (req: Request, res: Response) => { userName: getUserNameFromSession(req.session.user), }); }; + +/** + * post + * Check Declarations - Modern slavery validation errors and if successful, redirect to the next part of the flow. + * @param {Express.Request} Express request + * @param {Express.Response} Express response + * @returns {Express.Response.redirect} Next part of the flow or error page + */ +export const post = async (req: Request, res: Response) => { + const { application } = res.locals; + + if (!application) { + return res.redirect(PROBLEM_WITH_SERVICE); + } + + const { referenceNumber } = application; + + const payload = constructPayload(req.body, FIELD_IDS); + + const validationErrors = generateValidationErrors(payload); + + if (validationErrors) { + return res.render(TEMPLATE, { + ...insuranceCorePageVariables({ + PAGE_CONTENT_STRINGS, + BACK_LINK: req.headers.referer, + HTML_FLAGS, + }), + ...pageVariables(application.referenceNumber), + userName: getUserNameFromSession(req.session.user), + validationErrors, + submittedValues: sanitiseData(payload), + }); + } + + return res.redirect(`${INSURANCE_ROOT}/${referenceNumber}${ALL_SECTIONS}`); +}; diff --git a/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/index.test.ts b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/index.test.ts new file mode 100644 index 0000000000..7e487f8b1e --- /dev/null +++ b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/index.test.ts @@ -0,0 +1,15 @@ +import validation from '.'; +import validationRules from './rules'; +import combineValidationRules from '../../../../../helpers/combine-validation-rules'; + +describe('controllers/insurance/declarations/modern-slavery/validation', () => { + it('should return an array of results from rule functions', () => { + const mockFormBody = {}; + + const result = validation(mockFormBody); + + const expected = combineValidationRules(validationRules, mockFormBody); + + expect(result).toEqual(expected); + }); +}); diff --git a/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/index.ts b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/index.ts new file mode 100644 index 0000000000..d42a0d2786 --- /dev/null +++ b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/index.ts @@ -0,0 +1,7 @@ +import validationRules from './rules'; +import combineValidationRules from '../../../../../helpers/combine-validation-rules'; +import { RequestBody, ValidationErrors } from '../../../../../../types'; + +const validation = (formBody: RequestBody): ValidationErrors => combineValidationRules(validationRules, formBody) as ValidationErrors; + +export default validation; diff --git a/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/aware-of-existing-slavery/index.test.ts b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/aware-of-existing-slavery/index.test.ts new file mode 100644 index 0000000000..420f913f79 --- /dev/null +++ b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/aware-of-existing-slavery/index.test.ts @@ -0,0 +1,57 @@ +import awareOfExistingSlaveryRules from '.'; +import { MAXIMUM_CHARACTERS } from '../../../../../../../../constants'; +import DECLARATIONS_FIELD_IDS from '../../../../../../../../constants/field-ids/insurance/declarations'; +import { ERROR_MESSAGES } from '../../../../../../../../content-strings'; +import providedAndMaxLength from '../../../../../../../../shared-validation/provided-and-max-length'; +import { mockErrors } from '../../../../../../../../test-mocks'; + +const { + IS_NOT_AWARE_OF_EXISTING_SLAVERY, + CONDITIONAL_REASONS: { AWARE_OF_EXISTING_SLAVERY: FIELD_ID }, +} = DECLARATIONS_FIELD_IDS.MODERN_SLAVERY; + +const { + INSURANCE: { + DECLARATIONS: { + MODERN_SLAVERY: { + CONDITIONAL_REASONS: { [FIELD_ID]: ERROR_MESSAGES_OBJECT }, + }, + }, + }, +} = ERROR_MESSAGES; + +describe('controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/aware-of-existing-slavery', () => { + describe(`when ${IS_NOT_AWARE_OF_EXISTING_SLAVERY} is false`, () => { + const mockBody = { + [IS_NOT_AWARE_OF_EXISTING_SLAVERY]: 'false', + [FIELD_ID]: '', + }; + + it('should return the result of providedAndMaxLength', () => { + const result = awareOfExistingSlaveryRules(mockBody, mockErrors); + + const expected = providedAndMaxLength( + mockBody, + FIELD_ID, + ERROR_MESSAGES_OBJECT, + mockErrors, + MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON, + ); + + expect(result).toEqual(expected); + }); + }); + + describe(`when ${IS_NOT_AWARE_OF_EXISTING_SLAVERY} is true`, () => { + const mockBody = { + [IS_NOT_AWARE_OF_EXISTING_SLAVERY]: 'true', + [FIELD_ID]: '', + }; + + it('should return the provided errors', () => { + const result = awareOfExistingSlaveryRules(mockBody, mockErrors); + + expect(result).toEqual(mockErrors); + }); + }); +}); diff --git a/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/aware-of-existing-slavery/index.ts b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/aware-of-existing-slavery/index.ts new file mode 100644 index 0000000000..acb53c07cf --- /dev/null +++ b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/aware-of-existing-slavery/index.ts @@ -0,0 +1,36 @@ +import { MAXIMUM_CHARACTERS } from '../../../../../../../../constants'; +import DECLARATIONS_FIELD_IDS from '../../../../../../../../constants/field-ids/insurance/declarations'; +import { ERROR_MESSAGES } from '../../../../../../../../content-strings'; +import providedAndMaxLength from '../../../../../../../../shared-validation/provided-and-max-length'; +import { RequestBody } from '../../../../../../../../../types'; + +const { + IS_NOT_AWARE_OF_EXISTING_SLAVERY, + CONDITIONAL_REASONS: { AWARE_OF_EXISTING_SLAVERY: FIELD_ID }, +} = DECLARATIONS_FIELD_IDS.MODERN_SLAVERY; + +const { + INSURANCE: { + DECLARATIONS: { + MODERN_SLAVERY: { + CONDITIONAL_REASONS: { [FIELD_ID]: ERROR_MESSAGES_OBJECT }, + }, + }, + }, +} = ERROR_MESSAGES; + +/** + * awareOfExistingSlaveryRules + * @param {Express.Request.body} Express response body + * @param {Object} errors: Other validation errors for the same form + * @returns {ValidationErrors} providedAndMaxLength + */ +const awareOfExistingSlaveryRules = (formBody: RequestBody, errors: object) => { + if (formBody[IS_NOT_AWARE_OF_EXISTING_SLAVERY] === 'false') { + return providedAndMaxLength(formBody, FIELD_ID, ERROR_MESSAGES_OBJECT, errors, MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON); + } + + return errors; +}; + +export default awareOfExistingSlaveryRules; diff --git a/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/cannot-adhere-to-all-requirements/index.test.ts b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/cannot-adhere-to-all-requirements/index.test.ts new file mode 100644 index 0000000000..891023cf10 --- /dev/null +++ b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/cannot-adhere-to-all-requirements/index.test.ts @@ -0,0 +1,57 @@ +import cannotAdhereToAllRequirementsRules from '.'; +import { MAXIMUM_CHARACTERS } from '../../../../../../../../constants'; +import DECLARATIONS_FIELD_IDS from '../../../../../../../../constants/field-ids/insurance/declarations'; +import { ERROR_MESSAGES } from '../../../../../../../../content-strings'; +import providedAndMaxLength from '../../../../../../../../shared-validation/provided-and-max-length'; +import { mockErrors } from '../../../../../../../../test-mocks'; + +const { + WILL_ADHERE_TO_ALL_REQUIREMENTS, + CONDITIONAL_REASONS: { CANNOT_ADHERE_TO_ALL_REQUIREMENTS: FIELD_ID }, +} = DECLARATIONS_FIELD_IDS.MODERN_SLAVERY; + +const { + INSURANCE: { + DECLARATIONS: { + MODERN_SLAVERY: { + CONDITIONAL_REASONS: { [FIELD_ID]: ERROR_MESSAGES_OBJECT }, + }, + }, + }, +} = ERROR_MESSAGES; + +describe('controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/cannot-adhere-to-all-requirements', () => { + describe(`when ${WILL_ADHERE_TO_ALL_REQUIREMENTS} is false`, () => { + const mockBody = { + [WILL_ADHERE_TO_ALL_REQUIREMENTS]: 'false', + [FIELD_ID]: '', + }; + + it('should return the result of providedAndMaxLength', () => { + const result = cannotAdhereToAllRequirementsRules(mockBody, mockErrors); + + const expected = providedAndMaxLength( + mockBody, + FIELD_ID, + ERROR_MESSAGES_OBJECT, + mockErrors, + MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON, + ); + + expect(result).toEqual(expected); + }); + }); + + describe(`when ${WILL_ADHERE_TO_ALL_REQUIREMENTS} is true`, () => { + const mockBody = { + [WILL_ADHERE_TO_ALL_REQUIREMENTS]: 'true', + [FIELD_ID]: '', + }; + + it('should return the provided errors', () => { + const result = cannotAdhereToAllRequirementsRules(mockBody, mockErrors); + + expect(result).toEqual(mockErrors); + }); + }); +}); diff --git a/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/cannot-adhere-to-all-requirements/index.ts b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/cannot-adhere-to-all-requirements/index.ts new file mode 100644 index 0000000000..9bf2a90fe9 --- /dev/null +++ b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/cannot-adhere-to-all-requirements/index.ts @@ -0,0 +1,36 @@ +import { MAXIMUM_CHARACTERS } from '../../../../../../../../constants'; +import DECLARATIONS_FIELD_IDS from '../../../../../../../../constants/field-ids/insurance/declarations'; +import { ERROR_MESSAGES } from '../../../../../../../../content-strings'; +import providedAndMaxLength from '../../../../../../../../shared-validation/provided-and-max-length'; +import { RequestBody } from '../../../../../../../../../types'; + +const { + WILL_ADHERE_TO_ALL_REQUIREMENTS, + CONDITIONAL_REASONS: { CANNOT_ADHERE_TO_ALL_REQUIREMENTS: FIELD_ID }, +} = DECLARATIONS_FIELD_IDS.MODERN_SLAVERY; + +const { + INSURANCE: { + DECLARATIONS: { + MODERN_SLAVERY: { + CONDITIONAL_REASONS: { [FIELD_ID]: ERROR_MESSAGES_OBJECT }, + }, + }, + }, +} = ERROR_MESSAGES; + +/** + * cannotAdhereToAllRequirementsRules + * @param {Express.Request.body} Express response body + * @param {Object} errors: Other validation errors for the same form + * @returns {ValidationErrors} providedAndMaxLength + */ +const cannotAdhereToAllRequirementsRules = (formBody: RequestBody, errors: object) => { + if (formBody[WILL_ADHERE_TO_ALL_REQUIREMENTS] === 'false') { + return providedAndMaxLength(formBody, FIELD_ID, ERROR_MESSAGES_OBJECT, errors, MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON); + } + + return errors; +}; + +export default cannotAdhereToAllRequirementsRules; diff --git a/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/offenses-or-investigations/index.test.ts b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/offenses-or-investigations/index.test.ts new file mode 100644 index 0000000000..c5022221ad --- /dev/null +++ b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/offenses-or-investigations/index.test.ts @@ -0,0 +1,57 @@ +import offensesOrInvestigationsRules from '.'; +import { MAXIMUM_CHARACTERS } from '../../../../../../../../constants'; +import DECLARATIONS_FIELD_IDS from '../../../../../../../../constants/field-ids/insurance/declarations'; +import { ERROR_MESSAGES } from '../../../../../../../../content-strings'; +import providedAndMaxLength from '../../../../../../../../shared-validation/provided-and-max-length'; +import { mockErrors } from '../../../../../../../../test-mocks'; + +const { + HAS_NO_OFFENSES_OR_INVESTIGATIONS, + CONDITIONAL_REASONS: { OFFENSES_OR_INVESTIGATIONS: FIELD_ID }, +} = DECLARATIONS_FIELD_IDS.MODERN_SLAVERY; + +const { + INSURANCE: { + DECLARATIONS: { + MODERN_SLAVERY: { + CONDITIONAL_REASONS: { [FIELD_ID]: ERROR_MESSAGES_OBJECT }, + }, + }, + }, +} = ERROR_MESSAGES; + +describe('controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/offenses-or-investigations', () => { + describe(`when ${HAS_NO_OFFENSES_OR_INVESTIGATIONS} is false`, () => { + const mockBody = { + [HAS_NO_OFFENSES_OR_INVESTIGATIONS]: 'false', + [FIELD_ID]: '', + }; + + it('should return the result of providedAndMaxLength', () => { + const result = offensesOrInvestigationsRules(mockBody, mockErrors); + + const expected = providedAndMaxLength( + mockBody, + FIELD_ID, + ERROR_MESSAGES_OBJECT, + mockErrors, + MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON, + ); + + expect(result).toEqual(expected); + }); + }); + + describe(`when ${HAS_NO_OFFENSES_OR_INVESTIGATIONS} is true`, () => { + const mockBody = { + [HAS_NO_OFFENSES_OR_INVESTIGATIONS]: 'true', + [FIELD_ID]: '', + }; + + it('should return the provided errors', () => { + const result = offensesOrInvestigationsRules(mockBody, mockErrors); + + expect(result).toEqual(mockErrors); + }); + }); +}); diff --git a/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/offenses-or-investigations/index.ts b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/offenses-or-investigations/index.ts new file mode 100644 index 0000000000..d101a049d5 --- /dev/null +++ b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/offenses-or-investigations/index.ts @@ -0,0 +1,36 @@ +import { MAXIMUM_CHARACTERS } from '../../../../../../../../constants'; +import DECLARATIONS_FIELD_IDS from '../../../../../../../../constants/field-ids/insurance/declarations'; +import { ERROR_MESSAGES } from '../../../../../../../../content-strings'; +import providedAndMaxLength from '../../../../../../../../shared-validation/provided-and-max-length'; +import { RequestBody } from '../../../../../../../../../types'; + +const { + HAS_NO_OFFENSES_OR_INVESTIGATIONS, + CONDITIONAL_REASONS: { OFFENSES_OR_INVESTIGATIONS: FIELD_ID }, +} = DECLARATIONS_FIELD_IDS.MODERN_SLAVERY; + +const { + INSURANCE: { + DECLARATIONS: { + MODERN_SLAVERY: { + CONDITIONAL_REASONS: { [FIELD_ID]: ERROR_MESSAGES_OBJECT }, + }, + }, + }, +} = ERROR_MESSAGES; + +/** + * offensesOrInvestigationsRules + * @param {Express.Request.body} Express response body + * @param {Object} errors: Other validation errors for the same form + * @returns {ValidationErrors} providedAndMaxLength + */ +const offensesOrInvestigationsRules = (formBody: RequestBody, errors: object) => { + if (formBody[HAS_NO_OFFENSES_OR_INVESTIGATIONS] === 'false') { + return providedAndMaxLength(formBody, FIELD_ID, ERROR_MESSAGES_OBJECT, errors, MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON); + } + + return errors; +}; + +export default offensesOrInvestigationsRules; diff --git a/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/has-no-offenses-or-investigations/index.test.ts b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/has-no-offenses-or-investigations/index.test.ts new file mode 100644 index 0000000000..8bc77fbc90 --- /dev/null +++ b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/has-no-offenses-or-investigations/index.test.ts @@ -0,0 +1,29 @@ +import hasNoOffensesOrInvestigationsRule from '.'; +import DECLARATIONS_FIELD_IDS from '../../../../../../../constants/field-ids/insurance/declarations'; +import { ERROR_MESSAGES } from '../../../../../../../content-strings'; +import emptyFieldValidation from '../../../../../../../shared-validation/empty-field'; +import { mockErrors } from '../../../../../../../test-mocks'; + +const { HAS_NO_OFFENSES_OR_INVESTIGATIONS: FIELD_ID } = DECLARATIONS_FIELD_IDS.MODERN_SLAVERY; + +const { + INSURANCE: { + DECLARATIONS: { + MODERN_SLAVERY: { [FIELD_ID]: ERROR_MESSAGES_OBJECT }, + }, + }, +} = ERROR_MESSAGES; + +describe('controllers/insurance/declarations/modern-slavery/validation/rules/has-no-offenses-or-investigations', () => { + it('should return the result of emptyFieldValidation', () => { + const mockFormBody = { + [FIELD_ID]: 'true', + }; + + const result = hasNoOffensesOrInvestigationsRule(mockFormBody, mockErrors); + + const expected = emptyFieldValidation(mockFormBody, FIELD_ID, ERROR_MESSAGES_OBJECT.IS_EMPTY, mockErrors); + + expect(result).toEqual(expected); + }); +}); diff --git a/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/has-no-offenses-or-investigations/index.ts b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/has-no-offenses-or-investigations/index.ts new file mode 100644 index 0000000000..d0ee7f7938 --- /dev/null +++ b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/has-no-offenses-or-investigations/index.ts @@ -0,0 +1,26 @@ +import DECLARATIONS_FIELD_IDS from '../../../../../../../constants/field-ids/insurance/declarations'; +import { ERROR_MESSAGES } from '../../../../../../../content-strings'; +import emptyFieldValidation from '../../../../../../../shared-validation/empty-field'; +import { RequestBody } from '../../../../../../../../types'; + +const { HAS_NO_OFFENSES_OR_INVESTIGATIONS: FIELD_ID } = DECLARATIONS_FIELD_IDS.MODERN_SLAVERY; + +const { + INSURANCE: { + DECLARATIONS: { + MODERN_SLAVERY: { [FIELD_ID]: ERROR_MESSAGES_OBJECT }, + }, + }, +} = ERROR_MESSAGES; + +/** + * hasNoOffensesOrInvestigationsRule + * Returns the result of emptyFieldValidation + * @param {RequestBody} formBody: Form body + * @param {Object} errors: Errors from previous validation errors + * @returns {ValidationErrors} + */ +const hasNoOffensesOrInvestigationsRule = (formBody: RequestBody, errors: object) => + emptyFieldValidation(formBody, FIELD_ID, ERROR_MESSAGES_OBJECT.IS_EMPTY, errors); + +export default hasNoOffensesOrInvestigationsRule; diff --git a/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/index.ts b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/index.ts new file mode 100644 index 0000000000..832e992adf --- /dev/null +++ b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/index.ts @@ -0,0 +1,20 @@ +import willAdhereToAllRequirementsRule from './will-adhere-to-all-requirements'; +import cannotAdhereToAllRequirementsRules from './conditional-reasons/cannot-adhere-to-all-requirements'; +import hasNoOffensesOrInvestigationsRule from './has-no-offenses-or-investigations'; +import offensesOrInvestigationsRules from './conditional-reasons/offenses-or-investigations'; +import isNotAwareOfExistingSlavery from './is-not-aware-of-existing-slavery'; +import awareOfExistingSlaveryRules from './conditional-reasons/aware-of-existing-slavery'; +import { ValidationErrors } from '../../../../../../../types'; + +const rules = [ + willAdhereToAllRequirementsRule, + cannotAdhereToAllRequirementsRules, + hasNoOffensesOrInvestigationsRule, + offensesOrInvestigationsRules, + isNotAwareOfExistingSlavery, + awareOfExistingSlaveryRules, +]; + +const validationRules = rules as Array<() => ValidationErrors>; + +export default validationRules; diff --git a/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/is-not-aware-of-existing-slavery/index.test.ts b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/is-not-aware-of-existing-slavery/index.test.ts new file mode 100644 index 0000000000..bc53fb89a1 --- /dev/null +++ b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/is-not-aware-of-existing-slavery/index.test.ts @@ -0,0 +1,29 @@ +import isNotAwareOfExistingSlavery from '.'; +import DECLARATIONS_FIELD_IDS from '../../../../../../../constants/field-ids/insurance/declarations'; +import { ERROR_MESSAGES } from '../../../../../../../content-strings'; +import emptyFieldValidation from '../../../../../../../shared-validation/empty-field'; +import { mockErrors } from '../../../../../../../test-mocks'; + +const { IS_NOT_AWARE_OF_EXISTING_SLAVERY: FIELD_ID } = DECLARATIONS_FIELD_IDS.MODERN_SLAVERY; + +const { + INSURANCE: { + DECLARATIONS: { + MODERN_SLAVERY: { [FIELD_ID]: ERROR_MESSAGES_OBJECT }, + }, + }, +} = ERROR_MESSAGES; + +describe('controllers/insurance/declarations/modern-slavery/validation/rules/is-not-aware-of-existing-slavery', () => { + it('should return the result of emptyFieldValidation', () => { + const mockFormBody = { + [FIELD_ID]: 'true', + }; + + const result = isNotAwareOfExistingSlavery(mockFormBody, mockErrors); + + const expected = emptyFieldValidation(mockFormBody, FIELD_ID, ERROR_MESSAGES_OBJECT.IS_EMPTY, mockErrors); + + expect(result).toEqual(expected); + }); +}); diff --git a/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/is-not-aware-of-existing-slavery/index.ts b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/is-not-aware-of-existing-slavery/index.ts new file mode 100644 index 0000000000..288f1d4098 --- /dev/null +++ b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/is-not-aware-of-existing-slavery/index.ts @@ -0,0 +1,26 @@ +import DECLARATIONS_FIELD_IDS from '../../../../../../../constants/field-ids/insurance/declarations'; +import { ERROR_MESSAGES } from '../../../../../../../content-strings'; +import emptyFieldValidation from '../../../../../../../shared-validation/empty-field'; +import { RequestBody } from '../../../../../../../../types'; + +const { IS_NOT_AWARE_OF_EXISTING_SLAVERY: FIELD_ID } = DECLARATIONS_FIELD_IDS.MODERN_SLAVERY; + +const { + INSURANCE: { + DECLARATIONS: { + MODERN_SLAVERY: { [FIELD_ID]: ERROR_MESSAGES_OBJECT }, + }, + }, +} = ERROR_MESSAGES; + +/** + * isNotAwareOfExistingSlavery + * Returns the result of emptyFieldValidation + * else returns provided errors object + * @param {RequestBody} formBody: Form body + * @param {Object} errors: Errors from previous validation errors + * @returns {ValidationErrors} + */ +const isNotAwareOfExistingSlavery = (formBody: RequestBody, errors: object) => emptyFieldValidation(formBody, FIELD_ID, ERROR_MESSAGES_OBJECT.IS_EMPTY, errors); + +export default isNotAwareOfExistingSlavery; diff --git a/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/will-adhere-to-all-requirements/index.test.ts b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/will-adhere-to-all-requirements/index.test.ts new file mode 100644 index 0000000000..7189977a1f --- /dev/null +++ b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/will-adhere-to-all-requirements/index.test.ts @@ -0,0 +1,29 @@ +import willAdhereToAllRequirementsRule from '.'; +import DECLARATIONS_FIELD_IDS from '../../../../../../../constants/field-ids/insurance/declarations'; +import { ERROR_MESSAGES } from '../../../../../../../content-strings'; +import emptyFieldValidation from '../../../../../../../shared-validation/empty-field'; +import { mockErrors } from '../../../../../../../test-mocks'; + +const { WILL_ADHERE_TO_ALL_REQUIREMENTS: FIELD_ID } = DECLARATIONS_FIELD_IDS.MODERN_SLAVERY; + +const { + INSURANCE: { + DECLARATIONS: { + MODERN_SLAVERY: { [FIELD_ID]: ERROR_MESSAGES_OBJECT }, + }, + }, +} = ERROR_MESSAGES; + +describe('controllers/insurance/declarations/modern-slavery/validation/rules/will-adhere-to-all-requirements', () => { + it('should return the result of emptyFieldValidation', () => { + const mockFormBody = { + [FIELD_ID]: 'true', + }; + + const result = willAdhereToAllRequirementsRule(mockFormBody, mockErrors); + + const expected = emptyFieldValidation(mockFormBody, FIELD_ID, ERROR_MESSAGES_OBJECT.IS_EMPTY, mockErrors); + + expect(result).toEqual(expected); + }); +}); diff --git a/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/will-adhere-to-all-requirements/index.ts b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/will-adhere-to-all-requirements/index.ts new file mode 100644 index 0000000000..dc354fbde0 --- /dev/null +++ b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/will-adhere-to-all-requirements/index.ts @@ -0,0 +1,27 @@ +import DECLARATIONS_FIELD_IDS from '../../../../../../../constants/field-ids/insurance/declarations'; +import { ERROR_MESSAGES } from '../../../../../../../content-strings'; +import emptyFieldValidation from '../../../../../../../shared-validation/empty-field'; +import { RequestBody } from '../../../../../../../../types'; + +const { WILL_ADHERE_TO_ALL_REQUIREMENTS: FIELD_ID } = DECLARATIONS_FIELD_IDS.MODERN_SLAVERY; + +const { + INSURANCE: { + DECLARATIONS: { + MODERN_SLAVERY: { [FIELD_ID]: ERROR_MESSAGES_OBJECT }, + }, + }, +} = ERROR_MESSAGES; + +/** + * willAdhereToAllRequirementsRule + * Returns the result of emptyFieldValidation + * else returns provided errors object + * @param {RequestBody} formBody: Form body + * @param {Object} errors: Errors from previous validation errors + * @returns {ValidationErrors} + */ +const willAdhereToAllRequirementsRule = (formBody: RequestBody, errors: object) => + emptyFieldValidation(formBody, FIELD_ID, ERROR_MESSAGES_OBJECT.IS_EMPTY, errors); + +export default willAdhereToAllRequirementsRule; diff --git a/src/ui/server/routes/insurance/declarations/index.test.ts b/src/ui/server/routes/insurance/declarations/index.test.ts index 6a547893f9..499f66db10 100644 --- a/src/ui/server/routes/insurance/declarations/index.test.ts +++ b/src/ui/server/routes/insurance/declarations/index.test.ts @@ -7,7 +7,7 @@ import { get as exportingWithCodeOfConductGet, post as exportingWithCodeOfConductPost, } from '../../../controllers/insurance/declarations/anti-bribery/exporting-with-code-of-conduct'; -import { get as modernSlaveryGet } from '../../../controllers/insurance/declarations/modern-slavery'; +import { get as modernSlaveryGet, post as modernSlaveryPost } from '../../../controllers/insurance/declarations/modern-slavery'; import { get as confirmationAndAcknowledgementsGet, post as confirmationAndAcknowledgementsPost, @@ -25,7 +25,7 @@ describe('routes/insurance/declarations', () => { it('should setup all routes', () => { expect(get).toHaveBeenCalledTimes(6); - expect(post).toHaveBeenCalledTimes(10); + expect(post).toHaveBeenCalledTimes(11); expect(get).toHaveBeenCalledWith(`/:referenceNumber${INSURANCE_ROUTES.DECLARATIONS.CONFIDENTIALITY}`, confidentialityGet); expect(post).toHaveBeenCalledWith(`/:referenceNumber${INSURANCE_ROUTES.DECLARATIONS.CONFIDENTIALITY}`, confidentialityPost); @@ -55,6 +55,7 @@ describe('routes/insurance/declarations', () => { ); expect(get).toHaveBeenCalledWith(`/:referenceNumber${INSURANCE_ROUTES.DECLARATIONS.MODERN_SLAVERY}`, modernSlaveryGet); + expect(post).toHaveBeenCalledWith(`/:referenceNumber${INSURANCE_ROUTES.DECLARATIONS.MODERN_SLAVERY}`, modernSlaveryPost); expect(get).toHaveBeenCalledWith(`/:referenceNumber${INSURANCE_ROUTES.DECLARATIONS.CONFIRMATION_AND_ACKNOWLEDGEMENTS}`, confirmationAndAcknowledgementsGet); diff --git a/src/ui/server/routes/insurance/declarations/index.ts b/src/ui/server/routes/insurance/declarations/index.ts index 60bbdbf6d1..daa9543090 100644 --- a/src/ui/server/routes/insurance/declarations/index.ts +++ b/src/ui/server/routes/insurance/declarations/index.ts @@ -7,7 +7,7 @@ import { get as exportingWithCodeOfConductGet, post as exportingWithCodeOfConductPost, } from '../../../controllers/insurance/declarations/anti-bribery/exporting-with-code-of-conduct'; -import { get as modernSlaveryGet } from '../../../controllers/insurance/declarations/modern-slavery'; +import { get as modernSlaveryGet, post as modernSlaveryPost } from '../../../controllers/insurance/declarations/modern-slavery'; import { get as confirmationAndAcknowledgementsGet, post as confirmationAndAcknowledgementsPost, @@ -42,6 +42,7 @@ insuranceDeclarationsRouter.post( ); insuranceDeclarationsRouter.get(`/:referenceNumber${INSURANCE_ROUTES.DECLARATIONS.MODERN_SLAVERY}`, modernSlaveryGet); +insuranceDeclarationsRouter.post(`/:referenceNumber${INSURANCE_ROUTES.DECLARATIONS.MODERN_SLAVERY}`, modernSlaveryPost); insuranceDeclarationsRouter.get(`/:referenceNumber${INSURANCE_ROUTES.DECLARATIONS.CONFIRMATION_AND_ACKNOWLEDGEMENTS}`, confirmationAndAcknowledgementsGet); insuranceDeclarationsRouter.post(`/:referenceNumber${INSURANCE_ROUTES.DECLARATIONS.CONFIRMATION_AND_ACKNOWLEDGEMENTS}`, confirmationAndAcknowledgementsPost); diff --git a/src/ui/server/routes/insurance/index.test.ts b/src/ui/server/routes/insurance/index.test.ts index c03ca4e4b2..e00d6f2441 100644 --- a/src/ui/server/routes/insurance/index.test.ts +++ b/src/ui/server/routes/insurance/index.test.ts @@ -22,7 +22,7 @@ describe('routes/insurance', () => { it('should setup all routes', () => { expect(get).toHaveBeenCalledTimes(220); - expect(post).toHaveBeenCalledTimes(228); + expect(post).toHaveBeenCalledTimes(229); expect(get).toHaveBeenCalledWith(INSURANCE_ROUTES.START, startGet); diff --git a/src/ui/templates/partials/insurance/declarations/modern-slavery/has-no-offenses-or-investigations.njk b/src/ui/templates/partials/insurance/declarations/modern-slavery/has-no-offenses-or-investigations.njk index 9bed637c01..4b0ceb195b 100644 --- a/src/ui/templates/partials/insurance/declarations/modern-slavery/has-no-offenses-or-investigations.njk +++ b/src/ui/templates/partials/insurance/declarations/modern-slavery/has-no-offenses-or-investigations.njk @@ -4,13 +4,16 @@ {% include "partials/insurance/declarations/modern-slavery/conditional-reasons/offenses-or-investigations.njk" %} {% endset %} +{% set fieldId = FIELDS.HAS_NO_OFFENSES_OR_INVESTIGATIONS.ID %} + {{ yesNoRadioButtons.render({ - fieldId: FIELDS.HAS_NO_OFFENSES_OR_INVESTIGATIONS.ID, + fieldId: fieldId, legendText: FIELDS.HAS_NO_OFFENSES_OR_INVESTIGATIONS.LABEL, legendClass: 'govuk-fieldset__legend--s', legendSpan: true, - errorMessage: validationErrors.errorList[FIELDS.HAS_NO_OFFENSES_OR_INVESTIGATIONS.ID], - dataCyLegend: FIELDS.HAS_NO_OFFENSES_OR_INVESTIGATIONS.ID + '-legend', + errorMessage: validationErrors.errorList[fieldId], + dataCyLegend: fieldId + '-legend', horizontalRadios: HORIZONTAL_RADIOS, - conditionalNoHtml: conditionalNoHtml + conditionalNoHtml: conditionalNoHtml, + submittedAnswer: submittedValues[fieldId] }) }} diff --git a/src/ui/templates/partials/insurance/declarations/modern-slavery/is-not-aware-of-existing-slavery.njk b/src/ui/templates/partials/insurance/declarations/modern-slavery/is-not-aware-of-existing-slavery.njk index 38c8cc73ff..5bca9767d1 100644 --- a/src/ui/templates/partials/insurance/declarations/modern-slavery/is-not-aware-of-existing-slavery.njk +++ b/src/ui/templates/partials/insurance/declarations/modern-slavery/is-not-aware-of-existing-slavery.njk @@ -4,13 +4,16 @@ {% include "partials/insurance/declarations/modern-slavery/conditional-reasons/aware-of-existing-slavery.njk" %} {% endset %} +{% set fieldId = FIELDS.IS_NOT_AWARE_OF_EXISTING_SLAVERY.ID %} + {{ yesNoRadioButtons.render({ - fieldId: FIELDS.IS_NOT_AWARE_OF_EXISTING_SLAVERY.ID, + fieldId: fieldId, legendText: FIELDS.IS_NOT_AWARE_OF_EXISTING_SLAVERY.LABEL, legendClass: 'govuk-fieldset__legend--s', legendSpan: true, - errorMessage: validationErrors.errorList[FIELDS.IS_NOT_AWARE_OF_EXISTING_SLAVERY.ID], - dataCyLegend: FIELDS.IS_NOT_AWARE_OF_EXISTING_SLAVERY.ID + '-legend', + errorMessage: validationErrors.errorList[fieldId], + dataCyLegend: fieldId + '-legend', horizontalRadios: HORIZONTAL_RADIOS, - conditionalNoHtml: conditionalNoHtml + conditionalNoHtml: conditionalNoHtml, + submittedAnswer: submittedValues[fieldId] }) }} diff --git a/src/ui/templates/partials/insurance/declarations/modern-slavery/will-adhere-to-all-requirements.njk b/src/ui/templates/partials/insurance/declarations/modern-slavery/will-adhere-to-all-requirements.njk index 121643e97e..bc3b35c0cf 100644 --- a/src/ui/templates/partials/insurance/declarations/modern-slavery/will-adhere-to-all-requirements.njk +++ b/src/ui/templates/partials/insurance/declarations/modern-slavery/will-adhere-to-all-requirements.njk @@ -4,13 +4,16 @@ {% include "partials/insurance/declarations/modern-slavery/conditional-reasons/cannot-adhere-to-all-requirements.njk" %} {% endset %} +{% set fieldId = FIELDS.WILL_ADHERE_TO_ALL_REQUIREMENTS.ID %} + {{ yesNoRadioButtons.render({ - fieldId: FIELDS.WILL_ADHERE_TO_ALL_REQUIREMENTS.ID, + fieldId: fieldId, legendText: FIELDS.WILL_ADHERE_TO_ALL_REQUIREMENTS.LABEL, legendClass: 'govuk-fieldset__legend--s', legendSpan: true, - errorMessage: validationErrors.errorList[FIELDS.WILL_ADHERE_TO_ALL_REQUIREMENTS.ID], - dataCyLegend: FIELDS.WILL_ADHERE_TO_ALL_REQUIREMENTS.ID + '-legend', + errorMessage: validationErrors.errorList[fieldId], + dataCyLegend: fieldId + '-legend', horizontalRadios: HORIZONTAL_RADIOS, - conditionalNoHtml: conditionalNoHtml + conditionalNoHtml: conditionalNoHtml, + submittedAnswer: submittedValues[fieldId] }) }} From 054e40e7379483405d408afbc85e6907318bf27f Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Sat, 14 Dec 2024 15:57:29 +0000 Subject: [PATCH 6/9] chore(e2e): cypress command improvements --- ...e-and-submit-anti-bribery-code-of-conduct-form.js | 4 +++- .../complete-and-submit-anti-bribery-form.js | 4 +++- .../complete-and-submit-confidentiality-form.js | 4 +++- ...-submit-confirmation-and-acknowledgements-form.js | 4 +++- .../complete-and-submit-modern-slavery-form.js | 10 ++++++++++ ...omplete-modern-slavery-form-conditional-fields.js | 7 +++++++ .../declarations/complete-modern-slavery-form.js | 12 ++++++++++-- 7 files changed, 39 insertions(+), 6 deletions(-) diff --git a/e2e-tests/commands/insurance/declarations/complete-and-submit-anti-bribery-code-of-conduct-form.js b/e2e-tests/commands/insurance/declarations/complete-and-submit-anti-bribery-code-of-conduct-form.js index a960f6f7b5..12de9fd021 100644 --- a/e2e-tests/commands/insurance/declarations/complete-and-submit-anti-bribery-code-of-conduct-form.js +++ b/e2e-tests/commands/insurance/declarations/complete-and-submit-anti-bribery-code-of-conduct-form.js @@ -4,7 +4,7 @@ import { FIELD_VALUES } from '../../../constants'; * completeAndSubmitDeclarationAntiBriberyCodeOfConduct * @param {String} Yes/no answer */ -export default (answer) => { +const completeAndSubmitDeclarationAntiBriberyCodeOfConduct = (answer) => { if (answer === FIELD_VALUES.NO) { cy.clickNoRadioInput(); } else { @@ -13,3 +13,5 @@ export default (answer) => { cy.clickSubmitButton(); }; + +export default completeAndSubmitDeclarationAntiBriberyCodeOfConduct; diff --git a/e2e-tests/commands/insurance/declarations/complete-and-submit-anti-bribery-form.js b/e2e-tests/commands/insurance/declarations/complete-and-submit-anti-bribery-form.js index 524df4f610..12ffb82fe5 100644 --- a/e2e-tests/commands/insurance/declarations/complete-and-submit-anti-bribery-form.js +++ b/e2e-tests/commands/insurance/declarations/complete-and-submit-anti-bribery-form.js @@ -3,8 +3,10 @@ import { singleInputField } from '../../../pages/shared'; const FIELD_ID = FIELD_IDS.INSURANCE.DECLARATIONS.AGREE_ANTI_BRIBERY; -export default () => { +const completeAndSubmitAntiBriberyForm = () => { singleInputField(FIELD_ID).label().click(); cy.clickSubmitButton(); }; + +export default completeAndSubmitAntiBriberyForm; diff --git a/e2e-tests/commands/insurance/declarations/complete-and-submit-confidentiality-form.js b/e2e-tests/commands/insurance/declarations/complete-and-submit-confidentiality-form.js index b795569ebd..b94d0d59d0 100644 --- a/e2e-tests/commands/insurance/declarations/complete-and-submit-confidentiality-form.js +++ b/e2e-tests/commands/insurance/declarations/complete-and-submit-confidentiality-form.js @@ -3,8 +3,10 @@ import { singleInputField } from '../../../pages/shared'; const FIELD_ID = FIELD_IDS.INSURANCE.DECLARATIONS.AGREE_CONFIDENTIALITY; -export default () => { +const completeAndSubmitConfidentialityForm = () => { singleInputField(FIELD_ID).label().click(); cy.clickSubmitButton(); }; + +export default completeAndSubmitConfidentialityForm; diff --git a/e2e-tests/commands/insurance/declarations/complete-and-submit-confirmation-and-acknowledgements-form.js b/e2e-tests/commands/insurance/declarations/complete-and-submit-confirmation-and-acknowledgements-form.js index 9830f4f5bf..108f88f41b 100644 --- a/e2e-tests/commands/insurance/declarations/complete-and-submit-confirmation-and-acknowledgements-form.js +++ b/e2e-tests/commands/insurance/declarations/complete-and-submit-confirmation-and-acknowledgements-form.js @@ -3,8 +3,10 @@ import { singleInputField } from '../../../pages/shared'; const FIELD_ID = FIELD_IDS.INSURANCE.DECLARATIONS.AGREE_CONFIRMATION_ACKNOWLEDGEMENTS; -export default () => { +const completeAndSubmitConfirmationAndAcknowledgementsForm = () => { singleInputField(FIELD_ID).label().click(); cy.clickSubmitButton(); }; + +export default completeAndSubmitConfirmationAndAcknowledgementsForm; diff --git a/e2e-tests/commands/insurance/declarations/complete-and-submit-modern-slavery-form.js b/e2e-tests/commands/insurance/declarations/complete-and-submit-modern-slavery-form.js index 9a81a844b9..4da427e400 100644 --- a/e2e-tests/commands/insurance/declarations/complete-and-submit-modern-slavery-form.js +++ b/e2e-tests/commands/insurance/declarations/complete-and-submit-modern-slavery-form.js @@ -1,3 +1,13 @@ +/** + * completeAndSubmitModernSlaveryForm + * complete and submit the "modern slavery" form. + * @param {Boolean} willAdhereToAllRequirements: radio answer + * @param {Boolean} hasNoOffensesOrInvestigations: radio answer + * @param {Boolean} isNotAwareOfExistingSlavery: radio answer + * @param {String} conditionalFields.cannotAdhereToAllRequirements: Textarea answer + * @param {String} conditionalFields.offensesOrInvestigations: Textarea answer + * @param {String} conditionalFields.awareOfExistingSlavery: Textarea answer + */ const completeAndSubmitModernSlaveryForm = ({ willAdhereToAllRequirements, hasNoOffensesOrInvestigations, diff --git a/e2e-tests/commands/insurance/declarations/complete-modern-slavery-form-conditional-fields.js b/e2e-tests/commands/insurance/declarations/complete-modern-slavery-form-conditional-fields.js index bafc5f24de..167b789ebe 100644 --- a/e2e-tests/commands/insurance/declarations/complete-modern-slavery-form-conditional-fields.js +++ b/e2e-tests/commands/insurance/declarations/complete-modern-slavery-form-conditional-fields.js @@ -7,6 +7,13 @@ const { }, } = DECLARATIONS_FIELD_IDS; +/** + * completeModernSlaveryFormConditionalFields + * complete the conditional "modern slavery" form fields. + * @param {String} cannotAdhereToAllRequirements: Textarea answer + * @param {String} offensesOrInvestigations: Textarea answer + * @param {String} awareOfExistingSlavery: Textarea answer + */ const completeModernSlaveryFormConditionalFields = ({ cannotAdhereToAllRequirements, offensesOrInvestigations, awareOfExistingSlavery }) => { if (cannotAdhereToAllRequirements) { cy.keyboardInput(autoCompleteField(CANNOT_ADHERE_TO_ALL_REQUIREMENTS).input(), cannotAdhereToAllRequirements); diff --git a/e2e-tests/commands/insurance/declarations/complete-modern-slavery-form.js b/e2e-tests/commands/insurance/declarations/complete-modern-slavery-form.js index 7075a033b5..d25277d04d 100644 --- a/e2e-tests/commands/insurance/declarations/complete-modern-slavery-form.js +++ b/e2e-tests/commands/insurance/declarations/complete-modern-slavery-form.js @@ -1,3 +1,13 @@ +/** + * completeModernSlaveryForm + * complete the "modern slavery" form. + * @param {Boolean} willAdhereToAllRequirements: radio answer + * @param {Boolean} hasNoOffensesOrInvestigations: radio answer + * @param {Boolean} isNotAwareOfExistingSlavery: radio answer + * @param {String} conditionalFields.cannotAdhereToAllRequirements: Textarea answer + * @param {String} conditionalFields.offensesOrInvestigations: Textarea answer + * @param {String} conditionalFields.awareOfExistingSlavery: Textarea answer + */ const completeModernSlaveryForm = ({ willAdhereToAllRequirements = true, hasNoOffensesOrInvestigations = true, @@ -35,6 +45,4 @@ const completeModernSlaveryForm = ({ cy.completeModernSlaveryFormConditionalFields(conditionalFields); }; -// TODO: update other declration commands functions to have a function name - export default completeModernSlaveryForm; From 8421f1de0d839a41cff3c17cb2af437e085417c4 Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Sat, 14 Dec 2024 16:15:15 +0000 Subject: [PATCH 7/9] feat(EMS-4024): improve e2e test coverage --- ...lavery-validation-all-radios-as-no.spec.js | 86 +++++++++++++++++++ ...dern-slavery-validation-empty-form.spec.js | 66 ++++++-------- 2 files changed, 114 insertions(+), 38 deletions(-) create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/validation/modern-slavery-validation-all-radios-as-no.spec.js diff --git a/e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/validation/modern-slavery-validation-all-radios-as-no.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/validation/modern-slavery-validation-all-radios-as-no.spec.js new file mode 100644 index 0000000000..a199c6b50e --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/validation/modern-slavery-validation-all-radios-as-no.spec.js @@ -0,0 +1,86 @@ +import { autoCompleteField } from '../../../../../../../pages/shared'; +import { ERROR_MESSAGES } from '../../../../../../../content-strings'; +import { DECLARATIONS as DECLARATIONS_FIELD_IDS } from '../../../../../../../constants/field-ids/insurance/declarations'; +import { INSURANCE_ROUTES } from '../../../../../../../constants/routes/insurance'; + +const { + ROOT: INSURANCE_ROOT, + DECLARATIONS: { MODERN_SLAVERY }, +} = INSURANCE_ROUTES; + +const { + MODERN_SLAVERY: { + CONDITIONAL_REASONS: { CANNOT_ADHERE_TO_ALL_REQUIREMENTS, OFFENSES_OR_INVESTIGATIONS, AWARE_OF_EXISTING_SLAVERY }, + }, +} = DECLARATIONS_FIELD_IDS; + +const ERROR_STRINGS = ERROR_MESSAGES.INSURANCE.DECLARATIONS.MODERN_SLAVERY; + +const errorSummaryLength = 3; + +const baseUrl = Cypress.config('baseUrl'); + +context('Insurance - Declarations - Modern slavery page - validation - submitting all radios as no', () => { + let referenceNumber; + let url; + + before(() => { + cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => { + referenceNumber = refNumber; + + url = `${baseUrl}${INSURANCE_ROOT}/${referenceNumber}${MODERN_SLAVERY}`; + + cy.navigateToUrl(url); + cy.assertUrl(url); + }); + }); + + beforeEach(() => { + cy.saveSession(); + + cy.navigateToUrl(url); + + cy.completeAndSubmitModernSlaveryForm({ + willAdhereToAllRequirements: false, + hasNoOffensesOrInvestigations: false, + isNotAwareOfExistingSlavery: false, + }); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it(`should render a ${CANNOT_ADHERE_TO_ALL_REQUIREMENTS} validation error`, () => { + const fieldId = CANNOT_ADHERE_TO_ALL_REQUIREMENTS; + + cy.assertFieldErrors({ + field: autoCompleteField(fieldId), + errorIndex: 0, + errorSummaryLength, + errorMessage: ERROR_STRINGS.CONDITIONAL_REASONS[fieldId].IS_EMPTY, + }); + }); + + it(`should render a ${OFFENSES_OR_INVESTIGATIONS} validation error`, () => { + const fieldId = OFFENSES_OR_INVESTIGATIONS; + + cy.assertFieldErrors({ + field: autoCompleteField(fieldId), + errorIndex: 1, + errorSummaryLength, + errorMessage: ERROR_STRINGS.CONDITIONAL_REASONS[fieldId].IS_EMPTY, + }); + }); + + it(`should render a ${AWARE_OF_EXISTING_SLAVERY} validation error`, () => { + const fieldId = AWARE_OF_EXISTING_SLAVERY; + + cy.assertFieldErrors({ + field: autoCompleteField(fieldId), + errorIndex: 2, + errorSummaryLength, + errorMessage: ERROR_STRINGS.CONDITIONAL_REASONS[fieldId].IS_EMPTY, + }); + }); +}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/validation/modern-slavery-validation-empty-form.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/validation/modern-slavery-validation-empty-form.spec.js index e95c7f06d7..e983a06e15 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/validation/modern-slavery-validation-empty-form.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/declarations/modern-slavery/validation/modern-slavery-validation-empty-form.spec.js @@ -14,9 +14,11 @@ const { const ERROR_STRINGS = ERROR_MESSAGES.INSURANCE.DECLARATIONS.MODERN_SLAVERY; +const expectedErrorsCount = 3; + const baseUrl = Cypress.config('baseUrl'); -context('Insurance - Declarations - Modern slavery page - validation - empty form', () => { +context('Insurance - Declarations - Modern slavery page - validation - submitting an empty form', () => { let referenceNumber; let url; @@ -35,53 +37,41 @@ context('Insurance - Declarations - Modern slavery page - validation - empty for cy.saveSession(); cy.navigateToUrl(url); + + cy.clickSubmitButton(); }); after(() => { cy.deleteApplication(referenceNumber); }); - describe('when submitting an empty form', () => { - const expectedErrorsCount = 3; - - beforeEach(() => { - cy.navigateToUrl(url); - - cy.clickSubmitButton(); - }); - - it(`should render ${WILL_ADHERE_TO_ALL_REQUIREMENTS} validation error`, () => { - cy.submitAndAssertRadioErrors({ - errorIndex: 0, - field: yesRadio(WILL_ADHERE_TO_ALL_REQUIREMENTS), - expectedErrorsCount, - expectedErrorMessage: ERROR_STRINGS[WILL_ADHERE_TO_ALL_REQUIREMENTS].IS_EMPTY, - fieldShouldGainFocus: true, - }); + it(`should render ${WILL_ADHERE_TO_ALL_REQUIREMENTS} validation error`, () => { + cy.submitAndAssertRadioErrors({ + errorIndex: 0, + field: yesRadio(WILL_ADHERE_TO_ALL_REQUIREMENTS), + expectedErrorsCount, + expectedErrorMessage: ERROR_STRINGS[WILL_ADHERE_TO_ALL_REQUIREMENTS].IS_EMPTY, + fieldShouldGainFocus: true, }); + }); - it(`should render ${HAS_NO_OFFENSES_OR_INVESTIGATIONS} validation error`, () => { - cy.submitAndAssertRadioErrors({ - errorIndex: 1, - field: yesRadio(HAS_NO_OFFENSES_OR_INVESTIGATIONS), - expectedErrorsCount, - expectedErrorMessage: ERROR_STRINGS[HAS_NO_OFFENSES_OR_INVESTIGATIONS].IS_EMPTY, - fieldShouldGainFocus: true, - }); + it(`should render ${HAS_NO_OFFENSES_OR_INVESTIGATIONS} validation error`, () => { + cy.submitAndAssertRadioErrors({ + errorIndex: 1, + field: yesRadio(HAS_NO_OFFENSES_OR_INVESTIGATIONS), + expectedErrorsCount, + expectedErrorMessage: ERROR_STRINGS[HAS_NO_OFFENSES_OR_INVESTIGATIONS].IS_EMPTY, + fieldShouldGainFocus: true, }); + }); - it(`should render ${IS_NOT_AWARE_OF_EXISTING_SLAVERY} validation error`, () => { - cy.submitAndAssertRadioErrors({ - errorIndex: 2, - field: yesRadio(IS_NOT_AWARE_OF_EXISTING_SLAVERY), - expectedErrorsCount, - expectedErrorMessage: ERROR_STRINGS[IS_NOT_AWARE_OF_EXISTING_SLAVERY].IS_EMPTY, - fieldShouldGainFocus: true, - }); + it(`should render ${IS_NOT_AWARE_OF_EXISTING_SLAVERY} validation error`, () => { + cy.submitAndAssertRadioErrors({ + errorIndex: 2, + field: yesRadio(IS_NOT_AWARE_OF_EXISTING_SLAVERY), + expectedErrorsCount, + expectedErrorMessage: ERROR_STRINGS[IS_NOT_AWARE_OF_EXISTING_SLAVERY].IS_EMPTY, + fieldShouldGainFocus: true, }); }); - - // TODO - // TODO - // TODO: submit all as no }); From ca73a7faba6d2d644b60d53d2dbdf2b136e18a76 Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Tue, 17 Dec 2024 11:10:11 +0000 Subject: [PATCH 8/9] chore(e2e): documentation improvements --- ...submit-anti-bribery-exporting-with-code-of-conduct-form.js | 1 + .../declarations/complete-and-submit-anti-bribery-form.js | 4 ++++ .../declarations/complete-and-submit-confidentiality-form.js | 4 ++++ ...plete-and-submit-confirmation-and-acknowledgements-form.js | 4 ++++ .../declarations/complete-and-submit-modern-slavery-form.js | 4 +--- 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/e2e-tests/commands/insurance/declarations/complete-and-submit-anti-bribery-exporting-with-code-of-conduct-form.js b/e2e-tests/commands/insurance/declarations/complete-and-submit-anti-bribery-exporting-with-code-of-conduct-form.js index 3ab6c73abf..b51a862f1c 100644 --- a/e2e-tests/commands/insurance/declarations/complete-and-submit-anti-bribery-exporting-with-code-of-conduct-form.js +++ b/e2e-tests/commands/insurance/declarations/complete-and-submit-anti-bribery-exporting-with-code-of-conduct-form.js @@ -2,6 +2,7 @@ import { FIELD_VALUES } from '../../../constants'; /** * completeAndSubmitAntiBriberyExportingWithCodeOfConductForm + * Complete and submit the "anti-bribery - exporting with code of conduct" form. * @param {String} Yes/no answer */ const completeAndSubmitAntiBriberyExportingWithCodeOfConductForm = (answer) => { diff --git a/e2e-tests/commands/insurance/declarations/complete-and-submit-anti-bribery-form.js b/e2e-tests/commands/insurance/declarations/complete-and-submit-anti-bribery-form.js index 12ffb82fe5..f39424491b 100644 --- a/e2e-tests/commands/insurance/declarations/complete-and-submit-anti-bribery-form.js +++ b/e2e-tests/commands/insurance/declarations/complete-and-submit-anti-bribery-form.js @@ -3,6 +3,10 @@ import { singleInputField } from '../../../pages/shared'; const FIELD_ID = FIELD_IDS.INSURANCE.DECLARATIONS.AGREE_ANTI_BRIBERY; +/** + * completeAndSubmitAntiBriberyForm + * Complete and submit the "anti-bribery" form. + */ const completeAndSubmitAntiBriberyForm = () => { singleInputField(FIELD_ID).label().click(); diff --git a/e2e-tests/commands/insurance/declarations/complete-and-submit-confidentiality-form.js b/e2e-tests/commands/insurance/declarations/complete-and-submit-confidentiality-form.js index b94d0d59d0..e337a74e48 100644 --- a/e2e-tests/commands/insurance/declarations/complete-and-submit-confidentiality-form.js +++ b/e2e-tests/commands/insurance/declarations/complete-and-submit-confidentiality-form.js @@ -3,6 +3,10 @@ import { singleInputField } from '../../../pages/shared'; const FIELD_ID = FIELD_IDS.INSURANCE.DECLARATIONS.AGREE_CONFIDENTIALITY; +/** + * completeAndSubmitConfidentialityForm + * Complete and submit the "confidentiality" form. + */ const completeAndSubmitConfidentialityForm = () => { singleInputField(FIELD_ID).label().click(); diff --git a/e2e-tests/commands/insurance/declarations/complete-and-submit-confirmation-and-acknowledgements-form.js b/e2e-tests/commands/insurance/declarations/complete-and-submit-confirmation-and-acknowledgements-form.js index 108f88f41b..6c9bf7264c 100644 --- a/e2e-tests/commands/insurance/declarations/complete-and-submit-confirmation-and-acknowledgements-form.js +++ b/e2e-tests/commands/insurance/declarations/complete-and-submit-confirmation-and-acknowledgements-form.js @@ -3,6 +3,10 @@ import { singleInputField } from '../../../pages/shared'; const FIELD_ID = FIELD_IDS.INSURANCE.DECLARATIONS.AGREE_CONFIRMATION_ACKNOWLEDGEMENTS; +/** + * completeAndSubmitConfirmationAndAcknowledgementsForm + * Complete and submit the "confirmation and acknowledgements" form. + */ const completeAndSubmitConfirmationAndAcknowledgementsForm = () => { singleInputField(FIELD_ID).label().click(); diff --git a/e2e-tests/commands/insurance/declarations/complete-and-submit-modern-slavery-form.js b/e2e-tests/commands/insurance/declarations/complete-and-submit-modern-slavery-form.js index 4da427e400..8d579eec4b 100644 --- a/e2e-tests/commands/insurance/declarations/complete-and-submit-modern-slavery-form.js +++ b/e2e-tests/commands/insurance/declarations/complete-and-submit-modern-slavery-form.js @@ -1,6 +1,6 @@ /** * completeAndSubmitModernSlaveryForm - * complete and submit the "modern slavery" form. + * Complete and submit the "modern slavery" form. * @param {Boolean} willAdhereToAllRequirements: radio answer * @param {Boolean} hasNoOffensesOrInvestigations: radio answer * @param {Boolean} isNotAwareOfExistingSlavery: radio answer @@ -28,6 +28,4 @@ const completeAndSubmitModernSlaveryForm = ({ cy.clickSubmitButton(); }; -// TODO: update other declration commands functions to have a function name - export default completeAndSubmitModernSlaveryForm; From f354dd6b166a3dec63877dc72703e6d40cd53382 Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Tue, 17 Dec 2024 11:59:13 +0000 Subject: [PATCH 9/9] feat(EMS-4024): readability improvement --- .../insurance/declarations/modern-slavery/index.ts | 2 +- .../conditional-reasons/aware-of-existing-slavery/index.ts | 4 +++- .../cannot-adhere-to-all-requirements/index.ts | 4 +++- .../conditional-reasons/offenses-or-investigations/index.ts | 4 +++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/ui/server/controllers/insurance/declarations/modern-slavery/index.ts b/src/ui/server/controllers/insurance/declarations/modern-slavery/index.ts index 58aebee5a6..c606ccf8e9 100644 --- a/src/ui/server/controllers/insurance/declarations/modern-slavery/index.ts +++ b/src/ui/server/controllers/insurance/declarations/modern-slavery/index.ts @@ -104,7 +104,7 @@ export const get = (req: Request, res: Response) => { * @param {Express.Response} Express response * @returns {Express.Response.redirect} Next part of the flow or error page */ -export const post = async (req: Request, res: Response) => { +export const post = (req: Request, res: Response) => { const { application } = res.locals; if (!application) { diff --git a/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/aware-of-existing-slavery/index.ts b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/aware-of-existing-slavery/index.ts index acb53c07cf..4bb37596e2 100644 --- a/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/aware-of-existing-slavery/index.ts +++ b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/aware-of-existing-slavery/index.ts @@ -19,6 +19,8 @@ const { }, } = ERROR_MESSAGES; +const MAXIMUM = MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON; + /** * awareOfExistingSlaveryRules * @param {Express.Request.body} Express response body @@ -27,7 +29,7 @@ const { */ const awareOfExistingSlaveryRules = (formBody: RequestBody, errors: object) => { if (formBody[IS_NOT_AWARE_OF_EXISTING_SLAVERY] === 'false') { - return providedAndMaxLength(formBody, FIELD_ID, ERROR_MESSAGES_OBJECT, errors, MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON); + return providedAndMaxLength(formBody, FIELD_ID, ERROR_MESSAGES_OBJECT, errors, MAXIMUM); } return errors; diff --git a/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/cannot-adhere-to-all-requirements/index.ts b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/cannot-adhere-to-all-requirements/index.ts index 9bf2a90fe9..07c7eeb342 100644 --- a/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/cannot-adhere-to-all-requirements/index.ts +++ b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/cannot-adhere-to-all-requirements/index.ts @@ -19,6 +19,8 @@ const { }, } = ERROR_MESSAGES; +const MAXIMUM = MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON; + /** * cannotAdhereToAllRequirementsRules * @param {Express.Request.body} Express response body @@ -27,7 +29,7 @@ const { */ const cannotAdhereToAllRequirementsRules = (formBody: RequestBody, errors: object) => { if (formBody[WILL_ADHERE_TO_ALL_REQUIREMENTS] === 'false') { - return providedAndMaxLength(formBody, FIELD_ID, ERROR_MESSAGES_OBJECT, errors, MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON); + return providedAndMaxLength(formBody, FIELD_ID, ERROR_MESSAGES_OBJECT, errors, MAXIMUM); } return errors; diff --git a/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/offenses-or-investigations/index.ts b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/offenses-or-investigations/index.ts index d101a049d5..b61dda3195 100644 --- a/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/offenses-or-investigations/index.ts +++ b/src/ui/server/controllers/insurance/declarations/modern-slavery/validation/rules/conditional-reasons/offenses-or-investigations/index.ts @@ -19,6 +19,8 @@ const { }, } = ERROR_MESSAGES; +const MAXIMUM = MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON; + /** * offensesOrInvestigationsRules * @param {Express.Request.body} Express response body @@ -27,7 +29,7 @@ const { */ const offensesOrInvestigationsRules = (formBody: RequestBody, errors: object) => { if (formBody[HAS_NO_OFFENSES_OR_INVESTIGATIONS] === 'false') { - return providedAndMaxLength(formBody, FIELD_ID, ERROR_MESSAGES_OBJECT, errors, MAXIMUM_CHARACTERS.DECLARATIONS.MODERN_SLAVERY.CONDITIONAL_REASON); + return providedAndMaxLength(formBody, FIELD_ID, ERROR_MESSAGES_OBJECT, errors, MAXIMUM); } return errors;