Skip to content

Commit

Permalink
1. made weapons observed non-unique
Browse files Browse the repository at this point in the history
2. reinstated Not Known for body-worn cameras
3. fixed label and input associations for checkboxesWithNestedCheckboxes macro as it was cauing label on one question to trigger input on another
  • Loading branch information
GurnankCheema committed Jan 29, 2024
1 parent ea7a4f9 commit 56a0d2a
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,7 @@ context('Enter use of force details page', () => {
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")
})
})
5 changes: 2 additions & 3 deletions server/config/forms/useOfForceDetailsForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const completeSchema = joi.object({

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

bodyWornCameraNumbers: joi
Expand Down Expand Up @@ -65,8 +66,6 @@ const completeSchema = joi.object({
})
.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(),
Expand Down
10 changes: 0 additions & 10 deletions server/config/forms/useOfForceDetailsValidation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,16 +360,6 @@ describe('complete schema', () => {
expect(errors).toEqual([{ href: '#weaponTypes[0]', text: '"weaponTypes" is required' }])
})

it('Should return validation error if more than one weapon with same identifier', () => {
validInput.weaponsObserved = 'YES'
validInput.weaponTypes = [{ weaponType: 'Gun' }, { weaponType: 'Gun' }]
const { errors } = check(validInput)

expect(errors).toEqual([
{ href: '#weaponTypes[1]', text: "Weapon 'Gun' has already been added - remove this weapon" },
])
})

it('Should not return validation error if all weapon observed identifiers are unique', () => {
validInput.weaponsObserved = 'YES'
validInput.weaponTypes = [{ weaponType: 'Gun' }, { weaponType: 'Knife' }]
Expand Down
2 changes: 1 addition & 1 deletion server/config/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BodyWornCameras, toLabel } from './types'

describe('toLabel', () => {
test('Found', () => {
return expect(toLabel(BodyWornCameras, 'YES')).toEqual('Yes')
return expect(toLabel(BodyWornCameras, 'NOT_KNOWN')).toEqual('Not Known')
})
test('Passed undefined', () => {
return expect(toLabel(BodyWornCameras, undefined)).toEqual(undefined)
Expand Down
1 change: 1 addition & 0 deletions server/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const findEnum = <K extends string>(type: LabelledEnum<K>, val: string):
export const BodyWornCameras = toEnum({
YES: { value: 'YES', label: 'Yes' },
NO: { value: 'NO', label: 'No' },
NOT_KNOWN: { value: 'NOT_KNOWN', label: 'Not Known' },
})

export const WeaponsObserved = toEnum({
Expand Down

0 comments on commit 56a0d2a

Please sign in to comment.