From 7e1bbee7d572706b0995b81fb9d9249bc01713e7 Mon Sep 17 00:00:00 2001 From: Stuart Mindt Date: Tue, 25 Feb 2025 13:43:35 +0000 Subject: [PATCH 1/5] CLS2-1299 Show edit history on EYB leads --- src/apps/routers.js | 1 + src/client/components/AuditHistory/index.jsx | 2 +- .../Resource/EYBLeadAuditHistory.js | 6 + src/client/components/Resource/index.jsx | 1 + src/client/components/Resource/tasks.js | 2 + .../Investments/EYBLeads/EYBLeadDetails.jsx | 200 ++++++++++-------- .../EYBLeadEditHistory/EYBLeadEditHistory.jsx | 58 +++++ .../EYBLeads/EYBLeadEditHistory/constants.js | 21 ++ .../EYBLeadEditHistory/transformers.js | 52 +++++ src/client/routes.js | 9 + src/lib/urls.js | 4 + src/middleware/api-proxy.js | 1 + 12 files changed, 270 insertions(+), 87 deletions(-) create mode 100644 src/client/components/Resource/EYBLeadAuditHistory.js create mode 100644 src/client/modules/Investments/EYBLeads/EYBLeadEditHistory/EYBLeadEditHistory.jsx create mode 100644 src/client/modules/Investments/EYBLeads/EYBLeadEditHistory/constants.js create mode 100644 src/client/modules/Investments/EYBLeads/EYBLeadEditHistory/transformers.js diff --git a/src/apps/routers.js b/src/apps/routers.js index 493c66f9410..20dfdc9d6be 100644 --- a/src/apps/routers.js +++ b/src/apps/routers.js @@ -138,6 +138,7 @@ const reactRoutes = [ '/investments/projects/:projectId/propositions/:propositionId/document', '/investments/eyb-leads', '/investments/eyb-leads/:eybLeadId/details', + '/investments/eyb-leads/:eybLeadId/edit-history', '/companies/:companyId/referrals/send', '/companies/:companyId/referrals/:referralId', '/contacts/:contactId/details', diff --git a/src/client/components/AuditHistory/index.jsx b/src/client/components/AuditHistory/index.jsx index b120180e989..5eac0a398bb 100644 --- a/src/client/components/AuditHistory/index.jsx +++ b/src/client/components/AuditHistory/index.jsx @@ -19,7 +19,7 @@ const AuditHistory = ({ excludedFields = [], auditType, }) => ( - + {(items) => (
    {transformAuditResponseToCollection( diff --git a/src/client/components/Resource/EYBLeadAuditHistory.js b/src/client/components/Resource/EYBLeadAuditHistory.js new file mode 100644 index 00000000000..22563499d75 --- /dev/null +++ b/src/client/components/Resource/EYBLeadAuditHistory.js @@ -0,0 +1,6 @@ +import { createCollectionResource } from './Resource' + +export default createCollectionResource( + 'Changes to EYB lead details', + (id) => `v4/investment-lead/eyb/${id}/audit` +) diff --git a/src/client/components/Resource/index.jsx b/src/client/components/Resource/index.jsx index d1cb3d16d0e..1ff0ef3848d 100644 --- a/src/client/components/Resource/index.jsx +++ b/src/client/components/Resource/index.jsx @@ -27,6 +27,7 @@ export { default as ExportExperienceCategoriesResource } from './ExportExperienc export { default as ExportResource } from './Export' export { default as ExportYearsResource } from './ExportYears' export { default as EYBLeadResource } from './EYBLead' +export { default as EYBLeadAuditHistoryResource } from './EYBLeadAuditHistory' export { default as FDITypesResource } from './FDITypes' export { default as FDIValuesResource } from './FDIValues' export { default as HQTeamRegionOrPostsResource } from './HQTeamRegionOrPost' diff --git a/src/client/components/Resource/tasks.js b/src/client/components/Resource/tasks.js index f59f0d5d487..b4e1830eac4 100644 --- a/src/client/components/Resource/tasks.js +++ b/src/client/components/Resource/tasks.js @@ -99,6 +99,7 @@ import EvidenceTag from './EvidenceTag' import ProjectAuditHistory from './ProjectAuditHistory' import WinUKRegions from './WinUKRegions' import Referral from './Referral' +import EYBLeadAuditHistory from './EYBLeadAuditHistory' export default { ...AssociatedProgramme.tasks, @@ -202,4 +203,5 @@ export default { ...EvidenceTag.tasks, ...ProjectAuditHistory.tasks, ...Referral.tasks, + ...EYBLeadAuditHistory.tasks, } diff --git a/src/client/modules/Investments/EYBLeads/EYBLeadDetails.jsx b/src/client/modules/Investments/EYBLeads/EYBLeadDetails.jsx index e0c57991a8a..b7f8b559b0e 100644 --- a/src/client/modules/Investments/EYBLeads/EYBLeadDetails.jsx +++ b/src/client/modules/Investments/EYBLeads/EYBLeadDetails.jsx @@ -1,6 +1,9 @@ import React from 'react' import { useParams } from 'react-router-dom' import { Link } from 'govuk-react' +import styled from 'styled-components' + +import { SPACING_POINTS } from '@govuk-react/constants' import { formatDate, DATE_FORMAT_COMPACT } from '../../../utils/date-utils' import urls from '../../../../lib/urls' @@ -13,6 +16,12 @@ import { EYBLeadLayout, NewWindowLink, SummaryTable } from '../../../components' import { NOT_SET_TEXT } from '../../../../apps/companies/constants' import { VALUES_VALUE_TO_LABEL_MAP } from './constants' +const StyledRoot = styled('div')` + { + margin-top: ${SPACING_POINTS[4]}px; + margin-bottom: ${SPACING_POINTS[4]}px; + } +` const EYBLeadDetails = () => { const { eybLeadId } = useParams() return ( @@ -20,96 +29,115 @@ const EYBLeadDetails = () => { {(eybLead) => { return ( - - {eybLead.company ? ( - + +
    + Changes made to this information can be found on the{' '} + + Edit history page + + . +
    +
    + + {eybLead.company ? ( + + {eybLead.company.name} + + } + /> + ) : ( + + )} + + + + + + {eybLead.companyWebsite ? ( + - {eybLead.company.name} - + {eybLead.companyWebsite} + + ) : ( + NOT_SET_TEXT + )} + + + - ) : ( - - )} - - - - - - {eybLead.companyWebsite ? ( - - {eybLead.companyWebsite} - - ) : ( - NOT_SET_TEXT - )} - - - - - - - - - - - - + + + + + + + +
    + ) }}
    diff --git a/src/client/modules/Investments/EYBLeads/EYBLeadEditHistory/EYBLeadEditHistory.jsx b/src/client/modules/Investments/EYBLeads/EYBLeadEditHistory/EYBLeadEditHistory.jsx new file mode 100644 index 00000000000..4513c6f23fb --- /dev/null +++ b/src/client/modules/Investments/EYBLeads/EYBLeadEditHistory/EYBLeadEditHistory.jsx @@ -0,0 +1,58 @@ +import React from 'react' +import { useParams } from 'react-router-dom' + +import { + EYBLeadResource, + EYBLeadAuditHistoryResource, +} from '../../../../components/Resource' +import { AuditHistory, DefaultLayout } from '../../../../components' +import { getValue, mapFieldNameToLabel } from './transformers' +import urls from '../../../../../lib/urls' +import { EXCLUDED_FIELDS } from './constants' + +const EYBLeadName = ({ id }) => ( + {(eybLead) => eybLead.company.name} +) + +const EYBLeadEditHistory = () => { + const { eybLeadId } = useParams() + + return ( + + Edit history - EYB lead details - - + Investments + + } + heading="Edit history" + breadcrumbs={[ + { link: urls.dashboard.index(), text: 'Home' }, + { + link: urls.investments.index(), + text: 'Investments', + }, + { + link: urls.investments.eybLeads.index(), + text: 'EYB leads', + }, + { + link: urls.investments.eybLeads.details(eybLeadId), + text: , + }, + { text: 'Edit history' }, + ]} + > + + + ) +} + +export default EYBLeadEditHistory diff --git a/src/client/modules/Investments/EYBLeads/EYBLeadEditHistory/constants.js b/src/client/modules/Investments/EYBLeads/EYBLeadEditHistory/constants.js new file mode 100644 index 00000000000..a3b9959d485 --- /dev/null +++ b/src/client/modules/Investments/EYBLeads/EYBLeadEditHistory/constants.js @@ -0,0 +1,21 @@ +export const EXCLUDED_FIELDS = [ + 'triage_created', + 'triage_modified', + 'user_created', + 'user_modified', +] + +export const EYB_LEAD_FIELD_NAME_TO_LABEL_MAP = { + sector: 'Sector or industry', + intent: 'How do you plan to expand your business in the UK?', + proposed_investment_city: 'Where do you want to set up in the UK?', + hiring: 'How many people do you want to hire in the UK in the first 3 years?', + spend: 'How much do you want to spend on setting up in the first 3 years?', + is_high_value: 'Value', + company_website: 'Company website address', + role: 'Job title', + telephone_number: 'Phone number', + landing_timeframe: 'When do you want to set up?', + location_none: 'Do you know where you want to set up in the UK?', + company_headquarters: 'Location of company headquarters', +} diff --git a/src/client/modules/Investments/EYBLeads/EYBLeadEditHistory/transformers.js b/src/client/modules/Investments/EYBLeads/EYBLeadEditHistory/transformers.js new file mode 100644 index 00000000000..0a93b4ba037 --- /dev/null +++ b/src/client/modules/Investments/EYBLeads/EYBLeadEditHistory/transformers.js @@ -0,0 +1,52 @@ +import { isBoolean, isNumber } from 'lodash' + +import { EYB_LEAD_FIELD_NAME_TO_LABEL_MAP } from './constants' +import { NOT_SET, YES, NO } from '../../../../components/AuditHistory/constants' +// import { currencyGBP } from '../../../../utils/number-utils' +import { transformFieldName } from '../../../../components/AuditHistory/transformers' +import { + convertEYBChoicesToLabels, + formatProposedInvestmentCity, +} from '../../utils' + +export const mapFieldNameToLabel = (fieldName) => + EYB_LEAD_FIELD_NAME_TO_LABEL_MAP[fieldName] || transformFieldName(fieldName) + +const getValueFromBoolean = (value, field) => { + if (field === 'Value') { + return value ? 'High' : 'Low' + } + return value ? YES : NO +} + +export const getValue = (value, field) => { + if (isBoolean(value)) { + return getValueFromBoolean(value, field) + } + + if (isNumber(value)) { + return value.toString() + } + + if (field === 'Where do you want to set up in the UK?') { + return formatProposedInvestmentCity(value) || NOT_SET + } + + if ( + field === 'How do you plan to expand your business in the UK?' || + field === 'When do you want to set up?' + ) { + return convertEYBChoicesToLabels(value) || NOT_SET + } + + if ( + field === + 'How many people do you want to hire in the UK in the first 3 years?' + ) { + if (value === 'NO_PLANS_TO_HIRE_YET') { + return convertEYBChoicesToLabels(value) + } + } + + return value || NOT_SET +} diff --git a/src/client/routes.js b/src/client/routes.js index ea98dcf8322..825af03c0b0 100644 --- a/src/client/routes.js +++ b/src/client/routes.js @@ -105,6 +105,7 @@ import AddPropositionDocument from './modules/Investments/Projects/Propositions/ import ProtectedRoute from './components/ProtectedRoute/index' import CustomerFeedback from './modules/ExportWins/CustomerFeedback' import EYBLeadDetails from './modules/Investments/EYBLeads/EYBLeadDetails' +import EYBLeadEditHistory from './modules/Investments/EYBLeads/EYBLeadEditHistory/EYBLeadEditHistory' import SendReferralForm from './modules/Companies/Referrals/SendReferralForm/SendReferralForm' import ReferralDetails from './modules/Companies/Referrals/ReferralDetails' import ContactDetails from './modules/Contacts/ContactDetails/ContactDetails' @@ -1044,6 +1045,14 @@ function Routes() { ), }, + { + path: '/investments/eyb-leads/:eybLeadId/edit-history', + element: ( + + + + ), + }, { path: '/investments/opportunities/create', element: ( diff --git a/src/lib/urls.js b/src/lib/urls.js index 55b1ae2d474..3f953a717aa 100644 --- a/src/lib/urls.js +++ b/src/lib/urls.js @@ -533,6 +533,10 @@ module.exports = { eybLeads: { index: url('/investments', '/eyb-leads'), details: url('/investments', '/eyb-leads/:eybLeadId/details'), + editHistory: { + index: url('/investments/eyb-leads', '/:eybLeadId/edit-history'), + data: url('/investments/eyb-leads', '/:eybLeadId/edit-history/data'), + }, }, }, metadata: { diff --git a/src/middleware/api-proxy.js b/src/middleware/api-proxy.js index 1cebf728601..cf7d464f13e 100644 --- a/src/middleware/api-proxy.js +++ b/src/middleware/api-proxy.js @@ -90,6 +90,7 @@ const ALLOWLIST = [ '/v3/investment/:projectId/proposition/:propositionId/document/upload-callback', '/v4/investment-lead/eyb/:eybLeadId', '/v4/investment-lead/eyb', + '/v4/investment-lead/eyb/:eybLeadId/audit', '/v4/dnb/company-investigation', '/v4/company-activity/stova-events/:id', ] From 137dfbf74281847ae936efca52d9ca329ca44a94 Mon Sep 17 00:00:00 2001 From: Stuart Mindt Date: Wed, 26 Feb 2025 09:50:06 +0000 Subject: [PATCH 2/5] Adding functionality to conditionally show sort options in audit history component --- src/client/components/AuditHistory/index.jsx | 7 ++++++- src/client/components/Resource/Paginated.js | 5 +++-- src/client/components/Resource/Resource.jsx | 4 +++- .../CompanyEditHistory/CompanyEditHistory.jsx | 1 + .../Contacts/ContactAuditHistory/ContactAuditHistory.jsx | 1 + .../EYBLeads/EYBLeadEditHistory/EYBLeadEditHistory.jsx | 1 + .../EYBLeads/EYBLeadEditHistory/transformers.js | 1 - .../Projects/EditHistory/ProjectEditHistory.jsx | 1 + 8 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/client/components/AuditHistory/index.jsx b/src/client/components/AuditHistory/index.jsx index 5eac0a398bb..d611aa89f81 100644 --- a/src/client/components/AuditHistory/index.jsx +++ b/src/client/components/AuditHistory/index.jsx @@ -18,8 +18,9 @@ const AuditHistory = ({ fieldMapper = transformFieldName, excludedFields = [], auditType, + showSort = true, }) => ( - + {(items) => (
      {transformAuditResponseToCollection( @@ -68,6 +69,10 @@ AuditHistory.propTypes = { * The type of record. This is displayed as part of the 'no changes saved' text. */ auditType: PropTypes.string.isRequired, + /** + * An option to show / hide the sort options. This is true by default. + */ + showSort: PropTypes.bool, } export default AuditHistory diff --git a/src/client/components/Resource/Paginated.js b/src/client/components/Resource/Paginated.js index 6c3608db5ae..d19cb22b6fa 100644 --- a/src/client/components/Resource/Paginated.js +++ b/src/client/components/Resource/Paginated.js @@ -104,6 +104,7 @@ const PaginatedResource = multiInstance({ shouldPluralize, noResults = "You don't have any results", addItemUrl, + showSort = true, }) => { // We know better than ESLint that we are in deed in a React component // eslint-disable-next-line react-hooks/rules-of-hooks @@ -120,7 +121,6 @@ const PaginatedResource = multiInstance({ const routePage = parseInt(qsParams.page, 10) || 1 const totalPages = result ? Math.ceil(result.count / pageSize) : 0 const hasZeroResults = result?.count === 0 - const task = getTask(name, id) return ( @@ -156,7 +156,8 @@ const PaginatedResource = multiInstance({ shouldPluralize={shouldPluralize} addItemUrl={addItemUrl} /> - {totalPages > 0 && ( + {showSort} + {totalPages > 0 && showSort && ( { Component.taskName = name Component.resourceName = name - Component.Paginated = (props) => + Component.Paginated = ({ showSort = true, ...props }) => ( + + ) return Component } diff --git a/src/client/modules/Companies/CompanyBusinessDetails/CompanyEditHistory/CompanyEditHistory.jsx b/src/client/modules/Companies/CompanyBusinessDetails/CompanyEditHistory/CompanyEditHistory.jsx index 471cc155995..f4be4c74384 100644 --- a/src/client/modules/Companies/CompanyBusinessDetails/CompanyEditHistory/CompanyEditHistory.jsx +++ b/src/client/modules/Companies/CompanyBusinessDetails/CompanyEditHistory/CompanyEditHistory.jsx @@ -51,6 +51,7 @@ const CompanyEditHistory = () => { fieldMapper={mapFieldNameToLabel} excludedFields={EXCLUDED_FIELDS} auditType="business details" + showSort={false} /> ) diff --git a/src/client/modules/Contacts/ContactAuditHistory/ContactAuditHistory.jsx b/src/client/modules/Contacts/ContactAuditHistory/ContactAuditHistory.jsx index e1663dd246a..96b3e75a80f 100644 --- a/src/client/modules/Contacts/ContactAuditHistory/ContactAuditHistory.jsx +++ b/src/client/modules/Contacts/ContactAuditHistory/ContactAuditHistory.jsx @@ -19,6 +19,7 @@ const ContactAuditHistory = () => { fieldMapper={mapFieldNameToLabel} excludedFields={EXCLUDED_FIELDS} auditType="the contact" + showSort={false} /> ) diff --git a/src/client/modules/Investments/EYBLeads/EYBLeadEditHistory/EYBLeadEditHistory.jsx b/src/client/modules/Investments/EYBLeads/EYBLeadEditHistory/EYBLeadEditHistory.jsx index 4513c6f23fb..9a54cd9f86a 100644 --- a/src/client/modules/Investments/EYBLeads/EYBLeadEditHistory/EYBLeadEditHistory.jsx +++ b/src/client/modules/Investments/EYBLeads/EYBLeadEditHistory/EYBLeadEditHistory.jsx @@ -50,6 +50,7 @@ const EYBLeadEditHistory = () => { fieldMapper={mapFieldNameToLabel} excludedFields={EXCLUDED_FIELDS} auditType="eyb details" + showSort={false} /> ) diff --git a/src/client/modules/Investments/EYBLeads/EYBLeadEditHistory/transformers.js b/src/client/modules/Investments/EYBLeads/EYBLeadEditHistory/transformers.js index 0a93b4ba037..85798617155 100644 --- a/src/client/modules/Investments/EYBLeads/EYBLeadEditHistory/transformers.js +++ b/src/client/modules/Investments/EYBLeads/EYBLeadEditHistory/transformers.js @@ -2,7 +2,6 @@ import { isBoolean, isNumber } from 'lodash' import { EYB_LEAD_FIELD_NAME_TO_LABEL_MAP } from './constants' import { NOT_SET, YES, NO } from '../../../../components/AuditHistory/constants' -// import { currencyGBP } from '../../../../utils/number-utils' import { transformFieldName } from '../../../../components/AuditHistory/transformers' import { convertEYBChoicesToLabels, diff --git a/src/client/modules/Investments/Projects/EditHistory/ProjectEditHistory.jsx b/src/client/modules/Investments/Projects/EditHistory/ProjectEditHistory.jsx index 0cd7dd090b9..b2dce7782a7 100644 --- a/src/client/modules/Investments/Projects/EditHistory/ProjectEditHistory.jsx +++ b/src/client/modules/Investments/Projects/EditHistory/ProjectEditHistory.jsx @@ -28,6 +28,7 @@ const ProjectEditHistory = () => { valueTransformer={getValue} fieldMapper={mapFieldNameToLabel} auditType="the project" + showSort={false} /> ) From d9da732aadf37a9394bb8fd36e5ad6c48fd7b2b4 Mon Sep 17 00:00:00 2001 From: Stuart Mindt Date: Wed, 26 Feb 2025 11:43:18 +0000 Subject: [PATCH 3/5] Adding functional tests for EYB edit history --- .../CollectionList/CollectionSort.jsx | 40 ++++---- src/client/components/Resource/Paginated.js | 3 +- .../investments/eyb-lead-edit-history-spec.js | 91 +++++++++++++++++++ .../v4/investment/eyb-lead-audit.json | 84 +++++++++++++++++ .../routes/v4/investment/investment.js | 5 + test/sandbox/server.js | 2 + 6 files changed, 207 insertions(+), 18 deletions(-) create mode 100644 test/functional/cypress/specs/investments/eyb-lead-edit-history-spec.js create mode 100644 test/sandbox/fixtures/v4/investment/eyb-lead-audit.json diff --git a/src/client/components/CollectionList/CollectionSort.jsx b/src/client/components/CollectionList/CollectionSort.jsx index 9e8b5428088..c8560f8cdb5 100644 --- a/src/client/components/CollectionList/CollectionSort.jsx +++ b/src/client/components/CollectionList/CollectionSort.jsx @@ -12,23 +12,29 @@ const StyledSpan = styled('span')` color: ${DARK_GREY}; ` -const CollectionSort = ({ sortOptions, totalPages, ...props }) => { - const actions = sortOptions ? ( - - {sortOptions.map(({ name, value }, i) => { - return ( - - ) - })} - - ) : null +const CollectionSort = ({ + sortOptions, + totalPages, + showSort = true, + ...props +}) => { + const actions = + sortOptions && showSort ? ( + + {sortOptions.map(({ name, value }, i) => { + return ( + + ) + })} + + ) : null const location = useLocation() diff --git a/src/client/components/Resource/Paginated.js b/src/client/components/Resource/Paginated.js index d19cb22b6fa..f9b323a87f7 100644 --- a/src/client/components/Resource/Paginated.js +++ b/src/client/components/Resource/Paginated.js @@ -157,11 +157,12 @@ const PaginatedResource = multiInstance({ addItemUrl={addItemUrl} /> {showSort} - {totalPages > 0 && showSort && ( + {totalPages > 0 && ( )} {result ? children(result.results) : null} diff --git a/test/functional/cypress/specs/investments/eyb-lead-edit-history-spec.js b/test/functional/cypress/specs/investments/eyb-lead-edit-history-spec.js new file mode 100644 index 00000000000..27b78a59951 --- /dev/null +++ b/test/functional/cypress/specs/investments/eyb-lead-edit-history-spec.js @@ -0,0 +1,91 @@ +import { assertLocalHeader, assertBreadcrumbs } from '../../support/assertions' +import { assertBadge } from '../../support/collection-list-assertions' +import { eybLeadFaker } from '../../fakers/eyb-leads' +import urls from '../../../../../src/lib/urls' + +const setup = (eybLead) => { + cy.intercept('GET', `/api-proxy/v4/investment-lead/eyb/${eybLead.id}`, { + statusCode: 200, + body: eybLead, + }).as('getEYBLeadDetails') + cy.intercept('GET', `/api-proxy/v4/investment-lead/eyb/${eybLead.id}/audit`, { + statusCode: 200, + }).as('getEYBLeadEditHistory') +} + +const assertChanges = (itemNo, field, oldVal, newVal) => { + it(`should display the changes to "${field}"`, () => { + cy.get(`@listItem${itemNo}`) + .should('contain', field) + .and('contain', oldVal) + .and('contain', newVal) + }) +} + +describe('Edit History', () => { + const eybLeadWithValues = eybLeadFaker({ + company: { + name: 'Mars', + id: 'fc752802-e454-4c7c-bbfd-4bdd84759b84', + }, + }) + + beforeEach(() => { + setup(eybLeadWithValues) + cy.visit(urls.investments.eybLeads.editHistory.index(eybLeadWithValues.id)) + cy.get('[data-test="collection-item"]').as('collectionItems') + cy.get('@collectionItems').eq(0).as('listItem1') + cy.get('@collectionItems').eq(1).as('listItem2') + cy.get('@collectionItems').eq(2).as('listItem3') + cy.get('@collectionItems').eq(3).as('listItem4') + }) + + context('when viewing the "Edit History" page', () => { + it('should render the header', () => { + assertLocalHeader('Edit history') + }) + + it('should render breadcrumbs', () => { + assertBreadcrumbs({ + Home: urls.dashboard.index(), + Investments: urls.investments.index(), + 'EYB leads': urls.investments.eybLeads.index(), + Mars: urls.investments.eybLeads.details(eybLeadWithValues.id), + 'Edit history': null, + }) + }) + + it('should render the collection header', () => { + cy.get('[data-test="collection-header-name"]') + .should('exist') + .should('contain', '4 Changes to EYB lead details') + }) + + it('should render the correct badges', () => { + assertBadge('@listItem1', '1 change') + assertBadge('@listItem3', '1 change') + }) + }) + + context('when viewing the changes the correct values should be shown', () => { + assertChanges(1, 'Value', 'Low', 'High') + assertChanges( + 2, + 'Where do you want to set up in the UK?', + 'Cardiff', + 'Swansea' + ) + assertChanges( + 3, + 'How do you plan to expand your business in the UK?', + 'Research develop and collaborate', + 'Set up a new distribution centre' + ) + assertChanges( + 4, + 'How many people do you want to hire in the UK in the first 3 years?', + 'No plans to hire yet', + '6-10' + ) + }) +}) diff --git a/test/sandbox/fixtures/v4/investment/eyb-lead-audit.json b/test/sandbox/fixtures/v4/investment/eyb-lead-audit.json new file mode 100644 index 00000000000..1bad27214ff --- /dev/null +++ b/test/sandbox/fixtures/v4/investment/eyb-lead-audit.json @@ -0,0 +1,84 @@ +{ + "count": 4, + "next": null, + "previous": null, + "results": [ + { + "id": 761, + "user": { + "id": "64741bc5-b851-44ec-a565-75ec2e1a43cb", + "first_name": "", + "last_name": "", + "name": "", + "email": "test@gov.uk" + }, + "timestamp": "2025-02-27T13:10:19.466999Z", + "comment": "Changed Is high value.", + "changes": { + "is_high_value": [ + false, + true + ] + } + }, + { + "id": 759, + "user": { + "id": "64741bc5-b851-44ec-a565-75ec2e1a43cb", + "first_name": "", + "last_name": "", + "name": "", + "email": "test@gov.uk" + }, + "timestamp": "2025-02-26T13:09:05.063004Z", + "comment": "Changed Proposed investment city.", + "changes": { + "proposed_investment_city": [ + "CARDIFF", + "SWANSEA" + ] + } + }, + { + "id": 761, + "user": { + "id": "64741bc5-b851-44ec-a565-75ec2e1a43cb", + "first_name": "", + "last_name": "", + "name": "", + "email": "test@gov.uk" + }, + "timestamp": "2025-02-25T13:10:19.466999Z", + "comment": "Changed Intent.", + "changes": { + "intent": [ + [ + "RESEARCH_DEVELOP_AND_COLLABORATE" + ], + [ + "SET_UP_A_NEW_DISTRIBUTION_CENTRE" + ] + ] + } + }, + { + "id": 754, + "user": { + "id": "64741bc5-b851-44ec-a565-75ec2e1a43cb", + "first_name": "", + "last_name": "", + "name": "", + "email": "test@gov.uk" + }, + "timestamp": "2025-02-24T12:50:15.712184Z", + "comment": "Changed Hiring.", + "changes": { + "hiring": [ + "NO_PLANS_TO_HIRE_YET", + "6-10" + ] + } + } + ] + } + \ No newline at end of file diff --git a/test/sandbox/routes/v4/investment/investment.js b/test/sandbox/routes/v4/investment/investment.js index d264d9105ed..60531fc740f 100644 --- a/test/sandbox/routes/v4/investment/investment.js +++ b/test/sandbox/routes/v4/investment/investment.js @@ -3,6 +3,7 @@ import completeLargeCapitalOpportunity from '../../../fixtures/v4/investment/lar import largeCapitalOpportunityList from '../../../fixtures/v4/investment/large-capital-opportunity-list.json' assert { type: 'json' } import largeCapitalOpportunityListOnePage from '../../../fixtures/v4/investment/large-capital-opportunity-list-one-page.json' assert { type: 'json' } import eybLeadList from '../../../fixtures/v4/investment/eyb-lead-list.json' assert { type: 'json' } +import eybLeadEditHistory from '../../../fixtures/v4/investment/eyb-lead-audit.json' assert { type: 'json' } export const getLargeCapitalOpportunity = function (req, res) { if (req.params.opportunityId == completeLargeCapitalOpportunity.id) { @@ -30,3 +31,7 @@ export const getEYBLead = function (req, res) { export const getEYBLeadList = function (req, res) { res.json(eybLeadList) } + +export const getEYBLeadEditHistory = function (req, res) { + res.json(eybLeadEditHistory) +} diff --git a/test/sandbox/server.js b/test/sandbox/server.js index f2734e7cf1f..66631376771 100644 --- a/test/sandbox/server.js +++ b/test/sandbox/server.js @@ -191,6 +191,7 @@ import { getLargeCapitalOpportunityList, getEYBLead, getEYBLeadList, + getEYBLeadEditHistory, } from './routes/v4/investment/investment.js' import { getInteractions as _getInteractions, @@ -874,6 +875,7 @@ app.get('/v4/large-capital-opportunity', getLargeCapitalOpportunityList) app.post('/v4/search/large-capital-opportunity', getLargeCapitalOpportunityList) app.get('/v4/investment-lead/eyb/:eybLeadId', getEYBLead) app.get('/v4/investment-lead/eyb', getEYBLeadList) +app.get('/v4/investment-lead/eyb/:eybLeadId/audit', getEYBLeadEditHistory) // V4 Proposition app.get('/v4/proposition', propositions) From bdd8fe6d110d606712cc42dc740fc0b482753cb1 Mon Sep 17 00:00:00 2001 From: Stuart Mindt Date: Wed, 26 Feb 2025 13:55:55 +0000 Subject: [PATCH 4/5] Improving test coverage --- src/client/components/Resource/Paginated.js | 1 - .../EYBLeadEditHistory/transformers.js | 6 +----- .../fixtures/v4/investment/eyb-lead-audit.json | 18 ++++++++++++++++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/client/components/Resource/Paginated.js b/src/client/components/Resource/Paginated.js index f9b323a87f7..92c79770249 100644 --- a/src/client/components/Resource/Paginated.js +++ b/src/client/components/Resource/Paginated.js @@ -156,7 +156,6 @@ const PaginatedResource = multiInstance({ shouldPluralize={shouldPluralize} addItemUrl={addItemUrl} /> - {showSort} {totalPages > 0 && ( { return getValueFromBoolean(value, field) } - if (isNumber(value)) { - return value.toString() - } - if (field === 'Where do you want to set up in the UK?') { return formatProposedInvestmentCity(value) || NOT_SET } diff --git a/test/sandbox/fixtures/v4/investment/eyb-lead-audit.json b/test/sandbox/fixtures/v4/investment/eyb-lead-audit.json index 1bad27214ff..50169c1699a 100644 --- a/test/sandbox/fixtures/v4/investment/eyb-lead-audit.json +++ b/test/sandbox/fixtures/v4/investment/eyb-lead-audit.json @@ -78,6 +78,24 @@ "6-10" ] } + }, + { + "id": 754, + "user": { + "id": "64741bc5-b851-44ec-a565-75ec2e1a43cb", + "first_name": "", + "last_name": "", + "name": "", + "email": "test@gov.uk" + }, + "timestamp": "2025-02-23T12:50:15.712184Z", + "comment": "Changed Proposed investment location none.", + "changes": { + "proposed_investment_location_none": [ + false, + true + ] + } } ] } From a4998b554f82a1d1e0053fdc53f4703d5a203063 Mon Sep 17 00:00:00 2001 From: Stuart Mindt Date: Wed, 26 Feb 2025 18:27:34 +0000 Subject: [PATCH 5/5] Improving transformer and removing data url accidentally added --- .../modules/Investments/EYBLeads/EYBLeadDetails.jsx | 6 +----- .../EYBLeads/EYBLeadEditHistory/transformers.js | 13 +++++-------- src/lib/urls.js | 5 +---- .../specs/investments/eyb-lead-edit-history-spec.js | 2 +- 4 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/client/modules/Investments/EYBLeads/EYBLeadDetails.jsx b/src/client/modules/Investments/EYBLeads/EYBLeadDetails.jsx index b7f8b559b0e..fb0345c6f8a 100644 --- a/src/client/modules/Investments/EYBLeads/EYBLeadDetails.jsx +++ b/src/client/modules/Investments/EYBLeads/EYBLeadDetails.jsx @@ -33,11 +33,7 @@ const EYBLeadDetails = () => {
      Changes made to this information can be found on the{' '} - + Edit history page . diff --git a/src/client/modules/Investments/EYBLeads/EYBLeadEditHistory/transformers.js b/src/client/modules/Investments/EYBLeads/EYBLeadEditHistory/transformers.js index e2b9dc1881f..509271835f3 100644 --- a/src/client/modules/Investments/EYBLeads/EYBLeadEditHistory/transformers.js +++ b/src/client/modules/Investments/EYBLeads/EYBLeadEditHistory/transformers.js @@ -12,7 +12,7 @@ export const mapFieldNameToLabel = (fieldName) => EYB_LEAD_FIELD_NAME_TO_LABEL_MAP[fieldName] || transformFieldName(fieldName) const getValueFromBoolean = (value, field) => { - if (field === 'Value') { + if (field === EYB_LEAD_FIELD_NAME_TO_LABEL_MAP.is_high_value) { return value ? 'High' : 'Low' } return value ? YES : NO @@ -23,21 +23,18 @@ export const getValue = (value, field) => { return getValueFromBoolean(value, field) } - if (field === 'Where do you want to set up in the UK?') { + if (field === EYB_LEAD_FIELD_NAME_TO_LABEL_MAP.proposed_investment_city) { return formatProposedInvestmentCity(value) || NOT_SET } if ( - field === 'How do you plan to expand your business in the UK?' || - field === 'When do you want to set up?' + field === EYB_LEAD_FIELD_NAME_TO_LABEL_MAP.intent || + field === EYB_LEAD_FIELD_NAME_TO_LABEL_MAP.landing_timeframe ) { return convertEYBChoicesToLabels(value) || NOT_SET } - if ( - field === - 'How many people do you want to hire in the UK in the first 3 years?' - ) { + if (field === EYB_LEAD_FIELD_NAME_TO_LABEL_MAP.hiring) { if (value === 'NO_PLANS_TO_HIRE_YET') { return convertEYBChoicesToLabels(value) } diff --git a/src/lib/urls.js b/src/lib/urls.js index 3f953a717aa..a730b79add0 100644 --- a/src/lib/urls.js +++ b/src/lib/urls.js @@ -533,10 +533,7 @@ module.exports = { eybLeads: { index: url('/investments', '/eyb-leads'), details: url('/investments', '/eyb-leads/:eybLeadId/details'), - editHistory: { - index: url('/investments/eyb-leads', '/:eybLeadId/edit-history'), - data: url('/investments/eyb-leads', '/:eybLeadId/edit-history/data'), - }, + editHistory: url('/investments/eyb-leads', '/:eybLeadId/edit-history'), }, }, metadata: { diff --git a/test/functional/cypress/specs/investments/eyb-lead-edit-history-spec.js b/test/functional/cypress/specs/investments/eyb-lead-edit-history-spec.js index 27b78a59951..a3a287c4520 100644 --- a/test/functional/cypress/specs/investments/eyb-lead-edit-history-spec.js +++ b/test/functional/cypress/specs/investments/eyb-lead-edit-history-spec.js @@ -32,7 +32,7 @@ describe('Edit History', () => { beforeEach(() => { setup(eybLeadWithValues) - cy.visit(urls.investments.eybLeads.editHistory.index(eybLeadWithValues.id)) + cy.visit(urls.investments.eybLeads.editHistory(eybLeadWithValues.id)) cy.get('[data-test="collection-item"]').as('collectionItems') cy.get('@collectionItems').eq(0).as('listItem1') cy.get('@collectionItems').eq(1).as('listItem2')