Skip to content

Commit

Permalink
Add success page functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
paulgain committed Mar 12, 2024
1 parent f8257a1 commit 7e364f5
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 7 deletions.
2 changes: 1 addition & 1 deletion test/a11y/cypress/config/urlTestExclusions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' },

Expand Down
3 changes: 2 additions & 1 deletion test/functional/cypress/fakers/export-wins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -28,4 +28,5 @@ export const exportWinsFaker = () => ({
customer_response: {
responded_on: faker.date.anytime().toISOString(),
},
...overrides,
})
57 changes: 52 additions & 5 deletions test/functional/cypress/specs/export-win/add-export-win-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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: '[email protected]' }],
})

const twelveMonthsAgo = getTwelveMonthsAgo()
const month = twelveMonthsAgo.getMonth() + 1
const year = twelveMonthsAgo.getFullYear()
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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 [email protected] 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')
})
})

Expand Down

0 comments on commit 7e364f5

Please sign in to comment.