@ukhomeoffice/cop-react-form-renderer 5.0.0-alpha → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (277) hide show
  1. package/dist/components/CheckYourAnswers/Answer.js +18 -7
  2. package/dist/components/CheckYourAnswers/Answer.test.js +137 -0
  3. package/dist/components/CheckYourAnswers/CheckYourAnswers.js +70 -46
  4. package/dist/components/CheckYourAnswers/CheckYourAnswers.stories.mdx +410 -0
  5. package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +551 -0
  6. package/dist/components/CollectionPage/CollectionPage.js +15 -10
  7. package/dist/components/CollectionPage/CollectionPage.test.js +382 -0
  8. package/dist/components/FormComponent/Collection.js +91 -48
  9. package/dist/components/FormComponent/Collection.scss +2 -1
  10. package/dist/components/FormComponent/Collection.test.js +807 -0
  11. package/dist/components/FormComponent/Container.js +35 -16
  12. package/dist/components/FormComponent/Container.test.js +370 -0
  13. package/dist/components/FormComponent/FormComponent.js +39 -13
  14. package/dist/components/FormComponent/FormComponent.stories.mdx +184 -0
  15. package/dist/components/FormComponent/FormComponent.test.js +226 -0
  16. package/dist/components/FormComponent/helpers/addLabel.js +5 -4
  17. package/dist/components/FormComponent/helpers/getComponentFieldSet.js +16 -0
  18. package/dist/components/FormComponent/helpers/getComponentFieldSet.test.js +29 -0
  19. package/dist/components/FormComponent/helpers/index.js +8 -1
  20. package/dist/components/FormPage/FormPage.js +69 -30
  21. package/dist/components/FormPage/FormPage.stories.mdx +155 -0
  22. package/dist/components/FormPage/FormPage.test.js +330 -0
  23. package/dist/components/FormRenderer/FormRenderer.js +142 -228
  24. package/dist/components/FormRenderer/FormRenderer.stories.mdx +183 -0
  25. package/dist/components/FormRenderer/FormRenderer.test.js +968 -0
  26. package/dist/components/FormRenderer/handlers/index.js +1 -2
  27. package/dist/components/FormRenderer/handlers/navigate.js +3 -1
  28. package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.js +35 -14
  29. package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.test.js +88 -5
  30. package/dist/components/FormRenderer/helpers/getCYA.js +11 -2
  31. package/dist/components/FormRenderer/helpers/getNextPageId.js +13 -7
  32. package/dist/components/FormRenderer/helpers/getRelevantPages.js +10 -2
  33. package/dist/components/FormRenderer/helpers/getRelevantPages.test.js +1 -1
  34. package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +2 -2
  35. package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +6 -2
  36. package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.js +171 -51
  37. package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.test.js +307 -24
  38. package/dist/components/FormRenderer/helpers/index.js +1 -2
  39. package/dist/components/FormRenderer/onCYAAction.js +108 -0
  40. package/dist/components/FormRenderer/onCYAAction.test.js +583 -0
  41. package/dist/components/FormRenderer/onPageAction.js +145 -0
  42. package/dist/components/FormRenderer/onPageAction.test.js +678 -0
  43. package/dist/components/FormRenderer/onTaskAction.js +48 -0
  44. package/dist/components/FormRenderer/onTaskAction.test.js +217 -0
  45. package/dist/components/PageActions/ActionButton.js +0 -3
  46. package/dist/components/PageActions/ActionButton.test.js +93 -0
  47. package/dist/components/PageActions/PageActions.js +2 -2
  48. package/dist/components/PageActions/PageActions.stories.mdx +74 -0
  49. package/dist/components/PageActions/PageActions.test.js +132 -0
  50. package/dist/components/SummaryList/GroupAction.js +2 -2
  51. package/dist/components/SummaryList/GroupAction.test.js +80 -0
  52. package/dist/components/SummaryList/RowAction.js +2 -2
  53. package/dist/components/SummaryList/RowAction.test.js +80 -0
  54. package/dist/components/SummaryList/SummaryList.js +29 -12
  55. package/dist/components/SummaryList/SummaryList.scss +19 -0
  56. package/dist/components/SummaryList/SummaryList.stories.mdx +90 -0
  57. package/dist/components/SummaryList/SummaryList.test.js +400 -0
  58. package/dist/components/SummaryList/SummaryListHeadingRow.js +30 -0
  59. package/dist/components/SummaryList/SummaryListRow.js +5 -2
  60. package/dist/components/SummaryList/helpers/getGroupActionAttributes.js +2 -1
  61. package/dist/components/SummaryList/helpers/getRowActionAttributes.js +2 -1
  62. package/dist/components/TaskList/Task.js +3 -3
  63. package/dist/components/TaskList/Task.test.js +167 -0
  64. package/dist/components/TaskList/TaskList.js +73 -22
  65. package/dist/components/TaskList/TaskList.stories.mdx +164 -0
  66. package/dist/components/TaskList/TaskList.test.js +389 -0
  67. package/dist/components/TaskList/TaskState.js +2 -2
  68. package/dist/components/TaskList/TaskState.test.js +86 -0
  69. package/dist/components/index.js +14 -0
  70. package/dist/context/HooksContext/HooksContext.js +72 -8
  71. package/dist/context/HooksContext/HooksContext.test.js +44 -0
  72. package/dist/context/ValidationContext/ValidationContext.js +38 -28
  73. package/dist/context/ValidationContext/ValidationContext.test.js +84 -0
  74. package/dist/hooks/useAxios.js +10 -12
  75. package/dist/hooks/useGetRequest.js +48 -49
  76. package/dist/hooks/useRefData.js +7 -4
  77. package/dist/index.js +34 -1
  78. package/dist/json/addressDetails.json +149 -0
  79. package/dist/json/areYouACivilServant.json +7 -0
  80. package/dist/json/firstForm.json +94 -0
  81. package/dist/json/grade.json +108 -0
  82. package/dist/json/group.data.json +21 -0
  83. package/dist/json/group.json +402 -0
  84. package/dist/json/groupOfRow.json +137 -0
  85. package/dist/json/groupOfRowData.json +15 -0
  86. package/dist/json/port.json +346 -0
  87. package/dist/json/saveAndContinue.json +98 -0
  88. package/dist/json/sublocation.json +859 -0
  89. package/dist/json/taskList.json +265 -0
  90. package/dist/json/team.json +17351 -0
  91. package/dist/json/terminal.json +81 -0
  92. package/dist/json/userProfile.data.json +21 -0
  93. package/dist/json/userProfile.json +276 -0
  94. package/dist/models/ComponentTypes.js +8 -0
  95. package/dist/models/PageAction.js +4 -1
  96. package/dist/models/TaskStates.js +10 -2
  97. package/dist/models/index.js +16 -1
  98. package/dist/setupTests.js +46 -0
  99. package/dist/utils/CheckYourAnswers/getCYAAction.js +5 -5
  100. package/dist/utils/CheckYourAnswers/getCYAAction.test.js +121 -0
  101. package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.js +6 -2
  102. package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.test.js +71 -0
  103. package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.js +6 -2
  104. package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.test.js +55 -0
  105. package/dist/utils/CheckYourAnswers/getCYARow.js +14 -11
  106. package/dist/utils/CheckYourAnswers/getCYARow.test.js +291 -0
  107. package/dist/utils/CheckYourAnswers/getCYARowForGroup.js +4 -1
  108. package/dist/utils/CheckYourAnswers/getCYARowForGroup.test.js +70 -0
  109. package/dist/utils/CheckYourAnswers/getCYARowsForCollection.js +15 -10
  110. package/dist/utils/CheckYourAnswers/getCYARowsForCollection.test.js +288 -0
  111. package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +94 -36
  112. package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +414 -0
  113. package/dist/utils/CheckYourAnswers/getCYARowsForContainer.js +21 -7
  114. package/dist/utils/CheckYourAnswers/getCYARowsForContainer.test.js +486 -0
  115. package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +11 -3
  116. package/dist/utils/CheckYourAnswers/getCYARowsForPage.test.js +346 -0
  117. package/dist/utils/CheckYourAnswers/showComponentCYA.js +19 -3
  118. package/dist/utils/CheckYourAnswers/showComponentCYA.test.js +143 -0
  119. package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.js +5 -1
  120. package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.test.js +40 -0
  121. package/dist/utils/CollectionPage/getCollectionPageActiveIndex.test.js +53 -0
  122. package/dist/utils/CollectionPage/mergeCollectionPages.js +25 -17
  123. package/dist/utils/CollectionPage/mergeCollectionPages.test.js +130 -0
  124. package/dist/utils/Component/addShowWhen.js +44 -0
  125. package/dist/utils/Component/addShowWhen.test.js +216 -0
  126. package/dist/utils/Component/applyToComponentTree.js +71 -0
  127. package/dist/utils/Component/applyToComponentTree.test.js +127 -0
  128. package/dist/utils/Component/cleanAttributes.js +8 -2
  129. package/dist/utils/Component/cleanAttributes.test.js +68 -0
  130. package/dist/utils/Component/elevateNestedComponents.js +4 -1
  131. package/dist/utils/Component/elevateNestedComponents.test.js +122 -0
  132. package/dist/utils/Component/getComponent.js +80 -11
  133. package/dist/utils/Component/getComponentTests/getComponent.autocomplete.test.js +4 -4
  134. package/dist/utils/Component/getComponentTests/getComponent.calculation.test.js +25 -24
  135. package/dist/utils/Component/getComponentTests/getComponent.checkboxes.test.js +66 -5
  136. package/dist/utils/Component/getComponentTests/getComponent.date.test.js +2 -2
  137. package/dist/utils/Component/getComponentTests/getComponent.details.test.js +9 -7
  138. package/dist/utils/Component/getComponentTests/getComponent.email.test.js +3 -3
  139. package/dist/utils/Component/getComponentTests/getComponent.file.test.js +3 -3
  140. package/dist/utils/Component/getComponentTests/getComponent.list.test.js +44 -0
  141. package/dist/utils/Component/getComponentTests/{getComponent.textarea.test.js → getComponent.multifile.test.js} +29 -21
  142. package/dist/utils/Component/getComponentTests/getComponent.nested.test.js +159 -83
  143. package/dist/utils/Component/getComponentTests/getComponent.paragraph.test.js +43 -0
  144. package/dist/utils/Component/getComponentTests/getComponent.phoneNumber.test.js +3 -3
  145. package/dist/utils/Component/getComponentTests/getComponent.radios.test.js +55 -5
  146. package/dist/utils/Component/getComponentTests/getComponent.select.test.js +3 -9
  147. package/dist/utils/Component/getComponentTests/getComponent.text.test.js +3 -3
  148. package/dist/utils/Component/getComponentTests/getComponent.textArea.test.js +109 -0
  149. package/dist/utils/Component/getComponentTests/getComponent.time.test.js +7 -7
  150. package/dist/utils/Component/getDefaultValue.js +4 -1
  151. package/dist/utils/Component/getDefaultValue.test.js +50 -0
  152. package/dist/utils/Component/index.js +2 -0
  153. package/dist/utils/Component/isEditable.js +2 -2
  154. package/dist/utils/Component/isEditable.test.js +43 -0
  155. package/dist/utils/Component/optionIsSelected.js +22 -0
  156. package/dist/utils/Component/optionIsSelected.test.js +42 -0
  157. package/dist/utils/Component/setupContainerComponentsPath.js +40 -0
  158. package/dist/utils/Component/setupContainerComponentsPath.test.js +78 -0
  159. package/dist/utils/Component/showComponent.test.js +156 -0
  160. package/dist/utils/Component/wrapInFormGroup.js +1 -1
  161. package/dist/utils/Condition/meetsAllConditions.js +1 -1
  162. package/dist/utils/Condition/meetsAllConditions.test.js +61 -0
  163. package/dist/utils/Condition/meetsCondition.js +74 -4
  164. package/dist/utils/Condition/meetsCondition.test.js +763 -0
  165. package/dist/utils/Condition/meetsOneCondition.js +1 -1
  166. package/dist/utils/Condition/meetsOneCondition.test.js +100 -0
  167. package/dist/utils/Condition/setupConditions.js +6 -3
  168. package/dist/utils/Condition/setupConditions.test.js +33 -0
  169. package/dist/utils/Container/getEditableComponents.test.js +135 -0
  170. package/dist/utils/Container/setupNesting.js +21 -2
  171. package/dist/utils/Container/setupNesting.test.js +145 -0
  172. package/dist/utils/Container/showContainer.test.js +178 -0
  173. package/dist/utils/Data/applyFormula.js +20 -11
  174. package/dist/utils/Data/applyFormula.test.js +263 -0
  175. package/dist/utils/Data/getAutocompleteSource.js +6 -2
  176. package/dist/utils/Data/getAutocompleteSource.test.js +352 -0
  177. package/dist/utils/Data/getDataPath.test.js +48 -0
  178. package/dist/utils/Data/getOptions.js +17 -3
  179. package/dist/utils/Data/getOptions.test.js +140 -0
  180. package/dist/utils/Data/getSourceData.js +2 -2
  181. package/dist/utils/Data/getSourceData.test.js +153 -0
  182. package/dist/utils/Data/refDataToOptions.js +4 -1
  183. package/dist/utils/Data/refDataToOptions.test.js +196 -0
  184. package/dist/utils/Data/setDataItem.test.js +110 -0
  185. package/dist/utils/Data/setupFormData.js +39 -16
  186. package/dist/utils/Data/setupFormData.test.js +410 -0
  187. package/dist/utils/Data/setupRefDataUrlForComponent.js +4 -1
  188. package/dist/utils/Data/setupRefDataUrlForComponent.test.js +131 -0
  189. package/dist/utils/FormPage/applyConditionalProperties.js +35 -0
  190. package/dist/utils/FormPage/applyConditionalProperties.test.js +61 -0
  191. package/dist/utils/FormPage/getFormPage.js +5 -2
  192. package/dist/utils/FormPage/getFormPage.test.js +206 -0
  193. package/dist/utils/FormPage/getFormPages.js +4 -1
  194. package/dist/utils/FormPage/getFormPages.test.js +97 -0
  195. package/dist/utils/FormPage/getPageActions.js +8 -4
  196. package/dist/utils/FormPage/getPageActions.test.js +114 -0
  197. package/dist/utils/FormPage/getParagraphFromText.test.js +27 -0
  198. package/dist/utils/FormPage/index.js +2 -0
  199. package/dist/utils/FormPage/showFormPage.js +2 -2
  200. package/dist/utils/FormPage/showFormPage.test.js +180 -0
  201. package/dist/utils/FormPage/showFormPageCYA.js +1 -0
  202. package/dist/utils/FormPage/showFormPageCYA.test.js +28 -0
  203. package/dist/utils/FormPage/useComponent.js +29 -14
  204. package/dist/utils/FormPage/useComponent.test.js +167 -0
  205. package/dist/utils/Format/formatData.test.js +45 -0
  206. package/dist/utils/Format/formatDataForComponent.js +2 -1
  207. package/dist/utils/Format/formatDataForComponent.test.js +142 -0
  208. package/dist/utils/Format/formatDataForForm.js +4 -1
  209. package/dist/utils/Format/formatDataForForm.test.js +81 -0
  210. package/dist/utils/Format/formatDataForPage.test.js +99 -0
  211. package/dist/utils/Hub/getFormHub.test.js +105 -0
  212. package/dist/utils/Meta/documents/getDocuments.test.js +4 -1
  213. package/dist/utils/Meta/documents/index.js +2 -2
  214. package/dist/utils/Meta/documents/setDocumentsForField.js +31 -0
  215. package/dist/utils/Meta/documents/setDocumentsForField.test.js +59 -0
  216. package/dist/utils/Operate/checkValueIsTruthy.test.js +42 -0
  217. package/dist/utils/Operate/getFirstOf.js +31 -0
  218. package/dist/utils/Operate/getFirstOf.test.js +86 -0
  219. package/dist/utils/Operate/getIndexOfMatchingValueIn.test.js +163 -0
  220. package/dist/utils/Operate/persistValueInFormData.js +2 -1
  221. package/dist/utils/Operate/persistValueInFormData.test.js +115 -0
  222. package/dist/utils/Operate/runPageOperations.js +3 -1
  223. package/dist/utils/Operate/runPageOperations.test.js +105 -0
  224. package/dist/utils/Operate/setValueInFormData.test.js +44 -0
  225. package/dist/utils/Operate/shouldRun.js +16 -13
  226. package/dist/utils/Operate/shouldRun.test.js +66 -0
  227. package/dist/utils/Validate/additional/conditionallyRequired.js +24 -0
  228. package/dist/utils/Validate/additional/conditionallyRequired.test.js +73 -0
  229. package/dist/utils/Validate/additional/index.js +13 -4
  230. package/dist/utils/Validate/additional/mustBeAfter.js +8 -6
  231. package/dist/utils/Validate/additional/mustBeAfter.test.js +15 -1
  232. package/dist/utils/Validate/additional/mustBeBefore.js +9 -5
  233. package/dist/utils/Validate/additional/mustBeBefore.test.js +14 -0
  234. package/dist/utils/Validate/additional/mustBeEarlierDateTime.js +1 -1
  235. package/dist/utils/Validate/additional/mustBeEarlierDateTime.test.js +6 -3
  236. package/dist/utils/Validate/additional/mustBeGreaterThan.js +22 -0
  237. package/dist/utils/Validate/additional/mustBeGreaterThan.test.js +56 -0
  238. package/dist/utils/Validate/additional/mustBeInTheFuture.js +1 -1
  239. package/dist/utils/Validate/additional/mustBeInThePast.js +5 -5
  240. package/dist/utils/Validate/additional/mustBeLessThan.js +7 -6
  241. package/dist/utils/Validate/additional/mustBeLessThan.test.js +11 -1
  242. package/dist/utils/Validate/additional/mustBeNumbersOnly.js +9 -5
  243. package/dist/utils/Validate/additional/mustBeNumbersOnly.test.js +10 -2
  244. package/dist/utils/Validate/additional/mustEnterAtLeastOne.js +1 -0
  245. package/dist/utils/Validate/additional/mustEnterAtLeastOne.test.js +4 -1
  246. package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.js +19 -0
  247. package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.test.js +36 -0
  248. package/dist/utils/Validate/additional/mustSelectOnlyOne.js +29 -0
  249. package/dist/utils/Validate/additional/mustSelectOnlyOne.test.js +52 -0
  250. package/dist/utils/Validate/additional/utils.js +18 -18
  251. package/dist/utils/Validate/index.js +6 -0
  252. package/dist/utils/Validate/validateCollection.js +20 -5
  253. package/dist/utils/Validate/validateCollection.test.js +125 -0
  254. package/dist/utils/Validate/validateComponent.js +36 -20
  255. package/dist/utils/Validate/validateComponent.test.js +365 -0
  256. package/dist/utils/Validate/validateContainer.js +9 -3
  257. package/dist/utils/Validate/validateContainer.test.js +75 -0
  258. package/dist/utils/Validate/validateDate.js +4 -3
  259. package/dist/utils/Validate/validateDate.test.js +114 -0
  260. package/dist/utils/Validate/validateEmail.js +14 -1
  261. package/dist/utils/Validate/validateEmail.test.js +74 -0
  262. package/dist/utils/Validate/validateMultifile.js +32 -0
  263. package/dist/utils/Validate/validateMultifile.test.js +47 -0
  264. package/dist/utils/Validate/validatePage.js +12 -6
  265. package/dist/utils/Validate/validatePage.test.js +472 -0
  266. package/dist/utils/Validate/validateRegex.js +2 -5
  267. package/dist/utils/Validate/validateRegex.test.js +42 -0
  268. package/dist/utils/Validate/validateRequired.js +2 -4
  269. package/dist/utils/Validate/validateRequired.test.js +63 -0
  270. package/dist/utils/Validate/validateTextArea.js +37 -0
  271. package/dist/utils/Validate/validateTextArea.test.js +42 -0
  272. package/dist/utils/Validate/validateTime.js +2 -2
  273. package/dist/utils/Validate/validateTime.test.js +59 -0
  274. package/dist/utils/index.js +4 -1
  275. package/package.json +35 -50
  276. package/dist/utils/Meta/documents/setDocumentForField.js +0 -29
  277. package/dist/utils/Meta/documents/setDocumentForField.test.js +0 -49
@@ -6,9 +6,12 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _copReactComponents = require("@ukhomeoffice/cop-react-components");
8
8
  var _models = require("../../models");
9
+ 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); }
9
10
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
10
11
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
11
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
12
+ 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; }
13
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
14
+ 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); }
12
15
  var getCYACollectionChangeAction = function getCYACollectionChangeAction(page, item, _onAction, labelCount, action) {
13
16
  var label = (action === null || action === void 0 ? void 0 : action.label) || _models.CollectionLabels.change;
14
17
  return {
@@ -18,7 +21,8 @@ var getCYACollectionChangeAction = function getCYACollectionChangeAction(page, i
18
21
  type: 'action',
19
22
  action: {
20
23
  onAction: function onAction(row) {
21
- var changeCallback = function changeCallback(data) {
24
+ var changeCallback = function changeCallback(cyaData) {
25
+ var data = cyaData;
22
26
  data["".concat(page.collection.name, "ActiveId")] = item.id;
23
27
  return data;
24
28
  };
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+
3
+ var _getCYACollectionChangeAction = _interopRequireDefault(require("./getCYACollectionChangeAction"));
4
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
5
+ 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); }
6
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
7
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
8
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
9
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
10
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
11
+ describe('utils', function () {
12
+ describe('CheckYourAnswers', function () {
13
+ describe('getCYACollectionChangeAction', function () {
14
+ var PAGE = {
15
+ id: 2,
16
+ collection: {
17
+ name: 'collectionName'
18
+ }
19
+ };
20
+ var ITEM = {
21
+ id: 2
22
+ };
23
+ var TEST_DATA = {
24
+ page: _objectSpread({}, PAGE),
25
+ collectionName: [{
26
+ id: 1
27
+ }, {
28
+ id: 2
29
+ }, {
30
+ id: 3
31
+ }],
32
+ collectionNameActiveId: 3
33
+ };
34
+ it('should change activeId to the selected item and call onAction with the correct page', function () {
35
+ var ON_ACTION = function ON_ACTION(row, callback) {
36
+ expect(row.id).toEqual(2);
37
+ TEST_DATA = callback(TEST_DATA);
38
+ };
39
+ var action = (0, _getCYACollectionChangeAction.default)(PAGE, ITEM, ON_ACTION, 0, {});
40
+ action.action.onAction(PAGE);
41
+ expect(TEST_DATA.collectionNameActiveId).toEqual(2);
42
+ });
43
+ it('should get label to custom value', function () {
44
+ var action = (0, _getCYACollectionChangeAction.default)(PAGE, ITEM, function () {}, 0, {
45
+ label: 'customName'
46
+ });
47
+ expect(action.action.label).toEqual('customName');
48
+ });
49
+ it('should call onAction with a custom page', function () {
50
+ var PAGE_WITH_CUSTOM_DESTINATION = {
51
+ id: 2,
52
+ collection: {
53
+ name: 'collectionName',
54
+ actions: [{
55
+ type: 'change',
56
+ label: 'confirm delete',
57
+ page: 'confirmDelete'
58
+ }]
59
+ }
60
+ };
61
+ var ON_ACTION = function ON_ACTION(page, callback) {
62
+ expect(page.pageId).toEqual('confirmDelete');
63
+ TEST_DATA = callback(TEST_DATA);
64
+ };
65
+ var action = (0, _getCYACollectionChangeAction.default)(PAGE_WITH_CUSTOM_DESTINATION, ITEM, ON_ACTION, 0, PAGE_WITH_CUSTOM_DESTINATION.collection.actions[0]);
66
+ action.action.onAction({});
67
+ expect(TEST_DATA.collectionNameActiveId).toEqual(2);
68
+ });
69
+ });
70
+ });
71
+ });
@@ -6,9 +6,12 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _copReactComponents = require("@ukhomeoffice/cop-react-components");
8
8
  var _models = require("../../models");
9
+ 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); }
9
10
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
10
11
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
11
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
12
+ 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; }
13
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
14
+ 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); }
12
15
  var getCYACollectionDeleteAction = function getCYACollectionDeleteAction(page, item, _onAction, labelCount, action) {
13
16
  var label = (action === null || action === void 0 ? void 0 : action.label) || _models.CollectionLabels.remove;
14
17
  return {
@@ -18,7 +21,8 @@ var getCYACollectionDeleteAction = function getCYACollectionDeleteAction(page, i
18
21
  type: 'action',
19
22
  action: {
20
23
  onAction: function onAction() {
21
- var deleteCallback = function deleteCallback(data) {
24
+ var deleteCallback = function deleteCallback(cyaData) {
25
+ var data = cyaData;
22
26
  data["".concat(page.collection.name)] = data["".concat(page.collection.name)].filter(function (i) {
23
27
  return i.id !== item.id;
24
28
  });
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ var _getCYACollectionDeleteAction = _interopRequireDefault(require("./getCYACollectionDeleteAction"));
4
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
5
+ 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); }
6
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
7
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
8
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
9
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
10
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
11
+ describe('utils', function () {
12
+ describe('CheckYourAnswers', function () {
13
+ describe('getCYACollectionDeleteAction', function () {
14
+ var PAGE = {
15
+ id: 'pageid',
16
+ collection: {
17
+ name: 'collectionName',
18
+ labels: {
19
+ remove: 'customName'
20
+ }
21
+ }
22
+ };
23
+ var ITEM = {
24
+ id: 2
25
+ };
26
+ var TEST_DATA = {
27
+ page: _objectSpread({}, PAGE),
28
+ collectionName: [{
29
+ id: 1
30
+ }, {
31
+ id: 2
32
+ }, {
33
+ id: 3
34
+ }]
35
+ };
36
+ it('should remove selected item from the form data', function () {
37
+ var data = null;
38
+ var ON_ACTION = function ON_ACTION(_, callback) {
39
+ data = callback(TEST_DATA);
40
+ };
41
+ var action = (0, _getCYACollectionDeleteAction.default)(PAGE, ITEM, ON_ACTION, 0, {});
42
+ action.action.onAction();
43
+ expect(data.collectionName.length).toEqual(2);
44
+ expect(data.collectionName[0].id).toEqual(1);
45
+ expect(data.collectionName[1].id).toEqual(3);
46
+ });
47
+ it('should get label to custom value', function () {
48
+ var action = (0, _getCYACollectionDeleteAction.default)(PAGE, ITEM, function () {}, 0, {
49
+ label: "customName"
50
+ });
51
+ expect(action.action.label).toEqual('customName');
52
+ });
53
+ });
54
+ });
55
+ });
@@ -6,12 +6,26 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _copReactComponents = require("@ukhomeoffice/cop-react-components");
8
8
  var _Component = _interopRequireDefault(require("../Component"));
9
+ var _optionIsSelected = _interopRequireDefault(require("../Component/optionIsSelected"));
9
10
  var _getCYAAction = _interopRequireDefault(require("./getCYAAction"));
10
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
12
  // Global imports
12
13
 
13
14
  // Local imports
14
15
 
16
+ var setNestedValue = function setNestedValue(component, page) {
17
+ var _component$data, _component$data$optio;
18
+ (_component$data = component.data) === null || _component$data === void 0 ? void 0 : (_component$data$optio = _component$data.options) === null || _component$data$optio === void 0 ? void 0 : _component$data$optio.forEach(function (option) {
19
+ // check if option is selected and has nested component
20
+ if (Array.isArray(option.nested) && (0, _optionIsSelected.default)(page.formData[component.id], option)) {
21
+ option.nested.forEach(function (paramChild) {
22
+ var child = paramChild;
23
+ child.value = page.formData[child.id];
24
+ });
25
+ }
26
+ });
27
+ };
28
+
15
29
  /**
16
30
  * Gets a row object, configured appropriately for a Check your answers component.
17
31
  *
@@ -39,16 +53,5 @@ var getCYARow = function getCYARow(page, component, onAction) {
39
53
  action: (0, _getCYAAction.default)(component.readonly, page, onAction)
40
54
  };
41
55
  };
42
- var setNestedValue = function setNestedValue(component, page) {
43
- var _component$data, _component$data$optio;
44
- (_component$data = component.data) === null || _component$data === void 0 ? void 0 : (_component$data$optio = _component$data.options) === null || _component$data$optio === void 0 ? void 0 : _component$data$optio.forEach(function (option) {
45
- //check if option is selected and has nested component
46
- if (Array.isArray(option.nested) && page.formData[component.id] === option.value) {
47
- option.nested.forEach(function (child) {
48
- child.value = page.formData[child.id];
49
- });
50
- }
51
- });
52
- };
53
56
  var _default = getCYARow;
54
57
  exports.default = _default;
@@ -0,0 +1,291 @@
1
+ "use strict";
2
+
3
+ var _setupTests = require("../../setupTests");
4
+ var _getCYARow = _interopRequireDefault(require("./getCYARow"));
5
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
+ 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); }
7
+ 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; }
8
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
9
+ 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); }
10
+ describe('utils', function () {
11
+ describe('CheckYourAnswers', function () {
12
+ describe('getCYARow', function () {
13
+ it('should get an appropriate row for a readonly text component', function () {
14
+ var PAGE = {
15
+ id: 'page',
16
+ formData: {
17
+ a: 'Bravo'
18
+ }
19
+ };
20
+ var COMPONENT = {
21
+ type: 'text',
22
+ readonly: true,
23
+ id: 'a',
24
+ fieldId: 'a',
25
+ label: 'Alpha'
26
+ };
27
+ var ON_ACTION = function ON_ACTION() {};
28
+ var ROW = (0, _getCYARow.default)(PAGE, COMPONENT, ON_ACTION);
29
+ (0, _setupTests.expectObjectLike)(ROW, {
30
+ pageId: PAGE.id,
31
+ fieldId: COMPONENT.fieldId,
32
+ key: COMPONENT.label,
33
+ value: 'Bravo',
34
+ component: COMPONENT,
35
+ action: null
36
+ });
37
+ });
38
+ it('should get an appropriate row for a readonly text component with no value', function () {
39
+ var PAGE = {
40
+ id: 'page',
41
+ formData: {}
42
+ };
43
+ var COMPONENT = {
44
+ type: 'text',
45
+ readonly: true,
46
+ id: 'a',
47
+ fieldId: 'a',
48
+ label: 'Alpha'
49
+ };
50
+ var ON_ACTION = function ON_ACTION() {};
51
+ expect((0, _getCYARow.default)(PAGE, COMPONENT, ON_ACTION)).toEqual({
52
+ pageId: PAGE.id,
53
+ id: COMPONENT.id,
54
+ fieldId: COMPONENT.fieldId,
55
+ key: COMPONENT.label,
56
+ value: '',
57
+ component: COMPONENT,
58
+ action: null
59
+ });
60
+ });
61
+ it('should get an appropriate row for a readonly non-editable component', function () {
62
+ var PAGE = {
63
+ id: 'page',
64
+ formData: {
65
+ a: 'BLAH'
66
+ }
67
+ };
68
+ var COMPONENT = {
69
+ type: 'blah',
70
+ readonly: true,
71
+ id: 'a',
72
+ fieldId: 'a',
73
+ label: 'Alpha'
74
+ };
75
+ var ON_ACTION = function ON_ACTION() {};
76
+ expect((0, _getCYARow.default)(PAGE, COMPONENT, ON_ACTION)).toEqual({
77
+ pageId: PAGE.id,
78
+ id: COMPONENT.id,
79
+ fieldId: COMPONENT.fieldId,
80
+ key: COMPONENT.label,
81
+ value: 'BLAH',
82
+ action: null
83
+ });
84
+ });
85
+ it('should use the cya_label where there is no label', function () {
86
+ var PAGE = {
87
+ id: 'page',
88
+ formData: {
89
+ a: 'Bravo'
90
+ }
91
+ };
92
+ var COMPONENT = {
93
+ type: 'text',
94
+ readonly: true,
95
+ id: 'a',
96
+ fieldId: 'a',
97
+ cya_label: 'CYA Alpha'
98
+ };
99
+ var ON_ACTION = function ON_ACTION() {};
100
+ var ROW = (0, _getCYARow.default)(PAGE, COMPONENT, ON_ACTION);
101
+ (0, _setupTests.expectObjectLike)(ROW, {
102
+ pageId: PAGE.id,
103
+ fieldId: COMPONENT.fieldId,
104
+ key: COMPONENT.cya_label,
105
+ action: null,
106
+ component: COMPONENT,
107
+ value: 'Bravo'
108
+ });
109
+ });
110
+ it('should get an appropriate row for an editable text component', function () {
111
+ var PAGE = {
112
+ id: 'page',
113
+ formData: {
114
+ a: 'Bravo'
115
+ },
116
+ cya_link: {}
117
+ };
118
+ var COMPONENT = {
119
+ type: 'text',
120
+ id: 'a',
121
+ fieldId: 'a',
122
+ label: 'Alpha'
123
+ };
124
+ var ON_ACTION = function ON_ACTION() {};
125
+ var ROW = (0, _getCYARow.default)(PAGE, COMPONENT, ON_ACTION);
126
+ (0, _setupTests.expectObjectLike)(ROW, {
127
+ pageId: PAGE.id,
128
+ fieldId: COMPONENT.fieldId,
129
+ key: COMPONENT.label,
130
+ component: COMPONENT,
131
+ value: 'Bravo'
132
+ });
133
+ (0, _setupTests.expectObjectLike)(ROW.action, {
134
+ onAction: ON_ACTION
135
+ });
136
+ });
137
+ it('should update any nested components in radios with corresponding values from the stored formdata', function () {
138
+ var SELECTED_VALUE = 'selectedValue';
139
+ var NESTED_ID = 'nestedId';
140
+ var NESTED_VALUE = 'nestedValue';
141
+ var PAGE = {
142
+ id: 'page',
143
+ formData: _defineProperty({
144
+ a: SELECTED_VALUE
145
+ }, NESTED_ID, NESTED_VALUE),
146
+ cya_link: {}
147
+ };
148
+ var COMPONENT = {
149
+ type: 'radios',
150
+ id: 'a',
151
+ fieldId: 'a',
152
+ data: {
153
+ options: [{
154
+ value: SELECTED_VALUE,
155
+ nested: [{
156
+ id: NESTED_ID
157
+ }]
158
+ }]
159
+ }
160
+ };
161
+ var ROW = (0, _getCYARow.default)(PAGE, COMPONENT, function () {});
162
+ expect(ROW.component.data.options[0].nested[0].value).toEqual(NESTED_VALUE);
163
+ });
164
+ it('should handle an undefined formData when attempting to set nested values in radios', function () {
165
+ var SELECTED_VALUE = 'selectedValue';
166
+ var NESTED_ID = 'nestedId';
167
+ var PAGE = {
168
+ id: 'page',
169
+ cya_link: {}
170
+ };
171
+ var COMPONENT = {
172
+ type: 'radios',
173
+ id: 'a',
174
+ fieldId: 'a',
175
+ data: {
176
+ options: [{
177
+ value: SELECTED_VALUE,
178
+ nested: [{
179
+ id: NESTED_ID
180
+ }]
181
+ }]
182
+ }
183
+ };
184
+ var ROW = (0, _getCYARow.default)(PAGE, COMPONENT, function () {});
185
+ expect(ROW.component.data.options[0].nested[0].value).toBeUndefined();
186
+ });
187
+ it('should update any nested components in checkboxes with corresponding values from the stored formdata', function () {
188
+ var SELECTED_VALUE = 'selectedValue';
189
+ var NESTED_ID = 'nestedId';
190
+ var NESTED_VALUE = 'nestedValue';
191
+ var PAGE = {
192
+ id: 'page',
193
+ formData: _defineProperty({
194
+ a: [SELECTED_VALUE]
195
+ }, NESTED_ID, NESTED_VALUE),
196
+ cya_link: {}
197
+ };
198
+ var COMPONENT = {
199
+ type: 'checkboxes',
200
+ id: 'a',
201
+ fieldId: 'a',
202
+ data: {
203
+ options: [{
204
+ value: SELECTED_VALUE,
205
+ nested: [{
206
+ id: NESTED_ID
207
+ }]
208
+ }]
209
+ }
210
+ };
211
+ var ROW = (0, _getCYARow.default)(PAGE, COMPONENT, function () {});
212
+ expect(ROW.component.data.options[0].nested[0].value).toEqual(NESTED_VALUE);
213
+ });
214
+ it('should handle an undefined formData when attempting to set nested values in checkboxes', function () {
215
+ var SELECTED_VALUE = 'selectedValue';
216
+ var NESTED_ID = 'nestedId';
217
+ var PAGE = {
218
+ id: 'page',
219
+ cya_link: {}
220
+ };
221
+ var COMPONENT = {
222
+ type: 'checkboxes',
223
+ id: 'a',
224
+ fieldId: 'a',
225
+ data: {
226
+ options: [{
227
+ value: SELECTED_VALUE,
228
+ nested: [{
229
+ id: NESTED_ID
230
+ }]
231
+ }]
232
+ }
233
+ };
234
+ var ROW = (0, _getCYARow.default)(PAGE, COMPONENT, function () {});
235
+ expect(ROW.component.data.options[0].nested[0].value).toBeUndefined();
236
+ });
237
+ it('should get an appropriate row for a readonly text component with no value and interpolated label', function () {
238
+ var PAGE = {
239
+ id: 'page',
240
+ formData: {
241
+ text: 'Smith'
242
+ }
243
+ };
244
+ // eslint-disable-next-line no-template-curly-in-string
245
+ var COMPONENT = {
246
+ type: 'text',
247
+ readonly: true,
248
+ id: 'a',
249
+ fieldId: 'a',
250
+ label: 'Alpha ${text}'
251
+ };
252
+ var ON_ACTION = function ON_ACTION() {};
253
+ expect((0, _getCYARow.default)(PAGE, COMPONENT, ON_ACTION)).toEqual({
254
+ pageId: PAGE.id,
255
+ id: COMPONENT.id,
256
+ fieldId: COMPONENT.fieldId,
257
+ key: 'Alpha Smith',
258
+ value: '',
259
+ component: COMPONENT,
260
+ action: null
261
+ });
262
+ });
263
+ it('should use the interolated cya_label where there is no label', function () {
264
+ var PAGE = {
265
+ id: 'page',
266
+ formData: {
267
+ a: 'Bravo'
268
+ }
269
+ };
270
+ // eslint-disable-next-line no-template-curly-in-string
271
+ var COMPONENT = {
272
+ type: 'text',
273
+ readonly: true,
274
+ id: 'a',
275
+ fieldId: 'a',
276
+ cya_label: 'CYA Alpha ${a}'
277
+ };
278
+ var ON_ACTION = function ON_ACTION() {};
279
+ var ROW = (0, _getCYARow.default)(PAGE, COMPONENT, ON_ACTION);
280
+ (0, _setupTests.expectObjectLike)(ROW, {
281
+ pageId: PAGE.id,
282
+ fieldId: COMPONENT.fieldId,
283
+ key: 'CYA Alpha Bravo',
284
+ action: null,
285
+ component: COMPONENT,
286
+ value: 'Bravo'
287
+ });
288
+ });
289
+ });
290
+ });
291
+ });
@@ -8,9 +8,12 @@ var _react = _interopRequireDefault(require("react"));
8
8
  var _FormComponent = _interopRequireDefault(require("../../components/FormComponent"));
9
9
  var _getCYAAction = _interopRequireDefault(require("./getCYAAction"));
10
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ 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); }
11
12
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
12
13
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
13
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
14
+ 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; }
15
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
16
+ 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); }
14
17
  var getRowValue = function getRowValue(row) {
15
18
  if (!row.value) {
16
19
  return null;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ var _setupTests = require("../../setupTests");
4
+ var _getCYARowForGroup = _interopRequireDefault(require("./getCYARowForGroup"));
5
+ var _getCYARow = _interopRequireDefault(require("./getCYARow"));
6
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
7
+ // Local imports
8
+
9
+ describe('utils', function () {
10
+ describe('CheckYourAnswers', function () {
11
+ describe('getCYARowsForGroup', function () {
12
+ it('should check address values block', function () {
13
+ var COMPONENT_ADDRESS = {
14
+ id: 'firstLineOfTheAddress',
15
+ fieldId: 'firstLineOfTheAddress',
16
+ label: 'address',
17
+ type: 'text'
18
+ };
19
+ var COMPONENT_TOWN = {
20
+ id: 'town',
21
+ fieldId: 'town',
22
+ label: 'Town',
23
+ type: 'text'
24
+ };
25
+ var COMPONENT_CITY = {
26
+ id: 'city',
27
+ fieldId: 'city',
28
+ label: 'City',
29
+ type: 'text'
30
+ };
31
+ var COMPONENT_POSTCODE = {
32
+ id: 'postCode',
33
+ fieldId: 'postCode',
34
+ label: 'postCode',
35
+ type: 'text'
36
+ };
37
+ var PAGE = {
38
+ components: [COMPONENT_ADDRESS, COMPONENT_TOWN, COMPONENT_CITY, COMPONENT_POSTCODE],
39
+ id: 'addressDetails',
40
+ fieldId: 'UK address',
41
+ groups: [{
42
+ id: 'address',
43
+ label: 'Address details',
44
+ components: ['firstLineOfTheAddress', 'town', 'city', 'postCode']
45
+ }],
46
+ name: 'address-details',
47
+ title: 'Address details',
48
+ formData: {
49
+ firstLineOfTheAddress: '10 Downing Street',
50
+ town: 'City of Westminster',
51
+ city: 'London',
52
+ postCode: 'SW1A 2AA'
53
+ }
54
+ };
55
+ var ON_ACTION = function ON_ACTION() {};
56
+ var rows = PAGE.components.map(function (component) {
57
+ return (0, _getCYARow.default)(PAGE, component, ON_ACTION);
58
+ });
59
+ var _renderWithValidation = (0, _setupTests.renderWithValidation)((0, _getCYARowForGroup.default)(PAGE, PAGE.groups[0], rows, ON_ACTION).row.value),
60
+ container = _renderWithValidation.container;
61
+ expect(container.childNodes.length).toEqual(4);
62
+ var addressValues = container.childNodes;
63
+ expect(addressValues[0].childNodes[0].textContent).toEqual('10 Downing Street');
64
+ expect(addressValues[1].childNodes[0].textContent).toEqual('City of Westminster');
65
+ expect(addressValues[2].childNodes[0].textContent).toEqual('London');
66
+ expect(addressValues[3].childNodes[0].textContent).toEqual('SW1A 2AA');
67
+ });
68
+ });
69
+ });
70
+ });