@ukhomeoffice/cop-react-form-renderer 5.14.2 → 5.14.4

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.
Files changed (328) hide show
  1. package/dist/components/CheckYourAnswers/Answer.js +15 -15
  2. package/dist/components/CheckYourAnswers/Answer.test.js +94 -128
  3. package/dist/components/CheckYourAnswers/CheckYourAnswers.js +99 -129
  4. package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +291 -501
  5. package/dist/components/CheckYourAnswers/index.js +2 -3
  6. package/dist/components/CollectionPage/CollectionPage.js +64 -58
  7. package/dist/components/CollectionPage/CollectionPage.test.js +212 -238
  8. package/dist/components/CollectionPage/index.js +2 -3
  9. package/dist/components/FormComponent/Collection.js +77 -113
  10. package/dist/components/FormComponent/Collection.test.js +688 -787
  11. package/dist/components/FormComponent/Container.js +44 -43
  12. package/dist/components/FormComponent/Container.test.js +316 -346
  13. package/dist/components/FormComponent/FormComponent.js +58 -64
  14. package/dist/components/FormComponent/FormComponent.test.js +180 -219
  15. package/dist/components/FormComponent/helpers/addLabel.js +5 -9
  16. package/dist/components/FormComponent/helpers/getComponentDisabled.js +2 -3
  17. package/dist/components/FormComponent/helpers/getComponentDisabled.test.js +8 -8
  18. package/dist/components/FormComponent/helpers/getComponentError.js +4 -7
  19. package/dist/components/FormComponent/helpers/getComponentError.test.js +15 -15
  20. package/dist/components/FormComponent/helpers/getComponentFieldSet.js +2 -2
  21. package/dist/components/FormComponent/helpers/getComponentFieldSet.test.js +7 -7
  22. package/dist/components/FormComponent/helpers/index.js +5 -5
  23. package/dist/components/FormComponent/index.js +2 -3
  24. package/dist/components/FormPage/FormPage.js +65 -79
  25. package/dist/components/FormPage/FormPage.test.js +134 -170
  26. package/dist/components/FormPage/index.js +2 -3
  27. package/dist/components/FormRenderer/FormRenderer.js +151 -193
  28. package/dist/components/FormRenderer/FormRenderer.test.js +598 -920
  29. package/dist/components/FormRenderer/handlers/cyaAction.js +4 -5
  30. package/dist/components/FormRenderer/handlers/getPageId.js +2 -5
  31. package/dist/components/FormRenderer/handlers/getPageId.test.js +15 -15
  32. package/dist/components/FormRenderer/handlers/handlers.test.js +33 -33
  33. package/dist/components/FormRenderer/handlers/index.js +3 -4
  34. package/dist/components/FormRenderer/handlers/navigate.js +5 -6
  35. package/dist/components/FormRenderer/handlers/submissionError.js +2 -3
  36. package/dist/components/FormRenderer/helpers/canActionProceed.js +2 -3
  37. package/dist/components/FormRenderer/helpers/canActionProceed.test.js +10 -10
  38. package/dist/components/FormRenderer/helpers/canCYASubmit.js +2 -5
  39. package/dist/components/FormRenderer/helpers/canCYASubmit.test.js +17 -21
  40. package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.js +19 -27
  41. package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.test.js +17 -17
  42. package/dist/components/FormRenderer/helpers/getCYA.js +6 -9
  43. package/dist/components/FormRenderer/helpers/getCYA.test.js +12 -12
  44. package/dist/components/FormRenderer/helpers/getFormState.js +7 -10
  45. package/dist/components/FormRenderer/helpers/getFormState.test.js +11 -11
  46. package/dist/components/FormRenderer/helpers/getNextPageId.js +19 -34
  47. package/dist/components/FormRenderer/helpers/getNextPageId.test.js +68 -68
  48. package/dist/components/FormRenderer/helpers/getPage.js +3 -6
  49. package/dist/components/FormRenderer/helpers/getPage.test.js +12 -12
  50. package/dist/components/FormRenderer/helpers/getRelevantPages.js +9 -13
  51. package/dist/components/FormRenderer/helpers/getRelevantPages.test.js +15 -15
  52. package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +12 -13
  53. package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +98 -92
  54. package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.js +66 -66
  55. package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.test.js +72 -79
  56. package/dist/components/FormRenderer/helpers/index.js +3 -4
  57. package/dist/components/FormRenderer/index.js +2 -3
  58. package/dist/components/FormRenderer/onCYAAction.js +52 -62
  59. package/dist/components/FormRenderer/onCYAAction.test.js +146 -138
  60. package/dist/components/FormRenderer/onPageAction.js +48 -47
  61. package/dist/components/FormRenderer/onPageAction.test.js +219 -205
  62. package/dist/components/FormRenderer/onTaskAction.js +12 -17
  63. package/dist/components/FormRenderer/onTaskAction.test.js +94 -89
  64. package/dist/components/PageActions/ActionButton.js +15 -19
  65. package/dist/components/PageActions/ActionButton.test.js +58 -79
  66. package/dist/components/PageActions/PageActions.js +12 -13
  67. package/dist/components/PageActions/PageActions.test.js +88 -116
  68. package/dist/components/PageActions/index.js +2 -3
  69. package/dist/components/SummaryList/GroupAction.js +15 -23
  70. package/dist/components/SummaryList/GroupAction.test.js +41 -37
  71. package/dist/components/SummaryList/RowAction.js +14 -19
  72. package/dist/components/SummaryList/RowAction.test.js +41 -37
  73. package/dist/components/SummaryList/SummaryList.js +25 -30
  74. package/dist/components/SummaryList/SummaryList.test.js +160 -182
  75. package/dist/components/SummaryList/SummaryListHeadingRow.js +9 -8
  76. package/dist/components/SummaryList/SummaryListRow.js +9 -8
  77. package/dist/components/SummaryList/SummaryListTitleRow.js +8 -7
  78. package/dist/components/SummaryList/helpers/getGroupActionAttributes.js +5 -8
  79. package/dist/components/SummaryList/helpers/getGroupActionAttributes.test.js +24 -24
  80. package/dist/components/SummaryList/helpers/getRowActionAttributes.js +5 -8
  81. package/dist/components/SummaryList/helpers/getRowActionAttributes.test.js +24 -24
  82. package/dist/components/SummaryList/helpers/index.js +2 -2
  83. package/dist/components/SummaryList/index.js +2 -3
  84. package/dist/components/TaskList/Task.js +22 -33
  85. package/dist/components/TaskList/Task.test.js +84 -77
  86. package/dist/components/TaskList/TaskList.js +46 -75
  87. package/dist/components/TaskList/TaskList.test.js +118 -113
  88. package/dist/components/TaskList/TaskState.js +9 -9
  89. package/dist/components/TaskList/TaskState.test.js +56 -49
  90. package/dist/components/TaskList/index.js +2 -3
  91. package/dist/components/index.js +8 -8
  92. package/dist/context/HooksContext/HooksContext.js +59 -85
  93. package/dist/context/HooksContext/HooksContext.test.js +28 -36
  94. package/dist/context/HooksContext/index.js +4 -6
  95. package/dist/context/ValidationContext/ValidationContext.js +35 -76
  96. package/dist/context/ValidationContext/ValidationContext.test.js +50 -61
  97. package/dist/context/ValidationContext/index.js +4 -6
  98. package/dist/context/index.js +3 -3
  99. package/dist/hooks/index.js +10 -11
  100. package/dist/hooks/useAxios.js +17 -43
  101. package/dist/hooks/useGetRequest.js +61 -106
  102. package/dist/hooks/useHooks.js +2 -5
  103. package/dist/hooks/useRefData.js +29 -45
  104. package/dist/hooks/useValidation.js +2 -5
  105. package/dist/index.js +15 -17
  106. package/dist/models/CollectionLabels.js +2 -3
  107. package/dist/models/ComponentTypes.js +25 -26
  108. package/dist/models/EventTypes.js +5 -6
  109. package/dist/models/FormPages.js +5 -6
  110. package/dist/models/FormTypes.js +9 -10
  111. package/dist/models/HubFormats.js +4 -5
  112. package/dist/models/PageAction.js +45 -42
  113. package/dist/models/TaskStates.js +30 -31
  114. package/dist/models/index.js +11 -12
  115. package/dist/setupTests.js +20 -24
  116. package/dist/utils/CheckYourAnswers/getCYAAction.js +6 -7
  117. package/dist/utils/CheckYourAnswers/getCYAAction.test.js +53 -55
  118. package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.js +18 -20
  119. package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.test.js +21 -23
  120. package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.js +17 -21
  121. package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.test.js +18 -20
  122. package/dist/utils/CheckYourAnswers/getCYARow.js +8 -10
  123. package/dist/utils/CheckYourAnswers/getCYARow.test.js +72 -72
  124. package/dist/utils/CheckYourAnswers/getCYARowForGroup.js +20 -27
  125. package/dist/utils/CheckYourAnswers/getCYARowForGroup.test.js +16 -17
  126. package/dist/utils/CheckYourAnswers/getCYARowsForCollection.js +41 -47
  127. package/dist/utils/CheckYourAnswers/getCYARowsForCollection.test.js +72 -75
  128. package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +71 -78
  129. package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +133 -114
  130. package/dist/utils/CheckYourAnswers/getCYARowsForContainer.js +27 -23
  131. package/dist/utils/CheckYourAnswers/getCYARowsForContainer.test.js +112 -106
  132. package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +16 -23
  133. package/dist/utils/CheckYourAnswers/getCYARowsForPage.test.js +77 -83
  134. package/dist/utils/CheckYourAnswers/index.js +3 -4
  135. package/dist/utils/CheckYourAnswers/showComponentCYA.js +7 -9
  136. package/dist/utils/CheckYourAnswers/showComponentCYA.test.js +25 -25
  137. package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.js +9 -16
  138. package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.test.js +19 -20
  139. package/dist/utils/CollectionPage/getCollectionPageActiveIndex.js +4 -8
  140. package/dist/utils/CollectionPage/getCollectionPageActiveIndex.test.js +15 -15
  141. package/dist/utils/CollectionPage/index.js +3 -4
  142. package/dist/utils/CollectionPage/mergeCollectionPages.js +26 -29
  143. package/dist/utils/CollectionPage/mergeCollectionPages.test.js +15 -15
  144. package/dist/utils/Component/addShowWhen.js +5 -10
  145. package/dist/utils/Component/addShowWhen.test.js +38 -38
  146. package/dist/utils/Component/applyToComponentTree.js +20 -22
  147. package/dist/utils/Component/applyToComponentTree.test.js +28 -33
  148. package/dist/utils/Component/cleanAttributes.js +11 -16
  149. package/dist/utils/Component/cleanAttributes.test.js +17 -18
  150. package/dist/utils/Component/elevateNestedComponents.js +7 -9
  151. package/dist/utils/Component/elevateNestedComponents.test.js +19 -19
  152. package/dist/utils/Component/getComponent.js +91 -99
  153. package/dist/utils/Component/getComponentTests/getComponent.autocomplete.test.js +19 -18
  154. package/dist/utils/Component/getComponentTests/getComponent.calculation.test.js +51 -63
  155. package/dist/utils/Component/getComponentTests/getComponent.checkboxes.test.js +41 -49
  156. package/dist/utils/Component/getComponentTests/getComponent.date.test.js +33 -37
  157. package/dist/utils/Component/getComponentTests/getComponent.details.test.js +21 -19
  158. package/dist/utils/Component/getComponentTests/getComponent.email.test.js +19 -23
  159. package/dist/utils/Component/getComponentTests/getComponent.file.test.js +23 -27
  160. package/dist/utils/Component/getComponentTests/getComponent.heading.test.js +12 -11
  161. package/dist/utils/Component/getComponentTests/getComponent.html.test.js +18 -16
  162. package/dist/utils/Component/getComponentTests/getComponent.insetText.test.js +10 -9
  163. package/dist/utils/Component/getComponentTests/getComponent.list.test.js +18 -16
  164. package/dist/utils/Component/getComponentTests/getComponent.multifile.test.js +24 -27
  165. package/dist/utils/Component/getComponentTests/getComponent.nested.test.js +156 -175
  166. package/dist/utils/Component/getComponentTests/getComponent.paragraph.test.js +18 -16
  167. package/dist/utils/Component/getComponentTests/getComponent.phoneNumber.test.js +19 -23
  168. package/dist/utils/Component/getComponentTests/getComponent.radios.test.js +59 -73
  169. package/dist/utils/Component/getComponentTests/getComponent.select.test.js +19 -23
  170. package/dist/utils/Component/getComponentTests/getComponent.text.test.js +19 -23
  171. package/dist/utils/Component/getComponentTests/getComponent.textArea.test.js +35 -41
  172. package/dist/utils/Component/getComponentTests/getComponent.time.test.js +24 -32
  173. package/dist/utils/Component/getComponentTests/getComponent.unknown.test.js +3 -3
  174. package/dist/utils/Component/getComponentTests/getComponent.warningText.test.js +10 -9
  175. package/dist/utils/Component/getDefaultValue.js +7 -9
  176. package/dist/utils/Component/getDefaultValue.test.js +14 -14
  177. package/dist/utils/Component/index.js +3 -4
  178. package/dist/utils/Component/isEditable.js +3 -7
  179. package/dist/utils/Component/isEditable.test.js +14 -15
  180. package/dist/utils/Component/optionIsSelected.js +2 -3
  181. package/dist/utils/Component/optionIsSelected.test.js +10 -10
  182. package/dist/utils/Component/setupContainerComponentsPath.js +30 -33
  183. package/dist/utils/Component/setupContainerComponentsPath.test.js +16 -16
  184. package/dist/utils/Component/showComponent.js +4 -6
  185. package/dist/utils/Component/showComponent.test.js +29 -29
  186. package/dist/utils/Component/wrapInFormGroup.js +6 -6
  187. package/dist/utils/Condition/index.js +3 -4
  188. package/dist/utils/Condition/meetsAllConditions.js +9 -10
  189. package/dist/utils/Condition/meetsAllConditions.test.js +18 -18
  190. package/dist/utils/Condition/meetsCondition.js +19 -27
  191. package/dist/utils/Condition/meetsCondition.test.js +377 -377
  192. package/dist/utils/Condition/meetsOneCondition.js +7 -8
  193. package/dist/utils/Condition/meetsOneCondition.test.js +17 -17
  194. package/dist/utils/Condition/setupConditions.js +15 -21
  195. package/dist/utils/Condition/setupConditions.test.js +8 -8
  196. package/dist/utils/Container/getEditableComponents.js +5 -8
  197. package/dist/utils/Container/getEditableComponents.test.js +44 -46
  198. package/dist/utils/Container/index.js +3 -4
  199. package/dist/utils/Container/setupNesting.js +17 -24
  200. package/dist/utils/Container/setupNesting.test.js +28 -31
  201. package/dist/utils/Container/showContainer.js +5 -10
  202. package/dist/utils/Container/showContainer.test.js +31 -31
  203. package/dist/utils/Data/applyFormula.js +41 -52
  204. package/dist/utils/Data/applyFormula.test.js +26 -26
  205. package/dist/utils/Data/getAutocompleteSource.js +11 -14
  206. package/dist/utils/Data/getAutocompleteSource.test.js +59 -59
  207. package/dist/utils/Data/getDataPath.js +21 -32
  208. package/dist/utils/Data/getDataPath.test.js +20 -20
  209. package/dist/utils/Data/getOptions.js +22 -28
  210. package/dist/utils/Data/getOptions.test.js +21 -21
  211. package/dist/utils/Data/getSourceData.js +7 -21
  212. package/dist/utils/Data/getSourceData.test.js +85 -81
  213. package/dist/utils/Data/index.js +3 -4
  214. package/dist/utils/Data/refDataToOptions.js +12 -17
  215. package/dist/utils/Data/refDataToOptions.test.js +20 -20
  216. package/dist/utils/Data/setDataItem.js +8 -10
  217. package/dist/utils/Data/setDataItem.test.js +38 -38
  218. package/dist/utils/Data/setupFormData.js +32 -48
  219. package/dist/utils/Data/setupFormData.test.js +99 -98
  220. package/dist/utils/Data/setupRefDataUrlForComponent.js +22 -30
  221. package/dist/utils/Data/setupRefDataUrlForComponent.test.js +28 -28
  222. package/dist/utils/FormPage/applyConditionalProperties.js +7 -12
  223. package/dist/utils/FormPage/applyConditionalProperties.test.js +16 -19
  224. package/dist/utils/FormPage/getFormPage.js +17 -19
  225. package/dist/utils/FormPage/getFormPage.test.js +49 -48
  226. package/dist/utils/FormPage/getFormPages.js +9 -15
  227. package/dist/utils/FormPage/getFormPages.test.js +22 -25
  228. package/dist/utils/FormPage/getPageActions.js +11 -19
  229. package/dist/utils/FormPage/getPageActions.test.js +33 -33
  230. package/dist/utils/FormPage/getParagraphFromText.js +6 -9
  231. package/dist/utils/FormPage/getParagraphFromText.test.js +7 -7
  232. package/dist/utils/FormPage/index.js +3 -4
  233. package/dist/utils/FormPage/showFormPage.js +5 -10
  234. package/dist/utils/FormPage/showFormPage.test.js +33 -33
  235. package/dist/utils/FormPage/showFormPageCYA.js +4 -5
  236. package/dist/utils/FormPage/showFormPageCYA.test.js +9 -9
  237. package/dist/utils/FormPage/useComponent.js +21 -29
  238. package/dist/utils/FormPage/useComponent.test.js +71 -73
  239. package/dist/utils/Format/formatData.js +2 -3
  240. package/dist/utils/Format/formatData.test.js +19 -19
  241. package/dist/utils/Format/formatDataForComponent.js +6 -9
  242. package/dist/utils/Format/formatDataForComponent.test.js +50 -78
  243. package/dist/utils/Format/formatDataForForm.js +7 -10
  244. package/dist/utils/Format/formatDataForForm.test.js +14 -17
  245. package/dist/utils/Format/formatDataForPage.js +4 -7
  246. package/dist/utils/Format/formatDataForPage.test.js +20 -25
  247. package/dist/utils/Format/index.js +3 -4
  248. package/dist/utils/Hub/getFormHub.js +3 -4
  249. package/dist/utils/Hub/getFormHub.test.js +29 -32
  250. package/dist/utils/Hub/index.js +3 -4
  251. package/dist/utils/Meta/constants.js +2 -4
  252. package/dist/utils/Meta/documents/getDocuments.js +2 -6
  253. package/dist/utils/Meta/documents/getDocuments.test.js +25 -17
  254. package/dist/utils/Meta/documents/index.js +3 -4
  255. package/dist/utils/Meta/documents/setDocumentsForField.js +16 -19
  256. package/dist/utils/Meta/documents/setDocumentsForField.test.js +69 -35
  257. package/dist/utils/Meta/index.js +3 -4
  258. package/dist/utils/Operate/checkValueIsTruthy.js +5 -6
  259. package/dist/utils/Operate/checkValueIsTruthy.test.js +17 -17
  260. package/dist/utils/Operate/getFirstOf.js +9 -10
  261. package/dist/utils/Operate/getFirstOf.test.js +33 -33
  262. package/dist/utils/Operate/getIndexOfMatchingValueIn.js +13 -14
  263. package/dist/utils/Operate/getIndexOfMatchingValueIn.test.js +47 -53
  264. package/dist/utils/Operate/index.js +3 -4
  265. package/dist/utils/Operate/persistValueInFormData.js +7 -8
  266. package/dist/utils/Operate/persistValueInFormData.test.js +23 -21
  267. package/dist/utils/Operate/runPageOperations.js +10 -11
  268. package/dist/utils/Operate/runPageOperations.test.js +36 -37
  269. package/dist/utils/Operate/setValueInFormData.js +6 -7
  270. package/dist/utils/Operate/setValueInFormData.test.js +17 -17
  271. package/dist/utils/Operate/shouldRun.js +9 -10
  272. package/dist/utils/Operate/shouldRun.test.js +22 -28
  273. package/dist/utils/Validate/additional/conditionallyRequired.js +5 -7
  274. package/dist/utils/Validate/additional/conditionallyRequired.test.js +19 -19
  275. package/dist/utils/Validate/additional/index.js +8 -9
  276. package/dist/utils/Validate/additional/index.test.js +13 -13
  277. package/dist/utils/Validate/additional/mustBeAfter.js +4 -5
  278. package/dist/utils/Validate/additional/mustBeAfter.test.js +41 -41
  279. package/dist/utils/Validate/additional/mustBeBefore.js +4 -5
  280. package/dist/utils/Validate/additional/mustBeBefore.test.js +29 -29
  281. package/dist/utils/Validate/additional/mustBeEarlierDateTime.js +8 -14
  282. package/dist/utils/Validate/additional/mustBeEarlierDateTime.test.js +34 -38
  283. package/dist/utils/Validate/additional/mustBeGreaterThan.js +3 -4
  284. package/dist/utils/Validate/additional/mustBeGreaterThan.test.js +19 -19
  285. package/dist/utils/Validate/additional/mustBeInTheFuture.js +5 -6
  286. package/dist/utils/Validate/additional/mustBeInTheFuture.test.js +13 -13
  287. package/dist/utils/Validate/additional/mustBeInThePast.js +6 -7
  288. package/dist/utils/Validate/additional/mustBeInThePast.test.js +13 -13
  289. package/dist/utils/Validate/additional/mustBeLessThan.js +3 -4
  290. package/dist/utils/Validate/additional/mustBeLessThan.test.js +18 -18
  291. package/dist/utils/Validate/additional/mustBeLongerThan.js +2 -3
  292. package/dist/utils/Validate/additional/mustBeLongerThan.test.js +17 -17
  293. package/dist/utils/Validate/additional/mustBeNumbersOnly.js +3 -4
  294. package/dist/utils/Validate/additional/mustBeNumbersOnly.test.js +21 -21
  295. package/dist/utils/Validate/additional/mustBeShorterThan.js +2 -3
  296. package/dist/utils/Validate/additional/mustBeShorterThan.test.js +17 -17
  297. package/dist/utils/Validate/additional/mustEnterAtLeastOne.js +4 -7
  298. package/dist/utils/Validate/additional/mustEnterAtLeastOne.test.js +15 -17
  299. package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.js +2 -3
  300. package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.test.js +13 -13
  301. package/dist/utils/Validate/additional/mustSelectOnlyOne.js +4 -7
  302. package/dist/utils/Validate/additional/mustSelectOnlyOne.test.js +29 -27
  303. package/dist/utils/Validate/additional/utils.js +9 -25
  304. package/dist/utils/Validate/index.js +3 -4
  305. package/dist/utils/Validate/validateCollection.js +22 -29
  306. package/dist/utils/Validate/validateCollection.test.js +85 -77
  307. package/dist/utils/Validate/validateComponent.js +19 -19
  308. package/dist/utils/Validate/validateComponent.test.js +169 -147
  309. package/dist/utils/Validate/validateContainer.js +16 -22
  310. package/dist/utils/Validate/validateContainer.test.js +52 -48
  311. package/dist/utils/Validate/validateDate.js +14 -21
  312. package/dist/utils/Validate/validateDate.test.js +28 -29
  313. package/dist/utils/Validate/validateEmail.js +8 -11
  314. package/dist/utils/Validate/validateEmail.test.js +26 -26
  315. package/dist/utils/Validate/validateMultifile.js +6 -10
  316. package/dist/utils/Validate/validateMultifile.test.js +17 -18
  317. package/dist/utils/Validate/validatePage.js +20 -22
  318. package/dist/utils/Validate/validatePage.test.js +146 -143
  319. package/dist/utils/Validate/validateRegex.js +6 -10
  320. package/dist/utils/Validate/validateRegex.test.js +17 -17
  321. package/dist/utils/Validate/validateRequired.js +6 -9
  322. package/dist/utils/Validate/validateRequired.test.js +19 -19
  323. package/dist/utils/Validate/validateTextArea.js +6 -9
  324. package/dist/utils/Validate/validateTextArea.test.js +21 -21
  325. package/dist/utils/Validate/validateTime.js +8 -16
  326. package/dist/utils/Validate/validateTime.test.js +15 -15
  327. package/dist/utils/index.js +10 -12
  328. package/package.json +9 -6
@@ -2,56 +2,50 @@
2
2
 
3
3
  var _models = require("../../models");
4
4
  var _validatePage = _interopRequireDefault(require("./validatePage"));
5
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
7
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
8
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
9
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
10
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
11
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
12
- describe('utils.Validate.Page', function () {
13
- var setup = function setup(id, type, label, required) {
14
- return {
15
- id: id,
16
- fieldId: id,
17
- type: type,
18
- label: label,
19
- required: required
20
- };
21
- };
22
- describe('with FormPage', function () {
23
- it('should return no error when the components array is null', function () {
24
- var PAGE = {
5
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
6
+ // Local imports
7
+
8
+ describe('utils.Validate.Page', () => {
9
+ const setup = (id, type, label, required) => ({
10
+ id,
11
+ fieldId: id,
12
+ type,
13
+ label,
14
+ required
15
+ });
16
+ describe('with FormPage', () => {
17
+ it('should return no error when the components array is null', () => {
18
+ const PAGE = {
25
19
  components: null,
26
20
  formData: null
27
21
  };
28
22
  expect((0, _validatePage.default)(PAGE).length).toEqual(0);
29
23
  });
30
- it('should return no error when the components array is empty', function () {
31
- var PAGE = {
24
+ it('should return no error when the components array is empty', () => {
25
+ const PAGE = {
32
26
  components: [],
33
27
  formData: null
34
28
  };
35
29
  expect((0, _validatePage.default)(PAGE).length).toEqual(0);
36
30
  });
37
- describe('when there is no form data', function () {
38
- it('should return no errors when no components are required', function () {
39
- var COMPONENTS = [setup('a', _models.ComponentTypes.TEXT, 'Alpha', false), setup('b', _models.ComponentTypes.TEXT, 'Bravo', false)];
40
- var PAGE = {
31
+ describe('when there is no form data', () => {
32
+ it('should return no errors when no components are required', () => {
33
+ const COMPONENTS = [setup('a', _models.ComponentTypes.TEXT, 'Alpha', false), setup('b', _models.ComponentTypes.TEXT, 'Bravo', false)];
34
+ const PAGE = {
41
35
  components: COMPONENTS,
42
36
  formData: null
43
37
  };
44
38
  expect((0, _validatePage.default)(PAGE).length).toEqual(0);
45
39
  });
46
- it('should return an error for each required component', function () {
47
- var COMPONENTS = [setup('a', _models.ComponentTypes.TEXT, 'Alpha', true), setup('b', _models.ComponentTypes.TEXT, 'Bravo', true), setup('c', _models.ComponentTypes.TEXT, 'Charlie', false),
40
+ it('should return an error for each required component', () => {
41
+ const COMPONENTS = [setup('a', _models.ComponentTypes.TEXT, 'Alpha', true), setup('b', _models.ComponentTypes.TEXT, 'Bravo', true), setup('c', _models.ComponentTypes.TEXT, 'Charlie', false),
48
42
  // The only unrequired one
49
43
  setup('d', _models.ComponentTypes.TEXT, 'Delta', true), setup('e', _models.ComponentTypes.TEXT, 'Echo', true)];
50
- var PAGE = {
44
+ const PAGE = {
51
45
  components: COMPONENTS,
52
46
  formData: null
53
47
  };
54
- var RESULT = (0, _validatePage.default)(PAGE);
48
+ const RESULT = (0, _validatePage.default)(PAGE);
55
49
  expect(RESULT.length).toEqual(4);
56
50
  expect(RESULT[0]).toEqual({
57
51
  id: 'a',
@@ -70,18 +64,18 @@ describe('utils.Validate.Page', function () {
70
64
  error: 'Echo is required'
71
65
  });
72
66
  });
73
- it('should return an error for each required component on a collection page', function () {
74
- var COMPONENTS = [setup('a', _models.ComponentTypes.TEXT, 'Alpha', true), setup('b', _models.ComponentTypes.TEXT, 'Bravo', true), setup('c', _models.ComponentTypes.TEXT, 'Charlie', false),
67
+ it('should return an error for each required component on a collection page', () => {
68
+ const COMPONENTS = [setup('a', _models.ComponentTypes.TEXT, 'Alpha', true), setup('b', _models.ComponentTypes.TEXT, 'Bravo', true), setup('c', _models.ComponentTypes.TEXT, 'Charlie', false),
75
69
  // The only unrequired one
76
70
  setup('d', _models.ComponentTypes.TEXT, 'Delta', true), setup('e', _models.ComponentTypes.TEXT, 'Echo', true)];
77
- var PAGE = {
71
+ const PAGE = {
78
72
  components: COMPONENTS,
79
73
  collection: {
80
74
  name: 'testCollection'
81
75
  },
82
76
  formData: null
83
77
  };
84
- var RESULT = (0, _validatePage.default)(PAGE);
78
+ const RESULT = (0, _validatePage.default)(PAGE);
85
79
  expect(RESULT.length).toEqual(4);
86
80
  expect(RESULT[0]).toEqual({
87
81
  id: 'a',
@@ -100,8 +94,8 @@ describe('utils.Validate.Page', function () {
100
94
  error: 'Echo is required'
101
95
  });
102
96
  });
103
- it('should return an error for each required component with interpolated label', function () {
104
- var COMPONENTS = [
97
+ it('should return an error for each required component with interpolated label', () => {
98
+ const COMPONENTS = [
105
99
  // eslint-disable-next-line no-template-curly-in-string
106
100
  setup('a', _models.ComponentTypes.TEXT, 'Alpha ${tiger}', true),
107
101
  // eslint-disable-next-line no-template-curly-in-string
@@ -112,7 +106,7 @@ describe('utils.Validate.Page', function () {
112
106
  setup('d', _models.ComponentTypes.CHECKBOXES, 'Delta ${lion}', true),
113
107
  // eslint-disable-next-line no-template-curly-in-string
114
108
  setup('e', _models.ComponentTypes.FILE, 'Echo ${zoo}', true)];
115
- var PAGE = {
109
+ const PAGE = {
116
110
  components: COMPONENTS,
117
111
  formData: {
118
112
  tiger: 'Tiger',
@@ -122,114 +116,114 @@ describe('utils.Validate.Page', function () {
122
116
  zoo: 'Zoo'
123
117
  }
124
118
  };
125
- var RESULT = (0, _validatePage.default)(PAGE);
119
+ const RESULT = (0, _validatePage.default)(PAGE);
126
120
  expect(RESULT.length).toEqual(5);
127
121
  expect(RESULT[0]).toEqual({
128
122
  id: 'a',
129
- error: "Alpha ".concat(PAGE.formData.tiger, " is required")
123
+ error: `Alpha ${PAGE.formData.tiger} is required`
130
124
  });
131
125
  expect(RESULT[1]).toEqual({
132
126
  id: 'b',
133
- error: "Bravo ".concat(PAGE.formData.panther, " is required")
127
+ error: `Bravo ${PAGE.formData.panther} is required`
134
128
  });
135
129
  expect(RESULT[2]).toEqual({
136
130
  id: 'c',
137
- error: "Charlie ".concat(PAGE.formData.eagle, " is required")
131
+ error: `Charlie ${PAGE.formData.eagle} is required`
138
132
  });
139
133
  expect(RESULT[3]).toEqual({
140
134
  id: 'd',
141
- error: "Delta ".concat(PAGE.formData.lion, " is required")
135
+ error: `Delta ${PAGE.formData.lion} is required`
142
136
  });
143
137
  expect(RESULT[4]).toEqual({
144
138
  id: 'e',
145
- error: "Echo ".concat(PAGE.formData.zoo, " is required")
139
+ error: `Echo ${PAGE.formData.zoo} is required`
146
140
  });
147
141
  });
148
142
  });
149
- describe('when the form data is fully valid', function () {
150
- var DATA = {
143
+ describe('when the form data is fully valid', () => {
144
+ const DATA = {
151
145
  alpha: 'alpha.smith@digital.homeoffice.gov.uk',
152
146
  bravo: 'bravo.jones@digital.homeoffice.gov.uk'
153
147
  };
154
- it('should return no errors when none of the components are required or email types', function () {
155
- var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', false), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', false)];
156
- var PAGE = {
148
+ it('should return no errors when none of the components are required or email types', () => {
149
+ const COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', false), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', false)];
150
+ const PAGE = {
157
151
  components: COMPONENTS,
158
152
  formData: DATA
159
153
  };
160
154
  expect((0, _validatePage.default)(PAGE).length).toEqual(0);
161
155
  });
162
- it('should return no errors when all of the components are required but not email types', function () {
163
- var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', true), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', true)];
164
- var PAGE = {
156
+ it('should return no errors when all of the components are required but not email types', () => {
157
+ const COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', true), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', true)];
158
+ const PAGE = {
165
159
  components: COMPONENTS,
166
160
  formData: DATA
167
161
  };
168
162
  expect((0, _validatePage.default)(PAGE).length).toEqual(0);
169
163
  });
170
- it('should return no errors when none of the components are required but are all email types', function () {
171
- var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', false), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', false)];
172
- var PAGE = {
164
+ it('should return no errors when none of the components are required but are all email types', () => {
165
+ const COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', false), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', false)];
166
+ const PAGE = {
173
167
  components: COMPONENTS,
174
168
  formData: DATA
175
169
  };
176
170
  expect((0, _validatePage.default)(PAGE).length).toEqual(0);
177
171
  });
178
- it('should return no errors when all of the components are required and email types', function () {
179
- var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', true)];
180
- var PAGE = {
172
+ it('should return no errors when all of the components are required and email types', () => {
173
+ const COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', true)];
174
+ const PAGE = {
181
175
  components: COMPONENTS,
182
176
  formData: DATA
183
177
  };
184
178
  expect((0, _validatePage.default)(PAGE).length).toEqual(0);
185
179
  });
186
180
  });
187
- describe('when the form data has one field missing and includes an invalid email', function () {
188
- var DATA = {
181
+ describe('when the form data has one field missing and includes an invalid email', () => {
182
+ const DATA = {
189
183
  alpha: 'alpha.smith@digital.homeoffice.gov.uk',
190
184
  bravo: 'bravo.jones@hotmail.com'
191
185
  };
192
- it('should return no errors when none of the components are required or email types', function () {
193
- var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', false), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', false), setup('charlie', _models.ComponentTypes.TEXT, 'Charlie', false)];
194
- var PAGE = {
186
+ it('should return no errors when none of the components are required or email types', () => {
187
+ const COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', false), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', false), setup('charlie', _models.ComponentTypes.TEXT, 'Charlie', false)];
188
+ const PAGE = {
195
189
  components: COMPONENTS,
196
190
  formData: null
197
191
  };
198
192
  expect((0, _validatePage.default)(PAGE).length).toEqual(0);
199
193
  });
200
- it('should return an error for the missing field when all are required but not email types', function () {
201
- var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', true), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', true), setup('charlie', _models.ComponentTypes.TEXT, 'Charlie', true)];
202
- var PAGE = {
194
+ it('should return an error for the missing field when all are required but not email types', () => {
195
+ const COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', true), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', true), setup('charlie', _models.ComponentTypes.TEXT, 'Charlie', true)];
196
+ const PAGE = {
203
197
  components: COMPONENTS,
204
198
  formData: DATA
205
199
  };
206
- var RESULT = (0, _validatePage.default)(PAGE);
200
+ const RESULT = (0, _validatePage.default)(PAGE);
207
201
  expect(RESULT.length).toEqual(1);
208
202
  expect(RESULT[0]).toEqual({
209
203
  id: 'charlie',
210
204
  error: 'Charlie is required'
211
205
  });
212
206
  });
213
- it('should return an error for the invalid email field when none are required but all email types', function () {
214
- var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', false), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', false), setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie', false)];
215
- var PAGE = {
207
+ it('should return an error for the invalid email field when none are required but all email types', () => {
208
+ const COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', false), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', false), setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie', false)];
209
+ const PAGE = {
216
210
  components: COMPONENTS,
217
211
  formData: DATA
218
212
  };
219
- var RESULT = (0, _validatePage.default)(PAGE);
213
+ const RESULT = (0, _validatePage.default)(PAGE);
220
214
  expect(RESULT.length).toEqual(1);
221
215
  expect(RESULT[0]).toEqual({
222
216
  id: 'bravo',
223
217
  error: 'Enter bravo in the correct format, like jane.doe@homeoffice.gov.uk'
224
218
  });
225
219
  });
226
- it('should return an error for both invalid fields when all are required and email types', function () {
227
- var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', true), setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie', true)];
228
- var PAGE = {
220
+ it('should return an error for both invalid fields when all are required and email types', () => {
221
+ const COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', true), setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie', true)];
222
+ const PAGE = {
229
223
  components: COMPONENTS,
230
224
  formData: DATA
231
225
  };
232
- var RESULT = (0, _validatePage.default)(PAGE);
226
+ const RESULT = (0, _validatePage.default)(PAGE);
233
227
  expect(RESULT.length).toEqual(2);
234
228
  expect(RESULT[0]).toEqual({
235
229
  id: 'bravo',
@@ -240,84 +234,87 @@ describe('utils.Validate.Page', function () {
240
234
  error: 'Charlie is required'
241
235
  });
242
236
  });
243
- it('should return an interpolated error for both invalid fields when all are required and email types', function () {
244
- var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true),
237
+ it('should return an interpolated error for both invalid fields when all are required and email types', () => {
238
+ const COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true),
245
239
  // eslint-disable-next-line no-template-curly-in-string
246
240
  setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo ${lion}', true),
247
241
  // eslint-disable-next-line no-template-curly-in-string
248
242
  setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie ${panther}', true)];
249
- var PAGE = {
243
+ const PAGE = {
250
244
  components: COMPONENTS,
251
- formData: _objectSpread(_objectSpread({}, DATA), {}, {
245
+ formData: {
246
+ ...DATA,
252
247
  lion: 'Lion',
253
248
  panther: 'Panther'
254
- })
249
+ }
255
250
  };
256
- var RESULT = (0, _validatePage.default)(PAGE);
251
+ const RESULT = (0, _validatePage.default)(PAGE);
257
252
  expect(RESULT.length).toEqual(2);
258
253
  expect(RESULT[0]).toEqual({
259
254
  id: 'bravo',
260
- error: "Enter bravo ".concat(PAGE.formData.lion, " in the correct format, like jane.doe@homeoffice.gov.uk")
255
+ error: `Enter bravo ${PAGE.formData.lion} in the correct format, like jane.doe@homeoffice.gov.uk`
261
256
  });
262
257
  expect(RESULT[1]).toEqual({
263
258
  id: 'charlie',
264
- error: "Charlie ".concat(PAGE.formData.panther, " is required")
259
+ error: `Charlie ${PAGE.formData.panther} is required`
265
260
  });
266
261
  });
267
262
  });
268
263
  });
269
- describe('with CollectionPage', function () {
270
- var COLLECTION = {
264
+ describe('with CollectionPage', () => {
265
+ const COLLECTION = {
271
266
  name: 'pageCollection'
272
267
  };
273
- describe('when the form data is fully valid', function () {
274
- var _DATA;
275
- var DATA = (_DATA = {}, _defineProperty(_DATA, "".concat(COLLECTION.name, "ActiveId"), '01'), _defineProperty(_DATA, COLLECTION.name, [{
276
- id: '01',
277
- alpha: 'alpha.smith@digital.homeoffice.gov.uk',
278
- bravo: 'bravo.jones@digital.homeoffice.gov.uk'
279
- }]), _DATA);
280
- it('should return no errors when none of the components are required or email types', function () {
281
- var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', false), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', false)];
282
- var PAGE = {
268
+ describe('when the form data is fully valid', () => {
269
+ const DATA = {
270
+ [`${COLLECTION.name}ActiveId`]: '01',
271
+ [COLLECTION.name]: [{
272
+ id: '01',
273
+ alpha: 'alpha.smith@digital.homeoffice.gov.uk',
274
+ bravo: 'bravo.jones@digital.homeoffice.gov.uk'
275
+ }]
276
+ };
277
+ it('should return no errors when none of the components are required or email types', () => {
278
+ const COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', false), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', false)];
279
+ const PAGE = {
283
280
  collection: COLLECTION,
284
281
  components: COMPONENTS,
285
282
  formData: DATA
286
283
  };
287
284
  expect((0, _validatePage.default)(PAGE).length).toEqual(0);
288
285
  });
289
- it('should return no errors when all of the components are required but not email types', function () {
290
- var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', true), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', true)];
291
- var PAGE = {
286
+ it('should return no errors when all of the components are required but not email types', () => {
287
+ const COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', true), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', true)];
288
+ const PAGE = {
292
289
  collection: COLLECTION,
293
290
  components: COMPONENTS,
294
291
  formData: DATA
295
292
  };
296
293
  expect((0, _validatePage.default)(PAGE).length).toEqual(0);
297
294
  });
298
- it('should return no errors when none of the components are required but are all email types', function () {
299
- var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', false), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', false)];
300
- var PAGE = {
295
+ it('should return no errors when none of the components are required but are all email types', () => {
296
+ const COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', false), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', false)];
297
+ const PAGE = {
301
298
  collection: COLLECTION,
302
299
  components: COMPONENTS,
303
300
  formData: DATA
304
301
  };
305
302
  expect((0, _validatePage.default)(PAGE).length).toEqual(0);
306
303
  });
307
- it('should return no errors when all of the components are required and email types', function () {
308
- var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', true)];
309
- var PAGE = {
304
+ it('should return no errors when all of the components are required and email types', () => {
305
+ const COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', true)];
306
+ const PAGE = {
310
307
  collection: COLLECTION,
311
308
  components: COMPONENTS,
312
309
  formData: DATA
313
310
  };
314
311
  expect((0, _validatePage.default)(PAGE).length).toEqual(0);
315
312
  });
316
- it('should return an error for each required component on a collection page with a show_when that is true', function () {
317
- var COMPONENTS = [setup('a', _models.ComponentTypes.TEXT, 'Alpha', true), setup('b', _models.ComponentTypes.TEXT, 'Bravo', true), setup('c', _models.ComponentTypes.TEXT, 'Charlie', false),
313
+ it('should return an error for each required component on a collection page with a show_when that is true', () => {
314
+ const COMPONENTS = [setup('a', _models.ComponentTypes.TEXT, 'Alpha', true), setup('b', _models.ComponentTypes.TEXT, 'Bravo', true), setup('c', _models.ComponentTypes.TEXT, 'Charlie', false),
318
315
  // The only unrequired one
319
316
  setup('d', _models.ComponentTypes.TEXT, 'Delta', true), setup('e', _models.ComponentTypes.TEXT, 'Echo', true)];
320
- var PAGE = {
317
+ const PAGE = {
321
318
  components: COMPONENTS,
322
319
  collection: {
323
320
  name: 'testCollection'
@@ -335,7 +332,7 @@ describe('utils.Validate.Page', function () {
335
332
  }]
336
333
  }
337
334
  };
338
- var RESULT = (0, _validatePage.default)(PAGE);
335
+ const RESULT = (0, _validatePage.default)(PAGE);
339
336
  expect(RESULT.length).toEqual(4);
340
337
  expect(RESULT[0]).toEqual({
341
338
  id: 'a',
@@ -354,11 +351,11 @@ describe('utils.Validate.Page', function () {
354
351
  error: 'Echo is required'
355
352
  });
356
353
  });
357
- it('should return no errors on a collection page with a show_when that is false', function () {
358
- var COMPONENTS = [setup('a', _models.ComponentTypes.TEXT, 'Alpha', true), setup('b', _models.ComponentTypes.TEXT, 'Bravo', true), setup('c', _models.ComponentTypes.TEXT, 'Charlie', false),
354
+ it('should return no errors on a collection page with a show_when that is false', () => {
355
+ const COMPONENTS = [setup('a', _models.ComponentTypes.TEXT, 'Alpha', true), setup('b', _models.ComponentTypes.TEXT, 'Bravo', true), setup('c', _models.ComponentTypes.TEXT, 'Charlie', false),
359
356
  // The only unrequired one
360
357
  setup('d', _models.ComponentTypes.TEXT, 'Delta', true), setup('e', _models.ComponentTypes.TEXT, 'Echo', true)];
361
- var PAGE = {
358
+ const PAGE = {
362
359
  components: COMPONENTS,
363
360
  collection: {
364
361
  name: 'testCollection'
@@ -376,62 +373,64 @@ describe('utils.Validate.Page', function () {
376
373
  }]
377
374
  }
378
375
  };
379
- var RESULT = (0, _validatePage.default)(PAGE);
376
+ const RESULT = (0, _validatePage.default)(PAGE);
380
377
  expect(RESULT.length).toEqual(0);
381
378
  });
382
379
  });
383
- describe('when the form data has one field missing and includes an invalid email', function () {
384
- var _DATA2;
385
- var DATA = (_DATA2 = {}, _defineProperty(_DATA2, "".concat(COLLECTION.name, "ActiveId"), '01'), _defineProperty(_DATA2, COLLECTION.name, [{
386
- id: '01',
387
- alpha: 'alpha.smith@digital.homeoffice.gov.uk',
388
- bravo: 'bravo.jones@hotmail.com'
389
- }]), _DATA2);
390
- it('should return no errors when none of the components are required or email types', function () {
391
- var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', false), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', false), setup('charlie', _models.ComponentTypes.TEXT, 'Charlie', false)];
392
- var PAGE = {
380
+ describe('when the form data has one field missing and includes an invalid email', () => {
381
+ const DATA = {
382
+ [`${COLLECTION.name}ActiveId`]: '01',
383
+ [COLLECTION.name]: [{
384
+ id: '01',
385
+ alpha: 'alpha.smith@digital.homeoffice.gov.uk',
386
+ bravo: 'bravo.jones@hotmail.com'
387
+ }]
388
+ };
389
+ it('should return no errors when none of the components are required or email types', () => {
390
+ const COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', false), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', false), setup('charlie', _models.ComponentTypes.TEXT, 'Charlie', false)];
391
+ const PAGE = {
393
392
  collection: COLLECTION,
394
393
  components: COMPONENTS,
395
394
  formData: null
396
395
  };
397
396
  expect((0, _validatePage.default)(PAGE).length).toEqual(0);
398
397
  });
399
- it('should return an error for the missing field when all are required but not email types', function () {
400
- var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', true), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', true), setup('charlie', _models.ComponentTypes.TEXT, 'Charlie', true)];
401
- var PAGE = {
398
+ it('should return an error for the missing field when all are required but not email types', () => {
399
+ const COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', true), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', true), setup('charlie', _models.ComponentTypes.TEXT, 'Charlie', true)];
400
+ const PAGE = {
402
401
  collection: COLLECTION,
403
402
  components: COMPONENTS,
404
403
  formData: DATA
405
404
  };
406
- var RESULT = (0, _validatePage.default)(PAGE);
405
+ const RESULT = (0, _validatePage.default)(PAGE);
407
406
  expect(RESULT.length).toEqual(1);
408
407
  expect(RESULT[0]).toEqual({
409
408
  id: 'charlie',
410
409
  error: 'Charlie is required'
411
410
  });
412
411
  });
413
- it('should return an error for the invalid email field when none are required but all email types', function () {
414
- var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', false), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', false), setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie', false)];
415
- var PAGE = {
412
+ it('should return an error for the invalid email field when none are required but all email types', () => {
413
+ const COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', false), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', false), setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie', false)];
414
+ const PAGE = {
416
415
  collection: COLLECTION,
417
416
  components: COMPONENTS,
418
417
  formData: DATA
419
418
  };
420
- var RESULT = (0, _validatePage.default)(PAGE);
419
+ const RESULT = (0, _validatePage.default)(PAGE);
421
420
  expect(RESULT.length).toEqual(1);
422
421
  expect(RESULT[0]).toEqual({
423
422
  id: 'bravo',
424
423
  error: 'Enter bravo in the correct format, like jane.doe@homeoffice.gov.uk'
425
424
  });
426
425
  });
427
- it('should return an error for both invalid fields when all are required and email types', function () {
428
- var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', true), setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie', true)];
429
- var PAGE = {
426
+ it('should return an error for both invalid fields when all are required and email types', () => {
427
+ const COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', true), setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie', true)];
428
+ const PAGE = {
430
429
  collection: COLLECTION,
431
430
  components: COMPONENTS,
432
431
  formData: DATA
433
432
  };
434
- var RESULT = (0, _validatePage.default)(PAGE);
433
+ const RESULT = (0, _validatePage.default)(PAGE);
435
434
  expect(RESULT.length).toEqual(2);
436
435
  expect(RESULT[0]).toEqual({
437
436
  id: 'bravo',
@@ -442,29 +441,33 @@ describe('utils.Validate.Page', function () {
442
441
  error: 'Charlie is required'
443
442
  });
444
443
  });
445
- it('should return an interpolated error for both invalid fields when all are required and email types', function () {
446
- var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true),
444
+ it('should return an interpolated error for both invalid fields when all are required and email types', () => {
445
+ const COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true),
447
446
  // eslint-disable-next-line no-template-curly-in-string
448
447
  setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo ${lion}', true),
449
448
  // eslint-disable-next-line no-template-curly-in-string
450
449
  setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie ${panther}', true)];
451
- var PAGE = {
450
+ const PAGE = {
452
451
  collection: COLLECTION,
453
452
  components: COMPONENTS,
454
- formData: _objectSpread(_objectSpread({}, DATA), {}, _defineProperty({}, COLLECTION.name, [_objectSpread(_objectSpread({}, DATA[COLLECTION.name][0]), {}, {
455
- lion: 'Lion',
456
- panther: 'Panther'
457
- })]))
453
+ formData: {
454
+ ...DATA,
455
+ [COLLECTION.name]: [{
456
+ ...DATA[COLLECTION.name][0],
457
+ lion: 'Lion',
458
+ panther: 'Panther'
459
+ }]
460
+ }
458
461
  };
459
- var RESULT = (0, _validatePage.default)(PAGE);
462
+ const RESULT = (0, _validatePage.default)(PAGE);
460
463
  expect(RESULT.length).toEqual(2);
461
464
  expect(RESULT[0]).toEqual({
462
465
  id: 'bravo',
463
- error: "Enter bravo ".concat(PAGE.formData[COLLECTION.name][0].lion, " in the correct format, like jane.doe@homeoffice.gov.uk")
466
+ error: `Enter bravo ${PAGE.formData[COLLECTION.name][0].lion} in the correct format, like jane.doe@homeoffice.gov.uk`
464
467
  });
465
468
  expect(RESULT[1]).toEqual({
466
469
  id: 'charlie',
467
- error: "Charlie ".concat(PAGE.formData[COLLECTION.name][0].panther, " is required")
470
+ error: `Charlie ${PAGE.formData[COLLECTION.name][0].panther} is required`
468
471
  });
469
472
  });
470
473
  });
@@ -15,21 +15,18 @@ exports.default = void 0;
15
15
  * @param {array} customErrors The array of custom errors for the component.
16
16
  * @returns An error if the value doesn't match the regex pattern.
17
17
  */
18
- var validateRegex = function validateRegex(value, label, pattern, customErrors) {
18
+ const validateRegex = (value, label, pattern, customErrors) => {
19
19
  if (!value) {
20
20
  return undefined;
21
21
  }
22
22
  if (typeof value === 'string') {
23
- var regex = new RegExp(pattern);
23
+ const regex = new RegExp(pattern);
24
24
  if (regex.test(value)) {
25
25
  return undefined;
26
26
  }
27
27
  if (Array.isArray(customErrors)) {
28
- var _result$;
29
- var result = customErrors.filter(function (error) {
30
- return error.type === 'pattern';
31
- });
32
- if (result !== null && result !== void 0 && (_result$ = result[0]) !== null && _result$ !== void 0 && _result$.message) {
28
+ const result = customErrors.filter(error => error.type === 'pattern');
29
+ if (result?.[0]?.message) {
33
30
  return result[0].message;
34
31
  }
35
32
  }
@@ -37,7 +34,6 @@ var validateRegex = function validateRegex(value, label, pattern, customErrors)
37
34
  if (!label) {
38
35
  return 'Component failed regex validation';
39
36
  }
40
- return "".concat(label, " failed regex validation");
37
+ return `${label} failed regex validation`;
41
38
  };
42
- var _default = validateRegex;
43
- exports.default = _default;
39
+ var _default = exports.default = validateRegex;