Skip to content

Commit

Permalink
Merge pull request #7313 from uktrade/TET-851-company-activity-great-…
Browse files Browse the repository at this point in the history
…export-enquiry-feed

Add great data to company activity
  • Loading branch information
bau123 authored Nov 14, 2024
2 parents 84ff942 + 1470c70 commit e9ffbd9
Show file tree
Hide file tree
Showing 8 changed files with 223 additions and 29 deletions.
7 changes: 7 additions & 0 deletions src/client/modules/Companies/CompanyActivity/constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { TAG_COLOURS } from '../../../components/Tag/index'

export const LABELS = {
activityType: 'Activity type',
interaction: 'Interaction',
Expand Down Expand Up @@ -34,6 +36,11 @@ export const TAGS = {
colour: 'blue',
},
},
ACTIVITY_LABELS: {
KIND: TAG_COLOURS.GREY,
THEME: TAG_COLOURS.GOV_BLUE,
SERVICE: TAG_COLOURS.BLUE,
},
}

const FILTER_KEYS = {
Expand Down
81 changes: 69 additions & 12 deletions src/client/modules/Companies/CompanyActivity/transformers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { formatMediumDate } from '../../../utils/date'
import { AdviserResource } from '../../../components/Resource'
import { INTERACTION_NAMES } from '../../../../apps/interactions/constants'

const { isEmpty } = require('lodash')

const AdviserEmail = (props) => (
<AdviserResource.Inline {...props}>
{(adviser) => adviser.email}
Expand Down Expand Up @@ -38,6 +40,11 @@ export const formattedContacts = (contacts) =>
</span>
))

export const truncateEnquiry = (enquiry, maxLength = 200) =>
enquiry.length < maxLength
? enquiry
: enquiry.slice(0, maxLength).split(' ').slice(0, -1).join(' ') + ' ...'

export const formattedAdvisers = (advisers) =>
!!advisers.length &&
advisers.map((item) => (
Expand All @@ -52,18 +59,32 @@ export const verifyLabel = (array, label) =>
/*
From the activity_source field from the API, determine which transformer to
use to get the required data for the cards.
Removes any sources which does not have a transformer.
*/
export const transformActivity = (activity) => {
const activity_source = activity.activity_source
export const transformActivities = (activities) => {
const transformedActivites = activities.results.map((activity) => {
const activity_source = activity.activity_source

if (activity_source === 'interaction')
return transformInteractionToListItem(activity.interaction)
else if (activity_source === 'referral')
return transformReferralToListItem(activity)
else if (activity_source === 'investment')
return transformInvestmentToListItem(activity)
else if (activity_source === 'order')
return transformOrderToListItem(activity)
switch (activity_source) {
case 'interaction':
return transformInteractionToListItem(activity.interaction)
case 'referral':
return transformReferralToListItem(activity)
case 'investment':
return transformInvestmentToListItem(activity)
case 'order':
return transformOrderToListItem(activity)
case 'great_export_enquiry':
return transformGreatExportEnquiryToListItem(activity)
default:
return {}
}
})

return transformedActivites.filter(
(transformedActivity) => !isEmpty(transformedActivity)
)
}

export const transformInteractionToListItem = ({
Expand Down Expand Up @@ -258,9 +279,45 @@ export const transformOrderToListItem = (activity) => {
}
}

export const transformGreatExportEnquiryToListItem = (activity) => {
const great = activity.great_export_enquiry
return {
id: great.id,
metadata: [
{ label: 'Date', value: formatMediumDate(great.created_on) },
{
label: 'Contact',
value: formattedContacts([great.contact]),
},
{
label: 'Comment',
value: truncateEnquiry(great.data_enquiry),
},
].filter(({ value }) => Boolean(value)),
tags: [
{
text: 'great.gov.uk Enquiry',
colour: TAGS.ACTIVITY_LABELS.KIND,
dataTest: 'great-kind-label',
},
{
text: 'service',
colour: TAGS.ACTIVITY_LABELS.SERVICE,
dataTest: 'great-service-label',
},
{
text: 'great.gov.uk',
colour: TAGS.ACTIVITY_LABELS.THEME,
dataTest: 'great-theme-label',
},
].filter(({ text }) => Boolean(text)),
headingText: `Enquiry ` + great.meta_subject,
}
}

export const transformResponseToCollection = (activities) => ({
count: activities.count,
results: activities.results.map(transformActivity),
count: transformActivities(activities).length,
results: transformActivities(activities),
})

export const filterServiceNames = (services) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { formatMediumDate, isDateInFuture } from '../../../../../utils/date'
import { INTERACTION_NAMES } from '../../../../../../apps/interactions/constants'
import urls from '../../../../../../lib/urls'

const { isEmpty } = require('lodash')

const transformAdvisers = (advisers) => {
const stringAdvisers = advisers.map((value) => value.adviser.name).join(', ')

Expand Down Expand Up @@ -42,17 +44,29 @@ const buildSummary = (advisers, communicationChannel, contacts, date) => {
From the activity_source field from the API, determine which transformer to
use to get the required data for the cards.
*/
export const transformActivity = (activity) => {
const activity_source = activity.activity_source

if (activity_source === 'interaction')
return transformInteractionToListItem(activity.interaction)
else if (activity_source === 'referral')
return transformReferralToListItem(activity)
else if (activity_source === 'investment')
return transformInvestmentToListItem(activity)
else if (activity_source === 'order')
return transformOrderToListItem(activity)
export const transformActivity = (activities) => {
const transformedActivites = activities.results.map((activity) => {
const activity_source = activity.activity_source

switch (activity_source) {
case 'interaction':
return transformInteractionToListItem(activity.interaction)
case 'referral':
return transformReferralToListItem(activity)
case 'investment':
return transformInvestmentToListItem(activity)
case 'order':
return transformOrderToListItem(activity)
case 'great_export_enquiry':
return transformGreatExportEnquiryToListItem(activity)
default:
return {}
}
})

return transformedActivites.filter(
(transformedActivity) => !isEmpty(transformedActivity)
)
}

export const transformReferralToListItem = (activity) => {
Expand Down Expand Up @@ -163,7 +177,25 @@ export const transformOrderToListItem = (activity) => {
}
}

export const transformGreatExportEnquiryToListItem = (activity) => {
const great = activity.great_export_enquiry
return {
id: great.id,
date: formatMediumDate(activity.date),

tags: [
{
text: 'great.gov.uk Enquiry',
colour: TAGS.ACTIVITY_LABELS.KIND,
dataTest: 'great-kind-label',
},
].filter(({ text }) => Boolean(text)),
headingText: great.meta_subject,
summary: `Enquirer ${great.contact.first_name} ${great.contact.last_name}`,
}
}

export const transformResponseToCollection = (activities) => ({
count: activities.count,
results: activities.results.map(transformActivity),
count: transformActivity(activities).length,
results: transformActivity(activities),
})
4 changes: 2 additions & 2 deletions src/client/modules/Events/CollectionList/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { connect } from 'react-redux'
import { Link } from 'govuk-react'
import { Link, H3 } from 'govuk-react'
import { FONT_SIZE, FONT_WEIGHTS, SPACING } from '@govuk-react/constants'
import styled from 'styled-components'

Expand Down Expand Up @@ -60,7 +60,7 @@ const StyledLinkHeader = styled('h3')`
// e.g. the positional arguments should be passed as an object
export const TitleRenderer = (title, url, margin = { bottom: 10 }) => (
<StyledLinkHeader margin={margin}>
<Link href={url}>{title}</Link>
{url ? <Link href={url}>{title}</Link> : <H3>{title}</H3>}
</StyledLinkHeader>
)

Expand Down
30 changes: 30 additions & 0 deletions test/functional/cypress/fakers/company-activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,22 @@ const companyActivityOrderFaker = (overrides = {}, orderOverrides = {}) => ({
...overrides,
})

const companyActivityGreatFaker = (overrides = {}, orderOverrides = {}) => ({
...companyActivityFaker(),
activity_source: 'great_export_enquiry',
great_export_enquiry: {
id: faker.string.uuid(),
created_on: relativeDateFaker({ minDays: -100, maxDays: 365 }),
meta_full_name: faker.person.fullName(),
meta_email_address: faker.internet.email(),
contact: userFaker({ job_title: faker.person.jobTitle() }),
meta_subject: faker.company.buzzPhrase(),
data_enquiry: faker.lorem.paragraph(),
...orderOverrides,
},
...overrides,
})

const companyActivityInteractionListFaker = (length = 1, overrides) =>
listFaker({
fakerFunction: companyActivityInteractionFaker,
Expand All @@ -109,6 +125,19 @@ const companyActivityOrderListFaker = (
})
}

const companyActivityGreatListFaker = (
length = 1,
overrides,
orderOverrides
) => {
return listFakerAdditionalOverrides({
fakerFunction: companyActivityGreatFaker,
length,
overrides,
additionalOverrides: orderOverrides,
})
}

const companyActivityInvestmentListFaker = (
length = 1,
overrides,
Expand All @@ -128,6 +157,7 @@ export {
companyActivityInteractionListFaker,
companyActivityInvestmentListFaker,
companyActivityOrderListFaker,
companyActivityGreatListFaker,
}

export default companyActivityInteractionListFaker
52 changes: 51 additions & 1 deletion test/functional/cypress/specs/companies/activity-feed-spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { collectionListRequest } from '../../support/actions'
import { companyActivityOrderListFaker } from '../../fakers/company-activity'
import {
companyActivityOrderListFaker,
companyActivityGreatListFaker,
} from '../../fakers/company-activity'

const fixtures = require('../../fixtures')
const urls = require('../../../../../src/lib/urls')
Expand Down Expand Up @@ -53,6 +56,53 @@ describe('Company activity feed', () => {
'Activity Feed'
)
})
context('Great Export Enquiry activity feed', () => {
const greatData = companyActivityGreatListFaker(1)
beforeEach(() => {
collectionListRequest(
'v4/search/company-activity',
greatData,
urls.companies.activity.index(company.id)
)
})

const activity = greatData[0]
it('displays the correct activity type label', () => {
cy.get('[data-test="great-kind-label"]').contains(
'great.gov.uk Enquiry',
{
matchCase: false,
}
)
})

it('displays the correct topic label', () => {
cy.get('[data-test="great-theme-label"]').contains('great.gov.uk', {
matchCase: false,
})
})

it('displays the correct sub-topic label', () => {
cy.get('[data-test="great-service-label"]').contains('service', {
matchCase: false,
})
})
it('displays the Great export enquiry subject', () => {
cy.get('[data-test="collection-item"]').each(() =>
cy.get('h3').contains(`${activity.great_export_enquiry.meta_subject}`)
)
})
it('displays the Great export enquiry contact', () => {
cy.get('[data-test="metadata-item"]').contains(
`${activity.great_export_enquiry.contact.name}`
)
})
it('displays the Great export enquiry comment', () => {
cy.get('[data-test="metadata-item"]').contains(
`${activity.great_export_enquiry.data_enquiry}`
)
})
})

context('Orders (OMIS)', () => {
const orderListNoUkRegion = companyActivityOrderListFaker(
Expand Down
18 changes: 18 additions & 0 deletions test/functional/cypress/specs/companies/overview-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import { getCollectionList } from '../../support/collection-list-assertions'
import { collectionListRequest } from '../../support/actions'
import companyActivityListFaker, {
companyActivityGreatListFaker,
companyActivityInvestmentListFaker,
companyActivityOrderListFaker,
} from '../../fakers/company-activity'
Expand Down Expand Up @@ -401,6 +402,7 @@ describe('Company overview page', () => {
{},
{ primary_market: null }
)
const greatList = companyActivityGreatListFaker(1)
beforeEach(() => {
collectionListRequest(
'v4/search/company-activity',
Expand Down Expand Up @@ -579,6 +581,22 @@ describe('Company overview page', () => {
.next()
.contains('Joe Bloggs organised Best service')
})

it('should display Data Hub great activity', () => {
collectionListRequest(
'v4/search/company-activity',
greatList,
urls.companies.overview.index(fixtures.company.venusLtd.id)
)
const activity = greatList[0]
cy.get('[data-test="great-kind-label"]').contains('great.gov.uk')
cy.get('[data-test="activity-subject"]').contains(
activity.great_export_enquiry.meta_subject
)
cy.get('[data-test="activity-summary"]').contains(
`Enquirer ${activity.great_export_enquiry.contact.first_name} ${activity.great_export_enquiry.contact.last_name}`
)
})
})

context(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"count": 2,
"count": 5,
"results": [
{
"id": "e25696d1-a54b-4e2e-b0bf-9657e9c4c55b",
Expand Down

0 comments on commit e9ffbd9

Please sign in to comment.