@defra/forms-engine-plugin 4.0.35 → 4.0.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.server/server/plugins/engine/components/DeclarationField.js +2 -1
- package/.server/server/plugins/engine/components/DeclarationField.js.map +1 -1
- package/package.json +1 -1
- package/src/server/plugins/engine/components/DeclarationField.test.ts +52 -0
- package/src/server/plugins/engine/components/DeclarationField.ts +5 -1
|
@@ -83,7 +83,8 @@ export class DeclarationField extends FormComponent {
|
|
|
83
83
|
classes: 'govuk-fieldset__legend--m'
|
|
84
84
|
}
|
|
85
85
|
};
|
|
86
|
-
const
|
|
86
|
+
const payloadValue = payload[this.name];
|
|
87
|
+
const isChecked = payloadValue === 'true' || payloadValue === true || Array.isArray(payloadValue) && payloadValue.some(x => x === 'true');
|
|
87
88
|
return {
|
|
88
89
|
...viewModel,
|
|
89
90
|
hint: hint ? {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeclarationField.js","names":["ComponentType","hasFormComponents","isFormType","joi","FormComponent","isFormValue","messageTemplate","DeclarationField","DEFAULT_DECLARATION_LABEL","headerStartLevel","constructor","def","props","options","content","checkboxSchema","string","valid","required","formSchema","array","items","strip","label","single","messages","declarationRequired","stateSchema","boolean","cast","declarationConfirmationLabel","formComponents","page","pageDef","components","numOfQuestionsOnPage","filter","q","type","length","hasGuidance","some","comp","idx","Markdown","getFormValueFromState","state","name","getFormDataFromState","getStateFromValidForm","payload","payloadValue","value","isValue","every","v","getContextValueFromFormValue","getFormValue","undefined","getDisplayStringFromFormValue","getViewModel","errors","defaultDeclarationConfirmationLabel","hint","viewModel","fieldset","legend","text","classes","isChecked","checked","Array","isArray","getAllPossibleErrors","baseErrors","template","advancedSettingsErrors","isBool"],"sources":["../../../../../src/server/plugins/engine/components/DeclarationField.ts"],"sourcesContent":["import {\n ComponentType,\n hasFormComponents,\n isFormType,\n type DeclarationFieldComponent,\n type Item\n} from '@defra/forms-model'\nimport joi, {\n type ArraySchema,\n type BooleanSchema,\n type StringSchema\n} from 'joi'\n\nimport {\n FormComponent,\n isFormValue\n} from '~/src/server/plugins/engine/components/FormComponent.js'\nimport { messageTemplate } from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport {\n type ErrorMessageTemplateList,\n type FormPayload,\n type FormState,\n type FormStateValue,\n type FormSubmissionError,\n type FormSubmissionState,\n type FormValue\n} from '~/src/server/plugins/engine/types.js'\n\nexport class DeclarationField extends FormComponent {\n private readonly DEFAULT_DECLARATION_LABEL = 'I understand and agree'\n\n declare options: DeclarationFieldComponent['options']\n\n declare declarationConfirmationLabel: string\n\n declare formSchema: ArraySchema<StringSchema[]>\n declare stateSchema: BooleanSchema\n declare content: string\n headerStartLevel: number\n\n constructor(\n def: DeclarationFieldComponent,\n props: ConstructorParameters<typeof FormComponent>[1]\n ) {\n super(def, props)\n\n const { options, content } = def\n\n let checkboxSchema = joi.string().valid('true')\n\n if (options.required !== false) {\n checkboxSchema = checkboxSchema.required()\n }\n\n const formSchema = joi\n .array()\n .items(checkboxSchema, joi.string().valid('unchecked').strip())\n .label(this.label)\n .single()\n .messages({\n 'any.required': messageTemplate.declarationRequired as string,\n 'any.unknown': messageTemplate.declarationRequired as string,\n 'array.includesRequiredUnknowns':\n messageTemplate.declarationRequired as string\n }) as ArraySchema<StringSchema[]>\n\n this.formSchema = formSchema\n this.stateSchema = joi.boolean().cast('string').label(this.label).required()\n\n this.options = options\n this.content = content\n this.declarationConfirmationLabel =\n options.declarationConfirmationLabel ?? this.DEFAULT_DECLARATION_LABEL\n const formComponents = hasFormComponents(props.page?.pageDef)\n ? props.page.pageDef.components\n : []\n const numOfQuestionsOnPage = formComponents.filter((q) =>\n isFormType(q.type)\n ).length\n const hasGuidance = formComponents.some(\n (comp, idx) => comp.type === ComponentType.Markdown && idx === 0\n )\n this.headerStartLevel = numOfQuestionsOnPage < 2 && !hasGuidance ? 2 : 3\n }\n\n getFormValueFromState(state: FormSubmissionState) {\n const { name } = this\n return state[name] === true ? 'true' : 'false'\n }\n\n getFormDataFromState(state: FormSubmissionState): FormPayload {\n const { name } = this\n return { [name]: state[name] === true ? 'true' : 'false' }\n }\n\n getStateFromValidForm(payload: FormPayload): FormState {\n const { name } = this\n const payloadValue = payload[name]\n const value =\n this.isValue(payloadValue) &&\n payloadValue.length > 0 &&\n payloadValue.every((v) => {\n return v === 'true'\n })\n\n return { [name]: value }\n }\n\n getContextValueFromFormValue(value: FormValue | FormPayload): boolean {\n return value === 'true'\n }\n\n getFormValue(value?: FormStateValue | FormState) {\n return this.isValue(value) ? value : undefined\n }\n\n getDisplayStringFromFormValue(value: FormValue | FormPayload): string {\n return value === 'true' ? this.declarationConfirmationLabel : 'Not provided'\n }\n\n getViewModel(payload: FormPayload, errors?: FormSubmissionError[]) {\n const defaultDeclarationConfirmationLabel =\n 'I confirm that I understand and accept this declaration'\n const {\n hint,\n content,\n declarationConfirmationLabel = defaultDeclarationConfirmationLabel\n } = this\n\n const viewModel = super.getViewModel(payload, errors)\n let { fieldset, label } = viewModel\n\n fieldset ??= {\n legend: {\n text: label.text,\n classes: 'govuk-fieldset__legend--m'\n }\n }\n\n const isChecked =\n payload[this.name] === 'true' || payload[this.name] === true\n return {\n ...viewModel,\n hint: hint ? { text: hint } : undefined,\n fieldset,\n content,\n items: [\n {\n text: declarationConfirmationLabel,\n value: 'true',\n checked: isChecked\n }\n ],\n headerStartLevel: this.headerStartLevel\n }\n }\n\n isValue(value?: FormStateValue | FormState): value is Item['value'][] {\n if (!Array.isArray(value)) {\n return false\n }\n\n // Skip checks when empty\n if (!value.length) {\n return true\n }\n\n return value.every(isFormValue)\n }\n\n /**\n * For error preview page that shows all possible errors on a component\n */\n getAllPossibleErrors(): ErrorMessageTemplateList {\n return DeclarationField.getAllPossibleErrors()\n }\n\n /**\n * Static version of getAllPossibleErrors that doesn't require a component instance.\n */\n static getAllPossibleErrors(): ErrorMessageTemplateList {\n return {\n baseErrors: [\n { type: 'required', template: messageTemplate.declarationRequired }\n ],\n advancedSettingsErrors: []\n }\n }\n\n static isBool(value?: FormStateValue | FormState): value is boolean {\n return isFormValue(value) && typeof value === 'boolean'\n }\n}\n"],"mappings":"AAAA,SACEA,aAAa,EACbC,iBAAiB,EACjBC,UAAU,QAGL,oBAAoB;AAC3B,OAAOC,GAAG,MAIH,KAAK;AAEZ,SACEC,aAAa,EACbC,WAAW;AAEb,SAASC,eAAe;AAWxB,OAAO,MAAMC,gBAAgB,SAASH,aAAa,CAAC;EACjCI,yBAAyB,GAAG,wBAAwB;EASrEC,gBAAgB;EAEhBC,WAAWA,CACTC,GAA8B,EAC9BC,KAAqD,EACrD;IACA,KAAK,CAACD,GAAG,EAAEC,KAAK,CAAC;IAEjB,MAAM;MAAEC,OAAO;MAAEC;IAAQ,CAAC,GAAGH,GAAG;IAEhC,IAAII,cAAc,GAAGZ,GAAG,CAACa,MAAM,CAAC,CAAC,CAACC,KAAK,CAAC,MAAM,CAAC;IAE/C,IAAIJ,OAAO,CAACK,QAAQ,KAAK,KAAK,EAAE;MAC9BH,cAAc,GAAGA,cAAc,CAACG,QAAQ,CAAC,CAAC;IAC5C;IAEA,MAAMC,UAAU,GAAGhB,GAAG,CACnBiB,KAAK,CAAC,CAAC,CACPC,KAAK,CAACN,cAAc,EAAEZ,GAAG,CAACa,MAAM,CAAC,CAAC,CAACC,KAAK,CAAC,WAAW,CAAC,CAACK,KAAK,CAAC,CAAC,CAAC,CAC9DC,KAAK,CAAC,IAAI,CAACA,KAAK,CAAC,CACjBC,MAAM,CAAC,CAAC,CACRC,QAAQ,CAAC;MACR,cAAc,EAAEnB,eAAe,CAACoB,mBAA6B;MAC7D,aAAa,EAAEpB,eAAe,CAACoB,mBAA6B;MAC5D,gCAAgC,EAC9BpB,eAAe,CAACoB;IACpB,CAAC,CAAgC;IAEnC,IAAI,CAACP,UAAU,GAAGA,UAAU;IAC5B,IAAI,CAACQ,WAAW,GAAGxB,GAAG,CAACyB,OAAO,CAAC,CA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I,EAAEJ;MAAK,CAAC,GAAGL,SAAS;MACvCO,QAAQ;MACRnD,OAAO;MACPO,KAAK,EAAE,CACL;QACE8C,IAAI,EAAErC,4BAA4B;QAClCsB,KAAK,EAAE,MAAM;QACbkB,OAAO,EAAED;MACX,CAAC,CACF;MACD5D,gBAAgB,EAAE,IAAI,CAACA;IACzB,CAAC;EACH;EAEA4C,OAAOA,CAACD,KAAkC,EAA4B;IACpE,IAAI,CAACmB,KAAK,CAACC,OAAO,CAACpB,KAAK,CAAC,EAAE;MACzB,OAAO,KAAK;IACd;;IAEA;IACA,IAAI,CAACA,KAAK,CAACb,MAAM,EAAE;MACjB,OAAO,IAAI;IACb;IAEA,OAAOa,KAAK,CAACE,KAAK,CAACjD,WAAW,CAAC;EACjC;;EAEA;AACF;AACA;EACEoE,oBAAoBA,CAAA,EAA6B;IAC/C,OAAOlE,gBAAgB,CAACkE,oBAAoB,CAAC,CAAC;EAChD;;EAEA;AACF;AACA;EACE,OAAOA,oBAAoBA,CAAA,EAA6B;IACtD,OAAO;MACLC,UAAU,EAAE,CACV;QAAEpC,IAAI,EAAE,UAAU;QAAEqC,QAAQ,EAAErE,eAAe,CAACoB;MAAoB,CAAC,CACpE;MACDkD,sBAAsB,EAAE;IAC1B,CAAC;EACH;EAEA,OAAOC,MAAMA,CAACzB,KAAkC,EAAoB;IAClE,OAAO/C,WAAW,CAAC+C,KAAK,CAAC,IAAI,OAAOA,KAAK,KAAK,SAAS;EACzD;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"DeclarationField.js","names":["ComponentType","hasFormComponents","isFormType","joi","FormComponent","isFormValue","messageTemplate","DeclarationField","DEFAULT_DECLARATION_LABEL","headerStartLevel","constructor","def","props","options","content","checkboxSchema","string","valid","required","formSchema","array","items","strip","label","single","messages","declarationRequired","stateSchema","boolean","cast","declarationConfirmationLabel","formComponents","page","pageDef","components","numOfQuestionsOnPage","filter","q","type","length","hasGuidance","some","comp","idx","Markdown","getFormValueFromState","state","name","getFormDataFromState","getStateFromValidForm","payload","payloadValue","value","isValue","every","v","getContextValueFromFormValue","getFormValue","undefined","getDisplayStringFromFormValue","getViewModel","errors","defaultDeclarationConfirmationLabel","hint","viewModel","fieldset","legend","text","classes","isChecked","Array","isArray","x","checked","getAllPossibleErrors","baseErrors","template","advancedSettingsErrors","isBool"],"sources":["../../../../../src/server/plugins/engine/components/DeclarationField.ts"],"sourcesContent":["import {\n ComponentType,\n hasFormComponents,\n isFormType,\n type DeclarationFieldComponent,\n type Item\n} from '@defra/forms-model'\nimport joi, {\n type ArraySchema,\n type BooleanSchema,\n type StringSchema\n} from 'joi'\n\nimport {\n FormComponent,\n isFormValue\n} from '~/src/server/plugins/engine/components/FormComponent.js'\nimport { messageTemplate } from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport {\n type ErrorMessageTemplateList,\n type FormPayload,\n type FormState,\n type FormStateValue,\n type FormSubmissionError,\n type FormSubmissionState,\n type FormValue\n} from '~/src/server/plugins/engine/types.js'\n\nexport class DeclarationField extends FormComponent {\n private readonly DEFAULT_DECLARATION_LABEL = 'I understand and agree'\n\n declare options: DeclarationFieldComponent['options']\n\n declare declarationConfirmationLabel: string\n\n declare formSchema: ArraySchema<StringSchema[]>\n declare stateSchema: BooleanSchema\n declare content: string\n headerStartLevel: number\n\n constructor(\n def: DeclarationFieldComponent,\n props: ConstructorParameters<typeof FormComponent>[1]\n ) {\n super(def, props)\n\n const { options, content } = def\n\n let checkboxSchema = joi.string().valid('true')\n\n if (options.required !== false) {\n checkboxSchema = checkboxSchema.required()\n }\n\n const formSchema = joi\n .array()\n .items(checkboxSchema, joi.string().valid('unchecked').strip())\n .label(this.label)\n .single()\n .messages({\n 'any.required': messageTemplate.declarationRequired as string,\n 'any.unknown': messageTemplate.declarationRequired as string,\n 'array.includesRequiredUnknowns':\n messageTemplate.declarationRequired as string\n }) as ArraySchema<StringSchema[]>\n\n this.formSchema = formSchema\n this.stateSchema = joi.boolean().cast('string').label(this.label).required()\n\n this.options = options\n this.content = content\n this.declarationConfirmationLabel =\n options.declarationConfirmationLabel ?? this.DEFAULT_DECLARATION_LABEL\n const formComponents = hasFormComponents(props.page?.pageDef)\n ? props.page.pageDef.components\n : []\n const numOfQuestionsOnPage = formComponents.filter((q) =>\n isFormType(q.type)\n ).length\n const hasGuidance = formComponents.some(\n (comp, idx) => comp.type === ComponentType.Markdown && idx === 0\n )\n this.headerStartLevel = numOfQuestionsOnPage < 2 && !hasGuidance ? 2 : 3\n }\n\n getFormValueFromState(state: FormSubmissionState) {\n const { name } = this\n return state[name] === true ? 'true' : 'false'\n }\n\n getFormDataFromState(state: FormSubmissionState): FormPayload {\n const { name } = this\n return { [name]: state[name] === true ? 'true' : 'false' }\n }\n\n getStateFromValidForm(payload: FormPayload): FormState {\n const { name } = this\n const payloadValue = payload[name]\n const value =\n this.isValue(payloadValue) &&\n payloadValue.length > 0 &&\n payloadValue.every((v) => {\n return v === 'true'\n })\n\n return { [name]: value }\n }\n\n getContextValueFromFormValue(value: FormValue | FormPayload): boolean {\n return value === 'true'\n }\n\n getFormValue(value?: FormStateValue | FormState) {\n return this.isValue(value) ? value : undefined\n }\n\n getDisplayStringFromFormValue(value: FormValue | FormPayload): string {\n return value === 'true' ? this.declarationConfirmationLabel : 'Not provided'\n }\n\n getViewModel(payload: FormPayload, errors?: FormSubmissionError[]) {\n const defaultDeclarationConfirmationLabel =\n 'I confirm that I understand and accept this declaration'\n const {\n hint,\n content,\n declarationConfirmationLabel = defaultDeclarationConfirmationLabel\n } = this\n\n const viewModel = super.getViewModel(payload, errors)\n let { fieldset, label } = viewModel\n\n fieldset ??= {\n legend: {\n text: label.text,\n classes: 'govuk-fieldset__legend--m'\n }\n }\n\n const payloadValue = payload[this.name]\n const isChecked =\n payloadValue === 'true' ||\n payloadValue === true ||\n (Array.isArray(payloadValue) && payloadValue.some((x) => x === 'true'))\n\n return {\n ...viewModel,\n hint: hint ? { text: hint } : undefined,\n fieldset,\n content,\n items: [\n {\n text: declarationConfirmationLabel,\n value: 'true',\n checked: isChecked\n }\n ],\n headerStartLevel: this.headerStartLevel\n }\n }\n\n isValue(value?: FormStateValue | FormState): value is Item['value'][] {\n if (!Array.isArray(value)) {\n return false\n }\n\n // Skip checks when empty\n if (!value.length) {\n return true\n }\n\n return value.every(isFormValue)\n }\n\n /**\n * For error preview page that shows all possible errors on a component\n */\n getAllPossibleErrors(): ErrorMessageTemplateList {\n return DeclarationField.getAllPossibleErrors()\n }\n\n /**\n * Static version of getAllPossibleErrors that doesn't require a component instance.\n */\n static getAllPossibleErrors(): ErrorMessageTemplateList {\n return {\n baseErrors: [\n { type: 'required', template: messageTemplate.declarationRequired }\n ],\n advancedSettingsErrors: []\n }\n }\n\n static isBool(value?: FormStateValue | FormState): value is boolean {\n return isFormValue(value) && typeof value === 'boolean'\n }\n}\n"],"mappings":"AAAA,SACEA,aAAa,EACbC,iBAAiB,EACjBC,UAAU,QAGL,oBAAoB;AAC3B,OAAOC,GAAG,MAIH,KAAK;AAEZ,SACEC,aAAa,EACbC,WAAW;AAEb,SAASC,eAAe;AAWxB,OAAO,MAAMC,gBAAgB,SAASH,aAAa,CAAC;EACjCI,yBAAyB,GAAG,wBAAwB;EASrEC,gBAAgB;EAEhBC,WAAWA,CACTC,GAA8B,EAC9BC,KAAqD,EACrD;IACA,KAAK,CAACD,GAAG,EAAEC,KAAK,CAAC;IAEjB,MAAM;MAAEC,OAAO;MAAEC;IAAQ,CAAC,GAAGH,GAAG;IAEhC,IAAII,cAAc,GAAGZ,GAAG,CAACa,MAAM,CAAC,CAAC,CAACC,KAAK,CAAC,MAAM,CAAC;IAE/C,IAAIJ,OAAO,CAACK,QAAQ,KAAK,KAAK,EAAE;MAC9BH,cAAc,GAAGA,cAAc,CAACG,QAAQ,CAAC,CAAC;IAC5C;IAEA,MAAMC,UAAU,GAAGhB,GAAG,CACnBiB,KAAK,CAAC,CAAC,CACPC,KAAK,CAACN,cAAc,EAAEZ,GAAG,CAACa,MAAM,CAAC,CAA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,eAAe,CAACoB;MAAoB,CAAC,CACpE;MACDmD,sBAAsB,EAAE;IAC1B,CAAC;EACH;EAEA,OAAOC,MAAMA,CAAC1B,KAAkC,EAAoB;IAClE,OAAO/C,WAAW,CAAC+C,KAAK,CAAC,IAAI,OAAOA,KAAK,KAAK,SAAS;EACzD;AACF","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -293,6 +293,58 @@ describe('DeclarationField', () => {
|
|
|
293
293
|
)
|
|
294
294
|
})
|
|
295
295
|
|
|
296
|
+
it('sets Nunjucks component to true when checked from save-anbd-exit', () => {
|
|
297
|
+
def = {
|
|
298
|
+
...def,
|
|
299
|
+
hint: 'Please read and confirm the following'
|
|
300
|
+
} satisfies DeclarationFieldComponent
|
|
301
|
+
|
|
302
|
+
collection = new ComponentCollection([def], { model })
|
|
303
|
+
field = collection.fields[0]
|
|
304
|
+
const viewModel = field.getViewModel(getFormData(['true', 'unchecked']))
|
|
305
|
+
|
|
306
|
+
expect(viewModel).toEqual(
|
|
307
|
+
expect.objectContaining({
|
|
308
|
+
hint: {
|
|
309
|
+
text: 'Please read and confirm the following'
|
|
310
|
+
},
|
|
311
|
+
items: [
|
|
312
|
+
{
|
|
313
|
+
value: 'true',
|
|
314
|
+
text: 'I understand and agree',
|
|
315
|
+
checked: true
|
|
316
|
+
}
|
|
317
|
+
]
|
|
318
|
+
})
|
|
319
|
+
)
|
|
320
|
+
})
|
|
321
|
+
|
|
322
|
+
it('sets Nunjucks component to false when unchecked from save-anbd-exit', () => {
|
|
323
|
+
def = {
|
|
324
|
+
...def,
|
|
325
|
+
hint: 'Please read and confirm the following'
|
|
326
|
+
} satisfies DeclarationFieldComponent
|
|
327
|
+
|
|
328
|
+
collection = new ComponentCollection([def], { model })
|
|
329
|
+
field = collection.fields[0]
|
|
330
|
+
const viewModel = field.getViewModel(getFormData(['unchecked']))
|
|
331
|
+
|
|
332
|
+
expect(viewModel).toEqual(
|
|
333
|
+
expect.objectContaining({
|
|
334
|
+
hint: {
|
|
335
|
+
text: 'Please read and confirm the following'
|
|
336
|
+
},
|
|
337
|
+
items: [
|
|
338
|
+
{
|
|
339
|
+
value: 'true',
|
|
340
|
+
text: 'I understand and agree',
|
|
341
|
+
checked: false
|
|
342
|
+
}
|
|
343
|
+
]
|
|
344
|
+
})
|
|
345
|
+
)
|
|
346
|
+
})
|
|
347
|
+
|
|
296
348
|
it('sets Nunjucks component value when posted', () => {
|
|
297
349
|
def = {
|
|
298
350
|
...def,
|
|
@@ -137,8 +137,12 @@ export class DeclarationField extends FormComponent {
|
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
+
const payloadValue = payload[this.name]
|
|
140
141
|
const isChecked =
|
|
141
|
-
|
|
142
|
+
payloadValue === 'true' ||
|
|
143
|
+
payloadValue === true ||
|
|
144
|
+
(Array.isArray(payloadValue) && payloadValue.some((x) => x === 'true'))
|
|
145
|
+
|
|
142
146
|
return {
|
|
143
147
|
...viewModel,
|
|
144
148
|
hint: hint ? { text: hint } : undefined,
|