Skip to content

Commit

Permalink
feat(EMS-289): add "buyer body" page/flow (#93)
Browse files Browse the repository at this point in the history
* feat(EMS-289): add buyer body page/flow

* tech(EMS-289): render specific descriptions in 'get a quote by email' exit page depending on the reason

* feat(EMS-289): update/fix e2e tests
  • Loading branch information
ttbarnes authored Aug 25, 2022
1 parent c49d8ca commit 071e3f1
Show file tree
Hide file tree
Showing 53 changed files with 839 additions and 114 deletions.
1 change: 1 addition & 0 deletions e2e-tests/constants/field-ids.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const FIELD_IDS = {
VALID_BUYER_BODY: 'validBuyerBody',
VALID_COMPANY_BASE: 'validCompanyBase',
BUYER_COUNTRY: 'buyerCountry',
COUNTRY: 'country',
Expand Down
2 changes: 2 additions & 0 deletions e2e-tests/constants/routes/quote.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const QUOTE_ROUTES = {
BUYER_BODY: '/quote/type-of-buyer',

BUYER_COUNTRY: '/quote/buyer-country',
BUYER_COUNTRY_CHANGE: '/quote/buyer-country/change',

Expand Down
3 changes: 2 additions & 1 deletion e2e-tests/constants/templates/quote.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const QUOTE_TEMPLATES = {
COMPANY_BASED: 'quote/company-based.njk',
BUYER_BODY: 'quote/buyer-body.njk',
BUYER_COUNTRY: 'quote/buyer-country.njk',
COMPANY_BASED: 'quote/company-based.njk',
HAS_MINIMUM_UK_GOODS_OR_SERVICES: 'quote/uk-goods-or-services.njk',
POLICY_TYPE: 'quote/policy-type.njk',
TELL_US_ABOUT_YOUR_POLICY: 'quote/tell-us-about-your-policy.njk',
Expand Down
3 changes: 2 additions & 1 deletion e2e-tests/content-strings/error-messages.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const FIELD_IDS = require('../constants/field-ids');

const ERROR_MESSAGES = {
[FIELD_IDS.VALID_COMPANY_BASE]: 'Select if your company is based in the UK, Channel Islands, Isle of Man or not',
[FIELD_IDS.BUYER_COUNTRY]: 'Select where your buyer is based',
[FIELD_IDS.COUNTRY]: 'Select where your buyer is based',
[FIELD_IDS.VALID_BUYER_BODY]: 'Select if your buyer is a government or public sector body',
[FIELD_IDS.VALID_COMPANY_BASE]: 'Select if your company is based in the UK, Channel Islands, Isle of Man or not',
[FIELD_IDS.HAS_MINIMUM_UK_GOODS_OR_SERVICES]: {
IS_EMPTY: 'Select whether at least 20% of your export contract value is made up from UK goods and services',
},
Expand Down
29 changes: 21 additions & 8 deletions e2e-tests/content-strings/pages.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
const LINKS = require('./links');

const COMPANY_BASED_PAGE = {
PAGE_TITLE: 'Is your company based inside the UK, Channel Islands or Isle of Man?',
HEADING: 'Is your company based inside the UK, Channel Islands or Isle of Man?',
};

const BUYER_COUNTRY_PAGE = {
PAGE_TITLE: 'Where is your buyer based?',
HEADING: 'Where is your buyer based?',
};

const BUYER_BODY_PAGE = {
PAGE_TITLE: 'Is your buyer a government or public sector body?',
HEADING: 'Is your buyer a government or public sector body?',
DETAILS: {
INTRO: 'What counts as a government or public sector body?',
BODY_1: 'This means a formally established organisation that is, at least in part, publicly funded to deliver a public or government service.',
BODY_2: 'For example, a central government department, a local authority or a public utlity company.',
},
};

const COMPANY_BASED_PAGE = {
PAGE_TITLE: 'Is your company based inside the UK, Channel Islands or Isle of Man?',
HEADING: 'Is your company based inside the UK, Channel Islands or Isle of Man?',
};

const HAS_MINIMUM_UK_GOODS_OR_SERVICES_PAGE = {
PAGE_TITLE: 'Is at least 20% of your export contract value made up from UK goods or services?',
HEADING: 'Is at least 20% of your export contract value made up from UK goods or services?',
Expand Down Expand Up @@ -124,8 +134,10 @@ const GET_A_QUOTE_BY_EMAIL_PAGE = {
PAGE_TITLE: 'You need to get a quote by email',
HEADING: 'You need to get a quote by email',
REASON: {
BODY_1: 'We cannot give you a quote online because of the country where your buyer is based.',
BODY_2: "We can still give you a quote but may need extra information from you to assess the risks around your buyer's country first.",
BUYER_BODY: 'We cannot give you a quote online because your buyer is a government or public sector body.',
BUYER_BODY_DESCRIPTION: "We can still give you a quote but may need extra information from you to assess the risks around your buyer first.",
BUYER_COUNTRY: 'We cannot give you a quote online because of the country where your buyer is based.',
BUYER_COUNTRY_DESCRIPTION: "We can still give you a quote but may need extra information from you to assess the risks around your buyer's country first.",
},
ACTION: [
[
Expand Down Expand Up @@ -269,8 +281,9 @@ const PROBLEM_WITH_SERVICE_PAGE = {
};

module.exports = {
COMPANY_BASED_PAGE,
BUYER_COUNTRY_PAGE,
BUYER_BODY_PAGE,
COMPANY_BASED_PAGE,
HAS_MINIMUM_UK_GOODS_OR_SERVICES_PAGE,
POLICY_TYPE_PAGE,
TELL_US_ABOUT_YOUR_POLICY_PAGE,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import {
buyerBodyPage,
getAQuoteByEmailPage,
} from '../../../pages/quote';
import partials from '../../../partials';
import { PAGES } from '../../../../../content-strings';
import CONSTANTS from '../../../../../constants';
import { completeAndSubmitBuyerCountryForm } from '../../../../support/quote/forms';

const CONTENT_STRINGS = PAGES.BUYER_BODY_PAGE;
const { ROUTES, FIELD_IDS } = CONSTANTS;

context('Buyer body page - as an exporter, I want to check if I can get an EXIP online quote for my buyers country - submit `buyer is a government or public sector body`', () => {
before(() => {
cy.login();
completeAndSubmitBuyerCountryForm();

cy.url().should('include', ROUTES.QUOTE.BUYER_BODY);

buyerBodyPage[FIELD_IDS.VALID_BUYER_BODY].yes().click();
buyerBodyPage.submitButton().click();
});

beforeEach(() => {
Cypress.Cookies.preserveOnce('_csrf');
Cypress.Cookies.preserveOnce('connect.sid');
});

it('redirects to exit page', () => {
cy.url().should('include', ROUTES.QUOTE.GET_A_QUOTE_BY_EMAIL);
});

it('renders a back link with correct url', () => {
partials.backLink().should('exist');

partials.backLink().should('have.attr', 'href', ROUTES.QUOTE.BUYER_BODY);
});

it('renders a specific reason and description', () => {
getAQuoteByEmailPage.reason().invoke('text').then((text) => {
const expected = PAGES.GET_A_QUOTE_BY_EMAIL_PAGE.REASON.BUYER_BODY;

expect(text.trim()).equal(expected);
});

getAQuoteByEmailPage.description().invoke('text').then((text) => {
const expected = PAGES.GET_A_QUOTE_BY_EMAIL_PAGE.REASON.BUYER_BODY_DESCRIPTION;

expect(text.trim()).equal(expected);
});
});

describe('navigating back to the buyer body page', () => {
it('auto checks the previously submitted answer', () => {
partials.backLink().click();

const yesRadio = buyerBodyPage[FIELD_IDS.VALID_BUYER_BODY].yesInput();
yesRadio.should('be.checked');
});
});
});
118 changes: 118 additions & 0 deletions e2e-tests/cypress/e2e/journeys/quote/buyer-body/buyer-body.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import { buyerBodyPage } from '../../../pages/quote';
import partials from '../../../partials';
import {
BUTTONS,
ERROR_MESSAGES,
FIELDS,
LINKS,
ORGANISATION,
PAGES,
} from '../../../../../content-strings';
import CONSTANTS from '../../../../../constants';
import { completeAndSubmitBuyerCountryForm } from '../../../../support/quote/forms';

const CONTENT_STRINGS = PAGES.BUYER_BODY_PAGE;
const { ROUTES, FIELD_IDS } = CONSTANTS;

context('Buyer body page - as an exporter, I want to check if I can get an EXIP online quote for my buyers country', () => {
beforeEach(() => {
cy.login();
completeAndSubmitBuyerCountryForm();

cy.url().should('include', ROUTES.QUOTE.BUYER_BODY);
});

it('passes the audits', () => {
cy.lighthouse({
accessibility: 100,
performance: 80,
'best-practices': 100,
seo: 60,
});
});

it('renders a phase banner', () => {
cy.checkPhaseBanner();
});

it('renders a back link with correct url', () => {
partials.backLink().should('exist');
partials.backLink().invoke('text').then((text) => {
expect(text.trim()).equal(LINKS.BACK);
});

const expected = `${Cypress.config('baseUrl')}${ROUTES.QUOTE.BUYER_COUNTRY}`;
partials.backLink().should('have.attr', 'href', expected);
});

it('renders a page title and heading', () => {
const expectedPageTitle = `${CONTENT_STRINGS.PAGE_TITLE} - ${ORGANISATION}`;
cy.title().should('eq', expectedPageTitle);

buyerBodyPage.heading().invoke('text').then((text) => {
expect(text.trim()).equal(CONTENT_STRINGS.HEADING);
});
});

it('renders yes and no radio buttons', () => {
const yesRadio = buyerBodyPage[FIELD_IDS.VALID_BUYER_BODY].yes();
yesRadio.should('exist');

yesRadio.invoke('text').then((text) => {
expect(text.trim()).equal('Yes');
});

const noRadio = buyerBodyPage[FIELD_IDS.VALID_BUYER_BODY].no();
noRadio.should('exist');

noRadio.invoke('text').then((text) => {
expect(text.trim()).equal('No');
});
});

it('renders a submit button', () => {
const button = buyerBodyPage.submitButton();
button.should('exist');

button.invoke('text').then((text) => {
expect(text.trim()).equal(BUTTONS.CONTINUE);
});
});

describe('form submission', () => {
describe('when submitting an empty form', () => {
it('should render validation errors', () => {
buyerBodyPage.submitButton().click();

partials.errorSummaryListItems().should('exist');
partials.errorSummaryListItems().should('have.length', 1);

const expectedMessage = ERROR_MESSAGES[FIELD_IDS.VALID_BUYER_BODY];

partials.errorSummaryListItems().first().invoke('text').then((text) => {
expect(text.trim()).equal(expectedMessage);
});

buyerBodyPage[FIELD_IDS.VALID_BUYER_BODY].errorMessage().invoke('text').then((text) => {
expect(text.trim()).includes(expectedMessage);
});
});

it('should focus on input when clicking summary error message', () => {
buyerBodyPage.submitButton().click();

partials.errorSummaryListItemLinks().eq(0).click();
buyerBodyPage[FIELD_IDS.VALID_BUYER_BODY].yesInput().should('have.focus');
});
});

describe('when submitting the answer as `no`', () => {
it(`should redirect to ${ROUTES.QUOTE.COMPANY_BASED}`, () => {
buyerBodyPage[FIELD_IDS.VALID_BUYER_BODY].no().click();
buyerBodyPage.submitButton().click();

cy.url().should('include', ROUTES.QUOTE.COMPANY_BASED);
});
});
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
buyerCountryPage,
cannotObtainCoverPage,
} from '../../../pages/quote';
import { buyerCountryPage } from '../../../pages/quote';
import partials from '../../../partials';
import { PAGES } from '../../../../../content-strings';
import CONSTANTS from '../../../../../constants';
Expand Down Expand Up @@ -36,7 +33,7 @@ context('Buyer country page - as an exporter, I want to check if UKEF issue expo
it('renders a back link with correct url', () => {
partials.backLink().should('exist');

const expected = `${Cypress.config('baseUrl')}${ROUTES.QUOTE.BUYER_COUNTRY}`;
const expected = ROUTES.QUOTE.BUYER_COUNTRY;

partials.backLink().should('have.attr', 'href', expected);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,15 @@ context('Buyer country page - as an exporter, I want to check if UKEF issue expo
});

describe('when submitting with a supported country', () => {
it(`should redirect to ${ROUTES.QUOTE.COMPANY_BASED}`, () => {
it(`should redirect to ${ROUTES.QUOTE.BUYER_BODY}`, () => {
buyerCountryPage.searchInput().type('Algeria');

const results = buyerCountryPage.results();
results.first().click();

buyerCountryPage.submitButton().click();

cy.url().should('include', ROUTES.QUOTE.COMPANY_BASED);
cy.url().should('include', ROUTES.QUOTE.BUYER_BODY);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ import {
PAGES,
} from '../../../../content-strings';
import CONSTANTS from '../../../../constants';
import { completeAndSubmitBuyerForm, completeAndSubmitCompanyForm } from '../../../support/quote/forms';
import { completeAndSubmitBuyerCountryForm, completeAndSubmitBuyerBodyForm, completeAndSubmitCompanyForm } from '../../../support/quote/forms';

const CONTENT_STRINGS = PAGES.CANNOT_OBTAIN_COVER_PAGE;
const { FIELD_IDS, ROUTES } = CONSTANTS;

context('Cannot obtain UKEF cover exit page', () => {
beforeEach(() => {
cy.login();
completeAndSubmitBuyerForm();
completeAndSubmitBuyerCountryForm();
completeAndSubmitBuyerBodyForm();
completeAndSubmitCompanyForm();

cy.url().should('include', ROUTES.QUOTE.HAS_MINIMUM_UK_GOODS_OR_SERVICES);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import CONSTANTS from '../../../../../constants';
const { ROUTES } = CONSTANTS;

context('Manually going to the `Buyer body` via URL page without completing the previous forms', () => {
beforeEach(() => {
cy.visit(ROUTES.QUOTE.BUYER_BODY, {
auth: {
username: Cypress.config('basicAuthKey'),
password: Cypress.config('basicAuthSecret'),
},
});
});

it('should redirect to the `need to start again` exit page', () => {
cy.url().should('include', ROUTES.QUOTE.NEED_TO_START_AGAIN);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
import partials from '../../../partials';
import CONSTANTS from '../../../../../constants';
import {
completeAndSubmitBuyerForm,
completeAndSubmitBuyerCountryForm,
completeAndSubmitBuyerBodyForm,
completeAndSubmitCompanyForm,
completeAndSubmitUkContentForm,
completeAndSubmitPolicyTypeSingleForm,
Expand All @@ -27,10 +28,12 @@ context('Change your answers (policy type) - multiple times via back button - as
before(() => {
cy.login();

completeAndSubmitBuyerForm();
completeAndSubmitBuyerCountryForm();
completeAndSubmitBuyerBodyForm();
completeAndSubmitCompanyForm();
completeAndSubmitUkContentForm();
completeAndSubmitPolicyTypeSingleForm();

cy.url().should('include', ROUTES.QUOTE.TELL_US_ABOUT_YOUR_POLICY);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ import {
import partials from '../../../partials';
import { PAGES } from '../../../../../content-strings';
import CONSTANTS from '../../../../../constants';
import { completeAndSubmitBuyerForm } from '../../../../support/quote/forms';
import { completeAndSubmitBuyerCountryForm, completeAndSubmitBuyerBodyForm } from '../../../../support/quote/forms';

const CONTENT_STRINGS = PAGES.CANNOT_OBTAIN_COVER_PAGE;
const { ROUTES, FIELD_IDS } = CONSTANTS;

context('Company based page - as an exporter, I want to check if my company can get UKEF issue export insurance cover - submit `not based inside the UK`', () => {
before(() => {
cy.login();
completeAndSubmitBuyerForm();
completeAndSubmitBuyerCountryForm();
completeAndSubmitBuyerBodyForm();

cy.url().should('include', ROUTES.QUOTE.COMPANY_BASED);

Expand Down
Loading

0 comments on commit 071e3f1

Please sign in to comment.