Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(DTFS2-7781): add page e2e test (WIP)
Browse files Browse the repository at this point in the history
Mark Roberts committed Jan 29, 2025
1 parent 31227b7 commit 8ab91a8
Showing 2 changed files with 143 additions and 0 deletions.
12 changes: 12 additions & 0 deletions e2e-tests/gef/cypress/e2e/pages/amendments/effective-from.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const effectiveFrom = {
effectiveFromDay: () => cy.get('[data-cy="effective-from-day"]'),
effectiveFromMonth: () => cy.get('[data-cy="effective-from-month"]'),
effectiveFromYear: () => cy.get('[data-cy="effective-from-year"]'),
errorSummary: () => cy.get('[data-cy="error-summary"]'),
effectiveFromInlineError: () => cy.get('[data-cy="effective-from-inline-error"]'),
pageHeading: () => cy.get('[data-cy="page-heading"]'),
backLink: () => cy.get('[data-cy="back-link"]'),
cancelLink: () => cy.get('[data-cy="cancel-link"]'),
};

module.exports = effectiveFrom;
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import relative from '../../../../relativeURL';
import MOCK_USERS from '../../../../../../../e2e-fixtures/portal-users.fixture';
import { MOCK_APPLICATION_AIN_DRAFT } from '../../../../../../../e2e-fixtures/gef/mocks/mock-deals';
import { anIssuedCashFacility } from '../../../../../../../e2e-fixtures/mock-gef-facilities';
import { applicationPreview } from '../../../../../../../gef/cypress/e2e/pages';
import whatDoYouNeedToChange from '../../../../../../../gef/cypress/e2e/pages/amendments/what-do-you-need-to-change';
import facilityValue from '../../../../../../../gef/cypress/e2e/pages/amendments/facility-value';
import eligibility from '../../../../../../../gef/cypress/e2e/pages/amendments/eligibility';
import effectiveFrom from '../../../../../../../gef/cypress/e2e/pages/amendments/effective-from';
import { twoDaysAgo, twoMonths, yesterday } from '../../../../../../../e2e-fixtures/dateConstants';

const { BANK1_MAKER1 } = MOCK_USERS;

context('Amendments - Date amendment effective from - page tests', () => {
/**
* @type {string}
*/
let dealId;

/**
* @type {string}
*/
let facilityId;
/**
* @type {string}
*/
let amendmentId;

before(() => {
cy.insertOneGefDeal(MOCK_APPLICATION_AIN_DRAFT, BANK1_MAKER1).then((insertedDeal) => {
dealId = insertedDeal._id;

cy.updateGefDeal(dealId, MOCK_APPLICATION_AIN_DRAFT, BANK1_MAKER1);

cy.createGefFacilities(dealId, [anIssuedCashFacility({ facilityEndDateEnabled: true })], BANK1_MAKER1).then((createdFacility) => {
facilityId = createdFacility.details._id;

cy.makerLoginSubmitGefDealForReview(insertedDeal);
cy.checkerLoginSubmitGefDealToUkef(insertedDeal);

cy.clearSessionCookies();
cy.login(BANK1_MAKER1);
cy.saveSession();
cy.visit(relative(`/gef/application-details/${dealId}`));

applicationPreview.makeAChangeButton(facilityId).click();

cy.url().then((url) => {
const urlSplit = url.split('/');

amendmentId = urlSplit[9];
});

whatDoYouNeedToChange.facilityValueCheckbox().click();
cy.clickContinueButton();
cy.keyboardInput(facilityValue.facilityValue(), '10000');
cy.clickContinueButton();
eligibility.allTrueRadioButtons().click({ multiple: true });
cy.clickContinueButton();
});
});
});

after(() => {
cy.clearCookies();
cy.clearSessionCookies();
});

beforeEach(() => {
cy.clearSessionCookies();
cy.login(BANK1_MAKER1);
cy.visit(relative(`/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/effective-date`));
});

it('should render key features of the page', () => {
effectiveFrom.pageHeading().contains('Date amendment effective from');
effectiveFrom.backLink();
effectiveFrom.cancelLink();
});

it('should render an error if no date is provided', () => {
cy.clickContinueButton();

effectiveFrom.errorSummary().should('be.visible');
effectiveFrom.errorSummary().contains('Enter the date amendment effective from');

effectiveFrom.effectiveFromInlineError().should('be.visible');
effectiveFrom.effectiveFromInlineError().contains('Enter the date amendment effective from');
});

const effectiveFromErrorTestCases = [
{
description: 'the date amendment effective from consists of invalid characters',
dateFieldInput: { day: 'aa', month: '11', year: '2025' },
expectedErrorMessage: 'date amendment effective from must be a real date',
},
{
description: 'the date amendment effective from is missing a field',
dateFieldInput: { day: '2', month: '', year: '2025' },
expectedErrorMessage: 'date amendment effective from must include a month',
},
{
description: 'the date amendment effective from is greater than 30 days in the future',
dateFieldInput: twoMonths,
expectedErrorMessage: `You entered an amendment date more than 30 days from now. Amendments must be effective within the next 30 days - come back later or use the Schedule 8 form`,
},
{
description: 'the date amendment effective from is before the cover start date',
dateFieldInput: twoDaysAgo,
expectedErrorMessage: `Date amendment effective from cannot be before the cover start date ${yesterday.d_MMMM_yyyy}`,
},
];

effectiveFromErrorTestCases.forEach(({ description, dateFieldInput, expectedErrorMessage }) => {
it(`should render an error on the bank review date page if ${description}`, () => {
cy.completeDateFormFields({ idPrefix: 'bank-review-date', ...dateFieldInput });
cy.clickContinueButton();

effectiveFrom.errorSummary().should('be.visible');
effectiveFrom.errorSummary().contains(expectedErrorMessage);
effectiveFrom.effectiveFromInlineError().should('be.visible');
effectiveFrom.effectiveFromInlineError().contains(expectedErrorMessage);
});
});

it('should navigate to cancel page when cancel is clicked', () => {
eligibility.cancelLink().click();

cy.url().should('eq', relative(`/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/cancel`));
});
});

0 comments on commit 8ab91a8

Please sign in to comment.