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

Feature/CLS2-981 Display EYB activity on Company Overview page #7396

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
return transformOrderToListItem(activity)
case 'great_export_enquiry':
return transformGreatExportEnquiryToListItem(activity)
case 'eyb_lead':
return transformEYBLeadToListItem(activity)
default:
return {}
}
Expand Down Expand Up @@ -142,19 +144,31 @@
}
}

function getInvestmentSummary(activity) {
let investment = activity.investment
let summary = `${investment.investment_type.name} investment`
if (investment.number_new_jobs === null) {
summary = summary + ` added by ${investment.created_by.name}`
} else {
summary =
summary +
` for ${checkNewJobs(investment.number_new_jobs)} ${pluraliseLabel(investment.number_new_jobs, 'new job')} added by ${investment.created_by.name}`
}
if (activity.investment.eyb_leads.length !== 0) {
summary = summary + ' from EYB lead'
}
return summary
}

export const transformInvestmentToListItem = (activity) => {
const investment = activity.investment

return {
id: investment.id,
date: formatDate(activity.date, DATE_FORMAT_MEDIUM),
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 ${checkNewJobs(investment.number_new_jobs)} ${pluraliseLabel(investment.number_new_jobs, 'new job')} added by ${investment.created_by.name}`,
summary: getInvestmentSummary(activity),
}
}

Expand Down Expand Up @@ -192,3 +206,35 @@
count: activities.count,
results: transformActivity(activities),
})

export const getEYBValue = (activity) => {
const eybValue = activity.eyb_lead.is_high_value

switch (eybValue) {
case true:
return 'A high'
case false:
return 'A low'
default:
return 'An unknown'
}
}

export const transformEYBLeadToListItem = (activity) => {
return {
id: activity.eyb_lead.id,
date: formatDate(activity.eyb_lead.created_on),
tags: [
{
text: 'EYB',
colour: 'grey',
dataTest: 'eyb-label',
},
].filter(({ text }) => Boolean(text)),
headingUrl: urls.investments.eybLeads.details(activity.eyb_lead.id),
headingText: activity.company.name
? activity.company.name

Check warning on line 236 in src/client/modules/Companies/CompanyOverview/TableCards/ActivityCards/transformers.js

View check run for this annotation

Codecov / codecov/patch

src/client/modules/Companies/CompanyOverview/TableCards/ActivityCards/transformers.js#L236

Added line #L236 was not covered by tests
: activity.eyb_lead.company_name,
summary: `${getEYBValue(activity)}-value EYB lead associated with this company has been added to Data Hub`,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
import React from 'react'

import urls from '../../../../../../../src/lib/urls'

import { transformEYBLeadToListItem } 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,
assertEYBLabel,
} from '../../../../support/activity-assertions'

const EYB_LEAD_ID = 'e686c9d9-d7ba-444d-a85b-a64c477fc1ba'
const PROJECT_URL = urls.investments.eybLeads.details(EYB_LEAD_ID)
const EYB_COMPANY_NAME = 'EYB Company Name'
const LINKED_COMPANY_NAME = 'Linked Company Name'

const buildAndMountActivity = (value = null, linked_company_name = null) => {
const activity = {
company: {
name: linked_company_name,
},
eyb_lead: {
is_high_value: value,
created_on: '2024-12-02T09:59:03.911296+00:00',
company_name: EYB_COMPANY_NAME,
triage_created: '2024-12-01T09:59:03+00:00',
id: EYB_LEAD_ID,
},
}

cy.mountWithProvider(
<CollectionList
items={[transformEYBLeadToListItem(activity)]}
collectionItemTemplate={ItemTemplate}
/>
)
}

describe('EYB lead activity card', () => {
context(
'When the card is rendered with a lead of unknown value and linked company',
() => {
beforeEach(() => {
buildAndMountActivity(null, LINKED_COMPANY_NAME)
cy.get('[data-test="activity-card-wrapper"]').should('exist')
})

it('should render the labels and metadata', () => {
assertEYBLabel()
assertActivitySubject(
LINKED_COMPANY_NAME,
PROJECT_URL,
'activity-card-wrapper'
)
cy.get('[data-test="activity-date"]').should('have.text', '02 Dec 2024')
cy.get('[data-test="activity-summary"]').should(
'have.text',
`An unknown-value EYB lead associated with this company has been added to Data Hub`
)
})
}
)

context(
'When the card is rendered with a lead of high value and linked company',
() => {
beforeEach(() => {
buildAndMountActivity(true, LINKED_COMPANY_NAME)
cy.get('[data-test="activity-card-wrapper"]').should('exist')
})

it('should render the labels and metadata', () => {
assertEYBLabel()
assertActivitySubject(
LINKED_COMPANY_NAME,
PROJECT_URL,
'activity-card-wrapper'
)
cy.get('[data-test="activity-date"]').should('have.text', '02 Dec 2024')
cy.get('[data-test="activity-summary"]').should(
'have.text',
`A high-value EYB lead associated with this company has been added to Data Hub`
)
})
}
)

context(
'When the card is rendered with a lead of low value and linked company',
() => {
beforeEach(() => {
buildAndMountActivity(false, LINKED_COMPANY_NAME)
cy.get('[data-test="activity-card-wrapper"]').should('exist')
})

it('should render the labels and metadata', () => {
assertEYBLabel()
assertActivitySubject(
LINKED_COMPANY_NAME,
PROJECT_URL,
'activity-card-wrapper'
)
cy.get('[data-test="activity-date"]').should('have.text', '02 Dec 2024')
cy.get('[data-test="activity-summary"]').should(
'have.text',
`A low-value EYB lead associated with this company has been added to Data Hub`
)
})
}
)

context(
'When the card is rendered with a lead of unknown value and no linked company',
() => {
beforeEach(() => {
buildAndMountActivity()
cy.get('[data-test="activity-card-wrapper"]').should('exist')
})

it('should render the labels and metadata', () => {
assertEYBLabel()
assertActivitySubject(
EYB_COMPANY_NAME,
PROJECT_URL,
'activity-card-wrapper'
)
cy.get('[data-test="activity-date"]').should('have.text', '02 Dec 2024')
cy.get('[data-test="activity-summary"]').should(
'have.text',
`An unknown-value EYB lead associated with this company has been added to Data Hub`
)
})
}
)

context(
'When the card is rendered with a lead of high value and no linked company',
() => {
beforeEach(() => {
buildAndMountActivity(true)
cy.get('[data-test="activity-card-wrapper"]').should('exist')
})

it('should render the labels and metadata', () => {
assertEYBLabel()
assertActivitySubject(
EYB_COMPANY_NAME,
PROJECT_URL,
'activity-card-wrapper'
)
cy.get('[data-test="activity-date"]').should('have.text', '02 Dec 2024')
cy.get('[data-test="activity-summary"]').should(
'have.text',
`A high-value EYB lead associated with this company has been added to Data Hub`
)
})
}
)

context(
'When the card is rendered with a lead of low value and no linked company',
() => {
beforeEach(() => {
buildAndMountActivity(false)
cy.get('[data-test="activity-card-wrapper"]').should('exist')
})

it('should render the labels and metadata', () => {
assertEYBLabel()
assertActivitySubject(
EYB_COMPANY_NAME,
PROJECT_URL,
'activity-card-wrapper'
)
cy.get('[data-test="activity-date"]').should('have.text', '02 Dec 2024')
cy.get('[data-test="activity-summary"]').should(
'have.text',
`A low-value EYB lead associated with this company has been added to Data Hub`
)
})
}
)
})
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import { CREATED_BY, CREATED_ON } from '../../../../support/activity-constants'

const NAME = 'An investment project'
const PROJECT_URL = urls.investments.projects.details('2')
const EYB_LEAD = [{ id: '1' }]
const EYB_LEADS = [{ id: '2' }, { id: '3' }, { id: '4' }]

const buildAndMountActivity = (newJobs) => {
const buildAndMountActivity = (newJobs, eybLeads = []) => {
const activity = {
date: CREATED_ON,
investment: {
Expand All @@ -24,6 +26,7 @@ const buildAndMountActivity = (newJobs) => {
investment_type: {
name: 'FDI',
},
eyb_leads: eybLeads,
number_new_jobs: newJobs,
},
}
Expand Down Expand Up @@ -54,7 +57,7 @@ describe('Investment activity card', () => {
})
})

context('When the project has one new job', () => {
context('When the project has one new job and no linked EYB leads', () => {
beforeEach(() => {
buildAndMountActivity(1)
cy.get('[data-test="activity-card-wrapper"]').should('exist')
Expand All @@ -71,7 +74,44 @@ describe('Investment activity card', () => {
})
})

context('When the project has no new jobs', () => {
context('When the project has one new job and one linked EYB lead', () => {
beforeEach(() => {
buildAndMountActivity(1, EYB_LEAD)
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} from EYB lead`
)
})
})

context(
'When the project has one new job and multiple linked EYB lead',
() => {
beforeEach(() => {
buildAndMountActivity(1, EYB_LEADS)
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} from EYB lead`
)
})
}
)

context('When the project has no new jobs and no linked EYB leads', () => {
beforeEach(() => {
buildAndMountActivity(0)
cy.get('[data-test="activity-card-wrapper"]').should('exist')
Expand All @@ -87,4 +127,41 @@ describe('Investment activity card', () => {
)
})
})

context('When the project has no new jobs and one linked EYB leads', () => {
beforeEach(() => {
buildAndMountActivity(0, EYB_LEAD)
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} from EYB lead`
)
})
})

context(
'When the project has no new jobs and mutiple linked EYB leads',
() => {
beforeEach(() => {
buildAndMountActivity(0, EYB_LEADS)
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} from EYB lead`
)
})
}
)
})
4 changes: 4 additions & 0 deletions test/component/cypress/support/activity-assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export const assertProjectKindLabel = () => {
assertText('[data-test="investment-kind-label"]', 'New Investment Project')
}

export const assertEYBLabel = () => {
assertText('[data-test="eyb-label"]', 'EYB')
}

export const assertOrderKindLabel = () => {
assertText('[data-test="order-kind-label"]', 'New Order')
}
Loading
Loading