Skip to content

Commit

Permalink
Ensure conditional answers are removed on funding page
Browse files Browse the repository at this point in the history
Use the `onSave` hook to remove conditional answers when the parent
answer changes.
  • Loading branch information
Daniel Liburd committed Feb 24, 2025
1 parent c0e07a5 commit 124b117
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,30 @@ describe('FundingCas2Accommodation', () => {
})
})
})

describe('onSave', () => {
it('should remove conditional answers if the answers are no longer relevant', () => {
const page = new FundingCas2Accommodation(
{
fundingSource: 'benefits',
fundingSourceDetail: 'Funding source details',
hasNationalInsuranceNumber: 'no',
nationalInsuranceNumber: 'SF123456X',
receivingBenefits: 'no',
receivedBenefitSanctions: 'yes',
inEducationOrTraining: 'yes',
},
application,
)

page.onSave()

expect(page.body).toEqual({
fundingSource: 'benefits',
hasNationalInsuranceNumber: 'no',
receivingBenefits: 'no',
inEducationOrTraining: 'yes',
})
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,16 @@ export default class FundingCas2Accommodation implements TaskListPage {

return [{ ...yes, conditional: { html: conditionalHtml } }, ...items, { ...dontKnow }]
}

onSave() {
if (this.body.fundingSource === 'benefits') {
delete this.body.fundingSourceDetail
}
if (this.body.hasNationalInsuranceNumber === 'no') {
delete this.body.nationalInsuranceNumber
}
if (this.body.receivingBenefits === 'no') {
delete this.body.receivedBenefitSanctions
}
}
}

0 comments on commit 124b117

Please sign in to comment.