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-627 control restraint reformat #673

Merged
merged 12 commits into from
Jan 26, 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
9 changes: 9 additions & 0 deletions assets/js/deselect-children.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
document.querySelectorAll('[id^=parent-]').forEach(parent => {
parent.addEventListener('change', deselectChildrenOnUncheck)
})
function deselectChildrenOnUncheck(e) {
const parent = e.srcElement
if (!parent.checked) {
document.querySelectorAll(`[id^=child-${parent.value}__]`).forEach(child => (child.checked = false))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ context('Enter use of force details page', () => {
useOfForceDetailsPage.guidingHold().check('true')
useOfForceDetailsPage.guidingHoldOfficersInvolved.check('2')
useOfForceDetailsPage.escortingHold().check('true')
useOfForceDetailsPage.restraint().check('true')
useOfForceDetailsPage.restraintPositions.check(restraintPositions)
useOfForceDetailsPage.handcuffsApplied().check('true')
useOfForceDetailsPage.painInducingTechniques().check('true')
Expand Down Expand Up @@ -63,7 +62,6 @@ context('Enter use of force details page', () => {
pavaUsed: true,
personalProtectionTechniques: true,
positiveCommunication: true,
restraint: true,
restraintPositions: ['STANDING', 'ON_BACK', 'FACE_DOWN', 'KNEELING'],
painInducingTechniques: true,
painInducingTechniquesUsed: ['THROUGH_RIGID_BAR_CUFFS', 'THUMB_LOCK'],
Expand All @@ -90,8 +88,7 @@ context('Enter use of force details page', () => {
pavaUsed: true,
personalProtectionTechniques: true,
positiveCommunication: true,
restraint: true,
restraintPositions: ['STANDING'],
restraintPositions: 'STANDING',
painInducingTechniques: true,
painInducingTechniquesUsed: ['THROUGH_RIGID_BAR_CUFFS', 'THUMB_LOCK'],
})
Expand All @@ -116,7 +113,6 @@ context('Enter use of force details page', () => {
useOfForceDetailsPage.guidingHold().should('have.value', 'true')
useOfForceDetailsPage.guidingHoldOfficersInvolved.two().should('be.checked')
useOfForceDetailsPage.escortingHold().should('have.value', 'true')
useOfForceDetailsPage.restraint().should('have.value', 'true')
useOfForceDetailsPage.restraintPositions.standing().should('be.checked')
useOfForceDetailsPage.restraintPositions.faceDown().should('not.be.checked')
useOfForceDetailsPage.restraintPositions.kneeling().should('be.checked')
Expand All @@ -142,7 +138,6 @@ context('Enter use of force details page', () => {
useOfForceDetailsPage.guidingHold().check('true')
useOfForceDetailsPage.guidingHoldOfficersInvolved.check('2')
useOfForceDetailsPage.escortingHold().check('true')
useOfForceDetailsPage.restraint().check('false')
useOfForceDetailsPage.handcuffsApplied().check('true')
useOfForceDetailsPage.painInducingTechniques().check('true')
useOfForceDetailsPage.clickSaveAndContinue()
Expand Down
2 changes: 0 additions & 2 deletions integration-tests/integration/seedData.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ const expectedPayload = {
batonDrawn: true,
guidingHold: true,
escortingHold: true,
restraint: true,
handcuffsApplied: true,
restraintPositions: ['STANDING', 'ON_BACK', 'FACE_DOWN', 'KNEELING'],
painInducingTechniques: true,
painInducingTechniquesUsed: ['FINAL_LOCK_FLEXION', 'THUMB_LOCK'],

positiveCommunication: true,
guidingHoldOfficersInvolved: 2,
personalProtectionTechniques: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ const useOfForceDetailsPage = () =>
onBack: () => cy.get('#control-and-restraint [type="checkbox"][value="ON_BACK"]'),
faceDown: () => cy.get('#control-and-restraint [type="checkbox"][value="FACE_DOWN"]'),
kneeling: () => cy.get('#control-and-restraint [type="checkbox"][value="KNEELING"]'),
none: () => cy.get('#control-and-restraint [type="checkbox"][value="NONE"]'),
},

restraint: () => cy.get('[name="restraint"]'),
handcuffsApplied: () => cy.get('[name="handcuffsApplied"]'),

painInducingTechniques: () => cy.get('[name="painInducingTechniques"]'),
Expand Down Expand Up @@ -60,7 +60,6 @@ const useOfForceDetailsPage = () =>
this.guidingHold().check('true')
this.guidingHoldOfficersInvolved.check('2')
this.escortingHold().check('true')
this.restraint().check('true')
this.restraintPositions.check(['STANDING', 'ON_BACK', 'FACE_DOWN', 'KNEELING'])
this.handcuffsApplied().check('true')
this.painInducingTechniques().check('true')
Expand Down
5 changes: 4 additions & 1 deletion integration-tests/pages/sections/reportDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ module.exports = {
cy.get('[data-qa="pavaDrawn"]').contains('Yes and used')
cy.get('[data-qa="guidingHold"]').contains('Yes - 2 officers involved')
cy.get('[data-qa="escortingHold"]').contains('Yes')
cy.get('[data-qa="restraintUsed"]').contains('Yes - standing, on back (supine), on front (prone), kneeling')
cy.get('[data-qa="restraintUsed"]').contains('Standing')
cy.get('[data-qa="restraintUsed"]').contains('On back (supine)')
cy.get('[data-qa="restraintUsed"]').contains('On front (prone)')
cy.get('[data-qa="restraintUsed"]').contains('Kneeling')
handcuffsApplied().contains('Yes')
painInducingTechniques().contains('Yes')
cy.get('[data-qa="painInducingTechniques"]').contains('Yes - wrist flexion, thumb lock')
Expand Down
61 changes: 37 additions & 24 deletions server/config/forms/useOfForceDetailsForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,30 +71,43 @@ const completeSchema = joi.object({
}),

escortingHold: requiredBooleanMsg('Select yes if an escorting hold was used').alter(optionalForPartialValidation),

restraint: requiredBooleanMsg('Select yes if control and restraint was used').alter(optionalForPartialValidation),

restraintPositions: joi.when('restraint', {
is: true,
then: joi
.alternatives()
.try(
joi
.array()
.items(
requiredOneOfMsg(
'STANDING',
'FACE_DOWN',
'ON_BACK',
'KNEELING'
)('Select the control and restraint positions used').alter(optionalForPartialValidation)
)
)
.required()
.messages({ 'any.required': 'Select the control and restraint positions used' })
.alter(optionalForPartialValidation),
otherwise: joi.any().strip(),
}),
restraintPositions: joi
.alternatives()
.try(
joi
.valid('STANDING', 'ON_BACK', 'FACE_DOWN', 'KNEELING', 'NONE')
.messages({ 'any.only': 'Select which control and restraint positions were used' }),
joi
.array()
.items(
requiredOneOfMsg(
'STANDING',
'STANDING__WRIST_WEAVE',
'STANDING__DOUBLE_WRIST_HOLD',
'STANDING__UNDERHOOK',
'STANDING__WRIST_HOLD',
'STANDING__STRAIGHT_HOLD',
'ON_BACK',
'ON_BACK__STRAIGHT_ARM_HOLD',
'ON_BACK__CONVERSION_TO_RBH',
'ON_BACK__WRIST_HOLD',
'FACE_DOWN',
'FACE_DOWN__BALANCE_DISPLACEMENT',
'FACE_DOWN__STRAIGHT_ARM_HOLD',
'FACE_DOWN__CONVERSION_TO_RBH',
'FACE_DOWN__WRIST_HOLD',
'KNEELING'
)('Select which control and restraint positions were used')
)
)
.messages({
'alternatives.types': 'Select which control and restraint positions were used',
})
.required()
.messages({
'any.required': 'Select which control and restraint positions were used',
})
.alter(optionalForPartialValidation),

painInducingTechniques: requiredBooleanMsg('Select yes if pain inducing techniques were used').alter(
optionalForPartialValidation
Expand Down
69 changes: 34 additions & 35 deletions server/config/forms/useOfForceDetailsValidation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ beforeEach(() => {
guidingHold: 'true',
guidingHoldOfficersInvolved: '2',
escortingHold: 'true',
restraint: 'true',
restraintPositions: ['STANDING', 'FACE_DOWN'],
handcuffsApplied: 'true',
painInducingTechniques: 'true',
Expand Down Expand Up @@ -48,7 +47,6 @@ describe('complete schema', () => {
guidingHold: true,
guidingHoldOfficersInvolved: 2,
escortingHold: true,
restraint: true,
restraintPositions: ['STANDING', 'FACE_DOWN'],
handcuffsApplied: true,
painInducingTechniques: true,
Expand Down Expand Up @@ -90,8 +88,8 @@ describe('complete schema', () => {
text: 'Select yes if an escorting hold was used',
},
{
href: '#restraint',
text: 'Select yes if control and restraint was used',
href: '#restraintPositions',
text: 'Select which control and restraint positions were used',
},
{
href: '#painInducingTechniques',
Expand Down Expand Up @@ -197,7 +195,6 @@ describe('complete schema', () => {
pavaUsed: true,
personalProtectionTechniques: true,
positiveCommunication: true,
restraint: true,
restraintPositions: ['STANDING', 'FACE_DOWN'],
})
})
Expand All @@ -224,7 +221,6 @@ describe('complete schema', () => {
pavaUsed: true,
personalProtectionTechniques: true,
positiveCommunication: true,
restraint: true,
restraintPositions: ['STANDING', 'FACE_DOWN'],
})
})
Expand Down Expand Up @@ -255,7 +251,6 @@ describe('complete schema', () => {
pavaUsed: true,
personalProtectionTechniques: true,
positiveCommunication: true,
restraint: true,
restraintPositions: ['STANDING', 'FACE_DOWN'],
})
})
Expand Down Expand Up @@ -403,24 +398,7 @@ describe('complete schema', () => {
expect(formResponse.escortingHold).toEqual(undefined)
})

it("Not selecting an option for 'restraint'returns a validation error message plus 'restraint positions' is undefined", () => {
const input = {
...validInput,
restraint: undefined,
}
const { errors, formResponse } = check(input)

expect(errors).toEqual([
{
href: '#restraint',
text: 'Select yes if control and restraint was used',
},
])
expect(formResponse.restraint).toBe(undefined)
expect(formResponse.restraintPositions).toBe(undefined)
})

it("Selecting Yes to 'restraint' but nothing for 'restraint positions' returns a validation error message", () => {
it("Selecting nothing for 'restraint positions' returns a validation error message", () => {
const input = {
...validInput,
restraintPositions: undefined,
Expand All @@ -430,10 +408,9 @@ describe('complete schema', () => {
expect(errors).toEqual([
{
href: '#restraintPositions',
text: 'Select the control and restraint positions used',
text: 'Select which control and restraint positions were used',
},
])
expect(formResponse.restraint).toEqual(true)
expect(formResponse.restraintPositions).toBe(undefined)
})

Expand All @@ -445,7 +422,6 @@ describe('complete schema', () => {
const { errors, formResponse } = check(input)

expect(errors).toEqual([])
expect(formResponse.restraint).toBe(true)
expect(formResponse.restraintPositions).toEqual(['KNEELING'])
})

Expand All @@ -456,10 +432,20 @@ describe('complete schema', () => {
const { errors, formResponse } = check(input)

expect(errors).toEqual([])
expect(formResponse.restraint).toEqual(true)
expect(formResponse.restraintPositions).toEqual(['STANDING', 'FACE_DOWN'])
})

it("Selecting 'Standing' and child option 'Wrist hold' for 'restraint positions' returns no errors", () => {
const input = {
...validInput,
restraintPositions: ['STANDING', 'STANDING__WRIST_HOLD'],
}
const { errors, formResponse } = check(input)

expect(errors).toEqual([])
expect(formResponse.restraintPositions).toEqual(['STANDING', 'STANDING__WRIST_HOLD'])
})

it("Not selecting an option for 'handcuffs applied' returns a validation error message", () => {
const input = {
...validInput,
Expand Down Expand Up @@ -558,15 +544,14 @@ describe('partial schema', () => {
guidingHold: true,
guidingHoldOfficersInvolved: 2,
escortingHold: true,
restraint: true,
restraintPositions: ['STANDING', 'FACE_DOWN'],
handcuffsApplied: true,
painInducingTechniques: true,
painInducingTechniquesUsed: ['FINAL_LOCK_FLEXION', 'THUMB_LOCK'],
})
})

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

Expand All @@ -575,14 +560,13 @@ describe('partial schema', () => {
})
})

it('Should return no error massages when dependent answers are absent', () => {
it('Should return no error messages when dependent answers are absent', () => {
const { errors, formResponse } = check({
batonDrawn: 'true',
pavaDrawn: 'true',
guidingHold: 'true',
escortingHold: 'true',
restraint: 'true',
restraintPositions: [],
restraintPositions: 'NONE',
})

expect(errors).toEqual([])
Expand All @@ -591,7 +575,22 @@ describe('partial schema', () => {
guidingHold: true,
escortingHold: true,
pavaDrawn: true,
restraint: true,
restraintPositions: 'NONE',
})
})
it('Selecting only a child control technique returns a validation error message', () => {
const input = {
...validInput,
restraintPositions: 'STANDING__WRIST_HOLD',
}
const { errors, formResponse } = check(input)

expect(errors).toEqual([
{
href: '#restraintPositions',
text: 'Select which control and restraint positions were used',
},
])
expect(formResponse.restraintPositions).toBe('STANDING__WRIST_HOLD')
})
})
Loading
Loading