Skip to content

Commit

Permalink
feat(EMS-3829): export contract - how much is agent charging - e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ttbarnes committed Sep 16, 2024
1 parent 97979d0 commit 14aeae1
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { field } from '../../pages/shared';
import FIELD_IDS from '../../constants/field-ids/insurance/export-contract';
import application from '../../fixtures/application';

const {
AGENT_CHARGES: { FIXED_SUM_AMOUNT },
} = FIELD_IDS;

/**
* completeAndSubmitHowMuchIsTheAgentChargingForm
* Complete and submit the "How much is the agent charging" form
* @param {String} fixedSumAmount: Fixed sum amount
*/
const completeAndSubmitHowMuchIsTheAgentChargingForm = ({ fixedSumAmount = application.EXPORT_CONTRACT.AGENT_CHARGES[FIXED_SUM_AMOUNT] }) => {
cy.keyboardInput(field(FIXED_SUM_AMOUNT).input(), fixedSumAmount);

cy.clickSubmitButton();
};

export default completeAndSubmitHowMuchIsTheAgentChargingForm;
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { field as fieldSelector, headingCaption } from '../../../../../../pages/shared';
import { PAGES } from '../../../../../../content-strings';
import { EXPORT_CONTRACT_FIELDS as FIELD_STRINGS } from '../../../../../../content-strings/fields/insurance/export-contract';
import FIELD_IDS from '../../../../../../constants/field-ids/insurance/export-contract';
import { INSURANCE_ROUTES } from '../../../../../../constants/routes/insurance';

const CONTENT_STRINGS = PAGES.INSURANCE.EXPORT_CONTRACT.HOW_MUCH_IS_THE_AGENT_CHARGING;

const {
ROOT,
EXPORT_CONTRACT: { HOW_MUCH_IS_THE_AGENT_CHARGING, CHECK_YOUR_ANSWERS },
} = INSURANCE_ROUTES;

const {
AGENT_CHARGES: { FIXED_SUM_AMOUNT: FIELD_ID },
} = FIELD_IDS;

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

context(
"Insurance - Export contract - How much is the agent charging page - As an exporter, I want to state what my agent's charges are, So that UKEF, the legal team and the British Embassy are aware of expenses incurred in my export contract bid",
() => {
let referenceNumber;
let url;
let checkYourAnswersUrl;

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

url = `${baseUrl}${ROOT}/${referenceNumber}${HOW_MUCH_IS_THE_AGENT_CHARGING}`;
checkYourAnswersUrl = `${baseUrl}${ROOT}/${referenceNumber}${CHECK_YOUR_ANSWERS}`;

cy.navigateToUrl();
});
});

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

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

it('renders core page elements', () => {
cy.corePageChecks({
pageTitle: CONTENT_STRINGS.PAGE_TITLE,
currentHref: `${ROOT}/${referenceNumber}${HOW_MUCH_IS_THE_AGENT_CHARGING}`,
backLink: '#',
});
});

describe('page tests', () => {
beforeEach(() => {
cy.navigateToUrl(url);
});

it('renders a heading caption', () => {
cy.checkText(headingCaption(), CONTENT_STRINGS.HEADING_CAPTION);
});

it(`renders ${FIELD_ID} hint and input`, () => {
const field = fieldSelector(FIELD_ID);

cy.checkText(field.hint(), FIELD_STRINGS.AGENT_CHARGES[FIELD_ID]);

field.input().should('exist');
});

it('renders a `save and back` button', () => {
cy.assertSaveAndBackButton();
});
});

describe('form submission', () => {
it(`should redirect to ${CHECK_YOUR_ANSWERS}`, () => {
cy.navigateToUrl(url);

cy.completeAndSubmitHowMuchIsTheAgentChargingForm({});

cy.assertUrl(checkYourAnswersUrl);
});
});
},
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { field as fieldSelector } from '../../../../../../../pages/shared';
import { MINIMUM_CHARACTERS } from '../../../../../../../constants';
import { ERROR_MESSAGES } from '../../../../../../../content-strings';
import FIELD_IDS from '../../../../../../../constants/field-ids/insurance/export-contract';
import { INSURANCE_ROUTES } from '../../../../../../../constants/routes/insurance';

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

const {
AGENT_CHARGES: { FIXED_SUM_AMOUNT: FIELD_ID },
} = FIELD_IDS;

const {
INSURANCE: {
EXPORT_CONTRACT: {
AGENT_CHARGES: { [FIELD_ID]: ERROR_MESSAGES_OBJECT },
},
},
} = ERROR_MESSAGES;

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

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

context('Insurance - Export contract - How much is the agent charging page - form validation', () => {
let referenceNumber;
let url;

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

url = `${baseUrl}${ROOT}/${referenceNumber}${HOW_MUCH_IS_THE_AGENT_CHARGING}`;
});
});

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

cy.navigateToUrl(url);
});

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

it(`should display validation errors when ${FIELD_ID} is left empty`, () => {
cy.submitAndAssertFieldErrors({ ...assertions, expectedErrorMessage: ERROR_MESSAGES_OBJECT.IS_EMPTY });
});

it(`should display validation errors when ${FIELD_ID} has special characters`, () => {
cy.submitAndAssertFieldErrors({
...assertions,
value: '10!',
expectedErrorMessage: ERROR_MESSAGES_OBJECT.INCORRECT_FORMAT,
});
});

it(`should display validation errors when ${FIELD_ID} is below ${MINIMUM_CHARACTERS.ONE}`, () => {
cy.submitAndAssertFieldErrors({
...assertions,
value: String(MINIMUM_CHARACTERS.ONE - 1),
expectedErrorMessage: ERROR_MESSAGES_OBJECT.BELOW_MINIMUM,
});
});

it(`should NOT display validation errors when ${FIELD_ID} is a decimal place number`, () => {
cy.keyboardInput(fieldSelector(FIELD_ID).input(), '1.50');

cy.clickSubmitButton();
cy.assertErrorSummaryListDoesNotExist();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ Cypress.Commands.add('completeAndSubmitAgentServiceForm', require('../../../../.
Cypress.Commands.add('completeAgentChargesForm', require('../../../../../commands/insurance/complete-agent-charges-form'));
Cypress.Commands.add('completeAndSubmitAgentChargesForm', require('../../../../../commands/insurance/complete-and-submit-agent-charges-form'));

Cypress.Commands.add(
'completeAndSubmitHowMuchIsTheAgentChargingForm',
require('../../../../../commands/insurance/complete-and-submit-how-much-is-the-agent-charging-form'),
);

Cypress.Commands.add(
'completeAndSubmitExportContractForms',
require('../../../../../commands/insurance/export-contract/complete-and-submit-export-contract-forms'),
Expand Down

0 comments on commit 14aeae1

Please sign in to comment.