From 7e364f5a5f1d4fdd10a7f1b5bf1cd99fb29e51a2 Mon Sep 17 00:00:00 2001 From: Paul Gain Date: Tue, 12 Mar 2024 13:38:50 +0000 Subject: [PATCH] Add success page functional tests --- test/a11y/cypress/config/urlTestExclusions.js | 2 +- test/functional/cypress/fakers/export-wins.js | 3 +- .../specs/export-win/add-export-win-spec.js | 57 +++++++++++++++++-- 3 files changed, 55 insertions(+), 7 deletions(-) diff --git a/test/a11y/cypress/config/urlTestExclusions.js b/test/a11y/cypress/config/urlTestExclusions.js index 85b4233cfe9..eec4df73300 100644 --- a/test/a11y/cypress/config/urlTestExclusions.js +++ b/test/a11y/cypress/config/urlTestExclusions.js @@ -150,7 +150,7 @@ export const urlTestExclusions = [ { url: '/exportwins/sent/' }, { url: '/exportwins/rejected/' }, { url: '/exportwins/:winId/edit' }, - { url: '/exportwins/:winId/thankyou' }, + { url: '/exportwins/:winId/success' }, { url: '/exportwins/:winId/customer-feedback' }, { url: '/companies/:companyId/export/:exportId/exportwins/create' }, diff --git a/test/functional/cypress/fakers/export-wins.js b/test/functional/cypress/fakers/export-wins.js index 58d8b898f96..86529a6d659 100644 --- a/test/functional/cypress/fakers/export-wins.js +++ b/test/functional/cypress/fakers/export-wins.js @@ -3,7 +3,7 @@ import { faker } from '@faker-js/faker' /** * Generate fake data for a single export win. */ -export const exportWinsFaker = () => ({ +export const exportWinsFaker = (overrides = {}) => ({ id: faker.string.uuid(), adviser: { id: faker.string.uuid(), @@ -28,4 +28,5 @@ export const exportWinsFaker = () => ({ customer_response: { responded_on: faker.date.anytime().toISOString(), }, + ...overrides, }) diff --git a/test/functional/cypress/specs/export-win/add-export-win-spec.js b/test/functional/cypress/specs/export-win/add-export-win-spec.js index 96a0ff6af3d..14e73232777 100644 --- a/test/functional/cypress/specs/export-win/add-export-win-spec.js +++ b/test/functional/cypress/specs/export-win/add-export-win-spec.js @@ -9,6 +9,7 @@ import { clickContinueButton } from '../../support/actions' import { companyFaker } from '../../fakers/companies' import { contactFaker } from '../../fakers/contacts' import { exportFaker } from '../../fakers/export' +import { exportWinsFaker } from '../../fakers/export-wins' import urls from '../../../../../src/lib/urls' import { assertUrl, @@ -31,6 +32,12 @@ const company = companyFaker({ name: 'Advanced Mini Devices', }) +const exportWin = exportWinsFaker({ + country: { name: 'Dubai' }, + name_of_export: 'Rolls Reece Cars', + company_contacts: [{ email: 'jeff.marks@test.com' }], +}) + const twelveMonthsAgo = getTwelveMonthsAgo() const month = twelveMonthsAgo.getMonth() + 1 const year = twelveMonthsAgo.getFullYear() @@ -105,6 +112,13 @@ const formFields = { personallyConfirmed: '[data-test="field-is_personally_confirmed"]', lineManagerConfirmed: '[data-test="field-is_line_manager_confirmed"]', }, + successPage: { + flash: '[data-test="flash"]', + heading: '[data-test="heading"]', + review: '[data-test="review"]', + email: '[data-test="email"]', + exportWinsLink: '[data-test="export-wins-link"]', + }, } const clickContinueAndAssertUrl = (url) => { @@ -163,6 +177,12 @@ describe('Adding an export win', () => { cy.intercept('GET', '/api-proxy/v4/metadata/associated-programme', [ { id: '600', name: 'Afterburner' }, ]) + cy.intercept('POST', '/api-proxy/v4/export-win', { + statusCode: 201, + }).as('apiPostExportWin') + cy.intercept('GET', '/api-proxy/v4/export-win/*', exportWin).as( + 'apiGetExportWin' + ) }) context('Breadcrumbs', () => { @@ -1055,16 +1075,15 @@ describe('Adding an export win', () => { ) }) - it('should POST to the API and have the correct payload', () => { + it('should POST to the API and redirect to the success page', () => { + const successPageRegex = /\/exportwins\/[^/]+\/success/ + cy.get('[data-test="confirm-and-send-to-customer"]').should( 'have.text', 'Confirm and send to customer' ) - cy.intercept('POST', '/api-proxy/v4/export-win', { - statusCode: 201, - }).as('apiRequest') cy.get('[data-test="confirm-and-send-to-customer"]').click() - cy.wait('@apiRequest').then(({ request }) => { + cy.wait('@apiPostExportWin').then(({ request }) => { expect(omit(request.body, '_csrf')).to.deep.equal({ lead_officer: '100', team_type: '42bdaf2e-ae19-4589-9840-5dbb67b50add', @@ -1116,6 +1135,34 @@ describe('Adding an export win', () => { adviser: '7d19d407-9aec-4d06-b190-d3f404627f21', }) }) + cy.location().should(({ pathname }) => { + expect(pathname).to.match(successPageRegex) + }) + }) + + it('should render a success page', () => { + const { successPage } = formFields + + cy.get(successPage.flash).should( + 'have.text', + 'The export win Rolls Reece Cars to Dubai has been sent to jeff.marks@test.com for review and confirmation.' + ) + + cy.get(successPage.heading).should('have.text', 'What happens next?') + + cy.get(successPage.review).should( + 'have.text', + 'The customer will review the export win and have the option to provide feedback.' + ) + + cy.get(successPage.email).should( + 'have.text', + 'You will be sent an email once the customer has responded.' + ) + + cy.get(successPage.exportWinsLink) + .should('have.text', 'Export wins') + .should('have.attr', 'href', '/exportwins') }) })