Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dc 69 build violence task page #34

Merged
merged 2 commits into from Feb 5, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+278 −14
Diff settings

Always

Just for now

@@ -107,7 +107,3 @@ $path: "/assets/images/"
font-size: 1.4em
strong
padding-left: 70px

.app-buttons-inline
div.govuk-radios__item
display: inline-block
@@ -164,9 +164,3 @@ header.govuk-header {
padding-left: 70px;
}
}

.app-buttons-inline {
div.govuk-radios__item {
display: inline-block;
}
}
@@ -0,0 +1,31 @@
package uk.gov.justice.digital.hmpps.cattool.pages

import geb.Page

class ViolencePage extends Page {

static url = '/form/ratings/violenceRating'

static at = {
headingText == 'Violence rating'
}

static content = {
headingText { $('h1.govuk-heading-l').text() }
headerBlock { $('div.govuk-body-s') }
headerValue { headerBlock.$('p.govuk-\\!-font-weight-bold') }

form {$('form')}
highRiskOfViolenceYes {$('#highRiskOfViolence-1')}
highRiskOfViolenceNo {$('#highRiskOfViolence-2')}
highRiskOfViolenceText {$('#highRiskOfViolenceText')}
seriousThreatYes {$('#seriousThreat-1')}
seriousThreatNo {$('#seriousThreat-2')}
seriousThreatText {$('#seriousThreatText')}

submitButton { $('button', type:'submit') }
backLink { $( 'a.govuk-back-link') }
errorSummaries {$('ul.govuk-error-summary__list li')}
errors {$('span.govuk-error-message')}
}
}
@@ -0,0 +1,99 @@
package uk.gov.justice.digital.hmpps.cattool.specs

import com.github.tomakehurst.wiremock.core.WireMockConfiguration
import com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer
import geb.spock.GebReportingSpec
import org.junit.Rule
import uk.gov.justice.digital.hmpps.cattool.mockapis.Elite2Api
import uk.gov.justice.digital.hmpps.cattool.mockapis.OauthApi
import uk.gov.justice.digital.hmpps.cattool.mockapis.RiskProfilerApi
import uk.gov.justice.digital.hmpps.cattool.model.DatabaseUtils
import uk.gov.justice.digital.hmpps.cattool.model.TestFixture
import uk.gov.justice.digital.hmpps.cattool.pages.CategoriserHomePage
import uk.gov.justice.digital.hmpps.cattool.pages.CategoriserTasklistPage
import uk.gov.justice.digital.hmpps.cattool.pages.ViolencePage

import java.time.LocalDate

import static uk.gov.justice.digital.hmpps.cattool.model.UserAccount.ITAG_USER

class ViolenceSpecification extends GebReportingSpec {

@Rule
Elite2Api elite2api = new Elite2Api()

@Rule
RiskProfilerApi riskProfilerApi = new RiskProfilerApi()

@Rule
OauthApi oauthApi = new OauthApi(new WireMockConfiguration()
.extensions(new ResponseTemplateTransformer(false)))

def setup() {
db.clearDb()
}

TestFixture fixture = new TestFixture(browser, elite2api, oauthApi)
DatabaseUtils db = new DatabaseUtils()

def "The violence page saves details correctly"() {
when: 'I go to the violence page'

elite2api.stubUncategorised()
elite2api.stubSentenceData(['B2345XY', 'B2345YZ'], [11, 12], LocalDate.now().plusDays(-3).toString())
fixture.loginAs(ITAG_USER)
at CategoriserHomePage
elite2api.stubGetOffenderDetails(12)
to ViolencePage, '12'

then: 'The violence page is displayed'
//at(new ViolencePage(bookingId: '12')
at ViolencePage
!highRiskOfViolenceText.displayed
!seriousThreatText.displayed

when: 'Details are entered, saved and accessed'
highRiskOfViolenceYes.click()
highRiskOfViolenceText << "Some risk text"
seriousThreatYes.click()
seriousThreatText << "Some threat text"
submitButton.click()
at CategoriserTasklistPage
to ViolencePage, '12'

then: "data is correctly retrieved"
form.highRiskOfViolence == "Yes"
form.highRiskOfViolenceText == "Some risk text"
form.seriousThreat == "Yes"
form.seriousThreatText == "Some threat text"
}

def 'Validation test'() {
when: 'I submit the page with empty details'
elite2api.stubUncategorised()
elite2api.stubSentenceData(['B2345XY', 'B2345YZ'], [11, 12], LocalDate.now().plusDays(-3).toString())
fixture.loginAs(ITAG_USER)
at CategoriserHomePage
elite2api.stubGetOffenderDetails(12)
to ViolencePage, '12'
submitButton.click()

then: 'I stay on the page with radio button validation errors'
at ViolencePage
errorSummaries*.text() == ['High risk of violence: please select yes or no',
'Serious Threat: Please select yes or no']
errors*.text() == ['Please select yes or no',
'Please select yes or no']

when: 'I click yes but fail to add details'
highRiskOfViolenceYes.click()
seriousThreatYes.click()
submitButton.click()

then: 'I stay on the page with textarea validation errors'
errorSummaries*.text() == ['Please enter high risk of violence details',
'Please enter serious threat details']
errors*.text() == ['Please enter details',
'Please enter details']
}
}
@@ -26,6 +26,33 @@ module.exports = {
validate: true,
},
violenceRating: {
fields: [
{
highRiskOfViolence: {
responseType: 'requiredString',
validationMessage: 'High risk of violence: please select yes or no',
},
},
{
highRiskOfViolenceText: {
responseType: 'requiredStringIf_highRiskOfViolence_Yes',
validationMessage: 'Please enter high risk of violence details',
},
},
{
seriousThreat: {
responseType: 'requiredString',
validationMessage: 'Serious Threat: Please select yes or no',
},
},
{
seriousThreatText: {
responseType: 'requiredStringIf_seriousThreat_Yes',
validationMessage: 'Please enter serious threat details',
},
},
],
validate: true,
nextPath: {
path: '/tasklist/',
},
@@ -120,6 +120,16 @@ module.exports = function Index({
if (body.escapeFurtherCharges === 'No') {
updated.escapeFurtherChargesText = ''
}
if (body.highRiskOfViolence === 'No') {
updated.highRiskOfViolenceText = ''
}
if (body.seriousThreat === 'No') {
updated.seriousThreatText = ''
}
if (body.categoryAppropriate === 'Yes') {
updated.overriddenCategory = ''
updated.overriddenCategoryText = ''
}
return updated
}

@@ -69,7 +69,7 @@ <h1 class="govuk-heading-l">Provisional category</h1>

{{ govukRadios({
name: "categoryAppropriate",
classes: "govuk-radios--inline app-buttons-inline",
classes: "govuk-radios--inline",
fieldset: {
legend: {
text: "Do you think the category is appropriate for this person?",
@@ -1,7 +1,114 @@
{% extends "../formTemplate.html" %}
{% from "warning-text/macro.njk" import govukWarningText %}
{% from "textarea/macro.njk" import govukTextarea %}
{% from "radios/macro.njk" import govukRadios %}

{% set highRiskOfViolenceTextHtml %}
{{ govukTextarea({
name: "highRiskOfViolenceText",
type: "highRiskOfViolenceText",
id: "highRiskOfViolenceText",
label: {
text: "Give details of this evidence"
},
value: data.highRiskOfViolenceText,
errorMessage: {
text: "Please enter details"
} if (errors | findError('highRiskOfViolenceText'))
}) }}
{% endset %}

{% set seriousThreatTextHtml %}
{{ govukTextarea({
name: "seriousThreatText",
type: "seriousThreatText",
id: "seriousThreatText",
label: {
text: "Give details of this evidence"
},
value: data.seriousThreatText,
errorMessage: {
text: "Please enter details"
} if (errors | findError('seriousThreatText'))
}) }}
{% endset %}

{% block formItems %}

<h1 class="govuk-heading-l">Violence rating</h1>

{% if data.violenceProfile.veryHighRiskViolentOffender %}
{{ govukWarningText({
text: "Violent in custody Text TBC",
iconFallbackText: "Warning",
classes: "forms-warning-text warning-overrides"
}) }}
{% endif %}

{{ govukRadios({
name: "highRiskOfViolence",
classes: "govuk-radios--inline",
fieldset: {
legend: {
text: "Is there any other evidence to suggest that the person poses a high risk of violence in custody?",
isPageHeading: false
}
},
errorMessage: {
text: "Please select yes or no"
} if (errors | findError('highRiskOfViolence')),
items: [
{
value: "Yes",
text: "Yes",
checked: data.highRiskOfViolence === 'Yes',
conditional: {
html: highRiskOfViolenceTextHtml
}
},
{
value: "No",
checked: data.highRiskOfViolence === 'No',
text: "No"
}
]
}) }}

{{ govukRadios({
name: "seriousThreat",
classes: "govuk-radios--inline",
fieldset: {
legend: {
text: "Is there any other evidence to indicate that the person represents a serious threat to control, good order or discipline?",
isPageHeading: false
}
},
errorMessage: {
text: "Please select yes or no"
} if (errors | findError('seriousThreat')),
items: [
{
value: "Yes",
text: "Yes",
checked: data.seriousThreat === 'Yes',
conditional: {
html: seriousThreatTextHtml
}
},
{
value: "No",
checked: data.seriousThreat === 'No',
text: "No"
}
]
}) }}

{% endblock %}

{#
coming back from risk profiler:

private boolean veryHighRiskViolentOffender;
private boolean notifySafetyCustodyLead;
private boolean displayAssaults;
#}
@@ -123,7 +123,7 @@ <h1 class="govuk-heading-s">Offender details</h1>
<li>
<ul class="app-task-list__items">
<li class="app-task-list__item">
{% if data.ratings.offendingHistory %}
{% if data.ratings.offendingHistory.previousConvictions %}
<a href="/form/ratings/offendingHistory/{{ data.bookingId }}">Offending history</a>
<strong class="govuk-tag app-task-list__task-completed" id="offendingHistory-completed">Completed</strong>
{% else %}
@@ -139,7 +139,7 @@ <h1 class="govuk-heading-s">Offender details</h1>
{% endif %}
</li>
<li class="app-task-list__item">
{% if data.ratings.securityInput %}
{% if data.ratings.securityInput.securityInputNeeded %}
<a id="security-input-edit" href="/form/ratings/securityInput/{{ data.bookingId }}">Security input</a>
<strong class="govuk-tag app-task-list__task-completed" id="securityInput-completed">Completed</strong>
{% else %}
@@ -155,7 +155,7 @@ <h1 class="govuk-heading-s">Offender details</h1>
{% endif %}
</li>
<li class="app-task-list__item">
{% if data.ratings.violenceRating %}
{% if data.ratings.violenceRating.highRiskOfViolence and data.ratings.violenceRating.seriousThreat %}
<a href="/form/ratings/violenceRating/{{ data.bookingId }}">Violence rating</a>
<strong class="govuk-tag app-task-list__task-completed" id="violenceRating-completed">Completed</strong>
{% else %}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.