@ukhomeoffice/cop-react-form-renderer 2.2.0 → 2.6.1-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 (88) hide show
  1. package/dist/components/FormComponent/Container.test.js +250 -0
  2. package/dist/components/FormComponent/FormComponent.js +101 -22
  3. package/dist/components/FormPage/FormPage.js +2 -1
  4. package/dist/components/FormRenderer/FormRenderer.js +105 -6
  5. package/dist/components/FormRenderer/FormRenderer.test.js +235 -0
  6. package/dist/components/FormRenderer/helpers/getNextPageId.js +3 -0
  7. package/dist/components/FormRenderer/helpers/getNextPageId.test.js +6 -0
  8. package/dist/components/FormRenderer/helpers/getPage.js +1 -1
  9. package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +18 -1
  10. package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +44 -6
  11. package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.js +50 -0
  12. package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.test.js +122 -0
  13. package/dist/components/FormRenderer/helpers/index.js +7 -1
  14. package/dist/components/TaskList/Task.js +83 -0
  15. package/dist/components/TaskList/Task.test.js +112 -0
  16. package/dist/components/TaskList/TaskList.js +112 -0
  17. package/dist/components/TaskList/TaskList.scss +70 -0
  18. package/dist/components/TaskList/TaskList.stories.mdx +57 -0
  19. package/dist/components/TaskList/TaskList.test.js +223 -0
  20. package/dist/components/TaskList/TaskState.js +42 -0
  21. package/dist/components/TaskList/TaskState.test.js +99 -0
  22. package/dist/components/TaskList/index.js +13 -0
  23. package/dist/hooks/index.js +19 -1
  24. package/dist/json/taskList.json +228 -0
  25. package/dist/json/userProfile.data.json +2 -1
  26. package/dist/models/ComponentTypes.js +5 -1
  27. package/dist/models/FormTypes.js +2 -0
  28. package/dist/models/HubFormats.js +3 -1
  29. package/dist/models/PageAction.js +5 -0
  30. package/dist/models/TaskStates.js +41 -0
  31. package/dist/models/index.js +8 -0
  32. package/dist/utils/CheckYourAnswers/getCYARowsForContainer.js +40 -0
  33. package/dist/utils/CheckYourAnswers/getCYARowsForContainer.test.js +257 -0
  34. package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +9 -1
  35. package/dist/utils/CheckYourAnswers/getCYARowsForPage.test.js +44 -0
  36. package/dist/utils/CheckYourAnswers/showComponentCYA.js +6 -0
  37. package/dist/utils/Component/cleanAttributes.js +1 -1
  38. package/dist/utils/Component/getComponent.js +8 -0
  39. package/dist/utils/Component/isEditable.js +1 -1
  40. package/dist/utils/Component/showComponent.js +2 -20
  41. package/dist/utils/Condition/index.js +19 -0
  42. package/dist/utils/Condition/meetsAllConditions.js +40 -0
  43. package/dist/utils/Condition/meetsAllConditions.test.js +62 -0
  44. package/dist/utils/{meetsCondition.js → Condition/meetsCondition.js} +0 -0
  45. package/dist/utils/Condition/meetsCondition.test.js +302 -0
  46. package/dist/utils/Condition/setupConditions.js +47 -0
  47. package/dist/utils/Condition/setupConditions.test.js +35 -0
  48. package/dist/utils/Container/getEditableComponents.js +38 -0
  49. package/dist/utils/Container/getEditableComponents.test.js +157 -0
  50. package/dist/utils/Container/index.js +22 -0
  51. package/dist/utils/Container/setupNesting.js +45 -0
  52. package/dist/utils/Container/setupNesting.test.js +92 -0
  53. package/dist/utils/Container/showContainer.js +61 -0
  54. package/dist/utils/Container/showContainer.test.js +128 -0
  55. package/dist/utils/Data/getDataPath.js +90 -0
  56. package/dist/utils/Data/getDataPath.test.js +52 -0
  57. package/dist/utils/Data/index.js +3 -0
  58. package/dist/utils/FormPage/getFormPage.js +4 -2
  59. package/dist/utils/FormPage/getFormPage.test.js +18 -7
  60. package/dist/utils/FormPage/getFormPages.test.js +5 -2
  61. package/dist/utils/FormPage/getPageActions.js +6 -0
  62. package/dist/utils/FormPage/index.js +0 -3
  63. package/dist/utils/FormPage/showFormPage.js +7 -27
  64. package/dist/utils/Hub/getFormHub.js +4 -0
  65. package/dist/utils/Hub/getFormHub.test.js +15 -4
  66. package/dist/utils/Validate/additional/index.js +55 -0
  67. package/dist/utils/Validate/additional/index.test.js +69 -0
  68. package/dist/utils/Validate/additional/mustBeAfter.js +37 -0
  69. package/dist/utils/Validate/additional/mustBeAfter.test.js +98 -0
  70. package/dist/utils/Validate/additional/mustBeBefore.js +35 -0
  71. package/dist/utils/Validate/additional/mustBeBefore.test.js +66 -0
  72. package/dist/utils/Validate/additional/mustBeInTheFuture.js +42 -0
  73. package/dist/utils/Validate/additional/mustBeInTheFuture.test.js +34 -0
  74. package/dist/utils/Validate/additional/mustBeInThePast.js +44 -0
  75. package/dist/utils/Validate/additional/mustBeInThePast.test.js +34 -0
  76. package/dist/utils/Validate/additional/utils.js +66 -0
  77. package/dist/utils/Validate/index.js +7 -1
  78. package/dist/utils/Validate/validateComponent.js +57 -0
  79. package/dist/utils/Validate/validateComponent.test.js +92 -2
  80. package/dist/utils/Validate/validateDate.js +155 -0
  81. package/dist/utils/Validate/validateDate.test.js +118 -0
  82. package/dist/utils/Validate/validatePage.js +6 -8
  83. package/dist/utils/Validate/validateTime.js +95 -0
  84. package/dist/utils/Validate/validateTime.test.js +61 -0
  85. package/dist/utils/index.js +6 -3
  86. package/package.json +5 -4
  87. package/dist/utils/FormPage/getEditableComponents.js +0 -28
  88. package/dist/utils/FormPage/getEditableComponents.test.js +0 -75
@@ -0,0 +1,302 @@
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('unknown operator', function () {
265
+ var op = 'definitely_not_a_real_operator';
266
+ it('should reject anything regardless of the value', function () {
267
+ var CONDITION = getCondition(op, 'a');
268
+ TEST_VALUES.forEach(function (value) {
269
+ expect((0, _meetsCondition.default)(CONDITION, value)).toBeFalsy();
270
+ });
271
+ });
272
+ it('should accept anything even with a null value', function () {
273
+ var CONDITION = getCondition(op, null);
274
+ TEST_VALUES.forEach(function (value) {
275
+ expect((0, _meetsCondition.default)(CONDITION, value)).toBeFalsy();
276
+ });
277
+ });
278
+ it('should accept anything even with a undefined value', function () {
279
+ var CONDITION = getCondition(op, null);
280
+ TEST_VALUES.forEach(function (value) {
281
+ expect((0, _meetsCondition.default)(CONDITION, value)).toBeFalsy();
282
+ });
283
+ });
284
+ });
285
+ describe('invalid condition', function () {
286
+ it('should accept anything when the condition is null', function () {
287
+ TEST_VALUES.forEach(function (value) {
288
+ expect((0, _meetsCondition.default)(null, value)).toBeTruthy();
289
+ });
290
+ });
291
+ it('should accept anything when the condition is undefined', function () {
292
+ TEST_VALUES.forEach(function (value) {
293
+ expect((0, _meetsCondition.default)(undefined, value)).toBeTruthy();
294
+ });
295
+ });
296
+ it('should accept anything when the condition is not an object', function () {
297
+ TEST_VALUES.forEach(function (value) {
298
+ expect((0, _meetsCondition.default)('condition', value)).toBeTruthy();
299
+ });
300
+ });
301
+ });
302
+ });
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _Data = _interopRequireDefault(require("../Data"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
13
+
14
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
15
+
16
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
17
+
18
+ var makeComponentFieldsAbsolute = function makeComponentFieldsAbsolute(component) {
19
+ if (component.show_when) {
20
+ var full_path = component.full_path;
21
+ var show_when = Array.isArray(component.show_when) ? component.show_when : [component.show_when];
22
+ return show_when.map(function (sw) {
23
+ var field = _Data.default.getDataPath(sw.field, full_path);
24
+
25
+ return _objectSpread(_objectSpread({}, sw), {}, {
26
+ field: field
27
+ });
28
+ });
29
+ }
30
+
31
+ return undefined;
32
+ };
33
+
34
+ var isCondition = function isCondition(options) {
35
+ return Array.isArray(options) || !!(options.field && options.op);
36
+ };
37
+
38
+ var setupConditions = function setupConditions(options) {
39
+ if (options && !isCondition(options)) {
40
+ return makeComponentFieldsAbsolute(options);
41
+ }
42
+
43
+ return options;
44
+ };
45
+
46
+ var _default = setupConditions;
47
+ exports.default = _default;
@@ -0,0 +1,35 @@
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
+ });
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _models = require("../../models");
9
+
10
+ var _Component = _interopRequireDefault(require("../Component"));
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ // Local imports
15
+
16
+ /**
17
+ * Gets all the editable components in a container.
18
+ * @param {object} container The container to consider.
19
+ * @returns An array of ONLY the editable components in a container.
20
+ */
21
+ var getEditableComponents = function getEditableComponents(container) {
22
+ if (container && Array.isArray(container.components)) {
23
+ return container.components.flatMap(function (c) {
24
+ if (c.type === _models.ComponentTypes.CONTAINER) {
25
+ return getEditableComponents(c);
26
+ }
27
+
28
+ return _Component.default.editable(c) ? c : null;
29
+ }).filter(function (c) {
30
+ return !!c;
31
+ });
32
+ }
33
+
34
+ return [];
35
+ };
36
+
37
+ var _default = getEditableComponents;
38
+ exports.default = _default;
@@ -0,0 +1,157 @@
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
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
12
+
13
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
14
+
15
+ 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); }
16
+
17
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
18
+
19
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
20
+
21
+ 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; }
22
+
23
+ describe('utils.Container.getEditableComponents', function () {
24
+ var HTML = {
25
+ type: 'html',
26
+ tagName: 'p',
27
+ content: 'Alpha'
28
+ };
29
+ var INSET_TEXT = {
30
+ type: 'inset-text',
31
+ content: 'Bravo'
32
+ };
33
+ var HEADING = {
34
+ type: 'heading',
35
+ size: 'm',
36
+ content: 'Charlie'
37
+ };
38
+ it('should return an empty array for a null container', function () {
39
+ expect((0, _getEditableComponents.default)(null)).toEqual([]);
40
+ });
41
+ it('should return an empty array for a container with no components', function () {
42
+ expect((0, _getEditableComponents.default)({
43
+ components: []
44
+ })).toEqual([]);
45
+ });
46
+ it('should return an empty array for a container with only non-editable components', function () {
47
+ var COMPONENTS = [HTML, INSET_TEXT, HEADING];
48
+ expect((0, _getEditableComponents.default)({
49
+ components: COMPONENTS
50
+ })).toEqual([]);
51
+ });
52
+ it('should return an empty array for a container that contains a container with only non-editable components', function () {
53
+ var COMPONENTS = [HTML, INSET_TEXT, HEADING];
54
+ var INNER_CONTAINER = {
55
+ type: _models.ComponentTypes.CONTAINER,
56
+ components: COMPONENTS
57
+ };
58
+ expect((0, _getEditableComponents.default)({
59
+ components: [INNER_CONTAINER]
60
+ })).toEqual([]);
61
+ });
62
+
63
+ _isEditable.EDITABLE_TYPES.forEach(function (type) {
64
+ it("should return just the \"".concat(type, "\" component if it exists in the components, but no non-editable ones"), function () {
65
+ var EDITABLE = {
66
+ type: type
67
+ };
68
+ var COMPONENTS = [HTML, EDITABLE, INSET_TEXT, HEADING];
69
+ expect((0, _getEditableComponents.default)({
70
+ components: COMPONENTS
71
+ })).toEqual([EDITABLE]);
72
+ });
73
+ it("should return just the \"".concat(type, "\" component if it exists inside an inner container's components, but no non-editable ones"), function () {
74
+ var EDITABLE = {
75
+ type: type
76
+ };
77
+ var COMPONENTS = [HTML, EDITABLE, INSET_TEXT, HEADING];
78
+ var INNER_CONTAINER = {
79
+ type: _models.ComponentTypes.CONTAINER,
80
+ components: COMPONENTS
81
+ };
82
+ expect((0, _getEditableComponents.default)({
83
+ components: [INNER_CONTAINER]
84
+ })).toEqual([EDITABLE]);
85
+ });
86
+ it("should return just all \"".concat(type, "\" components that exists at any nested level within the container, but no non-editable ones"), function () {
87
+ var EDITABLE = {
88
+ type: type
89
+ };
90
+ var COMPONENTS = [HTML, EDITABLE, INSET_TEXT, HEADING];
91
+ var INNER_INNER_CONTAINER = {
92
+ type: _models.ComponentTypes.CONTAINER,
93
+ components: COMPONENTS
94
+ };
95
+ var INNER_CONTAINER = {
96
+ type: _models.ComponentTypes.CONTAINER,
97
+ components: [].concat(COMPONENTS, [INNER_INNER_CONTAINER])
98
+ };
99
+ expect((0, _getEditableComponents.default)({
100
+ components: [EDITABLE, INNER_CONTAINER]
101
+ })).toEqual([EDITABLE, EDITABLE, EDITABLE]);
102
+ });
103
+ });
104
+
105
+ it('should return all editable components and no non-editable ones', function () {
106
+ var COMPONENTS = [HTML, INSET_TEXT, HEADING];
107
+
108
+ _isEditable.EDITABLE_TYPES.forEach(function (type) {
109
+ COMPONENTS.push({
110
+ type: type
111
+ });
112
+ });
113
+
114
+ var RESULT = (0, _getEditableComponents.default)({
115
+ components: COMPONENTS
116
+ });
117
+ expect(RESULT.length).toEqual(_isEditable.EDITABLE_TYPES.length);
118
+
119
+ _isEditable.EDITABLE_TYPES.forEach(function (type) {
120
+ expect(RESULT).toContainEqual({
121
+ type: type
122
+ });
123
+ });
124
+ });
125
+ it('should return all editable components and no non-editable ones, regardless of nesting level', function () {
126
+ var EDITABLE_COMPONENTS = _isEditable.EDITABLE_TYPES.map(function (type) {
127
+ return {
128
+ type: type
129
+ };
130
+ });
131
+
132
+ var NON_EDITABLE_COMPONENTS = [HTML, INSET_TEXT, HEADING];
133
+ var COMPONENTS = [].concat(_toConsumableArray(EDITABLE_COMPONENTS), NON_EDITABLE_COMPONENTS, [{
134
+ type: _models.ComponentTypes.CONTAINER,
135
+ id: 'inner',
136
+ components: [].concat(_toConsumableArray(EDITABLE_COMPONENTS), NON_EDITABLE_COMPONENTS, [{
137
+ type: _models.ComponentTypes.CONTAINER,
138
+ id: 'inner-inner',
139
+ components: [].concat(NON_EDITABLE_COMPONENTS, _toConsumableArray(EDITABLE_COMPONENTS))
140
+ }])
141
+ }]);
142
+ var RESULT = (0, _getEditableComponents.default)({
143
+ components: COMPONENTS
144
+ });
145
+ expect(RESULT.length).toEqual(_isEditable.EDITABLE_TYPES.length * 3); // 1 each at top, inner, and inner-inner levels.
146
+
147
+ _isEditable.EDITABLE_TYPES.forEach(function (type) {
148
+ expect(RESULT).toContainEqual({
149
+ type: type
150
+ });
151
+ });
152
+
153
+ expect(RESULT).not.toContainEqual(HTML);
154
+ expect(RESULT).not.toContainEqual(INSET_TEXT);
155
+ expect(RESULT).not.toContainEqual(HEADING);
156
+ });
157
+ });
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _getEditableComponents = _interopRequireDefault(require("./getEditableComponents"));
9
+
10
+ var _setupNesting = _interopRequireDefault(require("./setupNesting"));
11
+
12
+ var _showContainer = _interopRequireDefault(require("./showContainer"));
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ var Container = {
17
+ editableComponents: _getEditableComponents.default,
18
+ setup: _setupNesting.default,
19
+ show: _showContainer.default
20
+ };
21
+ var _default = Container;
22
+ exports.default = _default;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _models = require("../../models");
9
+
10
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
11
+
12
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
13
+
14
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
15
+
16
+ var nestComponents = function nestComponents(container) {
17
+ var containerPath = container.full_path || container.fieldId;
18
+ return container.components.map(function (component) {
19
+ var full_path = containerPath ? "".concat(containerPath, ".").concat(component.fieldId) : component.fieldId;
20
+
21
+ var ret = _objectSpread(_objectSpread({}, component), {}, {
22
+ full_path: full_path
23
+ });
24
+
25
+ if (component.type === _models.ComponentTypes.CONTAINER) {
26
+ return setupNesting(ret);
27
+ }
28
+
29
+ return ret;
30
+ });
31
+ };
32
+
33
+ var setupNesting = function setupNesting(container) {
34
+ if (container) {
35
+ var components = nestComponents(container);
36
+ return _objectSpread(_objectSpread({}, container), {}, {
37
+ components: components
38
+ });
39
+ }
40
+
41
+ return container;
42
+ };
43
+
44
+ var _default = setupNesting;
45
+ exports.default = _default;