Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EYB human readable labels #7452

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/client/modules/Investments/EYBLeads/EYBLeadDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Link } from 'govuk-react'

import { formatDate, DATE_FORMAT_COMPACT } from '../../../utils/date-utils'
import urls from '../../../../lib/urls'
import { camelCaseToSentenceCase } from '../utils'
import { EYBLeadResource } from '../../../components/Resource'
import { EYBLeadLayout, NewWindowLink, SummaryTable } from '../../../components'
import { NOT_SET_TEXT } from '../../../../apps/companies/constants'
Expand Down Expand Up @@ -68,7 +69,7 @@ const EYBLeadDetails = () => {
</SummaryTable.Row>
<SummaryTable.Row
heading="When do you want to set up?"
children={eybLead.landingTimeframe}
children={camelCaseToSentenceCase(eybLead.landingTimeframe)}
/>
<SummaryTable.Row
heading="Do you know where you want to set up in the UK?"
Expand All @@ -80,11 +81,11 @@ const EYBLeadDetails = () => {
/>
<SummaryTable.Row
heading="How do you plan to expand your business in the UK?"
children={eybLead.intent}
children={camelCaseToSentenceCase(eybLead.intent)}
/>
<SummaryTable.Row
heading="How many people do you want to hire in the UK in the first 3 years?"
children={eybLead.hiring}
children={camelCaseToSentenceCase(eybLead.hiring)}
/>
<SummaryTable.Row
heading="How much do you want to spend on setting up in the first 3 years?"
Expand Down
22 changes: 22 additions & 0 deletions src/client/modules/Investments/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import urls from '../../../lib/urls'

const transformToSentenceCase = (text) => {
let result = text.replace(/_/g, ' ')
return (
result.charAt(0).toUpperCase() +
result.slice(1).toLowerCase().replace(/uk/g, 'UK')
)
}

export const buildProjectBreadcrumbs = (pageBreadcrumbs) => {
const initialBreadcrumbs = [
{ link: urls.dashboard.index(), text: 'Home' },
Expand Down Expand Up @@ -29,3 +37,17 @@ export const buildEYBLeadBreadcrumbs = (pageBreadcrumbs) => {
]
return initialBreadcrumbs.concat(pageBreadcrumbs)
}

export const camelCaseToSentenceCase = (text) => {
if (typeof text === 'string') {
return transformToSentenceCase(text)
} else if (Array.isArray(text)) {
return text.map((item) => {
if (typeof item === 'string') {
return transformToSentenceCase(item)
} else {
return item
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
assertLeadBreadcrumbs,
} from '../../support/assertions'
import { investments } from '../../../../../src/lib/urls'
import { camelCaseToSentenceCase } from '../../../../../src/client/modules/Investments/utils'
import { eybLeadFaker } from '../../fakers/eyb-leads'
import { NOT_SET_TEXT } from '../../../../../src/apps/companies/constants'
import { VALUES_VALUE_TO_LABEL_MAP } from '../../../../../src/client/modules/Investments/EYBLeads/constants'
Expand Down Expand Up @@ -53,6 +54,18 @@ describe('EYB lead details', () => {
cy.wait('@getEYBLeadDetails')
})

it('should return non-string, non-array items as it is', () => {
const input = [123, true, { key: 'value' }]
const output = camelCaseToSentenceCase(input)
expect(output).to.deep.equal([123, true, { key: 'value' }])
})

it('should transform a camelCase string to sentence case', () => {
expect(
camelCaseToSentenceCase('find people_with specialist skills_in uk')
).to.equal('Find people with specialist skills in UK')
})

it('should render all the fields of the details table', () => {
assertSummaryTable({
dataTest: 'eyb-lead-details-table',
Expand Down
Loading