@ukhomeoffice/cop-react-form-renderer 6.14.0 → 6.14.1

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 (385) hide show
  1. package/README.md +5 -0
  2. package/dist/components/CheckYourAnswers/Answer.js +12 -11
  3. package/dist/components/CheckYourAnswers/Answer.test.js +132 -181
  4. package/dist/components/CheckYourAnswers/CheckYourAnswers.js +98 -133
  5. package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +544 -939
  6. package/dist/components/CheckYourAnswers/index.js +1 -1
  7. package/dist/components/CollectionPage/CollectionPage.js +62 -60
  8. package/dist/components/CollectionPage/CollectionPage.test.js +315 -365
  9. package/dist/components/CollectionPage/index.js +1 -1
  10. package/dist/components/CollectionSummary/BannerStrip.js +14 -14
  11. package/dist/components/CollectionSummary/BannerStrip.test.js +79 -74
  12. package/dist/components/CollectionSummary/CollectionSummary.js +75 -97
  13. package/dist/components/CollectionSummary/CollectionSummary.test.js +182 -166
  14. package/dist/components/CollectionSummary/Confirmation.js +15 -13
  15. package/dist/components/CollectionSummary/Confirmation.test.js +68 -63
  16. package/dist/components/CollectionSummary/RenderListView.js +34 -47
  17. package/dist/components/CollectionSummary/RenderListView.test.js +113 -111
  18. package/dist/components/CollectionSummary/SummaryCard.js +101 -133
  19. package/dist/components/CollectionSummary/SummaryCard.test.js +961 -993
  20. package/dist/components/CollectionSummary/SummaryCardButtons.js +25 -30
  21. package/dist/components/CollectionSummary/SummaryCardButtons.test.js +30 -28
  22. package/dist/components/CollectionSummary/SummaryCardDetails.js +59 -76
  23. package/dist/components/CollectionSummary/SummaryCardDetails.test.js +170 -180
  24. package/dist/components/CollectionSummary/SummaryCardValidationContext.js +31 -36
  25. package/dist/components/CollectionSummary/SummaryCardValidationContext.test.js +63 -75
  26. package/dist/components/CollectionSummary/index.js +1 -1
  27. package/dist/components/FormComponent/Collection.js +63 -100
  28. package/dist/components/FormComponent/Collection.test.js +907 -1080
  29. package/dist/components/FormComponent/Container.js +35 -29
  30. package/dist/components/FormComponent/Container.test.js +378 -409
  31. package/dist/components/FormComponent/FormComponent.js +59 -63
  32. package/dist/components/FormComponent/FormComponent.test.js +354 -415
  33. package/dist/components/FormComponent/helpers/addLabel.js +4 -7
  34. package/dist/components/FormComponent/helpers/getComponentDisabled.js +1 -1
  35. package/dist/components/FormComponent/helpers/getComponentDisabled.test.js +8 -8
  36. package/dist/components/FormComponent/helpers/getComponentError.js +3 -5
  37. package/dist/components/FormComponent/helpers/getComponentError.test.js +15 -15
  38. package/dist/components/FormComponent/helpers/getComponentFieldSet.js +3 -4
  39. package/dist/components/FormComponent/helpers/getComponentFieldSet.test.js +7 -7
  40. package/dist/components/FormComponent/helpers/index.js +5 -5
  41. package/dist/components/FormComponent/index.js +1 -1
  42. package/dist/components/FormPage/FormPage.js +70 -93
  43. package/dist/components/FormPage/FormPage.test.js +150 -202
  44. package/dist/components/FormPage/index.js +1 -1
  45. package/dist/components/FormRenderer/FormRenderer.js +131 -173
  46. package/dist/components/FormRenderer/FormRenderer.test.js +732 -1114
  47. package/dist/components/FormRenderer/handlers/cyaAction.js +3 -3
  48. package/dist/components/FormRenderer/handlers/getPageId.js +1 -3
  49. package/dist/components/FormRenderer/handlers/getPageId.test.js +15 -15
  50. package/dist/components/FormRenderer/handlers/handlers.test.js +33 -33
  51. package/dist/components/FormRenderer/handlers/index.js +2 -2
  52. package/dist/components/FormRenderer/handlers/navigate.js +4 -4
  53. package/dist/components/FormRenderer/handlers/submissionError.js +1 -1
  54. package/dist/components/FormRenderer/helpers/canActionProceed.js +1 -1
  55. package/dist/components/FormRenderer/helpers/canActionProceed.test.js +16 -16
  56. package/dist/components/FormRenderer/helpers/canCYASubmit.js +1 -3
  57. package/dist/components/FormRenderer/helpers/canCYASubmit.test.js +17 -21
  58. package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.js +22 -25
  59. package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.test.js +21 -21
  60. package/dist/components/FormRenderer/helpers/getCYA.js +4 -6
  61. package/dist/components/FormRenderer/helpers/getCYA.test.js +12 -12
  62. package/dist/components/FormRenderer/helpers/getFormState.js +6 -8
  63. package/dist/components/FormRenderer/helpers/getFormState.test.js +11 -11
  64. package/dist/components/FormRenderer/helpers/getNextPageId.js +14 -25
  65. package/dist/components/FormRenderer/helpers/getNextPageId.test.js +68 -68
  66. package/dist/components/FormRenderer/helpers/getPage.js +2 -4
  67. package/dist/components/FormRenderer/helpers/getPage.test.js +12 -12
  68. package/dist/components/FormRenderer/helpers/getRelevantPages.js +7 -9
  69. package/dist/components/FormRenderer/helpers/getRelevantPages.test.js +15 -15
  70. package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +6 -6
  71. package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +104 -98
  72. package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.js +44 -51
  73. package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.test.js +68 -74
  74. package/dist/components/FormRenderer/helpers/index.js +2 -2
  75. package/dist/components/FormRenderer/index.js +1 -1
  76. package/dist/components/FormRenderer/onCYAAction.js +43 -44
  77. package/dist/components/FormRenderer/onCYAAction.test.js +126 -133
  78. package/dist/components/FormRenderer/onPageAction.js +26 -35
  79. package/dist/components/FormRenderer/onPageAction.test.js +177 -186
  80. package/dist/components/FormRenderer/onTaskAction.js +11 -12
  81. package/dist/components/FormRenderer/onTaskAction.test.js +63 -68
  82. package/dist/components/PageActions/ActionButton.js +14 -14
  83. package/dist/components/PageActions/ActionButton.test.js +57 -79
  84. package/dist/components/PageActions/PageActions.js +11 -11
  85. package/dist/components/PageActions/PageActions.test.js +87 -116
  86. package/dist/components/PageActions/index.js +1 -1
  87. package/dist/components/SummaryList/GroupAction.js +10 -18
  88. package/dist/components/SummaryList/GroupAction.test.js +38 -34
  89. package/dist/components/SummaryList/RowAction.js +12 -17
  90. package/dist/components/SummaryList/RowAction.test.js +38 -34
  91. package/dist/components/SummaryList/SummaryList.js +23 -25
  92. package/dist/components/SummaryList/SummaryList.test.js +162 -189
  93. package/dist/components/SummaryList/SummaryListHeadingRow.js +7 -5
  94. package/dist/components/SummaryList/SummaryListHeadingRowWithAction.js +7 -5
  95. package/dist/components/SummaryList/SummaryListRow.js +7 -5
  96. package/dist/components/SummaryList/SummaryListTitleRow.js +6 -4
  97. package/dist/components/SummaryList/helpers/getGroupActionAttributes.js +3 -5
  98. package/dist/components/SummaryList/helpers/getGroupActionAttributes.test.js +23 -23
  99. package/dist/components/SummaryList/helpers/getRowActionAttributes.js +3 -5
  100. package/dist/components/SummaryList/helpers/getRowActionAttributes.test.js +23 -23
  101. package/dist/components/SummaryList/helpers/index.js +2 -2
  102. package/dist/components/SummaryList/index.js +1 -1
  103. package/dist/components/TaskList/Task.js +20 -30
  104. package/dist/components/TaskList/Task.test.js +84 -77
  105. package/dist/components/TaskList/TaskList.js +56 -79
  106. package/dist/components/TaskList/TaskList.test.js +149 -149
  107. package/dist/components/TaskList/TaskState.js +8 -6
  108. package/dist/components/TaskList/TaskState.test.js +53 -46
  109. package/dist/components/TaskList/index.js +1 -1
  110. package/dist/components/index.js +8 -8
  111. package/dist/context/HooksContext/HooksContext.js +56 -79
  112. package/dist/context/HooksContext/HooksContext.test.js +27 -36
  113. package/dist/context/HooksContext/index.js +3 -4
  114. package/dist/context/ValidationContext/ValidationContext.js +44 -95
  115. package/dist/context/ValidationContext/ValidationContext.test.js +57 -69
  116. package/dist/context/ValidationContext/index.js +3 -4
  117. package/dist/context/index.js +3 -3
  118. package/dist/hooks/index.js +10 -11
  119. package/dist/hooks/useAxios.js +15 -41
  120. package/dist/hooks/useGetRequest.js +62 -98
  121. package/dist/hooks/useHooks.js +1 -3
  122. package/dist/hooks/useRefData.js +25 -37
  123. package/dist/hooks/useValidation.js +1 -3
  124. package/dist/index.js +14 -15
  125. package/dist/models/CollectionLabels.js +1 -1
  126. package/dist/models/ComponentTypes.js +25 -25
  127. package/dist/models/EventTypes.js +4 -4
  128. package/dist/models/FormPages.js +4 -4
  129. package/dist/models/FormTypes.js +8 -8
  130. package/dist/models/HubFormats.js +3 -3
  131. package/dist/models/PageAction.js +44 -38
  132. package/dist/models/TaskStates.js +29 -28
  133. package/dist/models/index.js +10 -10
  134. package/dist/setupTests.js +30 -31
  135. package/dist/utils/CheckYourAnswers/getCYAAction.js +5 -5
  136. package/dist/utils/CheckYourAnswers/getCYAAction.test.js +53 -55
  137. package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.js +12 -21
  138. package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.test.js +32 -33
  139. package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.js +15 -28
  140. package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.test.js +41 -42
  141. package/dist/utils/CheckYourAnswers/getCYARow.js +7 -7
  142. package/dist/utils/CheckYourAnswers/getCYARow.test.js +87 -87
  143. package/dist/utils/CheckYourAnswers/getCYARowForGroup.js +19 -21
  144. package/dist/utils/CheckYourAnswers/getCYARowForGroup.test.js +16 -17
  145. package/dist/utils/CheckYourAnswers/getCYARowsForCollection.js +27 -34
  146. package/dist/utils/CheckYourAnswers/getCYARowsForCollection.test.js +48 -52
  147. package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +76 -93
  148. package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +110 -115
  149. package/dist/utils/CheckYourAnswers/getCYARowsForContainer.js +11 -16
  150. package/dist/utils/CheckYourAnswers/getCYARowsForContainer.test.js +112 -106
  151. package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +14 -19
  152. package/dist/utils/CheckYourAnswers/getCYARowsForPage.test.js +69 -73
  153. package/dist/utils/CheckYourAnswers/getSummaryListRowForDetails.js +7 -8
  154. package/dist/utils/CheckYourAnswers/getSummaryListRowForDetails.test.js +15 -16
  155. package/dist/utils/CheckYourAnswers/index.js +2 -2
  156. package/dist/utils/CheckYourAnswers/showComponentCYA.js +5 -5
  157. package/dist/utils/CheckYourAnswers/showComponentCYA.test.js +26 -26
  158. package/dist/utils/CollectionPage/addCollectionPageEntry.js +2 -2
  159. package/dist/utils/CollectionPage/addCollectionPageEntry.test.js +6 -6
  160. package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.js +3 -3
  161. package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.test.js +18 -19
  162. package/dist/utils/CollectionPage/duplicateCollectionPageEntry.js +13 -20
  163. package/dist/utils/CollectionPage/duplicateCollectionPageEntry.test.js +48 -39
  164. package/dist/utils/CollectionPage/getCollectionPageActiveId.js +2 -2
  165. package/dist/utils/CollectionPage/getCollectionPageActiveId.test.js +11 -11
  166. package/dist/utils/CollectionPage/getCollectionPageActiveIndex.js +7 -11
  167. package/dist/utils/CollectionPage/getCollectionPageActiveIndex.test.js +23 -23
  168. package/dist/utils/CollectionPage/getCollectionPageData.js +8 -12
  169. package/dist/utils/CollectionPage/getCollectionPageData.test.js +20 -20
  170. package/dist/utils/CollectionPage/getErrorsForCollection.js +20 -21
  171. package/dist/utils/CollectionPage/getErrorsForCollection.test.js +21 -23
  172. package/dist/utils/CollectionPage/getQuickEditPage.js +22 -23
  173. package/dist/utils/CollectionPage/getQuickEditPage.test.js +17 -18
  174. package/dist/utils/CollectionPage/index.js +2 -2
  175. package/dist/utils/CollectionPage/mergeCollectionPages.js +26 -35
  176. package/dist/utils/CollectionPage/mergeCollectionPages.test.js +18 -18
  177. package/dist/utils/CollectionPage/removeCollectionPageEntry.js +5 -7
  178. package/dist/utils/CollectionPage/removeCollectionPageEntry.test.js +11 -11
  179. package/dist/utils/CollectionPage/setCollectionPageData.js +10 -16
  180. package/dist/utils/CollectionPage/setCollectionPageData.test.js +25 -25
  181. package/dist/utils/Component/addShowWhen.js +5 -6
  182. package/dist/utils/Component/addShowWhen.test.js +38 -38
  183. package/dist/utils/Component/applyToComponentTree.js +12 -15
  184. package/dist/utils/Component/applyToComponentTree.test.js +28 -31
  185. package/dist/utils/Component/cleanAttributes.js +12 -11
  186. package/dist/utils/Component/cleanAttributes.test.js +17 -18
  187. package/dist/utils/Component/elevateNestedComponents.js +6 -6
  188. package/dist/utils/Component/elevateNestedComponents.test.js +34 -34
  189. package/dist/utils/Component/getComponent.js +79 -85
  190. package/dist/utils/Component/getComponentTests/getComponent.autocomplete.test.js +19 -18
  191. package/dist/utils/Component/getComponentTests/getComponent.calculation.test.js +41 -58
  192. package/dist/utils/Component/getComponentTests/getComponent.checkboxes.test.js +40 -49
  193. package/dist/utils/Component/getComponentTests/getComponent.date.test.js +24 -34
  194. package/dist/utils/Component/getComponentTests/getComponent.details.test.js +21 -19
  195. package/dist/utils/Component/getComponentTests/getComponent.email.test.js +18 -23
  196. package/dist/utils/Component/getComponentTests/getComponent.file.test.js +21 -26
  197. package/dist/utils/Component/getComponentTests/getComponent.heading.test.js +11 -10
  198. package/dist/utils/Component/getComponentTests/getComponent.html.test.js +18 -16
  199. package/dist/utils/Component/getComponentTests/getComponent.insetText.test.js +10 -9
  200. package/dist/utils/Component/getComponentTests/getComponent.list.test.js +18 -16
  201. package/dist/utils/Component/getComponentTests/getComponent.multifile.test.js +23 -27
  202. package/dist/utils/Component/getComponentTests/getComponent.nested.test.js +201 -226
  203. package/dist/utils/Component/getComponentTests/getComponent.paragraph.test.js +18 -16
  204. package/dist/utils/Component/getComponentTests/getComponent.phoneNumber.test.js +18 -23
  205. package/dist/utils/Component/getComponentTests/getComponent.radios.test.js +58 -73
  206. package/dist/utils/Component/getComponentTests/getComponent.select.test.js +18 -23
  207. package/dist/utils/Component/getComponentTests/getComponent.text.test.js +18 -23
  208. package/dist/utils/Component/getComponentTests/getComponent.textArea.test.js +32 -39
  209. package/dist/utils/Component/getComponentTests/getComponent.time.test.js +21 -30
  210. package/dist/utils/Component/getComponentTests/getComponent.unknown.test.js +3 -3
  211. package/dist/utils/Component/getComponentTests/getComponent.warningText.test.js +10 -9
  212. package/dist/utils/Component/getDefaultValue.js +7 -9
  213. package/dist/utils/Component/getDefaultValue.test.js +13 -13
  214. package/dist/utils/Component/getDefaultValueFromConfig.js +16 -20
  215. package/dist/utils/Component/getDefaultValueFromConfig.test.js +32 -32
  216. package/dist/utils/Component/index.js +2 -2
  217. package/dist/utils/Component/isEditable.js +2 -4
  218. package/dist/utils/Component/isEditable.test.js +14 -15
  219. package/dist/utils/Component/optionIsSelected.js +2 -4
  220. package/dist/utils/Component/optionIsSelected.test.js +12 -12
  221. package/dist/utils/Component/setupContainerComponentsPath.js +23 -28
  222. package/dist/utils/Component/setupContainerComponentsPath.test.js +12 -12
  223. package/dist/utils/Component/showComponent.js +2 -2
  224. package/dist/utils/Component/showComponent.test.js +29 -29
  225. package/dist/utils/Component/wrapInFormGroup.js +4 -4
  226. package/dist/utils/Condition/index.js +2 -2
  227. package/dist/utils/Condition/meetsAllConditions.js +9 -9
  228. package/dist/utils/Condition/meetsAllConditions.test.js +21 -21
  229. package/dist/utils/Condition/meetsCondition.js +17 -26
  230. package/dist/utils/Condition/meetsCondition.test.js +403 -403
  231. package/dist/utils/Condition/meetsOneCondition.js +6 -6
  232. package/dist/utils/Condition/meetsOneCondition.test.js +17 -17
  233. package/dist/utils/Condition/setupConditions.js +12 -15
  234. package/dist/utils/Condition/setupConditions.test.js +8 -8
  235. package/dist/utils/Container/getEditableComponents.js +4 -6
  236. package/dist/utils/Container/getEditableComponents.test.js +44 -46
  237. package/dist/utils/Container/index.js +2 -2
  238. package/dist/utils/Container/setupNesting.js +14 -15
  239. package/dist/utils/Container/setupNesting.test.js +20 -23
  240. package/dist/utils/Container/showContainer.js +4 -8
  241. package/dist/utils/Container/showContainer.test.js +31 -31
  242. package/dist/utils/Data/applyFormula.js +30 -44
  243. package/dist/utils/Data/applyFormula.test.js +21 -21
  244. package/dist/utils/Data/deleteValues.js +4 -8
  245. package/dist/utils/Data/deleteValues.test.js +11 -11
  246. package/dist/utils/Data/getAutocompleteSource.js +19 -27
  247. package/dist/utils/Data/getAutocompleteSource.test.js +76 -81
  248. package/dist/utils/Data/getDataPath.js +18 -28
  249. package/dist/utils/Data/getDataPath.test.js +13 -13
  250. package/dist/utils/Data/getOptions.js +35 -42
  251. package/dist/utils/Data/getOptions.test.js +37 -38
  252. package/dist/utils/Data/getSourceData.js +6 -19
  253. package/dist/utils/Data/getSourceData.test.js +85 -81
  254. package/dist/utils/Data/index.js +2 -2
  255. package/dist/utils/Data/nestInRefdataOptions.js +9 -12
  256. package/dist/utils/Data/nestInRefdataOptions.test.js +17 -17
  257. package/dist/utils/Data/refDataToOptions.js +9 -10
  258. package/dist/utils/Data/refDataToOptions.test.js +20 -20
  259. package/dist/utils/Data/setDataItem.js +7 -8
  260. package/dist/utils/Data/setDataItem.test.js +38 -38
  261. package/dist/utils/Data/setupFormData.js +13 -20
  262. package/dist/utils/Data/setupFormData.test.js +48 -47
  263. package/dist/utils/Data/setupRefDataUrlForComponent.js +11 -20
  264. package/dist/utils/Data/setupRefDataUrlForComponent.test.js +25 -25
  265. package/dist/utils/FormPage/applyConditionalProperties.js +7 -8
  266. package/dist/utils/FormPage/applyConditionalProperties.test.js +14 -15
  267. package/dist/utils/FormPage/getConditionalText.js +4 -4
  268. package/dist/utils/FormPage/getConditionalText.test.js +30 -30
  269. package/dist/utils/FormPage/getFormPage.js +12 -15
  270. package/dist/utils/FormPage/getFormPage.test.js +23 -24
  271. package/dist/utils/FormPage/getFormPages.js +8 -11
  272. package/dist/utils/FormPage/getFormPages.test.js +15 -16
  273. package/dist/utils/FormPage/getPageActions.js +10 -13
  274. package/dist/utils/FormPage/getPageActions.test.js +33 -33
  275. package/dist/utils/FormPage/getParagraphFromText.js +5 -7
  276. package/dist/utils/FormPage/getParagraphFromText.test.js +7 -7
  277. package/dist/utils/FormPage/index.js +3 -5
  278. package/dist/utils/FormPage/showFormPage.js +4 -8
  279. package/dist/utils/FormPage/showFormPage.test.js +33 -33
  280. package/dist/utils/FormPage/showFormPageCYA.js +2 -2
  281. package/dist/utils/FormPage/showFormPageCYA.test.js +9 -9
  282. package/dist/utils/FormPage/useComponent.js +15 -23
  283. package/dist/utils/FormPage/useComponent.test.js +49 -50
  284. package/dist/utils/Format/formatData.js +1 -1
  285. package/dist/utils/Format/formatData.test.js +19 -19
  286. package/dist/utils/Format/formatDataForComponent.js +6 -7
  287. package/dist/utils/Format/formatDataForComponent.test.js +50 -78
  288. package/dist/utils/Format/formatDataForForm.js +5 -6
  289. package/dist/utils/Format/formatDataForForm.test.js +14 -17
  290. package/dist/utils/Format/formatDataForPage.js +4 -5
  291. package/dist/utils/Format/formatDataForPage.test.js +20 -25
  292. package/dist/utils/Format/index.js +2 -2
  293. package/dist/utils/Hub/getFormHub.js +2 -2
  294. package/dist/utils/Hub/getFormHub.test.js +23 -24
  295. package/dist/utils/Hub/index.js +2 -2
  296. package/dist/utils/Meta/constants.js +2 -2
  297. package/dist/utils/Meta/documents/getDocuments.js +1 -1
  298. package/dist/utils/Meta/documents/getDocuments.test.js +25 -17
  299. package/dist/utils/Meta/documents/index.js +2 -2
  300. package/dist/utils/Meta/documents/setDocumentsForField.js +12 -13
  301. package/dist/utils/Meta/documents/setDocumentsForField.test.js +70 -33
  302. package/dist/utils/Meta/index.js +2 -2
  303. package/dist/utils/Operate/checkValueIsTruthy.js +3 -3
  304. package/dist/utils/Operate/checkValueIsTruthy.test.js +17 -17
  305. package/dist/utils/Operate/deleteValueInFormData.js +2 -2
  306. package/dist/utils/Operate/deleteValueInFormData.test.js +15 -15
  307. package/dist/utils/Operate/getFirstOf.js +6 -6
  308. package/dist/utils/Operate/getFirstOf.test.js +32 -32
  309. package/dist/utils/Operate/getIndexOfMatchingValueIn.js +11 -11
  310. package/dist/utils/Operate/getIndexOfMatchingValueIn.test.js +47 -53
  311. package/dist/utils/Operate/getLength.js +9 -9
  312. package/dist/utils/Operate/getLength.test.js +19 -19
  313. package/dist/utils/Operate/index.js +2 -2
  314. package/dist/utils/Operate/persistValueInFormData.js +4 -4
  315. package/dist/utils/Operate/persistValueInFormData.test.js +23 -21
  316. package/dist/utils/Operate/runPageOperations.js +8 -8
  317. package/dist/utils/Operate/runPageOperations.test.js +24 -25
  318. package/dist/utils/Operate/setValueInFormData.js +3 -3
  319. package/dist/utils/Operate/setValueInFormData.test.js +17 -17
  320. package/dist/utils/Operate/shouldRun.js +7 -7
  321. package/dist/utils/Operate/shouldRun.test.js +22 -24
  322. package/dist/utils/Validate/additional/conditionallyPermittedChange.js +1 -1
  323. package/dist/utils/Validate/additional/conditionallyPermittedChange.test.js +15 -15
  324. package/dist/utils/Validate/additional/conditionallyRequired.js +4 -4
  325. package/dist/utils/Validate/additional/conditionallyRequired.test.js +19 -19
  326. package/dist/utils/Validate/additional/index.js +8 -8
  327. package/dist/utils/Validate/additional/index.test.js +22 -22
  328. package/dist/utils/Validate/additional/mustBeAfter.js +3 -3
  329. package/dist/utils/Validate/additional/mustBeAfter.test.js +41 -41
  330. package/dist/utils/Validate/additional/mustBeBefore.js +3 -3
  331. package/dist/utils/Validate/additional/mustBeBefore.test.js +29 -29
  332. package/dist/utils/Validate/additional/mustBeEarlierDateTime.js +8 -12
  333. package/dist/utils/Validate/additional/mustBeEarlierDateTime.test.js +37 -38
  334. package/dist/utils/Validate/additional/mustBeGreaterThan.js +2 -2
  335. package/dist/utils/Validate/additional/mustBeGreaterThan.test.js +19 -19
  336. package/dist/utils/Validate/additional/mustBeInTheFuture.js +3 -3
  337. package/dist/utils/Validate/additional/mustBeInTheFuture.test.js +13 -13
  338. package/dist/utils/Validate/additional/mustBeInThePast.js +4 -4
  339. package/dist/utils/Validate/additional/mustBeInThePast.test.js +13 -13
  340. package/dist/utils/Validate/additional/mustBeLessThan.js +2 -2
  341. package/dist/utils/Validate/additional/mustBeLessThan.test.js +18 -18
  342. package/dist/utils/Validate/additional/mustBeLongerThan.js +1 -1
  343. package/dist/utils/Validate/additional/mustBeLongerThan.test.js +17 -17
  344. package/dist/utils/Validate/additional/mustBeNumbersOnly.js +2 -2
  345. package/dist/utils/Validate/additional/mustBeNumbersOnly.test.js +21 -21
  346. package/dist/utils/Validate/additional/mustBeOneOf.js +1 -1
  347. package/dist/utils/Validate/additional/mustBeOneOf.test.js +13 -13
  348. package/dist/utils/Validate/additional/mustBeShorterThan.js +1 -1
  349. package/dist/utils/Validate/additional/mustBeShorterThan.test.js +17 -17
  350. package/dist/utils/Validate/additional/mustBeUniqueInCollection.js +5 -5
  351. package/dist/utils/Validate/additional/mustBeUniqueInCollection.test.js +35 -36
  352. package/dist/utils/Validate/additional/mustEnterAtLeastOne.js +2 -2
  353. package/dist/utils/Validate/additional/mustEnterAtLeastOne.test.js +15 -17
  354. package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.js +1 -1
  355. package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.test.js +13 -13
  356. package/dist/utils/Validate/additional/mustNotContainSql.js +3 -4
  357. package/dist/utils/Validate/additional/mustNotContainSql.test.js +15 -15
  358. package/dist/utils/Validate/additional/mustSelectOnlyOne.js +2 -2
  359. package/dist/utils/Validate/additional/mustSelectOnlyOne.test.js +29 -27
  360. package/dist/utils/Validate/additional/utils.js +9 -22
  361. package/dist/utils/Validate/index.js +2 -2
  362. package/dist/utils/Validate/validateCollection.js +18 -23
  363. package/dist/utils/Validate/validateCollection.test.js +75 -67
  364. package/dist/utils/Validate/validateComponent.js +19 -19
  365. package/dist/utils/Validate/validateComponent.test.js +179 -154
  366. package/dist/utils/Validate/validateContainer.js +14 -17
  367. package/dist/utils/Validate/validateContainer.test.js +59 -53
  368. package/dist/utils/Validate/validateDate.js +16 -22
  369. package/dist/utils/Validate/validateDate.test.js +31 -32
  370. package/dist/utils/Validate/validateEmail.js +7 -9
  371. package/dist/utils/Validate/validateEmail.test.js +27 -27
  372. package/dist/utils/Validate/validateMultifile.js +5 -7
  373. package/dist/utils/Validate/validateMultifile.test.js +17 -18
  374. package/dist/utils/Validate/validatePage.js +13 -18
  375. package/dist/utils/Validate/validatePage.test.js +198 -195
  376. package/dist/utils/Validate/validateRegex.js +3 -5
  377. package/dist/utils/Validate/validateRegex.test.js +15 -15
  378. package/dist/utils/Validate/validateRequired.js +4 -6
  379. package/dist/utils/Validate/validateRequired.test.js +19 -19
  380. package/dist/utils/Validate/validateTextArea.js +4 -6
  381. package/dist/utils/Validate/validateTextArea.test.js +21 -21
  382. package/dist/utils/Validate/validateTime.js +12 -19
  383. package/dist/utils/Validate/validateTime.test.js +27 -27
  384. package/dist/utils/index.js +5 -6
  385. package/package.json +2 -4
@@ -9,1097 +9,924 @@ var _utils = _interopRequireDefault(require("../../utils"));
9
9
  var _Collection = require("./Collection");
10
10
  var _Container = require("./Container");
11
11
  var _FormComponent = _interopRequireDefault(require("./FormComponent"));
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
- 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); }
12
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
13
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
15
14
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
16
- 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; }
17
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
18
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
19
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
20
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
21
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
22
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
23
- 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); } }
24
- 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); }); }; }
25
- 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; }
26
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
27
- 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); } // Global imports
15
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
16
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
17
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } // Global imports
28
18
  // Local imports
29
- describe('components.FormComponent.Collection', function () {
30
- var ID = 'collection';
31
- var TEXT_ID = 'text';
32
- var TEXT_VALUE = 'alpha';
33
- var FORM_DATA = _defineProperty({}, ID, [_defineProperty({
34
- id: '1'
35
- }, TEXT_ID, TEXT_VALUE)]);
36
- var TEXT_COMPONENT = {
19
+ describe('components.FormComponent.Collection', () => {
20
+ const ID = 'collection';
21
+ const TEXT_ID = 'text';
22
+ const TEXT_VALUE = 'alpha';
23
+ const FORM_DATA = {
24
+ [ID]: [{
25
+ id: '1',
26
+ [TEXT_ID]: TEXT_VALUE
27
+ }]
28
+ };
29
+ const TEXT_COMPONENT = {
37
30
  id: TEXT_ID,
38
31
  fieldId: TEXT_ID,
39
32
  type: _models.ComponentTypes.TEXT,
40
33
  label: 'Text component',
41
34
  hint: 'Text hint'
42
35
  };
43
- it('should render a collection component appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
44
- var COLLECTION, _renderWithValidation, container, c, item, _item$childNodes, title, itemContainer, formGroup, label, hint, input;
45
- return _regeneratorRuntime().wrap(function _callee$(_context) {
46
- while (1) switch (_context.prev = _context.next) {
47
- case 0:
48
- COLLECTION = {
49
- id: ID,
50
- fieldId: ID,
51
- type: _models.ComponentTypes.COLLECTION,
52
- item: [TEXT_COMPONENT]
53
- };
54
- _renderWithValidation = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
55
- component: COLLECTION,
56
- value: FORM_DATA[ID],
57
- formData: FORM_DATA
58
- })), container = _renderWithValidation.container; // Check the container itself.
59
- c = container.childNodes[0];
60
- expect(c.tagName).toEqual('DIV');
61
- expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
62
-
63
- // And now check the single text component within it.
64
- item = c.childNodes[0];
65
- expect(item.tagName).toEqual('DIV');
66
- expect(item.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
67
- _item$childNodes = _slicedToArray(item.childNodes, 2), title = _item$childNodes[0], itemContainer = _item$childNodes[1];
68
- expect(title.tagName).toEqual('LABEL');
69
- expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
70
- expect(itemContainer.tagName).toEqual('DIV');
71
- expect(itemContainer.classList).toContain(_Container.DEFAULT_CLASS);
72
- formGroup = itemContainer.childNodes[0];
73
- expect(formGroup.tagName).toEqual('DIV');
74
- expect(formGroup.classList).toContain('govuk-form-group');
75
- label = formGroup.childNodes[0];
76
- expect(label.tagName).toEqual('LABEL');
77
- expect(label.classList).toContain('govuk-label');
78
- expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
79
- expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
80
- hint = formGroup.childNodes[1];
81
- expect(hint.tagName).toEqual('DIV');
82
- expect(hint.classList).toContain('govuk-hint');
83
- expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
84
- input = formGroup.childNodes[2];
85
- expect(input.tagName).toEqual('INPUT');
86
- expect(input.classList).toContain('govuk-input');
87
- expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
88
- expect(input.value).toEqual(TEXT_VALUE);
89
- case 30:
90
- case "end":
91
- return _context.stop();
92
- }
93
- }, _callee);
94
- })));
95
- it('should handle a change to a component appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
96
- var ON_CHANGE_EVENTS, ON_CHANGE, COLLECTION, _renderWithValidation2, container, c, item, formGroup, input, NEW_TEXT_VALUE, EVENT;
97
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
98
- while (1) switch (_context2.prev = _context2.next) {
99
- case 0:
100
- ON_CHANGE_EVENTS = [];
101
- ON_CHANGE = function ON_CHANGE(e) {
102
- ON_CHANGE_EVENTS.push(e);
103
- };
104
- COLLECTION = {
105
- id: ID,
106
- fieldId: ID,
107
- type: _models.ComponentTypes.COLLECTION,
108
- item: [{
109
- id: TEXT_ID,
110
- fieldId: TEXT_ID,
111
- type: _models.ComponentTypes.TEXT,
112
- label: 'Text component'
113
- }]
114
- };
115
- _renderWithValidation2 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
116
- component: COLLECTION,
117
- value: FORM_DATA[ID],
118
- formData: FORM_DATA,
119
- onChange: ON_CHANGE
120
- })), container = _renderWithValidation2.container; // Get hold of the text input.
121
- c = container.childNodes[0];
122
- item = c.childNodes[0];
123
- formGroup = item.childNodes[1].childNodes[0];
124
- input = formGroup.childNodes[2];
125
- NEW_TEXT_VALUE = 'bravo';
126
- EVENT = {
127
- target: {
128
- name: TEXT_ID,
129
- value: NEW_TEXT_VALUE
130
- }
131
- };
132
- _react.fireEvent.change(input, EVENT);
133
-
134
- // And confirm the formData has been changed.
135
- expect(ON_CHANGE_EVENTS.length).toEqual(1);
136
- expect(ON_CHANGE_EVENTS[0].target.name).toEqual(ID);
137
- expect(ON_CHANGE_EVENTS[0].target.value[0][TEXT_ID]).toEqual(NEW_TEXT_VALUE);
138
- case 14:
139
- case "end":
140
- return _context2.stop();
141
- }
142
- }, _callee2);
143
- })));
144
- it('should handle a null value appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
145
- var COLLECTION, _renderWithValidation3, container, c, buttonGroup, button;
146
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
147
- while (1) switch (_context3.prev = _context3.next) {
148
- case 0:
149
- COLLECTION = {
150
- id: ID,
151
- fieldId: ID,
152
- type: _models.ComponentTypes.COLLECTION,
153
- item: [TEXT_COMPONENT]
154
- };
155
- _renderWithValidation3 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
156
- component: COLLECTION
157
- })), container = _renderWithValidation3.container; // Check the container itself.
158
- c = container.childNodes[0];
159
- expect(c.tagName).toEqual('DIV');
160
- expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
161
-
162
- // And now make sure it has no children OTHER than the button to add an item.
163
- expect(c.childNodes.length).toEqual(1);
164
- buttonGroup = c.childNodes[0];
165
- expect(buttonGroup.tagName).toEqual('DIV');
166
- expect(buttonGroup.classList).toContain('hods-button-group');
167
- button = buttonGroup.childNodes[0];
168
- expect(button.tagName).toEqual('BUTTON');
169
- expect(button.classList).toContain('hods-button');
170
- expect(button.classList).toContain('hods-button--secondary');
171
- expect(button.textContent).toContain(_models.CollectionLabels.add);
172
- case 14:
173
- case "end":
174
- return _context3.stop();
175
- }
176
- }, _callee3);
177
- })));
178
- it('should handle a collection label appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
179
- var LABEL, COLLECTION, _renderWithValidation4, container, c, _c$childNodes, title, buttonGroup, button;
180
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
181
- while (1) switch (_context4.prev = _context4.next) {
182
- case 0:
183
- LABEL = 'Alpha Collection';
184
- COLLECTION = {
185
- id: ID,
186
- fieldId: ID,
187
- type: _models.ComponentTypes.COLLECTION,
188
- item: [TEXT_COMPONENT],
189
- label: LABEL
190
- };
191
- _renderWithValidation4 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
192
- component: COLLECTION
193
- })), container = _renderWithValidation4.container; // Check the container itself.
194
- c = container.childNodes[0];
195
- expect(c.tagName).toEqual('DIV');
196
- expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
197
-
198
- // And now make sure it has no children OTHER than the button to add an item.
199
- expect(c.childNodes.length).toEqual(2);
200
- _c$childNodes = _slicedToArray(c.childNodes, 2), title = _c$childNodes[0], buttonGroup = _c$childNodes[1];
201
- expect(title.tagName).toEqual('LABEL');
202
- expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__title"));
203
- expect(title.getAttribute('for')).toEqual(ID);
204
- expect(title.textContent).toContain(LABEL);
205
- expect(buttonGroup.tagName).toEqual('DIV');
206
- expect(buttonGroup.classList).toContain('hods-button-group');
207
- button = buttonGroup.childNodes[0];
208
- expect(button.tagName).toEqual('BUTTON');
209
- expect(button.classList).toContain('hods-button');
210
- expect(button.classList).toContain('hods-button--secondary');
211
- expect(button.textContent).toContain(_models.CollectionLabels.add);
212
- case 19:
213
- case "end":
214
- return _context4.stop();
215
- }
216
- }, _callee4);
217
- })));
218
- it('should handle the addition and removal of an item', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
219
- var COLLECTION, container, c, addButton, item, label, removeButton;
220
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
221
- while (1) switch (_context6.prev = _context6.next) {
222
- case 0:
223
- COLLECTION = {
224
- id: ID,
225
- fieldId: ID,
226
- type: _models.ComponentTypes.COLLECTION,
227
- item: [TEXT_COMPONENT]
228
- };
229
- container = document.createElement('div');
230
- document.body.appendChild(container);
231
- _context6.next = 5;
232
- return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
233
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
234
- while (1) switch (_context5.prev = _context5.next) {
235
- case 0:
236
- (0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
237
- component: COLLECTION
238
- }), container);
239
- case 1:
240
- case "end":
241
- return _context5.stop();
242
- }
243
- }, _callee5);
244
- })));
245
- case 5:
246
- // Check the container itself.
247
- c = container.childNodes[0];
248
- expect(c.tagName).toEqual('DIV');
249
- expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
250
-
251
- // And now make sure it has no children OTHER than the button to add an item.
252
- expect(c.childNodes.length).toEqual(1);
253
-
254
- // Get hold of that "Add another" button and click it.
255
- addButton = c.childNodes[0].childNodes[0];
256
- _react.fireEvent.click(addButton, {});
257
-
258
- // Make sure an item has been added.
259
- expect(c.childNodes.length).toEqual(2);
260
- item = c.childNodes[0];
261
- label = item.childNodes[0];
262
- expect(label.textContent).toContain(_utils.default.interpolateString(_models.CollectionLabels.item, {
263
- index: 1
264
- }));
265
-
266
- // Get hold of the newly-add item's "Remove" button.
267
- removeButton = label.childNodes[1];
268
- expect(removeButton.tagName).toEqual('BUTTON');
269
- expect(removeButton.classList).toContain('hods-button--secondary');
270
- expect(removeButton.textContent).toContain(_models.CollectionLabels.remove);
271
-
272
- // Click the "Remove" button
273
- _react.fireEvent.click(removeButton, {});
274
-
275
- // Make sure the item has been removed.
276
- expect(c.childNodes.length).toEqual(1);
277
- expect(c.childNodes[0].classList).toContain('hods-button-group');
278
- case 22:
279
- case "end":
280
- return _context6.stop();
281
- }
282
- }, _callee6);
283
- })));
284
- it('should handle the alternative styling', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
285
- var COLLECTION, container, c, addButton, item, label, removeButton;
286
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
287
- while (1) switch (_context8.prev = _context8.next) {
288
- case 0:
289
- COLLECTION = {
290
- id: ID,
291
- fieldId: ID,
292
- type: _models.ComponentTypes.COLLECTION,
293
- item: [TEXT_COMPONENT],
294
- removeLocation: 'end'
295
- };
296
- container = document.createElement('div');
297
- document.body.appendChild(container);
298
- _context8.next = 5;
299
- return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
300
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
301
- while (1) switch (_context7.prev = _context7.next) {
302
- case 0:
303
- (0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
304
- component: COLLECTION
305
- }), container);
306
- case 1:
307
- case "end":
308
- return _context7.stop();
309
- }
310
- }, _callee7);
311
- })));
312
- case 5:
313
- // Check the container itself.
314
- c = container.childNodes[0];
315
- expect(c.tagName).toEqual('DIV');
316
- expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
317
-
318
- // And now make sure it has no children OTHER than the button to add an item.
319
- expect(c.childNodes.length).toEqual(1);
320
-
321
- // Get hold of that "Add another" button and click it.
322
- addButton = c.childNodes[0].childNodes[0];
323
- _react.fireEvent.click(addButton, {});
324
-
325
- // Make sure an item has been added.
326
- expect(c.childNodes.length).toEqual(2);
327
- item = c.childNodes[0];
328
- label = item.childNodes[0];
329
- expect(label.textContent).toContain(_utils.default.interpolateString(_models.CollectionLabels.item, {
330
- index: 1
331
- }));
332
-
333
- // Get hold of the newly-add item's "Remove" button.
334
- removeButton = item.childNodes[2].childNodes[0];
335
- expect(removeButton.tagName).toEqual('BUTTON');
336
- expect(removeButton.classList).toContain('hods-button--secondary');
337
- expect(removeButton.textContent).toContain(_models.CollectionLabels.remove);
338
-
339
- // Click the "Remove" button
340
- _react.fireEvent.click(removeButton, {});
341
-
342
- // Make sure the item has been removed.
343
- expect(c.childNodes.length).toEqual(1);
344
- expect(c.childNodes[0].classList).toContain('hods-button-group');
345
- case 22:
346
- case "end":
347
- return _context8.stop();
348
- }
349
- }, _callee8);
350
- })));
351
- it('should appropriately make child components of items readonly', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
352
- var COLLECTION, _renderWithValidation5, container, c, item, _item$childNodes2, title, itemContainer, formGroup, label, hint, input;
353
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
354
- while (1) switch (_context9.prev = _context9.next) {
355
- case 0:
356
- COLLECTION = {
357
- id: ID,
358
- fieldId: ID,
359
- type: _models.ComponentTypes.COLLECTION,
360
- item: [TEXT_COMPONENT],
361
- readonly: true
362
- };
363
- _renderWithValidation5 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
364
- component: COLLECTION,
365
- value: FORM_DATA[ID],
366
- formData: FORM_DATA
367
- })), container = _renderWithValidation5.container; // Check the container itself.
368
- c = container.childNodes[0];
369
- expect(c.tagName).toEqual('DIV');
370
- expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
371
-
372
- // And now check the single text component within it.
373
- item = c.childNodes[0];
374
- expect(item.tagName).toEqual('DIV');
375
- expect(item.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
376
- _item$childNodes2 = _slicedToArray(item.childNodes, 2), title = _item$childNodes2[0], itemContainer = _item$childNodes2[1];
377
- expect(title.tagName).toEqual('LABEL');
378
- expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
379
- expect(itemContainer.tagName).toEqual('DIV');
380
- expect(itemContainer.classList).toContain(_Container.DEFAULT_CLASS);
381
- formGroup = itemContainer.childNodes[0];
382
- expect(formGroup.tagName).toEqual('DIV');
383
- expect(formGroup.classList).toContain('govuk-form-group');
384
- label = formGroup.childNodes[0];
385
- expect(label.tagName).toEqual('LABEL');
386
- expect(label.classList).toContain('govuk-label');
387
- expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
388
- expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
389
- hint = formGroup.childNodes[1];
390
- expect(hint.tagName).toEqual('DIV');
391
- expect(hint.classList).toContain('govuk-hint');
392
- expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
393
- input = formGroup.childNodes[2];
394
- expect(input.tagName).toEqual('DIV'); // Now readonly, so a DIV.
395
- expect(input.classList).toContain('hods-readonly'); // Now readonly, so hods-readonly
396
- expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
397
- expect(input.textContent).toEqual(TEXT_VALUE);
398
- case 30:
399
- case "end":
400
- return _context9.stop();
401
- }
402
- }, _callee9);
403
- })));
404
- it('should render a collection component with minimumEntries appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
405
- var COLLECTION, _renderWithValidation6, container, c, item, _item$childNodes3, title, itemContainer, formGroup, label, hint, input;
406
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
407
- while (1) switch (_context10.prev = _context10.next) {
408
- case 0:
409
- COLLECTION = {
410
- id: ID,
411
- fieldId: ID,
412
- type: _models.ComponentTypes.COLLECTION,
413
- item: [TEXT_COMPONENT],
414
- minimumEntries: 1
415
- };
416
- _renderWithValidation6 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
417
- component: COLLECTION,
418
- value: [],
419
- formData: {}
420
- })), container = _renderWithValidation6.container; // Check the container itself.
421
- c = container.childNodes[0];
422
- expect(c.tagName).toEqual('DIV');
423
- expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
424
-
425
- // And now check the single text component within it.
426
- item = c.childNodes[0];
427
- expect(item.tagName).toEqual('DIV');
428
- expect(item.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
429
- _item$childNodes3 = _slicedToArray(item.childNodes, 2), title = _item$childNodes3[0], itemContainer = _item$childNodes3[1];
430
- expect(title.tagName).toEqual('LABEL');
431
- expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
432
- expect(itemContainer.tagName).toEqual('DIV');
433
- expect(itemContainer.classList).toContain(_Container.DEFAULT_CLASS);
434
- formGroup = itemContainer.childNodes[0];
435
- expect(formGroup.tagName).toEqual('DIV');
436
- expect(formGroup.classList).toContain('govuk-form-group');
437
- label = formGroup.childNodes[0];
438
- expect(label.tagName).toEqual('LABEL');
439
- expect(label.classList).toContain('govuk-label');
440
- expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
441
- expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
442
- hint = formGroup.childNodes[1];
443
- expect(hint.tagName).toEqual('DIV');
444
- expect(hint.classList).toContain('govuk-hint');
445
- expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
446
- input = formGroup.childNodes[2];
447
- expect(input.tagName).toEqual('INPUT');
448
- expect(input.classList).toContain('govuk-input');
449
- expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
450
- expect(input.value).toEqual('');
451
- case 30:
452
- case "end":
453
- return _context10.stop();
454
- }
455
- }, _callee10);
456
- })));
457
- it('should render a collection component with only a hint on the first item(s) when restrictHint is truthy', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
458
- var FORM_DATA_TWO_ITEMS, TEXT_COMPONENT_TWO, COLLECTION, _renderWithValidation7, container, c, item, _item$childNodes4, title, itemContainer, formGroup, label, hint, input, itemTwo, _itemTwo$childNodes, titleTwo, itemContainerTwo, formGroupTwo, labelTwo, hintTwo, inputTwo;
459
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
460
- while (1) switch (_context11.prev = _context11.next) {
461
- case 0:
462
- FORM_DATA_TWO_ITEMS = [{
463
- id: '1',
464
- text: 'alpha',
465
- textTwo: 'charlie'
466
- }, {
467
- id: '2',
468
- text: 'beta',
469
- textTwo: 'delta'
470
- }];
471
- TEXT_COMPONENT_TWO = {
472
- id: 'textTwo',
473
- fieldId: 'textTwo',
474
- type: _models.ComponentTypes.TEXT,
475
- label: 'Text component two',
476
- hint: 'Text hint two'
477
- };
478
- COLLECTION = {
479
- id: ID,
480
- fieldId: ID,
481
- type: _models.ComponentTypes.COLLECTION,
482
- item: [TEXT_COMPONENT, TEXT_COMPONENT_TWO]
483
- };
484
- _renderWithValidation7 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
485
- component: _objectSpread(_objectSpread({}, COLLECTION), {}, {
486
- restrictHint: true
487
- }),
488
- value: FORM_DATA_TWO_ITEMS,
489
- formData: FORM_DATA
490
- })), container = _renderWithValidation7.container; // Check the container itself.
491
- c = container.childNodes[0];
492
- expect(c.tagName).toEqual('DIV');
493
- expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
494
-
495
- // And now check the first text component within it.
496
- item = c.childNodes[0];
497
- expect(item.tagName).toEqual('DIV');
498
- expect(item.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
499
- _item$childNodes4 = _slicedToArray(item.childNodes, 2), title = _item$childNodes4[0], itemContainer = _item$childNodes4[1];
500
- expect(title.tagName).toEqual('LABEL');
501
- expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
502
- expect(itemContainer.tagName).toEqual('DIV');
503
- expect(itemContainer.classList).toContain(_Container.DEFAULT_CLASS);
504
-
505
- // First item component 1
506
- formGroup = itemContainer.childNodes[0];
507
- expect(formGroup.tagName).toEqual('DIV');
508
- expect(formGroup.classList).toContain('govuk-form-group');
509
- label = formGroup.childNodes[0];
510
- expect(label.tagName).toEqual('LABEL');
511
- expect(label.classList).toContain('govuk-label');
512
- expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
513
- expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
514
- hint = formGroup.childNodes[1];
515
- expect(hint.tagName).toEqual('DIV');
516
- expect(hint.classList).toContain('govuk-hint');
517
- expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
518
- input = formGroup.childNodes[2];
519
- expect(input.tagName).toEqual('INPUT');
520
- expect(input.classList).toContain('govuk-input');
521
- expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
522
- expect(input.value).toEqual(TEXT_VALUE);
523
-
524
- // First item component 2
525
- formGroup = itemContainer.childNodes[1];
526
- expect(formGroup.tagName).toEqual('DIV');
527
- expect(formGroup.classList).toContain('govuk-form-group');
528
- label = formGroup.childNodes[0];
529
- expect(label.tagName).toEqual('LABEL');
530
- expect(label.classList).toContain('govuk-label');
531
- expect(label.textContent).toEqual('Text component two (optional)');
532
- expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].textTwo"));
533
- hint = formGroup.childNodes[1];
534
- expect(hint.tagName).toEqual('DIV');
535
- expect(hint.classList).toContain('govuk-hint');
536
- expect(hint.textContent).toEqual('Text hint two');
537
- input = formGroup.childNodes[2];
538
- expect(input.tagName).toEqual('INPUT');
539
- expect(input.classList).toContain('govuk-input');
540
- expect(input.id).toEqual("".concat(ID, "[0].textTwo"));
541
- expect(input.value).toEqual('charlie');
542
-
543
- // Check the second item and confirm there is no hint
544
- itemTwo = c.childNodes[1];
545
- expect(itemTwo.tagName).toEqual('DIV');
546
- expect(itemTwo.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
547
- _itemTwo$childNodes = _slicedToArray(itemTwo.childNodes, 2), titleTwo = _itemTwo$childNodes[0], itemContainerTwo = _itemTwo$childNodes[1];
548
- expect(titleTwo.tagName).toEqual('LABEL');
549
- expect(titleTwo.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
550
- expect(itemContainerTwo.tagName).toEqual('DIV');
551
- expect(itemContainerTwo.classList).toContain(_Container.DEFAULT_CLASS);
552
-
553
- // Second item first component
554
- formGroupTwo = itemContainerTwo.childNodes[0];
555
- expect(formGroupTwo.tagName).toEqual('DIV');
556
- expect(formGroupTwo.classList).toContain('govuk-form-group');
557
- labelTwo = formGroupTwo.childNodes[0];
558
- expect(labelTwo.tagName).toEqual('LABEL');
559
- expect(labelTwo.classList).toContain('govuk-label');
560
- expect(labelTwo.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
561
- expect(labelTwo.getAttribute('for')).toEqual("".concat(ID, "[1].").concat(TEXT_ID));
562
- hintTwo = formGroupTwo.childNodes[1];
563
- expect(hintTwo.tagName).toEqual(undefined);
564
- inputTwo = formGroupTwo.childNodes[2];
565
- expect(inputTwo.tagName).toEqual('INPUT');
566
- expect(inputTwo.classList).toContain('govuk-input');
567
- expect(inputTwo.id).toEqual("".concat(ID, "[1].").concat(TEXT_ID));
568
- expect(inputTwo.value).toEqual('beta');
569
-
570
- // Second item second component
571
- formGroupTwo = itemContainerTwo.childNodes[1];
572
- expect(formGroupTwo.tagName).toEqual('DIV');
573
- expect(formGroupTwo.classList).toContain('govuk-form-group');
574
- labelTwo = formGroupTwo.childNodes[0];
575
- expect(labelTwo.tagName).toEqual('LABEL');
576
- expect(labelTwo.classList).toContain('govuk-label');
577
- expect(labelTwo.textContent).toEqual('Text component two (optional)');
578
- expect(labelTwo.getAttribute('for')).toEqual("".concat(ID, "[1].textTwo"));
579
- hintTwo = formGroupTwo.childNodes[1];
580
- expect(hintTwo.tagName).toEqual(undefined);
581
- inputTwo = formGroupTwo.childNodes[2];
582
- expect(inputTwo.tagName).toEqual('INPUT');
583
- expect(inputTwo.classList).toContain('govuk-input');
584
- expect(inputTwo.id).toEqual("".concat(ID, "[1].textTwo"));
585
- expect(inputTwo.value).toEqual('delta');
586
- case 87:
587
- case "end":
588
- return _context11.stop();
589
- }
590
- }, _callee11);
591
- })));
592
- it('should render a unique label for the first item(s) when firstOnlyLabel is defined', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
593
- var UNIQUE_FIRST_LABEL_ONE, UNIQUE_FIRST_LABEL_TWO, FORM_DATA_TWO_ITEMS, TEXT_COMPONENT_TWO, COLLECTION, _renderWithValidation8, container, c, item, _item$childNodes5, title, itemContainer, formGroup, label, hint, input, itemTwo, _itemTwo$childNodes2, titleTwo, itemContainerTwo, formGroupTwo, labelTwo, hintTwo, inputTwo;
594
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
595
- while (1) switch (_context12.prev = _context12.next) {
596
- case 0:
597
- UNIQUE_FIRST_LABEL_ONE = 'justForTextOne';
598
- UNIQUE_FIRST_LABEL_TWO = 'justForTextTwo';
599
- FORM_DATA_TWO_ITEMS = [{
600
- id: '1',
601
- text: 'alpha',
602
- textTwo: 'charlie'
603
- }, {
604
- id: '2',
605
- text: 'beta',
606
- textTwo: 'delta'
607
- }];
608
- TEXT_COMPONENT_TWO = {
609
- id: 'textTwo',
610
- fieldId: 'textTwo',
611
- type: _models.ComponentTypes.TEXT,
612
- label: 'Text component two',
613
- hint: 'Text hint two',
614
- firstOnlyLabel: UNIQUE_FIRST_LABEL_TWO
615
- };
616
- COLLECTION = {
617
- id: ID,
618
- fieldId: ID,
619
- type: _models.ComponentTypes.COLLECTION,
620
- item: [_objectSpread(_objectSpread({}, TEXT_COMPONENT), {}, {
621
- firstOnlyLabel: UNIQUE_FIRST_LABEL_ONE
622
- }), TEXT_COMPONENT_TWO]
623
- };
624
- _renderWithValidation8 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
625
- component: _objectSpread(_objectSpread({}, COLLECTION), {}, {
626
- restrictHint: true
627
- }),
628
- value: FORM_DATA_TWO_ITEMS,
629
- formData: FORM_DATA
630
- })), container = _renderWithValidation8.container; // Check the container itself.
631
- c = container.childNodes[0];
632
- expect(c.tagName).toEqual('DIV');
633
- expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
634
-
635
- // And now check the first text component within it.
636
- item = c.childNodes[0];
637
- expect(item.tagName).toEqual('DIV');
638
- expect(item.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
639
- _item$childNodes5 = _slicedToArray(item.childNodes, 2), title = _item$childNodes5[0], itemContainer = _item$childNodes5[1];
640
- expect(title.tagName).toEqual('LABEL');
641
- expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
642
- expect(itemContainer.tagName).toEqual('DIV');
643
- expect(itemContainer.classList).toContain(_Container.DEFAULT_CLASS);
644
-
645
- // First item component 1
646
- formGroup = itemContainer.childNodes[0];
647
- expect(formGroup.tagName).toEqual('DIV');
648
- expect(formGroup.classList).toContain('govuk-form-group');
649
- label = formGroup.childNodes[0];
650
- expect(label.tagName).toEqual('LABEL');
651
- expect(label.classList).toContain('govuk-label');
652
- expect(label.textContent).toEqual("".concat(UNIQUE_FIRST_LABEL_ONE, " (optional)"));
653
- expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
654
- hint = formGroup.childNodes[1];
655
- expect(hint.tagName).toEqual('DIV');
656
- expect(hint.classList).toContain('govuk-hint');
657
- expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
658
- input = formGroup.childNodes[2];
659
- expect(input.tagName).toEqual('INPUT');
660
- expect(input.classList).toContain('govuk-input');
661
- expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
662
- expect(input.value).toEqual(TEXT_VALUE);
663
-
664
- // First item component 2
665
- formGroup = itemContainer.childNodes[1];
666
- expect(formGroup.tagName).toEqual('DIV');
667
- expect(formGroup.classList).toContain('govuk-form-group');
668
- label = formGroup.childNodes[0];
669
- expect(label.tagName).toEqual('LABEL');
670
- expect(label.classList).toContain('govuk-label');
671
- expect(label.textContent).toEqual("".concat(UNIQUE_FIRST_LABEL_TWO, " (optional)"));
672
- expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].textTwo"));
673
- hint = formGroup.childNodes[1];
674
- expect(hint.tagName).toEqual('DIV');
675
- expect(hint.classList).toContain('govuk-hint');
676
- expect(hint.textContent).toEqual('Text hint two');
677
- input = formGroup.childNodes[2];
678
- expect(input.tagName).toEqual('INPUT');
679
- expect(input.classList).toContain('govuk-input');
680
- expect(input.id).toEqual("".concat(ID, "[0].textTwo"));
681
- expect(input.value).toEqual('charlie');
682
-
683
- // Check the second item and confirm there is no hint
684
- itemTwo = c.childNodes[1];
685
- expect(itemTwo.tagName).toEqual('DIV');
686
- expect(itemTwo.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
687
- _itemTwo$childNodes2 = _slicedToArray(itemTwo.childNodes, 2), titleTwo = _itemTwo$childNodes2[0], itemContainerTwo = _itemTwo$childNodes2[1];
688
- expect(titleTwo.tagName).toEqual('LABEL');
689
- expect(titleTwo.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
690
- expect(itemContainerTwo.tagName).toEqual('DIV');
691
- expect(itemContainerTwo.classList).toContain(_Container.DEFAULT_CLASS);
692
-
693
- // Second item first component
694
- formGroupTwo = itemContainerTwo.childNodes[0];
695
- expect(formGroupTwo.tagName).toEqual('DIV');
696
- expect(formGroupTwo.classList).toContain('govuk-form-group');
697
- labelTwo = formGroupTwo.childNodes[0];
698
- expect(labelTwo.tagName).toEqual('LABEL');
699
- expect(labelTwo.classList).toContain('govuk-label');
700
- expect(labelTwo.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
701
- expect(labelTwo.getAttribute('for')).toEqual("".concat(ID, "[1].").concat(TEXT_ID));
702
- hintTwo = formGroupTwo.childNodes[1];
703
- expect(hintTwo.tagName).toEqual(undefined);
704
- inputTwo = formGroupTwo.childNodes[2];
705
- expect(inputTwo.tagName).toEqual('INPUT');
706
- expect(inputTwo.classList).toContain('govuk-input');
707
- expect(inputTwo.id).toEqual("".concat(ID, "[1].").concat(TEXT_ID));
708
- expect(inputTwo.value).toEqual('beta');
709
-
710
- // Second item second component
711
- formGroupTwo = itemContainerTwo.childNodes[1];
712
- expect(formGroupTwo.tagName).toEqual('DIV');
713
- expect(formGroupTwo.classList).toContain('govuk-form-group');
714
- labelTwo = formGroupTwo.childNodes[0];
715
- expect(labelTwo.tagName).toEqual('LABEL');
716
- expect(labelTwo.classList).toContain('govuk-label');
717
- expect(labelTwo.textContent).toEqual('Text component two (optional)');
718
- expect(labelTwo.getAttribute('for')).toEqual("".concat(ID, "[1].textTwo"));
719
- hintTwo = formGroupTwo.childNodes[1];
720
- expect(hintTwo.tagName).toEqual(undefined);
721
- inputTwo = formGroupTwo.childNodes[2];
722
- expect(inputTwo.tagName).toEqual('INPUT');
723
- expect(inputTwo.classList).toContain('govuk-input');
724
- expect(inputTwo.id).toEqual("".concat(ID, "[1].textTwo"));
725
- expect(inputTwo.value).toEqual('delta');
726
- case 89:
727
- case "end":
728
- return _context12.stop();
729
- }
730
- }, _callee12);
731
- })));
732
- it('should handle the alternative styling with a background and padding on the subsequent item(s) when subsequentItemStyle is provided', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
733
- var COLLECTION, container, c, addButton, item, label, secondItem, secondLabel;
734
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
735
- while (1) switch (_context14.prev = _context14.next) {
736
- case 0:
737
- COLLECTION = {
738
- id: ID,
739
- fieldId: ID,
740
- type: _models.ComponentTypes.COLLECTION,
741
- item: [TEXT_COMPONENT],
742
- subsequentItemStyle: {
743
- background: 'white',
744
- padding: '1px'
745
- }
746
- };
747
- container = document.createElement('div');
748
- document.body.appendChild(container);
749
- _context14.next = 5;
750
- return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
751
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
752
- while (1) switch (_context13.prev = _context13.next) {
753
- case 0:
754
- (0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
755
- component: COLLECTION
756
- }), container);
757
- case 1:
758
- case "end":
759
- return _context13.stop();
760
- }
761
- }, _callee13);
762
- })));
763
- case 5:
764
- // Check the container itself.
765
- c = container.childNodes[0];
766
- expect(c.tagName).toEqual('DIV');
767
- expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
768
-
769
- // And now make sure it has no children OTHER than the button to add an item.
770
- expect(c.childNodes.length).toEqual(1);
771
-
772
- // Get hold of that "Add another" button and click it.
773
- addButton = c.childNodes[0].childNodes[0];
774
- _react.fireEvent.click(addButton, {});
775
-
776
- // Make sure an item has been added.
777
- expect(c.childNodes.length).toEqual(2);
778
- item = c.childNodes[0];
779
- label = item.childNodes[0];
780
- expect(label.textContent).toContain(_utils.default.interpolateString(_models.CollectionLabels.item, {
781
- index: 1
782
- }));
783
-
784
- // Check to see if styling has been untouched for the first item
785
- expect(item.style.background).toEqual('');
786
- expect(item.style.padding).toEqual('');
787
-
788
- // Get hold of that "Add another" button and click it.
789
- _react.fireEvent.click(addButton, {});
790
-
791
- // Make sure another item has been added.
792
- expect(c.childNodes.length).toEqual(3);
793
- secondItem = c.childNodes[1];
794
- secondLabel = secondItem.childNodes[0];
795
- expect(secondLabel.textContent).toContain(_utils.default.interpolateString(_models.CollectionLabels.secondItem, {
796
- index: 2
797
- }));
798
-
799
- // Get hold of the second item and check background and padding has been applied.
800
- expect(secondItem.style.background).toEqual('white');
801
- expect(secondItem.style.padding).toEqual('1px');
802
- case 24:
803
- case "end":
804
- return _context14.stop();
805
- }
806
- }, _callee14);
807
- })));
808
- it('should shift focus to most recent item on addition and removal of an item when focusOnAdd is true', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
809
- var COLLECTION, container, c, addButton, item, label, secondItem, secondItemLabel, removeButton;
810
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
811
- while (1) switch (_context16.prev = _context16.next) {
812
- case 0:
813
- COLLECTION = {
814
- id: ID,
815
- fieldId: ID,
816
- type: _models.ComponentTypes.COLLECTION,
817
- item: [TEXT_COMPONENT],
818
- focusOnAdd: true
819
- };
820
- container = document.createElement('div');
821
- document.body.appendChild(container);
822
- _context16.next = 5;
823
- return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
824
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
825
- while (1) switch (_context15.prev = _context15.next) {
826
- case 0:
827
- (0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
828
- component: COLLECTION
829
- }), container);
830
- case 1:
831
- case "end":
832
- return _context15.stop();
833
- }
834
- }, _callee15);
835
- })));
836
- case 5:
837
- // Check the container itself.
838
- c = container.childNodes[0];
839
- expect(c.tagName).toEqual('DIV');
840
- expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
841
-
842
- // And now make sure it has no children OTHER than the button to add an item.
843
- expect(c.childNodes.length).toEqual(1);
844
-
845
- // Get hold of that "Add another" button and click it.
846
- addButton = c.childNodes[0].childNodes[0];
847
- _react.fireEvent.click(addButton, {});
848
-
849
- // Make sure an item has been added.
850
- expect(c.childNodes.length).toEqual(2);
851
- item = c.childNodes[0];
852
- label = item.childNodes[0];
853
- expect(label.textContent).toContain(_utils.default.interpolateString(_models.CollectionLabels.item, {
854
- index: 1
855
- }));
856
-
857
- // Check to see if the item's text input is in focus
858
- expect(document.activeElement === item.childNodes[1].childNodes[0].querySelector("input")).toEqual(true);
859
-
860
- // Add another item and check if the second item has been added and it's input is in focus
861
- _react.fireEvent.click(addButton, {});
862
- secondItem = c.childNodes[1];
863
- secondItemLabel = secondItem.childNodes[0];
864
- expect(c.childNodes.length).toEqual(3);
865
- expect(document.activeElement === secondItem.childNodes[1].childNodes[0].querySelector("input")).toEqual(true);
866
-
867
- // Get hold of the second item's "Remove" button.
868
- removeButton = secondItemLabel.childNodes[1];
869
- expect(removeButton.tagName).toEqual('BUTTON');
870
- expect(removeButton.classList).toContain('hods-button--secondary');
871
- expect(removeButton.textContent).toContain(_models.CollectionLabels.remove);
872
-
873
- // Click the "Remove" button
874
- _react.fireEvent.click(removeButton, {});
875
-
876
- // Make sure the second item has been removed.
877
- expect(c.childNodes.length).toEqual(2);
878
- expect(c.childNodes[1].classList).toContain('hods-button-group');
879
-
880
- // Check to see if the first item is now in focus
881
- expect(document.activeElement === item.childNodes[1].childNodes[0].querySelector("input")).toEqual(true);
882
- case 29:
883
- case "end":
884
- return _context16.stop();
36
+ it('should render a collection component appropriately', async () => {
37
+ const COLLECTION = {
38
+ id: ID,
39
+ fieldId: ID,
40
+ type: _models.ComponentTypes.COLLECTION,
41
+ item: [TEXT_COMPONENT]
42
+ };
43
+ const {
44
+ container
45
+ } = (0, _setupTests.renderWithValidation)(/*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
46
+ component: COLLECTION,
47
+ value: FORM_DATA[ID],
48
+ formData: FORM_DATA
49
+ }));
50
+
51
+ // Check the container itself.
52
+ const c = container.childNodes[0];
53
+ expect(c.tagName).toEqual('DIV');
54
+ expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
55
+
56
+ // And now check the single text component within it.
57
+ const item = c.childNodes[0];
58
+ expect(item.tagName).toEqual('DIV');
59
+ expect(item.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
60
+ const [title, itemContainer] = item.childNodes;
61
+ expect(title.tagName).toEqual('LABEL');
62
+ expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
63
+ expect(itemContainer.tagName).toEqual('DIV');
64
+ expect(itemContainer.classList).toContain(_Container.DEFAULT_CLASS);
65
+ const formGroup = itemContainer.childNodes[0];
66
+ expect(formGroup.tagName).toEqual('DIV');
67
+ expect(formGroup.classList).toContain('govuk-form-group');
68
+ const label = formGroup.childNodes[0];
69
+ expect(label.tagName).toEqual('LABEL');
70
+ expect(label.classList).toContain('govuk-label');
71
+ expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
72
+ expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
73
+ const hint = formGroup.childNodes[1];
74
+ expect(hint.tagName).toEqual('DIV');
75
+ expect(hint.classList).toContain('govuk-hint');
76
+ expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
77
+ const input = formGroup.childNodes[2];
78
+ expect(input.tagName).toEqual('INPUT');
79
+ expect(input.classList).toContain('govuk-input');
80
+ expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
81
+ expect(input.value).toEqual(TEXT_VALUE);
82
+ });
83
+ it('should handle a change to a component appropriately', async () => {
84
+ const ON_CHANGE_EVENTS = [];
85
+ const ON_CHANGE = e => {
86
+ ON_CHANGE_EVENTS.push(e);
87
+ };
88
+ const COLLECTION = {
89
+ id: ID,
90
+ fieldId: ID,
91
+ type: _models.ComponentTypes.COLLECTION,
92
+ item: [{
93
+ id: TEXT_ID,
94
+ fieldId: TEXT_ID,
95
+ type: _models.ComponentTypes.TEXT,
96
+ label: 'Text component'
97
+ }]
98
+ };
99
+ const {
100
+ container
101
+ } = (0, _setupTests.renderWithValidation)(/*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
102
+ component: COLLECTION,
103
+ value: FORM_DATA[ID],
104
+ formData: FORM_DATA,
105
+ onChange: ON_CHANGE
106
+ }));
107
+
108
+ // Get hold of the text input.
109
+ const c = container.childNodes[0];
110
+ const item = c.childNodes[0];
111
+ const formGroup = item.childNodes[1].childNodes[0];
112
+ const input = formGroup.childNodes[2];
113
+ const NEW_TEXT_VALUE = 'bravo';
114
+ const EVENT = {
115
+ target: {
116
+ name: TEXT_ID,
117
+ value: NEW_TEXT_VALUE
885
118
  }
886
- }, _callee16);
887
- })));
888
- it('should not focus on first item when minimumEntries is 1 and focus on added item instead when focusOnAdd is true', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
889
- var COLLECTION, container, c, item, _item$childNodes6, title, itemContainer, formGroup, label, hint, input, addButton, secondItem;
890
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
891
- while (1) switch (_context18.prev = _context18.next) {
892
- case 0:
893
- COLLECTION = {
894
- id: ID,
895
- fieldId: ID,
896
- type: _models.ComponentTypes.COLLECTION,
897
- item: [TEXT_COMPONENT],
898
- focusOnAdd: true,
899
- minimumEntries: 1
900
- };
901
- container = document.createElement('div');
902
- document.body.appendChild(container);
903
- _context18.next = 5;
904
- return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
905
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
906
- while (1) switch (_context17.prev = _context17.next) {
907
- case 0:
908
- (0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
909
- component: COLLECTION
910
- }), container);
911
- case 1:
912
- case "end":
913
- return _context17.stop();
914
- }
915
- }, _callee17);
916
- })));
917
- case 5:
918
- // Check the container itself.
919
- c = container.childNodes[0];
920
- expect(c.tagName).toEqual('DIV');
921
- expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
922
-
923
- // And now check the single text component within it.
924
- item = c.childNodes[0];
925
- expect(item.tagName).toEqual('DIV');
926
- expect(item.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
927
- _item$childNodes6 = _slicedToArray(item.childNodes, 2), title = _item$childNodes6[0], itemContainer = _item$childNodes6[1];
928
- expect(title.tagName).toEqual('LABEL');
929
- expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
930
- expect(itemContainer.tagName).toEqual('DIV');
931
- expect(itemContainer.classList).toContain(_Container.DEFAULT_CLASS);
932
- formGroup = itemContainer.childNodes[0];
933
- expect(formGroup.tagName).toEqual('DIV');
934
- expect(formGroup.classList).toContain('govuk-form-group');
935
- label = formGroup.childNodes[0];
936
- expect(label.tagName).toEqual('LABEL');
937
- expect(label.classList).toContain('govuk-label');
938
- expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
939
- expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
940
- hint = formGroup.childNodes[1];
941
- expect(hint.tagName).toEqual('DIV');
942
- expect(hint.classList).toContain('govuk-hint');
943
- expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
944
- input = formGroup.childNodes[2];
945
- expect(input.tagName).toEqual('INPUT');
946
- expect(input.classList).toContain('govuk-input');
947
- expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
948
- expect(input.value).toEqual('');
949
-
950
- // Check to see if the item's text input is not in focus
951
- expect(document.activeElement === item.childNodes[1].childNodes[0].querySelector("input")).toEqual(false);
952
-
953
- // Get hold of that "Add another" button and click it.
954
- addButton = c.childNodes[1].childNodes[0];
955
- _react.fireEvent.click(addButton, {});
956
-
957
- // Check if the second item has been added and it's input is in focus
958
- secondItem = c.childNodes[1];
959
- expect(c.childNodes.length).toEqual(3);
960
- expect(document.activeElement === secondItem.childNodes[1].childNodes[0].querySelector("input")).toEqual(true);
961
- case 39:
962
- case "end":
963
- return _context18.stop();
119
+ };
120
+ _react.fireEvent.change(input, EVENT);
121
+
122
+ // And confirm the formData has been changed.
123
+ expect(ON_CHANGE_EVENTS.length).toEqual(1);
124
+ expect(ON_CHANGE_EVENTS[0].target.name).toEqual(ID);
125
+ expect(ON_CHANGE_EVENTS[0].target.value[0][TEXT_ID]).toEqual(NEW_TEXT_VALUE);
126
+ });
127
+ it('should handle a null value appropriately', async () => {
128
+ const COLLECTION = {
129
+ id: ID,
130
+ fieldId: ID,
131
+ type: _models.ComponentTypes.COLLECTION,
132
+ item: [TEXT_COMPONENT]
133
+ };
134
+ const {
135
+ container
136
+ } = (0, _setupTests.renderWithValidation)(/*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
137
+ component: COLLECTION
138
+ }));
139
+
140
+ // Check the container itself.
141
+ const c = container.childNodes[0];
142
+ expect(c.tagName).toEqual('DIV');
143
+ expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
144
+
145
+ // And now make sure it has no children OTHER than the button to add an item.
146
+ expect(c.childNodes.length).toEqual(1);
147
+ const buttonGroup = c.childNodes[0];
148
+ expect(buttonGroup.tagName).toEqual('DIV');
149
+ expect(buttonGroup.classList).toContain('hods-button-group');
150
+ const button = buttonGroup.childNodes[0];
151
+ expect(button.tagName).toEqual('BUTTON');
152
+ expect(button.classList).toContain('hods-button');
153
+ expect(button.classList).toContain('hods-button--secondary');
154
+ expect(button.textContent).toContain(_models.CollectionLabels.add);
155
+ });
156
+ it('should handle a collection label appropriately', async () => {
157
+ const LABEL = 'Alpha Collection';
158
+ const COLLECTION = {
159
+ id: ID,
160
+ fieldId: ID,
161
+ type: _models.ComponentTypes.COLLECTION,
162
+ item: [TEXT_COMPONENT],
163
+ label: LABEL
164
+ };
165
+ const {
166
+ container
167
+ } = (0, _setupTests.renderWithValidation)(/*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
168
+ component: COLLECTION
169
+ }));
170
+
171
+ // Check the container itself.
172
+ const c = container.childNodes[0];
173
+ expect(c.tagName).toEqual('DIV');
174
+ expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
175
+
176
+ // And now make sure it has no children OTHER than the button to add an item.
177
+ expect(c.childNodes.length).toEqual(2);
178
+ const [title, buttonGroup] = c.childNodes;
179
+ expect(title.tagName).toEqual('LABEL');
180
+ expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__title"));
181
+ expect(title.getAttribute('for')).toEqual(ID);
182
+ expect(title.textContent).toContain(LABEL);
183
+ expect(buttonGroup.tagName).toEqual('DIV');
184
+ expect(buttonGroup.classList).toContain('hods-button-group');
185
+ const button = buttonGroup.childNodes[0];
186
+ expect(button.tagName).toEqual('BUTTON');
187
+ expect(button.classList).toContain('hods-button');
188
+ expect(button.classList).toContain('hods-button--secondary');
189
+ expect(button.textContent).toContain(_models.CollectionLabels.add);
190
+ });
191
+ it('should handle the addition and removal of an item', async () => {
192
+ const COLLECTION = {
193
+ id: ID,
194
+ fieldId: ID,
195
+ type: _models.ComponentTypes.COLLECTION,
196
+ item: [TEXT_COMPONENT]
197
+ };
198
+ const container = document.createElement('div');
199
+ document.body.appendChild(container);
200
+ await (0, _testUtils.act)(async () => {
201
+ (0, _setupTests.renderDomWithValidation)(/*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
202
+ component: COLLECTION
203
+ }), container);
204
+ });
205
+
206
+ // Check the container itself.
207
+ const c = container.childNodes[0];
208
+ expect(c.tagName).toEqual('DIV');
209
+ expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
210
+
211
+ // And now make sure it has no children OTHER than the button to add an item.
212
+ expect(c.childNodes.length).toEqual(1);
213
+
214
+ // Get hold of that "Add another" button and click it.
215
+ const addButton = c.childNodes[0].childNodes[0];
216
+ _react.fireEvent.click(addButton, {});
217
+
218
+ // Make sure an item has been added.
219
+ expect(c.childNodes.length).toEqual(2);
220
+ const item = c.childNodes[0];
221
+ const label = item.childNodes[0];
222
+ expect(label.textContent).toContain(_utils.default.interpolateString(_models.CollectionLabels.item, {
223
+ index: 1
224
+ }));
225
+
226
+ // Get hold of the newly-add item's "Remove" button.
227
+ const removeButton = label.childNodes[1];
228
+ expect(removeButton.tagName).toEqual('BUTTON');
229
+ expect(removeButton.classList).toContain('hods-button--secondary');
230
+ expect(removeButton.textContent).toContain(_models.CollectionLabels.remove);
231
+
232
+ // Click the "Remove" button
233
+ _react.fireEvent.click(removeButton, {});
234
+
235
+ // Make sure the item has been removed.
236
+ expect(c.childNodes.length).toEqual(1);
237
+ expect(c.childNodes[0].classList).toContain('hods-button-group');
238
+ });
239
+ it('should handle the alternative styling', async () => {
240
+ const COLLECTION = {
241
+ id: ID,
242
+ fieldId: ID,
243
+ type: _models.ComponentTypes.COLLECTION,
244
+ item: [TEXT_COMPONENT],
245
+ removeLocation: 'end'
246
+ };
247
+ const container = document.createElement('div');
248
+ document.body.appendChild(container);
249
+ await (0, _testUtils.act)(async () => {
250
+ (0, _setupTests.renderDomWithValidation)(/*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
251
+ component: COLLECTION
252
+ }), container);
253
+ });
254
+
255
+ // Check the container itself.
256
+ const c = container.childNodes[0];
257
+ expect(c.tagName).toEqual('DIV');
258
+ expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
259
+
260
+ // And now make sure it has no children OTHER than the button to add an item.
261
+ expect(c.childNodes.length).toEqual(1);
262
+
263
+ // Get hold of that "Add another" button and click it.
264
+ const addButton = c.childNodes[0].childNodes[0];
265
+ _react.fireEvent.click(addButton, {});
266
+
267
+ // Make sure an item has been added.
268
+ expect(c.childNodes.length).toEqual(2);
269
+ const item = c.childNodes[0];
270
+ const label = item.childNodes[0];
271
+ expect(label.textContent).toContain(_utils.default.interpolateString(_models.CollectionLabels.item, {
272
+ index: 1
273
+ }));
274
+
275
+ // Get hold of the newly-add item's "Remove" button.
276
+ const removeButton = item.childNodes[2].childNodes[0];
277
+ expect(removeButton.tagName).toEqual('BUTTON');
278
+ expect(removeButton.classList).toContain('hods-button--secondary');
279
+ expect(removeButton.textContent).toContain(_models.CollectionLabels.remove);
280
+
281
+ // Click the "Remove" button
282
+ _react.fireEvent.click(removeButton, {});
283
+
284
+ // Make sure the item has been removed.
285
+ expect(c.childNodes.length).toEqual(1);
286
+ expect(c.childNodes[0].classList).toContain('hods-button-group');
287
+ });
288
+ it('should appropriately make child components of items readonly', async () => {
289
+ const COLLECTION = {
290
+ id: ID,
291
+ fieldId: ID,
292
+ type: _models.ComponentTypes.COLLECTION,
293
+ item: [TEXT_COMPONENT],
294
+ readonly: true
295
+ };
296
+ const {
297
+ container
298
+ } = (0, _setupTests.renderWithValidation)(/*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
299
+ component: COLLECTION,
300
+ value: FORM_DATA[ID],
301
+ formData: FORM_DATA
302
+ }));
303
+
304
+ // Check the container itself.
305
+ const c = container.childNodes[0];
306
+ expect(c.tagName).toEqual('DIV');
307
+ expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
308
+
309
+ // And now check the single text component within it.
310
+ const item = c.childNodes[0];
311
+ expect(item.tagName).toEqual('DIV');
312
+ expect(item.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
313
+ const [title, itemContainer] = item.childNodes;
314
+ expect(title.tagName).toEqual('LABEL');
315
+ expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
316
+ expect(itemContainer.tagName).toEqual('DIV');
317
+ expect(itemContainer.classList).toContain(_Container.DEFAULT_CLASS);
318
+ const formGroup = itemContainer.childNodes[0];
319
+ expect(formGroup.tagName).toEqual('DIV');
320
+ expect(formGroup.classList).toContain('govuk-form-group');
321
+ const label = formGroup.childNodes[0];
322
+ expect(label.tagName).toEqual('LABEL');
323
+ expect(label.classList).toContain('govuk-label');
324
+ expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
325
+ expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
326
+ const hint = formGroup.childNodes[1];
327
+ expect(hint.tagName).toEqual('DIV');
328
+ expect(hint.classList).toContain('govuk-hint');
329
+ expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
330
+ const input = formGroup.childNodes[2];
331
+ expect(input.tagName).toEqual('DIV'); // Now readonly, so a DIV.
332
+ expect(input.classList).toContain('hods-readonly'); // Now readonly, so hods-readonly
333
+ expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
334
+ expect(input.textContent).toEqual(TEXT_VALUE);
335
+ });
336
+ it('should render a collection component with minimumEntries appropriately', async () => {
337
+ const COLLECTION = {
338
+ id: ID,
339
+ fieldId: ID,
340
+ type: _models.ComponentTypes.COLLECTION,
341
+ item: [TEXT_COMPONENT],
342
+ minimumEntries: 1
343
+ };
344
+ const {
345
+ container
346
+ } = (0, _setupTests.renderWithValidation)(/*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
347
+ component: COLLECTION,
348
+ value: [],
349
+ formData: {}
350
+ }));
351
+
352
+ // Check the container itself.
353
+ const c = container.childNodes[0];
354
+ expect(c.tagName).toEqual('DIV');
355
+ expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
356
+
357
+ // And now check the single text component within it.
358
+ const item = c.childNodes[0];
359
+ expect(item.tagName).toEqual('DIV');
360
+ expect(item.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
361
+ const [title, itemContainer] = item.childNodes;
362
+ expect(title.tagName).toEqual('LABEL');
363
+ expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
364
+ expect(itemContainer.tagName).toEqual('DIV');
365
+ expect(itemContainer.classList).toContain(_Container.DEFAULT_CLASS);
366
+ const formGroup = itemContainer.childNodes[0];
367
+ expect(formGroup.tagName).toEqual('DIV');
368
+ expect(formGroup.classList).toContain('govuk-form-group');
369
+ const label = formGroup.childNodes[0];
370
+ expect(label.tagName).toEqual('LABEL');
371
+ expect(label.classList).toContain('govuk-label');
372
+ expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
373
+ expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
374
+ const hint = formGroup.childNodes[1];
375
+ expect(hint.tagName).toEqual('DIV');
376
+ expect(hint.classList).toContain('govuk-hint');
377
+ expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
378
+ const input = formGroup.childNodes[2];
379
+ expect(input.tagName).toEqual('INPUT');
380
+ expect(input.classList).toContain('govuk-input');
381
+ expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
382
+ expect(input.value).toEqual('');
383
+ });
384
+ it('should render a collection component with only a hint on the first item(s) when restrictHint is truthy', async () => {
385
+ const FORM_DATA_TWO_ITEMS = [{
386
+ id: '1',
387
+ text: 'alpha',
388
+ textTwo: 'charlie'
389
+ }, {
390
+ id: '2',
391
+ text: 'beta',
392
+ textTwo: 'delta'
393
+ }];
394
+ const TEXT_COMPONENT_TWO = {
395
+ id: 'textTwo',
396
+ fieldId: 'textTwo',
397
+ type: _models.ComponentTypes.TEXT,
398
+ label: 'Text component two',
399
+ hint: 'Text hint two'
400
+ };
401
+ const COLLECTION = {
402
+ id: ID,
403
+ fieldId: ID,
404
+ type: _models.ComponentTypes.COLLECTION,
405
+ item: [TEXT_COMPONENT, TEXT_COMPONENT_TWO]
406
+ };
407
+ const {
408
+ container
409
+ } = (0, _setupTests.renderWithValidation)(/*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
410
+ component: _objectSpread(_objectSpread({}, COLLECTION), {}, {
411
+ restrictHint: true
412
+ }),
413
+ value: FORM_DATA_TWO_ITEMS,
414
+ formData: FORM_DATA
415
+ }));
416
+
417
+ // Check the container itself.
418
+ const c = container.childNodes[0];
419
+ expect(c.tagName).toEqual('DIV');
420
+ expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
421
+
422
+ // And now check the first text component within it.
423
+ const item = c.childNodes[0];
424
+ expect(item.tagName).toEqual('DIV');
425
+ expect(item.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
426
+ const [title, itemContainer] = item.childNodes;
427
+ expect(title.tagName).toEqual('LABEL');
428
+ expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
429
+ expect(itemContainer.tagName).toEqual('DIV');
430
+ expect(itemContainer.classList).toContain(_Container.DEFAULT_CLASS);
431
+
432
+ // First item component 1
433
+ let formGroup = itemContainer.childNodes[0];
434
+ expect(formGroup.tagName).toEqual('DIV');
435
+ expect(formGroup.classList).toContain('govuk-form-group');
436
+ let label = formGroup.childNodes[0];
437
+ expect(label.tagName).toEqual('LABEL');
438
+ expect(label.classList).toContain('govuk-label');
439
+ expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
440
+ expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
441
+ let hint = formGroup.childNodes[1];
442
+ expect(hint.tagName).toEqual('DIV');
443
+ expect(hint.classList).toContain('govuk-hint');
444
+ expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
445
+ let input = formGroup.childNodes[2];
446
+ expect(input.tagName).toEqual('INPUT');
447
+ expect(input.classList).toContain('govuk-input');
448
+ expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
449
+ expect(input.value).toEqual(TEXT_VALUE);
450
+
451
+ // First item component 2
452
+ formGroup = itemContainer.childNodes[1];
453
+ expect(formGroup.tagName).toEqual('DIV');
454
+ expect(formGroup.classList).toContain('govuk-form-group');
455
+ label = formGroup.childNodes[0];
456
+ expect(label.tagName).toEqual('LABEL');
457
+ expect(label.classList).toContain('govuk-label');
458
+ expect(label.textContent).toEqual('Text component two (optional)');
459
+ expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].textTwo"));
460
+ hint = formGroup.childNodes[1];
461
+ expect(hint.tagName).toEqual('DIV');
462
+ expect(hint.classList).toContain('govuk-hint');
463
+ expect(hint.textContent).toEqual('Text hint two');
464
+ input = formGroup.childNodes[2];
465
+ expect(input.tagName).toEqual('INPUT');
466
+ expect(input.classList).toContain('govuk-input');
467
+ expect(input.id).toEqual("".concat(ID, "[0].textTwo"));
468
+ expect(input.value).toEqual('charlie');
469
+
470
+ // Check the second item and confirm there is no hint
471
+ const itemTwo = c.childNodes[1];
472
+ expect(itemTwo.tagName).toEqual('DIV');
473
+ expect(itemTwo.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
474
+ const [titleTwo, itemContainerTwo] = itemTwo.childNodes;
475
+ expect(titleTwo.tagName).toEqual('LABEL');
476
+ expect(titleTwo.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
477
+ expect(itemContainerTwo.tagName).toEqual('DIV');
478
+ expect(itemContainerTwo.classList).toContain(_Container.DEFAULT_CLASS);
479
+
480
+ // Second item first component
481
+ let formGroupTwo = itemContainerTwo.childNodes[0];
482
+ expect(formGroupTwo.tagName).toEqual('DIV');
483
+ expect(formGroupTwo.classList).toContain('govuk-form-group');
484
+ let labelTwo = formGroupTwo.childNodes[0];
485
+ expect(labelTwo.tagName).toEqual('LABEL');
486
+ expect(labelTwo.classList).toContain('govuk-label');
487
+ expect(labelTwo.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
488
+ expect(labelTwo.getAttribute('for')).toEqual("".concat(ID, "[1].").concat(TEXT_ID));
489
+ let hintTwo = formGroupTwo.childNodes[1];
490
+ expect(hintTwo.tagName).toEqual(undefined);
491
+ let inputTwo = formGroupTwo.childNodes[2];
492
+ expect(inputTwo.tagName).toEqual('INPUT');
493
+ expect(inputTwo.classList).toContain('govuk-input');
494
+ expect(inputTwo.id).toEqual("".concat(ID, "[1].").concat(TEXT_ID));
495
+ expect(inputTwo.value).toEqual('beta');
496
+
497
+ // Second item second component
498
+ formGroupTwo = itemContainerTwo.childNodes[1];
499
+ expect(formGroupTwo.tagName).toEqual('DIV');
500
+ expect(formGroupTwo.classList).toContain('govuk-form-group');
501
+ labelTwo = formGroupTwo.childNodes[0];
502
+ expect(labelTwo.tagName).toEqual('LABEL');
503
+ expect(labelTwo.classList).toContain('govuk-label');
504
+ expect(labelTwo.textContent).toEqual('Text component two (optional)');
505
+ expect(labelTwo.getAttribute('for')).toEqual("".concat(ID, "[1].textTwo"));
506
+ hintTwo = formGroupTwo.childNodes[1];
507
+ expect(hintTwo.tagName).toEqual(undefined);
508
+ inputTwo = formGroupTwo.childNodes[2];
509
+ expect(inputTwo.tagName).toEqual('INPUT');
510
+ expect(inputTwo.classList).toContain('govuk-input');
511
+ expect(inputTwo.id).toEqual("".concat(ID, "[1].textTwo"));
512
+ expect(inputTwo.value).toEqual('delta');
513
+ });
514
+ it('should render a unique label for the first item(s) when firstOnlyLabel is defined', async () => {
515
+ const UNIQUE_FIRST_LABEL_ONE = 'justForTextOne';
516
+ const UNIQUE_FIRST_LABEL_TWO = 'justForTextTwo';
517
+ const FORM_DATA_TWO_ITEMS = [{
518
+ id: '1',
519
+ text: 'alpha',
520
+ textTwo: 'charlie'
521
+ }, {
522
+ id: '2',
523
+ text: 'beta',
524
+ textTwo: 'delta'
525
+ }];
526
+ const TEXT_COMPONENT_TWO = {
527
+ id: 'textTwo',
528
+ fieldId: 'textTwo',
529
+ type: _models.ComponentTypes.TEXT,
530
+ label: 'Text component two',
531
+ hint: 'Text hint two',
532
+ firstOnlyLabel: UNIQUE_FIRST_LABEL_TWO
533
+ };
534
+ const COLLECTION = {
535
+ id: ID,
536
+ fieldId: ID,
537
+ type: _models.ComponentTypes.COLLECTION,
538
+ item: [_objectSpread(_objectSpread({}, TEXT_COMPONENT), {}, {
539
+ firstOnlyLabel: UNIQUE_FIRST_LABEL_ONE
540
+ }), TEXT_COMPONENT_TWO]
541
+ };
542
+ const {
543
+ container
544
+ } = (0, _setupTests.renderWithValidation)(/*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
545
+ component: _objectSpread(_objectSpread({}, COLLECTION), {}, {
546
+ restrictHint: true
547
+ }),
548
+ value: FORM_DATA_TWO_ITEMS,
549
+ formData: FORM_DATA
550
+ }));
551
+
552
+ // Check the container itself.
553
+ const c = container.childNodes[0];
554
+ expect(c.tagName).toEqual('DIV');
555
+ expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
556
+
557
+ // And now check the first text component within it.
558
+ const item = c.childNodes[0];
559
+ expect(item.tagName).toEqual('DIV');
560
+ expect(item.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
561
+ const [title, itemContainer] = item.childNodes;
562
+ expect(title.tagName).toEqual('LABEL');
563
+ expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
564
+ expect(itemContainer.tagName).toEqual('DIV');
565
+ expect(itemContainer.classList).toContain(_Container.DEFAULT_CLASS);
566
+
567
+ // First item component 1
568
+ let formGroup = itemContainer.childNodes[0];
569
+ expect(formGroup.tagName).toEqual('DIV');
570
+ expect(formGroup.classList).toContain('govuk-form-group');
571
+ let label = formGroup.childNodes[0];
572
+ expect(label.tagName).toEqual('LABEL');
573
+ expect(label.classList).toContain('govuk-label');
574
+ expect(label.textContent).toEqual("".concat(UNIQUE_FIRST_LABEL_ONE, " (optional)"));
575
+ expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
576
+ let hint = formGroup.childNodes[1];
577
+ expect(hint.tagName).toEqual('DIV');
578
+ expect(hint.classList).toContain('govuk-hint');
579
+ expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
580
+ let input = formGroup.childNodes[2];
581
+ expect(input.tagName).toEqual('INPUT');
582
+ expect(input.classList).toContain('govuk-input');
583
+ expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
584
+ expect(input.value).toEqual(TEXT_VALUE);
585
+
586
+ // First item component 2
587
+ formGroup = itemContainer.childNodes[1];
588
+ expect(formGroup.tagName).toEqual('DIV');
589
+ expect(formGroup.classList).toContain('govuk-form-group');
590
+ label = formGroup.childNodes[0];
591
+ expect(label.tagName).toEqual('LABEL');
592
+ expect(label.classList).toContain('govuk-label');
593
+ expect(label.textContent).toEqual("".concat(UNIQUE_FIRST_LABEL_TWO, " (optional)"));
594
+ expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].textTwo"));
595
+ hint = formGroup.childNodes[1];
596
+ expect(hint.tagName).toEqual('DIV');
597
+ expect(hint.classList).toContain('govuk-hint');
598
+ expect(hint.textContent).toEqual('Text hint two');
599
+ input = formGroup.childNodes[2];
600
+ expect(input.tagName).toEqual('INPUT');
601
+ expect(input.classList).toContain('govuk-input');
602
+ expect(input.id).toEqual("".concat(ID, "[0].textTwo"));
603
+ expect(input.value).toEqual('charlie');
604
+
605
+ // Check the second item and confirm there is no hint
606
+ const itemTwo = c.childNodes[1];
607
+ expect(itemTwo.tagName).toEqual('DIV');
608
+ expect(itemTwo.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
609
+ const [titleTwo, itemContainerTwo] = itemTwo.childNodes;
610
+ expect(titleTwo.tagName).toEqual('LABEL');
611
+ expect(titleTwo.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
612
+ expect(itemContainerTwo.tagName).toEqual('DIV');
613
+ expect(itemContainerTwo.classList).toContain(_Container.DEFAULT_CLASS);
614
+
615
+ // Second item first component
616
+ let formGroupTwo = itemContainerTwo.childNodes[0];
617
+ expect(formGroupTwo.tagName).toEqual('DIV');
618
+ expect(formGroupTwo.classList).toContain('govuk-form-group');
619
+ let labelTwo = formGroupTwo.childNodes[0];
620
+ expect(labelTwo.tagName).toEqual('LABEL');
621
+ expect(labelTwo.classList).toContain('govuk-label');
622
+ expect(labelTwo.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
623
+ expect(labelTwo.getAttribute('for')).toEqual("".concat(ID, "[1].").concat(TEXT_ID));
624
+ let hintTwo = formGroupTwo.childNodes[1];
625
+ expect(hintTwo.tagName).toEqual(undefined);
626
+ let inputTwo = formGroupTwo.childNodes[2];
627
+ expect(inputTwo.tagName).toEqual('INPUT');
628
+ expect(inputTwo.classList).toContain('govuk-input');
629
+ expect(inputTwo.id).toEqual("".concat(ID, "[1].").concat(TEXT_ID));
630
+ expect(inputTwo.value).toEqual('beta');
631
+
632
+ // Second item second component
633
+ formGroupTwo = itemContainerTwo.childNodes[1];
634
+ expect(formGroupTwo.tagName).toEqual('DIV');
635
+ expect(formGroupTwo.classList).toContain('govuk-form-group');
636
+ labelTwo = formGroupTwo.childNodes[0];
637
+ expect(labelTwo.tagName).toEqual('LABEL');
638
+ expect(labelTwo.classList).toContain('govuk-label');
639
+ expect(labelTwo.textContent).toEqual('Text component two (optional)');
640
+ expect(labelTwo.getAttribute('for')).toEqual("".concat(ID, "[1].textTwo"));
641
+ hintTwo = formGroupTwo.childNodes[1];
642
+ expect(hintTwo.tagName).toEqual(undefined);
643
+ inputTwo = formGroupTwo.childNodes[2];
644
+ expect(inputTwo.tagName).toEqual('INPUT');
645
+ expect(inputTwo.classList).toContain('govuk-input');
646
+ expect(inputTwo.id).toEqual("".concat(ID, "[1].textTwo"));
647
+ expect(inputTwo.value).toEqual('delta');
648
+ });
649
+ it('should handle the alternative styling with a background and padding on the subsequent item(s) when subsequentItemStyle is provided', async () => {
650
+ const COLLECTION = {
651
+ id: ID,
652
+ fieldId: ID,
653
+ type: _models.ComponentTypes.COLLECTION,
654
+ item: [TEXT_COMPONENT],
655
+ subsequentItemStyle: {
656
+ background: 'white',
657
+ padding: '1px'
964
658
  }
965
- }, _callee18);
966
- })));
967
- it('should display the initial cta add label and revert to default cta label on subsequent additions', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
968
- var COLLECTION, container, c, addButton, item, label;
969
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
970
- while (1) switch (_context20.prev = _context20.next) {
971
- case 0:
972
- COLLECTION = {
973
- id: ID,
974
- fieldId: ID,
975
- type: _models.ComponentTypes.COLLECTION,
976
- item: [TEXT_COMPONENT],
977
- // eslint-disable-next-line no-template-curly-in-string
978
- labels: {
979
- add: 'Add another item',
980
- initial: 'Add an item',
981
- item: 'Item ${index}'
982
- }
983
- };
984
- container = document.createElement('div');
985
- document.body.appendChild(container);
986
- _context20.next = 5;
987
- return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
988
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
989
- while (1) switch (_context19.prev = _context19.next) {
990
- case 0:
991
- (0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
992
- component: COLLECTION
993
- }), container);
994
- case 1:
995
- case "end":
996
- return _context19.stop();
997
- }
998
- }, _callee19);
999
- })));
1000
- case 5:
1001
- // Check the container itself.
1002
- c = container.childNodes[0];
1003
- expect(c.tagName).toEqual('DIV');
1004
- expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
1005
-
1006
- // And now make sure it has no children OTHER than the button to add an item.
1007
- expect(c.childNodes.length).toEqual(1);
1008
-
1009
- // Get hold of that "Add another" button and click it.
1010
- addButton = c.childNodes[0].childNodes[0];
1011
- expect(addButton.textContent).toContain('Add an item');
1012
- _react.fireEvent.click(addButton, {});
1013
-
1014
- // Make sure an item has been added.
1015
- expect(c.childNodes.length).toEqual(2);
1016
- item = c.childNodes[0];
1017
- label = item.childNodes[0];
1018
- expect(label.textContent).toContain(_utils.default.interpolateString(_models.CollectionLabels.item, {
1019
- index: 1
1020
- }));
1021
-
1022
- // Check label of subsequent call to action button has updated
1023
- expect(addButton.textContent).toContain('Add another item');
1024
- case 17:
1025
- case "end":
1026
- return _context20.stop();
659
+ };
660
+ const container = document.createElement('div');
661
+ document.body.appendChild(container);
662
+ await (0, _testUtils.act)(async () => {
663
+ (0, _setupTests.renderDomWithValidation)(/*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
664
+ component: COLLECTION
665
+ }), container);
666
+ });
667
+
668
+ // Check the container itself.
669
+ const c = container.childNodes[0];
670
+ expect(c.tagName).toEqual('DIV');
671
+ expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
672
+
673
+ // And now make sure it has no children OTHER than the button to add an item.
674
+ expect(c.childNodes.length).toEqual(1);
675
+
676
+ // Get hold of that "Add another" button and click it.
677
+ const addButton = c.childNodes[0].childNodes[0];
678
+ _react.fireEvent.click(addButton, {});
679
+
680
+ // Make sure an item has been added.
681
+ expect(c.childNodes.length).toEqual(2);
682
+ const item = c.childNodes[0];
683
+ const label = item.childNodes[0];
684
+ expect(label.textContent).toContain(_utils.default.interpolateString(_models.CollectionLabels.item, {
685
+ index: 1
686
+ }));
687
+
688
+ // Check to see if styling has been untouched for the first item
689
+ expect(item.style.background).toEqual('');
690
+ expect(item.style.padding).toEqual('');
691
+
692
+ // Get hold of that "Add another" button and click it.
693
+ _react.fireEvent.click(addButton, {});
694
+
695
+ // Make sure another item has been added.
696
+ expect(c.childNodes.length).toEqual(3);
697
+ const secondItem = c.childNodes[1];
698
+ const secondLabel = secondItem.childNodes[0];
699
+ expect(secondLabel.textContent).toContain(_utils.default.interpolateString(_models.CollectionLabels.secondItem, {
700
+ index: 2
701
+ }));
702
+
703
+ // Get hold of the second item and check background and padding has been applied.
704
+ expect(secondItem.style.background).toEqual('white');
705
+ expect(secondItem.style.padding).toEqual('1px');
706
+ });
707
+ it('should shift focus to most recent item on addition and removal of an item when focusOnAdd is true', async () => {
708
+ const COLLECTION = {
709
+ id: ID,
710
+ fieldId: ID,
711
+ type: _models.ComponentTypes.COLLECTION,
712
+ item: [TEXT_COMPONENT],
713
+ focusOnAdd: true
714
+ };
715
+ const container = document.createElement('div');
716
+ document.body.appendChild(container);
717
+ await (0, _testUtils.act)(async () => {
718
+ (0, _setupTests.renderDomWithValidation)(/*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
719
+ component: COLLECTION
720
+ }), container);
721
+ });
722
+
723
+ // Check the container itself.
724
+ const c = container.childNodes[0];
725
+ expect(c.tagName).toEqual('DIV');
726
+ expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
727
+
728
+ // And now make sure it has no children OTHER than the button to add an item.
729
+ expect(c.childNodes.length).toEqual(1);
730
+
731
+ // Get hold of that "Add another" button and click it.
732
+ const addButton = c.childNodes[0].childNodes[0];
733
+ _react.fireEvent.click(addButton, {});
734
+
735
+ // Make sure an item has been added.
736
+ expect(c.childNodes.length).toEqual(2);
737
+ const item = c.childNodes[0];
738
+ const label = item.childNodes[0];
739
+ expect(label.textContent).toContain(_utils.default.interpolateString(_models.CollectionLabels.item, {
740
+ index: 1
741
+ }));
742
+
743
+ // Check to see if the item's text input is in focus
744
+ expect(document.activeElement === item.childNodes[1].childNodes[0].querySelector("input")).toEqual(true);
745
+
746
+ // Add another item and check if the second item has been added and it's input is in focus
747
+ _react.fireEvent.click(addButton, {});
748
+ const secondItem = c.childNodes[1];
749
+ const secondItemLabel = secondItem.childNodes[0];
750
+ expect(c.childNodes.length).toEqual(3);
751
+ expect(document.activeElement === secondItem.childNodes[1].childNodes[0].querySelector("input")).toEqual(true);
752
+
753
+ // Get hold of the second item's "Remove" button.
754
+ const removeButton = secondItemLabel.childNodes[1];
755
+ expect(removeButton.tagName).toEqual('BUTTON');
756
+ expect(removeButton.classList).toContain('hods-button--secondary');
757
+ expect(removeButton.textContent).toContain(_models.CollectionLabels.remove);
758
+
759
+ // Click the "Remove" button
760
+ _react.fireEvent.click(removeButton, {});
761
+
762
+ // Make sure the second item has been removed.
763
+ expect(c.childNodes.length).toEqual(2);
764
+ expect(c.childNodes[1].classList).toContain('hods-button-group');
765
+
766
+ // Check to see if the first item is now in focus
767
+ expect(document.activeElement === item.childNodes[1].childNodes[0].querySelector("input")).toEqual(true);
768
+ });
769
+ it('should not focus on first item when minimumEntries is 1 and focus on added item instead when focusOnAdd is true', async () => {
770
+ const COLLECTION = {
771
+ id: ID,
772
+ fieldId: ID,
773
+ type: _models.ComponentTypes.COLLECTION,
774
+ item: [TEXT_COMPONENT],
775
+ focusOnAdd: true,
776
+ minimumEntries: 1
777
+ };
778
+ const container = document.createElement('div');
779
+ document.body.appendChild(container);
780
+ await (0, _testUtils.act)(async () => {
781
+ (0, _setupTests.renderDomWithValidation)(/*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
782
+ component: COLLECTION
783
+ }), container);
784
+ });
785
+
786
+ // Check the container itself.
787
+ const c = container.childNodes[0];
788
+ expect(c.tagName).toEqual('DIV');
789
+ expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
790
+
791
+ // And now check the single text component within it.
792
+ const item = c.childNodes[0];
793
+ expect(item.tagName).toEqual('DIV');
794
+ expect(item.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
795
+ const [title, itemContainer] = item.childNodes;
796
+ expect(title.tagName).toEqual('LABEL');
797
+ expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
798
+ expect(itemContainer.tagName).toEqual('DIV');
799
+ expect(itemContainer.classList).toContain(_Container.DEFAULT_CLASS);
800
+ const formGroup = itemContainer.childNodes[0];
801
+ expect(formGroup.tagName).toEqual('DIV');
802
+ expect(formGroup.classList).toContain('govuk-form-group');
803
+ const label = formGroup.childNodes[0];
804
+ expect(label.tagName).toEqual('LABEL');
805
+ expect(label.classList).toContain('govuk-label');
806
+ expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
807
+ expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
808
+ const hint = formGroup.childNodes[1];
809
+ expect(hint.tagName).toEqual('DIV');
810
+ expect(hint.classList).toContain('govuk-hint');
811
+ expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
812
+ const input = formGroup.childNodes[2];
813
+ expect(input.tagName).toEqual('INPUT');
814
+ expect(input.classList).toContain('govuk-input');
815
+ expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
816
+ expect(input.value).toEqual('');
817
+
818
+ // Check to see if the item's text input is not in focus
819
+ expect(document.activeElement === item.childNodes[1].childNodes[0].querySelector("input")).toEqual(false);
820
+
821
+ // Get hold of that "Add another" button and click it.
822
+ const addButton = c.childNodes[1].childNodes[0];
823
+ _react.fireEvent.click(addButton, {});
824
+
825
+ // Check if the second item has been added and it's input is in focus
826
+ const secondItem = c.childNodes[1];
827
+ expect(c.childNodes.length).toEqual(3);
828
+ expect(document.activeElement === secondItem.childNodes[1].childNodes[0].querySelector("input")).toEqual(true);
829
+ });
830
+ it('should display the initial cta add label and revert to default cta label on subsequent additions', async () => {
831
+ const COLLECTION = {
832
+ id: ID,
833
+ fieldId: ID,
834
+ type: _models.ComponentTypes.COLLECTION,
835
+ item: [TEXT_COMPONENT],
836
+ // eslint-disable-next-line no-template-curly-in-string
837
+ labels: {
838
+ add: 'Add another item',
839
+ initial: 'Add an item',
840
+ item: 'Item ${index}'
1027
841
  }
1028
- }, _callee20);
1029
- })));
1030
- it('should revert back to the initial cta add label on adding and removing an item', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
1031
- var COLLECTION, container, c, addButton, item, label, removeButton;
1032
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1033
- while (1) switch (_context22.prev = _context22.next) {
1034
- case 0:
1035
- COLLECTION = {
1036
- id: ID,
1037
- fieldId: ID,
1038
- type: _models.ComponentTypes.COLLECTION,
1039
- item: [TEXT_COMPONENT],
1040
- // eslint-disable-next-line no-template-curly-in-string
1041
- labels: {
1042
- add: 'Add another item',
1043
- initial: 'Add an item',
1044
- item: 'Item ${index}'
1045
- }
1046
- };
1047
- container = document.createElement('div');
1048
- document.body.appendChild(container);
1049
- _context22.next = 5;
1050
- return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
1051
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1052
- while (1) switch (_context21.prev = _context21.next) {
1053
- case 0:
1054
- (0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
1055
- component: COLLECTION
1056
- }), container);
1057
- case 1:
1058
- case "end":
1059
- return _context21.stop();
1060
- }
1061
- }, _callee21);
1062
- })));
1063
- case 5:
1064
- // Check the container itself.
1065
- c = container.childNodes[0];
1066
- expect(c.tagName).toEqual('DIV');
1067
- expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
1068
-
1069
- // And now make sure it has no children OTHER than the button to add an item.
1070
- expect(c.childNodes.length).toEqual(1);
1071
-
1072
- // Get hold of that "Add another" button and click it.
1073
- addButton = c.childNodes[0].childNodes[0];
1074
- expect(addButton.textContent).toContain('Add an item');
1075
- _react.fireEvent.click(addButton, {});
1076
-
1077
- // Make sure an item has been added.
1078
- expect(c.childNodes.length).toEqual(2);
1079
- item = c.childNodes[0];
1080
- label = item.childNodes[0];
1081
- expect(label.textContent).toContain(_utils.default.interpolateString(_models.CollectionLabels.item, {
1082
- index: 1
1083
- }));
1084
-
1085
- // Check label of subsequent call to action button has updated
1086
- expect(addButton.textContent).toContain('Add another item');
1087
-
1088
- // Get hold of the newly-add item's "Remove" button.
1089
- removeButton = label.childNodes[1];
1090
- expect(removeButton.tagName).toEqual('BUTTON');
1091
- expect(removeButton.classList).toContain('hods-button--secondary');
1092
- expect(removeButton.textContent).toContain(_models.CollectionLabels.remove);
1093
-
1094
- // Click the "Remove" button
1095
- _react.fireEvent.click(removeButton, {});
1096
-
1097
- // Check label of subsequent call to action button has updated
1098
- expect(addButton.textContent).toContain('Add an item');
1099
- case 23:
1100
- case "end":
1101
- return _context22.stop();
842
+ };
843
+ const container = document.createElement('div');
844
+ document.body.appendChild(container);
845
+ await (0, _testUtils.act)(async () => {
846
+ (0, _setupTests.renderDomWithValidation)(/*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
847
+ component: COLLECTION
848
+ }), container);
849
+ });
850
+
851
+ // Check the container itself.
852
+ const c = container.childNodes[0];
853
+ expect(c.tagName).toEqual('DIV');
854
+ expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
855
+
856
+ // And now make sure it has no children OTHER than the button to add an item.
857
+ expect(c.childNodes.length).toEqual(1);
858
+
859
+ // Get hold of that "Add another" button and click it.
860
+ const addButton = c.childNodes[0].childNodes[0];
861
+ expect(addButton.textContent).toContain('Add an item');
862
+ _react.fireEvent.click(addButton, {});
863
+
864
+ // Make sure an item has been added.
865
+ expect(c.childNodes.length).toEqual(2);
866
+ const item = c.childNodes[0];
867
+ const label = item.childNodes[0];
868
+ expect(label.textContent).toContain(_utils.default.interpolateString(_models.CollectionLabels.item, {
869
+ index: 1
870
+ }));
871
+
872
+ // Check label of subsequent call to action button has updated
873
+ expect(addButton.textContent).toContain('Add another item');
874
+ });
875
+ it('should revert back to the initial cta add label on adding and removing an item', async () => {
876
+ const COLLECTION = {
877
+ id: ID,
878
+ fieldId: ID,
879
+ type: _models.ComponentTypes.COLLECTION,
880
+ item: [TEXT_COMPONENT],
881
+ // eslint-disable-next-line no-template-curly-in-string
882
+ labels: {
883
+ add: 'Add another item',
884
+ initial: 'Add an item',
885
+ item: 'Item ${index}'
1102
886
  }
1103
- }, _callee22);
1104
- })));
887
+ };
888
+ const container = document.createElement('div');
889
+ document.body.appendChild(container);
890
+ await (0, _testUtils.act)(async () => {
891
+ (0, _setupTests.renderDomWithValidation)(/*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
892
+ component: COLLECTION
893
+ }), container);
894
+ });
895
+
896
+ // Check the container itself.
897
+ const c = container.childNodes[0];
898
+ expect(c.tagName).toEqual('DIV');
899
+ expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
900
+
901
+ // And now make sure it has no children OTHER than the button to add an item.
902
+ expect(c.childNodes.length).toEqual(1);
903
+
904
+ // Get hold of that "Add another" button and click it.
905
+ const addButton = c.childNodes[0].childNodes[0];
906
+ expect(addButton.textContent).toContain('Add an item');
907
+ _react.fireEvent.click(addButton, {});
908
+
909
+ // Make sure an item has been added.
910
+ expect(c.childNodes.length).toEqual(2);
911
+ const item = c.childNodes[0];
912
+ const label = item.childNodes[0];
913
+ expect(label.textContent).toContain(_utils.default.interpolateString(_models.CollectionLabels.item, {
914
+ index: 1
915
+ }));
916
+
917
+ // Check label of subsequent call to action button has updated
918
+ expect(addButton.textContent).toContain('Add another item');
919
+
920
+ // Get hold of the newly-add item's "Remove" button.
921
+ const removeButton = label.childNodes[1];
922
+ expect(removeButton.tagName).toEqual('BUTTON');
923
+ expect(removeButton.classList).toContain('hods-button--secondary');
924
+ expect(removeButton.textContent).toContain(_models.CollectionLabels.remove);
925
+
926
+ // Click the "Remove" button
927
+ _react.fireEvent.click(removeButton, {});
928
+
929
+ // Check label of subsequent call to action button has updated
930
+ expect(addButton.textContent).toContain('Add an item');
931
+ });
1105
932
  });