Skip to content

Commit

Permalink
feat(EMS-3661): export contract - how was contract awarded - form val…
Browse files Browse the repository at this point in the history
…idation (#2865)

* feat(EMS-3661): export contract - how was contract awarded - form validation

* feat(EMS-3661): update unit test

* feat(EMS-3661): fix/update unit test

* feat(EMS-3661): fix/update e2e command

* feat(EMS-3661): fix/update e2e tests

* feat(EMS-3661): fix/update e2e tests

* feat(EMS-3661): fix/update e2e test

* feat(EMS-3661): fix/update e2e test
  • Loading branch information
ttbarnes authored Aug 1, 2024
1 parent fd488dd commit c495363
Show file tree
Hide file tree
Showing 32 changed files with 489 additions and 47 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ jobs:
'eligibility/party-to-consortium/**/*.spec.js',
'eligibility/total-value-insured/**/*.spec.js',
'eligibility/uk-goods-or-services/**/*.spec.js',
'export-contract/how-was-the-contract-awarded/**/*.spec.js',
'export-contract/about-goods-or-services/**/*.spec.js',
'export-contract/how-will-you-get-paid/**/*.spec.js',
'export-contract/private-market/**/*.spec.js',
Expand Down
9 changes: 3 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,21 @@

## [2.28.2](https://github.com/UK-Export-Finance/exip/compare/v2.28.1...v2.28.2) (2024-08-01)


### Bug Fixes

* **EMS-3703:** eligibility - Member of a group - Wording fix ([#2869](https://github.com/UK-Export-Finance/exip/issues/2869)) ([119ce21](https://github.com/UK-Export-Finance/exip/commit/119ce21f56e97ea99d9db1dcdfd611ca7cb6de05))
- **EMS-3703:** eligibility - Member of a group - Wording fix ([#2869](https://github.com/UK-Export-Finance/exip/issues/2869)) ([119ce21](https://github.com/UK-Export-Finance/exip/commit/119ce21f56e97ea99d9db1dcdfd611ca7cb6de05))

## [2.28.1](https://github.com/UK-Export-Finance/exip/compare/v2.28.0...v2.28.1) (2024-08-01)


### Bug Fixes

* **iac:** afd custom domains association ([9ecd958](https://github.com/UK-Export-Finance/exip/commit/9ecd9582a228e3d8266daa228fb6655150358da5))
- **iac:** afd custom domains association ([9ecd958](https://github.com/UK-Export-Finance/exip/commit/9ecd9582a228e3d8266daa228fb6655150358da5))

## [2.28.0](https://github.com/UK-Export-Finance/exip/compare/v2.27.0...v2.28.0) (2024-07-31)


### Features

* **EMS-3667:** eligibility - Check if eligible - Content change ([#2861](https://github.com/UK-Export-Finance/exip/issues/2861)) ([0c7557f](https://github.com/UK-Export-Finance/exip/commit/0c7557faf6fc35a49c4cb6278f58fdaa4768b863))
- **EMS-3667:** eligibility - Check if eligible - Content change ([#2861](https://github.com/UK-Export-Finance/exip/issues/2861)) ([0c7557f](https://github.com/UK-Export-Finance/exip/commit/0c7557faf6fc35a49c4cb6278f58fdaa4768b863))

## [2.27.0](https://github.com/UK-Export-Finance/exip/compare/v2.26.0...v2.27.0) (2024-07-31)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
import { radios } from '../../pages/shared';
import { EXPORT_CONTRACT as EXPORT_CONTRACT_FIELD_IDS } from '../../constants/field-ids/insurance/export-contract';
import { EXPORT_CONTRACT_FIELDS as FIELDS } from '../../content-strings/fields/insurance';

const {
HOW_WAS_THE_CONTRACT_AWARDED: { AWARD_METHOD },
} = EXPORT_CONTRACT_FIELD_IDS;

const AWARD_METHOD_OPTIONS = FIELDS.HOW_WAS_THE_CONTRACT_AWARDED[AWARD_METHOD].OPTIONS;

/**
* completeAndSubmitHowWasTheContractAwardedForm
* Complete and submit the "How was the contract awarded" form
*/
const completeAndSubmitHowWasTheContractAwardedForm = () => {
const selector = radios(AWARD_METHOD_OPTIONS.OPEN_TENDER.ID).option;

selector.label().click();

cy.clickSubmitButton();
};

Expand Down
3 changes: 3 additions & 0 deletions e2e-tests/constants/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export const MAXIMUM_CHARACTERS = {
CREDIT_PERIOD_WITH_BUYER: 1000,
DECLINED_BY_PRIVATE_MARKET_DESCRIPTION: 1000,
EMAIL: 300,
EXPORT_CONTRACT: {
OTHER_AWARD_METHOD: 200,
},
FEEDBACK: {
IMPROVEMENT: 1200,
OTHER_COMMENTS: 1200,
Expand Down
9 changes: 9 additions & 0 deletions e2e-tests/content-strings/error-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@ export const ERROR_MESSAGES = {
},
},
EXPORT_CONTRACT: {
HOW_WAS_THE_CONTRACT_AWARDED: {
[FIELD_IDS.INSURANCE.EXPORT_CONTRACT.HOW_WAS_THE_CONTRACT_AWARDED.AWARD_METHOD]: {
IS_EMPTY: 'Select how the contract was awarded',
},
[FIELD_IDS.INSURANCE.EXPORT_CONTRACT.HOW_WAS_THE_CONTRACT_AWARDED.OTHER_AWARD_METHOD]: {
IS_EMPTY: 'Enter how the contract was awarded',
ABOVE_MAXIMUM: `The method of how your contract was awarded cannot be more than ${MAXIMUM_CHARACTERS.EXPORT_CONTRACT.OTHER_AWARD_METHOD} characters`,
},
},
ABOUT_GOODS_OR_SERVICES: {
[FIELD_IDS.INSURANCE.EXPORT_CONTRACT.ABOUT_GOODS_OR_SERVICES.DESCRIPTION]: {
IS_EMPTY: 'Enter the goods or services you will supply to the buyer',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { OPEN_TENDER, NEGOTIATED_CONTRACT, DIRECT_AWARD, COMPETITIVE_BIDDING, OTH
const {
CURRENCY: { CURRENCY_CODE },
EXPORT_CONTRACT: {
HOW_WAS_THE_CONTRACT_AWARDED: { AWARD_METHOD },
HOW_WAS_THE_CONTRACT_AWARDED: { AWARD_METHOD, OTHER_AWARD_METHOD },
ABOUT_GOODS_OR_SERVICES: { DESCRIPTION, FINAL_DESTINATION_KNOWN, FINAL_DESTINATION },
HOW_WILL_YOU_GET_PAID: { PAYMENT_TERMS_DESCRIPTION },
PRIVATE_MARKET: { ATTEMPTED, DECLINED_DESCRIPTION },
Expand Down Expand Up @@ -52,6 +52,9 @@ export const EXPORT_CONTRACT_FIELDS = {
},
},
},
[OTHER_AWARD_METHOD]: {
MAXIMUM: MAXIMUM_CHARACTERS.EXPORT_CONTRACT.OTHER_AWARD_METHOD,
},
},
ABOUT_GOODS_OR_SERVICES: {
[DESCRIPTION]: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,11 @@ context(`Insurance - Export contract - Agent charges - Save and go back - ${METH

cy.startInsuranceExportContractSection({});

// go through 6 export contract forms.
cy.clickSubmitButtonMultipleTimes({ count: 6 });
// TODO: EMS-3665 - increment the value in command below instead.
cy.completeAndSubmitHowWasTheContractAwardedForm();

// go through 5 export contract forms.
cy.clickSubmitButtonMultipleTimes({ count: 5 });

cy.assertAgentChargesFieldValues({ fixedSumMethod: true });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,11 @@ context(`Insurance - Export contract - Agent charges - Save and go back - ${METH

cy.startInsuranceExportContractSection({});

// go through 6 export contract forms.
cy.clickSubmitButtonMultipleTimes({ count: 6 });
// TODO: EMS-3665 - increment the value in command below instead.
cy.completeAndSubmitHowWasTheContractAwardedForm();

// go through 5 export contract forms.
cy.clickSubmitButtonMultipleTimes({ count: 5 });

cy.assertAgentChargesFieldValues({ percentageMethod: true });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,11 @@ context('Insurance - Export contract - Agent details - Save and go back', () =>

cy.startInsuranceExportContractSection({});

// go through 4 export contract forms.
cy.clickSubmitButtonMultipleTimes({ count: 4 });
// TODO: EMS-3665 - increment the value in command below instead.
cy.completeAndSubmitHowWasTheContractAwardedForm();

// go through 3 export contract forms.
cy.clickSubmitButtonMultipleTimes({ count: 3 });

cy.assertAgentDetailsFieldValues({});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ context('Insurance - Export contract - Agent service - Save and go back', () =>

cy.startInsuranceExportContractSection({});

// go through 5 export contract forms.
cy.clickSubmitButtonMultipleTimes({ count: 5 });
// TODO: EMS-3665 - increment the value in command below instead.
cy.completeAndSubmitHowWasTheContractAwardedForm();

// go through 4 export contract forms.
cy.clickSubmitButtonMultipleTimes({ count: 4 });

cy.assertAgentServiceFieldValues({});
});
Expand All @@ -121,8 +124,11 @@ context('Insurance - Export contract - Agent service - Save and go back', () =>

cy.startInsuranceExportContractSection({});

// go through 5 export contract forms.
cy.clickSubmitButtonMultipleTimes({ count: 5 });
// TODO: EMS-3665 - increment the value in command below instead.
cy.completeAndSubmitHowWasTheContractAwardedForm();

// go through 4 export contract forms.
cy.clickSubmitButtonMultipleTimes({ count: 4 });

cy.assertAgentServiceFieldValues({ agentIsCharging: true });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,11 @@ context('Insurance - Export contract - Agent - Save and go back', () => {

cy.startInsuranceExportContractSection({});

// go through 3 export contract forms.
cy.clickSubmitButtonMultipleTimes({ count: 3 });
// TODO: EMS-3665 - increment the value in command below instead.
cy.completeAndSubmitHowWasTheContractAwardedForm();

// go through 2 export contract forms.
cy.clickSubmitButtonMultipleTimes({ count: 2 });

cy.assertNoRadioOptionIsChecked();
});
Expand Down Expand Up @@ -105,8 +108,11 @@ context('Insurance - Export contract - Agent - Save and go back', () => {

cy.startInsuranceExportContractSection({});

// go through 3 export contract forms.
cy.clickSubmitButtonMultipleTimes({ count: 3 });
// TODO: EMS-3665 - increment the value in command below instead.
cy.completeAndSubmitHowWasTheContractAwardedForm();

// go through 2 export contract forms.
cy.clickSubmitButtonMultipleTimes({ count: 2 });

cy.assertYesRadioOptionIsChecked();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,11 @@ context('Insurance - Export contract - Declined by private market - Save and go

cy.startInsuranceExportContractSection({});

// go through 4 export contract forms.
cy.clickSubmitButtonMultipleTimes({ count: 4 });
// TODO: EMS-3665 - increment the value in command below instead.
cy.completeAndSubmitHowWasTheContractAwardedForm();

// go through 3 export contract forms.
cy.clickSubmitButtonMultipleTimes({ count: 3 });

cy.checkTextareaValue({
fieldId: FIELD_ID,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { field as fieldSelector, radios } from '../../../../../../pages/shared';
import { MAXIMUM_CHARACTERS } from '../../../../../../constants';
import { INSURANCE_ROUTES } from '../../../../../../constants/routes/insurance';
import { EXPORT_CONTRACT as EXPORT_CONTRACT_FIELD_IDS } from '../../../../../../constants/field-ids/insurance/export-contract';
import { ERROR_MESSAGES } from '../../../../../../content-strings';
import { EXPORT_CONTRACT_FIELDS as FIELDS } from '../../../../../../content-strings/fields/insurance';

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

const {
HOW_WAS_THE_CONTRACT_AWARDED: { AWARD_METHOD, OTHER_AWARD_METHOD },
} = EXPORT_CONTRACT_FIELD_IDS;

const AWARD_METHOD_OPTIONS = FIELDS.HOW_WAS_THE_CONTRACT_AWARDED[AWARD_METHOD].OPTIONS;

const {
INSURANCE: {
EXPORT_CONTRACT: { HOW_WAS_THE_CONTRACT_AWARDED: ERROR_MESSAGES_OBJECT },
},
} = ERROR_MESSAGES;

const OTHER_AWARD_METHOD_MAXIMUM_CHARACTERS = MAXIMUM_CHARACTERS.EXPORT_CONTRACT.OTHER_AWARD_METHOD;

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

context('Insurance - Export contract - How was the contract awarded page - form validation', () => {
let referenceNumber;
let url;

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

// go to the page we want to test.
cy.startInsuranceExportContractSection({});

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

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

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

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

describe('when no radios are selected', () => {
beforeEach(() => {
cy.navigateToUrl(url);
});

it('should display validation error', () => {
const expectedErrorsCount = 1;
const expectedErrorMessage = ERROR_MESSAGES_OBJECT[AWARD_METHOD].IS_EMPTY;

const radioField = {
...fieldSelector(AWARD_METHOD),
input: fieldSelector(AWARD_METHOD_OPTIONS.OPEN_TENDER.VALUE).input,
};

cy.submitAndAssertRadioErrors({
field: radioField,
expectedErrorsCount,
expectedErrorMessage,
});
});
});

describe(`when ${AWARD_METHOD_OPTIONS.OTHER.TEXT} is selected`, () => {
const selector = radios(AWARD_METHOD_OPTIONS.OTHER.VALUE).option;

const assertions = {
field: fieldSelector(OTHER_AWARD_METHOD),
errorIndex: 0,
expectedErrorsCount: 1,
};

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

radios(AWARD_METHOD_OPTIONS.OTHER.VALUE).option.label().click();
});

it(`should pre-select the method option and render validation errors when ${OTHER_AWARD_METHOD} is empty`, () => {
const expectedErrorMessage = ERROR_MESSAGES_OBJECT[OTHER_AWARD_METHOD].IS_EMPTY;

cy.submitAndAssertFieldErrors({ ...assertions, expectedErrorMessage });

cy.assertRadioOptionIsChecked(selector.input());
});

it(`should pre-select the method option and render validation errors when ${OTHER_AWARD_METHOD} is over ${OTHER_AWARD_METHOD_MAXIMUM_CHARACTERS} characters`, () => {
const value = 'a'.repeat(OTHER_AWARD_METHOD_MAXIMUM_CHARACTERS + 1);

const expectedErrorMessage = ERROR_MESSAGES_OBJECT[OTHER_AWARD_METHOD].ABOVE_MAXIMUM;

cy.submitAndAssertFieldErrors({ ...assertions, value, expectedErrorMessage });

cy.assertRadioOptionIsChecked(selector.input());
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -69,38 +69,38 @@ context(
});

it(`renders an ${OPEN_TENDER.VALUE} radio`, () => {
const field = AWARD_METHOD_OPTIONS.OPEN_TENDER;
const selector = radios(AWARD_METHOD_OPTIONS.OPEN_TENDER.ID).option;

cy.checkText(radios(field.ID).option.label(), OPEN_TENDER.VALUE);
cy.checkValue(radios(field.ID).option, OPEN_TENDER.DB_ID);
cy.checkText(selector.label(), OPEN_TENDER.VALUE);
cy.checkValue(selector, OPEN_TENDER.DB_ID);
});

it(`renders a ${NEGOTIATED_CONTRACT.VALUE} radio`, () => {
const field = AWARD_METHOD_OPTIONS.NEGOTIATED_CONTRACT;
const selector = radios(AWARD_METHOD_OPTIONS.NEGOTIATED_CONTRACT.ID).option;

cy.checkText(radios(field.ID).option.label(), NEGOTIATED_CONTRACT.VALUE);
cy.checkValue(radios(field.ID).option, NEGOTIATED_CONTRACT.DB_ID);
cy.checkText(selector.label(), NEGOTIATED_CONTRACT.VALUE);
cy.checkValue(selector, NEGOTIATED_CONTRACT.DB_ID);
});

it(`renders a ${DIRECT_AWARD.VALUE} radio`, () => {
const field = AWARD_METHOD_OPTIONS.DIRECT_AWARD;
const selector = radios(AWARD_METHOD_OPTIONS.DIRECT_AWARD.ID).option;

cy.checkText(radios(field.ID).option.label(), DIRECT_AWARD.VALUE);
cy.checkValue(radios(field.ID).option, DIRECT_AWARD.DB_ID);
cy.checkText(selector.label(), DIRECT_AWARD.VALUE);
cy.checkValue(selector, DIRECT_AWARD.DB_ID);
});

it(`renders a ${COMPETITIVE_BIDDING.VALUE} radio`, () => {
const field = AWARD_METHOD_OPTIONS.COMPETITIVE_BIDDING;
const selector = radios(AWARD_METHOD_OPTIONS.COMPETITIVE_BIDDING.ID).option;

cy.checkText(radios(field.ID).option.label(), COMPETITIVE_BIDDING.VALUE);
cy.checkValue(radios(field.ID).option, COMPETITIVE_BIDDING.DB_ID);
cy.checkText(selector.label(), COMPETITIVE_BIDDING.VALUE);
cy.checkValue(selector, COMPETITIVE_BIDDING.DB_ID);
});

it(`renders an ${OTHER.VALUE} radio`, () => {
const field = AWARD_METHOD_OPTIONS.OTHER;
const selector = radios(AWARD_METHOD_OPTIONS.OTHER.ID).option;

cy.checkText(radios(field.ID).option.label(), OTHER.VALUE);
cy.checkValue(radios(field.ID).option, OTHER.DB_ID);
cy.checkText(selector.label(), OTHER.VALUE);
cy.checkValue(selector, OTHER.DB_ID);
});

it(`should NOT display conditional "${OTHER_AWARD_METHOD}" section without selecting the "${OTHER.VALUE}" radio`, () => {
Expand Down
Loading

0 comments on commit c495363

Please sign in to comment.