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

Add tests for GREAT export enquiry activity #7410

Merged
merged 4 commits into from
Dec 17, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import CardUtils from './card/CardUtils'
import ActivityCardWrapper from './card/ActivityCardWrapper'
import ActivityCardLabels from './card/ActivityCardLabels'
import ActivityCardSubject from './card/ActivityCardSubject'
import ActivityCardNotes from './card/ActivityCardNotes'
import ActivityCardMetadata from './card/ActivityCardMetadata'
import ActivityOverviewSummary from './card/item-renderers/ActivityOverviewSummary'

Expand Down Expand Up @@ -104,38 +103,6 @@ export default class DirectoryFormsApi extends React.PureComponent {
<ActivityCardMetadata metadata={metadata} />
</ActivityCardWrapper>
)
} else {
kind = 'great.gov.uk Enquiry'
const metadata = [
{ label: 'Date', value: format(sentDate) },
{
label: 'Name',
value: `${formData.first_name} ${formData.last_name}`,
},
{ label: 'Job title', value: formData.position },
{ label: 'Email', value: formData.email },
]
return isOverview ? (
<ActivityOverviewSummary
dataTest="export-support-service-great-summary"
activity={activity}
date={format(sentDate)}
kind={kind}
subject="Enquiry"
summary={`Enquirer ${formData.first_name} ${formData.last_name}`}
></ActivityOverviewSummary>
) : (
<ActivityCardWrapper>
<ActivityCardSubject>Enquiry</ActivityCardSubject>
<ActivityCardLabels
theme="great.gov.uk"
service="export"
kind={kind}
/>
<ActivityCardNotes notes={formData.comment} />
<ActivityCardMetadata metadata={metadata} />
</ActivityCardWrapper>
)
}
}
}

This file was deleted.

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 @@ -71,3 +71,9 @@ export const NEW_ORDER_TAG = {
colour: 'grey',
dataTest: 'order-kind-label',
}

export const GREAT_EXPORT_TAG = {
text: 'great.gov.uk',
colour: TAGS.ACTIVITY_LABELS.KIND,
dataTest: 'great-kind-label',
}
38 changes: 21 additions & 17 deletions src/client/modules/Companies/CompanyActivity/transformers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import React from 'react'
import Link from '@govuk-react/link'

import { TAGS, NEW_PROJECT_TAG, NEW_ORDER_TAG } from './constants'
import {
TAGS,
NEW_PROJECT_TAG,
NEW_ORDER_TAG,
GREAT_EXPORT_TAG,
} from './constants'
import urls from '../../../../lib/urls'
import { formatDate, DATE_FORMAT_MEDIUM } from '../../../utils/date-utils'
import { truncateData } from '../utils'
Expand Down Expand Up @@ -291,38 +296,37 @@ export const transformOrderToListItem = (activity) => {
}

export const transformGreatExportEnquiryToListItem = (activity) => {
const great = activity.great_export_enquiry
const greatExportEnquiry = activity.great_export_enquiry
const contact = greatExportEnquiry.contact
return {
id: great.id,
id: greatExportEnquiry.id,
metadata: [
{ label: 'Date', value: formatDate(activity.date, DATE_FORMAT_MEDIUM) },
{
label: 'Contact',
value: formattedContacts([great.contact]),
label: '',
value: truncateData(greatExportEnquiry.data_enquiry),
},
{ label: 'Date', value: formatDate(activity.date, DATE_FORMAT_MEDIUM) },
{
label: 'Comment',
value: truncateData(great.data_enquiry),
label: 'Contact',
value: contact.name.length && contact.name,
},
{ label: 'Job title', value: contact?.job_title },
{ label: 'Email', value: greatExportEnquiry.meta_email_address },
].filter(({ value }) => Boolean(value)),
tags: [
{
text: 'great.gov.uk Enquiry',
colour: TAGS.ACTIVITY_LABELS.KIND,
dataTest: 'great-kind-label',
colour: TAGS.ACTIVITY_LABELS.THEME,
dataTest: 'great-theme-label',
},
{
text: 'service',
text: 'Export',
colour: TAGS.ACTIVITY_LABELS.SERVICE,
dataTest: 'great-service-label',
},
{
text: 'great.gov.uk',
colour: TAGS.ACTIVITY_LABELS.THEME,
dataTest: 'great-theme-label',
},
GREAT_EXPORT_TAG,
].filter(({ text }) => Boolean(text)),
headingText: `Enquiry ` + truncateData(great.meta_subject, 35),
headingText: `Enquiry ` + truncateData(greatExportEnquiry.meta_subject, 35),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
TAGS,
NEW_PROJECT_TAG,
NEW_ORDER_TAG,
GREAT_EXPORT_TAG,
} from '../../../CompanyActivity/constants'
import { isDateInFuture } from '../../../../../utils/date'
import { formatDate, DATE_FORMAT_MEDIUM } from '../../../../../utils/date-utils'
Expand Down Expand Up @@ -171,20 +172,16 @@
}

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

tags: [
{
text: 'great.gov.uk Enquiry',
colour: TAGS.ACTIVITY_LABELS.KIND,
dataTest: 'great-kind-label',
},
].filter(({ text }) => Boolean(text)),
headingText: truncateData(great.meta_subject, 35),
summary: `Enquirer ${great.contact.first_name} ${great.contact.last_name}`,
tags: [GREAT_EXPORT_TAG].filter(({ text }) => Boolean(text)),
headingText: truncateData(greatExportEnquiry.meta_subject, 35),
summary:
greatExportEnquiry.contact.name.length > 0
? `Enquirer ${greatExportEnquiry.contact?.name}`
: 'Unknown enquirer',

Check warning on line 184 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#L184

Added line #L184 was not covered by tests
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/client/modules/Companies/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ export const companyCollectionListMetadataTask = (ID) => {
}

export const truncateData = (enquiry, maxLength = 200) =>
enquiry.length < maxLength
enquiry.length == 0 || enquiry.length < maxLength
? enquiry
: enquiry.slice(0, maxLength).split(' ').slice(0, -1).join(' ') + ' ...'
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import React from 'react'

import { ItemTemplate } from '../../../../../../src/client/modules/Companies/CompanyActivity'
import { transformGreatExportEnquiryToListItem } from '../../../../../../src/client/modules/Companies/CompanyActivity/transformers'
import { CollectionList } from '../../../../../../src/client/components'
import {
assertMetadataItems,
assertGreatKindLabel,
assertText,
} from '../../../support/activity-assertions'
import {
CONTACT_1,
CREATED_BY,
CREATED_ON,
EMPTY_CONTACT,
} from '../../../support/activity-constants'

const SUBJECT = 'Lorem ipsum dolor'
const NOTES =
'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor.'
const LONG_NOTES =
'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium.'

const buildAndMountActivity = (
showOptionalFields,
notes = NOTES,
subject = SUBJECT
) => {
const activity = {
date: CREATED_ON,
great_export_enquiry: {
id: '2',
contact: showOptionalFields ? CONTACT_1 : EMPTY_CONTACT,
data_enquiry: showOptionalFields ? notes : '',
meta_subject: subject,
meta_email_address: showOptionalFields ? CREATED_BY.email : '',
},
}

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

describe('Great Export Enquiry activity card', () => {
context('When the card is rendered with a complete enquiry', () => {
beforeEach(() => {
buildAndMountActivity(true)
cy.get('[data-test=collection-item]').should('exist')
})

it('should render the labels and metadata', () => {
assertGreatLabels()
cy.get(`[data-test="collection-item"]`)
.find('h3')
.children()
.should('exist')
.should('have.text', `Enquiry ${SUBJECT}`)
.should('not.have.attr', 'href')
assertMetadataItems([
` ${NOTES}`,
'Date 25 Nov 2058',
'Contact Alexander Hamilton',
'Job title Test Job',
'Email [email protected]',
])
})
})

context('When the enquiry has missing fields', () => {
beforeEach(() => {
buildAndMountActivity(false)
cy.get('[data-test=collection-item]').should('exist')
})

it('should render the date and the labels', () => {
assertGreatLabels()
assertMetadataItems(['Date 25 Nov 2058'])
})
})

context('When the enquiry has a long name and notes', () => {
beforeEach(() => {
buildAndMountActivity(true, LONG_NOTES, LONG_NOTES)
cy.get('[data-test=collection-item]').should('exist')
})

it('should truncate the long fields', () => {
assertGreatLabels()
cy.get(`[data-test="collection-item"]`)
.find('h3')
.children()
.should('exist')
.should('have.text', 'Enquiry Lorem ipsum dolor sit amet, ...')
.should('not.have.attr', 'href')
assertMetadataItems([
' Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec ...',
'Date 25 Nov 2058',
'Contact Alexander Hamilton',
'Job title Test Job',
'Email [email protected]',
])
})
})
})

const assertGreatLabels = () => {
assertText('[data-test="great-theme-label"]', 'great.gov.uk Enquiry')
assertText('[data-test="great-service-label"]', 'Export')
assertGreatKindLabel()
}
Loading
Loading