Skip to content

Commit

Permalink
Add tests for investment activity (#7390)
Browse files Browse the repository at this point in the history
* Fix tag colour console error

* Fix unformatted/broken fields and add mising label

* Refactor verifyLabel to use numbers instead of arrays

* Write tests for investment project activity

* Expand the new constants file

* Remove legacy code

* Update functional specs
  • Loading branch information
cgsunkel authored Dec 12, 2024
1 parent 6d5a9a2 commit fe018c9
Show file tree
Hide file tree
Showing 16 changed files with 386 additions and 256 deletions.
122 changes: 0 additions & 122 deletions src/client/components/ActivityFeed/activities/InvestmentProject.jsx

This file was deleted.

2 changes: 0 additions & 2 deletions src/client/components/ActivityFeed/activities/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import CompaniesHouseCompany from './CompaniesHouseCompany'
import DirectoryFormsApi from './DirectoryFormsApi'
import MaxemailCampaign from './MaxemailCampaign'
import HmrcExporter from './HmrcExporter'
import InvestmentProject from './InvestmentProject'
import Omis from './Omis'
import AventriAttendee from './AventriAttendee'
import DataHubEvent from './DataHubEvent'
Expand All @@ -19,7 +18,6 @@ export default [
DirectoryFormsApi,
MaxemailCampaign,
HmrcExporter,
InvestmentProject,
Omis,
AventriEventSyncWarning,
]
6 changes: 6 additions & 0 deletions src/client/modules/Companies/CompanyActivity/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,9 @@ export const SORT_OPTIONS = [
{ value: 'date:desc', name: 'Recently created' },
{ value: 'date:asc', name: 'Oldest first' },
]

export const NEW_PROJECT_TAG = {
text: 'New Investment Project',
colour: 'grey',
dataTest: 'investment-kind-label',
}
55 changes: 32 additions & 23 deletions src/client/modules/Companies/CompanyActivity/transformers.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from 'react'
import Link from '@govuk-react/link'

import { TAGS } from './constants'
import { TAGS, NEW_PROJECT_TAG } from './constants'
import urls from '../../../../lib/urls'
import { formatDate, DATE_FORMAT_MEDIUM } from '../../../utils/date-utils'
import { truncateData } from '../utils'
import { AdviserResource } from '../../../components/Resource'
import { INTERACTION_NAMES } from '../../../../apps/interactions/constants'
import { getServiceText } from '../../../components/ActivityFeed/activities/InteractionUtils'
import { currencyGBP } from '../../../utils/number-utils'

const { isEmpty } = require('lodash')

Expand Down Expand Up @@ -51,8 +52,8 @@ export const formattedAdvisers = (advisers) =>
</span>
))

export const verifyLabel = (array, label) =>
array.length > 1 ? label + 's' : label
export const pluraliseLabel = (number, label) =>
number != 1 ? label + 's' : label

/*
From the activity_source field from the API, determine which transformer to
Expand Down Expand Up @@ -97,15 +98,15 @@ export const transformInteractionToListItem = (activity) => {
interaction.date && formatDate(interaction.date, DATE_FORMAT_MEDIUM),
},
{
label: verifyLabel(interaction.contacts, 'Contact'),
label: pluraliseLabel(interaction.contacts?.length, 'Contact'),
value: formattedContacts(interaction.contacts),
},
{
label: 'Communication channel',
value: interaction.communication_channel?.name,
},
{
label: verifyLabel(interaction.dit_participants, 'Adviser'),
label: pluraliseLabel(interaction.dit_participants?.length, 'Adviser'),
value: formattedAdvisers(interaction.dit_participants),
},
{ label: 'Service', value: interaction.service?.name },
Expand Down Expand Up @@ -173,16 +174,17 @@ export const transformReferralToListItem = (activity) => {
}

export const transformInvestmentToListItem = (activity) => {
const project = activity.investment
return {
id: activity.investment.id,
id: project.id,
metadata: [
{
label: 'Created Date',
label: 'Created on',
value: formatDate(activity.date, DATE_FORMAT_MEDIUM),
},
{
label: 'Investment Type',
value: activity.investment.investment_type.name,
label: 'Investment type',
value: project.investment_type.name,
},
{
label: 'Added by',
Expand All @@ -195,40 +197,47 @@ export const transformInvestmentToListItem = (activity) => {
},
{
label: 'Estimated land date',
value: activity.investment.estimated_land_date,
value: formatDate(project.estimated_land_date, DATE_FORMAT_MEDIUM),
},
{
label: 'Company Contact',
value: activity.investment.clinet_contacts,
label: pluraliseLabel(
project.client_contacts?.length,
'Company contact'
),
value:
project.client_contacts.length > 0
? project.client_contacts.map((contact) => contact.name).join(', ')
: '',
},
{
label: 'Total investment',
value: activity.investment.total_investment,
value: currencyGBP(project.total_investment),
},
{
label: 'Capital expenditure value',
value: activity.investment.foreign_equity_investment,
value: currencyGBP(project.foreign_equity_investment),
},
{
label: 'Gross value added (GVA)',
value: activity.investment.gross_value_added,
value: currencyGBP(project.gross_value_added),
},
{ label: 'Number of jobs', value: activity.investment.number_new_jobs },
{ label: 'Number of jobs', value: project.number_new_jobs },
].filter(({ value }) => Boolean(value)),
tags: [
{
text: 'Investment',
colour: 'default',
colour: 'govBlue',
dataTest: 'investment-theme-label',
},
{
text: 'New Investment Project',
colour: 'grey',
dataTest: 'investment-service-label',
text: `Project - ${project.investment_type.name}`,
colour: 'blue',
dataTest: 'investment-type-label',
},
NEW_PROJECT_TAG,
].filter(({ text }) => Boolean(text)),
headingUrl: urls.investments.projects.details(activity.investment.id),
headingText: activity.investment.name,
headingUrl: urls.investments.projects.details(project.id),
headingText: project.name,
}
}

Expand Down Expand Up @@ -263,7 +272,7 @@ export const transformOrderToListItem = (activity) => {
tags: [
{
text: 'Orders (OMIS)',
colour: 'default',
colour: 'govBlue',
dataTest: 'order-theme-label',
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { TAGS } from '../../../CompanyActivity/constants'
import { TAGS, NEW_PROJECT_TAG } from '../../../CompanyActivity/constants'
import { isDateInFuture } from '../../../../../utils/date'
import { formatDate, DATE_FORMAT_MEDIUM } from '../../../../../utils/date-utils'
import { truncateData } from '../../../../../utils/truncate'
import { INTERACTION_NAMES } from '../../../../../../apps/interactions/constants'
import urls from '../../../../../../lib/urls'
import { pluraliseLabel } from '../../../CompanyActivity/transformers'

const { isEmpty } = require('lodash')

Expand Down Expand Up @@ -42,6 +43,8 @@ const buildSummary = (advisers, communicationChannel, contacts, date) => {
return `${transformedAdvisers} ${isFuture} ${transformCommunicationChannel(communicationChannel)} contact with ${transformedContacts}`
}

const checkNewJobs = (jobs) => (jobs > 0 ? jobs : 'no')

/*
From the activity_source field from the API, determine which transformer to
use to get the required data for the cards.
Expand Down Expand Up @@ -129,25 +132,13 @@ export const transformInvestmentToListItem = (activity) => {
return {
id: investment.id,
date: formatDate(activity.date, DATE_FORMAT_MEDIUM),
tags: [
{
text: 'New Investment Project',
colour: 'grey',
dataTest: 'investment-service-label',
},
].filter(({ text }) => Boolean(text)),
tags: [NEW_PROJECT_TAG].filter(({ text }) => Boolean(text)),
headingUrl: urls.investments.projects.details(investment.id),
headingText: investment.name,
summary:
investment.number_new_jobs == null
? [
`${investment.investment_type.name} investment added by `,
investment.created_by.name,
]
: [
`${investment.investment_type.name} investment for ${investment.number_new_jobs} jobs added by `,
investment.created_by.name,
],
? `${investment.investment_type.name} investment added by ${investment.created_by.name}`
: `${investment.investment_type.name} investment for ${checkNewJobs(investment.number_new_jobs)} ${pluraliseLabel(investment.number_new_jobs, 'new job')} added by ${investment.created_by.name}`,
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/client/modules/Contacts/ContactActivity/transformers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import urls from '../../../../lib/urls'
import { formatDate, DATE_FORMAT_MEDIUM } from '../../../utils/date-utils'
import {
verifyLabel,
pluraliseLabel,
formattedAdvisers,
formattedContacts,
} from '../../Companies/CompanyActivity/transformers'
Expand All @@ -21,12 +21,12 @@ export const transformContactActivityToListItem = ({
metadata: [
{ label: 'Date', value: formatDate(date, DATE_FORMAT_MEDIUM) },
{
label: verifyLabel(contacts, 'Contact'),
label: pluraliseLabel(contacts.length, 'Contact'),
value: formattedContacts(contacts),
},
{ label: 'Communication channel', value: communication_channel?.name },
{
label: verifyLabel(dit_participants, 'Adviser'),
label: pluraliseLabel(dit_participants.length, 'Adviser'),
value: formattedAdvisers(dit_participants),
},
{ label: 'Service', value: service?.name },
Expand Down
Loading

0 comments on commit fe018c9

Please sign in to comment.