Skip to content
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
34 changes: 30 additions & 4 deletions src/server/plugins/engine/components/DeclarationField.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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
}
]
})
Expand All @@ -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({
Expand Down Expand Up @@ -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({
Expand Down
3 changes: 2 additions & 1 deletion src/server/plugins/engine/components/DeclarationField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading