Skip to content

Commit

Permalink
feat(EMS-3662): export contract - how was contract awarded - save and…
Browse files Browse the repository at this point in the history
… back (#2892)

* feat(EMS-3662): export contract - how was contract awarded - save and back

* chore(EMS-3665): address todo comments

* chore(docs): minor documentation improvements

* feat(EMS-3662): export contract - how was contract  awarded - save and back

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

* feat(EMS-3662): simplify e2e test
  • Loading branch information
ttbarnes authored Aug 5, 2024
1 parent 41ca155 commit 8003b9d
Show file tree
Hide file tree
Showing 26 changed files with 435 additions and 121 deletions.
Original file line number Diff line number Diff line change
@@ -1,57 +1,22 @@
import { field, 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';
import application from '../../fixtures/application';

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

const { OPEN_TENDER, NEGOTIATED_CONTRACT, DIRECT_AWARD, COMPETITIVE_BIDDING, OTHER } = FIELDS.HOW_WAS_THE_CONTRACT_AWARDED[AWARD_METHOD].OPTIONS;

/**
* completeAndSubmitHowWasTheContractAwardedForm
* Complete and submit the "How was the contract awarded" form
* @param {Boolean} openTender: Award method as OPEN_TENDER. Defaults to true
* @param {Boolean} negotiatedContract: Award method as NEGOTIATED_CONTRACT. Defaults to false
* @param {String} directAward: Award method as DIRECT_AWARD. Defaults to false
* @param {String} competitiveBidding: Award method as COMPETITIVE_BIDDING. Defaults to false
* @param {String} otherMethod: Award method as OTHER. Defaults to false
* @param {Boolean} openTender: Award method as OPEN_TENDER
* @param {Boolean} negotiatedContract: Award method as NEGOTIATED_CONTRACT
* @param {Boolean} directAward: Award method as DIRECT_AWARD
* @param {Boolean} competitiveBidding: Award method as COMPETITIVE_BIDDING
* @param {Boolean} otherMethod: Award method as OTHER
* @param {String} otherMethodText: OTHER award method text
*/
const completeAndSubmitHowWasTheContractAwardedForm = ({
openTender = true,
negotiatedContract = false,
directAward = false,
competitiveBidding = false,
otherMethod = false,
}) => {
let selector;

if (openTender) {
selector = radios(OPEN_TENDER.ID).option;
}

if (negotiatedContract) {
selector = radios(NEGOTIATED_CONTRACT.ID).option;
}

if (directAward) {
selector = radios(DIRECT_AWARD.ID).option;
}

if (competitiveBidding) {
selector = radios(COMPETITIVE_BIDDING.ID).option;
}

if (otherMethod) {
selector = radios(OTHER.ID).option;

selector.label().click();

cy.keyboardInput(field(OTHER_AWARD_METHOD).input(), application.EXPORT_CONTRACT[OTHER_AWARD_METHOD]);
}

selector.label().click();
const completeAndSubmitHowWasTheContractAwardedForm = ({ openTender, negotiatedContract, directAward, competitiveBidding, otherMethod, otherMethodText }) => {
cy.completeHowWasTheContractAwardedForm({
openTender,
negotiatedContract,
directAward,
competitiveBidding,
otherMethod,
otherMethodText,
});

cy.clickSubmitButton();
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { field, 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';
import application from '../../fixtures/application';

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

const { OPEN_TENDER, NEGOTIATED_CONTRACT, DIRECT_AWARD, COMPETITIVE_BIDDING, OTHER } = FIELDS.HOW_WAS_THE_CONTRACT_AWARDED[AWARD_METHOD].OPTIONS;

/**
* completeHowWasTheContractAwardedForm
* Complete the "How was the contract awarded" form
* @param {Boolean} openTender: Award method as OPEN_TENDER. Defaults to true
* @param {Boolean} negotiatedContract: Award method as NEGOTIATED_CONTRACT. Defaults to false
* @param {Boolean} directAward: Award method as DIRECT_AWARD. Defaults to false
* @param {Boolean} competitiveBidding: Award method as COMPETITIVE_BIDDING. Defaults to false
* @param {Boolean} otherMethod: Award method as OTHER. Defaults to false
* @param {String} otherMethodText: OTHER award method text
*/
const completeHowWasTheContractAwardedForm = ({
openTender = true,
negotiatedContract = false,
directAward = false,
competitiveBidding = false,
otherMethod = false,
otherMethodText = application.EXPORT_CONTRACT[OTHER_AWARD_METHOD],
}) => {
let selector;

if (openTender) {
selector = radios(OPEN_TENDER.ID).option;
}

if (negotiatedContract) {
selector = radios(NEGOTIATED_CONTRACT.ID).option;
}

if (directAward) {
selector = radios(DIRECT_AWARD.ID).option;
}

if (competitiveBidding) {
selector = radios(COMPETITIVE_BIDDING.ID).option;
}

if (otherMethod) {
selector = radios(OTHER.ID).option;

selector.label().click();

if (otherMethodText) {
cy.keyboardInput(field(OTHER_AWARD_METHOD).input(), otherMethodText);
}
}

selector.label().click();
};

export default completeHowWasTheContractAwardedForm;
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ const { OPEN_TENDER, NEGOTIATED_CONTRACT, DIRECT_AWARD, COMPETITIVE_BIDDING, OTH
* @param {String} directAward: Award method as DIRECT_AWARD
* @param {String} competitiveBidding: Award method as COMPETITIVE_BIDDING
* @param {String} otherMethod: Award method as OTHER
* @param {String} otherMethodText: OTHER award method text
*/
const assertHowWasTheContractAwardedFieldValues = ({
openTender = false,
negotiatedContract = false,
directAward = false,
competitiveBidding = false,
otherMethod = false,
otherMethodText = application.EXPORT_CONTRACT[OTHER_AWARD_METHOD],
}) => {
const selectors = {
openTender: radios(OPEN_TENDER.ID).option.input(),
Expand Down Expand Up @@ -73,7 +75,9 @@ const assertHowWasTheContractAwardedFieldValues = ({
if (otherMethod) {
cy.assertRadioOptionIsChecked(selectors.otherMethod);

cy.checkValue(selectors.otherMethodTextInput, application.EXPORT_CONTRACT[OTHER_AWARD_METHOD]);
if (otherMethodText) {
cy.checkValue(selectors.otherMethodTextInput, otherMethodText);
}

cy.assertRadioOptionIsNotChecked(selectors.openTender);
cy.assertRadioOptionIsNotChecked(selectors.negotiatedContract);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,8 @@ context(`Insurance - Export contract - Agent charges - Save and go back - ${METH

cy.startInsuranceExportContractSection({});

// TODO: EMS-3665 - increment the value in command below instead.
cy.completeAndSubmitHowWasTheContractAwardedForm({});

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

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

cy.startInsuranceExportContractSection({});

// TODO: EMS-3665 - increment the value in command below instead.
cy.completeAndSubmitHowWasTheContractAwardedForm({});

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

cy.assertAgentChargesFieldValues({ percentageMethod: true });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ context(`Insurance - Export contract - Agent charges - Save and go back - empty
});

// TODO: partially submitted - country, no method.
// . should be populated when going back to the page.
// should be populated when going back to the page.

describe('when submitting an empty form via `save and go back` button', () => {
beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,8 @@ context('Insurance - Export contract - Agent details - Save and go back', () =>

cy.startInsuranceExportContractSection({});

// TODO: EMS-3665 - increment the value in command below instead.
cy.completeAndSubmitHowWasTheContractAwardedForm({});

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

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

cy.startInsuranceExportContractSection({});

// TODO: EMS-3665 - increment the value in command below instead.
cy.completeAndSubmitHowWasTheContractAwardedForm({});

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

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

cy.startInsuranceExportContractSection({});

// TODO: EMS-3665 - increment the value in command below instead.
cy.completeAndSubmitHowWasTheContractAwardedForm({});

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

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

cy.startInsuranceExportContractSection({});

// TODO: EMS-3665 - increment the value in command below instead.
cy.completeAndSubmitHowWasTheContractAwardedForm({});

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

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

cy.startInsuranceExportContractSection({});

// TODO: EMS-3665 - increment the value in command below instead.
cy.completeAndSubmitHowWasTheContractAwardedForm({});

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

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

cy.startInsuranceExportContractSection({});

// TODO: EMS-3665 - increment the value in command below instead.
cy.completeAndSubmitHowWasTheContractAwardedForm({});

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

cy.checkTextareaValue({
fieldId: FIELD_ID,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { INSURANCE_ROUTES } from '../../../../../../constants/routes/insurance';

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

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

context('Insurance - Export contract - How was the contract awarded page - Save and go back', () => {
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 submitting an empty form via `save and go back` button', () => {
beforeEach(() => {
cy.navigateToUrl(url);

cy.clickSaveAndBackButton();
});

it('should redirect to `all sections`', () => {
cy.assertAllSectionsUrl(referenceNumber);
});

it('should retain the `export contract` task status as `not started yet`', () => {
cy.checkTaskExportContractStatusIsNotStartedYet();
});
});

describe('when fields are partially completed', () => {
beforeEach(() => {
cy.navigateToUrl(url);
});

it('should update the status of task `export contract` to `in progress`', () => {
cy.completeHowWasTheContractAwardedForm({
otherMethod: true,
otherMethodText: null,
});

cy.clickSaveAndBackButton();

cy.assertAllSectionsUrl(referenceNumber);

cy.checkTaskExportContractStatusIsInProgress();
});

describe('when going back to the page', () => {
it('should have the submitted value', () => {
cy.assertHowWasTheContractAwardedFieldValues({
otherMethodText: '',
});
});
});
});

describe('when all fields are provided', () => {
it('should retain the status of task `export contract` as `in progress`', () => {
cy.navigateToUrl(url);

cy.completeHowWasTheContractAwardedForm({ otherMethod: true });

cy.clickSaveAndBackButton();

cy.navigateToAllSectionsUrl(referenceNumber);

cy.checkTaskExportContractStatusIsInProgress();
});

describe('when going back to the page', () => {
it('should have the submitted values', () => {
cy.navigateToAllSectionsUrl(referenceNumber);

cy.startInsuranceExportContractSection({});

cy.assertHowWasTheContractAwardedFieldValues({ otherMethod: true });
});
});
});
});
Loading

0 comments on commit 8003b9d

Please sign in to comment.