-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add component for rendering consent details
- Loading branch information
1 parent
2126dfa
commit 09edb1f
Showing
9 changed files
with
295 additions
and
79 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/client/modules/Contacts/ContactDetails/ConsentDetails.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from 'react' | ||
import { isNil } from 'lodash' | ||
|
||
import { SectionHeader } from '../../../components' | ||
import { transformContactConsents } from './transformers' | ||
|
||
const ConsentDetails = ({ contact }) => { | ||
const consentGiven = transformContactConsents(contact) | ||
return ( | ||
<div> | ||
<SectionHeader type="contact-consent">Contact consents</SectionHeader> | ||
{isNil(contact.consentData) ? ( | ||
<p data-test="no-contact-consents"> | ||
There is no consent data available for this contact | ||
</p> | ||
) : ( | ||
<p> | ||
{`This contact has ${consentGiven ? 'given' : 'not given'} consent to be contacted.`} | ||
</p> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
export default ConsentDetails |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/client/modules/Contacts/ContactDetails/__test__/transformers.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import 'core-js/proposals/array-grouping-v2' | ||
import { transformContactConsents } from '../transformers' | ||
|
||
describe('transformContactConsents', () => { | ||
context('When a falsey contact is passed', () => { | ||
it('Should return false', () => { | ||
expect(transformContactConsents(undefined)).to.equal(false) | ||
}) | ||
}) | ||
|
||
context('When a contact has no consent data', () => { | ||
it('Should return false', () => { | ||
expect(transformContactConsents({})).to.equal(false) | ||
}) | ||
}) | ||
|
||
context( | ||
'When a contact has a single domain and has not given consent', | ||
() => { | ||
it('Should return false', () => { | ||
expect( | ||
transformContactConsents({ | ||
consentData: [ | ||
{ | ||
consentDomain: 'International', | ||
emailContactConsent: false, | ||
}, | ||
], | ||
}) | ||
).to.equal(false) | ||
}) | ||
} | ||
) | ||
|
||
context('When a contact has a single domain and has given consent', () => { | ||
it('Should return true', () => { | ||
expect( | ||
transformContactConsents({ | ||
consentData: [ | ||
{ | ||
consentDomain: 'International', | ||
emailContactConsent: true, | ||
}, | ||
], | ||
}) | ||
).to.equal(true) | ||
}) | ||
}) | ||
|
||
context( | ||
'When a contact has a multiple domains and has given consent to one', | ||
() => { | ||
it('Should return true', () => { | ||
expect( | ||
transformContactConsents({ | ||
consentData: [ | ||
{ | ||
consentDomain: 'International', | ||
emailContactConsent: true, | ||
}, | ||
{ | ||
consentDomain: 'International', | ||
emailContactConsent: false, | ||
}, | ||
], | ||
}) | ||
).to.equal(true) | ||
}) | ||
} | ||
) | ||
|
||
context( | ||
'When a contact has a multiple domains and has given consent to all', | ||
() => { | ||
it('Should return true', () => { | ||
expect( | ||
transformContactConsents({ | ||
consentData: [ | ||
{ | ||
consentDomain: 'International', | ||
emailContactConsent: true, | ||
}, | ||
{ | ||
consentDomain: 'International', | ||
emailContactConsent: true, | ||
}, | ||
], | ||
}) | ||
).to.equal(true) | ||
}) | ||
} | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const transformContactConsents = (contact) => { | ||
if (!contact || !contact.consentData) { | ||
return false | ||
} | ||
|
||
return contact.consentData.some((consent) => consent.emailContactConsent) | ||
} |
66 changes: 66 additions & 0 deletions
66
test/component/cypress/specs/Contacts/ConsentDetails.cy.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React from 'react' | ||
|
||
import ConsentDetails from '../../../../../src/client/modules/Contacts/ContactDetails/ConsentDetails' | ||
|
||
describe('ConsentDetails', () => { | ||
context('When contact has no consent data', () => { | ||
beforeEach(() => { | ||
cy.mount(<ConsentDetails contact={{}} />) | ||
}) | ||
|
||
it('should render a message that this data is missing for this contact', () => { | ||
cy.get('p').should( | ||
'have.text', | ||
'There is no consent data available for this contact' | ||
) | ||
}) | ||
}) | ||
|
||
context('When a contact has consented', () => { | ||
beforeEach(() => { | ||
cy.mount( | ||
<ConsentDetails | ||
contact={{ | ||
consentData: [ | ||
{ | ||
consentDomain: 'Domain 1', | ||
emailContactConsent: true, | ||
}, | ||
], | ||
}} | ||
/> | ||
) | ||
}) | ||
|
||
it('should render the expected message', () => { | ||
cy.get('p').should( | ||
'have.text', | ||
'This contact has given consent to be contacted.' | ||
) | ||
}) | ||
}) | ||
|
||
context('When a contact has not consented', () => { | ||
beforeEach(() => { | ||
cy.mount( | ||
<ConsentDetails | ||
contact={{ | ||
consentData: [ | ||
{ | ||
consentDomain: 'Domain 1', | ||
emailContactConsent: false, | ||
}, | ||
], | ||
}} | ||
/> | ||
) | ||
}) | ||
|
||
it('should render the expected message', () => { | ||
cy.get('p').should( | ||
'have.text', | ||
'This contact has not given consent to be contacted.' | ||
) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,50 @@ | ||
{ | ||
"id":"f3d19ea7-d4cf-43e0-8e97-755c57cae313", | ||
"title":null, | ||
"first_name":"Joseph", | ||
"last_name":"Woof", | ||
"name":"Joseph Woof", | ||
"job_title":"Dog master", | ||
"company":{ | ||
"name":"Zboncak Group|271eb29e-425b-4cd8-b386-3208c3a5f978", | ||
"id":"4cd4128b-1bad-4f1e-9146-5d4678c6a018" | ||
"id": "f3d19ea7-d4cf-43e0-8e97-755c57cae313", | ||
"title": null, | ||
"first_name": "Joseph", | ||
"last_name": "Woof", | ||
"name": "Joseph Woof", | ||
"job_title": "Dog master", | ||
"company": { | ||
"name": "Zboncak Group|271eb29e-425b-4cd8-b386-3208c3a5f978", | ||
"id": "4cd4128b-1bad-4f1e-9146-5d4678c6a018" | ||
}, | ||
"adviser":{ | ||
"name":"DBT Staff", | ||
"first_name":"DBT", | ||
"last_name":"Staff", | ||
"id":"7d19d407-9aec-4d06-b190-d3f404627f21" | ||
"adviser": { | ||
"name": "DBT Staff", | ||
"first_name": "DBT", | ||
"last_name": "Staff", | ||
"id": "7d19d407-9aec-4d06-b190-d3f404627f21" | ||
}, | ||
"primary":true, | ||
"telephone_countrycode":"", | ||
"telephone_number":"", | ||
"full_telephone_number":"222 3453454", | ||
"email":"[email protected]", | ||
"address_same_as_company":false, | ||
"primary": true, | ||
"telephone_countrycode": "", | ||
"telephone_number": "", | ||
"full_telephone_number": "222 3453454", | ||
"email": "[email protected]", | ||
"address_same_as_company": false, | ||
"address_1": null, | ||
"address_2":null, | ||
"address_town":null, | ||
"address_county":null, | ||
"address_2": null, | ||
"address_town": null, | ||
"address_county": null, | ||
"address_country": { | ||
"id": "80756b9a-5d95-e211-a939-e4115bead28a" | ||
}, | ||
"address_postcode":"E14 8RJ", | ||
"telephone_alternative":null, | ||
"email_alternative":null, | ||
"notes":null, | ||
"accepts_dit_email_marketing":false, | ||
"archived":false, | ||
"archived_documents_url_path":"/document/123", | ||
"archived_on":null, | ||
"archived_reason":null, | ||
"archived_by":null, | ||
"created_on":"2019-02-04T15:59:14.267412Z", | ||
"modified_on":"2019-02-05T13:17:23.112153Z" | ||
"address_postcode": "E14 8RJ", | ||
"telephone_alternative": null, | ||
"email_alternative": null, | ||
"notes": null, | ||
"accepts_dit_email_marketing": false, | ||
"archived": false, | ||
"archived_documents_url_path": "/document/123", | ||
"archived_on": null, | ||
"archived_reason": null, | ||
"archived_by": null, | ||
"created_on": "2019-02-04T15:59:14.267412Z", | ||
"modified_on": "2019-02-05T13:17:23.112153Z", | ||
"consent_data": [ | ||
{ | ||
"source_system": "System A", | ||
"consent_domain": "Domestic", | ||
"consent": false | ||
} | ||
] | ||
} |
Oops, something went wrong.