@ukhomeoffice/cop-react-form-renderer 5.45.2-alpha → 5.48.1-alpha

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 (353) hide show
  1. package/dist/components/CheckYourAnswers/Answer.js +12 -12
  2. package/dist/components/CheckYourAnswers/Answer.test.js +127 -92
  3. package/dist/components/CheckYourAnswers/CheckYourAnswers.js +131 -101
  4. package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +769 -464
  5. package/dist/components/CollectionPage/CollectionPage.js +58 -66
  6. package/dist/components/CollectionPage/CollectionPage.test.js +342 -300
  7. package/dist/components/CollectionSummary/BannerStrip.js +12 -12
  8. package/dist/components/CollectionSummary/BannerStrip.test.js +59 -63
  9. package/dist/components/CollectionSummary/CollectionSummary.js +88 -61
  10. package/dist/components/CollectionSummary/CollectionSummary.test.js +96 -102
  11. package/dist/components/CollectionSummary/Confirmation.js +12 -14
  12. package/dist/components/CollectionSummary/Confirmation.test.js +63 -68
  13. package/dist/components/CollectionSummary/SummaryCard.js +148 -109
  14. package/dist/components/CollectionSummary/SummaryCard.scss +1 -1
  15. package/dist/components/CollectionSummary/SummaryCard.test.js +927 -905
  16. package/dist/components/CollectionSummary/SummaryCardValidationContext.js +29 -23
  17. package/dist/components/CollectionSummary/SummaryCardValidationContext.test.js +73 -61
  18. package/dist/components/FormComponent/Collection.js +107 -73
  19. package/dist/components/FormComponent/Collection.test.js +945 -809
  20. package/dist/components/FormComponent/Container.js +38 -40
  21. package/dist/components/FormComponent/Container.test.js +345 -314
  22. package/dist/components/FormComponent/FormComponent.js +70 -67
  23. package/dist/components/FormComponent/FormComponent.test.js +342 -284
  24. package/dist/components/FormComponent/helpers/addLabel.js +7 -4
  25. package/dist/components/FormComponent/helpers/getComponentDisabled.js +1 -1
  26. package/dist/components/FormComponent/helpers/getComponentDisabled.test.js +7 -7
  27. package/dist/components/FormComponent/helpers/getComponentError.js +5 -3
  28. package/dist/components/FormComponent/helpers/getComponentError.test.js +14 -14
  29. package/dist/components/FormComponent/helpers/getComponentFieldSet.js +4 -3
  30. package/dist/components/FormComponent/helpers/getComponentFieldSet.test.js +6 -6
  31. package/dist/components/FormComponent/helpers/index.js +4 -4
  32. package/dist/components/FormPage/FormPage.js +80 -65
  33. package/dist/components/FormPage/FormPage.test.js +163 -127
  34. package/dist/components/FormRenderer/FormRenderer.js +181 -144
  35. package/dist/components/FormRenderer/FormRenderer.test.js +1115 -730
  36. package/dist/components/FormRenderer/handlers/cyaAction.js +2 -2
  37. package/dist/components/FormRenderer/handlers/getPageId.js +3 -1
  38. package/dist/components/FormRenderer/handlers/getPageId.test.js +14 -14
  39. package/dist/components/FormRenderer/handlers/handlers.test.js +32 -32
  40. package/dist/components/FormRenderer/handlers/index.js +1 -1
  41. package/dist/components/FormRenderer/handlers/navigate.js +3 -3
  42. package/dist/components/FormRenderer/handlers/submissionError.js +1 -1
  43. package/dist/components/FormRenderer/helpers/canActionProceed.js +5 -1
  44. package/dist/components/FormRenderer/helpers/canActionProceed.test.js +47 -11
  45. package/dist/components/FormRenderer/helpers/canCYASubmit.js +3 -1
  46. package/dist/components/FormRenderer/helpers/canCYASubmit.test.js +20 -16
  47. package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.js +22 -17
  48. package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.test.js +16 -16
  49. package/dist/components/FormRenderer/helpers/getCYA.js +5 -3
  50. package/dist/components/FormRenderer/helpers/getCYA.test.js +11 -11
  51. package/dist/components/FormRenderer/helpers/getFormState.js +7 -5
  52. package/dist/components/FormRenderer/helpers/getFormState.test.js +10 -10
  53. package/dist/components/FormRenderer/helpers/getNextPageId.js +24 -13
  54. package/dist/components/FormRenderer/helpers/getNextPageId.test.js +67 -67
  55. package/dist/components/FormRenderer/helpers/getPage.js +4 -2
  56. package/dist/components/FormRenderer/helpers/getPage.test.js +11 -11
  57. package/dist/components/FormRenderer/helpers/getRelevantPages.js +9 -7
  58. package/dist/components/FormRenderer/helpers/getRelevantPages.test.js +14 -14
  59. package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +5 -5
  60. package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +91 -97
  61. package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.js +60 -62
  62. package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.test.js +73 -71
  63. package/dist/components/FormRenderer/helpers/index.js +1 -1
  64. package/dist/components/FormRenderer/onCYAAction.js +51 -59
  65. package/dist/components/FormRenderer/onCYAAction.test.js +152 -164
  66. package/dist/components/FormRenderer/onPageAction.js +40 -44
  67. package/dist/components/FormRenderer/onPageAction.test.js +206 -223
  68. package/dist/components/FormRenderer/onTaskAction.js +13 -9
  69. package/dist/components/FormRenderer/onTaskAction.test.js +88 -93
  70. package/dist/components/PageActions/ActionButton.js +15 -12
  71. package/dist/components/PageActions/ActionButton.test.js +78 -56
  72. package/dist/components/PageActions/PageActions.js +10 -10
  73. package/dist/components/PageActions/PageActions.test.js +115 -86
  74. package/dist/components/SummaryList/GroupAction.js +17 -9
  75. package/dist/components/SummaryList/GroupAction.test.js +33 -37
  76. package/dist/components/SummaryList/RowAction.js +16 -11
  77. package/dist/components/SummaryList/RowAction.test.js +33 -37
  78. package/dist/components/SummaryList/SummaryList.js +26 -21
  79. package/dist/components/SummaryList/SummaryList.test.js +166 -143
  80. package/dist/components/SummaryList/SummaryListHeadingRow.js +4 -6
  81. package/dist/components/SummaryList/SummaryListRow.js +4 -6
  82. package/dist/components/SummaryList/SummaryListTitleRow.js +3 -5
  83. package/dist/components/SummaryList/helpers/getGroupActionAttributes.js +5 -3
  84. package/dist/components/SummaryList/helpers/getGroupActionAttributes.test.js +22 -22
  85. package/dist/components/SummaryList/helpers/getRowActionAttributes.js +5 -3
  86. package/dist/components/SummaryList/helpers/getRowActionAttributes.test.js +22 -22
  87. package/dist/components/SummaryList/helpers/index.js +1 -1
  88. package/dist/components/TaskList/Task.js +29 -19
  89. package/dist/components/TaskList/Task.test.js +76 -83
  90. package/dist/components/TaskList/TaskList.js +71 -45
  91. package/dist/components/TaskList/TaskList.test.js +111 -113
  92. package/dist/components/TaskList/TaskState.js +5 -7
  93. package/dist/components/TaskList/TaskState.test.js +45 -52
  94. package/dist/components/index.js +7 -7
  95. package/dist/context/HooksContext/HooksContext.js +79 -58
  96. package/dist/context/HooksContext/HooksContext.test.js +35 -26
  97. package/dist/context/HooksContext/index.js +4 -3
  98. package/dist/context/ValidationContext/ValidationContext.js +72 -32
  99. package/dist/context/ValidationContext/ValidationContext.test.js +59 -47
  100. package/dist/context/ValidationContext/index.js +4 -3
  101. package/dist/context/index.js +2 -2
  102. package/dist/hooks/index.js +10 -9
  103. package/dist/hooks/useAxios.js +40 -14
  104. package/dist/hooks/useGetRequest.js +97 -61
  105. package/dist/hooks/useHooks.js +3 -1
  106. package/dist/hooks/useRefData.js +39 -26
  107. package/dist/hooks/useValidation.js +3 -1
  108. package/dist/index.js +14 -13
  109. package/dist/models/CollectionLabels.js +1 -1
  110. package/dist/models/ComponentTypes.js +25 -25
  111. package/dist/models/EventTypes.js +4 -4
  112. package/dist/models/FormPages.js +4 -4
  113. package/dist/models/FormTypes.js +8 -8
  114. package/dist/models/HubFormats.js +3 -3
  115. package/dist/models/PageAction.js +38 -44
  116. package/dist/models/TaskStates.js +28 -30
  117. package/dist/models/index.js +9 -9
  118. package/dist/setupTests.js +31 -30
  119. package/dist/utils/CheckYourAnswers/getCYAAction.js +5 -5
  120. package/dist/utils/CheckYourAnswers/getCYAAction.test.js +54 -52
  121. package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.js +25 -15
  122. package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.test.js +35 -33
  123. package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.js +31 -17
  124. package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.test.js +44 -42
  125. package/dist/utils/CheckYourAnswers/getCYARow.js +6 -6
  126. package/dist/utils/CheckYourAnswers/getCYARow.test.js +86 -86
  127. package/dist/utils/CheckYourAnswers/getCYARowForGroup.js +24 -18
  128. package/dist/utils/CheckYourAnswers/getCYARowForGroup.test.js +16 -15
  129. package/dist/utils/CheckYourAnswers/getCYARowsForCollection.js +36 -33
  130. package/dist/utils/CheckYourAnswers/getCYARowsForCollection.test.js +60 -58
  131. package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +88 -79
  132. package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +124 -146
  133. package/dist/utils/CheckYourAnswers/getCYARowsForContainer.js +20 -25
  134. package/dist/utils/CheckYourAnswers/getCYARowsForContainer.test.js +97 -103
  135. package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +18 -13
  136. package/dist/utils/CheckYourAnswers/getCYARowsForPage.test.js +76 -70
  137. package/dist/utils/CheckYourAnswers/index.js +1 -1
  138. package/dist/utils/CheckYourAnswers/showComponentCYA.js +4 -4
  139. package/dist/utils/CheckYourAnswers/showComponentCYA.test.js +24 -24
  140. package/dist/utils/CollectionPage/addCollectionPageEntry.js +1 -1
  141. package/dist/utils/CollectionPage/addCollectionPageEntry.test.js +5 -5
  142. package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.js +2 -2
  143. package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.test.js +17 -17
  144. package/dist/utils/CollectionPage/duplicateCollectionPageEntry.js +18 -9
  145. package/dist/utils/CollectionPage/duplicateCollectionPageEntry.test.js +22 -27
  146. package/dist/utils/CollectionPage/getCollectionPageActiveId.js +2 -2
  147. package/dist/utils/CollectionPage/getCollectionPageActiveId.test.js +10 -10
  148. package/dist/utils/CollectionPage/getCollectionPageActiveIndex.js +11 -7
  149. package/dist/utils/CollectionPage/getCollectionPageActiveIndex.test.js +22 -22
  150. package/dist/utils/CollectionPage/getCollectionPageData.js +12 -8
  151. package/dist/utils/CollectionPage/getCollectionPageData.test.js +19 -19
  152. package/dist/utils/CollectionPage/getQuickEditPage.js +19 -19
  153. package/dist/utils/CollectionPage/getQuickEditPage.test.js +16 -12
  154. package/dist/utils/CollectionPage/index.js +1 -1
  155. package/dist/utils/CollectionPage/mergeCollectionPages.js +30 -29
  156. package/dist/utils/CollectionPage/mergeCollectionPages.test.js +17 -17
  157. package/dist/utils/CollectionPage/removeCollectionPageEntry.js +6 -4
  158. package/dist/utils/CollectionPage/removeCollectionPageEntry.test.js +10 -10
  159. package/dist/utils/CollectionPage/setCollectionPageData.js +12 -8
  160. package/dist/utils/CollectionPage/setCollectionPageData.test.js +17 -17
  161. package/dist/utils/Component/addShowWhen.js +8 -4
  162. package/dist/utils/Component/addShowWhen.test.js +37 -37
  163. package/dist/utils/Component/applyToComponentTree.js +18 -18
  164. package/dist/utils/Component/applyToComponentTree.test.js +32 -27
  165. package/dist/utils/Component/cleanAttributes.js +13 -10
  166. package/dist/utils/Component/cleanAttributes.test.js +18 -17
  167. package/dist/utils/Component/elevateNestedComponents.js +5 -5
  168. package/dist/utils/Component/elevateNestedComponents.test.js +30 -30
  169. package/dist/utils/Component/getComponent.js +94 -88
  170. package/dist/utils/Component/getComponentTests/getComponent.autocomplete.test.js +17 -18
  171. package/dist/utils/Component/getComponentTests/getComponent.calculation.test.js +59 -46
  172. package/dist/utils/Component/getComponentTests/getComponent.checkboxes.test.js +48 -39
  173. package/dist/utils/Component/getComponentTests/getComponent.date.test.js +33 -23
  174. package/dist/utils/Component/getComponentTests/getComponent.details.test.js +18 -20
  175. package/dist/utils/Component/getComponentTests/getComponent.email.test.js +22 -17
  176. package/dist/utils/Component/getComponentTests/getComponent.file.test.js +25 -20
  177. package/dist/utils/Component/getComponentTests/getComponent.heading.test.js +9 -10
  178. package/dist/utils/Component/getComponentTests/getComponent.html.test.js +15 -17
  179. package/dist/utils/Component/getComponentTests/getComponent.insetText.test.js +8 -9
  180. package/dist/utils/Component/getComponentTests/getComponent.list.test.js +15 -17
  181. package/dist/utils/Component/getComponentTests/getComponent.multifile.test.js +26 -22
  182. package/dist/utils/Component/getComponentTests/getComponent.nested.test.js +175 -155
  183. package/dist/utils/Component/getComponentTests/getComponent.paragraph.test.js +15 -17
  184. package/dist/utils/Component/getComponentTests/getComponent.phoneNumber.test.js +22 -17
  185. package/dist/utils/Component/getComponentTests/getComponent.radios.test.js +70 -57
  186. package/dist/utils/Component/getComponentTests/getComponent.select.test.js +22 -17
  187. package/dist/utils/Component/getComponentTests/getComponent.text.test.js +22 -17
  188. package/dist/utils/Component/getComponentTests/getComponent.textArea.test.js +38 -31
  189. package/dist/utils/Component/getComponentTests/getComponent.time.test.js +29 -20
  190. package/dist/utils/Component/getComponentTests/getComponent.unknown.test.js +2 -2
  191. package/dist/utils/Component/getComponentTests/getComponent.warningText.test.js +8 -9
  192. package/dist/utils/Component/getDefaultValue.js +8 -6
  193. package/dist/utils/Component/getDefaultValue.test.js +12 -12
  194. package/dist/utils/Component/getDefaultValueFromConfig.js +21 -22
  195. package/dist/utils/Component/getDefaultValueFromConfig.test.js +31 -31
  196. package/dist/utils/Component/index.js +1 -1
  197. package/dist/utils/Component/isEditable.js +4 -2
  198. package/dist/utils/Component/isEditable.test.js +15 -14
  199. package/dist/utils/Component/optionIsSelected.js +1 -1
  200. package/dist/utils/Component/optionIsSelected.test.js +9 -9
  201. package/dist/utils/Component/setupContainerComponentsPath.js +29 -27
  202. package/dist/utils/Component/setupContainerComponentsPath.test.js +11 -11
  203. package/dist/utils/Component/showComponent.js +1 -1
  204. package/dist/utils/Component/showComponent.test.js +28 -28
  205. package/dist/utils/Component/wrapInFormGroup.js +2 -2
  206. package/dist/utils/Condition/index.js +1 -1
  207. package/dist/utils/Condition/meetsAllConditions.js +7 -7
  208. package/dist/utils/Condition/meetsAllConditions.test.js +17 -17
  209. package/dist/utils/Condition/meetsCondition.js +17 -14
  210. package/dist/utils/Condition/meetsCondition.test.js +376 -376
  211. package/dist/utils/Condition/meetsOneCondition.js +5 -5
  212. package/dist/utils/Condition/meetsOneCondition.test.js +16 -16
  213. package/dist/utils/Condition/setupConditions.js +18 -13
  214. package/dist/utils/Condition/setupConditions.test.js +7 -7
  215. package/dist/utils/Container/getEditableComponents.js +5 -3
  216. package/dist/utils/Container/getEditableComponents.test.js +45 -43
  217. package/dist/utils/Container/index.js +1 -1
  218. package/dist/utils/Container/setupNesting.js +20 -16
  219. package/dist/utils/Container/setupNesting.test.js +30 -27
  220. package/dist/utils/Container/showContainer.js +7 -3
  221. package/dist/utils/Container/showContainer.test.js +30 -30
  222. package/dist/utils/Data/applyFormula.js +48 -38
  223. package/dist/utils/Data/applyFormula.test.js +20 -20
  224. package/dist/utils/Data/getAutocompleteSource.js +26 -18
  225. package/dist/utils/Data/getAutocompleteSource.test.js +86 -80
  226. package/dist/utils/Data/getDataPath.js +28 -18
  227. package/dist/utils/Data/getDataPath.test.js +12 -12
  228. package/dist/utils/Data/getOptions.js +25 -19
  229. package/dist/utils/Data/getOptions.test.js +20 -20
  230. package/dist/utils/Data/getSourceData.js +19 -6
  231. package/dist/utils/Data/getSourceData.test.js +80 -84
  232. package/dist/utils/Data/index.js +1 -1
  233. package/dist/utils/Data/refDataToOptions.js +13 -10
  234. package/dist/utils/Data/refDataToOptions.test.js +19 -19
  235. package/dist/utils/Data/setDataItem.js +8 -7
  236. package/dist/utils/Data/setDataItem.test.js +37 -37
  237. package/dist/utils/Data/setupFormData.js +21 -13
  238. package/dist/utils/Data/setupFormData.test.js +50 -51
  239. package/dist/utils/Data/setupRefDataUrlForComponent.js +26 -20
  240. package/dist/utils/Data/setupRefDataUrlForComponent.test.js +24 -24
  241. package/dist/utils/FormPage/applyConditionalProperties.js +9 -5
  242. package/dist/utils/FormPage/applyConditionalProperties.test.js +18 -15
  243. package/dist/utils/FormPage/getFormPage.js +16 -15
  244. package/dist/utils/FormPage/getFormPage.test.js +46 -47
  245. package/dist/utils/FormPage/getFormPages.js +12 -7
  246. package/dist/utils/FormPage/getFormPages.test.js +23 -20
  247. package/dist/utils/FormPage/getPageActions.js +15 -9
  248. package/dist/utils/FormPage/getPageActions.test.js +32 -32
  249. package/dist/utils/FormPage/getPageTitle.js +2 -2
  250. package/dist/utils/FormPage/getPageTitle.test.js +22 -22
  251. package/dist/utils/FormPage/getParagraphFromText.js +7 -5
  252. package/dist/utils/FormPage/getParagraphFromText.test.js +6 -6
  253. package/dist/utils/FormPage/index.js +1 -1
  254. package/dist/utils/FormPage/showFormPage.js +7 -3
  255. package/dist/utils/FormPage/showFormPage.test.js +32 -32
  256. package/dist/utils/FormPage/showFormPageCYA.js +1 -1
  257. package/dist/utils/FormPage/showFormPageCYA.test.js +8 -8
  258. package/dist/utils/FormPage/useComponent.js +28 -21
  259. package/dist/utils/FormPage/useComponent.test.js +79 -78
  260. package/dist/utils/Format/formatData.js +1 -1
  261. package/dist/utils/Format/formatData.test.js +18 -18
  262. package/dist/utils/Format/formatDataForComponent.js +6 -5
  263. package/dist/utils/Format/formatDataForComponent.test.js +77 -50
  264. package/dist/utils/Format/formatDataForForm.js +8 -6
  265. package/dist/utils/Format/formatDataForForm.test.js +15 -13
  266. package/dist/utils/Format/formatDataForPage.js +5 -4
  267. package/dist/utils/Format/formatDataForPage.test.js +23 -20
  268. package/dist/utils/Format/index.js +1 -1
  269. package/dist/utils/Hub/getFormHub.js +1 -1
  270. package/dist/utils/Hub/getFormHub.test.js +31 -28
  271. package/dist/utils/Hub/index.js +1 -1
  272. package/dist/utils/Meta/constants.js +2 -2
  273. package/dist/utils/Meta/documents/getDocuments.js +1 -1
  274. package/dist/utils/Meta/documents/getDocuments.test.js +16 -24
  275. package/dist/utils/Meta/documents/index.js +1 -1
  276. package/dist/utils/Meta/documents/setDocumentsForField.js +16 -14
  277. package/dist/utils/Meta/documents/setDocumentsForField.test.js +34 -68
  278. package/dist/utils/Meta/index.js +1 -1
  279. package/dist/utils/Operate/checkValueIsTruthy.js +2 -2
  280. package/dist/utils/Operate/checkValueIsTruthy.test.js +16 -16
  281. package/dist/utils/Operate/getFirstOf.js +5 -5
  282. package/dist/utils/Operate/getFirstOf.test.js +31 -31
  283. package/dist/utils/Operate/getIndexOfMatchingValueIn.js +10 -10
  284. package/dist/utils/Operate/getIndexOfMatchingValueIn.test.js +46 -46
  285. package/dist/utils/Operate/index.js +1 -1
  286. package/dist/utils/Operate/persistValueInFormData.js +3 -3
  287. package/dist/utils/Operate/persistValueInFormData.test.js +20 -22
  288. package/dist/utils/Operate/runPageOperations.js +7 -7
  289. package/dist/utils/Operate/runPageOperations.test.js +36 -35
  290. package/dist/utils/Operate/setValueInFormData.js +2 -2
  291. package/dist/utils/Operate/setValueInFormData.test.js +16 -16
  292. package/dist/utils/Operate/shouldRun.js +6 -6
  293. package/dist/utils/Operate/shouldRun.test.js +26 -21
  294. package/dist/utils/Validate/additional/conditionallyRequired.js +4 -4
  295. package/dist/utils/Validate/additional/conditionallyRequired.test.js +18 -18
  296. package/dist/utils/Validate/additional/index.js +10 -8
  297. package/dist/utils/Validate/additional/index.test.js +12 -12
  298. package/dist/utils/Validate/additional/mustBeAfter.js +2 -2
  299. package/dist/utils/Validate/additional/mustBeAfter.test.js +40 -40
  300. package/dist/utils/Validate/additional/mustBeBefore.js +2 -2
  301. package/dist/utils/Validate/additional/mustBeBefore.test.js +28 -28
  302. package/dist/utils/Validate/additional/mustBeEarlierDateTime.js +11 -7
  303. package/dist/utils/Validate/additional/mustBeEarlierDateTime.test.js +41 -37
  304. package/dist/utils/Validate/additional/mustBeGreaterThan.js +2 -2
  305. package/dist/utils/Validate/additional/mustBeGreaterThan.test.js +18 -18
  306. package/dist/utils/Validate/additional/mustBeInTheFuture.js +2 -2
  307. package/dist/utils/Validate/additional/mustBeInTheFuture.test.js +12 -12
  308. package/dist/utils/Validate/additional/mustBeInThePast.js +3 -3
  309. package/dist/utils/Validate/additional/mustBeInThePast.test.js +12 -12
  310. package/dist/utils/Validate/additional/mustBeLessThan.js +2 -2
  311. package/dist/utils/Validate/additional/mustBeLessThan.test.js +17 -17
  312. package/dist/utils/Validate/additional/mustBeLongerThan.js +1 -1
  313. package/dist/utils/Validate/additional/mustBeLongerThan.test.js +16 -16
  314. package/dist/utils/Validate/additional/mustBeNumbersOnly.js +2 -2
  315. package/dist/utils/Validate/additional/mustBeNumbersOnly.test.js +20 -20
  316. package/dist/utils/Validate/additional/mustBeShorterThan.js +1 -1
  317. package/dist/utils/Validate/additional/mustBeShorterThan.test.js +16 -16
  318. package/dist/utils/Validate/additional/mustBeUniqueInCollection.js +35 -0
  319. package/dist/utils/Validate/additional/mustBeUniqueInCollection.test.js +127 -0
  320. package/dist/utils/Validate/additional/mustEnterAtLeastOne.js +2 -2
  321. package/dist/utils/Validate/additional/mustEnterAtLeastOne.test.js +16 -14
  322. package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.js +1 -1
  323. package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.test.js +12 -12
  324. package/dist/utils/Validate/additional/mustNotContainSql.js +4 -3
  325. package/dist/utils/Validate/additional/mustNotContainSql.test.js +14 -14
  326. package/dist/utils/Validate/additional/mustSelectOnlyOne.js +2 -2
  327. package/dist/utils/Validate/additional/mustSelectOnlyOne.test.js +26 -28
  328. package/dist/utils/Validate/additional/utils.js +22 -9
  329. package/dist/utils/Validate/index.js +1 -1
  330. package/dist/utils/Validate/validateCollection.js +25 -19
  331. package/dist/utils/Validate/validateCollection.test.js +66 -74
  332. package/dist/utils/Validate/validateComponent.js +16 -18
  333. package/dist/utils/Validate/validateComponent.test.js +146 -167
  334. package/dist/utils/Validate/validateContainer.js +19 -14
  335. package/dist/utils/Validate/validateContainer.test.js +45 -49
  336. package/dist/utils/Validate/validateDate.js +17 -11
  337. package/dist/utils/Validate/validateDate.test.js +29 -28
  338. package/dist/utils/Validate/validateEmail.js +8 -6
  339. package/dist/utils/Validate/validateEmail.test.js +25 -25
  340. package/dist/utils/Validate/validateMultifile.js +7 -5
  341. package/dist/utils/Validate/validateMultifile.test.js +18 -17
  342. package/dist/utils/Validate/validatePage.js +18 -17
  343. package/dist/utils/Validate/validatePage.test.js +182 -185
  344. package/dist/utils/Validate/validateRegex.js +5 -3
  345. package/dist/utils/Validate/validateRegex.test.js +14 -14
  346. package/dist/utils/Validate/validateRequired.js +6 -4
  347. package/dist/utils/Validate/validateRequired.test.js +18 -18
  348. package/dist/utils/Validate/validateTextArea.js +6 -4
  349. package/dist/utils/Validate/validateTextArea.test.js +20 -20
  350. package/dist/utils/Validate/validateTime.js +14 -7
  351. package/dist/utils/Validate/validateTime.test.js +14 -14
  352. package/dist/utils/index.js +9 -7
  353. package/package.json +2 -2
@@ -1,293 +1,351 @@
1
1
  "use strict";
2
2
 
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
3
4
  var _react = _interopRequireDefault(require("react"));
4
5
  var _setupTests = require("../../setupTests");
5
6
  var _FormComponent = _interopRequireDefault(require("./FormComponent"));
6
7
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
7
- // Global imports
8
-
8
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
9
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
10
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } // Global imports
9
11
  // Local imports
10
-
11
- describe('components', () => {
12
- describe('FormComponent', () => {
13
- it('should render a text component appropriately', async () => {
14
- const ID = 'component';
15
- const VALUE = 'Text value';
16
- const COMPONENT = {
17
- id: ID,
18
- fieldId: ID,
19
- type: 'text',
20
- label: 'Text component',
21
- hint: 'Text hint'
22
- };
23
- const ON_CHANGE = () => {};
24
- const {
25
- container
26
- } = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
27
- "data-testid": ID,
28
- component: COMPONENT,
29
- value: VALUE,
30
- onChange: ON_CHANGE
31
- }));
32
-
33
- // text components are wrapper in a FormGroup by default.
34
- const formGroup = container.childNodes[0];
35
- expect(formGroup.tagName).toEqual('DIV');
36
- expect(formGroup.classList).toContain('govuk-form-group');
37
- const label = formGroup.childNodes[0];
38
- expect(label.tagName).toEqual('LABEL');
39
- expect(label.classList).toContain('govuk-label');
40
- expect(label.textContent).toEqual("".concat(COMPONENT.label, " (optional)"));
41
- expect(label.getAttribute('for')).toEqual(ID);
42
- const hint = formGroup.childNodes[1];
43
- expect(hint.tagName).toEqual('DIV');
44
- expect(hint.classList).toContain('govuk-hint');
45
- expect(hint.textContent).toEqual(COMPONENT.hint);
46
- const input = formGroup.childNodes[2];
47
- expect(input.tagName).toEqual('INPUT');
48
- expect(input.classList).toContain('govuk-input');
49
- expect(input.id).toEqual(ID);
50
- expect(input.value).toEqual(VALUE);
51
- });
52
- it('should render a text component appropriately with wrap turned off', async () => {
53
- const ID = 'component';
54
- const VALUE = 'Text value';
55
- const COMPONENT = {
56
- id: ID,
57
- fieldId: ID,
58
- type: 'text',
59
- label: 'Text component',
60
- hint: 'Text hint'
61
- };
62
- const ON_CHANGE = () => {};
63
- const {
64
- container
65
- } = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
66
- "data-testid": ID,
67
- component: COMPONENT,
68
- wrap: false,
69
- value: VALUE,
70
- onChange: ON_CHANGE
71
- }));
72
-
73
- // With wrap = false, there should be no form group.
74
- const input = container.childNodes[0];
75
- expect(input.tagName).toEqual('INPUT');
76
- expect(input.classList).toContain('govuk-input');
77
- expect(input.id).toEqual(ID);
78
- expect(input.value).toEqual(VALUE);
79
- });
80
- it('should render an html component appropriately', async () => {
81
- const ID = 'component';
82
- const COMPONENT = {
83
- type: 'html',
84
- tagName: 'p',
85
- content: 'HTML content'
86
- };
87
- const {
88
- container
89
- } = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
90
- "data-testid": ID,
91
- component: COMPONENT
92
- }));
93
- const p = container.childNodes[0];
94
- expect(p.tagName).toEqual('P');
95
- expect(p.textContent).toEqual(COMPONENT.content);
96
- });
97
- it('should render an overridden html component appropriately', async () => {
98
- const hooks = {
99
- onGetComponent: (config, wrap) => /*#__PURE__*/_react.default.createElement("div", null, "".concat(config.type, " | ").concat(config.tagName, " | ").concat(config.content, " | ").concat(wrap))
100
- };
101
- const ID = 'component';
102
- const COMPONENT = {
103
- type: 'html',
104
- tagName: 'p',
105
- content: 'HTML content'
106
- };
107
- const {
108
- container
109
- } = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
110
- "data-testid": ID,
111
- component: COMPONENT
112
- }), {
113
- hooks
114
- });
115
- const div = container.childNodes[0];
116
- expect(div.tagName).toEqual('DIV');
117
- expect(div.textContent).toEqual("".concat(COMPONENT.type, " | ").concat(COMPONENT.tagName, " | ").concat(COMPONENT.content, " | true"));
118
- });
119
- it('should render an overridden html component appropriately and pass through onAction', async () => {
120
- const hooks = {
121
- onGetComponent: (config, wrap) => /*#__PURE__*/_react.default.createElement("div", null, "".concat(config.type, " | ").concat(config.tagName, " | ").concat(config.content, " | ").concat(wrap, " | ").concat(config.onAction))
122
- };
123
- const ID = 'component';
124
- const COMPONENT = {
125
- type: 'html',
126
- tagName: 'p',
127
- content: 'HTML content'
128
- };
129
- const {
130
- container
131
- } = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
132
- "data-testid": ID,
133
- component: COMPONENT,
134
- onAction: "() => {}"
135
- }), {
136
- hooks
137
- });
138
- const div = container.childNodes[0];
139
- expect(div.tagName).toEqual('DIV');
140
- expect(div.textContent).toEqual("".concat(COMPONENT.type, " | ").concat(COMPONENT.tagName, " | ").concat(COMPONENT.content, " | true | () => {}"));
141
- });
142
- it('should render the correct html component when the override returns null', async () => {
143
- const hooks = {
144
- onGetComponent: () => null
145
- };
146
- const ID = 'component';
147
- const COMPONENT = {
148
- type: 'html',
149
- tagName: 'p',
150
- content: 'HTML content'
151
- };
152
- const {
153
- container
154
- } = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
155
- "data-testid": ID,
156
- component: COMPONENT
157
- }), {
158
- hooks
159
- });
160
- const p = container.childNodes[0];
161
- expect(p.tagName).toEqual('P');
162
- expect(p.textContent).toEqual(COMPONENT.content);
163
- });
164
- it('should render a text component appropriately with interpolated label', async () => {
165
- const ID = 'component';
166
- const VALUE = 'Text value';
167
- // eslint-disable-next-line no-template-curly-in-string
168
- const COMPONENT = {
169
- id: ID,
170
- fieldId: ID,
171
- type: 'text',
172
- label: '${text} Text component',
173
- cya_label: '${text} Text component',
174
- hint: 'Text hint'
175
- };
176
- const DATA = {
177
- text: 'Interpolated'
178
- };
179
- const ON_CHANGE = () => {};
180
- const {
181
- container
182
- } = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
183
- "data-testid": ID,
184
- component: COMPONENT,
185
- value: VALUE,
186
- onChange: ON_CHANGE,
187
- formData: DATA
188
- }));
189
-
190
- // text components are wrapper in a FormGroup by default.
191
- const formGroup = container.childNodes[0];
192
- expect(formGroup.tagName).toEqual('DIV');
193
- expect(formGroup.classList).toContain('govuk-form-group');
194
- const label = formGroup.childNodes[0];
195
- expect(label.tagName).toEqual('LABEL');
196
- expect(label.classList).toContain('govuk-label');
197
- expect(label.textContent).toEqual('Interpolated Text component (optional)');
198
- expect(label.getAttribute('for')).toEqual(ID);
199
- const hint = formGroup.childNodes[1];
200
- expect(hint.tagName).toEqual('DIV');
201
- expect(hint.classList).toContain('govuk-hint');
202
- expect(hint.textContent).toEqual(COMPONENT.hint);
203
- const input = formGroup.childNodes[2];
204
- expect(input.tagName).toEqual('INPUT');
205
- expect(input.classList).toContain('govuk-input');
206
- expect(input.id).toEqual(ID);
207
- expect(input.value).toEqual(VALUE);
208
- });
209
- it('should correctly handle a component\'s default value when it has no existing value', async () => {
210
- const ID = 'component';
211
- const COMPONENT = {
212
- id: ID,
213
- fieldId: ID,
214
- type: 'text',
215
- label: 'Text component',
216
- defaultValue: 'default text'
217
- };
218
- const DATA = {};
219
- const ON_CHANGE_ARGS = [];
220
- let ON_CHANGE_COUNT = 0;
221
- const ON_CHANGE = _ref => {
222
- let {
223
- target
224
- } = _ref;
225
- ON_CHANGE_ARGS.push(target);
226
- ON_CHANGE_COUNT += 1;
227
- DATA[target.name] = target.value;
228
- };
229
- const {
230
- container,
231
- rerender
232
- } = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
233
- "data-testid": ID,
234
- component: COMPONENT,
235
- value: DATA[ID],
236
- onChange: ON_CHANGE,
237
- formData: DATA
238
- }));
239
- expect(ON_CHANGE_COUNT).toEqual(1);
240
- expect(ON_CHANGE_ARGS[0]).toMatchObject({
241
- name: 'component',
242
- value: COMPONENT.defaultValue
243
- });
244
- const formGroup = container.childNodes[0];
245
- const input = formGroup.childNodes[2];
246
- (0, _setupTests.rerenderWithValidation)(rerender, /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
247
- "data-testid": ID,
248
- component: COMPONENT,
249
- value: DATA[ID],
250
- onChange: ON_CHANGE,
251
- formData: DATA
252
- }));
253
- // Input should only be updated once the changes caused
254
- // by onChange have had another render to propagate down.
255
- expect(input.value).toEqual(COMPONENT.defaultValue);
256
- });
257
- it('should correctly handle a component\'s default value when it has an existing value', async () => {
258
- const ID = 'component';
259
- const COMPONENT = {
260
- id: ID,
261
- fieldId: ID,
262
- type: 'text',
263
- label: 'Text component',
264
- defaultValue: 'default text'
265
- };
266
- const DATA = {
267
- component: 'existing value'
268
- };
269
- const ON_CHANGE_ARGS = [];
270
- let ON_CHANGE_COUNT = 0;
271
- const ON_CHANGE = _ref2 => {
272
- let {
273
- target
274
- } = _ref2;
275
- ON_CHANGE_ARGS.push(target);
276
- ON_CHANGE_COUNT += 1;
277
- };
278
- const {
279
- container
280
- } = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
281
- "data-testid": ID,
282
- component: COMPONENT,
283
- value: DATA[ID],
284
- onChange: ON_CHANGE,
285
- formData: DATA
286
- }));
287
- expect(ON_CHANGE_COUNT).toEqual(0);
288
- const formGroup = container.childNodes[0];
289
- const input = formGroup.childNodes[2];
290
- expect(input.value).toEqual(DATA[ID]);
291
- });
12
+ describe('components', function () {
13
+ describe('FormComponent', function () {
14
+ it('should render a text component appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
15
+ var ID, VALUE, COMPONENT, ON_CHANGE, _renderWithValidation, container, formGroup, label, hint, input;
16
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
17
+ while (1) switch (_context.prev = _context.next) {
18
+ case 0:
19
+ ID = 'component';
20
+ VALUE = 'Text value';
21
+ COMPONENT = {
22
+ id: ID,
23
+ fieldId: ID,
24
+ type: 'text',
25
+ label: 'Text component',
26
+ hint: 'Text hint'
27
+ };
28
+ ON_CHANGE = function ON_CHANGE() {};
29
+ _renderWithValidation = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
30
+ "data-testid": ID,
31
+ component: COMPONENT,
32
+ value: VALUE,
33
+ onChange: ON_CHANGE
34
+ })), container = _renderWithValidation.container; // text components are wrapper in a FormGroup by default.
35
+ formGroup = container.childNodes[0];
36
+ expect(formGroup.tagName).toEqual('DIV');
37
+ expect(formGroup.classList).toContain('govuk-form-group');
38
+ label = formGroup.childNodes[0];
39
+ expect(label.tagName).toEqual('LABEL');
40
+ expect(label.classList).toContain('govuk-label');
41
+ expect(label.textContent).toEqual("".concat(COMPONENT.label, " (optional)"));
42
+ expect(label.getAttribute('for')).toEqual(ID);
43
+ hint = formGroup.childNodes[1];
44
+ expect(hint.tagName).toEqual('DIV');
45
+ expect(hint.classList).toContain('govuk-hint');
46
+ expect(hint.textContent).toEqual(COMPONENT.hint);
47
+ input = formGroup.childNodes[2];
48
+ expect(input.tagName).toEqual('INPUT');
49
+ expect(input.classList).toContain('govuk-input');
50
+ expect(input.id).toEqual(ID);
51
+ expect(input.value).toEqual(VALUE);
52
+ case 22:
53
+ case "end":
54
+ return _context.stop();
55
+ }
56
+ }, _callee);
57
+ })));
58
+ it('should render a text component appropriately with wrap turned off', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
59
+ var ID, VALUE, COMPONENT, ON_CHANGE, _renderWithValidation2, container, input;
60
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
61
+ while (1) switch (_context2.prev = _context2.next) {
62
+ case 0:
63
+ ID = 'component';
64
+ VALUE = 'Text value';
65
+ COMPONENT = {
66
+ id: ID,
67
+ fieldId: ID,
68
+ type: 'text',
69
+ label: 'Text component',
70
+ hint: 'Text hint'
71
+ };
72
+ ON_CHANGE = function ON_CHANGE() {};
73
+ _renderWithValidation2 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
74
+ "data-testid": ID,
75
+ component: COMPONENT,
76
+ wrap: false,
77
+ value: VALUE,
78
+ onChange: ON_CHANGE
79
+ })), container = _renderWithValidation2.container; // With wrap = false, there should be no form group.
80
+ input = container.childNodes[0];
81
+ expect(input.tagName).toEqual('INPUT');
82
+ expect(input.classList).toContain('govuk-input');
83
+ expect(input.id).toEqual(ID);
84
+ expect(input.value).toEqual(VALUE);
85
+ case 10:
86
+ case "end":
87
+ return _context2.stop();
88
+ }
89
+ }, _callee2);
90
+ })));
91
+ it('should render an html component appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
92
+ var ID, COMPONENT, _renderWithValidation3, container, p;
93
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
94
+ while (1) switch (_context3.prev = _context3.next) {
95
+ case 0:
96
+ ID = 'component';
97
+ COMPONENT = {
98
+ type: 'html',
99
+ tagName: 'p',
100
+ content: 'HTML content'
101
+ };
102
+ _renderWithValidation3 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
103
+ "data-testid": ID,
104
+ component: COMPONENT
105
+ })), container = _renderWithValidation3.container;
106
+ p = container.childNodes[0];
107
+ expect(p.tagName).toEqual('P');
108
+ expect(p.textContent).toEqual(COMPONENT.content);
109
+ case 6:
110
+ case "end":
111
+ return _context3.stop();
112
+ }
113
+ }, _callee3);
114
+ })));
115
+ it('should render an overridden html component appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
116
+ var hooks, ID, COMPONENT, _renderWithValidation4, container, div;
117
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
118
+ while (1) switch (_context4.prev = _context4.next) {
119
+ case 0:
120
+ hooks = {
121
+ onGetComponent: function onGetComponent(config, wrap) {
122
+ return /*#__PURE__*/_react.default.createElement("div", null, "".concat(config.type, " | ").concat(config.tagName, " | ").concat(config.content, " | ").concat(wrap));
123
+ }
124
+ };
125
+ ID = 'component';
126
+ COMPONENT = {
127
+ type: 'html',
128
+ tagName: 'p',
129
+ content: 'HTML content'
130
+ };
131
+ _renderWithValidation4 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
132
+ "data-testid": ID,
133
+ component: COMPONENT
134
+ }), {
135
+ hooks: hooks
136
+ }), container = _renderWithValidation4.container;
137
+ div = container.childNodes[0];
138
+ expect(div.tagName).toEqual('DIV');
139
+ expect(div.textContent).toEqual("".concat(COMPONENT.type, " | ").concat(COMPONENT.tagName, " | ").concat(COMPONENT.content, " | true"));
140
+ case 7:
141
+ case "end":
142
+ return _context4.stop();
143
+ }
144
+ }, _callee4);
145
+ })));
146
+ it('should render an overridden html component appropriately and pass through onAction', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
147
+ var hooks, ID, COMPONENT, _renderWithValidation5, container, div;
148
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
149
+ while (1) switch (_context5.prev = _context5.next) {
150
+ case 0:
151
+ hooks = {
152
+ onGetComponent: function onGetComponent(config, wrap) {
153
+ return /*#__PURE__*/_react.default.createElement("div", null, "".concat(config.type, " | ").concat(config.tagName, " | ").concat(config.content, " | ").concat(wrap, " | ").concat(config.onAction));
154
+ }
155
+ };
156
+ ID = 'component';
157
+ COMPONENT = {
158
+ type: 'html',
159
+ tagName: 'p',
160
+ content: 'HTML content'
161
+ };
162
+ _renderWithValidation5 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
163
+ "data-testid": ID,
164
+ component: COMPONENT,
165
+ onAction: "() => {}"
166
+ }), {
167
+ hooks: hooks
168
+ }), container = _renderWithValidation5.container;
169
+ div = container.childNodes[0];
170
+ expect(div.tagName).toEqual('DIV');
171
+ expect(div.textContent).toEqual("".concat(COMPONENT.type, " | ").concat(COMPONENT.tagName, " | ").concat(COMPONENT.content, " | true | () => {}"));
172
+ case 7:
173
+ case "end":
174
+ return _context5.stop();
175
+ }
176
+ }, _callee5);
177
+ })));
178
+ it('should render the correct html component when the override returns null', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
179
+ var hooks, ID, COMPONENT, _renderWithValidation6, container, p;
180
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
181
+ while (1) switch (_context6.prev = _context6.next) {
182
+ case 0:
183
+ hooks = {
184
+ onGetComponent: function onGetComponent() {
185
+ return null;
186
+ }
187
+ };
188
+ ID = 'component';
189
+ COMPONENT = {
190
+ type: 'html',
191
+ tagName: 'p',
192
+ content: 'HTML content'
193
+ };
194
+ _renderWithValidation6 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
195
+ "data-testid": ID,
196
+ component: COMPONENT
197
+ }), {
198
+ hooks: hooks
199
+ }), container = _renderWithValidation6.container;
200
+ p = container.childNodes[0];
201
+ expect(p.tagName).toEqual('P');
202
+ expect(p.textContent).toEqual(COMPONENT.content);
203
+ case 7:
204
+ case "end":
205
+ return _context6.stop();
206
+ }
207
+ }, _callee6);
208
+ })));
209
+ it('should render a text component appropriately with interpolated label', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
210
+ var ID, VALUE, COMPONENT, DATA, ON_CHANGE, _renderWithValidation7, container, formGroup, label, hint, input;
211
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
212
+ while (1) switch (_context7.prev = _context7.next) {
213
+ case 0:
214
+ ID = 'component';
215
+ VALUE = 'Text value'; // eslint-disable-next-line no-template-curly-in-string
216
+ COMPONENT = {
217
+ id: ID,
218
+ fieldId: ID,
219
+ type: 'text',
220
+ label: '${text} Text component',
221
+ cya_label: '${text} Text component',
222
+ hint: 'Text hint'
223
+ };
224
+ DATA = {
225
+ text: 'Interpolated'
226
+ };
227
+ ON_CHANGE = function ON_CHANGE() {};
228
+ _renderWithValidation7 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
229
+ "data-testid": ID,
230
+ component: COMPONENT,
231
+ value: VALUE,
232
+ onChange: ON_CHANGE,
233
+ formData: DATA
234
+ })), container = _renderWithValidation7.container; // text components are wrapper in a FormGroup by default.
235
+ formGroup = container.childNodes[0];
236
+ expect(formGroup.tagName).toEqual('DIV');
237
+ expect(formGroup.classList).toContain('govuk-form-group');
238
+ label = formGroup.childNodes[0];
239
+ expect(label.tagName).toEqual('LABEL');
240
+ expect(label.classList).toContain('govuk-label');
241
+ expect(label.textContent).toEqual('Interpolated Text component (optional)');
242
+ expect(label.getAttribute('for')).toEqual(ID);
243
+ hint = formGroup.childNodes[1];
244
+ expect(hint.tagName).toEqual('DIV');
245
+ expect(hint.classList).toContain('govuk-hint');
246
+ expect(hint.textContent).toEqual(COMPONENT.hint);
247
+ input = formGroup.childNodes[2];
248
+ expect(input.tagName).toEqual('INPUT');
249
+ expect(input.classList).toContain('govuk-input');
250
+ expect(input.id).toEqual(ID);
251
+ expect(input.value).toEqual(VALUE);
252
+ case 23:
253
+ case "end":
254
+ return _context7.stop();
255
+ }
256
+ }, _callee7);
257
+ })));
258
+ it('should correctly handle a component\'s default value when it has no existing value', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
259
+ var ID, COMPONENT, DATA, ON_CHANGE_ARGS, ON_CHANGE_COUNT, ON_CHANGE, _renderWithValidation8, container, rerender, formGroup, input;
260
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
261
+ while (1) switch (_context8.prev = _context8.next) {
262
+ case 0:
263
+ ID = 'component';
264
+ COMPONENT = {
265
+ id: ID,
266
+ fieldId: ID,
267
+ type: 'text',
268
+ label: 'Text component',
269
+ defaultValue: 'default text'
270
+ };
271
+ DATA = {};
272
+ ON_CHANGE_ARGS = [];
273
+ ON_CHANGE_COUNT = 0;
274
+ ON_CHANGE = function ON_CHANGE(_ref9) {
275
+ var target = _ref9.target;
276
+ ON_CHANGE_ARGS.push(target);
277
+ ON_CHANGE_COUNT += 1;
278
+ DATA[target.name] = target.value;
279
+ };
280
+ _renderWithValidation8 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
281
+ "data-testid": ID,
282
+ component: COMPONENT,
283
+ value: DATA[ID],
284
+ onChange: ON_CHANGE,
285
+ formData: DATA
286
+ })), container = _renderWithValidation8.container, rerender = _renderWithValidation8.rerender;
287
+ expect(ON_CHANGE_COUNT).toEqual(1);
288
+ expect(ON_CHANGE_ARGS[0]).toMatchObject({
289
+ name: 'component',
290
+ value: COMPONENT.defaultValue
291
+ });
292
+ formGroup = container.childNodes[0];
293
+ input = formGroup.childNodes[2];
294
+ (0, _setupTests.rerenderWithValidation)(rerender, /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
295
+ "data-testid": ID,
296
+ component: COMPONENT,
297
+ value: DATA[ID],
298
+ onChange: ON_CHANGE,
299
+ formData: DATA
300
+ }));
301
+ // Input should only be updated once the changes caused
302
+ // by onChange have had another render to propagate down.
303
+ expect(input.value).toEqual(COMPONENT.defaultValue);
304
+ case 13:
305
+ case "end":
306
+ return _context8.stop();
307
+ }
308
+ }, _callee8);
309
+ })));
310
+ it('should correctly handle a component\'s default value when it has an existing value', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
311
+ var ID, COMPONENT, DATA, ON_CHANGE_ARGS, ON_CHANGE_COUNT, ON_CHANGE, _renderWithValidation9, container, formGroup, input;
312
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
313
+ while (1) switch (_context9.prev = _context9.next) {
314
+ case 0:
315
+ ID = 'component';
316
+ COMPONENT = {
317
+ id: ID,
318
+ fieldId: ID,
319
+ type: 'text',
320
+ label: 'Text component',
321
+ defaultValue: 'default text'
322
+ };
323
+ DATA = {
324
+ component: 'existing value'
325
+ };
326
+ ON_CHANGE_ARGS = [];
327
+ ON_CHANGE_COUNT = 0;
328
+ ON_CHANGE = function ON_CHANGE(_ref11) {
329
+ var target = _ref11.target;
330
+ ON_CHANGE_ARGS.push(target);
331
+ ON_CHANGE_COUNT += 1;
332
+ };
333
+ _renderWithValidation9 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
334
+ "data-testid": ID,
335
+ component: COMPONENT,
336
+ value: DATA[ID],
337
+ onChange: ON_CHANGE,
338
+ formData: DATA
339
+ })), container = _renderWithValidation9.container;
340
+ expect(ON_CHANGE_COUNT).toEqual(0);
341
+ formGroup = container.childNodes[0];
342
+ input = formGroup.childNodes[2];
343
+ expect(input.value).toEqual(DATA[ID]);
344
+ case 11:
345
+ case "end":
346
+ return _context9.stop();
347
+ }
348
+ }, _callee9);
349
+ })));
292
350
  });
293
351
  });