@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
@@ -0,0 +1,807 @@
1
+ "use strict";
2
+
3
+ var _react = require("@testing-library/react");
4
+ var _react2 = _interopRequireDefault(require("react"));
5
+ var _testUtils = require("react-dom/test-utils");
6
+ var _models = require("../../models");
7
+ var _setupTests = require("../../setupTests");
8
+ var _utils = _interopRequireDefault(require("../../utils"));
9
+ var _Collection = require("./Collection");
10
+ var _Container = require("./Container");
11
+ var _FormComponent = _interopRequireDefault(require("./FormComponent"));
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+ 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); }
14
+ 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; }
15
+ 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; }
16
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
17
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
18
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
19
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
20
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
21
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
22
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
23
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
24
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
25
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
26
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
27
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
28
+ describe('components.FormComponent.Collection', function () {
29
+ var ID = 'collection';
30
+ var TEXT_ID = 'text';
31
+ var TEXT_VALUE = 'alpha';
32
+ var FORM_DATA = _defineProperty({}, ID, [_defineProperty({
33
+ id: '1'
34
+ }, TEXT_ID, TEXT_VALUE)]);
35
+ var TEXT_COMPONENT = {
36
+ id: TEXT_ID,
37
+ fieldId: TEXT_ID,
38
+ type: _models.ComponentTypes.TEXT,
39
+ label: 'Text component',
40
+ hint: 'Text hint'
41
+ };
42
+ it('should render a collection component appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
43
+ var COLLECTION, _renderWithValidation, container, c, item, _item$childNodes, title, itemContainer, formGroup, label, hint, input;
44
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
45
+ while (1) switch (_context.prev = _context.next) {
46
+ case 0:
47
+ COLLECTION = {
48
+ id: ID,
49
+ fieldId: ID,
50
+ type: _models.ComponentTypes.COLLECTION,
51
+ item: [TEXT_COMPONENT]
52
+ };
53
+ _renderWithValidation = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
54
+ component: COLLECTION,
55
+ value: FORM_DATA[ID],
56
+ formData: FORM_DATA
57
+ })), container = _renderWithValidation.container; // Check the container itself.
58
+ c = container.childNodes[0];
59
+ expect(c.tagName).toEqual('DIV');
60
+ expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
61
+
62
+ // And now check the single text component within it.
63
+ item = c.childNodes[0];
64
+ expect(item.tagName).toEqual('DIV');
65
+ expect(item.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
66
+ _item$childNodes = _slicedToArray(item.childNodes, 2), title = _item$childNodes[0], itemContainer = _item$childNodes[1];
67
+ expect(title.tagName).toEqual('LABEL');
68
+ expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
69
+ expect(itemContainer.tagName).toEqual('DIV');
70
+ expect(itemContainer.classList).toContain(_Container.DEFAULT_CLASS);
71
+ formGroup = itemContainer.childNodes[0];
72
+ expect(formGroup.tagName).toEqual('DIV');
73
+ expect(formGroup.classList).toContain('govuk-form-group');
74
+ label = formGroup.childNodes[0];
75
+ expect(label.tagName).toEqual('LABEL');
76
+ expect(label.classList).toContain('govuk-label');
77
+ expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
78
+ expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
79
+ hint = formGroup.childNodes[1];
80
+ expect(hint.tagName).toEqual('DIV');
81
+ expect(hint.classList).toContain('govuk-hint');
82
+ expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
83
+ input = formGroup.childNodes[2];
84
+ expect(input.tagName).toEqual('INPUT');
85
+ expect(input.classList).toContain('govuk-input');
86
+ expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
87
+ expect(input.value).toEqual(TEXT_VALUE);
88
+ case 30:
89
+ case "end":
90
+ return _context.stop();
91
+ }
92
+ }, _callee);
93
+ })));
94
+ it('should handle a change to a component appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
95
+ var ON_CHANGE_EVENTS, ON_CHANGE, COLLECTION, _renderWithValidation2, container, c, item, formGroup, input, NEW_TEXT_VALUE, EVENT;
96
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
97
+ while (1) switch (_context2.prev = _context2.next) {
98
+ case 0:
99
+ ON_CHANGE_EVENTS = [];
100
+ ON_CHANGE = function ON_CHANGE(e) {
101
+ ON_CHANGE_EVENTS.push(e);
102
+ };
103
+ COLLECTION = {
104
+ id: ID,
105
+ fieldId: ID,
106
+ type: _models.ComponentTypes.COLLECTION,
107
+ item: [{
108
+ id: TEXT_ID,
109
+ fieldId: TEXT_ID,
110
+ type: _models.ComponentTypes.TEXT,
111
+ label: 'Text component'
112
+ }]
113
+ };
114
+ _renderWithValidation2 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
115
+ component: COLLECTION,
116
+ value: FORM_DATA[ID],
117
+ formData: FORM_DATA,
118
+ onChange: ON_CHANGE
119
+ })), container = _renderWithValidation2.container; // Get hold of the text input.
120
+ c = container.childNodes[0];
121
+ item = c.childNodes[0];
122
+ formGroup = item.childNodes[1].childNodes[0];
123
+ input = formGroup.childNodes[2];
124
+ NEW_TEXT_VALUE = 'bravo';
125
+ EVENT = {
126
+ target: {
127
+ name: TEXT_ID,
128
+ value: NEW_TEXT_VALUE
129
+ }
130
+ };
131
+ _react.fireEvent.change(input, EVENT);
132
+
133
+ // And confirm the formData has been changed.
134
+ expect(ON_CHANGE_EVENTS.length).toEqual(1);
135
+ expect(ON_CHANGE_EVENTS[0].target.name).toEqual(ID);
136
+ expect(ON_CHANGE_EVENTS[0].target.value[0][TEXT_ID]).toEqual(NEW_TEXT_VALUE);
137
+ case 14:
138
+ case "end":
139
+ return _context2.stop();
140
+ }
141
+ }, _callee2);
142
+ })));
143
+ it('should handle a null value appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
144
+ var COLLECTION, _renderWithValidation3, container, c, buttonGroup, button;
145
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
146
+ while (1) switch (_context3.prev = _context3.next) {
147
+ case 0:
148
+ COLLECTION = {
149
+ id: ID,
150
+ fieldId: ID,
151
+ type: _models.ComponentTypes.COLLECTION,
152
+ item: [TEXT_COMPONENT]
153
+ };
154
+ _renderWithValidation3 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
155
+ component: COLLECTION
156
+ })), container = _renderWithValidation3.container; // Check the container itself.
157
+ c = container.childNodes[0];
158
+ expect(c.tagName).toEqual('DIV');
159
+ expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
160
+
161
+ // And now make sure it has no children OTHER than the button to add an item.
162
+ expect(c.childNodes.length).toEqual(1);
163
+ buttonGroup = c.childNodes[0];
164
+ expect(buttonGroup.tagName).toEqual('DIV');
165
+ expect(buttonGroup.classList).toContain('hods-button-group');
166
+ button = buttonGroup.childNodes[0];
167
+ expect(button.tagName).toEqual('BUTTON');
168
+ expect(button.classList).toContain('hods-button');
169
+ expect(button.classList).toContain('hods-button--secondary');
170
+ expect(button.textContent).toContain(_models.CollectionLabels.add);
171
+ case 14:
172
+ case "end":
173
+ return _context3.stop();
174
+ }
175
+ }, _callee3);
176
+ })));
177
+ it('should handle a collection label appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
178
+ var LABEL, COLLECTION, _renderWithValidation4, container, c, _c$childNodes, title, buttonGroup, button;
179
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
180
+ while (1) switch (_context4.prev = _context4.next) {
181
+ case 0:
182
+ LABEL = 'Alpha Collection';
183
+ COLLECTION = {
184
+ id: ID,
185
+ fieldId: ID,
186
+ type: _models.ComponentTypes.COLLECTION,
187
+ item: [TEXT_COMPONENT],
188
+ label: LABEL
189
+ };
190
+ _renderWithValidation4 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
191
+ component: COLLECTION
192
+ })), container = _renderWithValidation4.container; // Check the container itself.
193
+ c = container.childNodes[0];
194
+ expect(c.tagName).toEqual('DIV');
195
+ expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
196
+
197
+ // And now make sure it has no children OTHER than the button to add an item.
198
+ expect(c.childNodes.length).toEqual(2);
199
+ _c$childNodes = _slicedToArray(c.childNodes, 2), title = _c$childNodes[0], buttonGroup = _c$childNodes[1];
200
+ expect(title.tagName).toEqual('LABEL');
201
+ expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__title"));
202
+ expect(title.getAttribute('for')).toEqual(ID);
203
+ expect(title.textContent).toContain(LABEL);
204
+ expect(buttonGroup.tagName).toEqual('DIV');
205
+ expect(buttonGroup.classList).toContain('hods-button-group');
206
+ button = buttonGroup.childNodes[0];
207
+ expect(button.tagName).toEqual('BUTTON');
208
+ expect(button.classList).toContain('hods-button');
209
+ expect(button.classList).toContain('hods-button--secondary');
210
+ expect(button.textContent).toContain(_models.CollectionLabels.add);
211
+ case 19:
212
+ case "end":
213
+ return _context4.stop();
214
+ }
215
+ }, _callee4);
216
+ })));
217
+ it('should handle the addition and removal of an item', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
218
+ var COLLECTION, container, c, addButton, item, label, removeButton;
219
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
220
+ while (1) switch (_context6.prev = _context6.next) {
221
+ case 0:
222
+ COLLECTION = {
223
+ id: ID,
224
+ fieldId: ID,
225
+ type: _models.ComponentTypes.COLLECTION,
226
+ item: [TEXT_COMPONENT]
227
+ };
228
+ container = document.createElement('div');
229
+ document.body.appendChild(container);
230
+ _context6.next = 5;
231
+ return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
232
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
233
+ while (1) switch (_context5.prev = _context5.next) {
234
+ case 0:
235
+ (0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
236
+ component: COLLECTION
237
+ }), container);
238
+ case 1:
239
+ case "end":
240
+ return _context5.stop();
241
+ }
242
+ }, _callee5);
243
+ })));
244
+ case 5:
245
+ // Check the container itself.
246
+ c = container.childNodes[0];
247
+ expect(c.tagName).toEqual('DIV');
248
+ expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
249
+
250
+ // And now make sure it has no children OTHER than the button to add an item.
251
+ expect(c.childNodes.length).toEqual(1);
252
+
253
+ // Get hold of that "Add another" button and click it.
254
+ addButton = c.childNodes[0].childNodes[0];
255
+ _react.fireEvent.click(addButton, {});
256
+
257
+ // Make sure an item has been added.
258
+ expect(c.childNodes.length).toEqual(2);
259
+ item = c.childNodes[0];
260
+ label = item.childNodes[0];
261
+ expect(label.textContent).toContain(_utils.default.interpolateString(_models.CollectionLabels.item, {
262
+ index: 1
263
+ }));
264
+
265
+ // Get hold of the newly-add item's "Remove" button.
266
+ removeButton = label.childNodes[1];
267
+ expect(removeButton.tagName).toEqual('BUTTON');
268
+ expect(removeButton.classList).toContain('hods-button--secondary');
269
+ expect(removeButton.textContent).toContain(_models.CollectionLabels.remove);
270
+
271
+ // Click the "Remove" button
272
+ _react.fireEvent.click(removeButton, {});
273
+
274
+ // Make sure the item has been removed.
275
+ expect(c.childNodes.length).toEqual(1);
276
+ expect(c.childNodes[0].classList).toContain('hods-button-group');
277
+ case 22:
278
+ case "end":
279
+ return _context6.stop();
280
+ }
281
+ }, _callee6);
282
+ })));
283
+ it('should handle the alternative styling', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
284
+ var COLLECTION, container, c, addButton, item, label, removeButton;
285
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
286
+ while (1) switch (_context8.prev = _context8.next) {
287
+ case 0:
288
+ COLLECTION = {
289
+ id: ID,
290
+ fieldId: ID,
291
+ type: _models.ComponentTypes.COLLECTION,
292
+ item: [TEXT_COMPONENT],
293
+ removeLocation: 'end'
294
+ };
295
+ container = document.createElement('div');
296
+ document.body.appendChild(container);
297
+ _context8.next = 5;
298
+ return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
299
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
300
+ while (1) switch (_context7.prev = _context7.next) {
301
+ case 0:
302
+ (0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
303
+ component: COLLECTION
304
+ }), container);
305
+ case 1:
306
+ case "end":
307
+ return _context7.stop();
308
+ }
309
+ }, _callee7);
310
+ })));
311
+ case 5:
312
+ // Check the container itself.
313
+ c = container.childNodes[0];
314
+ expect(c.tagName).toEqual('DIV');
315
+ expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
316
+
317
+ // And now make sure it has no children OTHER than the button to add an item.
318
+ expect(c.childNodes.length).toEqual(1);
319
+
320
+ // Get hold of that "Add another" button and click it.
321
+ addButton = c.childNodes[0].childNodes[0];
322
+ _react.fireEvent.click(addButton, {});
323
+
324
+ // Make sure an item has been added.
325
+ expect(c.childNodes.length).toEqual(2);
326
+ item = c.childNodes[0];
327
+ label = item.childNodes[0];
328
+ expect(label.textContent).toContain(_utils.default.interpolateString(_models.CollectionLabels.item, {
329
+ index: 1
330
+ }));
331
+
332
+ // Get hold of the newly-add item's "Remove" button.
333
+ removeButton = item.childNodes[2].childNodes[0];
334
+ expect(removeButton.tagName).toEqual('BUTTON');
335
+ expect(removeButton.classList).toContain('hods-button--secondary');
336
+ expect(removeButton.textContent).toContain(_models.CollectionLabels.remove);
337
+
338
+ // Click the "Remove" button
339
+ _react.fireEvent.click(removeButton, {});
340
+
341
+ // Make sure the item has been removed.
342
+ expect(c.childNodes.length).toEqual(1);
343
+ expect(c.childNodes[0].classList).toContain('hods-button-group');
344
+ case 22:
345
+ case "end":
346
+ return _context8.stop();
347
+ }
348
+ }, _callee8);
349
+ })));
350
+ it('should appropriately make child components of items readonly', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
351
+ var COLLECTION, _renderWithValidation5, container, c, item, _item$childNodes2, title, itemContainer, formGroup, label, hint, input;
352
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
353
+ while (1) switch (_context9.prev = _context9.next) {
354
+ case 0:
355
+ COLLECTION = {
356
+ id: ID,
357
+ fieldId: ID,
358
+ type: _models.ComponentTypes.COLLECTION,
359
+ item: [TEXT_COMPONENT],
360
+ readonly: true
361
+ };
362
+ _renderWithValidation5 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
363
+ component: COLLECTION,
364
+ value: FORM_DATA[ID],
365
+ formData: FORM_DATA
366
+ })), container = _renderWithValidation5.container; // Check the container itself.
367
+ c = container.childNodes[0];
368
+ expect(c.tagName).toEqual('DIV');
369
+ expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
370
+
371
+ // And now check the single text component within it.
372
+ item = c.childNodes[0];
373
+ expect(item.tagName).toEqual('DIV');
374
+ expect(item.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
375
+ _item$childNodes2 = _slicedToArray(item.childNodes, 2), title = _item$childNodes2[0], itemContainer = _item$childNodes2[1];
376
+ expect(title.tagName).toEqual('LABEL');
377
+ expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
378
+ expect(itemContainer.tagName).toEqual('DIV');
379
+ expect(itemContainer.classList).toContain(_Container.DEFAULT_CLASS);
380
+ formGroup = itemContainer.childNodes[0];
381
+ expect(formGroup.tagName).toEqual('DIV');
382
+ expect(formGroup.classList).toContain('govuk-form-group');
383
+ label = formGroup.childNodes[0];
384
+ expect(label.tagName).toEqual('LABEL');
385
+ expect(label.classList).toContain('govuk-label');
386
+ expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
387
+ expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
388
+ hint = formGroup.childNodes[1];
389
+ expect(hint.tagName).toEqual('DIV');
390
+ expect(hint.classList).toContain('govuk-hint');
391
+ expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
392
+ input = formGroup.childNodes[2];
393
+ expect(input.tagName).toEqual('DIV'); // Now readonly, so a DIV.
394
+ expect(input.classList).toContain('hods-readonly'); // Now readonly, so hods-readonly
395
+ expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
396
+ expect(input.textContent).toEqual(TEXT_VALUE);
397
+ case 30:
398
+ case "end":
399
+ return _context9.stop();
400
+ }
401
+ }, _callee9);
402
+ })));
403
+ it('should render a collection component with minimumEntries appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
404
+ var COLLECTION, _renderWithValidation6, container, c, item, _item$childNodes3, title, itemContainer, formGroup, label, hint, input;
405
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
406
+ while (1) switch (_context10.prev = _context10.next) {
407
+ case 0:
408
+ COLLECTION = {
409
+ id: ID,
410
+ fieldId: ID,
411
+ type: _models.ComponentTypes.COLLECTION,
412
+ item: [TEXT_COMPONENT],
413
+ minimumEntries: 1
414
+ };
415
+ _renderWithValidation6 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
416
+ component: COLLECTION,
417
+ value: [],
418
+ formData: {}
419
+ })), container = _renderWithValidation6.container; // Check the container itself.
420
+ c = container.childNodes[0];
421
+ expect(c.tagName).toEqual('DIV');
422
+ expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
423
+
424
+ // And now check the single text component within it.
425
+ item = c.childNodes[0];
426
+ expect(item.tagName).toEqual('DIV');
427
+ expect(item.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
428
+ _item$childNodes3 = _slicedToArray(item.childNodes, 2), title = _item$childNodes3[0], itemContainer = _item$childNodes3[1];
429
+ expect(title.tagName).toEqual('LABEL');
430
+ expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
431
+ expect(itemContainer.tagName).toEqual('DIV');
432
+ expect(itemContainer.classList).toContain(_Container.DEFAULT_CLASS);
433
+ formGroup = itemContainer.childNodes[0];
434
+ expect(formGroup.tagName).toEqual('DIV');
435
+ expect(formGroup.classList).toContain('govuk-form-group');
436
+ label = formGroup.childNodes[0];
437
+ expect(label.tagName).toEqual('LABEL');
438
+ expect(label.classList).toContain('govuk-label');
439
+ expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
440
+ expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
441
+ hint = formGroup.childNodes[1];
442
+ expect(hint.tagName).toEqual('DIV');
443
+ expect(hint.classList).toContain('govuk-hint');
444
+ expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
445
+ input = formGroup.childNodes[2];
446
+ expect(input.tagName).toEqual('INPUT');
447
+ expect(input.classList).toContain('govuk-input');
448
+ expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
449
+ expect(input.value).toEqual('');
450
+ case 30:
451
+ case "end":
452
+ return _context10.stop();
453
+ }
454
+ }, _callee10);
455
+ })));
456
+ it('should render a collection component with only a hint on the first item(s) when restrictHint is truthy', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
457
+ var FORM_DATA_TWO_ITEMS, TEXT_COMPONENT_TWO, COLLECTION, _renderWithValidation7, container, c, item, _item$childNodes4, title, itemContainer, formGroup, label, hint, input, itemTwo, _itemTwo$childNodes, titleTwo, itemContainerTwo, formGroupTwo, labelTwo, hintTwo, inputTwo;
458
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
459
+ while (1) switch (_context11.prev = _context11.next) {
460
+ case 0:
461
+ FORM_DATA_TWO_ITEMS = [{
462
+ id: '1',
463
+ text: 'alpha',
464
+ textTwo: 'charlie'
465
+ }, {
466
+ id: '2',
467
+ text: 'beta',
468
+ textTwo: 'delta'
469
+ }];
470
+ TEXT_COMPONENT_TWO = {
471
+ id: 'textTwo',
472
+ fieldId: 'textTwo',
473
+ type: _models.ComponentTypes.TEXT,
474
+ label: 'Text component two',
475
+ hint: 'Text hint two'
476
+ };
477
+ COLLECTION = {
478
+ id: ID,
479
+ fieldId: ID,
480
+ type: _models.ComponentTypes.COLLECTION,
481
+ item: [TEXT_COMPONENT, TEXT_COMPONENT_TWO]
482
+ };
483
+ _renderWithValidation7 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
484
+ component: _objectSpread(_objectSpread({}, COLLECTION), {}, {
485
+ restrictHint: true
486
+ }),
487
+ value: FORM_DATA_TWO_ITEMS,
488
+ formData: FORM_DATA
489
+ })), container = _renderWithValidation7.container; // Check the container itself.
490
+ c = container.childNodes[0];
491
+ expect(c.tagName).toEqual('DIV');
492
+ expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
493
+
494
+ // And now check the first text component within it.
495
+ item = c.childNodes[0];
496
+ expect(item.tagName).toEqual('DIV');
497
+ expect(item.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
498
+ _item$childNodes4 = _slicedToArray(item.childNodes, 2), title = _item$childNodes4[0], itemContainer = _item$childNodes4[1];
499
+ expect(title.tagName).toEqual('LABEL');
500
+ expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
501
+ expect(itemContainer.tagName).toEqual('DIV');
502
+ expect(itemContainer.classList).toContain(_Container.DEFAULT_CLASS);
503
+
504
+ // First item component 1
505
+ formGroup = itemContainer.childNodes[0];
506
+ expect(formGroup.tagName).toEqual('DIV');
507
+ expect(formGroup.classList).toContain('govuk-form-group');
508
+ label = formGroup.childNodes[0];
509
+ expect(label.tagName).toEqual('LABEL');
510
+ expect(label.classList).toContain('govuk-label');
511
+ expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
512
+ expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
513
+ hint = formGroup.childNodes[1];
514
+ expect(hint.tagName).toEqual('DIV');
515
+ expect(hint.classList).toContain('govuk-hint');
516
+ expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
517
+ input = formGroup.childNodes[2];
518
+ expect(input.tagName).toEqual('INPUT');
519
+ expect(input.classList).toContain('govuk-input');
520
+ expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
521
+ expect(input.value).toEqual(TEXT_VALUE);
522
+
523
+ // First item component 2
524
+ formGroup = itemContainer.childNodes[1];
525
+ expect(formGroup.tagName).toEqual('DIV');
526
+ expect(formGroup.classList).toContain('govuk-form-group');
527
+ label = formGroup.childNodes[0];
528
+ expect(label.tagName).toEqual('LABEL');
529
+ expect(label.classList).toContain('govuk-label');
530
+ expect(label.textContent).toEqual('Text component two (optional)');
531
+ expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].textTwo"));
532
+ hint = formGroup.childNodes[1];
533
+ expect(hint.tagName).toEqual('DIV');
534
+ expect(hint.classList).toContain('govuk-hint');
535
+ expect(hint.textContent).toEqual('Text hint two');
536
+ input = formGroup.childNodes[2];
537
+ expect(input.tagName).toEqual('INPUT');
538
+ expect(input.classList).toContain('govuk-input');
539
+ expect(input.id).toEqual("".concat(ID, "[0].textTwo"));
540
+ expect(input.value).toEqual('charlie');
541
+
542
+ // Check the second item and confirm there is no hint
543
+ itemTwo = c.childNodes[1];
544
+ expect(itemTwo.tagName).toEqual('DIV');
545
+ expect(itemTwo.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
546
+ _itemTwo$childNodes = _slicedToArray(itemTwo.childNodes, 2), titleTwo = _itemTwo$childNodes[0], itemContainerTwo = _itemTwo$childNodes[1];
547
+ expect(titleTwo.tagName).toEqual('LABEL');
548
+ expect(titleTwo.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
549
+ expect(itemContainerTwo.tagName).toEqual('DIV');
550
+ expect(itemContainerTwo.classList).toContain(_Container.DEFAULT_CLASS);
551
+
552
+ // Second item first component
553
+ formGroupTwo = itemContainerTwo.childNodes[0];
554
+ expect(formGroupTwo.tagName).toEqual('DIV');
555
+ expect(formGroupTwo.classList).toContain('govuk-form-group');
556
+ labelTwo = formGroupTwo.childNodes[0];
557
+ expect(labelTwo.tagName).toEqual('LABEL');
558
+ expect(labelTwo.classList).toContain('govuk-label');
559
+ expect(labelTwo.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
560
+ expect(labelTwo.getAttribute('for')).toEqual("".concat(ID, "[1].").concat(TEXT_ID));
561
+ hintTwo = formGroupTwo.childNodes[1];
562
+ expect(hintTwo.tagName).toEqual(undefined);
563
+ inputTwo = formGroupTwo.childNodes[2];
564
+ expect(inputTwo.tagName).toEqual('INPUT');
565
+ expect(inputTwo.classList).toContain('govuk-input');
566
+ expect(inputTwo.id).toEqual("".concat(ID, "[1].").concat(TEXT_ID));
567
+ expect(inputTwo.value).toEqual('beta');
568
+
569
+ // Second item second component
570
+ formGroupTwo = itemContainerTwo.childNodes[1];
571
+ expect(formGroupTwo.tagName).toEqual('DIV');
572
+ expect(formGroupTwo.classList).toContain('govuk-form-group');
573
+ labelTwo = formGroupTwo.childNodes[0];
574
+ expect(labelTwo.tagName).toEqual('LABEL');
575
+ expect(labelTwo.classList).toContain('govuk-label');
576
+ expect(labelTwo.textContent).toEqual('Text component two (optional)');
577
+ expect(labelTwo.getAttribute('for')).toEqual("".concat(ID, "[1].textTwo"));
578
+ hintTwo = formGroupTwo.childNodes[1];
579
+ expect(hintTwo.tagName).toEqual(undefined);
580
+ inputTwo = formGroupTwo.childNodes[2];
581
+ expect(inputTwo.tagName).toEqual('INPUT');
582
+ expect(inputTwo.classList).toContain('govuk-input');
583
+ expect(inputTwo.id).toEqual("".concat(ID, "[1].textTwo"));
584
+ expect(inputTwo.value).toEqual('delta');
585
+ case 87:
586
+ case "end":
587
+ return _context11.stop();
588
+ }
589
+ }, _callee11);
590
+ })));
591
+ it('should render a unique label for the first item(s) when firstOnlyLabel is defined', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
592
+ var UNIQUE_FIRST_LABEL_ONE, UNIQUE_FIRST_LABEL_TWO, FORM_DATA_TWO_ITEMS, TEXT_COMPONENT_TWO, COLLECTION, _renderWithValidation8, container, c, item, _item$childNodes5, title, itemContainer, formGroup, label, hint, input, itemTwo, _itemTwo$childNodes2, titleTwo, itemContainerTwo, formGroupTwo, labelTwo, hintTwo, inputTwo;
593
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
594
+ while (1) switch (_context12.prev = _context12.next) {
595
+ case 0:
596
+ UNIQUE_FIRST_LABEL_ONE = 'justForTextOne';
597
+ UNIQUE_FIRST_LABEL_TWO = 'justForTextTwo';
598
+ FORM_DATA_TWO_ITEMS = [{
599
+ id: '1',
600
+ text: 'alpha',
601
+ textTwo: 'charlie'
602
+ }, {
603
+ id: '2',
604
+ text: 'beta',
605
+ textTwo: 'delta'
606
+ }];
607
+ TEXT_COMPONENT_TWO = {
608
+ id: 'textTwo',
609
+ fieldId: 'textTwo',
610
+ type: _models.ComponentTypes.TEXT,
611
+ label: 'Text component two',
612
+ hint: 'Text hint two',
613
+ firstOnlyLabel: UNIQUE_FIRST_LABEL_TWO
614
+ };
615
+ COLLECTION = {
616
+ id: ID,
617
+ fieldId: ID,
618
+ type: _models.ComponentTypes.COLLECTION,
619
+ item: [_objectSpread(_objectSpread({}, TEXT_COMPONENT), {}, {
620
+ firstOnlyLabel: UNIQUE_FIRST_LABEL_ONE
621
+ }), TEXT_COMPONENT_TWO]
622
+ };
623
+ _renderWithValidation8 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
624
+ component: _objectSpread(_objectSpread({}, COLLECTION), {}, {
625
+ restrictHint: true
626
+ }),
627
+ value: FORM_DATA_TWO_ITEMS,
628
+ formData: FORM_DATA
629
+ })), container = _renderWithValidation8.container; // Check the container itself.
630
+ c = container.childNodes[0];
631
+ expect(c.tagName).toEqual('DIV');
632
+ expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
633
+
634
+ // And now check the first text component within it.
635
+ item = c.childNodes[0];
636
+ expect(item.tagName).toEqual('DIV');
637
+ expect(item.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
638
+ _item$childNodes5 = _slicedToArray(item.childNodes, 2), title = _item$childNodes5[0], itemContainer = _item$childNodes5[1];
639
+ expect(title.tagName).toEqual('LABEL');
640
+ expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
641
+ expect(itemContainer.tagName).toEqual('DIV');
642
+ expect(itemContainer.classList).toContain(_Container.DEFAULT_CLASS);
643
+
644
+ // First item component 1
645
+ formGroup = itemContainer.childNodes[0];
646
+ expect(formGroup.tagName).toEqual('DIV');
647
+ expect(formGroup.classList).toContain('govuk-form-group');
648
+ label = formGroup.childNodes[0];
649
+ expect(label.tagName).toEqual('LABEL');
650
+ expect(label.classList).toContain('govuk-label');
651
+ expect(label.textContent).toEqual("".concat(UNIQUE_FIRST_LABEL_ONE, " (optional)"));
652
+ expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
653
+ hint = formGroup.childNodes[1];
654
+ expect(hint.tagName).toEqual('DIV');
655
+ expect(hint.classList).toContain('govuk-hint');
656
+ expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
657
+ input = formGroup.childNodes[2];
658
+ expect(input.tagName).toEqual('INPUT');
659
+ expect(input.classList).toContain('govuk-input');
660
+ expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
661
+ expect(input.value).toEqual(TEXT_VALUE);
662
+
663
+ // First item component 2
664
+ formGroup = itemContainer.childNodes[1];
665
+ expect(formGroup.tagName).toEqual('DIV');
666
+ expect(formGroup.classList).toContain('govuk-form-group');
667
+ label = formGroup.childNodes[0];
668
+ expect(label.tagName).toEqual('LABEL');
669
+ expect(label.classList).toContain('govuk-label');
670
+ expect(label.textContent).toEqual("".concat(UNIQUE_FIRST_LABEL_TWO, " (optional)"));
671
+ expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].textTwo"));
672
+ hint = formGroup.childNodes[1];
673
+ expect(hint.tagName).toEqual('DIV');
674
+ expect(hint.classList).toContain('govuk-hint');
675
+ expect(hint.textContent).toEqual('Text hint two');
676
+ input = formGroup.childNodes[2];
677
+ expect(input.tagName).toEqual('INPUT');
678
+ expect(input.classList).toContain('govuk-input');
679
+ expect(input.id).toEqual("".concat(ID, "[0].textTwo"));
680
+ expect(input.value).toEqual('charlie');
681
+
682
+ // Check the second item and confirm there is no hint
683
+ itemTwo = c.childNodes[1];
684
+ expect(itemTwo.tagName).toEqual('DIV');
685
+ expect(itemTwo.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
686
+ _itemTwo$childNodes2 = _slicedToArray(itemTwo.childNodes, 2), titleTwo = _itemTwo$childNodes2[0], itemContainerTwo = _itemTwo$childNodes2[1];
687
+ expect(titleTwo.tagName).toEqual('LABEL');
688
+ expect(titleTwo.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
689
+ expect(itemContainerTwo.tagName).toEqual('DIV');
690
+ expect(itemContainerTwo.classList).toContain(_Container.DEFAULT_CLASS);
691
+
692
+ // Second item first component
693
+ formGroupTwo = itemContainerTwo.childNodes[0];
694
+ expect(formGroupTwo.tagName).toEqual('DIV');
695
+ expect(formGroupTwo.classList).toContain('govuk-form-group');
696
+ labelTwo = formGroupTwo.childNodes[0];
697
+ expect(labelTwo.tagName).toEqual('LABEL');
698
+ expect(labelTwo.classList).toContain('govuk-label');
699
+ expect(labelTwo.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
700
+ expect(labelTwo.getAttribute('for')).toEqual("".concat(ID, "[1].").concat(TEXT_ID));
701
+ hintTwo = formGroupTwo.childNodes[1];
702
+ expect(hintTwo.tagName).toEqual(undefined);
703
+ inputTwo = formGroupTwo.childNodes[2];
704
+ expect(inputTwo.tagName).toEqual('INPUT');
705
+ expect(inputTwo.classList).toContain('govuk-input');
706
+ expect(inputTwo.id).toEqual("".concat(ID, "[1].").concat(TEXT_ID));
707
+ expect(inputTwo.value).toEqual('beta');
708
+
709
+ // Second item second component
710
+ formGroupTwo = itemContainerTwo.childNodes[1];
711
+ expect(formGroupTwo.tagName).toEqual('DIV');
712
+ expect(formGroupTwo.classList).toContain('govuk-form-group');
713
+ labelTwo = formGroupTwo.childNodes[0];
714
+ expect(labelTwo.tagName).toEqual('LABEL');
715
+ expect(labelTwo.classList).toContain('govuk-label');
716
+ expect(labelTwo.textContent).toEqual('Text component two (optional)');
717
+ expect(labelTwo.getAttribute('for')).toEqual("".concat(ID, "[1].textTwo"));
718
+ hintTwo = formGroupTwo.childNodes[1];
719
+ expect(hintTwo.tagName).toEqual(undefined);
720
+ inputTwo = formGroupTwo.childNodes[2];
721
+ expect(inputTwo.tagName).toEqual('INPUT');
722
+ expect(inputTwo.classList).toContain('govuk-input');
723
+ expect(inputTwo.id).toEqual("".concat(ID, "[1].textTwo"));
724
+ expect(inputTwo.value).toEqual('delta');
725
+ case 89:
726
+ case "end":
727
+ return _context12.stop();
728
+ }
729
+ }, _callee12);
730
+ })));
731
+ it('should handle the alternative styling with a background and padding on the subsequent item(s) when subsequentItemStyle is provided', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
732
+ var COLLECTION, container, c, addButton, item, label, secondItem, secondLabel;
733
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
734
+ while (1) switch (_context14.prev = _context14.next) {
735
+ case 0:
736
+ COLLECTION = {
737
+ id: ID,
738
+ fieldId: ID,
739
+ type: _models.ComponentTypes.COLLECTION,
740
+ item: [TEXT_COMPONENT],
741
+ subsequentItemStyle: {
742
+ background: 'white',
743
+ padding: '1px'
744
+ }
745
+ };
746
+ container = document.createElement('div');
747
+ document.body.appendChild(container);
748
+ _context14.next = 5;
749
+ return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
750
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
751
+ while (1) switch (_context13.prev = _context13.next) {
752
+ case 0:
753
+ (0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
754
+ component: COLLECTION
755
+ }), container);
756
+ case 1:
757
+ case "end":
758
+ return _context13.stop();
759
+ }
760
+ }, _callee13);
761
+ })));
762
+ case 5:
763
+ // Check the container itself.
764
+ c = container.childNodes[0];
765
+ expect(c.tagName).toEqual('DIV');
766
+ expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
767
+
768
+ // And now make sure it has no children OTHER than the button to add an item.
769
+ expect(c.childNodes.length).toEqual(1);
770
+
771
+ // Get hold of that "Add another" button and click it.
772
+ addButton = c.childNodes[0].childNodes[0];
773
+ _react.fireEvent.click(addButton, {});
774
+
775
+ // Make sure an item has been added.
776
+ expect(c.childNodes.length).toEqual(2);
777
+ item = c.childNodes[0];
778
+ label = item.childNodes[0];
779
+ expect(label.textContent).toContain(_utils.default.interpolateString(_models.CollectionLabels.item, {
780
+ index: 1
781
+ }));
782
+
783
+ // Check to see if styling has been untouched for the first item
784
+ expect(item.style.background).toEqual('');
785
+ expect(item.style.padding).toEqual('');
786
+
787
+ // Get hold of that "Add another" button and click it.
788
+ _react.fireEvent.click(addButton, {});
789
+
790
+ // Make sure another item has been added.
791
+ expect(c.childNodes.length).toEqual(3);
792
+ secondItem = c.childNodes[1];
793
+ secondLabel = secondItem.childNodes[0];
794
+ expect(secondLabel.textContent).toContain(_utils.default.interpolateString(_models.CollectionLabels.secondItem, {
795
+ index: 2
796
+ }));
797
+
798
+ // Get hold of the second item and check background and padding has been applied.
799
+ expect(secondItem.style.background).toEqual('white');
800
+ expect(secondItem.style.padding).toEqual('1px');
801
+ case 24:
802
+ case "end":
803
+ return _context14.stop();
804
+ }
805
+ }, _callee14);
806
+ })));
807
+ });