diff --git a/src/server/forms/components.json b/src/server/forms/components.json index 743e4081b..802e90ecf 100644 --- a/src/server/forms/components.json +++ b/src/server/forms/components.json @@ -11,7 +11,9 @@ "name": "textField", "title": "Text field", "hint": "Help text", - "options": {}, + "options": { + "required": false + }, "schema": {} }, { @@ -19,49 +21,63 @@ "name": "multilineTextField", "title": "Multiline text field", "hint": "Help text", - "options": {}, + "options": { + "required": false + }, "schema": {} }, { "type": "NumberField", "name": "numberField", "title": "Number field", - "options": {}, + "options": { + "required": false + }, "schema": {} }, { "type": "DatePartsField", "name": "datePartsField", "title": "Date parts field", - "options": {}, + "options": { + "required": false + }, "schema": {} }, { "type": "YesNoField", "name": "yesNoField", "title": "Yes/No field", - "options": {}, + "options": { + "required": false + }, "schema": {} }, { "type": "EmailAddressField", "name": "emailAddressField", "title": "Email address field", - "options": {}, + "options": { + "required": false + }, "schema": {} }, { "type": "TelephoneNumberField", "name": "telephoneNumberField", "title": "Telephone number field", - "options": {}, + "options": { + "required": false + }, "schema": {} }, { "type": "UkAddressField", "name": "addressField", "title": "UK address field", - "options": {}, + "options": { + "required": false + }, "schema": {} }, { @@ -69,7 +85,9 @@ "name": "radiosField", "title": "Radios field", "list": "companyType", - "options": {}, + "options": { + "required": false + }, "schema": {} }, { @@ -77,17 +95,21 @@ "name": "selectField", "title": "Select field", "list": "country", - "options": {}, + "options": { + "required": false + }, "schema": {} }, { - "options": {}, "list": "horseBreed", "type": "CheckboxesField", "name": "checkboxesField", "title": "Checkboxes field", "hint": "Please help", - "schema": {} + "schema": {}, + "options": { + "required": false + } }, { "type": "Html", @@ -126,7 +148,10 @@ "name": "declaration", "title": "Declaration", "content": "By submitting this form, I agree to:\n\n- Provide accurate and complete information\n- Comply with all applicable regulations\n- Accept responsibility for any false statements", - "hint": "Please read and confirm the following terms" + "hint": "Please read and confirm the following terms", + "options": { + "required": false + } } ] }, diff --git a/src/server/plugins/engine/components/DeclarationField.test.ts b/src/server/plugins/engine/components/DeclarationField.test.ts index ffa163cb8..cab3f77c3 100644 --- a/src/server/plugins/engine/components/DeclarationField.test.ts +++ b/src/server/plugins/engine/components/DeclarationField.test.ts @@ -250,7 +250,8 @@ describe('DeclarationField', () => { id: 'myComponent', fieldset: { legend: { - text: 'Example Declaration Component' + text: 'Example Declaration Component', + classes: 'govuk-fieldset__legend--m' } }, items: [ diff --git a/src/server/plugins/engine/components/DeclarationField.ts b/src/server/plugins/engine/components/DeclarationField.ts index e2930155e..d76fdb00d 100644 --- a/src/server/plugins/engine/components/DeclarationField.ts +++ b/src/server/plugins/engine/components/DeclarationField.ts @@ -105,21 +105,27 @@ export class DeclarationField extends FormComponent { const defaultDeclarationConfirmationLabel = 'I confirm that I understand and accept this declaration' const { - title, hint, content, declarationConfirmationLabel = defaultDeclarationConfirmationLabel } = this + + const viewModel = super.getViewModel(payload, errors) + let { fieldset, label } = viewModel + + fieldset ??= { + legend: { + text: label.text, + classes: 'govuk-fieldset__legend--m' + } + } + const isChecked = payload[this.name] === 'true' || payload[this.name] === true return { - ...super.getViewModel(payload, errors), + ...viewModel, hint: hint ? { text: hint } : undefined, - fieldset: { - legend: { - text: title - } - }, + fieldset, content, items: [ { diff --git a/src/server/plugins/engine/pageControllers/QuestionPageController.test.ts b/src/server/plugins/engine/pageControllers/QuestionPageController.test.ts index 7e20e2696..f7098bd1d 100644 --- a/src/server/plugins/engine/pageControllers/QuestionPageController.test.ts +++ b/src/server/plugins/engine/pageControllers/QuestionPageController.test.ts @@ -582,7 +582,8 @@ describe('QuestionPageController', () => { checkboxesMultiple: [], checkboxesSingleNumber: [], checkboxesMultipleNumber: [], - fileUpload: null + fileUpload: null, + declaration: false }) Object.assign(state, { @@ -609,7 +610,8 @@ describe('QuestionPageController', () => { checkboxesSingle: ['Shetland'], checkboxesMultiple: ['Arabian', 'Shire', 'Race'], checkboxesSingleNumber: [1], - checkboxesMultipleNumber: [0, 1] + checkboxesMultipleNumber: [0, 1], + declaration: true }) request = buildFormContextRequest({ @@ -657,7 +659,8 @@ describe('QuestionPageController', () => { checkboxesMultiple: ['Arabian', 'Shire', 'Race'], checkboxesSingleNumber: [1], checkboxesMultipleNumber: [0, 1], - fileUpload: null + fileUpload: null, + declaration: true }) Object.assign(state, { @@ -729,7 +732,8 @@ describe('QuestionPageController', () => { checkboxesMultiple: ['Arabian', 'Shire', 'Race'], checkboxesSingleNumber: [1], checkboxesMultipleNumber: [0, 1], - fileUpload: ['fd5db541-179c-4107-a4d0-149d09672ffc'] + fileUpload: ['fd5db541-179c-4107-a4d0-149d09672ffc'], + declaration: true }) }) }) diff --git a/test/form/definitions/components-optional.json b/test/form/definitions/components-optional.json new file mode 100644 index 000000000..1af9fc430 --- /dev/null +++ b/test/form/definitions/components-optional.json @@ -0,0 +1,502 @@ +{ + "name": "All components", + "conditions": [], + "startPage": "/all-components", + "pages": [ + { + "path": "/all-components", + "title": "All Components", + "components": [ + { + "type": "TextField", + "name": "textField", + "title": "Text field", + "hint": "Help text", + "options": { + "required": false + }, + "schema": {} + }, + { + "type": "MultilineTextField", + "name": "multilineTextField", + "title": "Multiline text field", + "hint": "Help text", + "options": { + "required": false + }, + "schema": {} + }, + { + "type": "NumberField", + "name": "numberField", + "title": "Number field", + "options": { + "required": false + }, + "schema": {} + }, + { + "type": "DatePartsField", + "name": "datePartsField", + "title": "Date parts field", + "options": { + "required": false + }, + "schema": {} + }, + { + "type": "MonthYearField", + "name": "monthYearField", + "title": "Month year field", + "options": { + "required": false + }, + "schema": {} + }, + { + "type": "YesNoField", + "name": "yesNoField", + "title": "Yes/No field", + "options": { + "required": false + }, + "schema": {} + }, + { + "type": "EmailAddressField", + "name": "emailAddressField", + "title": "Email address field", + "options": { + "required": false + }, + "schema": {} + }, + { + "type": "TelephoneNumberField", + "name": "telephoneNumberField", + "title": "Telephone number field", + "options": { + "required": false + }, + "schema": {} + }, + { + "type": "UkAddressField", + "name": "addressField", + "title": "Address field", + "options": { + "required": false + }, + "schema": {} + }, + { + "type": "RadiosField", + "name": "radiosField", + "title": "Radios field", + "list": "companyType", + "options": { + "required": false + }, + "schema": {} + }, + { + "type": "SelectField", + "name": "selectField", + "title": "Select field", + "list": "country", + "options": { + "required": false + }, + "schema": {} + }, + { + "type": "AutocompleteField", + "name": "autocompleteField", + "title": "Autocomplete field", + "list": "country", + "options": { + "required": false + }, + "schema": {} + }, + { + "list": "horseBreed", + "type": "CheckboxesField", + "name": "checkboxesSingle", + "title": "Checkboxes field 1", + "hint": "Select all that apply.", + "options": { + "required": false + }, + "schema": {} + }, + { + "list": "horseBreed", + "type": "CheckboxesField", + "name": "checkboxesMultiple", + "title": "Checkboxes field 2", + "hint": "Select all that apply.", + "options": { + "required": false + }, + "schema": {} + }, + { + "list": "points", + "type": "CheckboxesField", + "name": "checkboxesSingleNumber", + "title": "Checkboxes field 3 (number)", + "hint": "Select all that apply.", + "options": { + "required": false + }, + "schema": {} + }, + { + "list": "points", + "type": "CheckboxesField", + "name": "checkboxesMultipleNumber", + "title": "Checkboxes field 4 (number)", + "hint": "Select all that apply.", + "options": { + "required": false + }, + "schema": {} + }, + { + "type": "Details", + "name": "details", + "title": "Title", + "content": "Content", + "options": {}, + "schema": {} + }, + { + "type": "Markdown", + "name": "markdown", + "title": "Title", + "content": "### This is a H3 in markdown\n\n[An internal link](http://localhost:3009/fictional-page)\n\n[An external link](https://defra.gov.uk/fictional-page)", + "options": {}, + "schema": {} + }, + { + "type": "DeclarationField", + "name": "declaration", + "title": "Declaration", + "content": "By submitting this form, I agree to:\n\n- Provide accurate and complete information\n- Comply with all applicable regulations\n- Accept responsibility for any false statements", + "hint": "Please read and confirm the following terms", + "options": { + "required": false + } + } + ], + "next": [{ "path": "/methodology-statement" }] + }, + { + "path": "/methodology-statement", + "title": "Upload your methodology statement", + "section": "section", + "controller": "FileUploadPageController", + "components": [ + { + "name": "fileUpload", + "type": "FileUploadField", + "hint": "Upload 2 copies of your methodology statement in Word, PDF or JPEG. The maximum file size for each file is 100MB", + "title": "Upload your methodology statement", + "options": { + "accept": "application/pdf,image/jpeg,image/png" + }, + "schema": { + "min": 1, + "max": 2 + } + } + ], + "next": [ + { + "path": "/summary" + } + ] + }, + { + "path": "/summary", + "title": "Summary", + "components": [], + "next": [], + "controller": "SummaryPageController" + } + ], + "sections": [ + { + "name": "checkBeforeStart", + "title": "Check before you start", + "hideTitle": false + }, + { + "name": "personalDetails", + "title": "Personal details", + "hideTitle": false + }, + { "name": "companyDetails", "title": "Company details", "hideTitle": false } + ], + "lists": [ + { + "name": "yesNoUnsure", + "title": "Yes/No/Not sure", + "type": "string", + "items": [ + { "text": "Yes", "value": "yes" }, + { "text": "No", "value": "no" }, + { "text": "Not sure", "value": "unsure" } + ] + }, + { + "name": "companyType", + "title": "Company type", + "type": "string", + "items": [ + { "text": "Sole trader", "value": "soleTrader" }, + { "text": "Private Limited Company", "value": "privateLimitedCompany" }, + { "text": "Public Limited Company", "value": "publicLimitedCompany" }, + { + "text": "Limited Liability Partnership", + "value": "limitedLiabilityPartnership" + }, + { "text": "Charity", "value": "charity" }, + { "text": "Other", "value": "other" } + ] + }, + { + "name": "country", + "title": "Country", + "type": "number", + "items": [ + { "text": "Afghanistan", "value": 910400000 }, + { "text": "Albania", "value": 910400001 }, + { "text": "Algeria", "value": 910400002 }, + { "text": "Andorra", "value": 910400003 }, + { "text": "Angola", "value": 910400004 }, + { "text": "Antigua and Barbuda", "value": 910400005 }, + { "text": "Argentina", "value": 910400006 }, + { "text": "Armenia", "value": 910400007 }, + { "text": "Australia", "value": 910400008 }, + { "text": "Austria", "value": 910400009 }, + { "text": "Azerbaijan", "value": 910400010 }, + { "text": "Bahrain", "value": 910400011 }, + { "text": "Bangladesh", "value": 910400012 }, + { "text": "Barbados", "value": 910400013 }, + { "text": "Belarus", "value": 910400014 }, + { "text": "Belgium", "value": 910400015 }, + { "text": "Belize", "value": 910400016 }, + { "text": "Benin", "value": 910400017 }, + { "text": "Bhutan", "value": 910400018 }, + { "text": "Bolivia", "value": 910400019 }, + { "text": "Bosnia and Herzegovina", "value": 910400020 }, + { "text": "Botswana", "value": 910400021 }, + { "text": "Brazil", "value": 910400022 }, + { "text": "Brunei", "value": 910400023 }, + { "text": "Bulgaria", "value": 910400024 }, + { "text": "Burkina Faso", "value": 910400025 }, + { "text": "Burma", "value": 910400026 }, + { "text": "Burundi", "value": 910400027 }, + { "text": "Cambodia", "value": 910400028 }, + { "text": "Cameroon", "value": 910400029 }, + { "text": "Canada", "value": 910400030 }, + { "text": "Cape Verde", "value": 910400031 }, + { "text": "Central African Republic", "value": 910400032 }, + { "text": "Chad", "value": 910400033 }, + { "text": "Chile", "value": 910400034 }, + { "text": "China", "value": 910400035 }, + { "text": "Colombia", "value": 910400036 }, + { "text": "Comoros", "value": 910400037 }, + { "text": "Congo", "value": 910400038 }, + { "text": "Congo (Democratic Republic)", "value": 910400039 }, + { "text": "Costa Rica", "value": 910400040 }, + { "text": "Croatia", "value": 910400041 }, + { "text": "Cuba", "value": 910400042 }, + { "text": "Cyprus", "value": 910400043 }, + { "text": "Czech Republic", "value": 910400044 }, + { "text": "Denmark", "value": 910400045 }, + { "text": "Djibouti", "value": 910400046 }, + { "text": "Dominica", "value": 910400047 }, + { "text": "Dominican Republic", "value": 910400048 }, + { "text": "East Timor", "value": 910400049 }, + { "text": "Ecuador", "value": 910400050 }, + { "text": "Egypt", "value": 910400051 }, + { "text": "El Salvador", "value": 910400052 }, + { "text": "Equatorial Guinea", "value": 910400053 }, + { "text": "Eritrea", "value": 910400054 }, + { "text": "Estonia", "value": 910400055 }, + { "text": "Ethiopia", "value": 910400056 }, + { "text": "Fiji", "value": 910400057 }, + { "text": "Finland", "value": 910400058 }, + { "text": "France", "value": 910400059 }, + { "text": "Gabon", "value": 910400060 }, + { "text": "Georgia", "value": 910400061 }, + { "text": "Germany", "value": 910400062 }, + { "text": "Ghana", "value": 910400063 }, + { "text": "Greece", "value": 910400064 }, + { "text": "Grenada", "value": 910400065 }, + { "text": "Guatemala", "value": 910400066 }, + { "text": "Guinea", "value": 910400067 }, + { "text": "Guinea-Bissau", "value": 910400068 }, + { "text": "Guyana", "value": 910400069 }, + { "text": "Haiti", "value": 910400070 }, + { "text": "Honduras", "value": 910400071 }, + { "text": "Hungary", "value": 910400072 }, + { "text": "Iceland", "value": 910400073 }, + { "text": "India", "value": 910400074 }, + { "text": "Indonesia", "value": 910400075 }, + { "text": "Iran", "value": 910400076 }, + { "text": "Iraq", "value": 910400077 }, + { "text": "Ireland", "value": 910400078 }, + { "text": "Israel", "value": 910400079 }, + { "text": "Italy", "value": 910400080 }, + { "text": "Ivory Coast", "value": 910400081 }, + { "text": "Jamaica", "value": 910400082 }, + { "text": "Japan", "value": 910400083 }, + { "text": "Jordan", "value": 910400084 }, + { "text": "Kazakhstan", "value": 910400085 }, + { "text": "Kenya", "value": 910400086 }, + { "text": "Kiribati", "value": 910400087 }, + { "text": "Kosovo", "value": 910400088 }, + { "text": "Kuwait", "value": 910400089 }, + { "text": "Kyrgyzstan", "value": 910400090 }, + { "text": "Laos", "value": 910400091 }, + { "text": "Latvia", "value": 910400092 }, + { "text": "Lebanon", "value": 910400093 }, + { "text": "Lesotho", "value": 910400094 }, + { "text": "Liberia", "value": 910400095 }, + { "text": "Libya", "value": 910400096 }, + { "text": "Liechtenstein", "value": 910400097 }, + { "text": "Lithuania", "value": 910400098 }, + { "text": "Luxembourg", "value": 910400099 }, + { "text": "Macedonia", "value": 910400100 }, + { "text": "Madagascar", "value": 910400101 }, + { "text": "Malawi", "value": 910400102 }, + { "text": "Malaysia", "value": 910400103 }, + { "text": "Maldives", "value": 910400104 }, + { "text": "Mali", "value": 910400105 }, + { "text": "Malta", "value": 910400106 }, + { "text": "Marshall Islands", "value": 910400107 }, + { "text": "Mauritania", "value": 910400108 }, + { "text": "Mauritius", "value": 910400109 }, + { "text": "Mexico", "value": 910400110 }, + { "text": "Micronesia", "value": 910400111 }, + { "text": "Moldova", "value": 910400112 }, + { "text": "Monaco", "value": 910400113 }, + { "text": "Mongolia", "value": 910400114 }, + { "text": "Montenegro", "value": 910400115 }, + { "text": "Morocco", "value": 910400116 }, + { "text": "Mozambique", "value": 910400117 }, + { "text": "Namibia", "value": 910400118 }, + { "text": "Nauru", "value": 910400119 }, + { "text": "Nepal", "value": 910400120 }, + { "text": "Netherlands", "value": 910400121 }, + { "text": "New Zealand", "value": 910400122 }, + { "text": "Nicaragua", "value": 910400123 }, + { "text": "Niger", "value": 910400124 }, + { "text": "Nigeria", "value": 910400125 }, + { "text": "North Korea", "value": 910400126 }, + { "text": "Norway", "value": 910400127 }, + { "text": "Oman", "value": 910400128 }, + { "text": "Pakistan", "value": 910400129 }, + { "text": "Palau", "value": 910400130 }, + { "text": "Panama", "value": 910400131 }, + { "text": "Papua New Guinea", "value": 910400132 }, + { "text": "Paraguay", "value": 910400133 }, + { "text": "Peru", "value": 910400134 }, + { "text": "Philippines", "value": 910400135 }, + { "text": "Poland", "value": 910400136 }, + { "text": "Portugal", "value": 910400137 }, + { "text": "Qatar", "value": 910400138 }, + { "text": "Romania", "value": 910400139 }, + { "text": "Russia", "value": 910400140 }, + { "text": "Rwanda", "value": 910400141 }, + { "text": "Samoa", "value": 910400142 }, + { "text": "San Marino", "value": 910400143 }, + { "text": "Sao Tome and Principe", "value": 910400144 }, + { "text": "Saudi Arabia", "value": 910400145 }, + { "text": "Senegal", "value": 910400146 }, + { "text": "Serbia", "value": 910400147 }, + { "text": "Seychelles", "value": 910400148 }, + { "text": "Sierra Leone", "value": 910400149 }, + { "text": "Singapore", "value": 910400150 }, + { "text": "Slovakia", "value": 910400151 }, + { "text": "Slovenia", "value": 910400152 }, + { "text": "Solomon Islands", "value": 910400153 }, + { "text": "Somalia", "value": 910400154 }, + { "text": "South Africa", "value": 910400155 }, + { "text": "South Korea", "value": 910400156 }, + { "text": "South Sudan", "value": 910400157 }, + { "text": "Spain", "value": 910400158 }, + { "text": "Sri Lanka", "value": 910400159 }, + { "text": "St Kitts and Nevis", "value": 910400160 }, + { "text": "St Lucia", "value": 910400161 }, + { "text": "St Vincent", "value": 910400162 }, + { "text": "Sudan", "value": 910400163 }, + { "text": "Suriname", "value": 910400164 }, + { "text": "Swaziland", "value": 910400165 }, + { "text": "Sweden", "value": 910400166 }, + { "text": "Switzerland", "value": 910400167 }, + { "text": "Syria", "value": 910400168 }, + { "text": "Tajikistan", "value": 910400169 }, + { "text": "Tanzania", "value": 910400170 }, + { "text": "Thailand", "value": 910400171 }, + { "text": "The Bahamas", "value": 910400172 }, + { "text": "The Gambia", "value": 910400173 }, + { "text": "Togo", "value": 910400174 }, + { "text": "Tonga", "value": 910400175 }, + { "text": "Trinidad and Tobago", "value": 910400176 }, + { "text": "Tunisia", "value": 910400177 }, + { "text": "Turkey", "value": 910400178 }, + { "text": "Turkmenistan", "value": 910400179 }, + { "text": "Tuvalu", "value": 910400180 }, + { "text": "Uganda", "value": 910400181 }, + { "text": "Ukraine", "value": 910400182 }, + { "text": "United Arab Emirates", "value": 910400183 }, + { "text": "United Kingdom", "value": 910400184 }, + { "text": "United States", "value": 910400185 }, + { "text": "Uruguay", "value": 910400186 }, + { "text": "Uzbekistan", "value": 910400187 }, + { "text": "Vanuatu", "value": 910400188 }, + { "text": "Vatican City", "value": 910400189 }, + { "text": "Venezuela", "value": 910400190 }, + { "text": "Vietnam", "value": 910400191 }, + { "text": "Yemen", "value": 910400192 }, + { "text": "Zambia", "value": 910400193 }, + { "text": "Zimbabwe", "value": 910400194 }, + { "text": "England", "value": 910400195 }, + { "text": "Wales", "value": 910400196 }, + { "text": "Scotland", "value": 910400197 }, + { "text": "Northern Ireland", "value": 910400198 } + ] + }, + { + "name": "horseBreed", + "title": "Horse breed", + "type": "string", + "items": [ + { "text": "Arabian", "value": "Arabian" }, + { "text": "Patomine", "value": "Patomine" }, + { "text": "Shire", "value": "Shire" }, + { "text": "Shetland", "value": "Shetland" }, + { "text": "Race", "value": "Race" } + ] + }, + { + "name": "points", + "title": "Number of points", + "type": "number", + "items": [ + { "text": "None", "value": 0 }, + { "text": "1 point", "value": 1 }, + { "text": "2 points", "value": 2 }, + { "text": "3 points", "value": 3 }, + { "text": "4 points", "value": 4 } + ] + } + ], + "outputEmail": "enrique.chase@defra.gov.uk" +} diff --git a/test/form/definitions/components.json b/test/form/definitions/components.json index f725bebfd..313af108f 100644 --- a/test/form/definitions/components.json +++ b/test/form/definitions/components.json @@ -139,6 +139,22 @@ "content": "Content", "options": {}, "schema": {} + }, + { + "type": "Markdown", + "name": "markdown", + "title": "Title", + "content": "### This is a H3 in markdown\n\n[An internal link](http://localhost:3009/fictional-page)\n\n[An external link](https://defra.gov.uk/fictional-page)", + "options": {}, + "schema": {} + }, + { + "type": "DeclarationField", + "name": "declaration", + "title": "Declaration", + "content": "By submitting this form, I agree to:\n\n- Provide accurate and complete information\n- Comply with all applicable regulations\n- Accept responsibility for any false statements", + "hint": "Please read and confirm the following terms", + "options": {} } ], "next": [{ "path": "/methodology-statement" }] diff --git a/test/form/definitions/fields-optional.js b/test/form/definitions/fields-optional.js index 074b0af80..beaca2f1a 100644 --- a/test/form/definitions/fields-optional.js +++ b/test/form/definitions/fields-optional.js @@ -130,6 +130,23 @@ export default /** @satisfies {FormDefinition} */ ({ title: 'Title', content: 'Content', options: {} + }, + { + type: ComponentType.Markdown, + name: 'Markdown', + title: 'Title', + content: + '### This is a H3 in markdown\n\n[An internal link](http://localhost:3009/fictional-page)\n\n[An external link](https://defra.gov.uk/fictional-page)', + options: {} + }, + { + type: ComponentType.DeclarationField, + name: 'declaration', + title: 'Declaration', + content: + 'By submitting this form, I agree to:\n\n- Provide accurate and complete information\n- Comply with all applicable regulations\n- Accept responsibility for any false statements', + hint: 'Please read and confirm the following terms', + options: { required: false } } ], next: [ diff --git a/test/form/definitions/fields-required.js b/test/form/definitions/fields-required.js index 57a3acf37..fa5ea16e3 100644 --- a/test/form/definitions/fields-required.js +++ b/test/form/definitions/fields-required.js @@ -130,6 +130,23 @@ export default /** @satisfies {FormDefinition} */ ({ title: 'Title', content: 'Content', options: {} + }, + { + type: ComponentType.Markdown, + name: 'Markdown', + title: 'Title', + content: + '### This is a H3 in markdown\n\n[An internal link](http://localhost:3009/fictional-page)\n\n[An external link](https://defra.gov.uk/fictional-page)', + options: {} + }, + { + type: ComponentType.DeclarationField, + name: 'declaration', + title: 'Declaration', + content: + 'By submitting this form, I agree to:\n\n- Provide accurate and complete information\n- Comply with all applicable regulations\n- Accept responsibility for any false statements', + hint: 'Please read and confirm the following terms', + options: {} } ], next: [ diff --git a/test/form/fields-optional.test.js b/test/form/fields-optional.test.js index 61c8c1833..c79af3af7 100644 --- a/test/form/fields-optional.test.js +++ b/test/form/fields-optional.test.js @@ -148,6 +148,13 @@ describe('Form fields (optional)', () => { payload: { empty: {} } + }, + { + name: 'declaration', + title: 'Declaration', + payload: { + empty: { declaration: 'unchecked' } + } } ] } @@ -212,6 +219,13 @@ describe('Form fields (optional)', () => { expect($heading).toBeInTheDocument() }) + it('should render the field label with (optional)', () => { + for (const field of fields) { + const $label = container.getByText(`${field.title} (optional)`) + expect($label).toBeInTheDocument() + } + }) + it('should redirect to the next page on submit', async () => { const payload = {} diff --git a/test/form/fields-required.test.js b/test/form/fields-required.test.js index b2b146446..b032d7af0 100644 --- a/test/form/fields-required.test.js +++ b/test/form/fields-required.test.js @@ -179,6 +179,14 @@ describe('Form fields (required)', () => { empty: {}, valid: { checkboxesMultipleNumber: '1' } } + }, + { + name: 'declaration', + title: 'Declaration', + payload: { + empty: {}, + valid: { declaration: 'true' } + } } ] } @@ -243,6 +251,13 @@ describe('Form fields (required)', () => { expect($heading).toBeInTheDocument() }) + it('should render the field label without (optional)', () => { + for (const field of fields) { + const $label = container.getByText(field.title) + expect($label).toBeInTheDocument() + } + }) + it('should show errors when invalid on submit', async () => { const payload = {} diff --git a/test/form/govuk-notify.test.js b/test/form/govuk-notify.test.js index 7a4b1b3b7..22efc6aa1 100644 --- a/test/form/govuk-notify.test.js +++ b/test/form/govuk-notify.test.js @@ -123,8 +123,6 @@ describe('Submission journey test', () => { personalisation: { subject: 'Form submission: All components', body: expect.stringContaining(outdent` - --- - ## Text field Text field @@ -228,6 +226,12 @@ describe('Submission journey test', () => { --- + ## Declaration + + I understand and agree + + --- + ## Upload your methodology statement Uploaded 1 file: @@ -322,6 +326,11 @@ describe('Submission journey test', () => { title: 'Checkboxes field 4 (number)', value: '0,1' }, + { + name: 'declaration', + title: 'Declaration', + value: 'true' + }, { name: 'fileUpload', title: 'Upload your methodology statement', @@ -365,7 +374,8 @@ describe('Submission journey test', () => { checkboxesSingle: 'Shetland', checkboxesMultiple: ['Arabian', 'Shire', 'Race'], checkboxesSingleNumber: 1, - checkboxesMultipleNumber: [0, 1] + checkboxesMultipleNumber: [0, 1], + declaration: 'true' } // POST the form data to set the state