diff --git a/src/client/components/ActivityFeed/activities/InvestmentProject.jsx b/src/client/components/ActivityFeed/activities/InvestmentProject.jsx deleted file mode 100644 index 15b4132c93e..00000000000 --- a/src/client/components/ActivityFeed/activities/InvestmentProject.jsx +++ /dev/null @@ -1,122 +0,0 @@ -import React from 'react' -import { get } from 'lodash' -import PropTypes from 'prop-types' -import Link from '@govuk-react/link' - -import { AdviserItemRenderer, ContactItemRenderer } from './card/item-renderers' -import { ACTIVITY_TYPE } from '../constants' - -import CardUtils from './card/CardUtils' -import { currencyGBP, decimal } from '../../../utils/number-utils' -import ActivityCardWrapper from './card/ActivityCardWrapper' -import ActivityCardLabels from './card/ActivityCardLabels' -import ActivityCardSubject from './card/ActivityCardSubject' -import ActivityCardMetadata from './card/ActivityCardMetadata' -import ActivityOverviewSummary from './card/item-renderers/ActivityOverviewSummary' -import OverviewActivityCardWrapper from './card/OverviewActivityCardWrapper' - -const { format } = require('../../../utils/date') - -export default class InvestmentProject extends React.PureComponent { - static propTypes = { - activity: PropTypes.object.isRequired, - showDetails: PropTypes.bool.isRequired, - } - - static canRender(activity) { - return CardUtils.canRenderByTypes(activity, ACTIVITY_TYPE.InvestmentProject) - } - - render() { - const kind = 'New Investment Project' - const { activity, isOverview } = this.props - const url = get(activity, 'object.url') - const name = get(activity, 'object.name') - const investmentType = get(activity, 'object.dit:investmentType.name') - const adviser = CardUtils.getAdviser(activity) - const estimatedLandDate = format( - get(activity, 'object.dit:estimatedLandDate') - ) - const contacts = CardUtils.getContacts(activity) - - // Specific to Foreign direct investment (FDI) only - const totalInvestment = currencyGBP( - get(activity, 'object.dit:totalInvestment') - ) - const foreignEquityInvestment = currencyGBP( - get(activity, 'object.dit:foreignEquityInvestment') - ) - const grossValueAdded = currencyGBP( - get(activity, 'object.dit:grossValueAdded') - ) - const numberNewJobs = decimal(get(activity, 'object.dit:numberNewJobs')) - - const published = get(activity, 'published') - - const addedBy = [adviser].map((adviser) => <>{adviser?.name}) - - const metadata = [ - { label: 'Date', value: format(published) }, - { label: 'Investment Type', value: investmentType }, - { - label: 'Added by', - value: [adviser].map((adviser, index) => - adviser ? ( - {AdviserItemRenderer(adviser, index)} - ) : ( - <> - ) - ), - }, - { - label: 'Estimated land date', - value: estimatedLandDate, - }, - { - label: 'Company contact', - value: contacts.map((contact, index) => ( - {ContactItemRenderer(contact, index)} - )), - }, - { label: 'Total investment', value: totalInvestment }, - { - label: 'Capital expenditure value', - value: foreignEquityInvestment, - }, - { - label: 'Gross value added (GVA)', - value: grossValueAdded, - }, - { label: 'Number of jobs', value: numberNewJobs }, - ] - const subject = {name} - const summary = [ - `${investmentType} investment for ${numberNewJobs} jobs added by `, - addedBy, - ] - return isOverview ? ( - - - - ) : ( - - - {subject} - - - - - ) - } -} diff --git a/src/client/components/ActivityFeed/activities/index.js b/src/client/components/ActivityFeed/activities/index.js index 70d7ffb4b26..4aa18b48c6c 100644 --- a/src/client/components/ActivityFeed/activities/index.js +++ b/src/client/components/ActivityFeed/activities/index.js @@ -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' @@ -19,7 +18,6 @@ export default [ DirectoryFormsApi, MaxemailCampaign, HmrcExporter, - InvestmentProject, Omis, AventriEventSyncWarning, ] diff --git a/src/client/modules/Companies/CompanyActivity/constants.js b/src/client/modules/Companies/CompanyActivity/constants.js index bffa814ad30..92dd731469e 100644 --- a/src/client/modules/Companies/CompanyActivity/constants.js +++ b/src/client/modules/Companies/CompanyActivity/constants.js @@ -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', +} diff --git a/src/client/modules/Companies/CompanyActivity/transformers.js b/src/client/modules/Companies/CompanyActivity/transformers.js index 5e4906599ce..3247f1c6660 100644 --- a/src/client/modules/Companies/CompanyActivity/transformers.js +++ b/src/client/modules/Companies/CompanyActivity/transformers.js @@ -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') @@ -51,8 +52,8 @@ export const formattedAdvisers = (advisers) => )) -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 @@ -97,7 +98,7 @@ 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), }, { @@ -105,7 +106,7 @@ export const transformInteractionToListItem = (activity) => { 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 }, @@ -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', @@ -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, } } @@ -263,7 +272,7 @@ export const transformOrderToListItem = (activity) => { tags: [ { text: 'Orders (OMIS)', - colour: 'default', + colour: 'govBlue', dataTest: 'order-theme-label', }, { diff --git a/src/client/modules/Companies/CompanyOverview/TableCards/ActivityCards/transformers.js b/src/client/modules/Companies/CompanyOverview/TableCards/ActivityCards/transformers.js index b6ed35ded2d..532c8b6a2c5 100644 --- a/src/client/modules/Companies/CompanyOverview/TableCards/ActivityCards/transformers.js +++ b/src/client/modules/Companies/CompanyOverview/TableCards/ActivityCards/transformers.js @@ -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') @@ -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. @@ -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}`, } } diff --git a/src/client/modules/Contacts/ContactActivity/transformers.js b/src/client/modules/Contacts/ContactActivity/transformers.js index 3e4b552e9cc..4999731b917 100644 --- a/src/client/modules/Contacts/ContactActivity/transformers.js +++ b/src/client/modules/Contacts/ContactActivity/transformers.js @@ -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' @@ -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 }, diff --git a/test/component/cypress/specs/Companies/CompanyActivity/InteractionActivity.cy.jsx b/test/component/cypress/specs/Companies/CompanyActivity/InteractionActivity.cy.jsx index 0186eff1249..c5dbce7b723 100644 --- a/test/component/cypress/specs/Companies/CompanyActivity/InteractionActivity.cy.jsx +++ b/test/component/cypress/specs/Companies/CompanyActivity/InteractionActivity.cy.jsx @@ -13,6 +13,13 @@ import { assertText, } from '../../../support/activity-assertions' import { checkName } from '../../../support/activity-utils' +import { + ADVISER_1, + ADVISER_2, + CONTACT_1, + CONTACT_2, + CREATED_ON as DATE, +} from '../../../support/activity-constants' const SUBJECT = 'An interaction with a company' const TYPE = 'interaction' @@ -24,37 +31,6 @@ const TWO_ADVISERS_TEXT = 'Advisers Bernard Harris-Patel bernardharrispatel@test.com, Test Team 1 Puck Head puckhead@test.com, Test Team 2 ' const ONE_CONTACT_TEXT = 'Contact Alexander Hamilton' const TWO_CONTACTS_TEXT = 'Contacts Alexander Hamilton, Oliver Twist' -const DATE = '2058-11-25T00:00:00Z' - -const ADVISER_1 = { - adviser: { - email: 'bernardharrispatel@test.com', - name: 'Bernard Harris-Patel', - }, - team: { - name: 'Test Team 1', - }, -} - -const ADVISER_2 = { - adviser: { - email: 'puckhead@test.com', - name: 'Puck Head', - }, - team: { - name: 'Test Team 2', - }, -} - -const CONTACT_1 = { - id: '115b4d96-d2ea-40ff-a01d-812507093a98', - name: 'Alexander Hamilton', -} - -const CONTACT_2 = { - id: '56cd5cd0-bb6f-440c-adae-0253f6d48d3b', - name: 'Oliver Twist', -} const INTERACTION_SERVICES = { specificDITService: diff --git a/test/component/cypress/specs/Companies/CompanyActivity/InvestmentActivity.cy.jsx b/test/component/cypress/specs/Companies/CompanyActivity/InvestmentActivity.cy.jsx new file mode 100644 index 00000000000..81d36a17400 --- /dev/null +++ b/test/component/cypress/specs/Companies/CompanyActivity/InvestmentActivity.cy.jsx @@ -0,0 +1,169 @@ +import React from 'react' + +import urls from '../../../../../../src/lib/urls' + +import { ItemTemplate } from '../../../../../../src/client/modules/Companies/CompanyActivity' +import { transformInvestmentToListItem } from '../../../../../../src/client/modules/Companies/CompanyActivity/transformers' +import { CollectionList } from '../../../../../../src/client/components' +import { + assertActivitySubject, + assertMetadataItems, + assertProjectKindLabel, + assertText, +} from '../../../support/activity-assertions' +import { + CONTACT_1, + CONTACT_2, + CREATED_BY, + CREATED_ON, +} from '../../../support/activity-constants' + +const NAME = 'An investment project' +const PROJECT_URL = urls.investments.projects.details('2') +const EL_DATE = '2023-12-01' + +const buildAndMountActivity = ( + showOptionalFields, + clientContacts = [], + type = 'FDI' +) => { + const activity = { + date: CREATED_ON, + investment: { + id: '2', + created_by: CREATED_BY, + name: NAME, + client_contacts: clientContacts, + estimated_land_date: EL_DATE, + foreign_equity_investment: showOptionalFields ? 123456789 : '', + gross_value_added: showOptionalFields ? 12345 : '', + investment_type: { + name: type, + }, + number_new_jobs: showOptionalFields ? 1 : '', + total_investment: showOptionalFields ? 1234567890 : '', + }, + } + + cy.mountWithProvider( + + ) +} + +describe('Investment project activity card', () => { + context('When the card is rendered with a complete FDI project', () => { + beforeEach(() => { + buildAndMountActivity(true, [CONTACT_1]) + cy.get('[data-test=collection-item]').should('exist') + }) + + it('should render the labels and metadata', () => { + assertInvestmentLabels() + assertActivitySubject(NAME, PROJECT_URL) + assertMetadataItems([ + 'Created on 25 Nov 2058', + 'Investment type FDI', + 'Added by Bernard Harris-Patel bernardharrispatel@test.com, Test Team 1 ', + 'Estimated land date 1 Dec 2023', + 'Company contact Alexander Hamilton', + 'Total investment £1,234,567,890', + 'Capital expenditure value £123,456,789', + 'Gross value added (GVA) £12,345', + 'Number of jobs 1', + ]) + }) + }) + context( + 'When the card is rendered with a complete project with multiple client contacts', + () => { + beforeEach(() => { + buildAndMountActivity(true, [CONTACT_1, CONTACT_2]) + cy.get('[data-test=collection-item]').should('exist') + }) + + it('should render the labels and metadata', () => { + assertInvestmentLabels() + assertActivitySubject(NAME, PROJECT_URL) + assertMetadataItems([ + 'Created on 25 Nov 2058', + 'Investment type FDI', + 'Added by Bernard Harris-Patel bernardharrispatel@test.com, Test Team 1 ', + 'Estimated land date 1 Dec 2023', + 'Company contacts Alexander Hamilton, Oliver Twist', + 'Total investment £1,234,567,890', + 'Capital expenditure value £123,456,789', + 'Gross value added (GVA) £12,345', + 'Number of jobs 1', + ]) + }) + } + ) + context('When the card is rendered with an incomplete project', () => { + beforeEach(() => { + buildAndMountActivity(false) + cy.get('[data-test=collection-item]').should('exist') + }) + + it('should only render the mandatory fields', () => { + assertInvestmentLabels() + assertActivitySubject(NAME, PROJECT_URL) + assertMetadataItems([ + 'Created on 25 Nov 2058', + 'Investment type FDI', + 'Added by Bernard Harris-Patel bernardharrispatel@test.com, Test Team 1 ', + 'Estimated land date 1 Dec 2023', + ]) + }) + }) + + context('When the card is rendered with a Non-FDI project', () => { + beforeEach(() => { + buildAndMountActivity(false, [], 'Non-FDI') + cy.get('[data-test=collection-item]').should('exist') + }) + + it('should only render the mandatory fields', () => { + assertInvestmentLabels('Non-FDI') + assertActivitySubject(NAME, PROJECT_URL) + assertMetadataItems([ + 'Created on 25 Nov 2058', + 'Investment type Non-FDI', + 'Added by Bernard Harris-Patel bernardharrispatel@test.com, Test Team 1 ', + 'Estimated land date 1 Dec 2023', + ]) + }) + }) + + context( + 'When the card is rendered with a Commitment to Invest project', + () => { + beforeEach(() => { + buildAndMountActivity(false, [], 'Commitment to invest') + cy.get('[data-test=collection-item]').should('exist') + }) + + it('should only render the mandatory fields', () => { + assertInvestmentLabels('Commitment to invest') + assertActivitySubject(NAME, PROJECT_URL) + assertMetadataItems([ + 'Created on 25 Nov 2058', + 'Investment type Commitment to invest', + 'Added by Bernard Harris-Patel bernardharrispatel@test.com, Test Team 1 ', + 'Estimated land date 1 Dec 2023', + ]) + }) + } + ) +}) + +const assertInvestmentLabels = (investmentType = 'FDI') => { + assertText('[data-test="investment-theme-label"]', 'Investment') + assertText( + '[data-test="investment-type-label"]', + `Project - ${investmentType}` + ) + assertProjectKindLabel() +} diff --git a/test/component/cypress/specs/Companies/CompanyActivity/ReferralActivity.cy.jsx b/test/component/cypress/specs/Companies/CompanyActivity/ReferralActivity.cy.jsx index 8a14e150f32..72d1c9b4762 100644 --- a/test/component/cypress/specs/Companies/CompanyActivity/ReferralActivity.cy.jsx +++ b/test/component/cypress/specs/Companies/CompanyActivity/ReferralActivity.cy.jsx @@ -10,28 +10,16 @@ import { assertMetadataItems, assertReferralLabel, } from '../../../support/activity-assertions' +import { + CREATED_BY, + CREATED_ON, + RECIPIENT, +} from '../../../support/activity-constants' const SUBJECT = 'A referral' const REFERRAL_URL = urls.companies.referrals.details('1', '2') -const CREATED_ON = '2058-11-25T00:00:00Z' const COMPLETED_ON = '2058-12-25T11:03:21.597375+00:00' -const CREATED_BY = { - email: 'bernardharrispatel@test.com', - name: 'Bernard Harris-Patel', - dit_team: { - name: 'Test Team 1', - }, -} - -const RECIPIENT = { - email: 'puckhead@test.com', - name: 'Puck Head', - dit_team: { - name: 'Test Team 2', - }, -} - const buildAndMountActivity = (status, showCompletedDate = true) => { const activity = { company: { diff --git a/test/component/cypress/specs/Companies/CompanyOverview/ActivityCard/InteractionActivityCard.cy.jsx b/test/component/cypress/specs/Companies/CompanyOverview/ActivityCard/InteractionActivityCard.cy.jsx index a10bf0ad683..297ca7275bb 100644 --- a/test/component/cypress/specs/Companies/CompanyOverview/ActivityCard/InteractionActivityCard.cy.jsx +++ b/test/component/cypress/specs/Companies/CompanyOverview/ActivityCard/InteractionActivityCard.cy.jsx @@ -10,32 +10,18 @@ import { assertActivitySubject, } from '../../../../support/activity-assertions' import { checkName } from '../../../../support/activity-utils' +import { + ADVISER_1, + ADVISER_2, + CONTACT_1, + CONTACT_2, + CREATED_ON as DATE, +} from '../../../../support/activity-constants' const SUBJECT = 'An interaction with a company' const TYPE = 'interaction' const SERVICE_DELIVERY = 'service_delivery' const INTERACTION_URL = urls.companies.interactions.detail('1', '2') -const DATE = '2058-11-25T00:00:00Z' - -const ADVISER_1 = { - adviser: { - name: 'Bernard Harris-Patel', - }, -} - -const ADVISER_2 = { - adviser: { - name: 'Puck Head', - }, -} - -const CONTACT_1 = { - name: 'Alexander Hamilton', -} - -const CONTACT_2 = { - name: 'Oliver Twist', -} const buildAndMountActivity = ( communicationChannel, diff --git a/test/component/cypress/specs/Companies/CompanyOverview/ActivityCard/InvestmentActivityCard.cy.jsx b/test/component/cypress/specs/Companies/CompanyOverview/ActivityCard/InvestmentActivityCard.cy.jsx new file mode 100644 index 00000000000..1f66e8bfbed --- /dev/null +++ b/test/component/cypress/specs/Companies/CompanyOverview/ActivityCard/InvestmentActivityCard.cy.jsx @@ -0,0 +1,90 @@ +import React from 'react' + +import urls from '../../../../../../../src/lib/urls' + +import { transformInvestmentToListItem } from '../../../../../../../src/client/modules/Companies/CompanyOverview/TableCards/ActivityCards/transformers' +import { ItemTemplate } from '../../../../../../../src/client/modules/Companies/CompanyOverview/TableCards/ActivityCards/ActivityCard' +import { CollectionList } from '../../../../../../../src/client/components' +import { + assertActivitySubject, + assertProjectKindLabel, +} from '../../../../support/activity-assertions' +import { CREATED_BY, CREATED_ON } from '../../../../support/activity-constants' + +const NAME = 'An investment project' +const PROJECT_URL = urls.investments.projects.details('2') + +const buildAndMountActivity = (newJobs) => { + const activity = { + date: CREATED_ON, + investment: { + id: '2', + created_by: CREATED_BY, + name: NAME, + investment_type: { + name: 'FDI', + }, + number_new_jobs: newJobs, + }, + } + + cy.mountWithProvider( + + ) +} + +describe('Investment activity card', () => { + context('When the card is rendered with a complete project', () => { + beforeEach(() => { + buildAndMountActivity(2) + cy.get('[data-test="activity-card-wrapper"]').should('exist') + }) + + it('should render the labels and metadata', () => { + assertProjectKindLabel() + assertActivitySubject(NAME, PROJECT_URL, 'activity-card-wrapper') + cy.get('[data-test="activity-date"]').should('have.text', '25 Nov 2058') + cy.get('[data-test="activity-summary"]').should( + 'have.text', + `FDI investment for 2 new jobs added by ${CREATED_BY.name}` + ) + }) + }) + + context('When the project has one new job', () => { + beforeEach(() => { + buildAndMountActivity(1) + cy.get('[data-test="activity-card-wrapper"]').should('exist') + }) + + it('should render the labels and metadata', () => { + assertProjectKindLabel() + assertActivitySubject(NAME, PROJECT_URL, 'activity-card-wrapper') + cy.get('[data-test="activity-date"]').should('have.text', '25 Nov 2058') + cy.get('[data-test="activity-summary"]').should( + 'have.text', + `FDI investment for 1 new job added by ${CREATED_BY.name}` + ) + }) + }) + + context('When the project has no new jobs', () => { + beforeEach(() => { + buildAndMountActivity(0) + cy.get('[data-test="activity-card-wrapper"]').should('exist') + }) + + it('should render the labels and metadata', () => { + assertProjectKindLabel() + assertActivitySubject(NAME, PROJECT_URL, 'activity-card-wrapper') + cy.get('[data-test="activity-date"]').should('have.text', '25 Nov 2058') + cy.get('[data-test="activity-summary"]').should( + 'have.text', + `FDI investment for no new jobs added by ${CREATED_BY.name}` + ) + }) + }) +}) diff --git a/test/component/cypress/specs/Companies/CompanyOverview/ActivityCard/ReferralActivityCard.cy.jsx b/test/component/cypress/specs/Companies/CompanyOverview/ActivityCard/ReferralActivityCard.cy.jsx index 2191ca19139..770b027c29f 100644 --- a/test/component/cypress/specs/Companies/CompanyOverview/ActivityCard/ReferralActivityCard.cy.jsx +++ b/test/component/cypress/specs/Companies/CompanyOverview/ActivityCard/ReferralActivityCard.cy.jsx @@ -9,28 +9,16 @@ import { assertReferralLabel, assertActivitySubject, } from '../../../../support/activity-assertions' +import { + CREATED_BY, + CREATED_ON, + RECIPIENT, +} from '../../../../support/activity-constants' const SUBJECT = 'A referral' const REFERRAL_URL = urls.companies.referrals.details('1', '2') -const CREATED_ON = '2058-11-25T00:00:00Z' const COMPLETED_ON = '2058-12-25T11:03:21.597375+00:00' -const CREATED_BY = { - email: 'bernardharrispatel@test.com', - name: 'Bernard Harris-Patel', - dit_team: { - name: 'Test Team 1', - }, -} - -const RECIPIENT = { - email: 'puckhead@test.com', - name: 'Puck Head', - dit_team: { - name: 'Test Team 2', - }, -} - const buildAndMountActivity = (status, showCompletedDate = true) => { const activity = { company: { diff --git a/test/component/cypress/support/activity-assertions.js b/test/component/cypress/support/activity-assertions.js index a2e13a171c2..fb2e3712c6d 100644 --- a/test/component/cypress/support/activity-assertions.js +++ b/test/component/cypress/support/activity-assertions.js @@ -39,3 +39,7 @@ export const assertKindLabel = (expectedText = 'Interaction') => { export const assertReferralLabel = (expectedText = 'Completed referral') => { assertText('[data-test="referral-label"]', expectedText) } + +export const assertProjectKindLabel = () => { + assertText('[data-test="investment-kind-label"]', 'New Investment Project') +} diff --git a/test/component/cypress/support/activity-constants.js b/test/component/cypress/support/activity-constants.js new file mode 100644 index 00000000000..b8aa524d724 --- /dev/null +++ b/test/component/cypress/support/activity-constants.js @@ -0,0 +1,47 @@ +export const CREATED_ON = '2058-11-25T00:00:00Z' + +export const CONTACT_1 = { + id: '115b4d96-d2ea-40ff-a01d-812507093a98', + name: 'Alexander Hamilton', +} + +export const CONTACT_2 = { + id: '56cd5cd0-bb6f-440c-adae-0253f6d48d3b', + name: 'Oliver Twist', +} + +export const CREATED_BY = { + email: 'bernardharrispatel@test.com', + name: 'Bernard Harris-Patel', + dit_team: { + name: 'Test Team 1', + }, +} + +export const RECIPIENT = { + email: 'puckhead@test.com', + name: 'Puck Head', + dit_team: { + name: 'Test Team 2', + }, +} + +export const ADVISER_1 = { + adviser: { + email: 'bernardharrispatel@test.com', + name: 'Bernard Harris-Patel', + }, + team: { + name: 'Test Team 1', + }, +} + +export const ADVISER_2 = { + adviser: { + email: 'puckhead@test.com', + name: 'Puck Head', + }, + team: { + name: 'Test Team 2', + }, +} diff --git a/test/functional/cypress/specs/companies/activity-feed-spec.js b/test/functional/cypress/specs/companies/activity-feed-spec.js index 6d37f23bb99..f9ce0cd7299 100644 --- a/test/functional/cypress/specs/companies/activity-feed-spec.js +++ b/test/functional/cypress/specs/companies/activity-feed-spec.js @@ -174,7 +174,7 @@ describe('Company activity feed', () => { }) it('displays the correct activity type label', () => { - cy.get('[data-test="investment-service-label"]').contains( + cy.get('[data-test="investment-kind-label"]').contains( 'New Investment Project', { matchCase: false, diff --git a/test/functional/cypress/specs/companies/overview-spec.js b/test/functional/cypress/specs/companies/overview-spec.js index 7fa921ee6a3..75572eba190 100644 --- a/test/functional/cypress/specs/companies/overview-spec.js +++ b/test/functional/cypress/specs/companies/overview-spec.js @@ -518,11 +518,11 @@ describe('Company overview page', () => { urls.companies.overview.index(fixtures.company.venusLtd.id) ) const activity = investmentsList[0] - cy.get('[data-test="investment-service-label"]').contains( + cy.get('[data-test="investment-kind-label"]').contains( 'New Investment Project' ) cy.get('[data-test="activity-summary"]').contains( - `${activity.investment.investment_type.name} investment for ${activity.investment.number_new_jobs} jobs added by ${activity.investment.created_by.name}` + `${activity.investment.investment_type.name} investment for ${activity.investment.number_new_jobs} new jobs added by ${activity.investment.created_by.name}` ) }) @@ -533,7 +533,7 @@ describe('Company overview page', () => { urls.companies.overview.index(fixtures.company.venusLtd.id) ) const activity = investmentsListNullJobs[0] - cy.get('[data-test="investment-service-label"]').contains( + cy.get('[data-test="investment-kind-label"]').contains( 'New Investment Project' ) cy.get('[data-test="activity-summary"]').contains(