@ukhomeoffice/cop-react-form-renderer 4.67.0 → 4.69.0

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 (317) hide show
  1. package/dist/components/CheckYourAnswers/Answer.js +6 -16
  2. package/dist/components/CheckYourAnswers/Answer.test.js +104 -129
  3. package/dist/components/CheckYourAnswers/CheckYourAnswers.js +26 -64
  4. package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +428 -555
  5. package/dist/components/CheckYourAnswers/index.js +0 -3
  6. package/dist/components/CollectionPage/CollectionPage.js +13 -42
  7. package/dist/components/CollectionPage/CollectionPage.test.js +160 -206
  8. package/dist/components/CollectionPage/index.js +0 -3
  9. package/dist/components/FormComponent/Collection.js +35 -79
  10. package/dist/components/FormComponent/Collection.test.js +340 -391
  11. package/dist/components/FormComponent/Container.js +10 -31
  12. package/dist/components/FormComponent/Container.test.js +304 -357
  13. package/dist/components/FormComponent/FormComponent.js +17 -60
  14. package/dist/components/FormComponent/FormComponent.test.js +190 -228
  15. package/dist/components/FormComponent/helpers/addLabel.js +4 -7
  16. package/dist/components/FormComponent/helpers/getComponentDisabled.js +0 -4
  17. package/dist/components/FormComponent/helpers/getComponentDisabled.test.js +0 -2
  18. package/dist/components/FormComponent/helpers/getComponentError.js +0 -6
  19. package/dist/components/FormComponent/helpers/getComponentError.test.js +0 -2
  20. package/dist/components/FormComponent/helpers/index.js +0 -4
  21. package/dist/components/FormComponent/index.js +0 -3
  22. package/dist/components/FormPage/FormPage.js +21 -53
  23. package/dist/components/FormPage/FormPage.test.js +122 -160
  24. package/dist/components/FormPage/index.js +0 -3
  25. package/dist/components/FormRenderer/FormRenderer.js +106 -296
  26. package/dist/components/FormRenderer/FormRenderer.test.js +820 -1058
  27. package/dist/components/FormRenderer/handlers/cyaAction.js +0 -5
  28. package/dist/components/FormRenderer/handlers/getPageId.js +0 -2
  29. package/dist/components/FormRenderer/handlers/getPageId.test.js +1 -2
  30. package/dist/components/FormRenderer/handlers/handlers.test.js +1 -18
  31. package/dist/components/FormRenderer/handlers/index.js +0 -5
  32. package/dist/components/FormRenderer/handlers/navigate.js +0 -5
  33. package/dist/components/FormRenderer/handlers/submissionError.js +0 -2
  34. package/dist/components/FormRenderer/helpers/canActionProceed.js +0 -3
  35. package/dist/components/FormRenderer/helpers/canActionProceed.test.js +1 -3
  36. package/dist/components/FormRenderer/helpers/canCYASubmit.js +0 -2
  37. package/dist/components/FormRenderer/helpers/canCYASubmit.test.js +1 -5
  38. package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.js +12 -16
  39. package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.test.js +48 -11
  40. package/dist/components/FormRenderer/helpers/getCYA.js +0 -9
  41. package/dist/components/FormRenderer/helpers/getCYA.test.js +1 -3
  42. package/dist/components/FormRenderer/helpers/getFormState.js +0 -5
  43. package/dist/components/FormRenderer/helpers/getFormState.test.js +1 -3
  44. package/dist/components/FormRenderer/helpers/getNextPageId.js +0 -25
  45. package/dist/components/FormRenderer/helpers/getNextPageId.test.js +1 -4
  46. package/dist/components/FormRenderer/helpers/getPage.js +0 -5
  47. package/dist/components/FormRenderer/helpers/getPage.test.js +1 -3
  48. package/dist/components/FormRenderer/helpers/getRelevantPages.js +0 -6
  49. package/dist/components/FormRenderer/helpers/getRelevantPages.test.js +1 -3
  50. package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +0 -10
  51. package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +4 -7
  52. package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.js +32 -41
  53. package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.test.js +122 -8
  54. package/dist/components/FormRenderer/helpers/index.js +1 -11
  55. package/dist/components/FormRenderer/index.js +0 -3
  56. package/dist/components/FormRenderer/onCYAAction.js +8 -30
  57. package/dist/components/FormRenderer/onCYAAction.test.js +54 -79
  58. package/dist/components/FormRenderer/onPageAction.js +123 -0
  59. package/dist/components/FormRenderer/onPageAction.test.js +632 -0
  60. package/dist/components/PageActions/ActionButton.js +2 -17
  61. package/dist/components/PageActions/ActionButton.test.js +58 -81
  62. package/dist/components/PageActions/PageActions.js +3 -10
  63. package/dist/components/PageActions/PageActions.test.js +95 -120
  64. package/dist/components/PageActions/index.js +0 -3
  65. package/dist/components/SummaryList/GroupAction.js +5 -26
  66. package/dist/components/SummaryList/GroupAction.test.js +14 -28
  67. package/dist/components/SummaryList/RowAction.js +5 -25
  68. package/dist/components/SummaryList/RowAction.test.js +14 -28
  69. package/dist/components/SummaryList/SummaryList.js +7 -31
  70. package/dist/components/SummaryList/SummaryList.test.js +69 -126
  71. package/dist/components/SummaryList/SummaryListHeadingRow.js +3 -8
  72. package/dist/components/SummaryList/SummaryListRow.js +4 -8
  73. package/dist/components/SummaryList/SummaryListTitleRow.js +2 -7
  74. package/dist/components/SummaryList/helpers/getGroupActionAttributes.js +0 -3
  75. package/dist/components/SummaryList/helpers/getGroupActionAttributes.test.js +0 -6
  76. package/dist/components/SummaryList/helpers/getRowActionAttributes.js +0 -3
  77. package/dist/components/SummaryList/helpers/getRowActionAttributes.test.js +0 -6
  78. package/dist/components/SummaryList/helpers/index.js +0 -2
  79. package/dist/components/SummaryList/index.js +0 -3
  80. package/dist/components/TaskList/Task.js +9 -31
  81. package/dist/components/TaskList/Task.test.js +32 -59
  82. package/dist/components/TaskList/TaskList.js +32 -59
  83. package/dist/components/TaskList/TaskList.test.js +52 -90
  84. package/dist/components/TaskList/TaskState.js +2 -10
  85. package/dist/components/TaskList/TaskState.test.js +23 -41
  86. package/dist/components/TaskList/index.js +0 -3
  87. package/dist/components/index.js +0 -7
  88. package/dist/context/HooksContext/HooksContext.js +21 -39
  89. package/dist/context/HooksContext/HooksContext.test.js +18 -34
  90. package/dist/context/HooksContext/index.js +0 -5
  91. package/dist/context/ValidationContext/ValidationContext.js +26 -56
  92. package/dist/context/ValidationContext/ValidationContext.test.js +43 -64
  93. package/dist/context/ValidationContext/index.js +0 -5
  94. package/dist/context/index.js +0 -3
  95. package/dist/hooks/index.js +0 -9
  96. package/dist/hooks/useAxios.js +17 -36
  97. package/dist/hooks/useGetRequest.js +57 -93
  98. package/dist/hooks/useHooks.js +2 -4
  99. package/dist/hooks/useRefData.js +14 -41
  100. package/dist/hooks/useValidation.js +2 -4
  101. package/dist/index.js +0 -9
  102. package/dist/models/PageAction.js +4 -4
  103. package/dist/models/TaskStates.js +4 -4
  104. package/dist/models/index.js +1 -10
  105. package/dist/setupTests.js +0 -13
  106. package/dist/utils/CheckYourAnswers/getCYAAction.js +1 -9
  107. package/dist/utils/CheckYourAnswers/getCYAAction.test.js +1 -19
  108. package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.js +4 -11
  109. package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.test.js +4 -9
  110. package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.js +4 -9
  111. package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.test.js +4 -8
  112. package/dist/utils/CheckYourAnswers/getCYARow.js +3 -11
  113. package/dist/utils/CheckYourAnswers/getCYARow.test.js +60 -25
  114. package/dist/utils/CheckYourAnswers/getCYARowForGroup.js +6 -21
  115. package/dist/utils/CheckYourAnswers/getCYARowForGroup.test.js +2 -9
  116. package/dist/utils/CheckYourAnswers/getCYARowsForCollection.js +4 -20
  117. package/dist/utils/CheckYourAnswers/getCYARowsForCollection.test.js +7 -22
  118. package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +4 -32
  119. package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +4 -34
  120. package/dist/utils/CheckYourAnswers/getCYARowsForContainer.js +4 -15
  121. package/dist/utils/CheckYourAnswers/getCYARowsForContainer.test.js +4 -22
  122. package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +2 -22
  123. package/dist/utils/CheckYourAnswers/getCYARowsForPage.test.js +7 -25
  124. package/dist/utils/CheckYourAnswers/index.js +1 -3
  125. package/dist/utils/CheckYourAnswers/showComponentCYA.js +2 -15
  126. package/dist/utils/CheckYourAnswers/showComponentCYA.test.js +1 -3
  127. package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.js +4 -12
  128. package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.test.js +5 -6
  129. package/dist/utils/CollectionPage/getCollectionPageActiveIndex.js +0 -6
  130. package/dist/utils/CollectionPage/getCollectionPageActiveIndex.test.js +1 -2
  131. package/dist/utils/CollectionPage/index.js +1 -5
  132. package/dist/utils/CollectionPage/mergeCollectionPages.js +5 -11
  133. package/dist/utils/CollectionPage/mergeCollectionPages.test.js +1 -2
  134. package/dist/utils/Component/addShowWhen.js +4 -10
  135. package/dist/utils/Component/addShowWhen.test.js +1 -2
  136. package/dist/utils/Component/applyToComponentTree.js +4 -18
  137. package/dist/utils/Component/applyToComponentTree.test.js +4 -8
  138. package/dist/utils/Component/cleanAttributes.js +1 -8
  139. package/dist/utils/Component/cleanAttributes.test.js +15 -16
  140. package/dist/utils/Component/elevateNestedComponents.js +0 -6
  141. package/dist/utils/Component/elevateNestedComponents.test.js +0 -2
  142. package/dist/utils/Component/getComponent.js +13 -86
  143. package/dist/utils/Component/getComponentTests/getComponent.autocomplete.test.js +6 -10
  144. package/dist/utils/Component/getComponentTests/getComponent.calculation.test.js +33 -51
  145. package/dist/utils/Component/getComponentTests/getComponent.checkboxes.test.js +8 -35
  146. package/dist/utils/Component/getComponentTests/getComponent.date.test.js +12 -29
  147. package/dist/utils/Component/getComponentTests/getComponent.details.test.js +4 -10
  148. package/dist/utils/Component/getComponentTests/getComponent.email.test.js +6 -23
  149. package/dist/utils/Component/getComponentTests/getComponent.file.test.js +6 -24
  150. package/dist/utils/Component/getComponentTests/getComponent.heading.test.js +3 -7
  151. package/dist/utils/Component/getComponentTests/getComponent.html.test.js +4 -10
  152. package/dist/utils/Component/getComponentTests/getComponent.insetText.test.js +3 -7
  153. package/dist/utils/Component/getComponentTests/getComponent.list.test.js +4 -10
  154. package/dist/utils/Component/getComponentTests/getComponent.multifile.test.js +5 -22
  155. package/dist/utils/Component/getComponentTests/getComponent.nested.test.js +156 -175
  156. package/dist/utils/Component/getComponentTests/getComponent.paragraph.test.js +4 -10
  157. package/dist/utils/Component/getComponentTests/getComponent.phoneNumber.test.js +6 -23
  158. package/dist/utils/Component/getComponentTests/getComponent.radios.test.js +8 -35
  159. package/dist/utils/Component/getComponentTests/getComponent.select.test.js +6 -23
  160. package/dist/utils/Component/getComponentTests/getComponent.text.test.js +6 -23
  161. package/dist/utils/Component/getComponentTests/getComponent.textArea.test.js +10 -34
  162. package/dist/utils/Component/getComponentTests/getComponent.time.test.js +12 -31
  163. package/dist/utils/Component/getComponentTests/getComponent.unknown.test.js +1 -2
  164. package/dist/utils/Component/getComponentTests/getComponent.warningText.test.js +3 -7
  165. package/dist/utils/Component/getDefaultValue.js +4 -8
  166. package/dist/utils/Component/getDefaultValue.test.js +0 -3
  167. package/dist/utils/Component/index.js +0 -10
  168. package/dist/utils/Component/isEditable.js +1 -4
  169. package/dist/utils/Component/isEditable.test.js +1 -5
  170. package/dist/utils/Component/optionIsSelected.js +22 -0
  171. package/dist/utils/Component/optionIsSelected.test.js +42 -0
  172. package/dist/utils/Component/setupContainerComponentsPath.js +4 -9
  173. package/dist/utils/Component/setupContainerComponentsPath.test.js +0 -3
  174. package/dist/utils/Component/showComponent.js +1 -8
  175. package/dist/utils/Component/showComponent.test.js +1 -2
  176. package/dist/utils/Component/wrapInFormGroup.js +0 -7
  177. package/dist/utils/Condition/index.js +0 -5
  178. package/dist/utils/Condition/meetsAllConditions.js +0 -9
  179. package/dist/utils/Condition/meetsAllConditions.test.js +1 -2
  180. package/dist/utils/Condition/meetsCondition.js +9 -34
  181. package/dist/utils/Condition/meetsCondition.test.js +21 -14
  182. package/dist/utils/Condition/meetsOneCondition.js +1 -9
  183. package/dist/utils/Condition/meetsOneCondition.test.js +1 -2
  184. package/dist/utils/Condition/setupConditions.js +4 -13
  185. package/dist/utils/Condition/setupConditions.test.js +0 -2
  186. package/dist/utils/Container/getEditableComponents.js +0 -7
  187. package/dist/utils/Container/getEditableComponents.test.js +1 -12
  188. package/dist/utils/Container/index.js +0 -5
  189. package/dist/utils/Container/setupNesting.js +4 -12
  190. package/dist/utils/Container/setupNesting.test.js +4 -10
  191. package/dist/utils/Container/showContainer.js +9 -18
  192. package/dist/utils/Container/showContainer.test.js +1 -2
  193. package/dist/utils/Data/applyFormula.js +6 -29
  194. package/dist/utils/Data/applyFormula.test.js +1 -2
  195. package/dist/utils/Data/getAutocompleteSource.js +1 -5
  196. package/dist/utils/Data/getAutocompleteSource.test.js +1 -2
  197. package/dist/utils/Data/getDataPath.js +3 -17
  198. package/dist/utils/Data/getDataPath.test.js +0 -4
  199. package/dist/utils/Data/getOptions.js +4 -14
  200. package/dist/utils/Data/getOptions.test.js +1 -2
  201. package/dist/utils/Data/getSourceData.js +6 -21
  202. package/dist/utils/Data/getSourceData.test.js +4 -6
  203. package/dist/utils/Data/index.js +1 -11
  204. package/dist/utils/Data/refDataToOptions.js +5 -13
  205. package/dist/utils/Data/refDataToOptions.test.js +1 -2
  206. package/dist/utils/Data/setDataItem.js +0 -5
  207. package/dist/utils/Data/setDataItem.test.js +0 -2
  208. package/dist/utils/Data/setupFormData.js +6 -25
  209. package/dist/utils/Data/setupFormData.test.js +8 -11
  210. package/dist/utils/Data/setupRefDataUrlForComponent.js +4 -15
  211. package/dist/utils/Data/setupRefDataUrlForComponent.test.js +1 -3
  212. package/dist/utils/FormPage/applyConditionalProperties.js +4 -11
  213. package/dist/utils/FormPage/applyConditionalProperties.test.js +4 -6
  214. package/dist/utils/FormPage/getFormPage.js +4 -16
  215. package/dist/utils/FormPage/getFormPage.test.js +10 -9
  216. package/dist/utils/FormPage/getFormPages.js +4 -9
  217. package/dist/utils/FormPage/getFormPages.test.js +6 -7
  218. package/dist/utils/FormPage/getPageActions.js +6 -19
  219. package/dist/utils/FormPage/getPageActions.test.js +1 -3
  220. package/dist/utils/FormPage/getParagraphFromText.js +0 -3
  221. package/dist/utils/FormPage/getParagraphFromText.test.js +1 -3
  222. package/dist/utils/FormPage/index.js +0 -7
  223. package/dist/utils/FormPage/showFormPage.js +9 -18
  224. package/dist/utils/FormPage/showFormPage.test.js +0 -2
  225. package/dist/utils/FormPage/showFormPageCYA.js +0 -5
  226. package/dist/utils/FormPage/showFormPageCYA.test.js +0 -2
  227. package/dist/utils/FormPage/useComponent.js +7 -19
  228. package/dist/utils/FormPage/useComponent.test.js +4 -7
  229. package/dist/utils/Format/formatData.js +0 -5
  230. package/dist/utils/Format/formatData.test.js +1 -2
  231. package/dist/utils/Format/formatDataForComponent.js +1 -6
  232. package/dist/utils/Format/formatDataForComponent.test.js +28 -47
  233. package/dist/utils/Format/formatDataForForm.js +4 -9
  234. package/dist/utils/Format/formatDataForForm.test.js +14 -11
  235. package/dist/utils/Format/formatDataForPage.js +1 -5
  236. package/dist/utils/Format/formatDataForPage.test.js +15 -12
  237. package/dist/utils/Format/index.js +1 -6
  238. package/dist/utils/Hub/getFormHub.js +0 -8
  239. package/dist/utils/Hub/getFormHub.test.js +6 -8
  240. package/dist/utils/Hub/index.js +1 -3
  241. package/dist/utils/Meta/documents/getDocuments.js +1 -4
  242. package/dist/utils/Meta/documents/getDocuments.test.js +4 -10
  243. package/dist/utils/Meta/documents/index.js +1 -5
  244. package/dist/utils/Meta/documents/setDocumentsForField.js +4 -11
  245. package/dist/utils/Meta/documents/setDocumentsForField.test.js +4 -16
  246. package/dist/utils/Meta/index.js +1 -4
  247. package/dist/utils/Operate/checkValueIsTruthy.js +1 -7
  248. package/dist/utils/Operate/checkValueIsTruthy.test.js +0 -2
  249. package/dist/utils/Operate/getFirstOf.js +2 -9
  250. package/dist/utils/Operate/getFirstOf.test.js +0 -2
  251. package/dist/utils/Operate/getIndexOfMatchingValueIn.js +7 -21
  252. package/dist/utils/Operate/getIndexOfMatchingValueIn.test.js +6 -2
  253. package/dist/utils/Operate/index.js +0 -3
  254. package/dist/utils/Operate/persistValueInFormData.js +1 -8
  255. package/dist/utils/Operate/persistValueInFormData.test.js +0 -4
  256. package/dist/utils/Operate/runPageOperations.js +3 -19
  257. package/dist/utils/Operate/runPageOperations.test.js +4 -6
  258. package/dist/utils/Operate/setValueInFormData.js +2 -7
  259. package/dist/utils/Operate/setValueInFormData.test.js +0 -2
  260. package/dist/utils/Operate/shouldRun.js +1 -14
  261. package/dist/utils/Operate/shouldRun.test.js +5 -8
  262. package/dist/utils/Validate/additional/conditionallyRequired.js +0 -3
  263. package/dist/utils/Validate/additional/conditionallyRequired.test.js +0 -2
  264. package/dist/utils/Validate/additional/index.js +1 -22
  265. package/dist/utils/Validate/additional/index.test.js +0 -6
  266. package/dist/utils/Validate/additional/mustBeAfter.js +3 -8
  267. package/dist/utils/Validate/additional/mustBeAfter.test.js +0 -4
  268. package/dist/utils/Validate/additional/mustBeBefore.js +3 -8
  269. package/dist/utils/Validate/additional/mustBeBefore.test.js +0 -4
  270. package/dist/utils/Validate/additional/mustBeEarlierDateTime.js +5 -16
  271. package/dist/utils/Validate/additional/mustBeEarlierDateTime.test.js +4 -8
  272. package/dist/utils/Validate/additional/mustBeGreaterThan.js +0 -3
  273. package/dist/utils/Validate/additional/mustBeGreaterThan.test.js +0 -2
  274. package/dist/utils/Validate/additional/mustBeInTheFuture.js +3 -12
  275. package/dist/utils/Validate/additional/mustBeInTheFuture.test.js +0 -3
  276. package/dist/utils/Validate/additional/mustBeInThePast.js +5 -13
  277. package/dist/utils/Validate/additional/mustBeInThePast.test.js +0 -3
  278. package/dist/utils/Validate/additional/mustBeLessThan.js +0 -3
  279. package/dist/utils/Validate/additional/mustBeLessThan.test.js +0 -2
  280. package/dist/utils/Validate/additional/mustBeLongerThan.js +0 -3
  281. package/dist/utils/Validate/additional/mustBeLongerThan.test.js +0 -2
  282. package/dist/utils/Validate/additional/mustBeNumbersOnly.js +0 -3
  283. package/dist/utils/Validate/additional/mustBeNumbersOnly.test.js +0 -2
  284. package/dist/utils/Validate/additional/mustBeShorterThan.js +0 -3
  285. package/dist/utils/Validate/additional/mustBeShorterThan.test.js +0 -2
  286. package/dist/utils/Validate/additional/mustEnterAtLeastOne.js +0 -5
  287. package/dist/utils/Validate/additional/mustEnterAtLeastOne.test.js +4 -5
  288. package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.js +0 -3
  289. package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.test.js +0 -2
  290. package/dist/utils/Validate/additional/mustSelectOnlyOne.js +0 -6
  291. package/dist/utils/Validate/additional/mustSelectOnlyOne.test.js +4 -7
  292. package/dist/utils/Validate/additional/utils.js +10 -26
  293. package/dist/utils/Validate/index.js +1 -11
  294. package/dist/utils/Validate/validateCollection.js +4 -10
  295. package/dist/utils/Validate/validateCollection.test.js +4 -6
  296. package/dist/utils/Validate/validateComponent.js +5 -40
  297. package/dist/utils/Validate/validateComponent.test.js +120 -22
  298. package/dist/utils/Validate/validateContainer.js +4 -14
  299. package/dist/utils/Validate/validateContainer.test.js +4 -10
  300. package/dist/utils/Validate/validateDate.js +6 -38
  301. package/dist/utils/Validate/validateDate.test.js +0 -4
  302. package/dist/utils/Validate/validateEmail.js +1 -8
  303. package/dist/utils/Validate/validateEmail.test.js +5 -4
  304. package/dist/utils/Validate/validateMultifile.js +0 -7
  305. package/dist/utils/Validate/validateMultifile.test.js +5 -6
  306. package/dist/utils/Validate/validatePage.js +4 -16
  307. package/dist/utils/Validate/validatePage.test.js +30 -25
  308. package/dist/utils/Validate/validateRegex.js +0 -10
  309. package/dist/utils/Validate/validateRegex.test.js +5 -4
  310. package/dist/utils/Validate/validateRequired.js +0 -8
  311. package/dist/utils/Validate/validateRequired.test.js +5 -4
  312. package/dist/utils/Validate/validateTextArea.js +0 -8
  313. package/dist/utils/Validate/validateTextArea.test.js +0 -2
  314. package/dist/utils/Validate/validateTime.js +5 -22
  315. package/dist/utils/Validate/validateTime.test.js +0 -2
  316. package/dist/utils/index.js +4 -20
  317. package/package.json +2 -2
@@ -1,200 +1,181 @@
1
1
  "use strict";
2
2
 
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
3
4
  var _react = require("@testing-library/react");
4
-
5
5
  var _getComponent = require("../getComponent");
6
-
7
6
  var _setupTests = require("../../../setupTests");
8
-
9
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
10
-
7
+ 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 exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
8
+ 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; }
9
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
10
+ 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); }
11
11
  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); } }
12
-
13
12
  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); }); }; }
14
-
15
13
  describe('utils.Component.get', function () {
16
- it('should return components that are nested within another component', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
14
+ it('should return components that are nested within another component', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
17
15
  var _formData;
18
-
19
16
  var ID, FIELD_ID, LABEL, ID2, FIELD_ID2, LABEL2, VALUE, VALUE2, PARENT_CONFIG, NESTED_CONFIG, _renderWithValidation, container, child, label, input, child2, label2, input2;
20
-
21
- return regeneratorRuntime.wrap(function _callee$(_context) {
22
- while (1) {
23
- switch (_context.prev = _context.next) {
24
- case 0:
25
- ID = 'testId';
26
- FIELD_ID = 'fieldId';
27
- LABEL = 'Test label';
28
- ID2 = 'testId2';
29
- FIELD_ID2 = 'fieldId2';
30
- LABEL2 = 'Test label 2';
31
- VALUE = 'nestedValue';
32
- VALUE2 = '1-2-2022';
33
- PARENT_CONFIG = {
34
- onChange: function onChange() {},
35
- formData: (_formData = {}, _defineProperty(_formData, FIELD_ID, VALUE), _defineProperty(_formData, FIELD_ID2, VALUE2), _formData)
36
- };
37
- NESTED_CONFIG = [{
38
- id: ID,
39
- fieldId: FIELD_ID,
40
- label: LABEL,
41
- type: 'text'
42
- }, {
43
- id: ID2,
44
- fieldId: FIELD_ID2,
45
- label: LABEL2,
46
- type: 'date'
47
- }];
48
- _renderWithValidation = (0, _setupTests.renderWithValidation)((0, _getComponent.getChildrenJsx)(PARENT_CONFIG, NESTED_CONFIG)), container = _renderWithValidation.container;
49
- child = container.childNodes[0];
50
- expect(child.childNodes[0].childNodes.length).toEqual(3);
51
- expect(child.classList).toContain('govuk-form-group');
52
- label = child.childNodes[0];
53
- expect(label).toBeDefined();
54
- expect(label.innerHTML).toContain(LABEL);
55
- input = child.childNodes[0].childNodes[2];
56
- expect(input.tagName).toEqual('INPUT');
57
- expect(input.classList).toContain('govuk-input');
58
- expect(input.id).toEqual(ID);
59
- expect(input.value).toEqual(VALUE);
60
- child2 = container.childNodes[1];
61
- expect(child2.childNodes[0].childNodes.length).toEqual(3);
62
- expect(child2.classList).toContain('govuk-form-group');
63
- label2 = child2.childNodes[0];
64
- expect(label2).toBeDefined();
65
- expect(label2.innerHTML).toContain(LABEL2);
66
- input2 = child2.childNodes[0].childNodes[2];
67
- expect(input2.tagName).toEqual('DIV');
68
- expect(input2.classList).toContain('govuk-date-input');
69
- expect(input2.id).toEqual(ID2);
70
- expect(input2.childNodes[0].childNodes[0].childNodes[1].value).toEqual('1');
71
- expect(input2.childNodes[1].childNodes[0].childNodes[1].value).toEqual('2');
72
- expect(input2.childNodes[2].childNodes[0].childNodes[1].value).toEqual('2022');
73
-
74
- case 35:
75
- case "end":
76
- return _context.stop();
77
- }
17
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
18
+ while (1) switch (_context.prev = _context.next) {
19
+ case 0:
20
+ ID = 'testId';
21
+ FIELD_ID = 'fieldId';
22
+ LABEL = 'Test label';
23
+ ID2 = 'testId2';
24
+ FIELD_ID2 = 'fieldId2';
25
+ LABEL2 = 'Test label 2';
26
+ VALUE = 'nestedValue';
27
+ VALUE2 = '1-2-2022';
28
+ PARENT_CONFIG = {
29
+ onChange: function onChange() {},
30
+ formData: (_formData = {}, _defineProperty(_formData, FIELD_ID, VALUE), _defineProperty(_formData, FIELD_ID2, VALUE2), _formData)
31
+ };
32
+ NESTED_CONFIG = [{
33
+ id: ID,
34
+ fieldId: FIELD_ID,
35
+ label: LABEL,
36
+ type: 'text'
37
+ }, {
38
+ id: ID2,
39
+ fieldId: FIELD_ID2,
40
+ label: LABEL2,
41
+ type: 'date'
42
+ }];
43
+ _renderWithValidation = (0, _setupTests.renderWithValidation)((0, _getComponent.getChildrenJsx)(PARENT_CONFIG, NESTED_CONFIG)), container = _renderWithValidation.container;
44
+ child = container.childNodes[0];
45
+ expect(child.childNodes[0].childNodes.length).toEqual(3);
46
+ expect(child.classList).toContain('govuk-form-group');
47
+ label = child.childNodes[0];
48
+ expect(label).toBeDefined();
49
+ expect(label.innerHTML).toContain(LABEL);
50
+ input = child.childNodes[0].childNodes[2];
51
+ expect(input.tagName).toEqual('INPUT');
52
+ expect(input.classList).toContain('govuk-input');
53
+ expect(input.id).toEqual(ID);
54
+ expect(input.value).toEqual(VALUE);
55
+ child2 = container.childNodes[1];
56
+ expect(child2.childNodes[0].childNodes.length).toEqual(3);
57
+ expect(child2.classList).toContain('govuk-form-group');
58
+ label2 = child2.childNodes[0];
59
+ expect(label2).toBeDefined();
60
+ expect(label2.innerHTML).toContain(LABEL2);
61
+ input2 = child2.childNodes[0].childNodes[2];
62
+ expect(input2.tagName).toEqual('DIV');
63
+ expect(input2.classList).toContain('govuk-date-input');
64
+ expect(input2.id).toEqual(ID2);
65
+ expect(input2.childNodes[0].childNodes[0].childNodes[1].value).toEqual('1');
66
+ expect(input2.childNodes[1].childNodes[0].childNodes[1].value).toEqual('2');
67
+ expect(input2.childNodes[2].childNodes[0].childNodes[1].value).toEqual('2022');
68
+ case 35:
69
+ case "end":
70
+ return _context.stop();
78
71
  }
79
72
  }, _callee);
80
73
  })));
81
- it('should return a read only component that is nested within another readonly component', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
74
+ it('should return a read only component that is nested within another readonly component', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
82
75
  var ID, FIELD_ID, LABEL, VALUE, PARENT_CONFIG, NESTED_CONFIG, _render, container, child;
83
-
84
- return regeneratorRuntime.wrap(function _callee2$(_context2) {
85
- while (1) {
86
- switch (_context2.prev = _context2.next) {
87
- case 0:
88
- ID = 'testId';
89
- FIELD_ID = 'fieldId';
90
- LABEL = 'Test label';
91
- VALUE = 'nestedValue';
92
- PARENT_CONFIG = {
93
- onChange: function onChange() {},
94
- formData: _defineProperty({}, FIELD_ID, VALUE),
95
- readonly: true
96
- };
97
- NESTED_CONFIG = [{
98
- id: ID,
99
- fieldId: FIELD_ID,
100
- label: LABEL,
101
- type: 'text',
102
- readonly: true
103
- }];
104
- _render = (0, _react.render)((0, _getComponent.getChildrenJsx)(PARENT_CONFIG, NESTED_CONFIG)), container = _render.container;
105
- child = container.childNodes[0].childNodes[0];
106
- expect(child.classList).toContain('hods-readonly');
107
-
108
- case 9:
109
- case "end":
110
- return _context2.stop();
111
- }
76
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
77
+ while (1) switch (_context2.prev = _context2.next) {
78
+ case 0:
79
+ ID = 'testId';
80
+ FIELD_ID = 'fieldId';
81
+ LABEL = 'Test label';
82
+ VALUE = 'nestedValue';
83
+ PARENT_CONFIG = {
84
+ onChange: function onChange() {},
85
+ formData: _defineProperty({}, FIELD_ID, VALUE),
86
+ readonly: true
87
+ };
88
+ NESTED_CONFIG = [{
89
+ id: ID,
90
+ fieldId: FIELD_ID,
91
+ label: LABEL,
92
+ type: 'text',
93
+ readonly: true
94
+ }];
95
+ _render = (0, _react.render)((0, _getComponent.getChildrenJsx)(PARENT_CONFIG, NESTED_CONFIG)), container = _render.container;
96
+ child = container.childNodes[0].childNodes[0];
97
+ expect(child.classList).toContain('hods-readonly');
98
+ case 9:
99
+ case "end":
100
+ return _context2.stop();
112
101
  }
113
102
  }, _callee2);
114
103
  })));
115
- it('should correctly set the value of the nested component within a container', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
104
+ it('should correctly set the value of the nested component within a container', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
116
105
  var CONTAINER_ID, ID, FIELD_ID, LABEL, VALUE, PARENT_CONFIG, NESTED_CONFIG, _renderWithValidation2, container, child, label, input;
117
-
118
- return regeneratorRuntime.wrap(function _callee3$(_context3) {
119
- while (1) {
120
- switch (_context3.prev = _context3.next) {
121
- case 0:
122
- CONTAINER_ID = 'container-id';
123
- ID = 'testId';
124
- FIELD_ID = 'fieldId';
125
- LABEL = 'Test label';
126
- VALUE = 'nestedValue';
127
- PARENT_CONFIG = {
128
- onChange: function onChange() {},
129
- formData: _defineProperty({}, CONTAINER_ID, _defineProperty({}, FIELD_ID, VALUE)),
130
- full_path: "".concat(CONTAINER_ID, ".").concat(FIELD_ID)
131
- };
132
- NESTED_CONFIG = [{
133
- id: ID,
134
- fieldId: FIELD_ID,
135
- label: LABEL,
136
- type: 'text'
137
- }];
138
- _renderWithValidation2 = (0, _setupTests.renderWithValidation)((0, _getComponent.getChildrenJsx)(PARENT_CONFIG, NESTED_CONFIG)), container = _renderWithValidation2.container;
139
- child = container.childNodes[0];
140
- expect(child.childNodes[0].childNodes.length).toEqual(3);
141
- expect(child.classList).toContain('govuk-form-group');
142
- label = child.childNodes[0];
143
- expect(label).toBeDefined();
144
- expect(label.innerHTML).toContain(LABEL);
145
- input = child.childNodes[0].childNodes[2];
146
- expect(input.tagName).toEqual('INPUT');
147
- expect(input.classList).toContain('govuk-input');
148
- expect(input.id).toEqual("".concat(CONTAINER_ID, ".").concat(FIELD_ID));
149
- expect(input.value).toEqual(VALUE);
150
-
151
- case 19:
152
- case "end":
153
- return _context3.stop();
154
- }
106
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
107
+ while (1) switch (_context3.prev = _context3.next) {
108
+ case 0:
109
+ CONTAINER_ID = 'container-id';
110
+ ID = 'testId';
111
+ FIELD_ID = 'fieldId';
112
+ LABEL = 'Test label';
113
+ VALUE = 'nestedValue';
114
+ PARENT_CONFIG = {
115
+ onChange: function onChange() {},
116
+ formData: _defineProperty({}, CONTAINER_ID, _defineProperty({}, FIELD_ID, VALUE)),
117
+ full_path: "".concat(CONTAINER_ID, ".").concat(FIELD_ID)
118
+ };
119
+ NESTED_CONFIG = [{
120
+ id: ID,
121
+ fieldId: FIELD_ID,
122
+ label: LABEL,
123
+ type: 'text'
124
+ }];
125
+ _renderWithValidation2 = (0, _setupTests.renderWithValidation)((0, _getComponent.getChildrenJsx)(PARENT_CONFIG, NESTED_CONFIG)), container = _renderWithValidation2.container;
126
+ child = container.childNodes[0];
127
+ expect(child.childNodes[0].childNodes.length).toEqual(3);
128
+ expect(child.classList).toContain('govuk-form-group');
129
+ label = child.childNodes[0];
130
+ expect(label).toBeDefined();
131
+ expect(label.innerHTML).toContain(LABEL);
132
+ input = child.childNodes[0].childNodes[2];
133
+ expect(input.tagName).toEqual('INPUT');
134
+ expect(input.classList).toContain('govuk-input');
135
+ expect(input.id).toEqual("".concat(CONTAINER_ID, ".").concat(FIELD_ID));
136
+ expect(input.value).toEqual(VALUE);
137
+ case 19:
138
+ case "end":
139
+ return _context3.stop();
155
140
  }
156
141
  }, _callee3);
157
142
  })));
158
- it('should correctly set the value of the nested component within a collection', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
143
+ it('should correctly set the value of the nested component within a collection', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
159
144
  var COLLECTION_ID, ID, FIELD_ID, LABEL, VALUE, PARENT_CONFIG, NESTED_CONFIG, _renderWithValidation3, container, child, label, input;
160
-
161
- return regeneratorRuntime.wrap(function _callee4$(_context4) {
162
- while (1) {
163
- switch (_context4.prev = _context4.next) {
164
- case 0:
165
- COLLECTION_ID = 'collection-id';
166
- ID = 'testId';
167
- FIELD_ID = 'fieldId';
168
- LABEL = 'Test label';
169
- VALUE = 'nestedValue';
170
- PARENT_CONFIG = {
171
- onChange: function onChange() {},
172
- formData: _defineProperty({}, COLLECTION_ID, [_defineProperty({}, FIELD_ID, VALUE)]),
173
- full_path: "".concat(COLLECTION_ID, "[0].").concat(FIELD_ID)
174
- };
175
- NESTED_CONFIG = [{
176
- id: ID,
177
- fieldId: FIELD_ID,
178
- label: LABEL,
179
- type: 'text'
180
- }];
181
- _renderWithValidation3 = (0, _setupTests.renderWithValidation)((0, _getComponent.getChildrenJsx)(PARENT_CONFIG, NESTED_CONFIG)), container = _renderWithValidation3.container;
182
- child = container.childNodes[0];
183
- expect(child.childNodes[0].childNodes.length).toEqual(3);
184
- expect(child.classList).toContain('govuk-form-group');
185
- label = child.childNodes[0];
186
- expect(label).toBeDefined();
187
- expect(label.innerHTML).toContain(LABEL);
188
- input = child.childNodes[0].childNodes[2];
189
- expect(input.tagName).toEqual('INPUT');
190
- expect(input.classList).toContain('govuk-input');
191
- expect(input.id).toEqual("".concat(COLLECTION_ID, "[0].").concat(FIELD_ID));
192
- expect(input.value).toEqual(VALUE);
193
-
194
- case 19:
195
- case "end":
196
- return _context4.stop();
197
- }
145
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
146
+ while (1) switch (_context4.prev = _context4.next) {
147
+ case 0:
148
+ COLLECTION_ID = 'collection-id';
149
+ ID = 'testId';
150
+ FIELD_ID = 'fieldId';
151
+ LABEL = 'Test label';
152
+ VALUE = 'nestedValue';
153
+ PARENT_CONFIG = {
154
+ onChange: function onChange() {},
155
+ formData: _defineProperty({}, COLLECTION_ID, [_defineProperty({}, FIELD_ID, VALUE)]),
156
+ full_path: "".concat(COLLECTION_ID, "[0].").concat(FIELD_ID)
157
+ };
158
+ NESTED_CONFIG = [{
159
+ id: ID,
160
+ fieldId: FIELD_ID,
161
+ label: LABEL,
162
+ type: 'text'
163
+ }];
164
+ _renderWithValidation3 = (0, _setupTests.renderWithValidation)((0, _getComponent.getChildrenJsx)(PARENT_CONFIG, NESTED_CONFIG)), container = _renderWithValidation3.container;
165
+ child = container.childNodes[0];
166
+ expect(child.childNodes[0].childNodes.length).toEqual(3);
167
+ expect(child.classList).toContain('govuk-form-group');
168
+ label = child.childNodes[0];
169
+ expect(label).toBeDefined();
170
+ expect(label.innerHTML).toContain(LABEL);
171
+ input = child.childNodes[0].childNodes[2];
172
+ expect(input.tagName).toEqual('INPUT');
173
+ expect(input.classList).toContain('govuk-input');
174
+ expect(input.id).toEqual("".concat(COLLECTION_ID, "[0].").concat(FIELD_ID));
175
+ expect(input.value).toEqual(VALUE);
176
+ case 19:
177
+ case "end":
178
+ return _context4.stop();
198
179
  }
199
180
  }, _callee4);
200
181
  })));
@@ -1,15 +1,13 @@
1
1
  "use strict";
2
2
 
3
3
  var _react = require("@testing-library/react");
4
-
5
4
  var _models = require("../../../models");
6
-
7
5
  var _getComponent = _interopRequireDefault(require("../getComponent"));
8
-
9
6
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
-
11
7
  // Global imports
8
+
12
9
  // Local imports
10
+
13
11
  describe('utils.Component.get', function () {
14
12
  it('should return a p tag and correct className for a paragraph component', function () {
15
13
  var ID = 'test-id';
@@ -19,10 +17,8 @@ describe('utils.Component.get', function () {
19
17
  content: CONTENT,
20
18
  'data-testid': ID
21
19
  };
22
-
23
20
  var _render = (0, _react.render)((0, _getComponent.default)(COMPONENT)),
24
- container = _render.container;
25
-
21
+ container = _render.container;
26
22
  var p = (0, _react.getByTestId)(container, ID);
27
23
  expect(p.innerHTML).toContain(CONTENT);
28
24
  expect(p.tagName).toEqual('P');
@@ -37,10 +33,8 @@ describe('utils.Component.get', function () {
37
33
  'data-testid': ID,
38
34
  className: 'govuk-body highlight'
39
35
  };
40
-
41
36
  var _render2 = (0, _react.render)((0, _getComponent.default)(COMPONENT)),
42
- container = _render2.container;
43
-
37
+ container = _render2.container;
44
38
  var p = (0, _react.getByTestId)(container, ID);
45
39
  expect(p.innerHTML).toContain(CONTENT);
46
40
  expect(p.tagName).toEqual('P');
@@ -1,36 +1,24 @@
1
1
  "use strict";
2
2
 
3
3
  var _react = require("@testing-library/react");
4
-
5
4
  var _models = require("../../../models");
6
-
7
5
  var _getComponent = _interopRequireDefault(require("../getComponent"));
8
-
9
6
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
-
11
7
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
12
-
13
8
  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."); }
14
-
15
9
  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); }
16
-
17
- 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; }
18
-
19
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
20
-
10
+ 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; }
11
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
21
12
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
22
-
23
13
  describe('utils.Component.get', function () {
24
14
  it('should return an appropriately rendered phone-number component', function () {
25
15
  var ID = 'test-id';
26
16
  var FIELD_ID = 'field-id';
27
17
  var LABEL = 'label';
28
18
  var ON_CHANGE_CALLS = [];
29
-
30
19
  var ON_CHANGE = function ON_CHANGE(e) {
31
20
  ON_CHANGE_CALLS.push(e.target);
32
21
  };
33
-
34
22
  var COMPONENT = {
35
23
  type: _models.ComponentTypes.PHONE_NUMBER,
36
24
  id: ID,
@@ -39,15 +27,12 @@ describe('utils.Component.get', function () {
39
27
  onChange: ON_CHANGE,
40
28
  'data-testid': ID
41
29
  };
42
-
43
30
  var _render = (0, _react.render)((0, _getComponent.default)(COMPONENT)),
44
- container = _render.container;
45
-
31
+ container = _render.container;
46
32
  var _getAllByTestId = (0, _react.getAllByTestId)(container, ID),
47
- _getAllByTestId2 = _slicedToArray(_getAllByTestId, 2),
48
- formGroup = _getAllByTestId2[0],
49
- input = _getAllByTestId2[1];
50
-
33
+ _getAllByTestId2 = _slicedToArray(_getAllByTestId, 2),
34
+ formGroup = _getAllByTestId2[0],
35
+ input = _getAllByTestId2[1];
51
36
  expect(formGroup.tagName).toEqual('DIV');
52
37
  expect(formGroup.classList).toContain('govuk-form-group');
53
38
  var label = undefined;
@@ -63,14 +48,12 @@ describe('utils.Component.get', function () {
63
48
  expect(input.tagName).toEqual('INPUT');
64
49
  expect(input.classList).toContain('govuk-input');
65
50
  expect(input.id).toEqual(ID);
66
-
67
51
  _react.fireEvent.change(input, {
68
52
  target: {
69
53
  name: FIELD_ID,
70
54
  value: '07777'
71
55
  }
72
56
  });
73
-
74
57
  expect(ON_CHANGE_CALLS.length).toEqual(1);
75
58
  expect(ON_CHANGE_CALLS[0]).toMatchObject({
76
59
  name: FIELD_ID,
@@ -1,25 +1,15 @@
1
1
  "use strict";
2
2
 
3
3
  var _react = require("@testing-library/react");
4
-
5
4
  var _models = require("../../../models");
6
-
7
5
  var _getComponent = _interopRequireDefault(require("../getComponent"));
8
-
9
6
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
-
11
7
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
12
-
13
8
  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."); }
14
-
15
9
  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); }
16
-
17
- 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; }
18
-
19
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
20
-
10
+ 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; }
11
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
21
12
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
22
-
23
13
  describe('utils.Component.get', function () {
24
14
  it('should return an appropriately rendered radios component', function () {
25
15
  var ID = 'test-id';
@@ -33,11 +23,9 @@ describe('utils.Component.get', function () {
33
23
  label: 'Bravo'
34
24
  }];
35
25
  var ON_CHANGE_CALLS = [];
36
-
37
26
  var ON_CHANGE = function ON_CHANGE(e) {
38
27
  ON_CHANGE_CALLS.push(e.target);
39
28
  };
40
-
41
29
  var COMPONENT = {
42
30
  type: _models.ComponentTypes.RADIOS,
43
31
  id: ID,
@@ -49,15 +37,12 @@ describe('utils.Component.get', function () {
49
37
  onChange: ON_CHANGE,
50
38
  'data-testid': ID
51
39
  };
52
-
53
40
  var _render = (0, _react.render)((0, _getComponent.default)(COMPONENT)),
54
- container = _render.container;
55
-
41
+ container = _render.container;
56
42
  var _getAllByTestId = (0, _react.getAllByTestId)(container, ID),
57
- _getAllByTestId2 = _slicedToArray(_getAllByTestId, 2),
58
- formGroup = _getAllByTestId2[0],
59
- radios = _getAllByTestId2[1];
60
-
43
+ _getAllByTestId2 = _slicedToArray(_getAllByTestId, 2),
44
+ formGroup = _getAllByTestId2[0],
45
+ radios = _getAllByTestId2[1];
61
46
  expect(formGroup.tagName).toEqual('DIV');
62
47
  expect(formGroup.classList).toContain('govuk-form-group');
63
48
  var label = undefined;
@@ -79,7 +64,6 @@ describe('utils.Component.get', function () {
79
64
  OPTIONS.forEach(function (_, index) {
80
65
  var radio = radios.childNodes[index];
81
66
  expect(radio instanceof Element).toBeTruthy();
82
-
83
67
  if (radio instanceof Element) {
84
68
  radioItems.push(radio);
85
69
  }
@@ -89,37 +73,26 @@ describe('utils.Component.get', function () {
89
73
  var radio = radioItems[index];
90
74
  expect(radio.tagName).toEqual('DIV');
91
75
  expect(radio.classList).toContain('govuk-radios__item');
92
-
93
76
  var _radio$childNodes = _slicedToArray(radio.childNodes, 2),
94
- input = _radio$childNodes[0],
95
- label = _radio$childNodes[1];
96
-
77
+ input = _radio$childNodes[0],
78
+ label = _radio$childNodes[1];
97
79
  expect(input.tagName).toEqual('INPUT');
98
80
  expect(input.type).toEqual('radio');
99
81
  expect(label.textContent).toEqual(option.label);
100
82
  });
101
-
102
83
  _react.fireEvent.click(radioItems[0].childNodes[0]); // alpha
103
-
104
-
105
84
  expect(ON_CHANGE_CALLS.length).toEqual(1);
106
85
  expect(ON_CHANGE_CALLS[0]).toMatchObject({
107
86
  name: FIELD_ID,
108
87
  value: OPTIONS[0].value
109
88
  });
110
-
111
89
  _react.fireEvent.click(radioItems[1].childNodes[0]); // bravo
112
-
113
-
114
90
  expect(ON_CHANGE_CALLS.length).toEqual(2);
115
91
  expect(ON_CHANGE_CALLS[1]).toMatchObject({
116
92
  name: FIELD_ID,
117
93
  value: OPTIONS[1].value
118
94
  });
119
-
120
95
  _react.fireEvent.click(radioItems[1].childNodes[0]); // bravo (already selected, above)
121
-
122
-
123
96
  expect(ON_CHANGE_CALLS.length).toEqual(2); // No change, so no new event should have fired.
124
97
  });
125
98
  });