Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(EMS-4024): declarations - modern slavery - form validation #3410

Merged
merged 10 commits into from
Dec 17, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -13,3 +13,5 @@ export default (answer) => {

cy.clickSubmitButton();
};

export default completeAndSubmitDeclarationAntiBriberyCodeOfConduct;
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ import { singleInputField } from '../../../pages/shared';

const FIELD_ID = FIELD_IDS.INSURANCE.DECLARATIONS.AGREE_ANTI_BRIBERY;

export default () => {
/**
* completeAndSubmitAntiBriberyForm
* Complete and submit the "anti-bribery" form.
*/
const completeAndSubmitAntiBriberyForm = () => {
singleInputField(FIELD_ID).label().click();

cy.clickSubmitButton();
};

export default completeAndSubmitAntiBriberyForm;
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ import { singleInputField } from '../../../pages/shared';

const FIELD_ID = FIELD_IDS.INSURANCE.DECLARATIONS.AGREE_CONFIDENTIALITY;

export default () => {
/**
* completeAndSubmitConfidentialityForm
* Complete and submit the "confidentiality" form.
*/
const completeAndSubmitConfidentialityForm = () => {
singleInputField(FIELD_ID).label().click();

cy.clickSubmitButton();
};

export default completeAndSubmitConfidentialityForm;
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ import { singleInputField } from '../../../pages/shared';

const FIELD_ID = FIELD_IDS.INSURANCE.DECLARATIONS.AGREE_CONFIRMATION_ACKNOWLEDGEMENTS;

export default () => {
/**
* completeAndSubmitConfirmationAndAcknowledgementsForm
* Complete and submit the "confirmation and acknowledgements" form.
*/
const completeAndSubmitConfirmationAndAcknowledgementsForm = () => {
singleInputField(FIELD_ID).label().click();

cy.clickSubmitButton();
};

export default completeAndSubmitConfirmationAndAcknowledgementsForm;
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* 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,
isNotAwareOfExistingSlavery,
conditionalFields = {
cannotAdhereToAllRequirements: '',
offensesOrInvestigations: '',
awareOfExistingSlavery: '',
},
}) => {
cy.completeModernSlaveryForm({
willAdhereToAllRequirements,
hasNoOffensesOrInvestigations,
isNotAwareOfExistingSlavery,
conditionalFields,
});

cy.clickSubmitButton();
};

export default completeAndSubmitModernSlaveryForm;
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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;

/**
* 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);
}

if (offensesOrInvestigations) {
cy.keyboardInput(autoCompleteField(OFFENSES_OR_INVESTIGATIONS).input(), offensesOrInvestigations);
}

if (awareOfExistingSlavery) {
cy.keyboardInput(autoCompleteField(AWARE_OF_EXISTING_SLAVERY).input(), awareOfExistingSlavery);
}
};

export default completeModernSlaveryFormConditionalFields;
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* 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,
isNotAwareOfExistingSlavery = true,
conditionalFields = {
cannotAdhereToAllRequirements: '',
offensesOrInvestigations: '',
awareOfExistingSlavery: '',
},
}) => {
if (willAdhereToAllRequirements) {
cy.clickYesRadioInput(0);
}

if (willAdhereToAllRequirements === false) {
cy.clickNoRadioInput(0);
}

if (hasNoOffensesOrInvestigations) {
Zainzzkk marked this conversation as resolved.
Show resolved Hide resolved
cy.clickYesRadioInput(1);
}

if (hasNoOffensesOrInvestigations === false) {
cy.clickNoRadioInput(1);
}

if (isNotAwareOfExistingSlavery) {
cy.clickYesRadioInput(2);
}

if (isNotAwareOfExistingSlavery === false) {
cy.clickNoRadioInput(2);
}

cy.completeModernSlaveryFormConditionalFields(conditionalFields);
};

export default completeModernSlaveryForm;
Original file line number Diff line number Diff line change
@@ -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,
Zainzzkk marked this conversation as resolved.
Show resolved Hide resolved
errorIndex,
errorSummaryLength: expectedErrorsCount,
errorMessage: expectedErrorMessage,
fieldShouldGainFocus,
});
};

export default submitAndAssertRadioErrors;
25 changes: 25 additions & 0 deletions e2e-tests/content-strings/error-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
},
},
},
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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);
});
Expand All @@ -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);
});
Expand Down Expand Up @@ -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);
});
Expand All @@ -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);
});
Expand Down Expand Up @@ -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);
});
Expand All @@ -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);
});
Expand Down
Loading
Loading