@ukhomeoffice/cop-react-form-renderer 6.14.0 → 6.14.2-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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 +72 -63
  247. package/dist/utils/Data/getAutocompleteSource.test.js +106 -98
  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
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
3
  var _react = require("@testing-library/react");
5
4
  var _axios = _interopRequireDefault(require("axios"));
6
5
  var _axiosMockAdapter = _interopRequireDefault(require("axios-mock-adapter"));
@@ -18,28 +17,19 @@ var _userProfileData = _interopRequireDefault(require("../../json/userProfile.da
18
17
  var _userProfile = _interopRequireDefault(require("../../json/userProfile.json"));
19
18
  var _taskList = _interopRequireDefault(require("../../json/taskList.json"));
20
19
  var _firstForm = _interopRequireDefault(require("../../json/firstForm.json"));
21
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
22
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
23
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
21
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
22
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
24
23
  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; }
25
24
  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; }
26
- 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; }
27
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
28
- 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); }
29
- 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; }
30
- function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
31
- 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); } }
32
- 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); }); }; }
33
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
34
- 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."); }
35
- 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); }
36
- 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; }
37
- 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; } }
38
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } // Global imports
25
+ 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; }
26
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
27
+ 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); }
28
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } // Global imports
39
29
  // Local imports
40
30
  // JSON
41
- var setDate = function setDate(element, date) {
42
- var items = element.children;
31
+ const setDate = (element, date) => {
32
+ const items = element.children;
43
33
  _react.fireEvent.change(items[0].childNodes[0].childNodes[1], {
44
34
  target: {
45
35
  name: 'date-day',
@@ -59,19 +49,15 @@ var setDate = function setDate(element, date) {
59
49
  }
60
50
  });
61
51
  };
62
- var sleep = function sleep(ms) {
63
- return new Promise(function (resolve) {
64
- setTimeout(resolve, ms);
65
- });
66
- };
67
- describe('components', function () {
68
- describe('FormRenderer', function () {
69
- var mockAxios = new _axiosMockAdapter.default(_axios.default);
70
- var container = null;
71
- var refDataUrl = function refDataUrl(suffix) {
72
- return "".concat(_userProfileData.default.urls.refData, "/").concat(suffix);
73
- };
74
- beforeEach(function () {
52
+ const sleep = ms => new Promise(resolve => {
53
+ setTimeout(resolve, ms);
54
+ });
55
+ describe('components', () => {
56
+ describe('FormRenderer', () => {
57
+ const mockAxios = new _axiosMockAdapter.default(_axios.default);
58
+ let container = null;
59
+ const refDataUrl = suffix => "".concat(_userProfileData.default.urls.refData, "/").concat(suffix);
60
+ beforeEach(() => {
75
61
  container = document.createElement('div');
76
62
  document.body.appendChild(container);
77
63
  mockAxios.reset();
@@ -79,1103 +65,735 @@ describe('components', function () {
79
65
  mockAxios.onGet(refDataUrl('grade')).reply(200, _grade.default);
80
66
  mockAxios.onGet(refDataUrl('team')).reply(200, _team.default);
81
67
  });
82
- afterEach(function () {
68
+ afterEach(() => {
83
69
  (0, _reactDom.unmountComponentAtNode)(container);
84
70
  container.remove();
85
71
  container = null;
86
72
  });
87
- var checkForm = function checkForm(formContainer) {
88
- var formWrapper = formContainer;
89
- var form = formWrapper.childNodes[0];
73
+ const checkForm = formContainer => {
74
+ const formWrapper = formContainer;
75
+ const form = formWrapper.childNodes[0];
90
76
  expect(form.tagName).toEqual('DIV');
91
77
  expect(form.classList).toContain(_FormRenderer.DEFAULT_CLASS);
92
78
  return form;
93
79
  };
94
- var getChangeLink = function getChangeLink(summaryList) {
95
- var _summaryList$childNod = _slicedToArray(summaryList.childNodes[0].childNodes[0].childNodes, 3),
96
- actions = _summaryList$childNod[2];
80
+ const getChangeLink = summaryList => {
81
+ const [,, actions] = summaryList.childNodes[0].childNodes[0].childNodes;
97
82
  return actions.childNodes[0];
98
83
  };
99
- var getContinueButton = function getContinueButton(page) {
100
- return page.childNodes[page.childNodes.length - 1].childNodes[0].childNodes[0];
101
- };
102
- var getCancelButton = function getCancelButton(page) {
103
- return page.childNodes[page.childNodes.length - 1].childNodes[1].childNodes[0];
104
- };
105
- it('should start on the hub page correctly and display the title', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
106
- var form, title, hub;
107
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
108
- while (1) switch (_context2.prev = _context2.next) {
109
- case 0:
110
- _context2.next = 2;
111
- return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
112
- return _regeneratorRuntime().wrap(function _callee$(_context) {
113
- while (1) switch (_context.prev = _context.next) {
114
- case 0:
115
- (0, _reactDom.render)( /*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, _userProfile.default, {
116
- data: _userProfileData.default
117
- })), container);
118
- case 1:
119
- case "end":
120
- return _context.stop();
121
- }
122
- }, _callee);
123
- })));
124
- case 2:
125
- form = checkForm(container);
126
- expect(form.childNodes.length).toEqual(2); // Title + Hub page (= CYA)
127
- title = form.childNodes[0];
128
- expect(title.tagName).toEqual('H1');
129
- expect(title.textContent).toEqual(_userProfile.default.title);
130
- hub = form.childNodes[1];
131
- expect(hub.tagName).toEqual('DIV');
132
- expect(hub.classList).toContain(_CheckYourAnswers.DEFAULT_CLASS);
133
- case 10:
134
- case "end":
135
- return _context2.stop();
136
- }
137
- }, _callee2);
138
- })));
139
- it('should fire the onFormLoad method passed in the hooks', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
140
- var onFormLoadCalled, ON_FORM_LOAD, HOOKS;
141
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
142
- while (1) switch (_context4.prev = _context4.next) {
143
- case 0:
144
- onFormLoadCalled = false;
145
- ON_FORM_LOAD = function ON_FORM_LOAD() {
146
- onFormLoadCalled = true;
147
- };
148
- HOOKS = {
149
- onFormLoad: ON_FORM_LOAD
150
- };
151
- _context4.next = 5;
152
- return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
153
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
154
- while (1) switch (_context3.prev = _context3.next) {
155
- case 0:
156
- (0, _reactDom.render)( /*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, _userProfile.default, {
157
- data: _userProfileData.default,
158
- hooks: HOOKS
159
- })), container);
160
- case 1:
161
- case "end":
162
- return _context3.stop();
163
- }
164
- }, _callee3);
165
- })));
166
- case 5:
167
- expect(onFormLoadCalled).toBeTruthy();
168
- case 6:
169
- case "end":
170
- return _context4.stop();
171
- }
172
- }, _callee4);
173
- })));
174
- it('should navigate to the first editable page', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
175
- var ON_PAGE_CHANGE_CALLS, ON_PAGE_CHANGE, HOOKS, form, hub, _hub$childNodes, civilServantList, link, page, pageHeading;
176
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
177
- while (1) switch (_context6.prev = _context6.next) {
178
- case 0:
179
- ON_PAGE_CHANGE_CALLS = [];
180
- ON_PAGE_CHANGE = function ON_PAGE_CHANGE(pageId) {
181
- ON_PAGE_CHANGE_CALLS.push(pageId);
182
- };
183
- HOOKS = {
184
- onPageChange: ON_PAGE_CHANGE
185
- };
186
- _context6.next = 5;
187
- return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
188
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
189
- while (1) switch (_context5.prev = _context5.next) {
190
- case 0:
191
- (0, _reactDom.render)( /*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, _userProfile.default, {
192
- data: _userProfileData.default,
193
- hooks: HOOKS
194
- })), container);
195
- case 1:
196
- case "end":
197
- return _context5.stop();
198
- }
199
- }, _callee5);
200
- })));
201
- case 5:
202
- form = checkForm(container);
203
- hub = form.childNodes[1]; // Hub = CYA
204
- _hub$childNodes = _slicedToArray(hub.childNodes, 3), civilServantList = _hub$childNodes[2];
205
- link = getChangeLink(civilServantList);
206
- expect(ON_PAGE_CHANGE_CALLS.length).toEqual(0);
207
- _react.fireEvent.click(link, {});
208
- expect(ON_PAGE_CHANGE_CALLS.length).toEqual(1);
209
- expect(ON_PAGE_CHANGE_CALLS[0]).toEqual(_userProfile.default.pages[1].id);
210
-
211
- // The form layout should have changed to the current page.
212
- expect(form.childNodes.length).toEqual(1); // Just the page.
213
- page = form.childNodes[0];
214
- pageHeading = page.childNodes[0];
215
- expect(pageHeading.tagName).toEqual('H1');
216
- expect(pageHeading.textContent).toEqual(_userProfile.default.pages[1].title);
217
- case 18:
218
- case "end":
219
- return _context6.stop();
220
- }
221
- }, _callee6);
222
- })));
223
- it('should handle a page submission', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
224
- var ON_SUBMIT_CALLS, ON_SUBMIT, HOOKS, form, hub, _hub$childNodes2, civilServantList, link, page, continueButton, title;
225
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
226
- while (1) switch (_context8.prev = _context8.next) {
227
- case 0:
228
- ON_SUBMIT_CALLS = [];
229
- ON_SUBMIT = function ON_SUBMIT(type, payload, onSuccess, onError, fieldName, fieldValue) {
230
- ON_SUBMIT_CALLS.push({
231
- type: type,
232
- payload: payload,
233
- onSuccess: onSuccess,
234
- onError: onError,
235
- fieldName: fieldName,
236
- fieldValue: fieldValue
237
- });
238
- onSuccess();
239
- };
240
- HOOKS = {
241
- onSubmit: ON_SUBMIT
242
- };
243
- _context8.next = 5;
244
- return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
245
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
246
- while (1) switch (_context7.prev = _context7.next) {
247
- case 0:
248
- (0, _reactDom.render)( /*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, _userProfile.default, {
249
- data: _userProfileData.default,
250
- hooks: HOOKS,
251
- type: _models.FormTypes.HUB
252
- })), container);
253
- case 1:
254
- case "end":
255
- return _context7.stop();
256
- }
257
- }, _callee7);
258
- })));
259
- case 5:
260
- form = checkForm(container); // Navigate to the "Are you a civil servant?" page.
261
- hub = form.childNodes[1]; // Hub = CYA
262
- _hub$childNodes2 = _slicedToArray(hub.childNodes, 3), civilServantList = _hub$childNodes2[2];
263
- link = getChangeLink(civilServantList);
264
- _react.fireEvent.click(link, {});
265
-
266
- // Should already be answered "Yes", but select "No, I'm a contractor" option to generate patch
267
- // and then click "Continue".
268
- _react.fireEvent.click(_react.screen.getByText("No, I'm a contractor"));
269
- page = form.childNodes[0];
270
- continueButton = getContinueButton(page);
271
- expect(ON_SUBMIT_CALLS.length).toEqual(0);
272
- _react.fireEvent.click(continueButton, {});
273
- expect(ON_SUBMIT_CALLS.length).toEqual(1);
274
- expect(ON_SUBMIT_CALLS[0].type).toEqual(_models.PageAction.TYPES.SUBMIT);
275
- expect(ON_SUBMIT_CALLS[0].payload.areYouACivilServant).toEqual('no-contractor');
276
- expect(ON_SUBMIT_CALLS[0].fieldName).toEqual('Are you a civil servant?');
277
- expect(ON_SUBMIT_CALLS[0].fieldValue).toEqual("No, I'm a contractor");
278
-
279
- // And we should be back on the hub.
280
- expect(form.childNodes.length).toEqual(2); // Title + Hub page (= CYA)
281
- title = form.childNodes[0];
282
- expect(title.tagName).toEqual('H1');
283
- expect(title.textContent).toEqual(_userProfile.default.title);
284
- case 24:
285
- case "end":
286
- return _context8.stop();
287
- }
288
- }, _callee8);
289
- })));
290
- it('should handle a page submission error', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
291
- var ON_SUBMIT_CALLS, ON_SUBMIT, HOOKS, form, hub, _hub$childNodes3, civilServantList, link, page, continueButton, pageHeading;
292
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
293
- while (1) switch (_context10.prev = _context10.next) {
294
- case 0:
295
- ON_SUBMIT_CALLS = [];
296
- ON_SUBMIT = function ON_SUBMIT(type, payload, onSuccess, onError) {
297
- ON_SUBMIT_CALLS.push({
298
- type: type,
299
- payload: payload,
300
- onSuccess: onSuccess,
301
- onError: onError
302
- });
303
- onError([{
304
- id: 'unknown',
305
- error: 'Something went wrong'
306
- }]);
307
- };
308
- HOOKS = {
309
- onSubmit: ON_SUBMIT,
310
- onAction: function onAction(formData, patch) {
311
- return {
312
- formData: formData,
313
- patch: patch
314
- };
315
- }
316
- };
317
- _context10.next = 5;
318
- return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
319
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
320
- while (1) switch (_context9.prev = _context9.next) {
321
- case 0:
322
- (0, _reactDom.render)( /*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, _userProfile.default, {
323
- data: _userProfileData.default,
324
- hooks: HOOKS
325
- })), container);
326
- case 1:
327
- case "end":
328
- return _context9.stop();
329
- }
330
- }, _callee9);
331
- })));
332
- case 5:
333
- form = checkForm(container); // Navigate to the "Are you a civil servant?" page.
334
- hub = form.childNodes[1]; // Hub = CYA
335
- _hub$childNodes3 = _slicedToArray(hub.childNodes, 3), civilServantList = _hub$childNodes3[2];
336
- link = getChangeLink(civilServantList);
337
- _react.fireEvent.click(link, {});
338
-
339
- // Should already be answered "Yes", so simply click "Continue".
340
- page = form.childNodes[0];
341
- continueButton = getContinueButton(page);
342
- expect(ON_SUBMIT_CALLS.length).toEqual(0);
343
- _react.fireEvent.click(continueButton, {});
344
- expect(ON_SUBMIT_CALLS.length).toEqual(1);
345
- expect(ON_SUBMIT_CALLS[0].type).toEqual(_models.PageAction.TYPES.SUBMIT);
346
- expect(ON_SUBMIT_CALLS[0].payload.areYouACivilServant).toEqual('yes');
347
-
348
- // And we should be kept on the same page.
349
- expect(form.childNodes.length).toEqual(1); // Just the page.
350
- pageHeading = form.childNodes[0].childNodes[1];
351
- expect(pageHeading.tagName).toEqual('H1');
352
- expect(pageHeading.textContent).toEqual(_userProfile.default.pages[1].title);
353
- case 21:
354
- case "end":
355
- return _context10.stop();
356
- }
357
- }, _callee10);
358
- })));
359
- it('should handle a page submission once regardless of how many times page action is clicked', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
360
- var ON_PAGE_CHANGE_CALLS, ON_PAGE_CHANGE, ON_SUBMIT_CALLS, ON_SUBMIT, HOOKS, _container$childNodes, continueButtonGroup, continueFormButton, innerDiv, firstNameInput, EVENT, submitButton;
361
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
362
- while (1) switch (_context12.prev = _context12.next) {
363
- case 0:
364
- ON_PAGE_CHANGE_CALLS = [];
365
- ON_PAGE_CHANGE = function ON_PAGE_CHANGE(pageId) {
366
- ON_PAGE_CHANGE_CALLS.push(pageId);
367
- };
368
- ON_SUBMIT_CALLS = [];
369
- ON_SUBMIT = /*#__PURE__*/function () {
370
- var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(type, payload, onSuccess, onError, fieldName, fieldValue) {
371
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
372
- while (1) switch (_context11.prev = _context11.next) {
373
- case 0:
374
- ON_SUBMIT_CALLS.push({
375
- type: type,
376
- payload: payload,
377
- onSuccess: onSuccess,
378
- onError: onError,
379
- fieldName: fieldName,
380
- fieldValue: fieldValue
381
- });
382
-
383
- // mock a delay when submitting to the backend
384
- _context11.next = 3;
385
- return sleep(2000);
386
- case 3:
387
- onSuccess();
388
- case 4:
389
- case "end":
390
- return _context11.stop();
391
- }
392
- }, _callee11);
393
- }));
394
- return function ON_SUBMIT(_x, _x2, _x3, _x4, _x5, _x6) {
395
- return _ref12.apply(this, arguments);
396
- };
397
- }();
398
- HOOKS = {
399
- onSubmit: ON_SUBMIT,
400
- onPageChange: ON_PAGE_CHANGE
401
- };
402
- (0, _testUtils.act)(function () {
403
- (0, _reactDom.render)( /*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, _firstForm.default, {
404
- hooks: HOOKS,
405
- type: _models.FormTypes.CYA
406
- })), container);
407
- });
408
- _container$childNodes = _slicedToArray(container.childNodes[0].childNodes[0].childNodes, 6), continueButtonGroup = _container$childNodes[5]; // go to first question page
409
- continueFormButton = continueButtonGroup.childNodes[0];
410
- _react.fireEvent.click(continueFormButton);
411
- innerDiv = container.childNodes[0].childNodes[0]; // enter a value in the input field
412
- firstNameInput = innerDiv.childNodes[1].childNodes[2];
413
- EVENT = {
414
- target: {
415
- name: firstNameInput.id,
416
- value: 'abc'
417
- }
418
- };
419
- _react.fireEvent.change(firstNameInput, EVENT);
420
- submitButton = innerDiv.childNodes[2].childNodes[0]; // click on save and continue
421
- _react.fireEvent.click(submitButton);
422
-
423
- // click on save and continue again
424
- _react.fireEvent.click(submitButton);
425
-
426
- // click on save and continue a third time
427
- _react.fireEvent.click(submitButton);
428
-
429
- // only expect one submit call to be made
430
- expect(ON_SUBMIT_CALLS.length).toEqual(1);
431
- expect(ON_PAGE_CHANGE_CALLS.length).toEqual(1);
432
- expect(ON_SUBMIT_CALLS[0].type).toEqual(_models.PageAction.TYPES.SAVE_AND_CONTINUE);
433
- case 20:
434
- case "end":
435
- return _context12.stop();
436
- }
437
- }, _callee12);
438
- })));
439
- it('should handle a page submission repeatedly if ignoreSubmittingFlag is true', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
440
- var ON_PAGE_CHANGE_CALLS, ON_PAGE_CHANGE, ON_SUBMIT_CALLS, ON_SUBMIT, HOOKS, formDefinition, form, hub, _hub$childNodes4, civilServantList, link, page, continueButton;
441
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
442
- while (1) switch (_context14.prev = _context14.next) {
443
- case 0:
444
- ON_PAGE_CHANGE_CALLS = [];
445
- ON_PAGE_CHANGE = function ON_PAGE_CHANGE(pageId) {
446
- ON_PAGE_CHANGE_CALLS.push(pageId);
447
- };
448
- ON_SUBMIT_CALLS = [];
449
- ON_SUBMIT = /*#__PURE__*/function () {
450
- var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(type, payload, onSuccess, onError, fieldName, fieldValue) {
451
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
452
- while (1) switch (_context13.prev = _context13.next) {
453
- case 0:
454
- ON_SUBMIT_CALLS.push({
455
- type: type,
456
- payload: payload,
457
- onSuccess: onSuccess,
458
- onError: onError,
459
- fieldName: fieldName,
460
- fieldValue: fieldValue
461
- });
462
-
463
- // mock a delay when submitting to the backend
464
- _context13.next = 3;
465
- return sleep(2000);
466
- case 3:
467
- onSuccess();
468
- case 4:
469
- case "end":
470
- return _context13.stop();
471
- }
472
- }, _callee13);
473
- }));
474
- return function ON_SUBMIT(_x7, _x8, _x9, _x10, _x11, _x12) {
475
- return _ref14.apply(this, arguments);
476
- };
477
- }();
478
- HOOKS = {
479
- onSubmit: ON_SUBMIT,
480
- onPageChange: ON_PAGE_CHANGE
481
- };
482
- formDefinition = _objectSpread({}, _userProfile.default);
483
- formDefinition.pages[1].actions = [{
484
- type: 'saveAndContinue',
485
- page: 'test',
486
- ignoreSubmittingFlag: true
487
- }, {
488
- type: 'cancel'
489
- }];
490
- (0, _testUtils.act)(function () {
491
- (0, _reactDom.render)( /*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, formDefinition, {
492
- data: _userProfileData.default,
493
- hooks: HOOKS
494
- })), container);
495
- });
496
- form = checkForm(container); // Navigate to the "Are you a civil servant?" page.
497
- hub = form.childNodes[1]; // Hub = CYA
498
- _hub$childNodes4 = _slicedToArray(hub.childNodes, 3), civilServantList = _hub$childNodes4[2];
499
- link = getChangeLink(civilServantList);
500
- _react.fireEvent.click(link, {});
501
-
502
- // Should already be answered "Yes", so simply click "Continue".
503
- page = form.childNodes[0];
504
- continueButton = getContinueButton(page);
505
- expect(ON_SUBMIT_CALLS.length).toEqual(0);
506
- _react.fireEvent.click(continueButton, {});
507
- expect(ON_SUBMIT_CALLS.length).toEqual(1);
508
- expect(ON_SUBMIT_CALLS[0].type).toEqual(_models.PageAction.TYPES.SAVE_AND_CONTINUE);
509
-
510
- // click on save and continue
511
- _react.fireEvent.click(continueButton);
512
-
513
- // click on save and continue again
514
- _react.fireEvent.click(continueButton);
515
-
516
- // click on save and continue a third time
517
- _react.fireEvent.click(continueButton);
518
-
519
- // expect all submit calls to be made
520
- expect(ON_SUBMIT_CALLS.length).toEqual(4);
521
- case 23:
522
- case "end":
523
- return _context14.stop();
524
- }
525
- }, _callee14);
526
- })));
527
- it('should handle page navigation', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
528
- var ON_PAGE_CHANGE_CALLS, ON_PAGE_CHANGE, HOOKS, form, hub, _hub$childNodes5, lineManagerList, link, page, pageHeading, continueButton, newPageHeading;
529
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
530
- while (1) switch (_context16.prev = _context16.next) {
531
- case 0:
532
- ON_PAGE_CHANGE_CALLS = [];
533
- ON_PAGE_CHANGE = function ON_PAGE_CHANGE(pageId) {
534
- ON_PAGE_CHANGE_CALLS.push(pageId);
535
- };
536
- HOOKS = {
537
- onPageChange: ON_PAGE_CHANGE
538
- };
539
- _context16.next = 5;
540
- return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
541
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
542
- while (1) switch (_context15.prev = _context15.next) {
543
- case 0:
544
- (0, _reactDom.render)( /*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, _userProfile.default, {
545
- data: _userProfileData.default,
546
- hooks: HOOKS
547
- })), container);
548
- case 1:
549
- case "end":
550
- return _context15.stop();
551
- }
552
- }, _callee15);
553
- })));
554
- case 5:
555
- form = checkForm(container); // Navigate to the "Add or change a line manager" page.
556
- hub = form.childNodes[1]; // Hub = CYA
557
- _hub$childNodes5 = _slicedToArray(hub.childNodes, 6), lineManagerList = _hub$childNodes5[5];
558
- link = getChangeLink(lineManagerList);
559
- expect(ON_PAGE_CHANGE_CALLS.length).toEqual(0);
560
- _react.fireEvent.click(link, {});
561
- expect(ON_PAGE_CHANGE_CALLS[0]).toEqual(_userProfile.default.pages[4].id);
562
-
563
- // Should be on the page explaining what changing the line manager means.
564
- page = form.childNodes[0];
565
- pageHeading = page.childNodes[0];
566
- expect(pageHeading.tagName).toEqual('H1');
567
- expect(pageHeading.textContent).toEqual(_userProfile.default.pages[4].title);
568
-
569
- // Now click on the "Continue" button on here.
570
- continueButton = getContinueButton(page);
571
- expect(ON_PAGE_CHANGE_CALLS.length).toEqual(1);
572
- _react.fireEvent.click(continueButton, {});
573
- expect(ON_PAGE_CHANGE_CALLS.length).toEqual(2);
574
- expect(ON_PAGE_CHANGE_CALLS[1]).toEqual(_userProfile.default.pages[5].id);
575
- newPageHeading = form.childNodes[0].childNodes[0];
576
- expect(newPageHeading.tagName).toEqual('H1');
577
- expect(newPageHeading.textContent).toEqual(_userProfile.default.pages[5].title);
578
- case 24:
579
- case "end":
580
- return _context16.stop();
581
- }
582
- }, _callee16);
583
- })));
584
- it('should show no title when hide_title is set to true', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
585
- var form, hub;
586
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
587
- while (1) switch (_context18.prev = _context18.next) {
588
- case 0:
589
- _context18.next = 2;
590
- return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
591
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
592
- while (1) switch (_context17.prev = _context17.next) {
593
- case 0:
594
- (0, _reactDom.render)( /*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, _userProfile.default, {
595
- data: _userProfileData.default,
596
- hide_title: true
597
- })), container);
598
- case 1:
599
- case "end":
600
- return _context17.stop();
601
- }
602
- }, _callee17);
603
- })));
604
- case 2:
605
- form = checkForm(container);
606
- expect(form.childNodes.length).toEqual(1); // Hub page (= CYA)
607
- hub = form.childNodes[0];
608
- expect(hub.tagName).toEqual('DIV');
609
- expect(hub.classList).toContain(_CheckYourAnswers.DEFAULT_CLASS);
610
- case 7:
611
- case "end":
612
- return _context18.stop();
613
- }
614
- }, _callee18);
615
- })));
616
- it('should render a task list', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
617
- var taskList;
618
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
619
- while (1) switch (_context20.prev = _context20.next) {
620
- case 0:
621
- _context20.next = 2;
622
- return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
623
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
624
- while (1) switch (_context19.prev = _context19.next) {
625
- case 0:
626
- (0, _reactDom.render)( /*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _taskList.default), container);
627
- case 1:
628
- case "end":
629
- return _context19.stop();
630
- }
631
- }, _callee19);
632
- })));
633
- case 2:
634
- taskList = container.childNodes[0].childNodes[1];
635
- expect(taskList.classList).toContain(_TaskList.DEFAULT_CLASS);
636
- case 4:
637
- case "end":
638
- return _context20.stop();
639
- }
640
- }, _callee20);
641
- })));
642
- it('should render a cya page', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
643
- var cya;
644
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
645
- while (1) switch (_context22.prev = _context22.next) {
646
- case 0:
647
- _context22.next = 2;
648
- return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
649
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
650
- while (1) switch (_context21.prev = _context21.next) {
651
- case 0:
652
- (0, _reactDom.render)( /*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _firstForm.default), container);
653
- case 1:
654
- case "end":
655
- return _context21.stop();
656
- }
657
- }, _callee21);
658
- })));
659
- case 2:
660
- cya = container.childNodes[0];
661
- expect(cya.classList).toContain('hods-form');
662
- case 4:
663
- case "end":
664
- return _context22.stop();
665
- }
666
- }, _callee22);
667
- })));
668
- it('should load task list with notes', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
669
- var ON_SUBMIT_CALLS, ON_SUBMIT, HOOKS, TASK_LIST_WITH_NOTES, taskList;
670
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
671
- while (1) switch (_context24.prev = _context24.next) {
672
- case 0:
673
- ON_SUBMIT_CALLS = [];
674
- ON_SUBMIT = function ON_SUBMIT(type, payload, onSuccess) {
675
- ON_SUBMIT_CALLS.push(payload);
676
- onSuccess();
677
- };
678
- HOOKS = {
679
- onSubmit: ON_SUBMIT
680
- };
681
- TASK_LIST_WITH_NOTES = JSON.parse(JSON.stringify(_taskList.default));
682
- TASK_LIST_WITH_NOTES.hub.notes = {
683
- title: "test title",
684
- text: "test text",
685
- show_when: [{
686
- "op": "=",
687
- "field": "areYouACivilServant",
688
- "value": "yes"
689
- }]
690
- };
691
- _context24.next = 7;
692
- return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
693
- return _regeneratorRuntime().wrap(function _callee23$(_context23) {
694
- while (1) switch (_context23.prev = _context23.next) {
695
- case 0:
696
- (0, _reactDom.render)( /*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, TASK_LIST_WITH_NOTES, {
697
- data: _userProfileData.default,
698
- hooks: HOOKS
699
- })), container);
700
- case 1:
701
- case "end":
702
- return _context23.stop();
703
- }
704
- }, _callee23);
705
- })));
706
- case 7:
707
- taskList = container.childNodes[0].childNodes[1];
708
- expect(taskList.childNodes[5].textContent).toEqual("test text");
709
- expect(taskList.childNodes[5].classList).toContain('govuk-textarea');
710
- case 10:
711
- case "end":
712
- return _context24.stop();
713
- }
714
- }, _callee24);
715
- })));
716
- it('should not load task list with notes', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
717
- var ON_SUBMIT_CALLS, ON_SUBMIT, HOOKS, TASK_LIST_WITH_NOTES, taskList;
718
- return _regeneratorRuntime().wrap(function _callee26$(_context26) {
719
- while (1) switch (_context26.prev = _context26.next) {
720
- case 0:
721
- ON_SUBMIT_CALLS = [];
722
- ON_SUBMIT = function ON_SUBMIT(type, payload, onSuccess) {
723
- ON_SUBMIT_CALLS.push(payload);
724
- onSuccess();
725
- };
726
- HOOKS = {
727
- onSubmit: ON_SUBMIT
728
- };
729
- TASK_LIST_WITH_NOTES = JSON.parse(JSON.stringify(_taskList.default));
730
- TASK_LIST_WITH_NOTES.hub.notes = {
731
- title: "test title",
732
- text: "test text",
733
- show_when: [{
734
- "op": "!=",
735
- "field": "changeSummary",
736
- "value": undefined
737
- }]
738
- };
739
- _context26.next = 7;
740
- return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
741
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
742
- while (1) switch (_context25.prev = _context25.next) {
743
- case 0:
744
- (0, _reactDom.render)( /*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, TASK_LIST_WITH_NOTES, {
745
- data: _userProfileData.default,
746
- hooks: HOOKS
747
- })), container);
748
- case 1:
749
- case "end":
750
- return _context25.stop();
751
- }
752
- }, _callee25);
753
- })));
754
- case 7:
755
- taskList = container.childNodes[0].childNodes[1];
756
- taskList.childNodes.forEach(function (child) {
757
- // eslint-disable-next-line no-console
758
- console.log("taskList, child = ".concat(JSON.stringify(child.textContent)));
759
- });
760
- expect(taskList.childNodes[5].textContent).not.toEqual("test text");
761
- expect(taskList.childNodes[5].classList).not.toContain('govuk-textarea');
762
- case 11:
763
- case "end":
764
- return _context26.stop();
765
- }
766
- }, _callee26);
767
- })));
768
- it('should handle navigating between task list pages', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
769
- var ON_SUBMIT_CALLS, ON_SUBMIT, HOOKS, taskList, firstTaskStatus, secondTaskStatus, firstTask, newPage, fieldset, continueButton, seaButton, cyaPageChange, modeChangeLink, changePage, airButton, cyaPage, finalSubmit;
770
- return _regeneratorRuntime().wrap(function _callee28$(_context28) {
771
- while (1) switch (_context28.prev = _context28.next) {
772
- case 0:
773
- ON_SUBMIT_CALLS = [];
774
- ON_SUBMIT = function ON_SUBMIT(type, payload, onSuccess) {
775
- ON_SUBMIT_CALLS.push(payload);
776
- onSuccess();
777
- };
778
- HOOKS = {
779
- onSubmit: ON_SUBMIT
780
- };
781
- _context28.next = 5;
782
- return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
783
- return _regeneratorRuntime().wrap(function _callee27$(_context27) {
784
- while (1) switch (_context27.prev = _context27.next) {
785
- case 0:
786
- (0, _reactDom.render)( /*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, _taskList.default, {
787
- hooks: HOOKS
788
- })), container);
789
- case 1:
790
- case "end":
791
- return _context27.stop();
792
- }
793
- }, _callee27);
794
- })));
795
- case 5:
796
- taskList = container.childNodes[0].childNodes[1]; // Check statuses are correct
797
- firstTaskStatus = taskList.childNodes[3].childNodes[0].childNodes[1];
798
- expect(firstTaskStatus.textContent).toEqual(_models.TaskStates.DETAILS[_models.TaskStates.TYPES.NOT_STARTED].label);
799
- secondTaskStatus = taskList.childNodes[3].childNodes[1].childNodes[1];
800
- expect(secondTaskStatus.textContent).toEqual(_models.TaskStates.DETAILS[_models.TaskStates.TYPES.CANNOT_START_YET].label);
801
-
802
- // Launch first task
803
- firstTask = taskList.childNodes[3].childNodes[0].childNodes[0].childNodes[0];
804
- expect(firstTask.textContent).toEqual('Date, location and mode details');
805
- _react.fireEvent.click(firstTask, {});
806
-
807
- // Fill first page and navigate
808
- newPage = container.childNodes[0].childNodes[0];
809
- expect(newPage.childNodes[0].textContent).toEqual('Event Date');
810
- fieldset = newPage.childNodes[1].childNodes[0]; // child nodes of fieldset are legend and date
811
- setDate(fieldset.children[1], ['7', '7', '2022']);
812
- continueButton = newPage.childNodes[2].childNodes[0];
813
- _react.fireEvent.click(continueButton, {});
814
-
815
- // Fill second page and navigate
816
- newPage = container.childNodes[0].childNodes[0];
817
- expect(newPage.childNodes[0].textContent).toEqual('Event Mode');
818
- seaButton = newPage.childNodes[1].childNodes[0].childNodes[2].childNodes[0];
819
- expect(seaButton.textContent).toEqual('Sea');
820
- _react.fireEvent.click(seaButton.childNodes[0], {});
821
- continueButton = newPage.childNodes[2].childNodes[0];
822
- _react.fireEvent.click(continueButton, {});
823
-
824
- // Click change to mode on CYA page
825
- cyaPageChange = container.childNodes[0].childNodes[0];
826
- expect(cyaPageChange.childNodes[0].textContent).toEqual('Check your answers');
827
- modeChangeLink = cyaPageChange.childNodes[4].childNodes[0].childNodes[0].childNodes[2].childNodes[0];
828
- expect(modeChangeLink.textContent).toEqual('Change Event Mode');
829
- _react.fireEvent.click(modeChangeLink, {});
830
- changePage = container.childNodes[0].childNodes[0];
831
- expect(changePage.childNodes[0].textContent).toEqual('Event Mode');
832
- // Click on radio for 'Air'
833
- airButton = changePage.childNodes[1].childNodes[0].childNodes[2].childNodes[1];
834
- expect(airButton.textContent).toEqual('Air');
835
- _react.fireEvent.click(airButton.childNodes[0]);
836
- // Continue again to CYA page
837
- expect(changePage.childNodes[2].childNodes[0].textContent).toEqual('Save and continue');
838
- continueButton = changePage.childNodes[2].childNodes[0];
839
- _react.fireEvent.click(continueButton, {});
840
-
841
- // Continue on from CYA page
842
- cyaPage = container.childNodes[0].childNodes[0];
843
- expect(cyaPage.childNodes[0].textContent).toEqual('Check your answers');
844
- expect(cyaPage.childNodes[5].childNodes[0].textContent).toEqual('Save and continue');
845
- expect(cyaPage.childNodes[5].childNodes[1].textContent).toEqual('Save and return later');
846
- _react.fireEvent.click(cyaPage.childNodes[5].childNodes[0], {});
847
-
848
- // Should be back at task list
849
- expect(container.childNodes[0].childNodes[0].textContent).toEqual('Task List Form');
850
-
851
- // Check statuses are correct
852
- firstTaskStatus = container.childNodes[0].childNodes[1].childNodes[3].childNodes[0].childNodes[1];
853
- expect(firstTaskStatus.textContent).toEqual(_models.TaskStates.DETAILS[_models.TaskStates.TYPES.COMPLETE].label);
854
- secondTaskStatus = container.childNodes[0].childNodes[1].childNodes[3].childNodes[1].childNodes[1];
855
- expect(secondTaskStatus.textContent).toEqual(_models.TaskStates.DETAILS[_models.TaskStates.TYPES.NOT_STARTED].label);
856
-
857
- // Check final data submitted to backend is as expected
858
- finalSubmit = ON_SUBMIT_CALLS[ON_SUBMIT_CALLS.length - 1];
859
- expect(finalSubmit.date).toEqual('7-7-2022');
860
- expect(finalSubmit.mode).toEqual('air');
861
- expect(finalSubmit.formStatus.tasks['Date, location and mode details'].complete).toEqual(true);
862
- case 53:
863
- case "end":
864
- return _context28.stop();
865
- }
866
- }, _callee28);
867
- })));
868
- it('should go straight to CYA page if a complete task is selected', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
869
- var ON_SUBMIT, HOOKS, taskList, newPage, fieldset;
870
- return _regeneratorRuntime().wrap(function _callee30$(_context30) {
871
- while (1) switch (_context30.prev = _context30.next) {
872
- case 0:
873
- ON_SUBMIT = function ON_SUBMIT(type, payload, onSuccess) {
874
- onSuccess();
875
- };
876
- HOOKS = {
877
- onSubmit: ON_SUBMIT
878
- };
879
- _context30.next = 4;
880
- return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
881
- return _regeneratorRuntime().wrap(function _callee29$(_context29) {
882
- while (1) switch (_context29.prev = _context29.next) {
883
- case 0:
884
- (0, _reactDom.render)( /*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, _taskList.default, {
885
- hooks: HOOKS
886
- })), container);
887
- case 1:
888
- case "end":
889
- return _context29.stop();
890
- }
891
- }, _callee29);
892
- })));
893
- case 4:
894
- taskList = container.childNodes[0].childNodes[1]; // Launch first task
895
- _react.fireEvent.click(taskList.childNodes[3].childNodes[0].childNodes[0].childNodes[0], {});
896
-
897
- // Fill first page and navigate
898
- newPage = container.childNodes[0].childNodes[0];
899
- fieldset = newPage.childNodes[1].childNodes[0];
900
- setDate(fieldset.children[1], ['7', '7', '2022']);
901
- // child nodes of fieldset are legend and date
902
-
903
- _react.fireEvent.click(newPage.childNodes[2].childNodes[0], {});
904
-
905
- // Fill second page and navigate
906
- newPage = container.childNodes[0].childNodes[0];
907
- _react.fireEvent.click(newPage.childNodes[1].childNodes[0].childNodes[2].childNodes[0].childNodes[0], {});
908
- _react.fireEvent.click(newPage.childNodes[2].childNodes[0], {});
909
-
910
- // Continue on from CYA page
911
- _react.fireEvent.click(container.childNodes[0].childNodes[0].childNodes[5].childNodes[0], {});
912
-
913
- // Launch same task again
914
- _react.fireEvent.click(container.childNodes[0].childNodes[1].childNodes[3].childNodes[0].childNodes[0].childNodes[0], {});
915
-
916
- // Should be at CYA page
917
- expect(container.childNodes[0].childNodes[0].childNodes[0].textContent).toEqual('Check your answers');
918
- case 16:
919
- case "end":
920
- return _context30.stop();
921
- }
922
- }, _callee30);
923
- })));
924
- it('should go to incomplete page when selecting in-progress task', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
925
- var ON_SUBMIT, HOOKS, DATA, taskList;
926
- return _regeneratorRuntime().wrap(function _callee32$(_context32) {
927
- while (1) switch (_context32.prev = _context32.next) {
928
- case 0:
929
- ON_SUBMIT = function ON_SUBMIT(type, payload, onSuccess) {
930
- onSuccess();
931
- };
932
- HOOKS = {
933
- onSubmit: ON_SUBMIT
934
- };
935
- DATA = {
936
- "date": "7-7-2022",
937
- "formStatus": {
938
- "tasks": {
939
- "Date, location and mode details": {
940
- "complete": false,
941
- "currentPage": "eventMode"
942
- }
943
- },
944
- "taskPage": "eventMode"
945
- }
946
- };
947
- _context32.next = 5;
948
- return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
949
- return _regeneratorRuntime().wrap(function _callee31$(_context31) {
950
- while (1) switch (_context31.prev = _context31.next) {
951
- case 0:
952
- (0, _reactDom.render)( /*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, _taskList.default, {
953
- hooks: HOOKS,
954
- data: DATA
955
- })), container);
956
- case 1:
957
- case "end":
958
- return _context31.stop();
959
- }
960
- }, _callee31);
961
- })));
962
- case 5:
963
- taskList = container.childNodes[0].childNodes[1]; // Launch first task
964
- _react.fireEvent.click(taskList.childNodes[3].childNodes[0].childNodes[0].childNodes[0], {});
965
-
966
- // Should be at Event Mode page
967
- expect(container.childNodes[0].childNodes[0].childNodes[0].textContent).toEqual('Event Mode');
968
- case 8:
969
- case "end":
970
- return _context32.stop();
971
- }
972
- }, _callee32);
973
- })));
974
- it('should go to the first page of a complete task if noTaskCYAs specified', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34() {
975
- var ON_SUBMIT, HOOKS, TASK_LIST_WITH_NO_TASK_CYAS, taskList, newPage, fieldset;
976
- return _regeneratorRuntime().wrap(function _callee34$(_context34) {
977
- while (1) switch (_context34.prev = _context34.next) {
978
- case 0:
979
- ON_SUBMIT = function ON_SUBMIT(type, payload, onSuccess) {
980
- onSuccess();
981
- };
982
- HOOKS = {
983
- onSubmit: ON_SUBMIT
984
- };
985
- TASK_LIST_WITH_NO_TASK_CYAS = JSON.parse(JSON.stringify(_taskList.default));
986
- TASK_LIST_WITH_NO_TASK_CYAS.hub.noTaskCYAs = true;
987
- TASK_LIST_WITH_NO_TASK_CYAS.pages[1].actions[0] = {
988
- type: 'save',
989
- complete: true
990
- };
991
- _context34.next = 7;
992
- return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
993
- return _regeneratorRuntime().wrap(function _callee33$(_context33) {
994
- while (1) switch (_context33.prev = _context33.next) {
995
- case 0:
996
- (0, _reactDom.render)( /*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, TASK_LIST_WITH_NO_TASK_CYAS, {
997
- hooks: HOOKS
998
- })), container);
999
- case 1:
1000
- case "end":
1001
- return _context33.stop();
1002
- }
1003
- }, _callee33);
1004
- })));
1005
- case 7:
1006
- taskList = container.childNodes[0].childNodes[1]; // Launch first task
1007
- _react.fireEvent.click(taskList.childNodes[3].childNodes[0].childNodes[0].childNodes[0], {});
1008
-
1009
- // Fill first page and navigate
1010
- newPage = container.childNodes[0].childNodes[0];
1011
- fieldset = newPage.childNodes[1].childNodes[0];
1012
- setDate(fieldset.children[1], ['7', '7', '2022']);
1013
- _react.fireEvent.click(newPage.childNodes[2].childNodes[0], {});
1014
-
1015
- // Fill second page
1016
- newPage = container.childNodes[0].childNodes[0];
1017
- // expect(newPage.childNodes[1].childNodes[0].childNodes[2].childNodes[0].childNodes[0]).toEqual('');
1018
- _react.fireEvent.click(newPage.childNodes[1].childNodes[0].childNodes[2].childNodes[0].childNodes[0], {});
1019
- _react.fireEvent.click(newPage.childNodes[2].childNodes[0], {});
1020
-
1021
- // Launch same task again
1022
- _react.fireEvent.click(container.childNodes[0].childNodes[1].childNodes[3].childNodes[0].childNodes[0].childNodes[0], {});
1023
-
1024
- // Should be on the first page
1025
- expect(container.childNodes[0].childNodes[0].childNodes[0].textContent).toEqual('Event Date');
1026
- case 18:
1027
- case "end":
1028
- return _context34.stop();
84
+ const getContinueButton = page => page.childNodes[page.childNodes.length - 1].childNodes[0].childNodes[0];
85
+ const getCancelButton = page => page.childNodes[page.childNodes.length - 1].childNodes[1].childNodes[0];
86
+ it('should start on the hub page correctly and display the title', async () => {
87
+ await (0, _testUtils.act)(async () => {
88
+ (0, _reactDom.render)(/*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, _userProfile.default, {
89
+ data: _userProfileData.default
90
+ })), container);
91
+ });
92
+ const form = checkForm(container);
93
+ expect(form.childNodes.length).toEqual(2); // Title + Hub page (= CYA)
94
+ const title = form.childNodes[0];
95
+ expect(title.tagName).toEqual('H1');
96
+ expect(title.textContent).toEqual(_userProfile.default.title);
97
+ const hub = form.childNodes[1];
98
+ expect(hub.tagName).toEqual('DIV');
99
+ expect(hub.classList).toContain(_CheckYourAnswers.DEFAULT_CLASS);
100
+ });
101
+ it('should fire the onFormLoad method passed in the hooks', async () => {
102
+ let onFormLoadCalled = false;
103
+ const ON_FORM_LOAD = () => {
104
+ onFormLoadCalled = true;
105
+ };
106
+ const HOOKS = {
107
+ onFormLoad: ON_FORM_LOAD
108
+ };
109
+ await (0, _testUtils.act)(async () => {
110
+ (0, _reactDom.render)(/*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, _userProfile.default, {
111
+ data: _userProfileData.default,
112
+ hooks: HOOKS
113
+ })), container);
114
+ });
115
+ expect(onFormLoadCalled).toBeTruthy();
116
+ });
117
+ it('should navigate to the first editable page', async () => {
118
+ const ON_PAGE_CHANGE_CALLS = [];
119
+ const ON_PAGE_CHANGE = pageId => {
120
+ ON_PAGE_CHANGE_CALLS.push(pageId);
121
+ };
122
+ const HOOKS = {
123
+ onPageChange: ON_PAGE_CHANGE
124
+ };
125
+ await (0, _testUtils.act)(async () => {
126
+ (0, _reactDom.render)(/*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, _userProfile.default, {
127
+ data: _userProfileData.default,
128
+ hooks: HOOKS
129
+ })), container);
130
+ });
131
+ const form = checkForm(container);
132
+ const hub = form.childNodes[1]; // Hub = CYA
133
+ const [,, civilServantList] = hub.childNodes;
134
+ const link = getChangeLink(civilServantList);
135
+ expect(ON_PAGE_CHANGE_CALLS.length).toEqual(0);
136
+ _react.fireEvent.click(link, {});
137
+ expect(ON_PAGE_CHANGE_CALLS.length).toEqual(1);
138
+ expect(ON_PAGE_CHANGE_CALLS[0]).toEqual(_userProfile.default.pages[1].id);
139
+
140
+ // The form layout should have changed to the current page.
141
+ expect(form.childNodes.length).toEqual(1); // Just the page.
142
+ const page = form.childNodes[0];
143
+ const pageHeading = page.childNodes[0];
144
+ expect(pageHeading.tagName).toEqual('H1');
145
+ expect(pageHeading.textContent).toEqual(_userProfile.default.pages[1].title);
146
+ });
147
+ it('should handle a page submission', async () => {
148
+ const ON_SUBMIT_CALLS = [];
149
+ const ON_SUBMIT = (type, payload, onSuccess, onError, fieldName, fieldValue) => {
150
+ ON_SUBMIT_CALLS.push({
151
+ type,
152
+ payload,
153
+ onSuccess,
154
+ onError,
155
+ fieldName,
156
+ fieldValue
157
+ });
158
+ onSuccess();
159
+ };
160
+ const HOOKS = {
161
+ onSubmit: ON_SUBMIT
162
+ };
163
+ await (0, _testUtils.act)(async () => {
164
+ (0, _reactDom.render)(/*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, _userProfile.default, {
165
+ data: _userProfileData.default,
166
+ hooks: HOOKS,
167
+ type: _models.FormTypes.HUB
168
+ })), container);
169
+ });
170
+ const form = checkForm(container);
171
+
172
+ // Navigate to the "Are you a civil servant?" page.
173
+ const hub = form.childNodes[1]; // Hub = CYA
174
+ const [,, civilServantList] = hub.childNodes;
175
+ const link = getChangeLink(civilServantList);
176
+ _react.fireEvent.click(link, {});
177
+
178
+ // Should already be answered "Yes", but select "No, I'm a contractor" option to generate patch
179
+ // and then click "Continue".
180
+ _react.fireEvent.click(_react.screen.getByText("No, I'm a contractor"));
181
+ const page = form.childNodes[0];
182
+ const continueButton = getContinueButton(page);
183
+ expect(ON_SUBMIT_CALLS.length).toEqual(0);
184
+ _react.fireEvent.click(continueButton, {});
185
+ expect(ON_SUBMIT_CALLS.length).toEqual(1);
186
+ expect(ON_SUBMIT_CALLS[0].type).toEqual(_models.PageAction.TYPES.SUBMIT);
187
+ expect(ON_SUBMIT_CALLS[0].payload.areYouACivilServant).toEqual('no-contractor');
188
+ expect(ON_SUBMIT_CALLS[0].fieldName).toEqual('Are you a civil servant?');
189
+ expect(ON_SUBMIT_CALLS[0].fieldValue).toEqual("No, I'm a contractor");
190
+
191
+ // And we should be back on the hub.
192
+ expect(form.childNodes.length).toEqual(2); // Title + Hub page (= CYA)
193
+ const title = form.childNodes[0];
194
+ expect(title.tagName).toEqual('H1');
195
+ expect(title.textContent).toEqual(_userProfile.default.title);
196
+ });
197
+ it('should handle a page submission error', async () => {
198
+ const ON_SUBMIT_CALLS = [];
199
+ const ON_SUBMIT = (type, payload, onSuccess, onError) => {
200
+ ON_SUBMIT_CALLS.push({
201
+ type,
202
+ payload,
203
+ onSuccess,
204
+ onError
205
+ });
206
+ onError([{
207
+ id: 'unknown',
208
+ error: 'Something went wrong'
209
+ }]);
210
+ };
211
+ const HOOKS = {
212
+ onSubmit: ON_SUBMIT,
213
+ onAction: (formData, patch) => ({
214
+ formData,
215
+ patch
216
+ })
217
+ };
218
+ await (0, _testUtils.act)(async () => {
219
+ (0, _reactDom.render)(/*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, _userProfile.default, {
220
+ data: _userProfileData.default,
221
+ hooks: HOOKS
222
+ })), container);
223
+ });
224
+ const form = checkForm(container);
225
+
226
+ // Navigate to the "Are you a civil servant?" page.
227
+ const hub = form.childNodes[1]; // Hub = CYA
228
+ const [,, civilServantList] = hub.childNodes;
229
+ const link = getChangeLink(civilServantList);
230
+ _react.fireEvent.click(link, {});
231
+
232
+ // Should already be answered "Yes", so simply click "Continue".
233
+ const page = form.childNodes[0];
234
+ const continueButton = getContinueButton(page);
235
+ expect(ON_SUBMIT_CALLS.length).toEqual(0);
236
+ _react.fireEvent.click(continueButton, {});
237
+ expect(ON_SUBMIT_CALLS.length).toEqual(1);
238
+ expect(ON_SUBMIT_CALLS[0].type).toEqual(_models.PageAction.TYPES.SUBMIT);
239
+ expect(ON_SUBMIT_CALLS[0].payload.areYouACivilServant).toEqual('yes');
240
+
241
+ // And we should be kept on the same page.
242
+ expect(form.childNodes.length).toEqual(1); // Just the page.
243
+ const pageHeading = form.childNodes[0].childNodes[1];
244
+ expect(pageHeading.tagName).toEqual('H1');
245
+ expect(pageHeading.textContent).toEqual(_userProfile.default.pages[1].title);
246
+ });
247
+ it('should handle a page submission once regardless of how many times page action is clicked', async () => {
248
+ const ON_PAGE_CHANGE_CALLS = [];
249
+ const ON_PAGE_CHANGE = pageId => {
250
+ ON_PAGE_CHANGE_CALLS.push(pageId);
251
+ };
252
+ const ON_SUBMIT_CALLS = [];
253
+ const ON_SUBMIT = async (type, payload, onSuccess, onError, fieldName, fieldValue) => {
254
+ ON_SUBMIT_CALLS.push({
255
+ type,
256
+ payload,
257
+ onSuccess,
258
+ onError,
259
+ fieldName,
260
+ fieldValue
261
+ });
262
+
263
+ // mock a delay when submitting to the backend
264
+ await sleep(2000);
265
+ onSuccess();
266
+ };
267
+ const HOOKS = {
268
+ onSubmit: ON_SUBMIT,
269
+ onPageChange: ON_PAGE_CHANGE
270
+ };
271
+ (0, _testUtils.act)(() => {
272
+ (0, _reactDom.render)(/*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, _firstForm.default, {
273
+ hooks: HOOKS,
274
+ type: _models.FormTypes.CYA
275
+ })), container);
276
+ });
277
+ const [,,,,, continueButtonGroup] = container.childNodes[0].childNodes[0].childNodes;
278
+
279
+ // go to first question page
280
+ const continueFormButton = continueButtonGroup.childNodes[0];
281
+ _react.fireEvent.click(continueFormButton);
282
+ const innerDiv = container.childNodes[0].childNodes[0];
283
+
284
+ // enter a value in the input field
285
+ const firstNameInput = innerDiv.childNodes[1].childNodes[2];
286
+ const EVENT = {
287
+ target: {
288
+ name: firstNameInput.id,
289
+ value: 'abc'
1029
290
  }
1030
- }, _callee34);
1031
- })));
1032
- it('should handle cancellation from a page', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36() {
1033
- var ON_CANCEL_CALLS, ON_CANCEL, HOOKS, form, hub, _hub$childNodes6, civilServantList, link, page, cancel;
1034
- return _regeneratorRuntime().wrap(function _callee36$(_context36) {
1035
- while (1) switch (_context36.prev = _context36.next) {
1036
- case 0:
1037
- ON_CANCEL_CALLS = [];
1038
- ON_CANCEL = function ON_CANCEL() {
1039
- ON_CANCEL_CALLS.push(undefined);
1040
- };
1041
- HOOKS = {
1042
- onCancel: ON_CANCEL
1043
- };
1044
- _context36.next = 5;
1045
- return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35() {
1046
- return _regeneratorRuntime().wrap(function _callee35$(_context35) {
1047
- while (1) switch (_context35.prev = _context35.next) {
1048
- case 0:
1049
- (0, _reactDom.render)( /*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, _userProfile.default, {
1050
- data: _userProfileData.default,
1051
- hooks: HOOKS
1052
- })), container);
1053
- case 1:
1054
- case "end":
1055
- return _context35.stop();
1056
- }
1057
- }, _callee35);
1058
- })));
1059
- case 5:
1060
- form = checkForm(container); // Navigate to the "Are you a civil servant?" page.
1061
- hub = form.childNodes[1]; // Hub = CYA
1062
- _hub$childNodes6 = _slicedToArray(hub.childNodes, 3), civilServantList = _hub$childNodes6[2];
1063
- link = getChangeLink(civilServantList);
1064
- _react.fireEvent.click(link, {});
291
+ };
292
+ _react.fireEvent.change(firstNameInput, EVENT);
293
+ const submitButton = innerDiv.childNodes[2].childNodes[0];
1065
294
 
1066
- // Should already be answered "Yes", so simply click "Continue".
1067
- page = form.childNodes[0];
1068
- cancel = getCancelButton(page);
1069
- expect(ON_CANCEL_CALLS.length).toEqual(0);
1070
- _react.fireEvent.click(cancel, {});
1071
- expect(ON_CANCEL_CALLS.length).toEqual(1);
1072
- case 15:
1073
- case "end":
1074
- return _context36.stop();
1075
- }
1076
- }, _callee36);
1077
- })));
1078
- it('should navigate to a specific page at the beginning of a task if it is set as the firstPage of a task', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38() {
1079
- var ON_SUBMIT_CALLS, ON_SUBMIT, HOOKS, TASK_LIST_NON_SEQUENTIAL, taskList, firstTask, newPage;
1080
- return _regeneratorRuntime().wrap(function _callee38$(_context38) {
1081
- while (1) switch (_context38.prev = _context38.next) {
1082
- case 0:
1083
- ON_SUBMIT_CALLS = [];
1084
- ON_SUBMIT = function ON_SUBMIT(type, payload, onSuccess) {
1085
- ON_SUBMIT_CALLS.push(payload);
1086
- onSuccess();
1087
- };
1088
- HOOKS = {
1089
- onSubmit: ON_SUBMIT
1090
- };
1091
- TASK_LIST_NON_SEQUENTIAL = JSON.parse(JSON.stringify(_taskList.default));
1092
- TASK_LIST_NON_SEQUENTIAL.hub.nonSequential = true;
1093
- _context38.next = 7;
1094
- return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37() {
1095
- return _regeneratorRuntime().wrap(function _callee37$(_context37) {
1096
- while (1) switch (_context37.prev = _context37.next) {
1097
- case 0:
1098
- (0, _reactDom.render)( /*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, TASK_LIST_NON_SEQUENTIAL, {
1099
- hooks: HOOKS
1100
- })), container);
1101
- case 1:
1102
- case "end":
1103
- return _context37.stop();
1104
- }
1105
- }, _callee37);
1106
- })));
1107
- case 7:
1108
- taskList = container.childNodes[0].childNodes[1]; // Launch first task of second section
1109
- firstTask = taskList.childNodes[5].childNodes[0].childNodes[0].childNodes[0];
1110
- expect(firstTask.textContent).toEqual('People details');
1111
- _react.fireEvent.click(firstTask, {});
295
+ // click on save and continue
296
+ _react.fireEvent.click(submitButton);
1112
297
 
1113
- // Should be at Surname page
1114
- newPage = container.childNodes[0].childNodes[0];
1115
- expect(newPage.childNodes[0].textContent).toEqual('Surname');
1116
- case 13:
1117
- case "end":
1118
- return _context38.stop();
1119
- }
1120
- }, _callee38);
1121
- })));
1122
- it('should handle page navigation correctly when hideBlankRows is true', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40() {
1123
- var ON_PAGE_CHANGE_CALLS, ON_PAGE_CHANGE, HOOKS, form, hub, _hub$childNodes7, lineManagerList, link, page, pageHeading, continueButton, newPageHeading;
1124
- return _regeneratorRuntime().wrap(function _callee40$(_context40) {
1125
- while (1) switch (_context40.prev = _context40.next) {
1126
- case 0:
1127
- ON_PAGE_CHANGE_CALLS = [];
1128
- ON_PAGE_CHANGE = function ON_PAGE_CHANGE(pageId) {
1129
- ON_PAGE_CHANGE_CALLS.push(pageId);
1130
- };
1131
- HOOKS = {
1132
- onPageChange: ON_PAGE_CHANGE
1133
- };
1134
- _context40.next = 5;
1135
- return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39() {
1136
- return _regeneratorRuntime().wrap(function _callee39$(_context39) {
1137
- while (1) switch (_context39.prev = _context39.next) {
1138
- case 0:
1139
- (0, _reactDom.render)( /*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, _userProfile.default, {
1140
- data: _userProfileData.default,
1141
- hooks: HOOKS,
1142
- hideBlankRows: true
1143
- })), container);
1144
- case 1:
1145
- case "end":
1146
- return _context39.stop();
1147
- }
1148
- }, _callee39);
1149
- })));
1150
- case 5:
1151
- form = checkForm(container); // Navigate to the "Add or change a line manager" page.
1152
- hub = form.childNodes[1]; // Hub = CYA
1153
- _hub$childNodes7 = _slicedToArray(hub.childNodes, 4), lineManagerList = _hub$childNodes7[3];
1154
- link = getChangeLink(lineManagerList);
1155
- expect(ON_PAGE_CHANGE_CALLS.length).toEqual(0);
1156
- _react.fireEvent.click(link, {});
1157
- expect(ON_PAGE_CHANGE_CALLS[0]).toEqual(_userProfile.default.pages[4].id);
298
+ // click on save and continue again
299
+ _react.fireEvent.click(submitButton);
1158
300
 
1159
- // Should be on the page explaining what changing the line manager means.
1160
- page = form.childNodes[0];
1161
- pageHeading = page.childNodes[0];
1162
- expect(pageHeading.tagName).toEqual('H1');
1163
- expect(pageHeading.textContent).toEqual(_userProfile.default.pages[4].title);
301
+ // click on save and continue a third time
302
+ _react.fireEvent.click(submitButton);
1164
303
 
1165
- // Now click on the "Continue" button on here.
1166
- continueButton = getContinueButton(page);
1167
- expect(ON_PAGE_CHANGE_CALLS.length).toEqual(1);
1168
- _react.fireEvent.click(continueButton, {});
1169
- expect(ON_PAGE_CHANGE_CALLS.length).toEqual(2);
1170
- expect(ON_PAGE_CHANGE_CALLS[1]).toEqual(_userProfile.default.pages[5].id);
1171
- newPageHeading = form.childNodes[0].childNodes[0];
1172
- expect(newPageHeading.tagName).toEqual('H1');
1173
- expect(newPageHeading.textContent).toEqual(_userProfile.default.pages[5].title);
1174
- case 24:
1175
- case "end":
1176
- return _context40.stop();
304
+ // only expect one submit call to be made
305
+ expect(ON_SUBMIT_CALLS.length).toEqual(1);
306
+ expect(ON_PAGE_CHANGE_CALLS.length).toEqual(1);
307
+ expect(ON_SUBMIT_CALLS[0].type).toEqual(_models.PageAction.TYPES.SAVE_AND_CONTINUE);
308
+ });
309
+ it('should handle a page submission repeatedly if ignoreSubmittingFlag is true', async () => {
310
+ const ON_PAGE_CHANGE_CALLS = [];
311
+ const ON_PAGE_CHANGE = pageId => {
312
+ ON_PAGE_CHANGE_CALLS.push(pageId);
313
+ };
314
+ const ON_SUBMIT_CALLS = [];
315
+ const ON_SUBMIT = async (type, payload, onSuccess, onError, fieldName, fieldValue) => {
316
+ ON_SUBMIT_CALLS.push({
317
+ type,
318
+ payload,
319
+ onSuccess,
320
+ onError,
321
+ fieldName,
322
+ fieldValue
323
+ });
324
+
325
+ // mock a delay when submitting to the backend
326
+ await sleep(2000);
327
+ onSuccess();
328
+ };
329
+ const HOOKS = {
330
+ onSubmit: ON_SUBMIT,
331
+ onPageChange: ON_PAGE_CHANGE
332
+ };
333
+ const formDefinition = _objectSpread({}, _userProfile.default);
334
+ formDefinition.pages[1].actions = [{
335
+ type: 'saveAndContinue',
336
+ page: 'test',
337
+ ignoreSubmittingFlag: true
338
+ }, {
339
+ type: 'cancel'
340
+ }];
341
+ (0, _testUtils.act)(() => {
342
+ (0, _reactDom.render)(/*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, formDefinition, {
343
+ data: _userProfileData.default,
344
+ hooks: HOOKS
345
+ })), container);
346
+ });
347
+ const form = checkForm(container);
348
+
349
+ // Navigate to the "Are you a civil servant?" page.
350
+ const hub = form.childNodes[1]; // Hub = CYA
351
+ const [,, civilServantList] = hub.childNodes;
352
+ const link = getChangeLink(civilServantList);
353
+ _react.fireEvent.click(link, {});
354
+
355
+ // Should already be answered "Yes", so simply click "Continue".
356
+ const page = form.childNodes[0];
357
+ const continueButton = getContinueButton(page);
358
+ expect(ON_SUBMIT_CALLS.length).toEqual(0);
359
+ _react.fireEvent.click(continueButton, {});
360
+ expect(ON_SUBMIT_CALLS.length).toEqual(1);
361
+ expect(ON_SUBMIT_CALLS[0].type).toEqual(_models.PageAction.TYPES.SAVE_AND_CONTINUE);
362
+
363
+ // click on save and continue
364
+ _react.fireEvent.click(continueButton);
365
+
366
+ // click on save and continue again
367
+ _react.fireEvent.click(continueButton);
368
+
369
+ // click on save and continue a third time
370
+ _react.fireEvent.click(continueButton);
371
+
372
+ // expect all submit calls to be made
373
+ expect(ON_SUBMIT_CALLS.length).toEqual(4);
374
+ });
375
+ it('should handle page navigation', async () => {
376
+ const ON_PAGE_CHANGE_CALLS = [];
377
+ const ON_PAGE_CHANGE = pageId => {
378
+ ON_PAGE_CHANGE_CALLS.push(pageId);
379
+ };
380
+ const HOOKS = {
381
+ onPageChange: ON_PAGE_CHANGE
382
+ };
383
+ await (0, _testUtils.act)(async () => {
384
+ (0, _reactDom.render)(/*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, _userProfile.default, {
385
+ data: _userProfileData.default,
386
+ hooks: HOOKS
387
+ })), container);
388
+ });
389
+ const form = checkForm(container);
390
+
391
+ // Navigate to the "Add or change a line manager" page.
392
+ const hub = form.childNodes[1]; // Hub = CYA
393
+ const [,,,,, lineManagerList] = hub.childNodes;
394
+ const link = getChangeLink(lineManagerList);
395
+ expect(ON_PAGE_CHANGE_CALLS.length).toEqual(0);
396
+ _react.fireEvent.click(link, {});
397
+ expect(ON_PAGE_CHANGE_CALLS[0]).toEqual(_userProfile.default.pages[4].id);
398
+
399
+ // Should be on the page explaining what changing the line manager means.
400
+ const page = form.childNodes[0];
401
+ const pageHeading = page.childNodes[0];
402
+ expect(pageHeading.tagName).toEqual('H1');
403
+ expect(pageHeading.textContent).toEqual(_userProfile.default.pages[4].title);
404
+
405
+ // Now click on the "Continue" button on here.
406
+ const continueButton = getContinueButton(page);
407
+ expect(ON_PAGE_CHANGE_CALLS.length).toEqual(1);
408
+ _react.fireEvent.click(continueButton, {});
409
+ expect(ON_PAGE_CHANGE_CALLS.length).toEqual(2);
410
+ expect(ON_PAGE_CHANGE_CALLS[1]).toEqual(_userProfile.default.pages[5].id);
411
+ const newPageHeading = form.childNodes[0].childNodes[0];
412
+ expect(newPageHeading.tagName).toEqual('H1');
413
+ expect(newPageHeading.textContent).toEqual(_userProfile.default.pages[5].title);
414
+ });
415
+ it('should show no title when hide_title is set to true', async () => {
416
+ await (0, _testUtils.act)(async () => {
417
+ (0, _reactDom.render)(/*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, _userProfile.default, {
418
+ data: _userProfileData.default,
419
+ hide_title: true
420
+ })), container);
421
+ });
422
+ const form = checkForm(container);
423
+ expect(form.childNodes.length).toEqual(1); // Hub page (= CYA)
424
+ const hub = form.childNodes[0];
425
+ expect(hub.tagName).toEqual('DIV');
426
+ expect(hub.classList).toContain(_CheckYourAnswers.DEFAULT_CLASS);
427
+ });
428
+ it('should render a task list', async () => {
429
+ await (0, _testUtils.act)(async () => {
430
+ (0, _reactDom.render)(/*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _taskList.default), container);
431
+ });
432
+ const taskList = container.childNodes[0].childNodes[1];
433
+ expect(taskList.classList).toContain(_TaskList.DEFAULT_CLASS);
434
+ });
435
+ it('should render a cya page', async () => {
436
+ await (0, _testUtils.act)(async () => {
437
+ (0, _reactDom.render)(/*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _firstForm.default), container);
438
+ });
439
+ const cya = container.childNodes[0];
440
+ expect(cya.classList).toContain('hods-form');
441
+ });
442
+ it('should load task list with notes', async () => {
443
+ const ON_SUBMIT_CALLS = [];
444
+ const ON_SUBMIT = (type, payload, onSuccess) => {
445
+ ON_SUBMIT_CALLS.push(payload);
446
+ onSuccess();
447
+ };
448
+ const HOOKS = {
449
+ onSubmit: ON_SUBMIT
450
+ };
451
+ const TASK_LIST_WITH_NOTES = JSON.parse(JSON.stringify(_taskList.default));
452
+ TASK_LIST_WITH_NOTES.hub.notes = {
453
+ title: "test title",
454
+ text: "test text",
455
+ show_when: [{
456
+ "op": "=",
457
+ "field": "areYouACivilServant",
458
+ "value": "yes"
459
+ }]
460
+ };
461
+ await (0, _testUtils.act)(async () => {
462
+ (0, _reactDom.render)(/*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, TASK_LIST_WITH_NOTES, {
463
+ data: _userProfileData.default,
464
+ hooks: HOOKS
465
+ })), container);
466
+ });
467
+ const taskList = container.childNodes[0].childNodes[1];
468
+ expect(taskList.childNodes[5].textContent).toEqual("test text");
469
+ expect(taskList.childNodes[5].classList).toContain('govuk-textarea');
470
+ });
471
+ it('should not load task list with notes', async () => {
472
+ const ON_SUBMIT_CALLS = [];
473
+ const ON_SUBMIT = (type, payload, onSuccess) => {
474
+ ON_SUBMIT_CALLS.push(payload);
475
+ onSuccess();
476
+ };
477
+ const HOOKS = {
478
+ onSubmit: ON_SUBMIT
479
+ };
480
+ const TASK_LIST_WITH_NOTES = JSON.parse(JSON.stringify(_taskList.default));
481
+ TASK_LIST_WITH_NOTES.hub.notes = {
482
+ title: "test title",
483
+ text: "test text",
484
+ show_when: [{
485
+ "op": "!=",
486
+ "field": "changeSummary",
487
+ "value": undefined
488
+ }]
489
+ };
490
+ await (0, _testUtils.act)(async () => {
491
+ (0, _reactDom.render)(/*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, TASK_LIST_WITH_NOTES, {
492
+ data: _userProfileData.default,
493
+ hooks: HOOKS
494
+ })), container);
495
+ });
496
+ const taskList = container.childNodes[0].childNodes[1];
497
+ taskList.childNodes.forEach(child => {
498
+ // eslint-disable-next-line no-console
499
+ console.log("taskList, child = ".concat(JSON.stringify(child.textContent)));
500
+ });
501
+ expect(taskList.childNodes[5].textContent).not.toEqual("test text");
502
+ expect(taskList.childNodes[5].classList).not.toContain('govuk-textarea');
503
+ });
504
+ it('should handle navigating between task list pages', async () => {
505
+ const ON_SUBMIT_CALLS = [];
506
+ const ON_SUBMIT = (type, payload, onSuccess) => {
507
+ ON_SUBMIT_CALLS.push(payload);
508
+ onSuccess();
509
+ };
510
+ const HOOKS = {
511
+ onSubmit: ON_SUBMIT
512
+ };
513
+ await (0, _testUtils.act)(async () => {
514
+ (0, _reactDom.render)(/*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, _taskList.default, {
515
+ hooks: HOOKS
516
+ })), container);
517
+ });
518
+ const taskList = container.childNodes[0].childNodes[1];
519
+
520
+ // Check statuses are correct
521
+ let firstTaskStatus = taskList.childNodes[3].childNodes[0].childNodes[1];
522
+ expect(firstTaskStatus.textContent).toEqual(_models.TaskStates.DETAILS[_models.TaskStates.TYPES.NOT_STARTED].label);
523
+ let secondTaskStatus = taskList.childNodes[3].childNodes[1].childNodes[1];
524
+ expect(secondTaskStatus.textContent).toEqual(_models.TaskStates.DETAILS[_models.TaskStates.TYPES.CANNOT_START_YET].label);
525
+
526
+ // Launch first task
527
+ const firstTask = taskList.childNodes[3].childNodes[0].childNodes[0].childNodes[0];
528
+ expect(firstTask.textContent).toEqual('Date, location and mode details');
529
+ _react.fireEvent.click(firstTask, {});
530
+
531
+ // Fill first page and navigate
532
+ let newPage = container.childNodes[0].childNodes[0];
533
+ expect(newPage.childNodes[0].textContent).toEqual('Event Date');
534
+ const fieldset = newPage.childNodes[1].childNodes[0];
535
+ // child nodes of fieldset are legend and date
536
+ setDate(fieldset.children[1], ['7', '7', '2022']);
537
+ let continueButton = newPage.childNodes[2].childNodes[0];
538
+ _react.fireEvent.click(continueButton, {});
539
+
540
+ // Fill second page and navigate
541
+ newPage = container.childNodes[0].childNodes[0];
542
+ expect(newPage.childNodes[0].textContent).toEqual('Event Mode');
543
+ const seaButton = newPage.childNodes[1].childNodes[0].childNodes[2].childNodes[0];
544
+ expect(seaButton.textContent).toEqual('Sea');
545
+ _react.fireEvent.click(seaButton.childNodes[0], {});
546
+ continueButton = newPage.childNodes[2].childNodes[0];
547
+ _react.fireEvent.click(continueButton, {});
548
+
549
+ // Click change to mode on CYA page
550
+ const cyaPageChange = container.childNodes[0].childNodes[0];
551
+ expect(cyaPageChange.childNodes[0].textContent).toEqual('Check your answers');
552
+ const modeChangeLink = cyaPageChange.childNodes[4].childNodes[0].childNodes[0].childNodes[2].childNodes[0];
553
+ expect(modeChangeLink.textContent).toEqual('Change Event Mode');
554
+ _react.fireEvent.click(modeChangeLink, {});
555
+ const changePage = container.childNodes[0].childNodes[0];
556
+ expect(changePage.childNodes[0].textContent).toEqual('Event Mode');
557
+ // Click on radio for 'Air'
558
+ const airButton = changePage.childNodes[1].childNodes[0].childNodes[2].childNodes[1];
559
+ expect(airButton.textContent).toEqual('Air');
560
+ _react.fireEvent.click(airButton.childNodes[0]);
561
+ // Continue again to CYA page
562
+ expect(changePage.childNodes[2].childNodes[0].textContent).toEqual('Save and continue');
563
+ continueButton = changePage.childNodes[2].childNodes[0];
564
+ _react.fireEvent.click(continueButton, {});
565
+
566
+ // Continue on from CYA page
567
+ const cyaPage = container.childNodes[0].childNodes[0];
568
+ expect(cyaPage.childNodes[0].textContent).toEqual('Check your answers');
569
+ expect(cyaPage.childNodes[5].childNodes[0].textContent).toEqual('Save and continue');
570
+ expect(cyaPage.childNodes[5].childNodes[1].textContent).toEqual('Save and return later');
571
+ _react.fireEvent.click(cyaPage.childNodes[5].childNodes[0], {});
572
+
573
+ // Should be back at task list
574
+ expect(container.childNodes[0].childNodes[0].textContent).toEqual('Task List Form');
575
+
576
+ // Check statuses are correct
577
+ firstTaskStatus = container.childNodes[0].childNodes[1].childNodes[3].childNodes[0].childNodes[1];
578
+ expect(firstTaskStatus.textContent).toEqual(_models.TaskStates.DETAILS[_models.TaskStates.TYPES.COMPLETE].label);
579
+ secondTaskStatus = container.childNodes[0].childNodes[1].childNodes[3].childNodes[1].childNodes[1];
580
+ expect(secondTaskStatus.textContent).toEqual(_models.TaskStates.DETAILS[_models.TaskStates.TYPES.NOT_STARTED].label);
581
+
582
+ // Check final data submitted to backend is as expected
583
+ const finalSubmit = ON_SUBMIT_CALLS[ON_SUBMIT_CALLS.length - 1];
584
+ expect(finalSubmit.date).toEqual('7-7-2022');
585
+ expect(finalSubmit.mode).toEqual('air');
586
+ expect(finalSubmit.formStatus.tasks['Date, location and mode details'].complete).toEqual(true);
587
+ });
588
+ it('should go straight to CYA page if a complete task is selected', async () => {
589
+ const ON_SUBMIT = (type, payload, onSuccess) => {
590
+ onSuccess();
591
+ };
592
+ const HOOKS = {
593
+ onSubmit: ON_SUBMIT
594
+ };
595
+ await (0, _testUtils.act)(async () => {
596
+ (0, _reactDom.render)(/*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, _taskList.default, {
597
+ hooks: HOOKS
598
+ })), container);
599
+ });
600
+ const taskList = container.childNodes[0].childNodes[1];
601
+
602
+ // Launch first task
603
+ _react.fireEvent.click(taskList.childNodes[3].childNodes[0].childNodes[0].childNodes[0], {});
604
+
605
+ // Fill first page and navigate
606
+ let newPage = container.childNodes[0].childNodes[0];
607
+ const fieldset = newPage.childNodes[1].childNodes[0];
608
+ setDate(fieldset.children[1], ['7', '7', '2022']);
609
+ // child nodes of fieldset are legend and date
610
+
611
+ _react.fireEvent.click(newPage.childNodes[2].childNodes[0], {});
612
+
613
+ // Fill second page and navigate
614
+ newPage = container.childNodes[0].childNodes[0];
615
+ _react.fireEvent.click(newPage.childNodes[1].childNodes[0].childNodes[2].childNodes[0].childNodes[0], {});
616
+ _react.fireEvent.click(newPage.childNodes[2].childNodes[0], {});
617
+
618
+ // Continue on from CYA page
619
+ _react.fireEvent.click(container.childNodes[0].childNodes[0].childNodes[5].childNodes[0], {});
620
+
621
+ // Launch same task again
622
+ _react.fireEvent.click(container.childNodes[0].childNodes[1].childNodes[3].childNodes[0].childNodes[0].childNodes[0], {});
623
+
624
+ // Should be at CYA page
625
+ expect(container.childNodes[0].childNodes[0].childNodes[0].textContent).toEqual('Check your answers');
626
+ });
627
+ it('should go to incomplete page when selecting in-progress task', async () => {
628
+ const ON_SUBMIT = (type, payload, onSuccess) => {
629
+ onSuccess();
630
+ };
631
+ const HOOKS = {
632
+ onSubmit: ON_SUBMIT
633
+ };
634
+ const DATA = {
635
+ "date": "7-7-2022",
636
+ "formStatus": {
637
+ "tasks": {
638
+ "Date, location and mode details": {
639
+ "complete": false,
640
+ "currentPage": "eventMode"
641
+ }
642
+ },
643
+ "taskPage": "eventMode"
1177
644
  }
1178
- }, _callee40);
1179
- })));
645
+ };
646
+ await (0, _testUtils.act)(async () => {
647
+ (0, _reactDom.render)(/*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, _taskList.default, {
648
+ hooks: HOOKS,
649
+ data: DATA
650
+ })), container);
651
+ });
652
+ const taskList = container.childNodes[0].childNodes[1];
653
+
654
+ // Launch first task
655
+ _react.fireEvent.click(taskList.childNodes[3].childNodes[0].childNodes[0].childNodes[0], {});
656
+
657
+ // Should be at Event Mode page
658
+ expect(container.childNodes[0].childNodes[0].childNodes[0].textContent).toEqual('Event Mode');
659
+ });
660
+ it('should go to the first page of a complete task if noTaskCYAs specified', async () => {
661
+ const ON_SUBMIT = (type, payload, onSuccess) => {
662
+ onSuccess();
663
+ };
664
+ const HOOKS = {
665
+ onSubmit: ON_SUBMIT
666
+ };
667
+ const TASK_LIST_WITH_NO_TASK_CYAS = JSON.parse(JSON.stringify(_taskList.default));
668
+ TASK_LIST_WITH_NO_TASK_CYAS.hub.noTaskCYAs = true;
669
+ TASK_LIST_WITH_NO_TASK_CYAS.pages[1].actions[0] = {
670
+ type: 'save',
671
+ complete: true
672
+ };
673
+ await (0, _testUtils.act)(async () => {
674
+ (0, _reactDom.render)(/*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, TASK_LIST_WITH_NO_TASK_CYAS, {
675
+ hooks: HOOKS
676
+ })), container);
677
+ });
678
+ const taskList = container.childNodes[0].childNodes[1];
679
+
680
+ // Launch first task
681
+ _react.fireEvent.click(taskList.childNodes[3].childNodes[0].childNodes[0].childNodes[0], {});
682
+
683
+ // Fill first page and navigate
684
+ let newPage = container.childNodes[0].childNodes[0];
685
+ const fieldset = newPage.childNodes[1].childNodes[0];
686
+ setDate(fieldset.children[1], ['7', '7', '2022']);
687
+ _react.fireEvent.click(newPage.childNodes[2].childNodes[0], {});
688
+
689
+ // Fill second page
690
+ newPage = container.childNodes[0].childNodes[0];
691
+ // expect(newPage.childNodes[1].childNodes[0].childNodes[2].childNodes[0].childNodes[0]).toEqual('');
692
+ _react.fireEvent.click(newPage.childNodes[1].childNodes[0].childNodes[2].childNodes[0].childNodes[0], {});
693
+ _react.fireEvent.click(newPage.childNodes[2].childNodes[0], {});
694
+
695
+ // Launch same task again
696
+ _react.fireEvent.click(container.childNodes[0].childNodes[1].childNodes[3].childNodes[0].childNodes[0].childNodes[0], {});
697
+
698
+ // Should be on the first page
699
+ expect(container.childNodes[0].childNodes[0].childNodes[0].textContent).toEqual('Event Date');
700
+ });
701
+ it('should handle cancellation from a page', async () => {
702
+ const ON_CANCEL_CALLS = [];
703
+ const ON_CANCEL = () => {
704
+ ON_CANCEL_CALLS.push(undefined);
705
+ };
706
+ const HOOKS = {
707
+ onCancel: ON_CANCEL
708
+ };
709
+ await (0, _testUtils.act)(async () => {
710
+ (0, _reactDom.render)(/*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, _userProfile.default, {
711
+ data: _userProfileData.default,
712
+ hooks: HOOKS
713
+ })), container);
714
+ });
715
+ const form = checkForm(container);
716
+
717
+ // Navigate to the "Are you a civil servant?" page.
718
+ const hub = form.childNodes[1]; // Hub = CYA
719
+ const [,, civilServantList] = hub.childNodes;
720
+ const link = getChangeLink(civilServantList);
721
+ _react.fireEvent.click(link, {});
722
+
723
+ // Should already be answered "Yes", so simply click "Continue".
724
+ const page = form.childNodes[0];
725
+ const cancel = getCancelButton(page);
726
+ expect(ON_CANCEL_CALLS.length).toEqual(0);
727
+ _react.fireEvent.click(cancel, {});
728
+ expect(ON_CANCEL_CALLS.length).toEqual(1);
729
+ });
730
+ it('should navigate to a specific page at the beginning of a task if it is set as the firstPage of a task', async () => {
731
+ const ON_SUBMIT_CALLS = [];
732
+ const ON_SUBMIT = (type, payload, onSuccess) => {
733
+ ON_SUBMIT_CALLS.push(payload);
734
+ onSuccess();
735
+ };
736
+ const HOOKS = {
737
+ onSubmit: ON_SUBMIT
738
+ };
739
+ const TASK_LIST_NON_SEQUENTIAL = JSON.parse(JSON.stringify(_taskList.default));
740
+ TASK_LIST_NON_SEQUENTIAL.hub.nonSequential = true;
741
+ await (0, _testUtils.act)(async () => {
742
+ (0, _reactDom.render)(/*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, TASK_LIST_NON_SEQUENTIAL, {
743
+ hooks: HOOKS
744
+ })), container);
745
+ });
746
+ const taskList = container.childNodes[0].childNodes[1];
747
+
748
+ // Launch first task of second section
749
+ const firstTask = taskList.childNodes[5].childNodes[0].childNodes[0].childNodes[0];
750
+ expect(firstTask.textContent).toEqual('People details');
751
+ _react.fireEvent.click(firstTask, {});
752
+
753
+ // Should be at Surname page
754
+ const newPage = container.childNodes[0].childNodes[0];
755
+ expect(newPage.childNodes[0].textContent).toEqual('Surname');
756
+ });
757
+ it('should handle page navigation correctly when hideBlankRows is true', async () => {
758
+ const ON_PAGE_CHANGE_CALLS = [];
759
+ const ON_PAGE_CHANGE = pageId => {
760
+ ON_PAGE_CHANGE_CALLS.push(pageId);
761
+ };
762
+ const HOOKS = {
763
+ onPageChange: ON_PAGE_CHANGE
764
+ };
765
+ await (0, _testUtils.act)(async () => {
766
+ (0, _reactDom.render)(/*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, _userProfile.default, {
767
+ data: _userProfileData.default,
768
+ hooks: HOOKS,
769
+ hideBlankRows: true
770
+ })), container);
771
+ });
772
+ const form = checkForm(container);
773
+
774
+ // Navigate to the "Add or change a line manager" page.
775
+ const hub = form.childNodes[1]; // Hub = CYA
776
+ const [,,, lineManagerList] = hub.childNodes;
777
+ const link = getChangeLink(lineManagerList);
778
+ expect(ON_PAGE_CHANGE_CALLS.length).toEqual(0);
779
+ _react.fireEvent.click(link, {});
780
+ expect(ON_PAGE_CHANGE_CALLS[0]).toEqual(_userProfile.default.pages[4].id);
781
+
782
+ // Should be on the page explaining what changing the line manager means.
783
+ const page = form.childNodes[0];
784
+ const pageHeading = page.childNodes[0];
785
+ expect(pageHeading.tagName).toEqual('H1');
786
+ expect(pageHeading.textContent).toEqual(_userProfile.default.pages[4].title);
787
+
788
+ // Now click on the "Continue" button on here.
789
+ const continueButton = getContinueButton(page);
790
+ expect(ON_PAGE_CHANGE_CALLS.length).toEqual(1);
791
+ _react.fireEvent.click(continueButton, {});
792
+ expect(ON_PAGE_CHANGE_CALLS.length).toEqual(2);
793
+ expect(ON_PAGE_CHANGE_CALLS[1]).toEqual(_userProfile.default.pages[5].id);
794
+ const newPageHeading = form.childNodes[0].childNodes[0];
795
+ expect(newPageHeading.tagName).toEqual('H1');
796
+ expect(newPageHeading.textContent).toEqual(_userProfile.default.pages[5].title);
797
+ });
1180
798
  });
1181
799
  });