@ukhomeoffice/cop-react-form-renderer 6.16.2-delta → 6.16.3-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.
- package/dist/components/FormRenderer/onPageAction.js +7 -44
- package/dist/components/FormRenderer/onPageAction.test.js +10 -150
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +4 -10
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +0 -49
- package/dist/utils/CollectionPage/removeCollectionPageEntry.js +0 -2
- package/dist/utils/Validate/validateTextArea.js +1 -1
- package/dist/utils/Validate/validateTextArea.test.js +6 -0
- package/package.json +1 -1
|
@@ -61,22 +61,6 @@ const onPageAction = (action, patch, patchLabel, hooks, data, formState, validat
|
|
|
61
61
|
setSubmitting(false);
|
|
62
62
|
} else {
|
|
63
63
|
let pageUpdate = next => onPageChange(_helpers.default.getNextPageId(type, pages, pageId, action, next));
|
|
64
|
-
let collectionName;
|
|
65
|
-
let addAnotherName;
|
|
66
|
-
if (action.collection) {
|
|
67
|
-
collectionName = action.collection;
|
|
68
|
-
const collectionNameCapitalised = collectionName.charAt(0).toUpperCase() + collectionName.slice(1);
|
|
69
|
-
addAnotherName = "addAnother".concat(collectionNameCapitalised).slice(0, -1);
|
|
70
|
-
}
|
|
71
|
-
let collectionArray;
|
|
72
|
-
let index;
|
|
73
|
-
if (collectionName) {
|
|
74
|
-
collectionArray = form.page.formData[collectionName];
|
|
75
|
-
if (collectionArray && collectionArray.length > 0 && form.page.formData["".concat(collectionName, "ActiveId")]) {
|
|
76
|
-
index = collectionArray.findIndex(obj => obj.id === form.page.formData["".concat(collectionName, "ActiveId")]);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
64
|
/* eslint-disable no-case-declarations */
|
|
81
65
|
switch (action.type) {
|
|
82
66
|
case _models.PageAction.TYPES.SUBMIT:
|
|
@@ -84,33 +68,10 @@ const onPageAction = (action, patch, patchLabel, hooks, data, formState, validat
|
|
|
84
68
|
break;
|
|
85
69
|
case _models.PageAction.TYPES.SAVE_AND_NAVIGATE:
|
|
86
70
|
const state = _objectSpread({}, currentTask);
|
|
87
|
-
// If resetActiveId is true then point active ID to first entry in collection
|
|
88
|
-
if (collectionArray && collectionArray.length > 0 && action.resetActiveId) {
|
|
89
|
-
form.page.formData["".concat(collectionName, "ActiveId")] = collectionArray[0].id;
|
|
90
|
-
}
|
|
91
|
-
// If resetActiveId is false
|
|
92
|
-
if (collectionArray && collectionArray.length > 0 && !action.resetActiveId) {
|
|
93
|
-
// Set addAnother field to yes if not reached last entry in collection
|
|
94
|
-
if (index !== undefined && index + 1 < form.page.formData[collectionName].length) {
|
|
95
|
-
form.page.formData[addAnotherName] = 'Yes';
|
|
96
|
-
}
|
|
97
|
-
// Set addAnother field to no if reached last entry
|
|
98
|
-
if (index !== undefined && index + 1 === form.page.formData[collectionName].length && form.page.formData[addAnotherName]) {
|
|
99
|
-
form.page.formData[addAnotherName] = 'No';
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
71
|
pageUpdate = () => _handlers.default.navigate(action, pageId, onPageChange, state);
|
|
103
72
|
break;
|
|
104
73
|
case _models.PageAction.TYPES.COLLECTION_ADD:
|
|
105
|
-
|
|
106
|
-
// the array is empty
|
|
107
|
-
// or the active ID is the last one in the collection,
|
|
108
|
-
// otherwise move to next entry.
|
|
109
|
-
if (index === undefined || collectionArray.length === 0 || index + 1 === form.page.formData[collectionName].length) {
|
|
110
|
-
_utils.default.CollectionPage.addEntry(action.collection, form.page.formData);
|
|
111
|
-
} else {
|
|
112
|
-
form.page.formData["".concat(action.collection, "ActiveId")] = collectionArray[index + 1].id;
|
|
113
|
-
}
|
|
74
|
+
_utils.default.CollectionPage.addEntry(action.collection, form.page.formData);
|
|
114
75
|
|
|
115
76
|
// We need to delete the collection entry fields from formData as it will be holding previous values.
|
|
116
77
|
if (form.page.formData["".concat(action.collection)] && form.page.formData["".concat(action.collection)].length > 0) {
|
|
@@ -144,13 +105,16 @@ const onPageAction = (action, patch, patchLabel, hooks, data, formState, validat
|
|
|
144
105
|
removedEntryFieldsToDelete.forEach(i => delete form.page.formData[i]);
|
|
145
106
|
}
|
|
146
107
|
|
|
147
|
-
// 3.
|
|
108
|
+
// 3. Retrieve the collection array from formData.
|
|
109
|
+
const collectionArray = form.page.formData[action.collection];
|
|
110
|
+
|
|
111
|
+
// 4. Assign the fields in the last collection entry to formData.
|
|
148
112
|
Object.assign(form.page.formData, collectionArray[collectionArray.length - 1]);
|
|
149
113
|
|
|
150
|
-
//
|
|
114
|
+
// 5. Assign the formData ID back to the formData.
|
|
151
115
|
form.page.formData.id = formDataId;
|
|
152
116
|
|
|
153
|
-
//
|
|
117
|
+
// 6. If the collection array has entries set the correct ActiveId
|
|
154
118
|
// otherwise delete it as well as the collection array.
|
|
155
119
|
if (collectionArray.length > 0) {
|
|
156
120
|
form.page.formData["".concat(action.collection, "ActiveId")] = collectionArray[collectionArray.length - 1].id;
|
|
@@ -158,7 +122,6 @@ const onPageAction = (action, patch, patchLabel, hooks, data, formState, validat
|
|
|
158
122
|
delete form.page.formData["".concat(action.collection, "ActiveId")];
|
|
159
123
|
delete form.page.formData[action.collection];
|
|
160
124
|
}
|
|
161
|
-
pageUpdate = () => _handlers.default.navigate(action, pageId, onPageChange);
|
|
162
125
|
break;
|
|
163
126
|
default:
|
|
164
127
|
break;
|
|
@@ -380,74 +380,6 @@ describe('components.FormRenderer.onPageAction', () => {
|
|
|
380
380
|
// that's called as part of the onSubmit hook's onSuccess callback.
|
|
381
381
|
expect(_handlers.default.navigateCalls).toEqual(1);
|
|
382
382
|
});
|
|
383
|
-
it("should handle the ".concat(_models.PageAction.TYPES.COLLECTION_ADD, " Page Action type where active ID is not the last entry in collection"), () => {
|
|
384
|
-
// If the active ID is not the last entry in the collection
|
|
385
|
-
// then a new entry is not added
|
|
386
|
-
// and the active ID moves to the next entry ID.
|
|
387
|
-
const FORM_STATE = {
|
|
388
|
-
page: {
|
|
389
|
-
formData: {
|
|
390
|
-
'testCollection': [{
|
|
391
|
-
id: '1'
|
|
392
|
-
}, {
|
|
393
|
-
id: '2'
|
|
394
|
-
}],
|
|
395
|
-
testCollectionActiveId: '1'
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
};
|
|
399
|
-
const ACTION = {
|
|
400
|
-
type: _models.PageAction.TYPES.COLLECTION_ADD,
|
|
401
|
-
collection: 'testCollection'
|
|
402
|
-
};
|
|
403
|
-
const CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
404
|
-
action: ACTION,
|
|
405
|
-
formState: FORM_STATE
|
|
406
|
-
});
|
|
407
|
-
_onPageAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
408
|
-
preActionChecks();
|
|
409
|
-
expect(FORM_STATE.page.formData["".concat(ACTION.collection, "ActiveId")]).toEqual('2');
|
|
410
|
-
expect(FORM_STATE.page.formData[ACTION.collection].length).toEqual(2);
|
|
411
|
-
postActionChecks(CUSTOM_ARGS);
|
|
412
|
-
|
|
413
|
-
// This action type also sets up a call to handlers.navigate
|
|
414
|
-
// that's called as part of the onSubmit hook's onSuccess callback.
|
|
415
|
-
expect(_handlers.default.navigateCalls).toEqual(1);
|
|
416
|
-
});
|
|
417
|
-
it("should handle the ".concat(_models.PageAction.TYPES.COLLECTION_ADD, " Page Action type where active ID is the last entry in collection"), () => {
|
|
418
|
-
// If the active ID is the last entry in the collection
|
|
419
|
-
// then a new entry is added (although not picked up in this test)
|
|
420
|
-
// and the active ID becomes null.
|
|
421
|
-
const FORM_STATE = {
|
|
422
|
-
page: {
|
|
423
|
-
formData: {
|
|
424
|
-
'testCollection': [{
|
|
425
|
-
id: '1'
|
|
426
|
-
}, {
|
|
427
|
-
id: '2'
|
|
428
|
-
}],
|
|
429
|
-
testCollectionActiveId: '2'
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
};
|
|
433
|
-
const ACTION = {
|
|
434
|
-
type: _models.PageAction.TYPES.COLLECTION_ADD,
|
|
435
|
-
collection: 'testCollection'
|
|
436
|
-
};
|
|
437
|
-
const CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
438
|
-
action: ACTION,
|
|
439
|
-
formState: FORM_STATE
|
|
440
|
-
});
|
|
441
|
-
_onPageAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
442
|
-
preActionChecks();
|
|
443
|
-
expect(FORM_STATE.page.formData["".concat(ACTION.collection, "ActiveId")]).toEqual(null);
|
|
444
|
-
expect(FORM_STATE.page.formData[ACTION.collection].length).toEqual(2);
|
|
445
|
-
postActionChecks(CUSTOM_ARGS);
|
|
446
|
-
|
|
447
|
-
// This action type also sets up a call to handlers.navigate
|
|
448
|
-
// that's called as part of the onSubmit hook's onSuccess callback.
|
|
449
|
-
expect(_handlers.default.navigateCalls).toEqual(1);
|
|
450
|
-
});
|
|
451
383
|
it("should clean previous collection entry fields at top level of formData", () => {
|
|
452
384
|
const FORM_STATE = {
|
|
453
385
|
page: {
|
|
@@ -565,8 +497,8 @@ describe('components.FormRenderer.onPageAction', () => {
|
|
|
565
497
|
});
|
|
566
498
|
postActionChecks(CUSTOM_ARGS);
|
|
567
499
|
|
|
568
|
-
// This action type uses
|
|
569
|
-
expect(
|
|
500
|
+
// This action type uses the default onPageChange.
|
|
501
|
+
expect(onPageChangeCalls).toEqual(1);
|
|
570
502
|
});
|
|
571
503
|
it("should not store a reference to the removed item if action.recordRemoval is false", () => {
|
|
572
504
|
const FORM_STATE = {
|
|
@@ -598,8 +530,8 @@ describe('components.FormRenderer.onPageAction', () => {
|
|
|
598
530
|
expect(FORM_STATE.page.formData.testCollectionLastRemoved).toBeUndefined();
|
|
599
531
|
postActionChecks(CUSTOM_ARGS);
|
|
600
532
|
|
|
601
|
-
// This action type uses
|
|
602
|
-
expect(
|
|
533
|
+
// This action type uses the default onPageChange.
|
|
534
|
+
expect(onPageChangeCalls).toEqual(1);
|
|
603
535
|
});
|
|
604
536
|
it("should not store a reference to the removed item if action.recordRemoval is not defined", () => {
|
|
605
537
|
const FORM_STATE = {
|
|
@@ -630,8 +562,8 @@ describe('components.FormRenderer.onPageAction', () => {
|
|
|
630
562
|
expect(FORM_STATE.page.formData.testCollectionLastRemoved).toBeUndefined();
|
|
631
563
|
postActionChecks(CUSTOM_ARGS);
|
|
632
564
|
|
|
633
|
-
// This action type uses
|
|
634
|
-
expect(
|
|
565
|
+
// This action type uses the default onPageChange.
|
|
566
|
+
expect(onPageChangeCalls).toEqual(1);
|
|
635
567
|
});
|
|
636
568
|
it("should clean collection fields at top level of formData when entries remain", () => {
|
|
637
569
|
// After removing the active entry, the collection data is assigned to the
|
|
@@ -675,8 +607,8 @@ describe('components.FormRenderer.onPageAction', () => {
|
|
|
675
607
|
expect(FORM_STATE.page.formData.testCollectionActiveId).toEqual('leaveMeAlone');
|
|
676
608
|
postActionChecks(CUSTOM_ARGS);
|
|
677
609
|
|
|
678
|
-
// This action type uses
|
|
679
|
-
expect(
|
|
610
|
+
// This action type uses the default onPageChange.
|
|
611
|
+
expect(onPageChangeCalls).toEqual(1);
|
|
680
612
|
});
|
|
681
613
|
it("should clean collection fields at top level of formData after last entry removed", () => {
|
|
682
614
|
// After removing the last active entry, the collection array and activeID are deleted,
|
|
@@ -714,8 +646,8 @@ describe('components.FormRenderer.onPageAction', () => {
|
|
|
714
646
|
expect(FORM_STATE.page.formData.testCollectionActiveId).toBeUndefined();
|
|
715
647
|
postActionChecks(CUSTOM_ARGS);
|
|
716
648
|
|
|
717
|
-
// This action type uses
|
|
718
|
-
expect(
|
|
649
|
+
// This action type uses the default onPageChange.
|
|
650
|
+
expect(onPageChangeCalls).toEqual(1);
|
|
719
651
|
});
|
|
720
652
|
});
|
|
721
653
|
describe('if validation fails', () => {
|
|
@@ -776,78 +708,6 @@ describe('components.FormRenderer.onPageAction', () => {
|
|
|
776
708
|
expect(FORM_STATE.page.formData.parent[0].child[0].id).toEqual('12345');
|
|
777
709
|
});
|
|
778
710
|
});
|
|
779
|
-
it("should work for the ".concat(_models.PageAction.TYPES.SAVE_AND_NAVIGATE, " action type to reset the active ID"), () => {
|
|
780
|
-
// In this test the action includes the resetActiveId field
|
|
781
|
-
// requiring that the active ID is pointed to the first entry in the collection
|
|
782
|
-
// so that user can cycle through the full collection again.
|
|
783
|
-
const FORM_STATE = {
|
|
784
|
-
page: {
|
|
785
|
-
formData: {
|
|
786
|
-
testCollection: [{
|
|
787
|
-
id: '1'
|
|
788
|
-
}, {
|
|
789
|
-
id: '2'
|
|
790
|
-
}, {
|
|
791
|
-
id: '3'
|
|
792
|
-
}],
|
|
793
|
-
testCollectionActiveId: '3'
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
};
|
|
797
|
-
const ACTION = {
|
|
798
|
-
type: _models.PageAction.TYPES.SAVE_AND_NAVIGATE,
|
|
799
|
-
collection: 'testCollection',
|
|
800
|
-
resetActiveId: true
|
|
801
|
-
};
|
|
802
|
-
const CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
803
|
-
formState: FORM_STATE,
|
|
804
|
-
action: ACTION
|
|
805
|
-
});
|
|
806
|
-
_onPageAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
807
|
-
preActionChecks();
|
|
808
|
-
// All the actions does in this case is set a function
|
|
809
|
-
// to be called in the onSuccess callback for the onSubmit hook.
|
|
810
|
-
postActionChecks(CUSTOM_ARGS);
|
|
811
|
-
expect(_handlers.default.navigateCalls).toEqual(1);
|
|
812
|
-
expect(FORM_STATE.page.formData["".concat(ACTION.collection, "ActiveId")]).toEqual('1');
|
|
813
|
-
});
|
|
814
|
-
it("should work for the ".concat(_models.PageAction.TYPES.SAVE_AND_NAVIGATE, " action type to set addAnother to yes"), () => {
|
|
815
|
-
// If the user is midway through the collection
|
|
816
|
-
// then the addAnother field is set to yes
|
|
817
|
-
// to allow the navigation to move to next entry.
|
|
818
|
-
const FORM_STATE = {
|
|
819
|
-
page: {
|
|
820
|
-
formData: {
|
|
821
|
-
tests: [{
|
|
822
|
-
id: '1'
|
|
823
|
-
}, {
|
|
824
|
-
id: '2'
|
|
825
|
-
}, {
|
|
826
|
-
id: '3'
|
|
827
|
-
}],
|
|
828
|
-
testsActiveId: '2',
|
|
829
|
-
addAnotherTest: 'No'
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
};
|
|
833
|
-
const ACTION = {
|
|
834
|
-
type: _models.PageAction.TYPES.SAVE_AND_NAVIGATE,
|
|
835
|
-
collection: 'tests'
|
|
836
|
-
};
|
|
837
|
-
const CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
838
|
-
formState: FORM_STATE,
|
|
839
|
-
action: ACTION
|
|
840
|
-
});
|
|
841
|
-
_onPageAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
842
|
-
preActionChecks();
|
|
843
|
-
// All the actions does in this case is set a function
|
|
844
|
-
// to be called in the onSuccess callback for the onSubmit hook.
|
|
845
|
-
postActionChecks(CUSTOM_ARGS);
|
|
846
|
-
expect(_handlers.default.navigateCalls).toEqual(1);
|
|
847
|
-
expect(FORM_STATE.page.formData["".concat(ACTION.collection, "ActiveId")]).toEqual('2');
|
|
848
|
-
expect(FORM_STATE.page.formData[ACTION.collection].length).toEqual(3);
|
|
849
|
-
expect(FORM_STATE.page.formData.addAnotherTest).toEqual('Yes');
|
|
850
|
-
});
|
|
851
711
|
it("should work for the ".concat(_models.PageAction.TYPES.NAVIGATE, " action type"), () => {
|
|
852
712
|
const FORM_STATE = {
|
|
853
713
|
page: {
|
|
@@ -19,12 +19,6 @@ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object
|
|
|
19
19
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
20
20
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } // Global imports
|
|
21
21
|
// Local imports
|
|
22
|
-
const showAction = (data, action) => {
|
|
23
|
-
if (!action.show_when) {
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
return (0, _meetsAllConditions.default)(action.show_when, data);
|
|
27
|
-
};
|
|
28
22
|
const getContainerForPage = (page, item, labelCount, fullPath) => ({
|
|
29
23
|
id: item.id,
|
|
30
24
|
fieldId: item.id,
|
|
@@ -80,10 +74,10 @@ const getCollectionNameHeading = (page, titleName, config, changeAction) => ({
|
|
|
80
74
|
label: 'Change'
|
|
81
75
|
}
|
|
82
76
|
});
|
|
83
|
-
const getActionRows = function (page, item, onAction, labelCount
|
|
77
|
+
const getActionRows = function (page, item, onAction, labelCount) {
|
|
84
78
|
var _page$collection;
|
|
85
|
-
let activeIds = arguments.length >
|
|
86
|
-
return (_page$collection = page.collection) === null || _page$collection === void 0 || (_page$collection = _page$collection.actions) === null || _page$collection === void 0 ? void 0 : _page$collection.
|
|
79
|
+
let activeIds = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
80
|
+
return (_page$collection = page.collection) === null || _page$collection === void 0 || (_page$collection = _page$collection.actions) === null || _page$collection === void 0 ? void 0 : _page$collection.map(action => {
|
|
87
81
|
if (action.type === 'remove') {
|
|
88
82
|
return (0, _getCYACollectionDeleteAction.default)(page, item, onAction, labelCount, action, activeIds);
|
|
89
83
|
}
|
|
@@ -217,7 +211,7 @@ const getCYARowsForCollectionPage = function (page, onAction, fnOverride, data)
|
|
|
217
211
|
const labelCount = itemIndex + 1;
|
|
218
212
|
const actionPosition = ((_page$collection2 = page.collection) === null || _page$collection2 === void 0 ? void 0 : _page$collection2.actionPosition) || 'top';
|
|
219
213
|
const fullPath = "".concat(page.collection.name, "[").concat(itemIndex, "]");
|
|
220
|
-
const actionRows = getActionRows(page, item, onAction, labelCount,
|
|
214
|
+
const actionRows = getActionRows(page, item, onAction, labelCount, activeIds);
|
|
221
215
|
if (!hideItemTitles) {
|
|
222
216
|
const titleRow = getTitleRowForItem(page, item, page.id, labelCount, fullPath);
|
|
223
217
|
rows = rows.concat(titleRow);
|
|
@@ -595,55 +595,6 @@ describe('utils.CheckYourAnswers.getCYARowsForCollectionPage', () => {
|
|
|
595
595
|
expect(ROWS[ROWS.length - 2].action.label).toEqual('custom remove label');
|
|
596
596
|
expect(ROWS[ROWS.length - 1].action.label).toEqual('custom change label');
|
|
597
597
|
});
|
|
598
|
-
it('Show show the collection action when show_when condition is true', () => {
|
|
599
|
-
const FORM_DATA = {
|
|
600
|
-
collection: [{
|
|
601
|
-
id: '01',
|
|
602
|
-
testText: 'value'
|
|
603
|
-
}]
|
|
604
|
-
};
|
|
605
|
-
const PAGE = _objectSpread(_objectSpread({}, MASTER_PAGE), {}, {
|
|
606
|
-
collection: _objectSpread(_objectSpread({}, MASTER_PAGE.collection), {}, {
|
|
607
|
-
// Add a show_when to the colleciton action.
|
|
608
|
-
actions: MASTER_PAGE.collection.actions.map((action, index) => index === 1 ? _objectSpread(_objectSpread({}, action), {}, {
|
|
609
|
-
show_when: [{
|
|
610
|
-
field: "collection.length",
|
|
611
|
-
op: "=",
|
|
612
|
-
value: 1
|
|
613
|
-
}]
|
|
614
|
-
}) : action)
|
|
615
|
-
}),
|
|
616
|
-
formData: FORM_DATA
|
|
617
|
-
});
|
|
618
|
-
const ROWS = (0, _getCYARowsForCollectionPage.default)(PAGE, null, null, FORM_DATA);
|
|
619
|
-
expect(ROWS[2].action.label).toEqual('Change');
|
|
620
|
-
expect(ROWS[3].action.label).toEqual('custom remove label');
|
|
621
|
-
expect(ROWS[4].action.label).toEqual('custom change label');
|
|
622
|
-
});
|
|
623
|
-
it('Should hide the collection action when show_when condition is false', () => {
|
|
624
|
-
const FORM_DATA = {
|
|
625
|
-
collection: [{
|
|
626
|
-
id: '01',
|
|
627
|
-
testText: 'value'
|
|
628
|
-
}]
|
|
629
|
-
};
|
|
630
|
-
const PAGE = _objectSpread(_objectSpread({}, MASTER_PAGE), {}, {
|
|
631
|
-
collection: _objectSpread(_objectSpread({}, MASTER_PAGE.collection), {}, {
|
|
632
|
-
// Add a show_when to the colleciton action.
|
|
633
|
-
actions: MASTER_PAGE.collection.actions.map((action, index) => index === 1 ? _objectSpread(_objectSpread({}, action), {}, {
|
|
634
|
-
show_when: [{
|
|
635
|
-
field: "collection.length",
|
|
636
|
-
op: "=",
|
|
637
|
-
value: 10
|
|
638
|
-
}]
|
|
639
|
-
}) : action)
|
|
640
|
-
}),
|
|
641
|
-
formData: FORM_DATA
|
|
642
|
-
});
|
|
643
|
-
const ROWS = (0, _getCYARowsForCollectionPage.default)(PAGE, null, null, FORM_DATA);
|
|
644
|
-
expect(ROWS[2].action.label).toEqual('Change');
|
|
645
|
-
expect(ROWS[3].action.label).toEqual('custom change label');
|
|
646
|
-
});
|
|
647
598
|
it('should ignore the result of the override function if it returns nullish', () => {
|
|
648
599
|
const FORM_DATA = {
|
|
649
600
|
collection: [{
|
|
@@ -28,8 +28,6 @@ const removeCollectionPageEntry = (collectionName, formData, id) => {
|
|
|
28
28
|
}
|
|
29
29
|
const deletedEntry = collectionData[indexToDelete];
|
|
30
30
|
collectionData.splice(indexToDelete, 1);
|
|
31
|
-
const data = formData;
|
|
32
|
-
data["".concat(collectionName, "ActiveId")] = collectionData.length > 0 ? collectionData[0].id : null;
|
|
33
31
|
return deletedEntry;
|
|
34
32
|
};
|
|
35
33
|
var _default = exports.default = removeCollectionPageEntry;
|
|
@@ -19,7 +19,7 @@ const validateTextArea = function (label, value, showCharacterCount, customError
|
|
|
19
19
|
if (!showCharacterCount) {
|
|
20
20
|
return undefined;
|
|
21
21
|
}
|
|
22
|
-
const hasError = value.length > maxLength;
|
|
22
|
+
const hasError = !value || value.length > maxLength;
|
|
23
23
|
if (hasError) {
|
|
24
24
|
if (Array.isArray(customErrors)) {
|
|
25
25
|
const result = customErrors.filter(error => error.type === 'length');
|
|
@@ -37,6 +37,12 @@ describe('utils', () => {
|
|
|
37
37
|
expect(error).toBeDefined();
|
|
38
38
|
expect(error).toEqual(CUSTOM_ERROR);
|
|
39
39
|
});
|
|
40
|
+
it('Should return a custom error when one is provided and the value is undefined', () => {
|
|
41
|
+
const VALUE = undefined;
|
|
42
|
+
const error = (0, _validateTextArea.default)(LABEL, VALUE, true, CUSTOM_ERRORS, MAX_LENGTH);
|
|
43
|
+
expect(error).toBeDefined();
|
|
44
|
+
expect(error).toEqual(CUSTOM_ERROR);
|
|
45
|
+
});
|
|
40
46
|
});
|
|
41
47
|
});
|
|
42
48
|
});
|