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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (307) hide show
  1. package/dist/components/CheckYourAnswers/Answer.js +1 -14
  2. package/dist/components/CheckYourAnswers/CheckYourAnswers.js +19 -57
  3. package/dist/components/CheckYourAnswers/index.js +0 -3
  4. package/dist/components/CollectionPage/CollectionPage.js +8 -38
  5. package/dist/components/CollectionPage/index.js +0 -3
  6. package/dist/components/FormComponent/Collection.js +13 -54
  7. package/dist/components/FormComponent/Container.js +6 -30
  8. package/dist/components/FormComponent/FormComponent.js +14 -57
  9. package/dist/components/FormComponent/helpers/addLabel.js +4 -7
  10. package/dist/components/FormComponent/helpers/getComponentDisabled.js +0 -4
  11. package/dist/components/FormComponent/helpers/getComponentDisabled.test.js +0 -2
  12. package/dist/components/FormComponent/helpers/getComponentError.js +0 -6
  13. package/dist/components/FormComponent/helpers/getComponentError.test.js +0 -2
  14. package/dist/components/FormComponent/helpers/index.js +0 -4
  15. package/dist/components/FormComponent/index.js +0 -3
  16. package/dist/components/FormPage/FormPage.js +14 -45
  17. package/dist/components/FormPage/index.js +0 -3
  18. package/dist/components/FormRenderer/FormRenderer.js +106 -189
  19. package/dist/components/FormRenderer/handlers/cyaAction.js +0 -5
  20. package/dist/components/FormRenderer/handlers/getPageId.js +0 -2
  21. package/dist/components/FormRenderer/handlers/getPageId.test.js +1 -2
  22. package/dist/components/FormRenderer/handlers/handlers.test.js +1 -18
  23. package/dist/components/FormRenderer/handlers/index.js +0 -5
  24. package/dist/components/FormRenderer/handlers/navigate.js +0 -5
  25. package/dist/components/FormRenderer/handlers/submissionError.js +0 -2
  26. package/dist/components/FormRenderer/helpers/canActionProceed.js +0 -3
  27. package/dist/components/FormRenderer/helpers/canActionProceed.test.js +1 -3
  28. package/dist/components/FormRenderer/helpers/canCYASubmit.js +0 -2
  29. package/dist/components/FormRenderer/helpers/canCYASubmit.test.js +1 -5
  30. package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.js +0 -5
  31. package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.test.js +1 -2
  32. package/dist/components/FormRenderer/helpers/getCYA.js +0 -6
  33. package/dist/components/FormRenderer/helpers/getCYA.test.js +1 -3
  34. package/dist/components/FormRenderer/helpers/getFormState.js +0 -5
  35. package/dist/components/FormRenderer/helpers/getFormState.test.js +1 -3
  36. package/dist/components/FormRenderer/helpers/getNextPageId.js +0 -25
  37. package/dist/components/FormRenderer/helpers/getNextPageId.test.js +1 -4
  38. package/dist/components/FormRenderer/helpers/getPage.js +0 -5
  39. package/dist/components/FormRenderer/helpers/getPage.test.js +1 -3
  40. package/dist/components/FormRenderer/helpers/getRelevantPages.js +0 -6
  41. package/dist/components/FormRenderer/helpers/getRelevantPages.test.js +1 -3
  42. package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +0 -10
  43. package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +0 -6
  44. package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.js +6 -20
  45. package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.test.js +3 -8
  46. package/dist/components/FormRenderer/helpers/index.js +1 -11
  47. package/dist/components/FormRenderer/index.js +0 -3
  48. package/dist/components/PageActions/ActionButton.js +2 -17
  49. package/dist/components/PageActions/PageActions.js +3 -10
  50. package/dist/components/PageActions/index.js +0 -3
  51. package/dist/components/SummaryList/GroupAction.js +3 -24
  52. package/dist/components/SummaryList/RowAction.js +3 -23
  53. package/dist/components/SummaryList/SummaryList.js +6 -28
  54. package/dist/components/SummaryList/SummaryListRow.js +4 -8
  55. package/dist/components/SummaryList/SummaryListTitleRow.js +2 -7
  56. package/dist/components/SummaryList/helpers/getGroupActionAttributes.js +0 -3
  57. package/dist/components/SummaryList/helpers/getGroupActionAttributes.test.js +0 -6
  58. package/dist/components/SummaryList/helpers/getRowActionAttributes.js +0 -3
  59. package/dist/components/SummaryList/helpers/getRowActionAttributes.test.js +0 -6
  60. package/dist/components/SummaryList/helpers/index.js +0 -2
  61. package/dist/components/SummaryList/index.js +0 -3
  62. package/dist/components/TaskList/Task.js +7 -29
  63. package/dist/components/TaskList/TaskList.js +12 -33
  64. package/dist/components/TaskList/TaskState.js +2 -10
  65. package/dist/components/TaskList/index.js +0 -3
  66. package/dist/components/index.js +0 -6
  67. package/dist/context/HooksContext/HooksContext.js +14 -34
  68. package/dist/context/HooksContext/index.js +0 -5
  69. package/dist/context/ValidationContext/ValidationContext.js +8 -34
  70. package/dist/context/ValidationContext/index.js +0 -5
  71. package/dist/context/index.js +0 -3
  72. package/dist/hooks/index.js +0 -9
  73. package/dist/hooks/useAxios.js +8 -25
  74. package/dist/hooks/useGetRequest.js +13 -47
  75. package/dist/hooks/useHooks.js +2 -4
  76. package/dist/hooks/useRefData.js +8 -37
  77. package/dist/hooks/useValidation.js +2 -4
  78. package/dist/index.js +0 -6
  79. package/dist/models/PageAction.js +0 -3
  80. package/dist/models/TaskStates.js +0 -3
  81. package/dist/models/index.js +0 -9
  82. package/dist/utils/CheckYourAnswers/getCYAAction.js +1 -9
  83. package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.js +0 -10
  84. package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.js +0 -8
  85. package/dist/utils/CheckYourAnswers/getCYARow.js +1 -10
  86. package/dist/utils/CheckYourAnswers/getCYARowForGroup.js +2 -20
  87. package/dist/utils/CheckYourAnswers/getCYARowsForCollection.js +0 -18
  88. package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +0 -20
  89. package/dist/utils/CheckYourAnswers/getCYARowsForContainer.js +0 -13
  90. package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +2 -22
  91. package/dist/utils/CheckYourAnswers/index.js +1 -3
  92. package/dist/utils/CheckYourAnswers/showComponentCYA.js +2 -11
  93. package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.js +0 -11
  94. package/dist/utils/CollectionPage/getCollectionPageActiveIndex.js +0 -6
  95. package/dist/utils/CollectionPage/index.js +1 -5
  96. package/dist/utils/CollectionPage/mergeCollectionPages.js +1 -12
  97. package/dist/utils/Component/cleanAttributes.js +1 -8
  98. package/dist/utils/Component/elevateNestedComponents.js +0 -3
  99. package/dist/utils/Component/getComponent.js +4 -68
  100. package/dist/utils/Component/getComponentTests/getComponent.autocomplete.test.js +6 -10
  101. package/dist/utils/Component/getComponentTests/getComponent.calculation.test.js +10 -28
  102. package/dist/utils/Component/getComponentTests/getComponent.checkboxes.test.js +6 -33
  103. package/dist/utils/Component/getComponentTests/getComponent.date.test.js +10 -27
  104. package/dist/utils/Component/getComponentTests/getComponent.details.test.js +4 -10
  105. package/dist/utils/Component/getComponentTests/getComponent.email.test.js +4 -21
  106. package/dist/utils/Component/getComponentTests/getComponent.file.test.js +4 -22
  107. package/dist/utils/Component/getComponentTests/getComponent.heading.test.js +3 -7
  108. package/dist/utils/Component/getComponentTests/getComponent.html.test.js +4 -10
  109. package/dist/utils/Component/getComponentTests/getComponent.insetText.test.js +3 -7
  110. package/dist/utils/Component/getComponentTests/getComponent.nested.test.js +6 -15
  111. package/dist/utils/Component/getComponentTests/getComponent.phoneNumber.test.js +4 -21
  112. package/dist/utils/Component/getComponentTests/getComponent.radios.test.js +6 -33
  113. package/dist/utils/Component/getComponentTests/getComponent.select.test.js +4 -21
  114. package/dist/utils/Component/getComponentTests/getComponent.text.test.js +4 -21
  115. package/dist/utils/Component/getComponentTests/getComponent.textarea.test.js +4 -21
  116. package/dist/utils/Component/getComponentTests/getComponent.time.test.js +10 -29
  117. package/dist/utils/Component/getComponentTests/getComponent.unknown.test.js +1 -2
  118. package/dist/utils/Component/getComponentTests/getComponent.warningText.test.js +3 -7
  119. package/dist/utils/Component/getDefaultValue.js +0 -7
  120. package/dist/utils/Component/index.js +0 -9
  121. package/dist/utils/Component/isEditable.js +1 -4
  122. package/dist/utils/Component/showComponent.js +1 -8
  123. package/dist/utils/Component/wrapInFormGroup.js +0 -7
  124. package/dist/utils/Condition/index.js +0 -5
  125. package/dist/utils/Condition/meetsAllConditions.js +0 -9
  126. package/dist/utils/Condition/meetsCondition.js +7 -19
  127. package/dist/utils/Condition/meetsOneCondition.js +1 -9
  128. package/dist/utils/Condition/setupConditions.js +0 -12
  129. package/dist/utils/Container/getEditableComponents.js +0 -7
  130. package/dist/utils/Container/index.js +0 -5
  131. package/dist/utils/Container/setupNesting.js +0 -11
  132. package/dist/utils/Container/showContainer.js +9 -18
  133. package/dist/utils/Data/applyFormula.js +2 -28
  134. package/dist/utils/Data/getAutocompleteSource.js +1 -4
  135. package/dist/utils/Data/getDataPath.js +3 -17
  136. package/dist/utils/Data/getOptions.js +0 -9
  137. package/dist/utils/Data/getSourceData.js +4 -19
  138. package/dist/utils/Data/index.js +1 -11
  139. package/dist/utils/Data/refDataToOptions.js +1 -12
  140. package/dist/utils/Data/setDataItem.js +0 -5
  141. package/dist/utils/Data/setupFormData.js +2 -20
  142. package/dist/utils/Data/setupRefDataUrlForComponent.js +0 -14
  143. package/dist/utils/FormPage/getFormPage.js +0 -15
  144. package/dist/utils/FormPage/getFormPages.js +0 -8
  145. package/dist/utils/FormPage/getPageActions.js +3 -18
  146. package/dist/utils/FormPage/getParagraphFromText.js +0 -3
  147. package/dist/utils/FormPage/index.js +0 -6
  148. package/dist/utils/FormPage/showFormPage.js +9 -18
  149. package/dist/utils/FormPage/showFormPageCYA.js +0 -5
  150. package/dist/utils/FormPage/useComponent.js +3 -18
  151. package/dist/utils/Format/formatData.js +0 -5
  152. package/dist/utils/Format/formatDataForComponent.js +1 -6
  153. package/dist/utils/Format/formatDataForForm.js +0 -8
  154. package/dist/utils/Format/formatDataForPage.js +1 -5
  155. package/dist/utils/Format/index.js +1 -6
  156. package/dist/utils/Hub/getFormHub.js +0 -8
  157. package/dist/utils/Hub/index.js +1 -3
  158. package/dist/utils/Meta/documents/getDocuments.js +1 -4
  159. package/dist/utils/Meta/documents/getDocuments.test.js +0 -9
  160. package/dist/utils/Meta/documents/index.js +1 -5
  161. package/dist/utils/Meta/documents/setDocumentForField.js +0 -11
  162. package/dist/utils/Meta/documents/setDocumentForField.test.js +0 -11
  163. package/dist/utils/Meta/index.js +2 -6
  164. package/dist/utils/Operate/checkValueIsTruthy.js +1 -7
  165. package/dist/utils/Operate/getIndexOfMatchingValueIn.js +7 -21
  166. package/dist/utils/Operate/index.js +0 -3
  167. package/dist/utils/Operate/persistValueInFormData.js +1 -8
  168. package/dist/utils/Operate/runPageOperations.js +3 -18
  169. package/dist/utils/Operate/setValueInFormData.js +2 -7
  170. package/dist/utils/Operate/shouldRun.js +1 -14
  171. package/dist/utils/Validate/additional/index.js +1 -18
  172. package/dist/utils/Validate/additional/index.test.js +0 -6
  173. package/dist/utils/Validate/additional/mustBeAfter.js +3 -8
  174. package/dist/utils/Validate/additional/mustBeAfter.test.js +0 -4
  175. package/dist/utils/Validate/additional/mustBeBefore.js +3 -8
  176. package/dist/utils/Validate/additional/mustBeBefore.test.js +0 -4
  177. package/dist/utils/Validate/additional/mustBeEarlierDateTime.js +5 -16
  178. package/dist/utils/Validate/additional/mustBeEarlierDateTime.test.js +0 -7
  179. package/dist/utils/Validate/additional/mustBeInTheFuture.js +3 -12
  180. package/dist/utils/Validate/additional/mustBeInTheFuture.test.js +0 -3
  181. package/dist/utils/Validate/additional/mustBeInThePast.js +5 -13
  182. package/dist/utils/Validate/additional/mustBeInThePast.test.js +0 -3
  183. package/dist/utils/Validate/additional/mustBeLessThan.js +0 -3
  184. package/dist/utils/Validate/additional/mustBeLessThan.test.js +0 -2
  185. package/dist/utils/Validate/additional/mustBeLongerThan.js +0 -3
  186. package/dist/utils/Validate/additional/mustBeLongerThan.test.js +0 -2
  187. package/dist/utils/Validate/additional/mustBeNumbersOnly.js +0 -4
  188. package/dist/utils/Validate/additional/mustBeNumbersOnly.test.js +0 -2
  189. package/dist/utils/Validate/additional/mustBeShorterThan.js +0 -3
  190. package/dist/utils/Validate/additional/mustBeShorterThan.test.js +0 -2
  191. package/dist/utils/Validate/additional/mustEnterAtLeastOne.js +0 -5
  192. package/dist/utils/Validate/additional/mustEnterAtLeastOne.test.js +0 -4
  193. package/dist/utils/Validate/additional/utils.js +8 -24
  194. package/dist/utils/Validate/index.js +1 -9
  195. package/dist/utils/Validate/validateCollection.js +0 -9
  196. package/dist/utils/Validate/validateComponent.js +2 -35
  197. package/dist/utils/Validate/validateContainer.js +0 -13
  198. package/dist/utils/Validate/validateDate.js +4 -36
  199. package/dist/utils/Validate/validateEmail.js +1 -7
  200. package/dist/utils/Validate/validatePage.js +0 -15
  201. package/dist/utils/Validate/validateRegex.js +0 -10
  202. package/dist/utils/Validate/validateRequired.js +0 -8
  203. package/dist/utils/Validate/validateTime.js +3 -20
  204. package/dist/utils/index.js +0 -19
  205. package/package.json +50 -34
  206. package/dist/components/CheckYourAnswers/Answer.test.js +0 -95
  207. package/dist/components/CheckYourAnswers/CheckYourAnswers.stories.mdx +0 -410
  208. package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +0 -680
  209. package/dist/components/CollectionPage/CollectionPage.test.js +0 -428
  210. package/dist/components/FormComponent/Collection.test.js +0 -381
  211. package/dist/components/FormComponent/Container.test.js +0 -423
  212. package/dist/components/FormComponent/FormComponent.stories.mdx +0 -184
  213. package/dist/components/FormComponent/FormComponent.test.js +0 -264
  214. package/dist/components/FormPage/FormPage.stories.mdx +0 -131
  215. package/dist/components/FormPage/FormPage.test.js +0 -368
  216. package/dist/components/FormRenderer/FormRenderer.stories.mdx +0 -183
  217. package/dist/components/FormRenderer/FormRenderer.test.js +0 -1006
  218. package/dist/components/PageActions/ActionButton.test.js +0 -116
  219. package/dist/components/PageActions/PageActions.stories.mdx +0 -74
  220. package/dist/components/PageActions/PageActions.test.js +0 -157
  221. package/dist/components/SummaryList/GroupAction.test.js +0 -94
  222. package/dist/components/SummaryList/RowAction.test.js +0 -94
  223. package/dist/components/SummaryList/SummaryList.stories.mdx +0 -90
  224. package/dist/components/SummaryList/SummaryList.test.js +0 -361
  225. package/dist/components/TaskList/Task.test.js +0 -194
  226. package/dist/components/TaskList/TaskList.stories.mdx +0 -164
  227. package/dist/components/TaskList/TaskList.test.js +0 -334
  228. package/dist/components/TaskList/TaskState.test.js +0 -104
  229. package/dist/context/HooksContext/HooksContext.test.js +0 -60
  230. package/dist/context/ValidationContext/ValidationContext.test.js +0 -98
  231. package/dist/json/areYouACivilServant.json +0 -7
  232. package/dist/json/firstForm.json +0 -94
  233. package/dist/json/grade.json +0 -108
  234. package/dist/json/group.data.json +0 -21
  235. package/dist/json/group.json +0 -402
  236. package/dist/json/groupOfRow.json +0 -137
  237. package/dist/json/groupOfRowData.json +0 -15
  238. package/dist/json/port.json +0 -346
  239. package/dist/json/saveAndContinue.json +0 -98
  240. package/dist/json/sublocation.json +0 -859
  241. package/dist/json/taskList.json +0 -265
  242. package/dist/json/team.json +0 -17351
  243. package/dist/json/terminal.json +0 -81
  244. package/dist/json/userProfile.data.json +0 -21
  245. package/dist/json/userProfile.json +0 -276
  246. package/dist/setupTests.js +0 -59
  247. package/dist/utils/CheckYourAnswers/getCYAAction.test.js +0 -139
  248. package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.test.js +0 -76
  249. package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.test.js +0 -59
  250. package/dist/utils/CheckYourAnswers/getCYARow.test.js +0 -256
  251. package/dist/utils/CheckYourAnswers/getCYARowForGroup.test.js +0 -77
  252. package/dist/utils/CheckYourAnswers/getCYARowsForCollection.test.js +0 -199
  253. package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +0 -170
  254. package/dist/utils/CheckYourAnswers/getCYARowsForContainer.test.js +0 -323
  255. package/dist/utils/CheckYourAnswers/getCYARowsForPage.test.js +0 -281
  256. package/dist/utils/CheckYourAnswers/showComponentCYA.test.js +0 -64
  257. package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.test.js +0 -41
  258. package/dist/utils/CollectionPage/getCollectionPageActiveIndex.test.js +0 -54
  259. package/dist/utils/CollectionPage/mergeCollectionPages.test.js +0 -131
  260. package/dist/utils/Component/cleanAttributes.test.js +0 -69
  261. package/dist/utils/Component/elevateNestedComponents.test.js +0 -92
  262. package/dist/utils/Component/getDefaultValue.test.js +0 -53
  263. package/dist/utils/Component/isEditable.test.js +0 -42
  264. package/dist/utils/Component/showComponent.test.js +0 -157
  265. package/dist/utils/Condition/meetsAllConditions.test.js +0 -62
  266. package/dist/utils/Condition/meetsCondition.test.js +0 -391
  267. package/dist/utils/Condition/meetsOneCondition.test.js +0 -101
  268. package/dist/utils/Condition/setupConditions.test.js +0 -35
  269. package/dist/utils/Container/getEditableComponents.test.js +0 -146
  270. package/dist/utils/Container/setupNesting.test.js +0 -92
  271. package/dist/utils/Container/showContainer.test.js +0 -179
  272. package/dist/utils/Data/applyFormula.test.js +0 -264
  273. package/dist/utils/Data/getAutocompleteSource.test.js +0 -146
  274. package/dist/utils/Data/getDataPath.test.js +0 -52
  275. package/dist/utils/Data/getOptions.test.js +0 -71
  276. package/dist/utils/Data/getSourceData.test.js +0 -141
  277. package/dist/utils/Data/refDataToOptions.test.js +0 -197
  278. package/dist/utils/Data/setDataItem.test.js +0 -112
  279. package/dist/utils/Data/setupFormData.test.js +0 -276
  280. package/dist/utils/Data/setupRefDataUrlForComponent.test.js +0 -133
  281. package/dist/utils/FormPage/getFormPage.test.js +0 -205
  282. package/dist/utils/FormPage/getFormPages.test.js +0 -98
  283. package/dist/utils/FormPage/getPageActions.test.js +0 -89
  284. package/dist/utils/FormPage/getParagraphFromText.test.js +0 -29
  285. package/dist/utils/FormPage/showFormPage.test.js +0 -182
  286. package/dist/utils/FormPage/showFormPageCYA.test.js +0 -30
  287. package/dist/utils/FormPage/useComponent.test.js +0 -169
  288. package/dist/utils/Format/formatData.test.js +0 -46
  289. package/dist/utils/Format/formatDataForComponent.test.js +0 -161
  290. package/dist/utils/Format/formatDataForForm.test.js +0 -78
  291. package/dist/utils/Format/formatDataForPage.test.js +0 -96
  292. package/dist/utils/Hub/getFormHub.test.js +0 -107
  293. package/dist/utils/Operate/checkValueIsTruthy.test.js +0 -44
  294. package/dist/utils/Operate/getIndexOfMatchingValueIn.test.js +0 -159
  295. package/dist/utils/Operate/persistValueInFormData.test.js +0 -106
  296. package/dist/utils/Operate/runPageOperations.test.js +0 -107
  297. package/dist/utils/Operate/setValueInFormData.test.js +0 -46
  298. package/dist/utils/Operate/shouldRun.test.js +0 -69
  299. package/dist/utils/Validate/validateCollection.test.js +0 -74
  300. package/dist/utils/Validate/validateComponent.test.js +0 -267
  301. package/dist/utils/Validate/validateContainer.test.js +0 -81
  302. package/dist/utils/Validate/validateDate.test.js +0 -118
  303. package/dist/utils/Validate/validateEmail.test.js +0 -57
  304. package/dist/utils/Validate/validatePage.test.js +0 -383
  305. package/dist/utils/Validate/validateRegex.test.js +0 -41
  306. package/dist/utils/Validate/validateRequired.test.js +0 -62
  307. package/dist/utils/Validate/validateTime.test.js +0 -61
@@ -1,391 +0,0 @@
1
- "use strict";
2
-
3
- var _meetsCondition = _interopRequireDefault(require("./meetsCondition"));
4
-
5
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
-
7
- // Local imports
8
- describe('utils.Condition.meetsCondition', function () {
9
- var getCondition = function getCondition(operator, val) {
10
- if (['in', 'nin'].includes(operator)) {
11
- return {
12
- op: operator,
13
- values: val
14
- };
15
- }
16
-
17
- return {
18
- op: operator,
19
- value: val
20
- };
21
- };
22
-
23
- var TEST_VALUES = ['a', 'b', 3, 4, null, undefined, true, false, 0];
24
- describe('equality operators', function () {
25
- ['eq', '='].forEach(function (op) {
26
- describe("operator ".concat(op), function () {
27
- // Should match...
28
- it('should match two nulls', function () {
29
- var VALUE = null;
30
- var CONDITION = getCondition(op, null);
31
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
32
- });
33
- it('should match two undefineds', function () {
34
- var VALUE = undefined;
35
- var CONDITION = getCondition(op, undefined);
36
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
37
- });
38
- it('should match two identical strings', function () {
39
- var VALUE = 'value';
40
- var CONDITION = getCondition(op, 'value');
41
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
42
- });
43
- it('should match two empty strings', function () {
44
- var VALUE = '';
45
- var CONDITION = getCondition(op, '');
46
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
47
- });
48
- it('should match two identical numbers', function () {
49
- var VALUE = 3;
50
- var CONDITION = getCondition(op, 3);
51
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
52
- });
53
- it('should match two zeroes', function () {
54
- var VALUE = 0;
55
- var CONDITION = getCondition(op, 0);
56
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
57
- });
58
- it('should match two boolean trues', function () {
59
- var VALUE = true;
60
- var CONDITION = getCondition(op, true);
61
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
62
- });
63
- it('should match two boolean falses', function () {
64
- var VALUE = false;
65
- var CONDITION = getCondition(op, false);
66
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
67
- }); // Should reject...
68
-
69
- it('should reject a null and undefined', function () {
70
- var VALUE = null;
71
- var CONDITION = getCondition(op, undefined);
72
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
73
- });
74
- it('should reject a null and empty string', function () {
75
- var VALUE = null;
76
- var CONDITION = getCondition(op, '');
77
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
78
- });
79
- it('should reject an undefined and empty string', function () {
80
- var VALUE = undefined;
81
- var CONDITION = getCondition(op, '');
82
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
83
- });
84
- it('should reject a string of just whitespace and empty string', function () {
85
- var VALUE = ' ';
86
- var CONDITION = getCondition(op, '');
87
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
88
- });
89
- it("should reject the string number '3' and the number 3", function () {
90
- var VALUE = '3';
91
- var CONDITION = getCondition(op, 3);
92
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
93
- });
94
- it('should reject a boolean true and the number 1', function () {
95
- var VALUE = true;
96
- var CONDITION = getCondition(op, 1);
97
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
98
- });
99
- it('should reject a boolean false and a zero', function () {
100
- var VALUE = false;
101
- var CONDITION = getCondition(op, 0);
102
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
103
- });
104
- });
105
- });
106
- });
107
- describe('inequality operators', function () {
108
- ['ne', 'neq', '!=', '<>'].forEach(function (op) {
109
- describe("operator ".concat(op), function () {
110
- // Should reject...
111
- it('should reject two nulls', function () {
112
- var VALUE = null;
113
- var CONDITION = getCondition(op, null);
114
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
115
- });
116
- it('should reject two undefineds', function () {
117
- var VALUE = undefined;
118
- var CONDITION = getCondition(op, undefined);
119
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
120
- });
121
- it('should reject two identical strings', function () {
122
- var VALUE = 'value';
123
- var CONDITION = getCondition(op, 'value');
124
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
125
- });
126
- it('should reject two empty strings', function () {
127
- var VALUE = '';
128
- var CONDITION = getCondition(op, '');
129
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
130
- });
131
- it('should reject two identical numbers', function () {
132
- var VALUE = 3;
133
- var CONDITION = getCondition(op, 3);
134
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
135
- });
136
- it('should reject two zeroes', function () {
137
- var VALUE = 0;
138
- var CONDITION = getCondition(op, 0);
139
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
140
- });
141
- it('should reject two boolean trues', function () {
142
- var VALUE = true;
143
- var CONDITION = getCondition(op, true);
144
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
145
- });
146
- it('should reject two boolean falses', function () {
147
- var VALUE = false;
148
- var CONDITION = getCondition(op, false);
149
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
150
- }); // Should match...
151
-
152
- it('should match a null and undefined', function () {
153
- var VALUE = null;
154
- var CONDITION = getCondition(op, undefined);
155
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
156
- });
157
- it('should match a null and empty string', function () {
158
- var VALUE = null;
159
- var CONDITION = getCondition(op, '');
160
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
161
- });
162
- it('should match an undefined and empty string', function () {
163
- var VALUE = undefined;
164
- var CONDITION = getCondition(op, '');
165
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
166
- });
167
- it('should match a string of just whitespace and empty string', function () {
168
- var VALUE = ' ';
169
- var CONDITION = getCondition(op, '');
170
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
171
- });
172
- it("should match the string number '3' and the number 3", function () {
173
- var VALUE = '3';
174
- var CONDITION = getCondition(op, 3);
175
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
176
- });
177
- it('should match a boolean true and the number 1', function () {
178
- var VALUE = true;
179
- var CONDITION = getCondition(op, 1);
180
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
181
- });
182
- it('should match a boolean false and a zero', function () {
183
- var VALUE = false;
184
- var CONDITION = getCondition(op, 0);
185
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
186
- });
187
- });
188
- });
189
- });
190
- describe('operator in', function () {
191
- var op = 'in'; // Should match...
192
-
193
- it('should match a string that is in the values array', function () {
194
- var VALUE = 'alpha';
195
- var CONDITION = getCondition(op, ['alpha', 'bravo', 'charlie']);
196
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
197
- });
198
- it('should match a number that is in the values array', function () {
199
- var VALUE = 4;
200
- var CONDITION = getCondition(op, ['alpha', 'bravo', 'charlie', 4]);
201
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
202
- }); // Should reject...
203
-
204
- it('should reject a string that is missing from the values array', function () {
205
- var VALUE = 'delta';
206
- var CONDITION = getCondition(op, ['alpha', 'bravo', 'charlie']);
207
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
208
- });
209
- it('should reject a number that is missing from the values array', function () {
210
- var VALUE = 4;
211
- var CONDITION = getCondition(op, ['alpha', 'bravo', 'charlie']);
212
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
213
- });
214
- it('should reject everything when the values array is empty', function () {
215
- var CONDITION = getCondition(op, []);
216
- ['a', 'b', 'c', 'd', 'e', 6, 7, 8, 9, 'ten'].forEach(function (value) {
217
- expect((0, _meetsCondition.default)(CONDITION, value)).toBeFalsy();
218
- });
219
- });
220
- it('should reject everything when the values array is null', function () {
221
- var CONDITION = getCondition(op, null);
222
- ['a', 'b', 'c', 'd', 'e', 6, 7, 8, 9, 'ten'].forEach(function (value) {
223
- expect((0, _meetsCondition.default)(CONDITION, value)).toBeFalsy();
224
- });
225
- });
226
- });
227
- describe('operator nin', function () {
228
- var op = 'nin'; // Should reject...
229
-
230
- it('should reject a string that is in the values array', function () {
231
- var VALUE = 'alpha';
232
- var CONDITION = getCondition(op, ['alpha', 'bravo', 'charlie']);
233
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
234
- });
235
- it('should reject a number that is in the values array', function () {
236
- var VALUE = 4;
237
- var CONDITION = getCondition(op, ['alpha', 'bravo', 'charlie', 4]);
238
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
239
- }); // Should match...
240
-
241
- it('should match a string that is missing from the values array', function () {
242
- var VALUE = 'delta';
243
- var CONDITION = getCondition(op, ['alpha', 'bravo', 'charlie']);
244
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
245
- });
246
- it('should match a number that is missing from the values array', function () {
247
- var VALUE = 4;
248
- var CONDITION = getCondition(op, ['alpha', 'bravo', 'charlie']);
249
- expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
250
- });
251
- it('should match anything when the values array is empty', function () {
252
- var CONDITION = getCondition(op, []);
253
- TEST_VALUES.forEach(function (value) {
254
- expect((0, _meetsCondition.default)(CONDITION, value)).toBeTruthy();
255
- });
256
- });
257
- it('should match anything when the values array is null', function () {
258
- var CONDITION = getCondition(op, null);
259
- TEST_VALUES.forEach(function (value) {
260
- expect((0, _meetsCondition.default)(CONDITION, value)).toBeTruthy();
261
- });
262
- });
263
- });
264
- describe('operator contains', function () {
265
- var op = 'contains'; // Should match...
266
-
267
- it('should match a string that is in the field array', function () {
268
- var FIELD = ['alpha', 'bravo', 'charlie'];
269
- var VALUE = 'alpha';
270
- var CONDITION = getCondition(op, VALUE);
271
- expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeTruthy();
272
- });
273
- it('should match a sub-string that is in the field array', function () {
274
- var FIELD = ['alpha', 'bravo', 'charlie'];
275
- var VALUE = 'alp';
276
- var CONDITION = getCondition(op, VALUE);
277
- expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeTruthy();
278
- });
279
- it('should match a number that is in the field array', function () {
280
- var FIELD = [1, 2, 3];
281
- var VALUE = 1;
282
- var CONDITION = getCondition(op, VALUE);
283
- expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeTruthy();
284
- });
285
- it('should match a sub-string that is in the field string', function () {
286
- var FIELD = 'alphabravocharlie';
287
- var VALUE = 'alpha';
288
- var CONDITION = getCondition(op, VALUE);
289
- expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeTruthy();
290
- });
291
- it('should match a string that is in the field array regardless of case', function () {
292
- var FIELD = ['Alpha', 'bravo', 'charlie'];
293
- var VALUE = 'alpha';
294
- var CONDITION = getCondition(op, VALUE);
295
- expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeTruthy();
296
- }); // Should reject...
297
-
298
- it('should reject a string that is missing from the field array', function () {
299
- var FIELD = ['alpha', 'bravo', 'charlie'];
300
- var VALUE = 'delta';
301
- var CONDITION = getCondition(op, VALUE);
302
- expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeFalsy();
303
- });
304
- it('should reject a number that is missing from the field array', function () {
305
- var FIELD = [1, 2, 3];
306
- var VALUE = 4;
307
- var CONDITION = getCondition(op, VALUE);
308
- expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeFalsy();
309
- });
310
- it('should reject a substring that is missing from the field string', function () {
311
- var FIELD = 'alphabravocharlie';
312
- var VALUE = 'delta';
313
- var CONDITION = getCondition(op, VALUE);
314
- expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeFalsy();
315
- });
316
- it('should reject any value when the field is an empty Array', function () {
317
- var FIELD = [];
318
- var VALUE = 'alpha';
319
- var CONDITION = getCondition(op, VALUE);
320
- expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeFalsy();
321
- });
322
- it('should reject any value when the field is an empty string', function () {
323
- var FIELD = '';
324
- var VALUE = 'alpha';
325
- var CONDITION = getCondition(op, VALUE);
326
- expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeFalsy();
327
- });
328
- it('should reject any field when the value is null', function () {
329
- var FIELD = ['alpha', 'bravo', 'charlie'];
330
- var VALUE = null;
331
- var CONDITION = getCondition(op, VALUE);
332
- expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeFalsy();
333
- });
334
- it('should reject any field when the value is undefined', function () {
335
- var FIELD = ['alpha', 'bravo', 'charlie'];
336
- var VALUE = undefined;
337
- var CONDITION = getCondition(op, VALUE);
338
- expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeFalsy();
339
- });
340
- it('should reject any value when the field is null', function () {
341
- var FIELD = null;
342
- var VALUE = 'alpha';
343
- var CONDITION = getCondition(op, VALUE);
344
- expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeFalsy();
345
- });
346
- it('should reject any value when the field is undefined', function () {
347
- var FIELD = undefined;
348
- var VALUE = 'alpha';
349
- var CONDITION = getCondition(op, VALUE);
350
- expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeFalsy();
351
- });
352
- });
353
- describe('unknown operator', function () {
354
- var op = 'definitely_not_a_real_operator';
355
- it('should reject anything regardless of the value', function () {
356
- var CONDITION = getCondition(op, 'a');
357
- TEST_VALUES.forEach(function (value) {
358
- expect((0, _meetsCondition.default)(CONDITION, value)).toBeFalsy();
359
- });
360
- });
361
- it('should accept anything even with a null value', function () {
362
- var CONDITION = getCondition(op, null);
363
- TEST_VALUES.forEach(function (value) {
364
- expect((0, _meetsCondition.default)(CONDITION, value)).toBeFalsy();
365
- });
366
- });
367
- it('should accept anything even with a undefined value', function () {
368
- var CONDITION = getCondition(op, null);
369
- TEST_VALUES.forEach(function (value) {
370
- expect((0, _meetsCondition.default)(CONDITION, value)).toBeFalsy();
371
- });
372
- });
373
- });
374
- describe('invalid condition', function () {
375
- it('should accept anything when the condition is null', function () {
376
- TEST_VALUES.forEach(function (value) {
377
- expect((0, _meetsCondition.default)(null, value)).toBeTruthy();
378
- });
379
- });
380
- it('should accept anything when the condition is undefined', function () {
381
- TEST_VALUES.forEach(function (value) {
382
- expect((0, _meetsCondition.default)(undefined, value)).toBeTruthy();
383
- });
384
- });
385
- it('should accept anything when the condition is not an object', function () {
386
- TEST_VALUES.forEach(function (value) {
387
- expect((0, _meetsCondition.default)('condition', value)).toBeTruthy();
388
- });
389
- });
390
- });
391
- });
@@ -1,101 +0,0 @@
1
- "use strict";
2
-
3
- var _meetsOneCondition = _interopRequireDefault(require("./meetsOneCondition"));
4
-
5
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
-
7
- // Local imports
8
- describe('utils.Condition.meetsOneCondition', function () {
9
- var DATA = {
10
- alpha: 'bravo',
11
- charlie: 'delta'
12
- };
13
- it('should evaluate to true when conditions are null', function () {
14
- expect((0, _meetsOneCondition.default)(null, DATA)).toBeTruthy();
15
- });
16
- it('should evaluate to true when conditions are undefined', function () {
17
- expect((0, _meetsOneCondition.default)(undefined, DATA)).toBeTruthy();
18
- });
19
- it('should evaluate to true when conditions is an empty array', function () {
20
- var CONDITION = {
21
- "type": "or",
22
- "conditions": []
23
- };
24
- expect((0, _meetsOneCondition.default)(CONDITION, DATA)).toBeTruthy();
25
- });
26
- it('should evaluate to true when one condition is provided and one condition is met', function () {
27
- var CONDITION = {
28
- "type": "or",
29
- "conditions": [{
30
- field: 'alpha',
31
- op: 'eq',
32
- value: 'bravo'
33
- }]
34
- };
35
- expect((0, _meetsOneCondition.default)(CONDITION, DATA)).toBeTruthy();
36
- });
37
- it('should evaluate to true when two conditions are provided and one condition is met', function () {
38
- var CONDITION = {
39
- "type": "or",
40
- "conditions": [{
41
- field: 'alpha',
42
- op: 'eq',
43
- value: 'bravo'
44
- }, {
45
- field: 'alpha',
46
- op: 'eq',
47
- value: "charlie"
48
- }]
49
- };
50
- expect((0, _meetsOneCondition.default)(CONDITION, DATA)).toBeTruthy();
51
- });
52
- it('should evaluate to true when three conditions are provided and two conditions are met', function () {
53
- var CONDITION = {
54
- "type": "or",
55
- "conditions": [{
56
- field: 'alpha',
57
- op: 'eq',
58
- value: 'bravo'
59
- }, {
60
- field: 'charlie',
61
- op: 'eq',
62
- value: 'delta'
63
- }, {
64
- field: 'alpha',
65
- op: 'eq',
66
- value: "charlie"
67
- }]
68
- };
69
- expect((0, _meetsOneCondition.default)(CONDITION, DATA)).toBeTruthy();
70
- });
71
- it('should evaluate to true when all conditions are met', function () {
72
- var CONDITION = {
73
- "type": "or",
74
- "conditions": [{
75
- field: 'alpha',
76
- op: 'eq',
77
- value: 'bravo'
78
- }, {
79
- field: 'charlie',
80
- op: 'eq',
81
- value: 'delta'
82
- }]
83
- };
84
- expect((0, _meetsOneCondition.default)(CONDITION, DATA)).toBeTruthy();
85
- });
86
- it('should evaluate to false when no conditions are met', function () {
87
- var CONDITION = {
88
- "type": "or",
89
- "conditions": [{
90
- field: 'alpha',
91
- op: 'eq',
92
- value: 'delta'
93
- }, {
94
- field: 'charlie',
95
- op: 'eq',
96
- value: 'bravo'
97
- }]
98
- };
99
- expect((0, _meetsOneCondition.default)(CONDITION, DATA)).toBeTruthy();
100
- });
101
- });
@@ -1,35 +0,0 @@
1
- "use strict";
2
-
3
- var _setupConditions = _interopRequireDefault(require("./setupConditions"));
4
-
5
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
-
7
- describe('utils.Condition.setupConditions', function () {
8
- it('should return an array of conditions directly', function () {
9
- var OPTIONS = [{
10
- field: 'alpha',
11
- op: '=',
12
- value: 'ALPHA'
13
- }];
14
- expect((0, _setupConditions.default)(OPTIONS)).toEqual(OPTIONS);
15
- });
16
- it('should return a condition directly', function () {
17
- var OPTIONS = {
18
- field: 'alpha',
19
- op: '=',
20
- value: 'ALPHA'
21
- };
22
- expect((0, _setupConditions.default)(OPTIONS)).toEqual(OPTIONS);
23
- });
24
- it('should return the options on a component with untouched absolute path fields', function () {
25
- var OPTIONS = {
26
- id: 'field',
27
- show_when: {
28
- field: 'alpha',
29
- op: '=',
30
- value: 'ALPHA'
31
- }
32
- };
33
- expect((0, _setupConditions.default)(OPTIONS)).toEqual([OPTIONS.show_when]);
34
- });
35
- });
@@ -1,146 +0,0 @@
1
- "use strict";
2
-
3
- var _models = require("../../models");
4
-
5
- var _isEditable = require("../Component/isEditable");
6
-
7
- var _getEditableComponents = _interopRequireDefault(require("./getEditableComponents"));
8
-
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
-
11
- // Local imports
12
- describe('utils.Container.getEditableComponents', function () {
13
- var HTML = {
14
- type: 'html',
15
- tagName: 'p',
16
- content: 'Alpha'
17
- };
18
- var INSET_TEXT = {
19
- type: 'inset-text',
20
- content: 'Bravo'
21
- };
22
- var HEADING = {
23
- type: 'heading',
24
- size: 'm',
25
- content: 'Charlie'
26
- };
27
- it('should return an empty array for a null container', function () {
28
- expect((0, _getEditableComponents.default)(null)).toEqual([]);
29
- });
30
- it('should return an empty array for a container with no components', function () {
31
- expect((0, _getEditableComponents.default)({
32
- components: []
33
- })).toEqual([]);
34
- });
35
- it('should return an empty array for a container with only non-editable components', function () {
36
- var COMPONENTS = [HTML, INSET_TEXT, HEADING];
37
- expect((0, _getEditableComponents.default)({
38
- components: COMPONENTS
39
- })).toEqual([]);
40
- });
41
- it('should return an empty array for a container that contains a container with only non-editable components', function () {
42
- var COMPONENTS = [HTML, INSET_TEXT, HEADING];
43
- var INNER_CONTAINER = {
44
- type: _models.ComponentTypes.CONTAINER,
45
- components: COMPONENTS
46
- };
47
- expect((0, _getEditableComponents.default)({
48
- components: [INNER_CONTAINER]
49
- })).toEqual([]);
50
- });
51
-
52
- _isEditable.EDITABLE_TYPES.forEach(function (type) {
53
- it("should return just the \"".concat(type, "\" component if it exists in the components, but no non-editable ones"), function () {
54
- var EDITABLE = {
55
- type: type
56
- };
57
- var COMPONENTS = [HTML, EDITABLE, INSET_TEXT, HEADING];
58
- expect((0, _getEditableComponents.default)({
59
- components: COMPONENTS
60
- })).toEqual([EDITABLE]);
61
- });
62
- it("should return just the \"".concat(type, "\" component if it exists inside an inner container's components, but no non-editable ones"), function () {
63
- var EDITABLE = {
64
- type: type
65
- };
66
- var COMPONENTS = [HTML, EDITABLE, INSET_TEXT, HEADING];
67
- var INNER_CONTAINER = {
68
- type: _models.ComponentTypes.CONTAINER,
69
- components: COMPONENTS
70
- };
71
- expect((0, _getEditableComponents.default)({
72
- components: [INNER_CONTAINER]
73
- })).toEqual([EDITABLE]);
74
- });
75
- it("should return just all \"".concat(type, "\" components that exists at any nested level within the container, but no non-editable ones"), function () {
76
- var EDITABLE = {
77
- type: type
78
- };
79
- var COMPONENTS = [HTML, EDITABLE, INSET_TEXT, HEADING];
80
- var INNER_INNER_CONTAINER = {
81
- type: _models.ComponentTypes.CONTAINER,
82
- components: COMPONENTS
83
- };
84
- var INNER_CONTAINER = {
85
- type: _models.ComponentTypes.CONTAINER,
86
- components: [].concat(COMPONENTS, [INNER_INNER_CONTAINER])
87
- };
88
- expect((0, _getEditableComponents.default)({
89
- components: [EDITABLE, INNER_CONTAINER]
90
- })).toEqual([EDITABLE, EDITABLE, EDITABLE]);
91
- });
92
- });
93
-
94
- it('should return all editable components and no non-editable ones', function () {
95
- var COMPONENTS = [HTML, INSET_TEXT, HEADING];
96
-
97
- _isEditable.EDITABLE_TYPES.forEach(function (type) {
98
- COMPONENTS.push({
99
- type: type
100
- });
101
- });
102
-
103
- var RESULT = (0, _getEditableComponents.default)({
104
- components: COMPONENTS
105
- });
106
- expect(RESULT.length).toEqual(_isEditable.EDITABLE_TYPES.length);
107
-
108
- _isEditable.EDITABLE_TYPES.forEach(function (type) {
109
- expect(RESULT).toContainEqual({
110
- type: type
111
- });
112
- });
113
- });
114
- it('should return all editable components and no non-editable ones, regardless of nesting level', function () {
115
- var EDITABLE_COMPONENTS = _isEditable.EDITABLE_TYPES.map(function (type) {
116
- return {
117
- type: type
118
- };
119
- });
120
-
121
- var NON_EDITABLE_COMPONENTS = [HTML, INSET_TEXT, HEADING];
122
- var COMPONENTS = [].concat(EDITABLE_COMPONENTS, NON_EDITABLE_COMPONENTS, [{
123
- type: _models.ComponentTypes.CONTAINER,
124
- id: 'inner',
125
- components: [].concat(EDITABLE_COMPONENTS, NON_EDITABLE_COMPONENTS, [{
126
- type: _models.ComponentTypes.CONTAINER,
127
- id: 'inner-inner',
128
- components: [].concat(NON_EDITABLE_COMPONENTS, EDITABLE_COMPONENTS)
129
- }])
130
- }]);
131
- var RESULT = (0, _getEditableComponents.default)({
132
- components: COMPONENTS
133
- });
134
- expect(RESULT.length).toEqual(_isEditable.EDITABLE_TYPES.length * 3); // 1 each at top, inner, and inner-inner levels.
135
-
136
- _isEditable.EDITABLE_TYPES.forEach(function (type) {
137
- expect(RESULT).toContainEqual({
138
- type: type
139
- });
140
- });
141
-
142
- expect(RESULT).not.toContainEqual(HTML);
143
- expect(RESULT).not.toContainEqual(INSET_TEXT);
144
- expect(RESULT).not.toContainEqual(HEADING);
145
- });
146
- });