From 68fc7bbee3af5ddf2f963a0d16f5ad5ef35e58a6 Mon Sep 17 00:00:00 2001 From: Chris Hopkins Date: Thu, 31 Oct 2024 11:07:12 +0000 Subject: [PATCH] Add component for rendering consent details --- .../ContactDetails/ConsentDetails.jsx | 53 +++++++++++++++ .../ContactDetails/ContactDetails.jsx | 3 + .../specs/Contacts/ConsentDetails.cy.jsx | 66 +++++++++++++++++++ 3 files changed, 122 insertions(+) create mode 100644 src/client/modules/Contacts/ContactDetails/ConsentDetails.jsx create mode 100644 test/component/cypress/specs/Contacts/ConsentDetails.cy.jsx diff --git a/src/client/modules/Contacts/ContactDetails/ConsentDetails.jsx b/src/client/modules/Contacts/ContactDetails/ConsentDetails.jsx new file mode 100644 index 00000000000..e24d183ea5a --- /dev/null +++ b/src/client/modules/Contacts/ContactDetails/ConsentDetails.jsx @@ -0,0 +1,53 @@ +import React from 'react' + +import Table from '@govuk-react/table' + +import { SummaryTable } from '../../../components' + +const getConsentRows = (consentData) => { + const domainGroupedConsent = Object.groupBy( + consentData, + ({ consentDomain }) => consentDomain + ) + const domainRows = Object.entries(domainGroupedConsent).map((domain) => { + { + const domainTitle = domain[0] + const domainTopics = domain[1] + return domainTopics.map((topic, index) => ( + + {index == 0 && {domainTitle}} + {topic.topic} + + {topic.emailContactConsent || topic.telephoneContactConsent + ? 'Yes' + : 'No'} + + + )) + } + }) + + return ( + <> + + Domain + Topic + Consent Given + + {domainRows} + + ) +} + +const ConsentDetails = ({ contact }) => ( + + {contact.consentData ? ( + getConsentRows(contact.consentData) + ) : ( + + No consent data is available for this contact + + )} + +) +export default ConsentDetails diff --git a/src/client/modules/Contacts/ContactDetails/ContactDetails.jsx b/src/client/modules/Contacts/ContactDetails/ContactDetails.jsx index 3206096e065..1b6e7c61b3a 100644 --- a/src/client/modules/Contacts/ContactDetails/ContactDetails.jsx +++ b/src/client/modules/Contacts/ContactDetails/ContactDetails.jsx @@ -16,6 +16,7 @@ import { import { ID, TASK_ARCHIVE_CONTACT } from './state' import ArchiveForm from '../../../components/ArchiveForm' import ContactLayout from '../../../components/Layout/ContactLayout' +import ConsentDetails from './ConsentDetails' const getAddress = (contact, companyAddress) => { const address = contact.addressSameAsCompany @@ -103,6 +104,8 @@ const ContactDetails = ({ contactId, companyAddress, permissions }) => ( ) : null} + + { + context('When contact has no consent data', () => { + beforeEach(() => { + cy.mount() + }) + + it('should render a message that this data is missing for this contact', () => { + cy.get('[data-test=no-contact-consents]').should('exist') + }) + }) + + context('When contact has consent data with multiple domains', () => { + beforeEach(() => { + cy.mount( + + ) + }) + + it('should render a row for each domain', () => { + assertGovReactTable({ + element: '[data-test="contact-consent-table"]', + rows: [ + ['Domain', 'Topic', 'Consent Given'], + ['Domain 1', 'Topic 2', 'No'], + ['Domain 2', 'Topic 2', 'Yes'], + ['Domain 3', 'Topic 1', 'Yes'], + ['Domain 4', 'Topic 3', 'Yes'], + ], + }) + }) + }) +})