Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Commit

Permalink
Add summary resources merged with master (#15)
Browse files Browse the repository at this point in the history
* Allow resources to be added to snapshot summary page

* Amend so checkboxes are used instead of buttons

* Add chai

* revert test

* Allow resources to be added to snapshot summary page

* Remove select resource from resource finder

* amend tests assertion

Co-authored-by: Maysa <maysa@madetech.com>
Co-authored-by: Riccardo Noviello <riccardo.noviello@gmail.com>
  • Loading branch information
3 people authored Aug 21, 2020
1 parent 0697af6 commit dca0e79
Show file tree
Hide file tree
Showing 7 changed files with 1,786 additions and 2,656 deletions.
32 changes: 29 additions & 3 deletions components/Feature/VulnerabilitiesGrid/ResourceCard/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import css from './index.module.scss';
import SummaryList from 'components/Form/SummaryList';
import { useState } from 'react';

const HIDDEN_TAGS = ['Delivery', 'Collection', 'Food']

const ResourceCard = ({
id,
updateSelectedResources,
name,
description,
websites,
Expand All @@ -19,6 +22,7 @@ const ResourceCard = ({
notes,
distance,
matches,
customerId,
...others
}) => {
const trimLength = (s, length) => s.length > length ? s.substring(0, length) + "..." : s
Expand All @@ -27,7 +31,21 @@ const ResourceCard = ({
const websiteElement = websites && websites.length > 0 && websites.map(website => (<a href={websites[0]} target="_blank" rel="noopener noreferrer">{websites[0]}</a>))
const distributionElement = tags.filter(t => HIDDEN_TAGS.includes(t)).join(", ")
const tagsElement = tags.filter(t => !HIDDEN_TAGS.includes(t)).map(item=> (<span key={"tags-"+item} className={css.tags}>{trimLength(item, 20)}</span>))

const snapshot = (customerId != undefined) ? true : false
const updateResource = () =>{
updateSelectedResources({
name:name,
description: description,
address:address,
telephone: telephone,
email:email,
referralContact: referralContact,
selfReferral: selfReferral,
openingTimes: openingTimes,
websites:websites,
notes:notes
})
}

return (
<div className={`resource ${css.resource}`} {...others}>
Expand All @@ -42,11 +60,19 @@ const ResourceCard = ({
</>

<details className="govuk-details" data-module="govuk-details">
<summary className="">View more information</summary>
<summary id ={`summary-${id}`} className="">View more information</summary>

<SummaryList key="moreResourceInfo" name={'moreResourceInfo'} entries={{ 'How to contact': selfReferralElement,
'Address': address, 'Description' : description, 'Website' : websiteElement, 'Additional notes' : notes }} customStyle="small" />

{ snapshot &&
(
<div className="govuk-checkboxes__item">
<input className="govuk-checkboxes__input" id={`input-${id}`} onClick={() => updateResource()} type="checkbox" value={name}/>
<label className="govuk-label govuk-checkboxes__label" id={`label-${id}`}>
Would you like to recommend this resource?
</label>
</div>)
}
</details>
</div>
);
Expand Down
7 changes: 6 additions & 1 deletion components/Feature/VulnerabilitiesGrid/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function createLookup() {
return lookup;
}

const VulnerabilitiesGrid = ({ resources, onUpdate, residentCoordinates, genericPostcode, onError }) => {
const VulnerabilitiesGrid = ({ resources, onUpdate, residentCoordinates, genericPostcode, onError , updateSelectedResources, customerId}) => {

const [grid, setGrid] = useState({
assets: {},
Expand All @@ -43,6 +43,9 @@ const VulnerabilitiesGrid = ({ resources, onUpdate, residentCoordinates, generic
const [expandedGroups, setExpandedGroups] = useState({});
const [residentData, setResidentData] = useState(null);

const updateSummaryResource = resourceName => {
updateSelectedResources(resourceName)
}
const updateResidentData = (result) => {
if(result){
setResidentData(result);
Expand Down Expand Up @@ -319,6 +322,8 @@ const VulnerabilitiesGrid = ({ resources, onUpdate, residentCoordinates, generic
key={resource.id}
data-testid={`resource-${resource.id}`}
{...resource}
updateSelectedResources = {updateSummaryResource}
customerId={customerId}
/>
);
})}
Expand Down
33 changes: 33 additions & 0 deletions cypress/integration/features/editSnapshot.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,39 @@ context('Edit snapshot', () => {
cy.task('deleteSnapshot', '1');
});


it("Adds resources to the summary list", () => {
cy.visit(`/snapshots/1`);
cy.get('[data-testid=accordion-item]').eq(0).click();
cy.get('[data-testid=food-needs-v-halal-checkbox]').click();

cy.get('[data-testid=resource-rec2FkHGEn9BiiXvW] > h3').eq(0)
.should('contain', 'Made Up Kitchen')
cy.get('#summary-recisR36NAVBna3N4').click()
cy.get('#input-recisR36NAVBna3N4').check()
cy.get('[data-testid=finish-and-save-button]').click();

cy.get('[data-testid=resources-summary]')
.should('contain', 'Resources')
.and('contain', 'Shirdi Sai Baba Temple');
})

it("Adds and removes resources to the summary list", () => {
cy.visit(`/snapshots/1`);
cy.get('[data-testid=accordion-item]').eq(0).click();
cy.get('[data-testid=food-needs-v-halal-checkbox]').click();

cy.get('[data-testid=resource-rec2FkHGEn9BiiXvW] > h3').eq(0)
.should('contain', 'Made Up Kitchen')
cy.get('#summary-recisR36NAVBna3N4').click()
cy.get('#input-recisR36NAVBna3N4').check()
cy.get('[data-testid=finish-and-save-button]').click();

cy.get('[data-testid=resources-summary]')
.should('contain', 'Resources')
.and('contain', 'Shirdi Sai Baba Temple');
})

describe('Edit snapshot', () => {
it('Displays editable snapshot if there are no assets, vulnerabilites and notes added', () => {
cy.visit(`/snapshots/1`);
Expand Down
108 changes: 47 additions & 61 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"babel-core": "^6.26.3",
"babel-eslint": "^10.1.0",
"babel-jest": "^25.5.1",
"chai": "^4.2.0",
"cypress": "^4.5.0",
"cypress-axe": "^0.8.1",
"dynamodb-admin": "^4.0.0",
Expand Down
Loading

0 comments on commit dca0e79

Please sign in to comment.