@ukhomeoffice/cop-react-form-renderer 4.18.0 → 5.0.0-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 (307) hide show
  1. package/dist/components/CheckYourAnswers/Answer.js +1 -14
  2. package/dist/components/CheckYourAnswers/CheckYourAnswers.js +19 -57
  3. package/dist/components/CheckYourAnswers/index.js +0 -3
  4. package/dist/components/CollectionPage/CollectionPage.js +8 -38
  5. package/dist/components/CollectionPage/index.js +0 -3
  6. package/dist/components/FormComponent/Collection.js +13 -54
  7. package/dist/components/FormComponent/Container.js +6 -30
  8. package/dist/components/FormComponent/FormComponent.js +14 -57
  9. package/dist/components/FormComponent/helpers/addLabel.js +4 -7
  10. package/dist/components/FormComponent/helpers/getComponentDisabled.js +0 -4
  11. package/dist/components/FormComponent/helpers/getComponentDisabled.test.js +0 -2
  12. package/dist/components/FormComponent/helpers/getComponentError.js +0 -6
  13. package/dist/components/FormComponent/helpers/getComponentError.test.js +0 -2
  14. package/dist/components/FormComponent/helpers/index.js +0 -4
  15. package/dist/components/FormComponent/index.js +0 -3
  16. package/dist/components/FormPage/FormPage.js +14 -45
  17. package/dist/components/FormPage/index.js +0 -3
  18. package/dist/components/FormRenderer/FormRenderer.js +106 -189
  19. package/dist/components/FormRenderer/handlers/cyaAction.js +0 -5
  20. package/dist/components/FormRenderer/handlers/getPageId.js +0 -2
  21. package/dist/components/FormRenderer/handlers/getPageId.test.js +1 -2
  22. package/dist/components/FormRenderer/handlers/handlers.test.js +1 -18
  23. package/dist/components/FormRenderer/handlers/index.js +0 -5
  24. package/dist/components/FormRenderer/handlers/navigate.js +0 -5
  25. package/dist/components/FormRenderer/handlers/submissionError.js +0 -2
  26. package/dist/components/FormRenderer/helpers/canActionProceed.js +0 -3
  27. package/dist/components/FormRenderer/helpers/canActionProceed.test.js +1 -3
  28. package/dist/components/FormRenderer/helpers/canCYASubmit.js +0 -2
  29. package/dist/components/FormRenderer/helpers/canCYASubmit.test.js +1 -5
  30. package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.js +0 -5
  31. package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.test.js +1 -2
  32. package/dist/components/FormRenderer/helpers/getCYA.js +0 -6
  33. package/dist/components/FormRenderer/helpers/getCYA.test.js +1 -3
  34. package/dist/components/FormRenderer/helpers/getFormState.js +0 -5
  35. package/dist/components/FormRenderer/helpers/getFormState.test.js +1 -3
  36. package/dist/components/FormRenderer/helpers/getNextPageId.js +0 -25
  37. package/dist/components/FormRenderer/helpers/getNextPageId.test.js +1 -4
  38. package/dist/components/FormRenderer/helpers/getPage.js +0 -5
  39. package/dist/components/FormRenderer/helpers/getPage.test.js +1 -3
  40. package/dist/components/FormRenderer/helpers/getRelevantPages.js +0 -6
  41. package/dist/components/FormRenderer/helpers/getRelevantPages.test.js +1 -3
  42. package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +0 -10
  43. package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +0 -6
  44. package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.js +6 -20
  45. package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.test.js +3 -8
  46. package/dist/components/FormRenderer/helpers/index.js +1 -11
  47. package/dist/components/FormRenderer/index.js +0 -3
  48. package/dist/components/PageActions/ActionButton.js +2 -17
  49. package/dist/components/PageActions/PageActions.js +3 -10
  50. package/dist/components/PageActions/index.js +0 -3
  51. package/dist/components/SummaryList/GroupAction.js +3 -24
  52. package/dist/components/SummaryList/RowAction.js +3 -23
  53. package/dist/components/SummaryList/SummaryList.js +6 -28
  54. package/dist/components/SummaryList/SummaryListRow.js +4 -8
  55. package/dist/components/SummaryList/SummaryListTitleRow.js +2 -7
  56. package/dist/components/SummaryList/helpers/getGroupActionAttributes.js +0 -3
  57. package/dist/components/SummaryList/helpers/getGroupActionAttributes.test.js +0 -6
  58. package/dist/components/SummaryList/helpers/getRowActionAttributes.js +0 -3
  59. package/dist/components/SummaryList/helpers/getRowActionAttributes.test.js +0 -6
  60. package/dist/components/SummaryList/helpers/index.js +0 -2
  61. package/dist/components/SummaryList/index.js +0 -3
  62. package/dist/components/TaskList/Task.js +7 -29
  63. package/dist/components/TaskList/TaskList.js +12 -33
  64. package/dist/components/TaskList/TaskState.js +2 -10
  65. package/dist/components/TaskList/index.js +0 -3
  66. package/dist/components/index.js +0 -6
  67. package/dist/context/HooksContext/HooksContext.js +14 -34
  68. package/dist/context/HooksContext/index.js +0 -5
  69. package/dist/context/ValidationContext/ValidationContext.js +8 -34
  70. package/dist/context/ValidationContext/index.js +0 -5
  71. package/dist/context/index.js +0 -3
  72. package/dist/hooks/index.js +0 -9
  73. package/dist/hooks/useAxios.js +8 -25
  74. package/dist/hooks/useGetRequest.js +13 -47
  75. package/dist/hooks/useHooks.js +2 -4
  76. package/dist/hooks/useRefData.js +8 -37
  77. package/dist/hooks/useValidation.js +2 -4
  78. package/dist/index.js +0 -6
  79. package/dist/models/PageAction.js +0 -3
  80. package/dist/models/TaskStates.js +0 -3
  81. package/dist/models/index.js +0 -9
  82. package/dist/utils/CheckYourAnswers/getCYAAction.js +1 -9
  83. package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.js +0 -10
  84. package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.js +0 -8
  85. package/dist/utils/CheckYourAnswers/getCYARow.js +1 -10
  86. package/dist/utils/CheckYourAnswers/getCYARowForGroup.js +2 -20
  87. package/dist/utils/CheckYourAnswers/getCYARowsForCollection.js +0 -18
  88. package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +0 -20
  89. package/dist/utils/CheckYourAnswers/getCYARowsForContainer.js +0 -13
  90. package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +2 -22
  91. package/dist/utils/CheckYourAnswers/index.js +1 -3
  92. package/dist/utils/CheckYourAnswers/showComponentCYA.js +2 -11
  93. package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.js +0 -11
  94. package/dist/utils/CollectionPage/getCollectionPageActiveIndex.js +0 -6
  95. package/dist/utils/CollectionPage/index.js +1 -5
  96. package/dist/utils/CollectionPage/mergeCollectionPages.js +1 -12
  97. package/dist/utils/Component/cleanAttributes.js +1 -8
  98. package/dist/utils/Component/elevateNestedComponents.js +0 -3
  99. package/dist/utils/Component/getComponent.js +4 -68
  100. package/dist/utils/Component/getComponentTests/getComponent.autocomplete.test.js +6 -10
  101. package/dist/utils/Component/getComponentTests/getComponent.calculation.test.js +10 -28
  102. package/dist/utils/Component/getComponentTests/getComponent.checkboxes.test.js +6 -33
  103. package/dist/utils/Component/getComponentTests/getComponent.date.test.js +10 -27
  104. package/dist/utils/Component/getComponentTests/getComponent.details.test.js +4 -10
  105. package/dist/utils/Component/getComponentTests/getComponent.email.test.js +4 -21
  106. package/dist/utils/Component/getComponentTests/getComponent.file.test.js +4 -22
  107. package/dist/utils/Component/getComponentTests/getComponent.heading.test.js +3 -7
  108. package/dist/utils/Component/getComponentTests/getComponent.html.test.js +4 -10
  109. package/dist/utils/Component/getComponentTests/getComponent.insetText.test.js +3 -7
  110. package/dist/utils/Component/getComponentTests/getComponent.nested.test.js +6 -15
  111. package/dist/utils/Component/getComponentTests/getComponent.phoneNumber.test.js +4 -21
  112. package/dist/utils/Component/getComponentTests/getComponent.radios.test.js +6 -33
  113. package/dist/utils/Component/getComponentTests/getComponent.select.test.js +4 -21
  114. package/dist/utils/Component/getComponentTests/getComponent.text.test.js +4 -21
  115. package/dist/utils/Component/getComponentTests/getComponent.textarea.test.js +4 -21
  116. package/dist/utils/Component/getComponentTests/getComponent.time.test.js +10 -29
  117. package/dist/utils/Component/getComponentTests/getComponent.unknown.test.js +1 -2
  118. package/dist/utils/Component/getComponentTests/getComponent.warningText.test.js +3 -7
  119. package/dist/utils/Component/getDefaultValue.js +0 -7
  120. package/dist/utils/Component/index.js +0 -9
  121. package/dist/utils/Component/isEditable.js +1 -4
  122. package/dist/utils/Component/showComponent.js +1 -8
  123. package/dist/utils/Component/wrapInFormGroup.js +0 -7
  124. package/dist/utils/Condition/index.js +0 -5
  125. package/dist/utils/Condition/meetsAllConditions.js +0 -9
  126. package/dist/utils/Condition/meetsCondition.js +7 -19
  127. package/dist/utils/Condition/meetsOneCondition.js +1 -9
  128. package/dist/utils/Condition/setupConditions.js +0 -12
  129. package/dist/utils/Container/getEditableComponents.js +0 -7
  130. package/dist/utils/Container/index.js +0 -5
  131. package/dist/utils/Container/setupNesting.js +0 -11
  132. package/dist/utils/Container/showContainer.js +9 -18
  133. package/dist/utils/Data/applyFormula.js +2 -28
  134. package/dist/utils/Data/getAutocompleteSource.js +1 -4
  135. package/dist/utils/Data/getDataPath.js +3 -17
  136. package/dist/utils/Data/getOptions.js +0 -9
  137. package/dist/utils/Data/getSourceData.js +4 -19
  138. package/dist/utils/Data/index.js +1 -11
  139. package/dist/utils/Data/refDataToOptions.js +1 -12
  140. package/dist/utils/Data/setDataItem.js +0 -5
  141. package/dist/utils/Data/setupFormData.js +2 -20
  142. package/dist/utils/Data/setupRefDataUrlForComponent.js +0 -14
  143. package/dist/utils/FormPage/getFormPage.js +0 -15
  144. package/dist/utils/FormPage/getFormPages.js +0 -8
  145. package/dist/utils/FormPage/getPageActions.js +3 -18
  146. package/dist/utils/FormPage/getParagraphFromText.js +0 -3
  147. package/dist/utils/FormPage/index.js +0 -6
  148. package/dist/utils/FormPage/showFormPage.js +9 -18
  149. package/dist/utils/FormPage/showFormPageCYA.js +0 -5
  150. package/dist/utils/FormPage/useComponent.js +3 -18
  151. package/dist/utils/Format/formatData.js +0 -5
  152. package/dist/utils/Format/formatDataForComponent.js +1 -6
  153. package/dist/utils/Format/formatDataForForm.js +0 -8
  154. package/dist/utils/Format/formatDataForPage.js +1 -5
  155. package/dist/utils/Format/index.js +1 -6
  156. package/dist/utils/Hub/getFormHub.js +0 -8
  157. package/dist/utils/Hub/index.js +1 -3
  158. package/dist/utils/Meta/documents/getDocuments.js +1 -4
  159. package/dist/utils/Meta/documents/getDocuments.test.js +0 -9
  160. package/dist/utils/Meta/documents/index.js +1 -5
  161. package/dist/utils/Meta/documents/setDocumentForField.js +0 -11
  162. package/dist/utils/Meta/documents/setDocumentForField.test.js +0 -11
  163. package/dist/utils/Meta/index.js +2 -6
  164. package/dist/utils/Operate/checkValueIsTruthy.js +1 -7
  165. package/dist/utils/Operate/getIndexOfMatchingValueIn.js +7 -21
  166. package/dist/utils/Operate/index.js +0 -3
  167. package/dist/utils/Operate/persistValueInFormData.js +1 -8
  168. package/dist/utils/Operate/runPageOperations.js +3 -18
  169. package/dist/utils/Operate/setValueInFormData.js +2 -7
  170. package/dist/utils/Operate/shouldRun.js +1 -14
  171. package/dist/utils/Validate/additional/index.js +1 -18
  172. package/dist/utils/Validate/additional/index.test.js +0 -6
  173. package/dist/utils/Validate/additional/mustBeAfter.js +3 -8
  174. package/dist/utils/Validate/additional/mustBeAfter.test.js +0 -4
  175. package/dist/utils/Validate/additional/mustBeBefore.js +3 -8
  176. package/dist/utils/Validate/additional/mustBeBefore.test.js +0 -4
  177. package/dist/utils/Validate/additional/mustBeEarlierDateTime.js +5 -16
  178. package/dist/utils/Validate/additional/mustBeEarlierDateTime.test.js +0 -7
  179. package/dist/utils/Validate/additional/mustBeInTheFuture.js +3 -12
  180. package/dist/utils/Validate/additional/mustBeInTheFuture.test.js +0 -3
  181. package/dist/utils/Validate/additional/mustBeInThePast.js +5 -13
  182. package/dist/utils/Validate/additional/mustBeInThePast.test.js +0 -3
  183. package/dist/utils/Validate/additional/mustBeLessThan.js +0 -3
  184. package/dist/utils/Validate/additional/mustBeLessThan.test.js +0 -2
  185. package/dist/utils/Validate/additional/mustBeLongerThan.js +0 -3
  186. package/dist/utils/Validate/additional/mustBeLongerThan.test.js +0 -2
  187. package/dist/utils/Validate/additional/mustBeNumbersOnly.js +0 -4
  188. package/dist/utils/Validate/additional/mustBeNumbersOnly.test.js +0 -2
  189. package/dist/utils/Validate/additional/mustBeShorterThan.js +0 -3
  190. package/dist/utils/Validate/additional/mustBeShorterThan.test.js +0 -2
  191. package/dist/utils/Validate/additional/mustEnterAtLeastOne.js +0 -5
  192. package/dist/utils/Validate/additional/mustEnterAtLeastOne.test.js +0 -4
  193. package/dist/utils/Validate/additional/utils.js +8 -24
  194. package/dist/utils/Validate/index.js +1 -9
  195. package/dist/utils/Validate/validateCollection.js +0 -9
  196. package/dist/utils/Validate/validateComponent.js +2 -35
  197. package/dist/utils/Validate/validateContainer.js +0 -13
  198. package/dist/utils/Validate/validateDate.js +4 -36
  199. package/dist/utils/Validate/validateEmail.js +1 -7
  200. package/dist/utils/Validate/validatePage.js +0 -15
  201. package/dist/utils/Validate/validateRegex.js +0 -10
  202. package/dist/utils/Validate/validateRequired.js +0 -8
  203. package/dist/utils/Validate/validateTime.js +3 -20
  204. package/dist/utils/index.js +0 -19
  205. package/package.json +50 -34
  206. package/dist/components/CheckYourAnswers/Answer.test.js +0 -95
  207. package/dist/components/CheckYourAnswers/CheckYourAnswers.stories.mdx +0 -410
  208. package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +0 -680
  209. package/dist/components/CollectionPage/CollectionPage.test.js +0 -428
  210. package/dist/components/FormComponent/Collection.test.js +0 -381
  211. package/dist/components/FormComponent/Container.test.js +0 -423
  212. package/dist/components/FormComponent/FormComponent.stories.mdx +0 -184
  213. package/dist/components/FormComponent/FormComponent.test.js +0 -264
  214. package/dist/components/FormPage/FormPage.stories.mdx +0 -131
  215. package/dist/components/FormPage/FormPage.test.js +0 -368
  216. package/dist/components/FormRenderer/FormRenderer.stories.mdx +0 -183
  217. package/dist/components/FormRenderer/FormRenderer.test.js +0 -1006
  218. package/dist/components/PageActions/ActionButton.test.js +0 -116
  219. package/dist/components/PageActions/PageActions.stories.mdx +0 -74
  220. package/dist/components/PageActions/PageActions.test.js +0 -157
  221. package/dist/components/SummaryList/GroupAction.test.js +0 -94
  222. package/dist/components/SummaryList/RowAction.test.js +0 -94
  223. package/dist/components/SummaryList/SummaryList.stories.mdx +0 -90
  224. package/dist/components/SummaryList/SummaryList.test.js +0 -361
  225. package/dist/components/TaskList/Task.test.js +0 -194
  226. package/dist/components/TaskList/TaskList.stories.mdx +0 -164
  227. package/dist/components/TaskList/TaskList.test.js +0 -334
  228. package/dist/components/TaskList/TaskState.test.js +0 -104
  229. package/dist/context/HooksContext/HooksContext.test.js +0 -60
  230. package/dist/context/ValidationContext/ValidationContext.test.js +0 -98
  231. package/dist/json/areYouACivilServant.json +0 -7
  232. package/dist/json/firstForm.json +0 -94
  233. package/dist/json/grade.json +0 -108
  234. package/dist/json/group.data.json +0 -21
  235. package/dist/json/group.json +0 -402
  236. package/dist/json/groupOfRow.json +0 -137
  237. package/dist/json/groupOfRowData.json +0 -15
  238. package/dist/json/port.json +0 -346
  239. package/dist/json/saveAndContinue.json +0 -98
  240. package/dist/json/sublocation.json +0 -859
  241. package/dist/json/taskList.json +0 -265
  242. package/dist/json/team.json +0 -17351
  243. package/dist/json/terminal.json +0 -81
  244. package/dist/json/userProfile.data.json +0 -21
  245. package/dist/json/userProfile.json +0 -276
  246. package/dist/setupTests.js +0 -59
  247. package/dist/utils/CheckYourAnswers/getCYAAction.test.js +0 -139
  248. package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.test.js +0 -76
  249. package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.test.js +0 -59
  250. package/dist/utils/CheckYourAnswers/getCYARow.test.js +0 -256
  251. package/dist/utils/CheckYourAnswers/getCYARowForGroup.test.js +0 -77
  252. package/dist/utils/CheckYourAnswers/getCYARowsForCollection.test.js +0 -199
  253. package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +0 -170
  254. package/dist/utils/CheckYourAnswers/getCYARowsForContainer.test.js +0 -323
  255. package/dist/utils/CheckYourAnswers/getCYARowsForPage.test.js +0 -281
  256. package/dist/utils/CheckYourAnswers/showComponentCYA.test.js +0 -64
  257. package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.test.js +0 -41
  258. package/dist/utils/CollectionPage/getCollectionPageActiveIndex.test.js +0 -54
  259. package/dist/utils/CollectionPage/mergeCollectionPages.test.js +0 -131
  260. package/dist/utils/Component/cleanAttributes.test.js +0 -69
  261. package/dist/utils/Component/elevateNestedComponents.test.js +0 -92
  262. package/dist/utils/Component/getDefaultValue.test.js +0 -53
  263. package/dist/utils/Component/isEditable.test.js +0 -42
  264. package/dist/utils/Component/showComponent.test.js +0 -157
  265. package/dist/utils/Condition/meetsAllConditions.test.js +0 -62
  266. package/dist/utils/Condition/meetsCondition.test.js +0 -391
  267. package/dist/utils/Condition/meetsOneCondition.test.js +0 -101
  268. package/dist/utils/Condition/setupConditions.test.js +0 -35
  269. package/dist/utils/Container/getEditableComponents.test.js +0 -146
  270. package/dist/utils/Container/setupNesting.test.js +0 -92
  271. package/dist/utils/Container/showContainer.test.js +0 -179
  272. package/dist/utils/Data/applyFormula.test.js +0 -264
  273. package/dist/utils/Data/getAutocompleteSource.test.js +0 -146
  274. package/dist/utils/Data/getDataPath.test.js +0 -52
  275. package/dist/utils/Data/getOptions.test.js +0 -71
  276. package/dist/utils/Data/getSourceData.test.js +0 -141
  277. package/dist/utils/Data/refDataToOptions.test.js +0 -197
  278. package/dist/utils/Data/setDataItem.test.js +0 -112
  279. package/dist/utils/Data/setupFormData.test.js +0 -276
  280. package/dist/utils/Data/setupRefDataUrlForComponent.test.js +0 -133
  281. package/dist/utils/FormPage/getFormPage.test.js +0 -205
  282. package/dist/utils/FormPage/getFormPages.test.js +0 -98
  283. package/dist/utils/FormPage/getPageActions.test.js +0 -89
  284. package/dist/utils/FormPage/getParagraphFromText.test.js +0 -29
  285. package/dist/utils/FormPage/showFormPage.test.js +0 -182
  286. package/dist/utils/FormPage/showFormPageCYA.test.js +0 -30
  287. package/dist/utils/FormPage/useComponent.test.js +0 -169
  288. package/dist/utils/Format/formatData.test.js +0 -46
  289. package/dist/utils/Format/formatDataForComponent.test.js +0 -161
  290. package/dist/utils/Format/formatDataForForm.test.js +0 -78
  291. package/dist/utils/Format/formatDataForPage.test.js +0 -96
  292. package/dist/utils/Hub/getFormHub.test.js +0 -107
  293. package/dist/utils/Operate/checkValueIsTruthy.test.js +0 -44
  294. package/dist/utils/Operate/getIndexOfMatchingValueIn.test.js +0 -159
  295. package/dist/utils/Operate/persistValueInFormData.test.js +0 -106
  296. package/dist/utils/Operate/runPageOperations.test.js +0 -107
  297. package/dist/utils/Operate/setValueInFormData.test.js +0 -46
  298. package/dist/utils/Operate/shouldRun.test.js +0 -69
  299. package/dist/utils/Validate/validateCollection.test.js +0 -74
  300. package/dist/utils/Validate/validateComponent.test.js +0 -267
  301. package/dist/utils/Validate/validateContainer.test.js +0 -81
  302. package/dist/utils/Validate/validateDate.test.js +0 -118
  303. package/dist/utils/Validate/validateEmail.test.js +0 -57
  304. package/dist/utils/Validate/validatePage.test.js +0 -383
  305. package/dist/utils/Validate/validateRegex.test.js +0 -41
  306. package/dist/utils/Validate/validateRequired.test.js +0 -62
  307. package/dist/utils/Validate/validateTime.test.js +0 -61
@@ -1,368 +0,0 @@
1
- "use strict";
2
-
3
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
-
5
- var _react = require("@testing-library/react");
6
-
7
- var _react2 = _interopRequireDefault(require("react"));
8
-
9
- var _models = require("../../models");
10
-
11
- var _setupTests = require("../../setupTests");
12
-
13
- var _ActionButton = require("../PageActions/ActionButton");
14
-
15
- var _FormPage = _interopRequireWildcard(require("./FormPage"));
16
-
17
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
18
-
19
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
20
-
21
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
-
23
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
24
-
25
- 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); }); }; }
26
-
27
- describe('components.FormPage', function () {
28
- describe('FormPage', function () {
29
- var TEXT = {
30
- id: 'text',
31
- fieldId: 'text',
32
- type: 'text',
33
- label: 'Text component',
34
- hint: 'Text hint'
35
- }; // eslint-disable-next-line no-template-curly-in-string
36
-
37
- var TEXT_WITH_EXPRESSION = {
38
- id: 'text1',
39
- fieldId: 'text1',
40
- type: 'text',
41
- label: 'Email to ${wrapper.email}',
42
- hint: 'Text hint ${currentUser.givenName}'
43
- }; // eslint-disable-next-line no-template-curly-in-string
44
-
45
- var AUTO_WITH_EXPRESSION = {
46
- id: 'text2',
47
- fieldId: 'text2',
48
- label: '${text2} ${currentUser.givenName}',
49
- hint: '${wrapper.email}',
50
- type: 'autocomplete',
51
- required: true,
52
- source: [],
53
- disabled: false
54
- };
55
- var VALUE = 'Text value';
56
- var PAGE = {
57
- id: 'pageId',
58
- title: 'Page 1',
59
- components: [TEXT],
60
- actions: [_models.PageAction.TYPES.SUBMIT],
61
- formData: {
62
- text: VALUE
63
- }
64
- };
65
- var PAGE_WITH_BUTTON_ACTIONS = {
66
- id: 'pageId',
67
- // eslint-disable-next-line no-template-curly-in-string
68
- title: '${title}',
69
- components: [TEXT_WITH_EXPRESSION, AUTO_WITH_EXPRESSION],
70
- actions: [// eslint-disable-next-line no-template-curly-in-string
71
- {
72
- type: 'submit',
73
- validate: true,
74
- label: 'Next ${wrapper.nextAction}'
75
- }, // eslint-disable-next-line no-template-curly-in-string
76
- {
77
- type: 'navigate',
78
- page: '1',
79
- label: 'Go back ${wrapper.prevAction}'
80
- }],
81
- formData: {
82
- title: 'Order Form',
83
- text1: "Text1 ".concat(VALUE),
84
- text2: "Text2 ".concat(VALUE),
85
- wrapper: {
86
- email: 'test@example.email',
87
- nextAction: 'Payment',
88
- prevAction: 'User Details'
89
- },
90
- currentUser: {
91
- givenName: 'Doe'
92
- }
93
- }
94
- };
95
- var PAGE_WITH_CONDITIONAL_BUTTONS = {
96
- id: 'pageId',
97
- // eslint-disable-next-line no-template-curly-in-string
98
- title: '${title}',
99
- components: [TEXT_WITH_EXPRESSION, AUTO_WITH_EXPRESSION],
100
- actions: [{
101
- type: 'submit',
102
- validate: true,
103
- label: 'Button 1',
104
- show_when: [{
105
- field: 'currentUser.givenName',
106
- op: '!=',
107
- value: 'Doe'
108
- }]
109
- }, {
110
- type: 'submit',
111
- validate: false,
112
- label: 'Button 2',
113
- show_when: [{
114
- field: 'currentUser.givenName',
115
- op: '=',
116
- value: 'Doe'
117
- }]
118
- }],
119
- formData: {
120
- title: 'Order Form',
121
- text1: "Text1 ".concat(VALUE),
122
- text2: "Text2 ".concat(VALUE),
123
- wrapper: {
124
- email: 'test@example.email',
125
- nextAction: 'Payment',
126
- prevAction: 'User Details'
127
- },
128
- currentUser: {
129
- givenName: 'Doe'
130
- }
131
- }
132
- };
133
- var ON_ACTION_CALLS = [];
134
-
135
- var checkInputField = function checkInputField(formGroup, fieldId, lbl, hnt, val) {
136
- expect(formGroup.tagName).toEqual('DIV');
137
- expect(formGroup.classList).toContain('govuk-form-group');
138
- var label = formGroup.childNodes[0];
139
- expect(label.tagName).toEqual('LABEL');
140
- expect(label.classList).toContain('govuk-label');
141
- expect(label.textContent).toEqual(lbl);
142
- expect(label.getAttribute('for')).toEqual(fieldId);
143
- var hint = formGroup.childNodes[1];
144
- expect(hint.tagName).toEqual('SPAN');
145
- expect(hint.classList).toContain('govuk-hint');
146
- expect(hint.textContent).toEqual(hnt);
147
- var input = formGroup.childNodes[2];
148
- expect(input.tagName).toEqual('INPUT');
149
- expect(input.classList).toContain('govuk-input');
150
- expect(input.id).toEqual(fieldId);
151
- expect(input.value).toEqual(val);
152
- return input;
153
- };
154
-
155
- var checkAutoCompleteField = function checkAutoCompleteField(formGroup, fieldId, lbl, hnt, val) {
156
- expect(formGroup.tagName).toEqual('DIV');
157
- expect(formGroup.classList).toContain('govuk-form-group');
158
- var label = formGroup.childNodes[0];
159
- expect(label.tagName).toEqual('LABEL');
160
- expect(label.classList).toContain('govuk-label');
161
- expect(label.textContent).toEqual(lbl);
162
- expect(label.getAttribute('for')).toEqual(fieldId);
163
- var hint = formGroup.childNodes[1];
164
- expect(hint.tagName).toEqual('SPAN');
165
- expect(hint.classList).toContain('govuk-hint');
166
- expect(hint.textContent).toEqual(hnt);
167
- var outerWrapper = formGroup.childNodes[2];
168
- expect(outerWrapper.classList).toContain('hods-autocomplete__outer-wrapper');
169
- var autocomplete = outerWrapper.childNodes[0];
170
- expect(autocomplete.classList).toContain('hods-autocomplete__wrapper');
171
- var input = [].concat(autocomplete.childNodes).filter(function (e) {
172
- return e.tagName === 'INPUT';
173
- })[0];
174
- expect(input.classList).toContain('hods-autocomplete__input');
175
- expect(input.tagName).toEqual('INPUT');
176
- expect(input.id).toEqual(fieldId);
177
- expect(input.value).toEqual(val);
178
- return input;
179
- };
180
-
181
- var checkFormButtonGroup = function checkFormButtonGroup(buttonGroup, labels) {
182
- var _buttonGroup$childNod;
183
-
184
- var buttons = [];
185
- expect(buttonGroup.tagName).toEqual('DIV');
186
- expect(buttonGroup.classList).toContain('hods-button-group');
187
- expect((_buttonGroup$childNod = buttonGroup.childNodes) === null || _buttonGroup$childNod === void 0 ? void 0 : _buttonGroup$childNod.length).toEqual(labels.length);
188
- buttonGroup.childNodes.forEach(function (button, i) {
189
- expect(button.tagName).toEqual('BUTTON');
190
- expect(button.classList).toContain('hods-button');
191
- expect(button.textContent).toEqual(labels[i]);
192
- buttons.push(button);
193
- });
194
- return buttons;
195
- };
196
-
197
- var ON_ACTION = function ON_ACTION(action, patch, onError) {
198
- ON_ACTION_CALLS.push({
199
- action: action,
200
- patch: patch,
201
- onError: onError
202
- });
203
- };
204
-
205
- beforeEach(function () {
206
- PAGE.formData = {
207
- text: VALUE
208
- };
209
- ON_ACTION_CALLS.length = 0;
210
- });
211
- it('should render a submit page correctly', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
212
- var _renderWithValidation, container, page, heading;
213
-
214
- return regeneratorRuntime.wrap(function _callee$(_context) {
215
- while (1) {
216
- switch (_context.prev = _context.next) {
217
- case 0:
218
- _renderWithValidation = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormPage.default, {
219
- page: PAGE,
220
- onAction: ON_ACTION
221
- })), container = _renderWithValidation.container;
222
- page = container.childNodes[0];
223
- expect(page.tagName).toEqual('DIV');
224
- expect(page.classList).toContain("".concat(_FormPage.DEFAULT_CLASS, "__page"));
225
- heading = page.childNodes[0];
226
- expect(heading.classList).toContain('govuk-heading-l');
227
- expect(heading.textContent).toEqual(PAGE.title);
228
- checkInputField(page.childNodes[1], TEXT.fieldId, "".concat(TEXT.label, " (optional)"), TEXT.hint, VALUE);
229
- checkFormButtonGroup(page.childNodes[2], [_ActionButton.DEFAULT_LABEL]);
230
-
231
- case 9:
232
- case "end":
233
- return _context.stop();
234
- }
235
- }
236
- }, _callee);
237
- })));
238
- it('should render a submit page correctly and submit action button has interpolated label', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
239
- var _renderWithValidation2, container, page, FORM_DATA, heading;
240
-
241
- return regeneratorRuntime.wrap(function _callee2$(_context2) {
242
- while (1) {
243
- switch (_context2.prev = _context2.next) {
244
- case 0:
245
- _renderWithValidation2 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormPage.default, {
246
- page: PAGE_WITH_BUTTON_ACTIONS,
247
- onAction: ON_ACTION
248
- })), container = _renderWithValidation2.container;
249
- page = container.childNodes[0];
250
- FORM_DATA = PAGE_WITH_BUTTON_ACTIONS.formData;
251
- expect(page.tagName).toEqual('DIV');
252
- expect(page.classList).toContain("".concat(_FormPage.DEFAULT_CLASS, "__page"));
253
- heading = page.childNodes[0];
254
- expect(heading.classList).toContain('govuk-heading-l');
255
- expect(heading.textContent).toEqual(FORM_DATA.title);
256
- checkInputField(page.childNodes[1], TEXT_WITH_EXPRESSION.fieldId, 'Email to test@example.email (optional)', 'Text hint Doe', 'Text1 Text value');
257
- checkAutoCompleteField(page.childNodes[2], AUTO_WITH_EXPRESSION.fieldId, "".concat(FORM_DATA.text2, " ").concat(FORM_DATA.currentUser.givenName), FORM_DATA.wrapper.email, "Text2 ".concat(VALUE));
258
- checkFormButtonGroup(page.childNodes[3], ['Next Payment', 'Go back User Details']);
259
-
260
- case 11:
261
- case "end":
262
- return _context2.stop();
263
- }
264
- }
265
- }, _callee2);
266
- })));
267
- it('should handle a page change appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
268
- var _renderWithValidation3, container, page, input, NEW_VALUE, EVENT;
269
-
270
- return regeneratorRuntime.wrap(function _callee3$(_context3) {
271
- while (1) {
272
- switch (_context3.prev = _context3.next) {
273
- case 0:
274
- _renderWithValidation3 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormPage.default, {
275
- page: PAGE,
276
- onAction: ON_ACTION
277
- })), container = _renderWithValidation3.container;
278
- page = container.childNodes[0];
279
- expect(page.tagName).toEqual('DIV'); // Change the input.
280
-
281
- input = page.childNodes[1].childNodes[2];
282
- NEW_VALUE = "".concat(VALUE, ".");
283
- EVENT = {
284
- target: {
285
- name: TEXT.fieldId,
286
- value: NEW_VALUE
287
- }
288
- };
289
-
290
- _react.fireEvent.change(input, EVENT); // And confirm the formData has been changed.
291
-
292
-
293
- expect(PAGE.formData.text).toEqual(NEW_VALUE);
294
-
295
- case 8:
296
- case "end":
297
- return _context3.stop();
298
- }
299
- }
300
- }, _callee3);
301
- })));
302
- it('should handle a page action appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
303
- var _renderWithValidation4, container, page, input, NEW_VALUE, CHANGE_EVENT, button;
304
-
305
- return regeneratorRuntime.wrap(function _callee4$(_context4) {
306
- while (1) {
307
- switch (_context4.prev = _context4.next) {
308
- case 0:
309
- _renderWithValidation4 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormPage.default, {
310
- page: PAGE,
311
- onAction: ON_ACTION
312
- })), container = _renderWithValidation4.container;
313
- page = container.childNodes[0]; // Change the input.
314
-
315
- input = page.childNodes[1].childNodes[2];
316
- NEW_VALUE = "".concat(VALUE, ".");
317
- CHANGE_EVENT = {
318
- target: {
319
- name: TEXT.fieldId,
320
- value: NEW_VALUE
321
- }
322
- };
323
-
324
- _react.fireEvent.change(input, CHANGE_EVENT); // Then click the action button.
325
-
326
-
327
- button = page.childNodes[2].childNodes[0];
328
-
329
- _react.fireEvent.click(button, {}); // And confirm an appropriate action was received.
330
-
331
-
332
- expect(ON_ACTION_CALLS.length).toEqual(1);
333
- expect(PAGE.formData.text).toEqual(NEW_VALUE);
334
- expect(ON_ACTION_CALLS[0].action).toEqual(_models.PageAction.DEFAULTS.submit);
335
- expect(ON_ACTION_CALLS[0].patch).toEqual({
336
- text: NEW_VALUE
337
- });
338
-
339
- case 12:
340
- case "end":
341
- return _context4.stop();
342
- }
343
- }
344
- }, _callee4);
345
- })));
346
- it('should render only the conditionally shown button', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
347
- var _renderWithValidation5, container, page;
348
-
349
- return regeneratorRuntime.wrap(function _callee5$(_context5) {
350
- while (1) {
351
- switch (_context5.prev = _context5.next) {
352
- case 0:
353
- _renderWithValidation5 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormPage.default, {
354
- page: PAGE_WITH_CONDITIONAL_BUTTONS,
355
- onAction: ON_ACTION
356
- })), container = _renderWithValidation5.container;
357
- page = container.childNodes[0];
358
- checkFormButtonGroup(page.childNodes[3], ['Button 2']); // Just the second button shown
359
-
360
- case 3:
361
- case "end":
362
- return _context5.stop();
363
- }
364
- }
365
- }, _callee5);
366
- })));
367
- });
368
- });
@@ -1,183 +0,0 @@
1
- <!-- Global imports -->
2
-
3
- import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
4
- import {
5
- Button,
6
- Details,
7
- Heading,
8
- Link,
9
- Panel,
10
- } from '@ukhomeoffice/cop-react-components';
11
- import { useState } from 'react';
12
- import withMock from 'storybook-addon-mock';
13
-
14
- <!-- Local imports -->
15
- import FormRenderer from './FormRenderer';
16
-
17
- <!-- JSON documents -->
18
- import CIVIL_SERVANT from '../../json/areYouACivilServant.json';
19
- import FIRST_FORM from '../../json/firstForm.json';
20
- import GRADE from '../../json/grade.json';
21
- import TEAMS from '../../json/team.json';
22
- import USER_PROFILE_DATA from '../../json/userProfile.data.json';
23
- import USER_PROFILE from '../../json/userProfile.json';
24
-
25
- <Meta
26
- title='Components/Form renderer'
27
- id='D-FormRenderer'
28
- component={FormRenderer}
29
- decorators={[withMock]}
30
- />
31
-
32
- <Heading size='xl' caption='Components'>
33
- Form renderer
34
- </Heading>
35
-
36
- Renders a form with <Link href="https://ukhomeoffice.github.io/cop-react-components/?path=/docs/d-alert--default-story">COP React components</Link>,
37
- on the basis of a <Link href="/?path=/docs/f-json-form">JSON</Link> that describes which elements are required.
38
-
39
- <Canvas withToolbar>
40
- <Story
41
- name='Default'
42
- parameters={{
43
- mockData: [
44
- {
45
- url: `${USER_PROFILE_DATA.urls.refData}/areYouACivilServant`,
46
- method: 'GET',
47
- status: 200,
48
- response: CIVIL_SERVANT,
49
- },
50
- {
51
- url: `${USER_PROFILE_DATA.urls.refData}/grade`,
52
- method: 'GET',
53
- status: 200,
54
- response: GRADE,
55
- },
56
- {
57
- url: `${USER_PROFILE_DATA.urls.refData}/team`,
58
- method: 'GET',
59
- status: 200,
60
- response: TEAMS,
61
- },
62
- ],
63
- }}
64
- >
65
- {() => {
66
- return <FormRenderer {...USER_PROFILE} data={USER_PROFILE_DATA} />;
67
- }}
68
- </Story>
69
- </Canvas>
70
-
71
- <Details summary='Properties' className='no-indent'>
72
- <ArgsTable of={FormRenderer} />
73
- </Details>
74
-
75
- ## CYA type
76
-
77
- <Canvas>
78
- <Story name='CYA'>
79
- {() => {
80
- const [complete, setComplete] = useState(false);
81
- const [returnLater, setReturnLater] = useState(false);
82
- const reset = () => {
83
- setComplete(false);
84
- setReturnLater(false);
85
- };
86
- return (
87
- <>
88
- {!complete && !returnLater && (
89
- <FormRenderer
90
- {...FIRST_FORM}
91
- data={{}}
92
- hooks={{
93
- onRequest: (req) => {
94
- // Do whatever you need to do to the request in here, such as adding an Authorization header.
95
- console.log('onRequest hook called');
96
- return req;
97
- },
98
- onFormLoad: () => {
99
- console.log('onFormLoad called');
100
- },
101
- onFormComplete: () => {
102
- console.log('onFormComplete called');
103
- setComplete(true);
104
- },
105
- onPageChange: (pageId) => {
106
- console.log('onPageChange called', pageId);
107
- setReturnLater(!!pageId === false);
108
- },
109
- onSubmit: (type, payload, onSuccess, onError) => {
110
- console.log(
111
- 'onSubmit called of type',
112
- type,
113
- 'called, with the payload',
114
- payload
115
- );
116
- onSuccess();
117
- }
118
- }}
119
- />
120
- )}
121
- {complete && (
122
- <div>
123
- <Panel title='Submission successful'>
124
- Your submission was successful.
125
- </Panel>
126
- <Button onClick={() => reset()}>Start again</Button>
127
- </div>
128
- )}
129
- {!complete && returnLater && (
130
- <div>
131
- <Panel title='Saved to return later'>
132
- You clicked on "Save and return later".
133
- </Panel>
134
- <Button onClick={() => reset()}>Start again</Button>
135
- </div>
136
- )}
137
- </>
138
- );
139
- }}
140
- </Story>
141
- </Canvas>
142
-
143
- ## Read-only style
144
-
145
- <Canvas>
146
- <Story
147
- name='Read-only style'
148
- parameters={{
149
- mockData: [
150
- {
151
- url: `${USER_PROFILE_DATA.urls.refData}/areYouACivilServant`,
152
- method: 'GET',
153
- status: 200,
154
- response: CIVIL_SERVANT,
155
- },
156
- {
157
- url: `${USER_PROFILE_DATA.urls.refData}/grade`,
158
- method: 'GET',
159
- status: 200,
160
- response: GRADE,
161
- },
162
- {
163
- url: `${USER_PROFILE_DATA.urls.refData}/team`,
164
- method: 'GET',
165
- status: 200,
166
- response: TEAMS,
167
- },
168
- ],
169
- }}
170
- >
171
- {() => {
172
- return (
173
- <FormRenderer
174
- {...USER_PROFILE}
175
- data={USER_PROFILE_DATA}
176
- summaryListClassModifiers='no-border'
177
- hide_title={true}
178
- noChangeAction={true}
179
- />
180
- );
181
- }}
182
- </Story>
183
- </Canvas>