From eda33425060b40a21ec1c691859749cc520fa171 Mon Sep 17 00:00:00 2001 From: Jez Barnsley Date: Mon, 17 Nov 2025 16:32:15 +0000 Subject: [PATCH] Fix - reinstates original value for declaration checkbox --- .../components/DeclarationField.test.ts | 34 ++++++++++++++++--- .../engine/components/DeclarationField.ts | 3 +- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/server/plugins/engine/components/DeclarationField.test.ts b/src/server/plugins/engine/components/DeclarationField.test.ts index be89fd504..461556a1a 100644 --- a/src/server/plugins/engine/components/DeclarationField.test.ts +++ b/src/server/plugins/engine/components/DeclarationField.test.ts @@ -239,7 +239,7 @@ describe('DeclarationField', () => { describe('View model', () => { it('sets Nunjucks component defaults', () => { - const viewModel = field.getViewModel(getFormData([])) + const viewModel = field.getViewModel(getFormData(undefined)) expect(viewModel).toEqual( expect.objectContaining({ @@ -257,7 +257,33 @@ describe('DeclarationField', () => { { value: 'true', text: 'I understand and agree', - checked: true + checked: false + } + ] + }) + ) + }) + + it('sets Nunjucks component to false when not checked', () => { + def = { + ...def, + hint: 'Please read and confirm the following' + } satisfies DeclarationFieldComponent + + collection = new ComponentCollection([def], { model }) + field = collection.fields[0] + const viewModel = field.getViewModel(getFormData('unchecked')) + + expect(viewModel).toEqual( + expect.objectContaining({ + hint: { + text: 'Please read and confirm the following' + }, + items: [ + { + value: 'true', + text: 'I understand and agree', + checked: false } ] }) @@ -272,7 +298,7 @@ describe('DeclarationField', () => { collection = new ComponentCollection([def], { model }) field = collection.fields[0] - const viewModel = field.getViewModel(getFormData(['true'])) + const viewModel = field.getViewModel(getFormData('true')) expect(viewModel).toEqual( expect.objectContaining({ @@ -307,7 +333,7 @@ describe('DeclarationField', () => { collection = new ComponentCollection([def], { model }) field = collection.fields[0] - const viewModel = field.getViewModel(getFormData(['true'])) + const viewModel = field.getViewModel(getFormData('true')) expect(viewModel).toEqual( expect.objectContaining({ diff --git a/src/server/plugins/engine/components/DeclarationField.ts b/src/server/plugins/engine/components/DeclarationField.ts index 8584d6dc7..c0b07c8f0 100644 --- a/src/server/plugins/engine/components/DeclarationField.ts +++ b/src/server/plugins/engine/components/DeclarationField.ts @@ -110,7 +110,8 @@ export class DeclarationField extends FormComponent { content, declarationConfirmationLabel = defaultDeclarationConfirmationLabel } = this - const isChecked = !!payload[this.name] + const isChecked = + payload[this.name] === 'true' || payload[this.name] === true return { ...super.getViewModel(payload, errors), hint: hint ? { text: hint } : undefined,