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 all 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,23 @@ 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.clickSaveAndContinue()
useOfForceDetailsPage.errorSummary().contains("Camera '1' has already been added - remove this camera")
})
})
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
19 changes: 19 additions & 0 deletions server/config/forms/useOfForceDetailsForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,25 @@ 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')
.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
120 changes: 117 additions & 3 deletions server/config/forms/useOfForceDetailsValidation.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { complete, partial } = require('./useOfForceDetailsForm')
const { processInput } = require('../../services/validation')
const { BodyWornCameras } = require('../types')

const checkFactory = schema => input => {
const { payloadFields: formResponse, errors } = processInput({ validationSpec: schema, input })
Expand All @@ -16,6 +17,7 @@ beforeEach(() => {
batonDrawn: 'true',
batonUsed: 'true',
pavaDrawn: 'true',
weaponsObserved: 'NO',
pavaUsed: 'true',
guidingHold: 'true',
guidingHoldOfficersInvolved: '2',
Expand Down Expand Up @@ -44,6 +46,7 @@ describe('complete schema', () => {
batonUsed: true,
pavaDrawn: true,
pavaUsed: true,
weaponsObserved: 'NO',
guidingHold: true,
guidingHoldOfficersInvolved: 2,
escortingHold: true,
Expand All @@ -53,7 +56,7 @@ describe('complete schema', () => {
})
})

it('Should return 9 error messages if no input field is completed', () => {
it('Should return 10 error messages if no input field is completed', () => {
const input = {}
const { errors, formResponse } = check(input)

Expand All @@ -78,6 +81,7 @@ describe('complete schema', () => {
href: '#pavaDrawn',
text: 'Select yes if PAVA was drawn',
},
{ href: '#weaponsObserved', text: 'Select yes if any weapons were observed' },
{
href: '#guidingHold',
text: 'Select yes if a guiding hold was used',
Expand All @@ -100,7 +104,7 @@ describe('complete schema', () => {
},
])

expect(errors.length).toEqual(10)
expect(errors.length).toEqual(11)

expect(formResponse).toEqual({})
})
Expand Down Expand Up @@ -190,6 +194,7 @@ describe('complete schema', () => {
handcuffsApplied: true,
painInducingTechniquesUsed: ['FINAL_LOCK_FLEXION', 'THUMB_LOCK'],
pavaDrawn: true,
weaponsObserved: 'NO',
pavaUsed: true,
personalProtectionTechniques: true,
positiveCommunication: true,
Expand All @@ -198,7 +203,7 @@ describe('complete schema', () => {
})

it('Body-worn camera identifiers are not required when bodyWornCamera is NO', () => {
validInput.bodyWornCamer = 'NO'
validInput.bodyWornCamera = 'NO'
validInput.bodyWornCameraNumbers = [{ cameraNum: 'AAA' }, { cameraNum: '' }, { cameraNum: 'AAA' }]

const { errors, formResponse } = check(validInput)
Expand All @@ -215,6 +220,7 @@ describe('complete schema', () => {
handcuffsApplied: true,
painInducingTechniquesUsed: ['FINAL_LOCK_FLEXION', 'THUMB_LOCK'],
pavaDrawn: true,
weaponsObserved: 'NO',
pavaUsed: true,
personalProtectionTechniques: true,
positiveCommunication: true,
Expand Down Expand Up @@ -244,6 +250,7 @@ describe('complete schema', () => {
handcuffsApplied: true,
painInducingTechniquesUsed: ['FINAL_LOCK_FLEXION', 'THUMB_LOCK'],
pavaDrawn: true,
weaponsObserved: 'NO',
pavaUsed: true,
personalProtectionTechniques: true,
positiveCommunication: true,
Expand Down Expand Up @@ -332,6 +339,108 @@ describe('complete schema', () => {
expect(formResponse.pavaUsed).toBe(undefined)
})

it("Not selecting an option for 'weapons observed' returns a validation error message", () => {
const input = {
...validInput,
weaponsObserved: undefined,
}
const { errors } = check(input)
expect(errors).toEqual([
{
href: '#weaponsObserved',
text: 'Select yes if any weapons were observed',
},
])
})

it('Selecting YES for weapons observed but not adding weapon types generates validation error', () => {
validInput.weaponsObserved = 'YES'
const { errors } = check(validInput)

expect(errors).toEqual([{ href: '#weaponTypes[0]', text: '"weaponTypes" is required' }])
})

it('Should not return validation error if all weapon observed identifiers are unique', () => {
validInput.weaponsObserved = 'YES'
validInput.weaponTypes = [{ weaponType: 'Gun' }, { weaponType: 'Knife' }]
const { errors } = check(validInput)

expect(errors).toEqual([])
})

it('Should trim empty-string weapons observed identifiers', () => {
validInput.weaponsObserved = 'YES'
validInput.weaponTypes = [{ weaponType: ' gun ', age: 'knife' }, { weaponType: '' }, { weaponType: 'GUN' }]

const { errors, formResponse } = check(validInput)

expect(errors).toEqual([])

expect(formResponse).toEqual({
batonDrawn: true,
batonUsed: true,
bodyWornCamera: 'NO',
escortingHold: true,
guidingHold: true,
guidingHoldOfficersInvolved: 2,
handcuffsApplied: true,
painInducingTechniquesUsed: ['FINAL_LOCK_FLEXION', 'THUMB_LOCK'],
pavaDrawn: true,
pavaUsed: true,
personalProtectionTechniques: true,
positiveCommunication: true,
restraintPositions: ['STANDING', 'FACE_DOWN'],
weaponTypes: [
{
weaponType: 'gun',
},
{
weaponType: 'GUN',
},
],
weaponsObserved: 'YES',
})
})

it('Weapon types identifiers are not required when weaponsObserved is NO', () => {
validInput.weaponsObserved = 'NO'
validInput.weaponTypes = [{ weaponType: 'Gun' }]

const { errors, formResponse } = check(validInput)

expect(errors).toEqual([])

expect(formResponse).toEqual({
batonDrawn: true,
batonUsed: true,
bodyWornCamera: 'NO',
weaponsObserved: 'NO',
escortingHold: true,
guidingHold: true,
guidingHoldOfficersInvolved: 2,
handcuffsApplied: true,
painInducingTechniquesUsed: ['FINAL_LOCK_FLEXION', 'THUMB_LOCK'],
pavaDrawn: true,
pavaUsed: true,
personalProtectionTechniques: true,
positiveCommunication: true,
restraintPositions: ['STANDING', 'FACE_DOWN'],
})
})

it('Weapons observed field must be one of allowed values', () => {
validInput.weaponsObserved = 'SOMETHING_RANDOM'
validInput.weaponTypes = [{ weaponType: 'gun' }]
const { errors } = check(validInput)

expect(errors).toEqual([
{
href: '#weaponsObserved',
text: 'Select yes if any weapons were observed',
},
])
})

it("Not selecting an option for 'guiding hold' returns validation error message plus 'how many officers involved' is undefined", () => {
const input = {
...validInput,
Expand Down Expand Up @@ -515,6 +624,7 @@ describe('partial schema', () => {
batonUsed: true,
pavaDrawn: true,
pavaUsed: true,
weaponsObserved: 'NO',
guidingHold: true,
guidingHoldOfficersInvolved: 2,
escortingHold: true,
Expand All @@ -536,19 +646,23 @@ describe('partial schema', () => {
it('Should return no error messages when dependent answers are absent', () => {
const { errors, formResponse } = check({
batonDrawn: 'true',
bodyWornCamera: 'YES',
pavaDrawn: 'true',
guidingHold: 'true',
escortingHold: 'true',
restraintPositions: 'NONE',
weaponsObserved: 'YES',
})

expect(errors).toEqual([])
expect(formResponse).toEqual({
batonDrawn: true,
bodyWornCamera: 'YES',
guidingHold: true,
escortingHold: true,
pavaDrawn: true,
restraintPositions: 'NONE',
weaponsObserved: 'YES',
})
})
it('Selecting only a child control technique returns a validation error message', () => {
Expand Down
Loading
Loading