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

Map 625 uof new weapons observed question #678

Merged
merged 5 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions assets/js/add-another-detail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
new AddAnother($('.add-another-body-worn-camera'), '.remove-button-container')
new AddAnother($('.add-another-weapons-observed'), '.remove-button-container')
1 change: 0 additions & 1 deletion assets/js/add-another-evidence.js
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
new AddAnother($('.add-another-evidence'), '.remove-button-container')
new AddAnother($('.add-another-input'), '.remove-button-container')
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ context('Submit the incident report', () => {
useOfForceDetailsPage.bodyWornCameraNumber(1).type('789')
useOfForceDetailsPage.addAnotherBodyWornCamera()
useOfForceDetailsPage.bodyWornCameraNumber(2).type('456')

useOfForceDetailsPage.weaponsObserved().check('YES')
useOfForceDetailsPage.weaponTypes(0).type('gun')
useOfForceDetailsPage.addAnotherWeapon()
useOfForceDetailsPage.weaponTypes(1).type('knife')
useOfForceDetailsPage.addAnotherWeapon()
useOfForceDetailsPage.weaponTypes(2).type('fork')

const relocationAndInjuriesPage = useOfForceDetailsPage.save()
relocationAndInjuriesPage.fillForm()
const evidencePage = relocationAndInjuriesPage.save()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const { use } = require('passport')
const { offender } = require('../../mockApis/data')

const ReportUseOfForcePage = require('../../pages/createReport/reportUseOfForcePage')
Expand Down Expand Up @@ -31,6 +30,7 @@ context('Enter use of force details page', () => {
useOfForceDetailsPage.batonDrawn().check('true')
useOfForceDetailsPage.batonUsed().check('true')
useOfForceDetailsPage.pavaDrawn().check('true')
useOfForceDetailsPage.weaponsObserved().check('NO')
useOfForceDetailsPage.pavaUsed().check('true')
useOfForceDetailsPage.guidingHold().check('true')
useOfForceDetailsPage.guidingHoldOfficersInvolved.check('2')
Expand Down Expand Up @@ -59,6 +59,7 @@ context('Enter use of force details page', () => {
handcuffsApplied: true,
pavaDrawn: true,
pavaUsed: true,
weaponsObserved: 'NO',
personalProtectionTechniques: true,
positiveCommunication: true,
restraintPositions: ['STANDING', 'ON_BACK', 'FACE_DOWN', 'KNEELING'],
Expand All @@ -83,6 +84,7 @@ context('Enter use of force details page', () => {
escortingHold: true,
handcuffsApplied: true,
pavaDrawn: true,
weaponsObserved: 'NO',
pavaUsed: true,
personalProtectionTechniques: true,
positiveCommunication: true,
Expand Down Expand Up @@ -127,12 +129,39 @@ context('Enter use of force details page', () => {
selectUofReasonsPage.checkReason('FIGHT_BETWEEN_PRISONERS')
selectUofReasonsPage.clickSaveAndContinue()

const useOfForceDetailsPage = UseOfForceDetailsPage.verifyOnPage()
useOfForceDetailsPage.positiveCommunication().check('true')
useOfForceDetailsPage.personalProtectionTechniques().check('true')
useOfForceDetailsPage.pavaDrawn().check('true')
useOfForceDetailsPage.pavaUsed().check('true')
useOfForceDetailsPage.guidingHold().check('true')
useOfForceDetailsPage.guidingHoldOfficersInvolved.check('2')
useOfForceDetailsPage.escortingHold().check('true')
useOfForceDetailsPage.handcuffsApplied().check('true')
useOfForceDetailsPage.clickSaveAndContinue()
useOfForceDetailsPage.errorSummary().contains('Select yes if a baton was drawn')
useOfForceDetailsPage
.errorSummary()
.contains('Select yes if any part of the incident was captured on a body-worn camera')
useOfForceDetailsPage.errorSummary().contains('Select if any pain inducing techniques were used')
useOfForceDetailsPage.errorSummary().contains('Select yes if any weapons were observed')
})

it('Displays secondary validation messages', () => {
cy.login()

const reportUseOfForcePage = ReportUseOfForcePage.visit(offender.bookingId)
const selectUofReasonsPage = reportUseOfForcePage.goToSelectUofReasonsPage()
selectUofReasonsPage.checkReason('FIGHT_BETWEEN_PRISONERS')
selectUofReasonsPage.clickSaveAndContinue()

const useOfForceDetailsPage = UseOfForceDetailsPage.verifyOnPage()
useOfForceDetailsPage.positiveCommunication().check('true')
useOfForceDetailsPage.bodyWornCamera().check('YES')
useOfForceDetailsPage.personalProtectionTechniques().check('true')
useOfForceDetailsPage.pavaDrawn().check('true')
useOfForceDetailsPage.pavaUsed().check('true')
useOfForceDetailsPage.weaponsObserved().check('YES')
useOfForceDetailsPage.guidingHold().check('true')
useOfForceDetailsPage.guidingHoldOfficersInvolved.check('2')
useOfForceDetailsPage.escortingHold().check('true')
Expand All @@ -141,5 +170,31 @@ context('Enter use of force details page', () => {
useOfForceDetailsPage.errorSummary().contains('Select yes if a baton was drawn')
useOfForceDetailsPage.errorSummary().contains('Enter the body-worn camera number')
useOfForceDetailsPage.errorSummary().contains('Select if any pain inducing techniques were used')
useOfForceDetailsPage.errorSummary().contains('Enter the type of weapon observed')
})

it('Displays validation messages when multiple inputs are not unique', () => {
cy.login()

const reportUseOfForcePage = ReportUseOfForcePage.visit(offender.bookingId)
const selectUofReasonsPage = reportUseOfForcePage.goToSelectUofReasonsPage()
selectUofReasonsPage.checkReason('FIGHT_BETWEEN_PRISONERS')
selectUofReasonsPage.clickSaveAndContinue()

const useOfForceDetailsPage = UseOfForceDetailsPage.verifyOnPage()
useOfForceDetailsPage.bodyWornCamera().check('YES')
useOfForceDetailsPage.bodyWornCameraNumber(0).type('1')
useOfForceDetailsPage.addAnotherBodyWornCamera()
useOfForceDetailsPage.bodyWornCameraNumber(1).type('1')

useOfForceDetailsPage.weaponsObserved().check('YES')
useOfForceDetailsPage.weaponTypes(0).type('gun')
useOfForceDetailsPage.addAnotherWeapon()
useOfForceDetailsPage.weaponTypes(1).type('gun')

useOfForceDetailsPage.clickSaveAndContinue()

useOfForceDetailsPage.errorSummary().contains("Camera '1' has already been added - remove this camera")
useOfForceDetailsPage.errorSummary().contains("Weapon 'gun' has already been added - remove this weapon")
})
})
2 changes: 2 additions & 0 deletions integration-tests/integration/seedData.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const expectedPayload = {
pavaUsed: true,
batonUsed: true,
pavaDrawn: true,
weaponsObserved: 'YES',
weaponTypes: [{ weaponType: 'gun' }, { weaponType: 'knife' }, { weaponType: 'fork' }],
batonDrawn: true,
guidingHold: true,
escortingHold: true,
Expand Down
9 changes: 7 additions & 2 deletions integration-tests/pages/createReport/useOfForceDetailsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ const useOfForceDetailsPage = () =>

bodyWornCamera: () => cy.get('[name="bodyWornCamera"]'),
bodyWornCameraNumber: index => cy.get(`[name="bodyWornCameraNumbers[${index}][cameraNum]"]`),
addAnotherBodyWornCamera: () => cy.get('[data-qa-add-another-input = true]').click(),
removeBodyWornCamera: index => cy.get('.add-another-input .add-another__remove-button').eq(index).click(),
addAnotherBodyWornCamera: () => cy.get('[dataqa=add-another-body-worn-camera]').click(),
removeBodyWornCamera: index =>
cy.get('.add-another-body-worn-camera .add-another__remove-button').eq(index).click(),

personalProtectionTechniques: () => cy.get('[name="personalProtectionTechniques"]'),
batonDrawn: () => cy.get('[name="batonDrawn"]'),
batonUsed: () => cy.get('[name="batonUsed"]'),
pavaDrawn: () => cy.get('[name="pavaDrawn"]'),
weaponsObserved: () => cy.get('[name="weaponsObserved"]'),
weaponTypes: index => cy.get(`[name="weaponTypes[${index}][weaponType]"]`),
addAnotherWeapon: () => cy.get('[dataqa=add-another-weapons-observed]').click(),
pavaUsed: () => cy.get('[name="pavaUsed"]'),
guidingHold: () => cy.get('[name="guidingHold"]'),
guidingHoldOfficersInvolved: {
Expand Down Expand Up @@ -57,6 +61,7 @@ const useOfForceDetailsPage = () =>
this.batonUsed().check('true')
this.pavaDrawn().check('true')
this.pavaUsed().check('true')
this.weaponsObserved().check('NO')
this.guidingHold().check('true')
this.guidingHoldOfficersInvolved.check('2')
this.escortingHold().check('true')
Expand Down
24 changes: 22 additions & 2 deletions server/config/forms/useOfForceDetailsForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ const completeSchema = joi.object({

bodyWornCamera: requiredOneOfMsg(
'YES',
'NO',
'NOT_KNOWN'
'NO'
)('Select yes if any part of the incident was captured on a body-worn camera').alter(optionalForPartialValidation),

bodyWornCameraNumbers: joi
Expand Down Expand Up @@ -53,6 +52,27 @@ const completeSchema = joi.object({

pavaDrawn: requiredBooleanMsg('Select yes if PAVA was drawn').alter(optionalForPartialValidation),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validation spec for the new weapons observed question

weaponsObserved: requiredOneOfMsg(
'YES',
'NO'
)('Select yes if any weapons were observed').alter(optionalForPartialValidation),

weaponTypes: joi
.when('weaponsObserved', {
is: 'YES',
then: arrayOfObjects({
weaponType: requiredStringMsg('Enter the type of weapon observed').alter(optionalForPartialValidation),
})
.min(1)
.message('Enter the type of weapon observed')
.ruleset.unique('weaponType')
.message("Weapon '{#value.weaponType}' has already been added - remove this weapon")
.required()
.alter(minZeroForPartialValidation),
otherwise: joi.any().strip(),
})
.meta({ firstFieldName: 'weaponTypes[0]' }),

pavaUsed: joi.when('pavaDrawn', {
is: true,
then: requiredBooleanMsg('Select yes if PAVA was used').alter(optionalForPartialValidation),
Expand Down
Loading
Loading