Skip to content

Commit

Permalink
Map 1960: Adding change used for link on a cell level (#219)
Browse files Browse the repository at this point in the history
* MAP-1960: Adding change used for link on a cell level

* update README.md
  • Loading branch information
ashleygyngell authored Dec 11, 2024
1 parent 4dcccba commit a2054cc
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ so that assets are rebuilt when modified and tests will re-run:

```shell
docker compose -f docker-compose-test.yml up
npm run start-feature:dev
npm run start-feature
npm run int-test-ui
```

Expand Down
45 changes: 33 additions & 12 deletions integration_tests/e2e/changeUsedFor/index.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,7 @@ context('Set cell type', () => {
})

const itBehavesLikeChangeUsedForPage = () => {
it('does not show the change used for link on a cell level', () => {
cy.task('stubLocationsLocationsResidentialSummaryForLocation', { parentLocation: locationAsCell })
cy.task('stubLocations', locationAsCell)
ViewLocationsShowPage.goTo(locationAsCell.prisonId, locationAsCell.id)
const viewLocationsShowPage = Page.verifyOnPage(ViewLocationsShowPage)
viewLocationsShowPage.changeCellUsedForLink().should('not.exist')
})

it('does show the change used for link on a parent level and can be accessed', () => {
it('shows the change used for link on all levels and can be accessed', () => {
ViewLocationsShowPage.goTo(locationAsWing.prisonId, locationAsWing.id)
const viewLocationsShowPage = Page.verifyOnPage(ViewLocationsShowPage)
viewLocationsShowPage.changeCellUsedForLink().click()
Expand All @@ -82,7 +74,7 @@ context('Set cell type', () => {
Page.verifyOnPage(ViewLocationsShowPage)
})

it('displays a warning about applying change', () => {
it('displays a warning on parent levels about applying change', () => {
ChangeUsedForPage.goTo(locationAsWing.id)
const changeUsedForPage = Page.verifyOnPage(ChangeUsedForPage)
changeUsedForPage
Expand All @@ -93,7 +85,14 @@ context('Set cell type', () => {
)
})

it('shows the correct unchecked checkbox list', () => {
it('does not display a warning on a cell level about applying change', () => {
cy.task('stubLocations', locationAsCell)
ChangeUsedForPage.goTo(locationAsCell.id)
const changeUsedForPage = Page.verifyOnPage(ChangeUsedForPage)
changeUsedForPage.usedForWarningText().should('not.exist')
})

it('does show an unchecked checkbox list on a parent level when multiple are checked', () => {
ViewLocationsShowPage.goTo(locationAsWing.prisonId, locationAsWing.id)
const viewLocationsShowPage = Page.verifyOnPage(ViewLocationsShowPage)
viewLocationsShowPage.changeCellUsedForLink().click()
Expand All @@ -113,7 +112,29 @@ context('Set cell type', () => {
})
})

it('shows the correct checked checkbox list', () => {
it('does show a checked checkbox list on a cell level when multiple are checked', () => {
cy.task('stubLocations', locationAsCell)
ViewLocationsShowPage.goTo(locationAsWing.prisonId, locationAsCell.id)
const viewLocationsShowPage = Page.verifyOnPage(ViewLocationsShowPage)
viewLocationsShowPage.changeCellUsedForLink().click()
ChangeUsedForPage.goTo(locationAsWing.id)
const changeUsedForPage = Page.verifyOnPage(ChangeUsedForPage)

const expectedLabels = [
'Close Supervision Centre (CSC)',
'Drug recovery / Incentivised substance free living (ISFL)',
'First night centre / Induction',
'Test type',
'Standard accommodation',
]
expectedLabels.forEach((label, index) => {
changeUsedForPage.cellTypeCheckboxLabels().eq(index).contains(label)
})
changeUsedForPage.cellTypeCheckboxLabels().eq(3).prev('input[type="checkbox"]').should('be.checked')
changeUsedForPage.cellTypeCheckboxLabels().eq(4).prev('input[type="checkbox"]').should('be.checked')
})

it('shows the correct checked checkbox list when one option is checked', () => {
const updatedLocation = LocationFactory.build({ usedFor: ['TEST_TYPE'] })
cy.task('stubLocations', updatedLocation)

Expand Down
1 change: 1 addition & 0 deletions server/controllers/changeUsedFor/details.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ describe('ChangeUsedForDetails', () => {
],
},
},
leafLevel: false,
validationErrors: [],
})
})
Expand Down
6 changes: 3 additions & 3 deletions server/controllers/changeUsedFor/details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ export default class ChangeUsedForDetails extends FormInitialStep {
locals(req: FormWizard.Request, res: Response): Record<string, any> {
const locals = super.locals(req, res)
const { location } = res.locals
const { id: locationId, prisonId } = location
const { id: locationId, prisonId, leafLevel } = location

const fields = { ...locals.fields }

if (!req.form.values?.usedFor) {
if (location.usedFor.length === 1) {
if (leafLevel || location.usedFor.length === 1) {
fields.usedFor.items = fields.usedFor.items.map((item: FormWizard.Field) => ({
...item,
checked: location.raw.usedFor.includes(item.value),
Expand All @@ -43,6 +42,7 @@ export default class ChangeUsedForDetails extends FormInitialStep {

return {
...locals,
leafLevel,
backLink,
cancelLink: `/view-and-update-locations/${prisonId}/${locationId}`,
}
Expand Down
2 changes: 1 addition & 1 deletion server/middleware/populateResidentialSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function showEditCellTypeLinks(location: DecoratedLocation, req: Request) {
}

function showChangeUsedForLink(location: DecoratedLocation, req: Request) {
return !location.leafLevel && location.active && req.canAccess('change_used_for')
return location.active && req.canAccess('change_used_for')
}

function localNameRow(location: DecoratedLocation, req: Request): SummaryListRow {
Expand Down
5 changes: 3 additions & 2 deletions server/views/pages/changeUsedFor/details.njk
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
{% from "govuk/components/warning-text/macro.njk" import govukWarningText %}

{% set title = "Change what the location is used for" %}
{% set locationName = location.displayName | capFirst %}
{% set locationName = location.displayName | capFirst %}
{% set leafLevel = location.leafLevel %}

{% block beforeContent %}
<div class="govuk-width-container">
Expand Down Expand Up @@ -38,7 +39,7 @@
{{ govukWarningText({
text: 'This change will apply to all normal accommodation locations in ' + locationName + '.',
iconFallbackText: "Warning"
}) }}
}) if not leafLevel }}
</div>
</div>
{% endblock %}
Expand Down

0 comments on commit a2054cc

Please sign in to comment.