Skip to content

Commit

Permalink
Merge pull request #2276 from ministryofjustice/bugfix/APS-1778-esap-…
Browse files Browse the repository at this point in the history
…infinite-loop

Prevent infinite loop for ineligible application
froddd authored Jan 8, 2025
2 parents a9a7191 + b46148d commit a709cf2
Showing 5 changed files with 42 additions and 40 deletions.
2 changes: 1 addition & 1 deletion integration_tests/helpers/apply.ts
Original file line number Diff line number Diff line change
@@ -678,7 +678,7 @@ export default class ApplyHelper {
const notEligiblePage = Page.verifyOnPage(ApplyPages.EsapNotEligible, this.application)

// When I click the continue button
notEligiblePage.clickSubmit()
notEligiblePage.clickContinueWithApplication()

// Then I should be able to choose a different type of AP
Page.verifyOnPage(ApplyPages.ApType, this.application)
4 changes: 4 additions & 0 deletions integration_tests/pages/apply/esapNotEligible.ts
Original file line number Diff line number Diff line change
@@ -4,4 +4,8 @@ export default class EsapNotEligible extends Page {
constructor() {
super(`The person is not eligible for an Enhanced Security Approved Premises (ESAP) placement.`)
}

clickContinueWithApplication() {
cy.get('a[role="button"]').contains('Continue with application').click()
}
}
Original file line number Diff line number Diff line change
@@ -16,11 +16,13 @@ describe('EsapNotEligible', () => {

itShouldHavePreviousValue(page, 'esap-exceptional-case')

itShouldHaveNextValue(page, 'ap-type')
itShouldHaveNextValue(page, '')

describe('errors', () => {
it('should return an empty object', () => {
expect(page.errors()).toEqual({})
it('should return an object with an error to prevent continuing with the application', () => {
expect(page.errors()).toEqual({
esapNotEligible: 'The person is not eligible for an Enhanced Security Approved Premises (ESAP) placement.',
})
})
})

Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { ApprovedPremisesApplication as Application } from '@approved-premises/api'
import type { TaskListErrors } from '@approved-premises/ui'
import { Page } from '../../../utils/decorators'

import TasklistPage from '../../../tasklistPage'

@Page({ name: 'not-esap-eligible', bodyProperties: [] })
@Page({ name: 'not-esap-eligible', bodyProperties: ['esapNotEligible'] })
export default class EsapNotEligible implements TasklistPage {
title = `The person is not eligible for an Enhanced Security Approved Premises (ESAP) placement.`

constructor(
readonly body: Record<string, never>,
readonly body: Partial<{
esapNotEligible: never
}>,
readonly application: Application,
) {}

@@ -21,10 +24,14 @@ export default class EsapNotEligible implements TasklistPage {
}

next() {
return 'ap-type'
return ''
}

errors() {
return {}
const errors: TaskListErrors<this> = {}

errors.esapNotEligible = this.title

return errors
}
}
53 changes: 21 additions & 32 deletions server/views/applications/pages/type-of-ap/not-esap-eligible.njk
Original file line number Diff line number Diff line change
@@ -7,42 +7,31 @@
{% set mainClasses = "app-container govuk-body" %}

{% block beforeContent %}
{{ govukBackLink({
text: "Back",
href: paths.applications.pages.show({ id: applicationId, task: task, page: page.previous() })
{{ govukBackLink({
text: "Back",
href: paths.applications.pages.show({ id: applicationId, task: task, page: page.previous() })
}) }}
{% endblock %}

{% block content %}
<div class="govuk-grid-row">
<div class="{{ columnClasses | default("govuk-grid-column-two-thirds") }}">
<form action="{{ paths.applications.pages.update({ id: applicationId, task: task, page: page.name }) }}?_method=PUT" method="post">
<input type="hidden" name="_csrf" value="{{ csrfToken }}"/>

<h1 class="govuk-heading-l">{{ page.title }}</h1>

<p>From the information you've provided this person is not eligible for an ESAP placement.</p>

<p>You can continue with an application for a standard Approved Premises placement. Or you can return to the dashboard to withdraw your application.</p>

<div class="govuk-button-group">
{{
govukButton({
text: "Continue with application",
preventDoubleClick: true
})
}}
{{
linkTo(
paths.applications.index,
{},
{
text: 'Back to dashboard'
}
) | safe
}}
<div class="govuk-grid-row">
<div class="{{ columnClasses | default("govuk-grid-column-two-thirds") }}">

<h1 class="govuk-heading-l">{{ page.title }}</h1>

<p>From the information you've provided this person is not eligible for an ESAP placement.</p>

<p>You can continue with an application for a standard Approved Premises placement. Or you can return to the
dashboard to withdraw your application.</p>

<div class="govuk-button-group">
{{ govukButton({
text: "Continue with application",
href: paths.applications.pages.show({ id: applicationId, task: task, page: 'ap-type' })
}) }}

<a href="{{ paths.applications.index() }}">Back to dashboard</a>
</div>
</div>
</form>
</div>
</div>
{% endblock %}

0 comments on commit a709cf2

Please sign in to comment.