Skip to content

Commit

Permalink
chore(EMS-3790-3791): various minor housekeeping, dry click event cyp…
Browse files Browse the repository at this point in the history
…ress command (#3001)

* chore(EMS-3790): dry cypress command for clicking new application button

* chore(nunjucks): remove unused components

* chore(docs): align errors documentation

* chore(tests): align mock referenceNumber url assertions

* chore(business): remove unused nunjucks template, content strings

* chore(tests): fix typo

* chore(EMS-3791): mapYesNoField - remove unused param

* chore(tests): remove unused const from multiple contract policy controller

* chore(e2e): fix/update e2e test
  • Loading branch information
ttbarnes authored Aug 23, 2024
1 parent 3434e25 commit 22deb8d
Show file tree
Hide file tree
Showing 95 changed files with 152 additions and 376 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import partials from '../../../partials';

/**
* clickStartNewApplicationButton
* Click the "start new application" button
*/
const clickStartNewApplicationButton = () => {
partials.startNewApplicationButton().click();
};

export default clickStartNewApplicationButton;
2 changes: 2 additions & 0 deletions e2e-tests/commands/shared-commands/click-events/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Cypress.Commands.add('clickYesRadioInput', require('./click-yes-radio-input'));
Cypress.Commands.add('clickProvideAlternativeCurrencyLink', require('./click-provide-alternative-currency-link'));
Cypress.Commands.add('clickAlternativeCurrencyRadioOption', require('./click-alternative-currency-radio-option'));

Cypress.Commands.add('clickStartNewApplicationButton', require('./click-start-new-application-button'));

Cypress.Commands.add('clickTaskBusiness', require('./tasks/click-task-business'));
Cypress.Commands.add('clickTaskBuyer', require('./tasks/click-task-buyer'));
Cypress.Commands.add('clickTaskPolicy', require('./tasks/click-task-policy'));
Expand Down
9 changes: 0 additions & 9 deletions e2e-tests/content-strings/pages/insurance/business/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@ export const COMPANY_DETAILS = {
DIFFERENT_TRADING_NAME_HINT: 'Your official trading name will still be on the policy.',
};

export const CONTACT = {
...SHARED,
PAGE_TITLE: 'Your contact details',
CONTACT_DETAILS: {
LEGEND: 'Contact details',
HINT: 'This will be the name on the contract policy',
},
};

export const ALTERNATIVE_TRADING_ADDRESS = {
...SHARED,
PAGE_TITLE: 'Alternative trading address',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import header from '../../../../../../../partials/header';
import dashboardPage from '../../../../../../../pages/insurance/dashboard';

context(
'Insurance - Account - Sign in - I want to go straight to my application if there is exactly one application in progress or the dashboard otherwise',
Expand Down Expand Up @@ -43,7 +42,7 @@ context(
// go to all applications for user
cy.clickHeaderApplicationsLink();
// click on start new application page
dashboardPage.startNewApplicationButton().click();
cy.clickStartNewApplicationButton();

// complete eligibility questions
cy.submitInsuranceEligibilityAnswersHappyPath();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import dashboardPage from '../../../../pages/insurance/dashboard';
import { autoCompleteField, field } from '../../../../pages/shared';
import { ROUTES, FIELD_IDS } from '../../../../constants';

Expand Down Expand Up @@ -28,7 +27,7 @@ context('Insurance - Eligibility - start and complete for a second time after cr

cy.clickHeaderApplicationsLink();

dashboardPage.startNewApplicationButton().click();
cy.clickStartNewApplicationButton();

cy.assertUrl(exporterLocationUrl);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import dashboardPage from '../../../../../pages/insurance/dashboard';
import { INSURANCE_ROUTES } from '../../../../../constants/routes/insurance';

const { ROOT: INSURANCE_ROOT, ALL_SECTIONS } = INSURANCE_ROUTES;
Expand All @@ -14,7 +13,7 @@ context('Insurance - Dashboard - Start new application button - As an Exporter,

cy.clickHeaderApplicationsLink();

dashboardPage.startNewApplicationButton().click();
cy.clickStartNewApplicationButton();

cy.submitInsuranceEligibilityAnswersHappyPath();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ context('Insurance - Dashboard - new application', () => {
let secondReferenceNumber;

before(() => {
dashboardPage.startNewApplicationButton().click();
cy.clickStartNewApplicationButton();

cy.submitInsuranceEligibilityAnswersFromExporterLocationHappyPath({});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import dashboardPage from '../../../../../pages/insurance/dashboard';
import partials from '../../../../../partials';
import { PAGES } from '../../../../../content-strings';
import { INSURANCE_ROUTES } from '../../../../../constants/routes/insurance';

Expand Down Expand Up @@ -43,18 +44,16 @@ context('Insurance - Dashboard - no applications', () => {
});

it('should render `start new application` link', () => {
const selector = dashboardPage.startNewApplicationButton();

const expected = {
href: ELIGIBILITY.EXPORTER_LOCATION,
copy: CONTENT_STRINGS.START_NEW_APPLICATION.TEXT,
};

cy.checkLink(selector, expected.href, expected.copy);
cy.checkLink(partials.startNewApplicationButton(), expected.href, expected.copy);
});

it(`should redirect to ${ELIGIBILITY.EXPORTER_LOCATION}`, () => {
dashboardPage.startNewApplicationButton().click();
cy.clickStartNewApplicationButton();

const expectedUrl = `${baseUrl}${ELIGIBILITY.EXPORTER_LOCATION}`;

Expand All @@ -65,7 +64,7 @@ context('Insurance - Dashboard - no applications', () => {
describe('when starting and completing insurance eligibility via the `start new` button ', () => {
it('should create a new application and render in the dashboard', () => {
cy.navigateToDashboardUrl();
dashboardPage.startNewApplicationButton().click();
cy.clickStartNewApplicationButton();

cy.submitInsuranceEligibilityAnswersHappyPath();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import dashboardPage from '../../../../../pages/insurance/dashboard';
import partials from '../../../../../partials';
import { DEFAULT, PAGES, BUTTONS } from '../../../../../content-strings';
import { ROUTES } from '../../../../../constants';
import { INSURANCE_FIELD_IDS } from '../../../../../constants/field-ids/insurance';
Expand Down Expand Up @@ -161,14 +162,12 @@ context(
});

it('should render', () => {
const element = dashboardPage.startNewApplicationButton();

const expected = {
href: expectedUrl,
text: BUTTONS.START_A_NEW_APPLICATION,
};

cy.checkLink(element, expected.href, expected.text);
cy.checkLink(partials.startNewApplicationButton(), expected.href, expected.text);
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import dashboardPage from '../../../../../../pages/insurance/dashboard';
import { INSURANCE_ROUTES } from '../../../../../../constants/routes/insurance';

const { ROOT, ALL_SECTIONS } = INSURANCE_ROUTES;
Expand All @@ -12,7 +11,7 @@ context(
before(() => {
cy.completeSignInAndGoToDashboard().then(() => {
// start new application/eligibility flow
dashboardPage.startNewApplicationButton().click();
cy.clickStartNewApplicationButton();

cy.submitInsuranceEligibilityAnswersFromExporterLocationHappyPath({});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import dashboardPage from '../../../../pages/insurance/dashboard';

context('Insurance - header - authenticated - complete insurance eligibility', () => {
let referenceNumber;

Expand All @@ -11,7 +9,7 @@ context('Insurance - header - authenticated - complete insurance eligibility', (
cy.clickHeaderApplicationsLink();

// start a new application
dashboardPage.startNewApplicationButton().click();
cy.clickStartNewApplicationButton();
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { INSURANCE_FIELD_IDS } from '../../../../../constants/field-ids/insurance';
import { field } from '../../../../../pages/shared';
import dashboardPage from '../../../../../pages/insurance/dashboard';
import partials from '../../../../../partials';
import mockAccount from '../../../../../fixtures/account';
import mockNameWithSpecialCharacters from '../../../../../fixtures/name-with-special-characters';
Expand Down Expand Up @@ -51,7 +50,7 @@ context('Insurance - Name fields - Header and page fields should render special

cy.navigateToDashboardUrl();

dashboardPage.startNewApplicationButton().click();
cy.clickStartNewApplicationButton();

cy.submitInsuranceEligibilityAnswersFromExporterLocationHappyPath({});

Expand Down
1 change: 0 additions & 1 deletion e2e-tests/pages/insurance/dashboard/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const dashboardPage = {
noApplications: () => cy.get('[data-cy="no-applications"]'),
startNewApplicationButton: () => cy.get('[data-cy="start-new-application-button"]'),
getAQuoteButton: () => cy.get('[data-cy="get-a-quote-button"]'),
table: {
headers: {
Expand Down
1 change: 1 addition & 0 deletions e2e-tests/partials/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const partials = {
provideAlternativeCurrencyLink: () => cy.get('[data-cy="provide-alternative-currency-link"]'),
privateMarketWhyDescription,
skipLink: () => cy.get('[data-cy="skip-link"]'),
startNewApplicationButton: () => cy.get('[data-cy="start-new-application-button"]'),
ukGoodsOrServicesCalculateDescription,
ukGoodsOrServicesDescription,
};
Expand Down
5 changes: 1 addition & 4 deletions src/api/.keystone/config.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,7 @@ describe('api/generate-xlsx/map-application-to-xlsx/helpers/map-yes-no-field', (
});
});

describe('when value is undefined and a default value is passed', () => {
it('should return the default value', () => {
const mockDefaultValue = 'Mock default value';

const response = mapYesNoField({ defaultValue: mockDefaultValue });

expect(response).toEqual(mockDefaultValue);
});
});

describe('when value is "undefined"', () => {
describe('when value is undefined', () => {
it(`should return ${DEFAULT.EMPTY}`, () => {
const response = mapYesNoField({});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ const { YES, NO } = FIELD_VALUES;
* mapYesNoField
* Map a "true" or "false" field to Yes/No
* @param {Boolean} answer: The boolean answer to map into a yes/no string.
* @param {String} defaultValue: Custom default value.
* @returns {String} "Yes/No" or DEFAULT.EMPTY
*/
const mapYesNoField = ({ answer, defaultValue }: MapYesNoFieldParams): string => {
const mapYesNoField = ({ answer }: MapYesNoFieldParams): string => {
if (answer === false) {
return NO;
}
Expand All @@ -20,10 +19,6 @@ const mapYesNoField = ({ answer, defaultValue }: MapYesNoFieldParams): string =>
return YES;
}

if (defaultValue) {
return defaultValue;
}

return DEFAULT.EMPTY;
};

Expand Down
2 changes: 1 addition & 1 deletion src/api/test-helpers/applications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const update = async ({ context, applicationId, data }: TestHelperApplicationUpd

/**
* deleteAll test helper
* Get all accounts and delete them.
* Get all applications and delete them.
* @param {Context} context: KeystoneJS context API
* @returns {Array} Accounts that have been deleted
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const {
* Check submitted form data for errors with the email field
* Returns generateValidationErrors if there are any errors.
* @param {RequestBody} formBody: Form body
* @param {Object} Errors object from previous validation errors
* @param {Object} errors: Errors from previous validation errors
* @returns {ValidationErrors}
*/
const emailRules = (formBody: RequestBody, errors: object) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const {
* Check submitted form data for errors with the first name field
* Returns generateValidationErrors if there are any errors.
* @param {RequestBody} formBody: Form body
* @param {Object} Errors object from previous validation errors
* @param {Object} errors: Errors from previous validation errors
* @returns {ValidationErrors}
*/
const firstNameRules = (formBody: RequestBody, errors: object) => nameValidation(formBody, FIELD_ID, ERROR_MESSAGE, errors);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const {
* Check submitted form data for errors with the last name field
* Returns generateValidationErrors if there are any errors.
* @param {RequestBody} formBody: Form body
* @param {Object} Errors object from previous validation errors
* @param {Object} errors: Errors from previous validation errors
* @returns {ValidationErrors} nameValidation
*/
const lastNameRules = (formBody: RequestBody, errors: object) => nameValidation(formBody, FIELD_ID, ERROR_MESSAGE, errors);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const {
* Check submitted form data for errors with the password field
* Returns generateValidationErrors if there are any errors.
* @param {RequestBody} formBody: Form body
* @param {Object} Errors object from previous validation errors
* @param {Object} errors: Errors from previous validation errors
* @returns {ValidationErrors}
*/
const passwordRules = (formBody: RequestBody, errors: object) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const {
* Check submitted form data for errors with the password field
* Returns generateValidationErrors if there are any errors.
* @param {RequestBody} formBody: Form body
* @param {Object} Errors object from previous validation errors
* @param {Object} errors: Errors from previous validation errors
* @returns {ValidationErrors}
*/
const passwordRules = (formBody: RequestBody, errors: object) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const {
* emailRules
* Returns emailValidation
* @param {RequestBody} formBody: Form body
* @param {Object} Errors object from previous validation errors
* @param {Object} errors: Errors from previous validation errors
* @returns {ValidationErrors}
*/
const emailRules = (formBody: RequestBody, errors: object) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const {
* accessCodeRules
* Returns the result of emptyFieldValidation
* @param {RequestBody} formBody: Form body
* @param {Object} Errors object from previous validation errors
* @param {Object} errors: Errors from previous validation errors
* @returns {ValidationErrors}
*/
const accessCodeRules = (formBody: RequestBody, errors: object) => emptyFieldValidation(formBody, FIELD_ID, ERROR_MESSAGE.INCORRECT, errors);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const {
* 3) Check if an email is below the minimum length via maxLengthValidation.
* If all of the conditions are met, empty errors are returned (via maxLengthValidation).
* @param {RequestBody} formBody: Form body
* @param {Object} Errors object from previous validation errors
* @param {Object} errors: Errors from previous validation errors
* @returns {ValidationErrors} emailAndPasswordValidation | maxLengthValidation
*/
const emailRules = (formBody: RequestBody, errors: object) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const { PASSWORD: FIELD_ID } = FIELD_IDS;
* This ensures that a validation error is returned for both EMIL and PASSWORD,
* to indicate to a user that the credentials are invalid.
* @param {RequestBody} formBody: Form body
* @param {Object} Errors object from previous validation errors
* @param {Object} errors: Errors from previous validation errors
* @returns {Function} emailAndPasswordValidation
*/
const passwordRules = (formBody: RequestBody, errors: object) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FIELD_IDS } from '..';
import { ROUTES } from '../../../../../constants';
import BUSINESS_FIELD_IDS from '../../../../../constants/field-ids/insurance/business';
import mapAndSave from '../../map-and-save/company-different-trading-address';
import { mockReq, mockRes, mockApplication, mockSpyPromiseRejection } from '../../../../../test-mocks';
import { mockReq, mockRes, mockApplication, mockSpyPromiseRejection, referenceNumber } from '../../../../../test-mocks';
import { Request, Response } from '../../../../../../types';

const {
Expand Down Expand Up @@ -40,7 +40,7 @@ describe('controllers/insurance/business/alternative-trading-address/save-and-ba

await post(req, res);

expect(res.redirect).toHaveBeenCalledWith(`${INSURANCE_ROOT}/${req.params.referenceNumber}${ALL_SECTIONS}`);
expect(res.redirect).toHaveBeenCalledWith(`${INSURANCE_ROOT}/${referenceNumber}${ALL_SECTIONS}`);
});

it('should call mapAndSave.companyDifferentTradingAddress once with data from constructPayload', async () => {
Expand All @@ -66,7 +66,7 @@ describe('controllers/insurance/business/alternative-trading-address/save-and-ba

await post(req, res);

expect(res.redirect).toHaveBeenCalledWith(`${INSURANCE_ROOT}/${req.params.referenceNumber}${ALL_SECTIONS}`);
expect(res.redirect).toHaveBeenCalledWith(`${INSURANCE_ROOT}/${referenceNumber}${ALL_SECTIONS}`);
});

it('should not call mapAndSave.companyDifferentTradingAddress', async () => {
Expand Down
Loading

0 comments on commit 22deb8d

Please sign in to comment.