Skip to content

Commit

Permalink
Added the CustomerFeedback page
Browse files Browse the repository at this point in the history
  • Loading branch information
peterhudec committed Mar 5, 2024
1 parent d9d4271 commit 5bc140b
Show file tree
Hide file tree
Showing 9 changed files with 364 additions and 32 deletions.
1 change: 1 addition & 0 deletions src/apps/routers.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const reactRoutes = [
'/exportwins/sent',
'/exportwins/rejected',
'/exportwins/:winId/details',
'/exportwins/:winId/customer-feedback',
'/companies/:companyId/dnb-hierarchy',
'/companies/:companyId/company-tree',
'/companies/:companyId/account-management/strategy/create',
Expand Down
2 changes: 1 addition & 1 deletion src/client/components/ProtectedLink/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { connect } from 'react-redux'
import PropTypes from 'prop-types'

const ProtectedLink = ({ module, modulePermissions, children = null }) =>
modulePermissions.includes(module) ? children : null
modulePermissions?.includes(module) ? children : null

ProtectedLink.propTypes = {
module: PropTypes.string.isRequired,
Expand Down
121 changes: 121 additions & 0 deletions src/client/modules/ExportWins/CustomerFeedback.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import React from 'react'
import { Link } from 'govuk-react'
import { Link as ReactRouterLink } from 'react-router-dom/cjs/react-router-dom'

import { DefaultLayout } from '../../components'
import urls from '../../../lib/urls'
import SummaryTable from '../../components/SummaryTable'
import ExportWin from '../../components/Resource/ExportWin'

import { ExportWinTitle, ExportWinsLink, VerticalSpacer } from './Details'

const toYesNo = (val) => {
if (val === undefined || val === null) return
return val ? 'Yes' : 'No'
}

const CustomerFeedback = ({
match: {
params: { winId },
},
}) => (
<DefaultLayout
heading="Customer feedback"
pageTitle={<ExportWinTitle id={winId} />}
breadcrumbs={[
{
link: urls.dashboard.index(),
text: 'Home',
},
{
link: urls.companies.exportWins.index(),
text: 'Export wins',
},
{
text: <ExportWinTitle id={winId} />,
link: urls.companies.exportWins.details(winId),
},
{ text: 'Customer feedback' },
]}
>
<ExportWin id={winId} progressBox={true}>
{(_, win) => {
const response = win?.customer_response || {}
return (
<>
<SummaryTable caption="1. To what extent did our support help in?">
<SummaryTable.Row heading="Securing the win overall?">
{response.our_support?.name}
</SummaryTable.Row>
<SummaryTable.Row heading="Gaining access to contacts?">
{response.access_to_contacts?.name}
</SummaryTable.Row>
<SummaryTable.Row heading="Getting information or improved understanding of this country?">
{response.access_to_information?.name}
</SummaryTable.Row>
<SummaryTable.Row heading="Improving your profile or credibility in the country?">
{response.improved_profile?.name}
</SummaryTable.Row>
<SummaryTable.Row heading="Having confidence to explore or expand in the country?">
{response.gained_confidence?.name}
</SummaryTable.Row>
<SummaryTable.Row heading="Developing or nurturing critical relationships?">
{response.developed_relationships?.name}
</SummaryTable.Row>
<SummaryTable.Row heading="Overcoming a problem in the country (eg legal, regulatory, commercial)">
{response.overcame_problem?.name}
</SummaryTable.Row>
</SummaryTable>
<SummaryTable caption="2. About this win">
<SummaryTable.Row heading="The win involved a foreign government or state-owned enterprise (eg as an intermediary or facilitator)">
{toYesNo(response.involved_state_enterprise)}
</SummaryTable.Row>
<SummaryTable.Row heading="Our support was a prerequisite to generate this value">
{toYesNo(response.interventions_were_prerequisite)}
</SummaryTable.Row>
<SummaryTable.Row heading="Our support helped you achieve this win more quickly">
{toYesNo(response.support_improved_speed)}
</SummaryTable.Row>
<SummaryTable.Row heading="It enabled you to expand into a new market">
{toYesNo(response.has_enabled_expansion_into_new_market)}
</SummaryTable.Row>
<SummaryTable.Row heading="It enabled you to maintain or expand in an existing market">
{toYesNo(response.has_enabled_expansion_into_existing_market)}
</SummaryTable.Row>
<SummaryTable.Row heading="It enabled you to increase exports as a proportion of your turnover">
{toYesNo(response.has_increased_exports_as_percent_of_turnover)}
</SummaryTable.Row>
<SummaryTable.Row heading="If you hadn't achieved this win, your company might have stopped exporting">
{toYesNo(response.company_was_at_risk_of_not_exporting)}
</SummaryTable.Row>
<SummaryTable.Row heading="Apart from this win, you already have plans to export in the next 12 months">
{toYesNo(response.has_explicit_export_plans)}
</SummaryTable.Row>
</SummaryTable>
<SummaryTable caption="3. Your export experience">
<SummaryTable.Row heading="Apart from this win, when did your company last export goods or services?">
{response.last_export?.name}
</SummaryTable.Row>
</SummaryTable>
<SummaryTable caption="4. Marketing">
<SummaryTable.Row heading="Would you be willing for DBT/Exporting is GREAT to feature your success in marketing materials?">
{response.case_study_willing?.name}
</SummaryTable.Row>
<SummaryTable.Row heading="How did you first hear about DBT(or it predecessor, DIT)?">
{response.marketing_source?.name}
</SummaryTable.Row>
</SummaryTable>
</>
)
}}
</ExportWin>
<VerticalSpacer>
<ExportWinsLink />
<Link as={ReactRouterLink} to={urls.companies.exportWins.details(winId)}>
Back
</Link>
</VerticalSpacer>
</DefaultLayout>
)

export default CustomerFeedback
26 changes: 15 additions & 11 deletions src/client/modules/ExportWins/Details/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { ResendExportWin } from './ResendExportWin'
import urls from '../../../../lib/urls'
import { state2props } from './state'

const VerticalSpacer = styled.div`
export const VerticalSpacer = styled.div`
display: flex;
flex-direction: column;
gap: ${SPACING.SCALE_1};
Expand All @@ -27,7 +27,7 @@ const NormalFontWeightRow = styled(SummaryTable.Row)`
}
`

const ExportWinTitle = (props) => (
export const ExportWinTitle = (props) => (
<ExportWin.Inline {...props}>
{(exportWin) => (
<>
Expand All @@ -37,6 +37,16 @@ const ExportWinTitle = (props) => (
</ExportWin.Inline>
)

export const ExportWinsLink = () => (
<Link
data-test="export-wins-link"
as={ReactRouterLink}
to={urls.companies.exportWins.index()}
>
Export wins
</Link>
)

const groupBreakdowns = (breakdowns) => {
const result =
breakdowns.reduce(
Expand Down Expand Up @@ -144,26 +154,20 @@ const Detail = (props) => {
</SummaryTable.Row>
<SummaryTable.Row heading="Export win confirmed">
{exportWin &&
(exportWin.isPersonallyConfirmed ? 'Yes' : 'No')}
(exportWin.customerResponse.agreeWithWin ? 'Yes' : 'No')}
</SummaryTable.Row>
</Summary>
{exportWin && <ResendExportWin id={exportWin.id} />}
<VerticalSpacer>
{exportWin?.isPersonallyConfirmed && (
{exportWin?.customerResponse.agreeWithWin && (
<Link
as={ReactRouterLink}
to={urls.companies.exportWins.customerFeedback(winId)}
>
View customer feedback
</Link>
)}
<Link
data-test="export-wins-link"
as={ReactRouterLink}
to={urls.companies.exportWins.index()}
>
Export wins
</Link>
<ExportWinsLink />
</VerticalSpacer>
</>
)
Expand Down
6 changes: 6 additions & 0 deletions src/client/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ import OrderQuote from './modules/Omis/OrderQuote'
import OrdersReconciliationCollection from './modules/Omis/CollectionList/OrdersReconciliationCollection'
import CompanyEditHistory from './modules/Companies/CompanyBusinessDetails/CompanyEditHistory/CompanyEditHistory'
import AddProjectDocument from './modules/Investments/Projects/Evidence/AddProjectDocument'
import CustomerFeedback from './modules/ExportWins/CustomerFeedback'

const routes = {
companies: [
Expand Down Expand Up @@ -506,6 +507,11 @@ const routes = {
module: 'datahub:companies',
component: EditExportWin,
},
{
path: '/exportwins/:winId/customer-feedback',
module: 'datahub:companies',
component: CustomerFeedback,
},
],
investments: [
{
Expand Down
134 changes: 134 additions & 0 deletions test/component/cypress/specs/ExportWins/CustomerFeedback.cy.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/* eslint-disable prettier/prettier */
import React from 'react'

import {
assertSummaryTableStrict,
assertBreadcrumbs,
} from '../../../../functional/cypress/support/assertions'
import CustomerFeedback from '../../../../../src/client/modules/ExportWins/CustomerFeedback'
import { createTestProvider } from '../provider'

const toYesNo = x =>
x ? 'Yes' : 'No'

const dummyExportWin = (prefix, booleans) => ({
id: `${prefix}-id`,
name_of_export: `${prefix}-name_of_export`,
country: {
name: `${prefix}-country`,
},
customer_response: {
our_support: { name: `${prefix}-our_support` },
access_to_contacts: { name: `${prefix}-access_to_contacts` },
access_to_information: { name: `${prefix}-access_to_information` },
improved_profile: { name: `${prefix}-improved_profile` },
gained_confidence: { name: `${prefix}-gained_confidence` },
developed_relationships: { name: `${prefix}-developed_relationships` },
overcame_problem: { name: `${prefix}-overcame_problem` },

involved_state_enterprise: booleans,
interventions_were_prerequisite: booleans,
support_improved_speed: booleans,
has_enabled_expansion_into_new_market: booleans,
has_enabled_expansion_into_existing_market: booleans,
has_increased_exports_as_percent_of_turnover: booleans,
company_was_at_risk_of_not_exporting: booleans,
has_explicit_export_plans: booleans,

last_export: { name: `${prefix}-last_export` },
case_study_willing: { name: `${prefix}-case_study_willing` },
marketing_source: { name: `${prefix}-marketing_source` },
},
})

describe('ExportWins/CustomerFeedback', () => {
;[
{testTitle: 'All true', win: dummyExportWin('all-true', true)},
{testTitle: 'All false', win: dummyExportWin('all-false', false)},
].forEach(({testTitle, win}) => {
it(testTitle, () => {
const Provider = createTestProvider({
'Export Win': () => Promise.resolve(win),
TASK_GET_REMINDER_SUMMARY: () => Promise.resolve(),
})
cy.mount(
<Provider>
<CustomerFeedback match={{ params: { winId: win.id } }} />
</Provider>
)

assertBreadcrumbs({
Home: '/',
'Export wins': '/exportwins',
[`${win.name_of_export} to ${win.country.name}`]: `/exportwins/${win.id}/details`,
'Customer feedback': null,
})

cy.contains('h1', /^\s*Customer feedback\s*$/)

assertSummaryTableStrict({
caption: '1. To what extent did our support help in?',
rows: [
['Securing the win overall?', win.customer_response.our_support.name],
['Gaining access to contacts?', win.customer_response.access_to_contacts.name],
['Getting information or improved understanding of this country?', win.customer_response.access_to_information.name],
['Improving your profile or credibility in the country?', win.customer_response.improved_profile.name],
['Having confidence to explore or expand in the country?', win.customer_response.gained_confidence.name],
['Developing or nurturing critical relationships?', win.customer_response.developed_relationships.name],
['Overcoming a problem in the country (eg legal, regulatory, commercial)', win.customer_response.overcame_problem.name],
],
})

assertSummaryTableStrict({
caption: '2. About this win',
rows: [
['The win involved a foreign government or state-owned enterprise (eg as an intermediary or facilitator)', toYesNo(win.customer_response.involved_state_enterprise)],
['Our support was a prerequisite to generate this value', toYesNo(win.customer_response.interventions_were_prerequisite)],
['Our support helped you achieve this win more quickly', toYesNo(win.customer_response.support_improved_speed)],
['It enabled you to expand into a new market', toYesNo(win.customer_response.has_enabled_expansion_into_new_market)],
['It enabled you to maintain or expand in an existing market', toYesNo(win.customer_response.has_enabled_expansion_into_existing_market)],
['It enabled you to increase exports as a proportion of your turnover', toYesNo(win.customer_response.has_increased_exports_as_percent_of_turnover)],
["If you hadn't achieved this win, your company might have stopped exporting", toYesNo(win.customer_response.company_was_at_risk_of_not_exporting)],
['Apart from this win, you already have plans to export in the next 12 months', toYesNo(win.customer_response.has_explicit_export_plans)],
],
})

assertSummaryTableStrict({
caption: '3. Your export experience',
rows: [
['Apart from this win, when did your company last export goods or services?', win.customer_response.last_export.name],
],
})

assertSummaryTableStrict({
caption: '4. Marketing',
rows: [
['Would you be willing for DBT/Exporting is GREAT to feature your success in marketing materials?', win.customer_response.case_study_willing.name],
['How did you first hear about DBT(or it predecessor, DIT)?', win.customer_response.marketing_source.name],
],
})

// Assert captions appear in a particular order
;[
'1. To what extent did our support help in?',
'2. About this win',
'3. Your export experience',
'4. Marketing',
].forEach((heading, i) => {
cy.get('caption').eq(i).should('have.text', heading)
})

// This little trick ensures that we are not accidentally
// making assertions about the "Export wins" link in breadcrumbs
cy.contains('Export winsBack')
.within(() => {
cy.contains('a', 'Export wins')
.should('have.attr', 'href', '/exportwins')

cy.contains('a', 'Back')
.should('have.attr', 'href', `/exportwins/${win.id}/details`)
})
})

})
})
8 changes: 6 additions & 2 deletions test/component/cypress/specs/ExportWins/Details.cy.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ const EXPORT_WIN = {
name: 'Services',
},
is_personally_confirmed: false,
customer_response: {
agree_with_win: false,
},
breakdowns: [
{
type: {
Expand Down Expand Up @@ -74,7 +77,9 @@ describe('ExportWins/Details', () => {
testTitle: 'Confirmed',
exportWinAPIResponse: {
...EXPORT_WIN,
is_personally_confirmed: true,
customer_response: {
agree_with_win: true,
},
},
tableRows: {
...EXPECTED_ROWS,
Expand All @@ -86,7 +91,6 @@ describe('ExportWins/Details', () => {
testTitle: 'Unconfirmed',
exportWinAPIResponse: {
...EXPORT_WIN,
is_personally_confirmed: false,
},
tableRows: {
...EXPECTED_ROWS,
Expand Down
Loading

0 comments on commit 5bc140b

Please sign in to comment.