Skip to content

Commit

Permalink
Implement EW migration alert banner messages
Browse files Browse the repository at this point in the history
WIP
  • Loading branch information
dredmonds committed Nov 5, 2024
1 parent f80fd38 commit 3de730a
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 58 deletions.
53 changes: 27 additions & 26 deletions src/client/modules/ExportWins/Form/ExportWinForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Link } from 'govuk-react'
import { connect } from 'react-redux'
import styled from 'styled-components'
import pluralize from 'pluralize'
import { FONT_SIZE } from '@govuk-react/constants'

import FlashMessages from '../../../components/LocalHeader/FlashMessages'
import { steps, EMAIL, STEP_TO_EXCLUDED_FIELDS_MAP } from './constants'
Expand All @@ -22,22 +21,11 @@ import { ExportWinSuccess } from './Success'
import State from '../../../components/State'
import urls from '../../../../lib/urls'
import SummaryStep from './SummaryStep'
import {
Form,
FormLayout,
DefaultLayout,
StatusMessage,
} from '../../../components'
import { Form, FormLayout, DefaultLayout } from '../../../components'
import { WINS_HISTORIC_ALERT_BANNER } from '../Status/ExportWinsTabNav'

const FORM_ID = 'export-win-form'

const StyledStatusMessage = styled(StatusMessage)({
fontSize: FONT_SIZE.SIZE_20,
fontWeight: 700,
marginTop: 25,
marginBottom: 5,
})

const StyledParagraph = styled('p')({
fontWeight: 'bold',
})
Expand Down Expand Up @@ -93,6 +81,31 @@ const ExportWinForm = ({
heading={heading}
subheading={subheading}
breadcrumbs={breadcrumbs}
flashMessages={[
[
isEditing ? (
<>
<StyledParagraph>
{WINS_HISTORIC_ALERT_BANNER}
</StyledParagraph>
{currentStepName === steps.SUMMARY ? (
<>
<StyledParagraph>
To edit an export win
</StyledParagraph>
<StyledParagraph>
Edit each section that needs changing then return to
the summary page. When you are happy with all the
changes save the page.
</StyledParagraph>
</>
) : excludedStepFields ? (
<ContactLink sections={excludedStepFields} />
) : null}
</>
) : null,
],
]}
localHeaderChildren={
isEditing ? (
currentStepName === steps.SUMMARY ? (
Expand All @@ -104,24 +117,12 @@ const ExportWinForm = ({
}}
/>
)}
<StyledStatusMessage>
<StyledParagraph>To edit an export win</StyledParagraph>
<StyledParagraph>
Edit each section that needs changing then return to
the summary page. When you are happy with all the
changes save the page.
</StyledParagraph>
</StyledStatusMessage>
{winStatus === WIN_STATUS.PENDING && (
<ResentExportWinContainer>
<ResendExportWin id={exportWinId} />
</ResentExportWinContainer>
)}
</>
) : excludedStepFields ? (
<StyledStatusMessage>
<ContactLink sections={excludedStepFields} />
</StyledStatusMessage>
) : null
) : null
}
Expand Down
11 changes: 5 additions & 6 deletions src/client/modules/ExportWins/Form/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,12 @@ export const bothGoodsAndServices = {
}

export const STEP_TO_EXCLUDED_FIELDS_MAP = {
[steps.OFFICER_DETAILS]: ['Lead officer name'],
[steps.CUSTOMER_DETAILS]: ['Export experience'],
[steps.CUSTOMER_DETAILS]: ['export experience.'],
[steps.WIN_DETAILS]: [
'Summary of the support given',
'Destination country',
'Date won',
'Type of win and Value',
'summary of the support given',
'destination country',
'date won',
'type of win and value.',
],
}

Expand Down
19 changes: 19 additions & 0 deletions src/client/modules/ExportWins/Status/ExportWinsTabNav.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
import React from 'react'
import { useLocation } from 'react-router-dom'
import { capitalize } from 'lodash'
import { Link } from 'govuk-react'

import { DefaultLayout } from '../../../components'
import TabNav from '../../../components/TabNav'
import WinsRejectedList from './WinsRejectedList'
import WinsPendingList from './WinsPendingList'
import WinsConfirmedList from './WinsConfirmedList'
import urls from '../../../../lib/urls'
import { HISTORIC_ALERT_MESSAGE } from './constants'

const LAST_WORD = /([^\/]+)$/

export const WINS_HISTORIC_ALERT_BANNER = (
<>
{[HISTORIC_ALERT_MESSAGE.ELEMENT].concat(' ')}
{[
<Link
href={HISTORIC_ALERT_MESSAGE.URI_LINK}
target="_blank"
rel="noopener noreferrer"
aria-label="Find out more about historic wins moved to Data Hub"
>
{HISTORIC_ALERT_MESSAGE.URI_ELEMENT}
</Link>,
].concat('.')}
</>
)

const ExportWinsTabNav = () => {
const location = useLocation()
const match = LAST_WORD.exec(location.pathname)
Expand All @@ -28,6 +46,7 @@ const ExportWinsTabNav = () => {
},
{ text: capitalize(title) },
]}
flashMessages={[[WINS_HISTORIC_ALERT_BANNER]]}
>
<TabNav
id="exportwins-tab-nav"
Expand Down
7 changes: 7 additions & 0 deletions src/client/modules/ExportWins/Status/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@ export const ADVISER_ROLES = {
TEAM_MEMBER: 'team member',
CONTRIBUTING_OFFICER: 'contributing officer',
}

export const HISTORIC_ALERT_MESSAGE = {
ELEMENT: 'Historic export wins have now moved to Data Hub,',
URI_ELEMENT: 'see the export wins announcement',
URI_LINK:
'https://data-services-help.trade.gov.uk/data-hub/updates/announcements/new-role-label-on-export-wins/',
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,42 @@
import { exportWinsFaker } from '../../fakers/export-wins'
import urls from '../../../../../src/lib/urls'
import { company, formFields } from './constants'
import { HISTORIC_ALERT_MESSAGE } from '../../../../../src/client/modules/ExportWins/Status/constants'

const exportWin = exportWinsFaker()

const assertHistoricExportWinsMessage = () => {
cy.get('[data-test="status-message"]')
.should('contain', HISTORIC_ALERT_MESSAGE.ELEMENT)
.should('contain.text', HISTORIC_ALERT_MESSAGE.URI_ELEMENT)
.find('a')
.should('have.attr', 'href', HISTORIC_ALERT_MESSAGE.URI_LINK)
}

const assertCustomerDetailsMessage = () => {
cy.get('[data-test="status-message"]').should(
'contain.text',
'Contact [email protected] if you need to update the section: export experience.'
)
}

const assertWinDetailsMessage = () => {
cy.get('[data-test="status-message"]').should(
'contain.text',
'Contact [email protected] if you need to update the sections: ' +
'summary of the support given, destination country, date won, type of win and value.'
)
}

const assertSummaryMessage = () => {
cy.get('[data-test="status-message"]').should(
'contain.text',
'To edit an export win' +
'Edit each section that needs changing then return to the summary page. ' +
'When you are happy with all the changes save the page.'
)
}

describe('Editing a pending export win', () => {
beforeEach(() => {
cy.intercept('GET', '/api-proxy/v4/export-win/*', exportWin).as(
Expand Down Expand Up @@ -41,10 +74,7 @@ describe('Editing a pending export win', () => {
urls.companies.exportWins.editOfficerDetails(company.id, exportWin.id)
)
cy.wait(['@apiGetExportWin', '@apiTeamType', '@apiHqTeam'])
cy.get('[data-test="status-message"]').should(
'have.text',
'Contact [email protected] if you need to update the section: Lead officer name'
)
assertHistoricExportWinsMessage()
})
})

Expand All @@ -54,7 +84,7 @@ describe('Editing a pending export win', () => {
urls.companies.exportWins.editCreditForThisWin(company.id, exportWin.id)
)
cy.wait(['@apiGetExportWin', '@apiTeamType', '@apiHqTeam'])
cy.get('[data-test="status-message"]').should('not.exist')
assertHistoricExportWinsMessage()
})
})

Expand All @@ -67,12 +97,8 @@ describe('Editing a pending export win', () => {
})

it('should render an edit status message', () => {
cy.get('[data-test="status-message"]')
.should('exist')
.should(
'have.text',
'Contact [email protected] if you need to update the section: Export experience'
)
assertHistoricExportWinsMessage()
assertCustomerDetailsMessage()
})

it('should not render Export experience', () => {
Expand All @@ -91,13 +117,8 @@ describe('Editing a pending export win', () => {
})

it('should render an edit status message', () => {
cy.get('[data-test="status-message"]')
.should('exist')
.should(
'have.text',
'Contact [email protected] if you need to update the sections: ' +
'Summary of the support given, Destination country, Date won, Type of win and Value'
)
assertHistoricExportWinsMessage()
assertWinDetailsMessage()
})

it('should not render a hint', () => {
Expand Down Expand Up @@ -137,20 +158,17 @@ describe('Editing a pending export win', () => {
urls.companies.exportWins.editSupportProvided(company.id, exportWin.id)
)
cy.wait(['@apiGetExportWin'])
cy.get('[data-test="status-message"]').should('not.exist')
cy.get('[data-test="status-message"]')
assertHistoricExportWinsMessage()
})
})

context('Summary', () => {
it('should render an edit status message', () => {
cy.visit(urls.companies.exportWins.editSummary(company.id, exportWin.id))
cy.wait(['@apiGetExportWin'])
cy.get('[data-test="status-message"]').should(
'contain',
'To edit an export win' +
'Edit each section that needs changing then return to the summary page. ' +
'When you are happy with all the changes save the page.'
)
assertHistoricExportWinsMessage()
assertSummaryMessage()
})

it('should render a lead officer name contact link', () => {
Expand Down Expand Up @@ -249,7 +267,7 @@ describe('Editing a pending export win', () => {
cy.get('[data-test="resend-export-win"]').click()
cy.wait('@apiResendExportWin')
cy.get('[data-test="flash"]').should(
'have.text',
'contain.text',
`The export win ${exportWin.name_of_export} to ${exportWin.country.name} has been sent to ${exportWin.company_contacts[0].email} for review and confirmation.`
)
})
Expand Down

0 comments on commit 3de730a

Please sign in to comment.