@ukhomeoffice/cop-react-form-renderer 4.64.0-charlie → 4.65.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/CheckYourAnswers/Answer.js +4 -2
- package/dist/components/CheckYourAnswers/Answer.test.js +42 -0
- package/dist/components/CheckYourAnswers/CheckYourAnswers.js +2 -1
- package/dist/components/FormRenderer/FormRenderer.js +9 -106
- package/dist/components/FormRenderer/FormRenderer.test.js +3 -3
- package/dist/components/FormRenderer/onCYAAction.js +130 -0
- package/dist/components/FormRenderer/onCYAAction.test.js +608 -0
- package/dist/utils/Operate/getFirstOf.js +2 -3
- package/dist/utils/Operate/getFirstOf.test.js +9 -0
- package/package.json +2 -2
|
@@ -23,7 +23,8 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
23
23
|
|
|
24
24
|
var Answer = function Answer(_ref) {
|
|
25
25
|
var value = _ref.value,
|
|
26
|
-
component = _ref.component
|
|
26
|
+
component = _ref.component,
|
|
27
|
+
formData = _ref.formData;
|
|
27
28
|
|
|
28
29
|
if (!value) {
|
|
29
30
|
return /*#__PURE__*/_react.default.createElement(_VisuallyHidden.default, null, "No answer");
|
|
@@ -38,7 +39,8 @@ var Answer = function Answer(_ref) {
|
|
|
38
39
|
readonly: true
|
|
39
40
|
}),
|
|
40
41
|
wrap: false,
|
|
41
|
-
value: value
|
|
42
|
+
value: value,
|
|
43
|
+
formData: formData
|
|
42
44
|
});
|
|
43
45
|
};
|
|
44
46
|
|
|
@@ -116,5 +116,47 @@ describe('components', function () {
|
|
|
116
116
|
}
|
|
117
117
|
}, _callee4);
|
|
118
118
|
})));
|
|
119
|
+
it('should handle a component that requires interpolation', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
|
|
120
|
+
var VALUE, DATA, COMPONENT, _renderWithValidation5, container, answer;
|
|
121
|
+
|
|
122
|
+
return regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
123
|
+
while (1) {
|
|
124
|
+
switch (_context5.prev = _context5.next) {
|
|
125
|
+
case 0:
|
|
126
|
+
VALUE = 'beta';
|
|
127
|
+
DATA = {
|
|
128
|
+
dynamic: 'delta'
|
|
129
|
+
};
|
|
130
|
+
COMPONENT = {
|
|
131
|
+
id: 'alpha',
|
|
132
|
+
fieldId: 'alpha',
|
|
133
|
+
type: 'radios',
|
|
134
|
+
data: {
|
|
135
|
+
options: [{
|
|
136
|
+
value: 'beta',
|
|
137
|
+
label: 'hardcoded ${dynamic}'
|
|
138
|
+
}, {
|
|
139
|
+
value: 'charlie',
|
|
140
|
+
label: 'all hardcoded'
|
|
141
|
+
}]
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
_renderWithValidation5 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_Answer.default, {
|
|
145
|
+
value: VALUE,
|
|
146
|
+
component: COMPONENT,
|
|
147
|
+
formData: DATA
|
|
148
|
+
})), container = _renderWithValidation5.container;
|
|
149
|
+
answer = container.childNodes[0];
|
|
150
|
+
expect(answer.tagName).toEqual('DIV');
|
|
151
|
+
expect(answer.classList).toContain(_Readonly.DEFAULT_CLASS);
|
|
152
|
+
expect(answer.textContent).toEqual('hardcoded delta');
|
|
153
|
+
|
|
154
|
+
case 8:
|
|
155
|
+
case "end":
|
|
156
|
+
return _context5.stop();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}, _callee5);
|
|
160
|
+
})));
|
|
119
161
|
});
|
|
120
162
|
});
|
|
@@ -97,7 +97,8 @@ var CheckYourAnswers = function CheckYourAnswers(_ref) {
|
|
|
97
97
|
value: /*#__PURE__*/_react.default.createElement(_Answer.default, {
|
|
98
98
|
key: "".concat(pageIndex, "_").concat(index),
|
|
99
99
|
value: row.value,
|
|
100
|
-
component: row.component
|
|
100
|
+
component: row.component,
|
|
101
|
+
formData: page.formData
|
|
101
102
|
})
|
|
102
103
|
});
|
|
103
104
|
});
|
|
@@ -33,6 +33,8 @@ var _handlers = _interopRequireDefault(require("./handlers"));
|
|
|
33
33
|
|
|
34
34
|
var _helpers = _interopRequireDefault(require("./helpers"));
|
|
35
35
|
|
|
36
|
+
var _onCYAAction = _interopRequireDefault(require("./onCYAAction"));
|
|
37
|
+
|
|
36
38
|
require("./FormRenderer.scss");
|
|
37
39
|
|
|
38
40
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
@@ -105,7 +107,7 @@ var DEFAULT_CLASS = 'hods-form';
|
|
|
105
107
|
exports.DEFAULT_CLASS = DEFAULT_CLASS;
|
|
106
108
|
|
|
107
109
|
var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
108
|
-
var _formState$
|
|
110
|
+
var _formState$page4, _formState$page$actio, _formState$cya$hideCh, _formState$cya$hideGr;
|
|
109
111
|
|
|
110
112
|
var title = _ref2.title,
|
|
111
113
|
type = _ref2.type,
|
|
@@ -498,8 +500,9 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
498
500
|
|
|
499
501
|
if (currentTask.state === _models.TaskStates.TYPES.COMPLETE) {
|
|
500
502
|
if (hubDetails !== null && hubDetails !== void 0 && hubDetails.noTaskCYAs) {
|
|
503
|
+
// If the task is complete and there are no CYA's then show user first page
|
|
501
504
|
var currentPage = data.formStatus.tasks[currentTask.name].currentPage;
|
|
502
|
-
onPageChange(
|
|
505
|
+
onPageChange(currentTask.pages[0] || currentPage);
|
|
503
506
|
} else if (currentTask.customCYA) {
|
|
504
507
|
onPageChange(currentTask.customCYA);
|
|
505
508
|
} else {
|
|
@@ -515,108 +518,6 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
515
518
|
onPageChange(currentTask.pages[0], state);
|
|
516
519
|
}
|
|
517
520
|
}
|
|
518
|
-
}; // Handle actions from "Check your answers".
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
var onCYAAction = function onCYAAction(action) {
|
|
522
|
-
// Check to see whether the action is able to proceed, which in
|
|
523
|
-
// in the case of a submission will validate the fields in the page.
|
|
524
|
-
if (action.type === _models.PageAction.TYPES.SUBMIT) {
|
|
525
|
-
setPagePoint('submit');
|
|
526
|
-
|
|
527
|
-
if (_helpers.default.canCYASubmit(pages, validate.pages)) {
|
|
528
|
-
// Submit.
|
|
529
|
-
var submissionData = _utils.default.Format.form({
|
|
530
|
-
pages: pages,
|
|
531
|
-
components: components
|
|
532
|
-
}, _objectSpread({}, data), _models.EventTypes.SUBMIT);
|
|
533
|
-
|
|
534
|
-
submissionData.formStatus = _helpers.default.getSubmissionStatus(type, pages, pageId, action, submissionData, currentTask, true);
|
|
535
|
-
setData(submissionData); // Now submit the data to the backend...
|
|
536
|
-
|
|
537
|
-
hooks.onSubmit(action.type, submissionData, function () {
|
|
538
|
-
return hooks.onFormComplete();
|
|
539
|
-
}, function (errors) {
|
|
540
|
-
return _handlers.default.submissionError(errors, addErrors);
|
|
541
|
-
});
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
if (action.type === _models.PageAction.TYPES.SAVE_AND_CONTINUE && hub === _models.HubFormats.TASK) {
|
|
546
|
-
var shouldValidate = !(action.hasOwnProperty('validate') && !action.validate);
|
|
547
|
-
var canSubmit = shouldValidate ? _helpers.default.canCYASubmit(currentTask.fullPages, validate.pages) : true;
|
|
548
|
-
|
|
549
|
-
if (canSubmit) {
|
|
550
|
-
var _submissionData = _utils.default.Format.form({
|
|
551
|
-
pages: pages,
|
|
552
|
-
components: components
|
|
553
|
-
}, _objectSpread({}, data), _models.EventTypes.SUBMIT);
|
|
554
|
-
|
|
555
|
-
_submissionData.formStatus = _helpers.default.getSubmissionStatus(type, pages, pageId, action, _submissionData, currentTask, true);
|
|
556
|
-
setData(_submissionData);
|
|
557
|
-
hooks.onSubmit(action.type, _submissionData, function () {
|
|
558
|
-
return onPageChange(_models.FormPages.HUB);
|
|
559
|
-
}, function (errors) {
|
|
560
|
-
return _handlers.default.submissionError(errors, addErrors);
|
|
561
|
-
});
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
if (action.type === _models.PageAction.TYPES.SUBMIT && hub === _models.HubFormats.TASK) {
|
|
566
|
-
setPagePoint('submit');
|
|
567
|
-
|
|
568
|
-
if (_helpers.default.canCYASubmit(currentTask.fullPages, validate.pages)) {
|
|
569
|
-
// Submit.
|
|
570
|
-
var _submissionData2 = _utils.default.Format.form({
|
|
571
|
-
pages: pages,
|
|
572
|
-
components: components
|
|
573
|
-
}, _objectSpread({}, data), _models.EventTypes.SUBMIT);
|
|
574
|
-
|
|
575
|
-
_submissionData2.formStatus = _helpers.default.getSubmissionStatus(type, pages, pageId, action, _submissionData2, currentTask, true);
|
|
576
|
-
setData(_submissionData2); // Now submit the data to the backend...
|
|
577
|
-
|
|
578
|
-
hooks.onSubmit(action.type, _submissionData2, function () {
|
|
579
|
-
return hooks.onFormComplete();
|
|
580
|
-
}, function (errors) {
|
|
581
|
-
return _handlers.default.submissionError(errors, addErrors);
|
|
582
|
-
});
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
if (action.type === _models.PageAction.TYPES.SAVE_AND_RETURN) {
|
|
587
|
-
var _shouldValidate = !(action.hasOwnProperty('validate') && !action.validate);
|
|
588
|
-
|
|
589
|
-
var _canSubmit = _shouldValidate ? _helpers.default.canCYASubmit(currentTask.fullPages, validate.pages) : true;
|
|
590
|
-
|
|
591
|
-
if (_canSubmit) {
|
|
592
|
-
var _submissionData3 = _utils.default.Format.form({
|
|
593
|
-
pages: pages,
|
|
594
|
-
components: components
|
|
595
|
-
}, _objectSpread({}, data), _models.EventTypes.SUBMIT);
|
|
596
|
-
|
|
597
|
-
_submissionData3.formStatus = _helpers.default.getSubmissionStatus(type, pages, pageId, action, _submissionData3, currentTask);
|
|
598
|
-
setData(_submissionData3);
|
|
599
|
-
hooks.onSubmit(action.type, _submissionData3, function () {
|
|
600
|
-
if (type === _models.FormTypes.TASK) {
|
|
601
|
-
onPageChange(undefined);
|
|
602
|
-
} else {
|
|
603
|
-
onPageChange(_models.FormPages.HUB);
|
|
604
|
-
}
|
|
605
|
-
}, function (errors) {
|
|
606
|
-
return _handlers.default.submissionError(errors, addErrors);
|
|
607
|
-
});
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
if (action.type === _models.PageAction.TYPES.NAVIGATE) {
|
|
612
|
-
var _formState$page4;
|
|
613
|
-
|
|
614
|
-
onPageChange(_helpers.default.getNextPageId(type, pages, pageId, action, (_formState$page4 = formState.page) === null || _formState$page4 === void 0 ? void 0 : _formState$page4.formData));
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
if (action.type === _models.PageAction.TYPES.CANCEL) {
|
|
618
|
-
hooks.onCancel();
|
|
619
|
-
}
|
|
620
521
|
};
|
|
621
522
|
|
|
622
523
|
var classes = _utils.default.classBuilder(classBlock, classModifiers, className);
|
|
@@ -629,12 +530,14 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
629
530
|
className: classes()
|
|
630
531
|
}, title && !hide_title && pageId === _models.FormPages.HUB && /*#__PURE__*/_react.default.createElement(_copReactComponents.LargeHeading, null, title), formState.cya && /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, _extends({
|
|
631
532
|
pages: _helpers.default.getRelevantPages(formState, pages, currentTask.fullPages)
|
|
632
|
-
}, cya, ((_formState$
|
|
533
|
+
}, cya, ((_formState$page4 = formState.page) === null || _formState$page4 === void 0 ? void 0 : _formState$page4.type) === _models.FormPages.PARTIAL_CYA && {
|
|
633
534
|
actions: (_formState$page$actio = formState.page.actions) === null || _formState$page$actio === void 0 ? void 0 : _formState$page$actio.filter(function (action) {
|
|
634
535
|
return _utils.default.Component.show(action, data);
|
|
635
536
|
})
|
|
636
537
|
}, formState.cya, {
|
|
637
|
-
onAction:
|
|
538
|
+
onAction: function onAction(action) {
|
|
539
|
+
(0, _onCYAAction.default)(setPagePoint, action, pages, validate, components, data, setData, type, pageId, currentTask, hooks, addErrors, hub, onPageChange, formState);
|
|
540
|
+
},
|
|
638
541
|
onRowAction: onCYARowAction,
|
|
639
542
|
summaryListClassModifiers: summaryListClassModifiers,
|
|
640
543
|
hide_title: hide_title,
|
|
@@ -990,7 +990,7 @@ describe('components', function () {
|
|
|
990
990
|
}
|
|
991
991
|
}, _callee28);
|
|
992
992
|
})));
|
|
993
|
-
it('should go to the
|
|
993
|
+
it('should go to the first page of a complete task if noTaskCYAs specified', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee30() {
|
|
994
994
|
var ON_SUBMIT, HOOKS, TASK_LIST_WITH_NO_TASK_CYAS, taskList, newPage;
|
|
995
995
|
return regeneratorRuntime.wrap(function _callee30$(_context30) {
|
|
996
996
|
while (1) {
|
|
@@ -1066,10 +1066,10 @@ describe('components', function () {
|
|
|
1066
1066
|
_react.fireEvent.click(newPage.childNodes[2].childNodes[0], {}); // Launch same task again
|
|
1067
1067
|
|
|
1068
1068
|
|
|
1069
|
-
_react.fireEvent.click(container.childNodes[0].childNodes[1].childNodes[3].childNodes[1].childNodes[0].childNodes[0], {}); // Should be on the
|
|
1069
|
+
_react.fireEvent.click(container.childNodes[0].childNodes[1].childNodes[3].childNodes[1].childNodes[0].childNodes[0], {}); // Should be on the first page
|
|
1070
1070
|
|
|
1071
1071
|
|
|
1072
|
-
expect(container.childNodes[0].childNodes[0].childNodes[0].textContent).toEqual('Event
|
|
1072
|
+
expect(container.childNodes[0].childNodes[0].childNodes[0].textContent).toEqual('Event Date');
|
|
1073
1073
|
|
|
1074
1074
|
case 19:
|
|
1075
1075
|
case "end":
|
|
@@ -0,0 +1,130 @@
|
|
|
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 _utils = _interopRequireDefault(require("../../utils"));
|
|
11
|
+
|
|
12
|
+
var _handlers = _interopRequireDefault(require("./handlers"));
|
|
13
|
+
|
|
14
|
+
var _helpers = _interopRequireDefault(require("./helpers"));
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
|
|
18
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
19
|
+
|
|
20
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
21
|
+
|
|
22
|
+
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; }
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
* @param {*} action
|
|
27
|
+
*/
|
|
28
|
+
var onCYAAction = function onCYAAction(setPagePoint, action, pages, validate, components, data, setData, type, pageId, currentTask, hooks, addErrors, hub, onPageChange, formState) {
|
|
29
|
+
// Check to see whether the action is able to proceed, which in
|
|
30
|
+
// in the case of a submission will validate the fields in the page.
|
|
31
|
+
if (action.type === _models.PageAction.TYPES.SUBMIT && hub !== _models.HubFormats.TASK) {
|
|
32
|
+
setPagePoint('submit');
|
|
33
|
+
|
|
34
|
+
if (_helpers.default.canCYASubmit(pages, validate.pages)) {
|
|
35
|
+
// Submit.
|
|
36
|
+
var submissionData = _utils.default.Format.form({
|
|
37
|
+
pages: pages,
|
|
38
|
+
components: components
|
|
39
|
+
}, _objectSpread({}, data), _models.EventTypes.SUBMIT);
|
|
40
|
+
|
|
41
|
+
submissionData.formStatus = _helpers.default.getSubmissionStatus(type, pages, pageId, action, submissionData, currentTask, true);
|
|
42
|
+
setData(submissionData); // Now submit the data to the backend...
|
|
43
|
+
|
|
44
|
+
hooks.onSubmit(action.type, submissionData, function () {
|
|
45
|
+
return hooks.onFormComplete();
|
|
46
|
+
}, function (errors) {
|
|
47
|
+
return _handlers.default.submissionError(errors, addErrors);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (action.type === _models.PageAction.TYPES.SAVE_AND_CONTINUE && hub === _models.HubFormats.TASK) {
|
|
53
|
+
var shouldValidate = !(action.hasOwnProperty('validate') && !action.validate);
|
|
54
|
+
var canSubmit = shouldValidate ? _helpers.default.canCYASubmit(currentTask.fullPages, validate.pages) : true;
|
|
55
|
+
|
|
56
|
+
if (canSubmit) {
|
|
57
|
+
var _submissionData = _utils.default.Format.form({
|
|
58
|
+
pages: pages,
|
|
59
|
+
components: components
|
|
60
|
+
}, _objectSpread({}, data), _models.EventTypes.SUBMIT);
|
|
61
|
+
|
|
62
|
+
_submissionData.formStatus = _helpers.default.getSubmissionStatus(type, pages, pageId, action, _submissionData, currentTask, true);
|
|
63
|
+
setData(_submissionData);
|
|
64
|
+
hooks.onSubmit(action.type, _submissionData, function () {
|
|
65
|
+
return onPageChange(_models.FormPages.HUB);
|
|
66
|
+
}, function (errors) {
|
|
67
|
+
return _handlers.default.submissionError(errors, addErrors);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (action.type === _models.PageAction.TYPES.SUBMIT && hub === _models.HubFormats.TASK) {
|
|
73
|
+
setPagePoint('submit');
|
|
74
|
+
|
|
75
|
+
if (_helpers.default.canCYASubmit(currentTask.fullPages, validate.pages)) {
|
|
76
|
+
// Submit.
|
|
77
|
+
var _submissionData2 = _utils.default.Format.form({
|
|
78
|
+
pages: pages,
|
|
79
|
+
components: components
|
|
80
|
+
}, _objectSpread({}, data), _models.EventTypes.SUBMIT);
|
|
81
|
+
|
|
82
|
+
_submissionData2.formStatus = _helpers.default.getSubmissionStatus(type, pages, pageId, action, _submissionData2, currentTask, true);
|
|
83
|
+
setData(_submissionData2); // Now submit the data to the backend...
|
|
84
|
+
|
|
85
|
+
hooks.onSubmit(action.type, _submissionData2, function () {
|
|
86
|
+
return hooks.onFormComplete();
|
|
87
|
+
}, function (errors) {
|
|
88
|
+
return _handlers.default.submissionError(errors, addErrors);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (action.type === _models.PageAction.TYPES.SAVE_AND_RETURN) {
|
|
94
|
+
var _shouldValidate = !(action.hasOwnProperty('validate') && !action.validate);
|
|
95
|
+
|
|
96
|
+
var _canSubmit = _shouldValidate ? _helpers.default.canCYASubmit(currentTask.fullPages, validate.pages) : true;
|
|
97
|
+
|
|
98
|
+
if (_canSubmit) {
|
|
99
|
+
var _submissionData3 = _utils.default.Format.form({
|
|
100
|
+
pages: pages,
|
|
101
|
+
components: components
|
|
102
|
+
}, _objectSpread({}, data), _models.EventTypes.SUBMIT);
|
|
103
|
+
|
|
104
|
+
_submissionData3.formStatus = _helpers.default.getSubmissionStatus(type, pages, pageId, action, _submissionData3, currentTask, false);
|
|
105
|
+
setData(_submissionData3);
|
|
106
|
+
hooks.onSubmit(action.type, _submissionData3, function () {
|
|
107
|
+
if (type === _models.FormTypes.TASK) {
|
|
108
|
+
onPageChange(undefined);
|
|
109
|
+
} else {
|
|
110
|
+
onPageChange(_models.FormPages.HUB);
|
|
111
|
+
}
|
|
112
|
+
}, function (errors) {
|
|
113
|
+
return _handlers.default.submissionError(errors, addErrors);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (action.type === _models.PageAction.TYPES.NAVIGATE) {
|
|
119
|
+
var _formState$page;
|
|
120
|
+
|
|
121
|
+
onPageChange(_helpers.default.getNextPageId(type, pages, pageId, action, (_formState$page = formState.page) === null || _formState$page === void 0 ? void 0 : _formState$page.formData));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (action.type === _models.PageAction.TYPES.CANCEL) {
|
|
125
|
+
hooks.onCancel();
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
var _default = onCYAAction;
|
|
130
|
+
exports.default = _default;
|
|
@@ -0,0 +1,608 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _models = require("../../models");
|
|
4
|
+
|
|
5
|
+
var _utils = _interopRequireDefault(require("../../utils"));
|
|
6
|
+
|
|
7
|
+
var _handlers = _interopRequireDefault(require("./handlers"));
|
|
8
|
+
|
|
9
|
+
var _helpers = _interopRequireDefault(require("./helpers"));
|
|
10
|
+
|
|
11
|
+
var _onCYAAction = _interopRequireDefault(require("./onCYAAction"));
|
|
12
|
+
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
+
|
|
15
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
16
|
+
|
|
17
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
18
|
+
|
|
19
|
+
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; }
|
|
20
|
+
|
|
21
|
+
jest.mock('./handlers', function () {
|
|
22
|
+
return {
|
|
23
|
+
submissionErrorCalls: 0,
|
|
24
|
+
submissionErrorArgs: [],
|
|
25
|
+
submissionError: function submissionError(errors, addErrors) {
|
|
26
|
+
this.submissionErrorCalls++;
|
|
27
|
+
this.submissionErrorArgs.push(errors);
|
|
28
|
+
|
|
29
|
+
if (typeof addErrors === 'function') {
|
|
30
|
+
addErrors(errors);
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
reset: function reset() {
|
|
34
|
+
this.submissionErrorCalls = 0;
|
|
35
|
+
this.submissionErrorArgs = [];
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
jest.mock('./helpers', function () {
|
|
40
|
+
return {
|
|
41
|
+
canCYASubmitResult: true,
|
|
42
|
+
canCYASubmitCalls: 0,
|
|
43
|
+
canCYASubmit: function canCYASubmit() {
|
|
44
|
+
this.canCYASubmitCalls++;
|
|
45
|
+
return this.canCYASubmitResult;
|
|
46
|
+
},
|
|
47
|
+
getNextPageIdCalls: 0,
|
|
48
|
+
getNextPageId: function getNextPageId() {
|
|
49
|
+
this.getNextPageIdCalls++;
|
|
50
|
+
return 'page2';
|
|
51
|
+
},
|
|
52
|
+
getFormStateCalls: 0,
|
|
53
|
+
getFormState: function getFormState() {
|
|
54
|
+
this.getFormStateCalls++;
|
|
55
|
+
return {};
|
|
56
|
+
},
|
|
57
|
+
getSubmissionStatusCalls: 0,
|
|
58
|
+
getSubmissionStatus: function getSubmissionStatus() {
|
|
59
|
+
this.getSubmissionStatusCalls++;
|
|
60
|
+
return 'Good to go!';
|
|
61
|
+
},
|
|
62
|
+
reset: function reset() {
|
|
63
|
+
this.canCYASubmitCalls = 0;
|
|
64
|
+
this.canCYASubmitResult = true;
|
|
65
|
+
this.getFormStateCalls = 0;
|
|
66
|
+
this.getNextPageIdCalls = 0;
|
|
67
|
+
this.getFormStateCalls = 0;
|
|
68
|
+
this.getSubmissionStatusCalls = 0;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
jest.mock('../../utils', function () {
|
|
73
|
+
return {
|
|
74
|
+
Format: {
|
|
75
|
+
formCalls: 0,
|
|
76
|
+
form: function form() {
|
|
77
|
+
this.formCalls++;
|
|
78
|
+
return {
|
|
79
|
+
id: 'formId'
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
reset: function reset() {
|
|
84
|
+
this.Format.formCalls = 0;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
describe('components.FormRenderer.onCYAAction', function () {
|
|
89
|
+
var MOCK_HOOKS = {
|
|
90
|
+
onSubmitCalls: 0,
|
|
91
|
+
onSubmitArgs: [],
|
|
92
|
+
onSubmit: function onSubmit(type, payload, onSuccess, onError) {
|
|
93
|
+
this.onSubmitCalls++;
|
|
94
|
+
this.onSubmitArgs.push({
|
|
95
|
+
type: type,
|
|
96
|
+
payload: payload
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
if (typeof onSuccess === 'function') {
|
|
100
|
+
onSuccess();
|
|
101
|
+
} // onError would not normally be called alongside
|
|
102
|
+
// onSuccess, we're just doing it here to make sure
|
|
103
|
+
// the expected function chain is called.
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
if (typeof onError === 'function') {
|
|
107
|
+
onError(['an example error']);
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
onFormCompleteCalls: 0,
|
|
111
|
+
onFormComplete: function onFormComplete() {
|
|
112
|
+
this.onFormCompleteCalls++;
|
|
113
|
+
},
|
|
114
|
+
onCancelCalls: 0,
|
|
115
|
+
onCancel: function onCancel() {
|
|
116
|
+
this.onCancelCalls++;
|
|
117
|
+
},
|
|
118
|
+
reset: function reset() {
|
|
119
|
+
this.onSubmitCalls = 0;
|
|
120
|
+
this.onSubmitArgs = [];
|
|
121
|
+
this.onFormCompleteCalls = 0;
|
|
122
|
+
this.onCancelCalls = 0;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
var setPagePointCalls = 0;
|
|
126
|
+
var setPagePointArgs = [];
|
|
127
|
+
|
|
128
|
+
var mockSetPagePoint = function mockSetPagePoint(point) {
|
|
129
|
+
setPagePointCalls++;
|
|
130
|
+
setPagePointArgs.push(point);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
var setDataCalls = 0;
|
|
134
|
+
var setDataArgs = [];
|
|
135
|
+
|
|
136
|
+
var mockSetData = function mockSetData(data) {
|
|
137
|
+
setDataCalls++;
|
|
138
|
+
setDataArgs.push(data);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
var onPageChangeCalls = 0;
|
|
142
|
+
var onPageChangeArgs = [];
|
|
143
|
+
|
|
144
|
+
var mockOnPageChange = function mockOnPageChange(pageId) {
|
|
145
|
+
onPageChangeCalls++;
|
|
146
|
+
onPageChangeArgs.push(pageId);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
var addErrorsCalls = 0;
|
|
150
|
+
var addErrorsArgs = [];
|
|
151
|
+
|
|
152
|
+
var mockAddErrors = function mockAddErrors(errors) {
|
|
153
|
+
addErrorsCalls++;
|
|
154
|
+
addErrorsArgs.push(errors);
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
var COMPONENTS = [{
|
|
158
|
+
id: 'alpha',
|
|
159
|
+
fieldId: 'alpha'
|
|
160
|
+
}, {
|
|
161
|
+
id: 'bravo',
|
|
162
|
+
fieldId: 'bravo'
|
|
163
|
+
}, {
|
|
164
|
+
id: 'charlie',
|
|
165
|
+
fieldId: 'charlie'
|
|
166
|
+
}, {
|
|
167
|
+
id: 'delta',
|
|
168
|
+
fieldId: 'delta'
|
|
169
|
+
}];
|
|
170
|
+
var PAGES = [{
|
|
171
|
+
id: 'page1',
|
|
172
|
+
components: [_objectSpread({}, COMPONENTS[0]), _objectSpread({}, COMPONENTS[1])]
|
|
173
|
+
}, {
|
|
174
|
+
id: 'page2',
|
|
175
|
+
components: [_objectSpread({}, COMPONENTS[2]), _objectSpread({}, COMPONENTS[3])]
|
|
176
|
+
}];
|
|
177
|
+
var CURRENT_TASK = {
|
|
178
|
+
name: 'testTask',
|
|
179
|
+
fullPages: PAGES
|
|
180
|
+
};
|
|
181
|
+
var ARGS = {
|
|
182
|
+
setPagePoint: mockSetPagePoint,
|
|
183
|
+
action: {
|
|
184
|
+
type: _models.PageAction.TYPES.SUBMIT
|
|
185
|
+
},
|
|
186
|
+
pages: PAGES,
|
|
187
|
+
validate: function validate() {},
|
|
188
|
+
components: COMPONENTS,
|
|
189
|
+
data: {},
|
|
190
|
+
setData: mockSetData,
|
|
191
|
+
type: _models.FormTypes.FORM_WITH_TASK,
|
|
192
|
+
pageId: 'alpha',
|
|
193
|
+
currentTask: CURRENT_TASK,
|
|
194
|
+
hooks: MOCK_HOOKS,
|
|
195
|
+
addErrors: mockAddErrors,
|
|
196
|
+
hub: _models.HubFormats.TASK,
|
|
197
|
+
onPageChange: mockOnPageChange,
|
|
198
|
+
formState: _helpers.default.getFormState('alpha', PAGES, null)
|
|
199
|
+
};
|
|
200
|
+
beforeEach(function () {
|
|
201
|
+
_handlers.default.reset();
|
|
202
|
+
|
|
203
|
+
_helpers.default.reset();
|
|
204
|
+
|
|
205
|
+
_utils.default.reset();
|
|
206
|
+
|
|
207
|
+
MOCK_HOOKS.reset();
|
|
208
|
+
setPagePointCalls = 0;
|
|
209
|
+
setPagePointArgs = [];
|
|
210
|
+
setDataCalls = 0;
|
|
211
|
+
setDataArgs = [];
|
|
212
|
+
onPageChangeCalls = 0;
|
|
213
|
+
onPageChangeArgs = [];
|
|
214
|
+
addErrorsCalls = 0;
|
|
215
|
+
addErrorsArgs = [];
|
|
216
|
+
});
|
|
217
|
+
describe('with a page action of PageAction.TYPES.SUBMIT', function () {
|
|
218
|
+
it('should handle a hub format of HubFormats.CYA', function () {
|
|
219
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
220
|
+
hub: _models.HubFormats.CYA
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
_onCYAAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
224
|
+
|
|
225
|
+
expect(setPagePointCalls).toEqual(1);
|
|
226
|
+
expect(setPagePointArgs[0]).toEqual('submit');
|
|
227
|
+
expect(_helpers.default.canCYASubmitCalls).toEqual(1);
|
|
228
|
+
expect(_utils.default.Format.formCalls).toEqual(1);
|
|
229
|
+
expect(_helpers.default.getSubmissionStatusCalls).toEqual(1);
|
|
230
|
+
expect(setDataCalls).toEqual(1);
|
|
231
|
+
expect(setDataArgs[0]).toEqual({
|
|
232
|
+
id: 'formId',
|
|
233
|
+
formStatus: 'Good to go!'
|
|
234
|
+
});
|
|
235
|
+
expect(MOCK_HOOKS.onSubmitCalls).toEqual(1);
|
|
236
|
+
expect(MOCK_HOOKS.onSubmitArgs[0]).toEqual({
|
|
237
|
+
type: _models.PageAction.TYPES.SUBMIT,
|
|
238
|
+
payload: {
|
|
239
|
+
id: 'formId',
|
|
240
|
+
formStatus: 'Good to go!'
|
|
241
|
+
}
|
|
242
|
+
}); // Checking the onSuccess branch.
|
|
243
|
+
|
|
244
|
+
expect(MOCK_HOOKS.onFormCompleteCalls).toEqual(1); // Checking the onError branch.
|
|
245
|
+
|
|
246
|
+
expect(_handlers.default.submissionErrorCalls).toEqual(1);
|
|
247
|
+
expect(_handlers.default.submissionErrorArgs[0]).toEqual(['an example error']);
|
|
248
|
+
expect(addErrorsCalls).toEqual(1);
|
|
249
|
+
expect(addErrorsArgs[0]).toEqual(['an example error']);
|
|
250
|
+
});
|
|
251
|
+
it('should handle a hub format of HubFormats.TASK', function () {
|
|
252
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
253
|
+
hub: _models.HubFormats.TASK
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
_onCYAAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
257
|
+
|
|
258
|
+
expect(setPagePointCalls).toEqual(1);
|
|
259
|
+
expect(setPagePointArgs[0]).toEqual('submit');
|
|
260
|
+
expect(_helpers.default.canCYASubmitCalls).toEqual(1);
|
|
261
|
+
expect(_utils.default.Format.formCalls).toEqual(1);
|
|
262
|
+
expect(_helpers.default.getSubmissionStatusCalls).toEqual(1);
|
|
263
|
+
expect(setDataCalls).toEqual(1);
|
|
264
|
+
expect(setDataArgs[0]).toEqual({
|
|
265
|
+
id: 'formId',
|
|
266
|
+
formStatus: 'Good to go!'
|
|
267
|
+
});
|
|
268
|
+
expect(MOCK_HOOKS.onSubmitCalls).toEqual(1);
|
|
269
|
+
expect(MOCK_HOOKS.onSubmitArgs[0]).toEqual({
|
|
270
|
+
type: _models.PageAction.TYPES.SUBMIT,
|
|
271
|
+
payload: {
|
|
272
|
+
id: 'formId',
|
|
273
|
+
formStatus: 'Good to go!'
|
|
274
|
+
}
|
|
275
|
+
}); // Checking the onSuccess branch.
|
|
276
|
+
|
|
277
|
+
expect(MOCK_HOOKS.onFormCompleteCalls).toEqual(1); // Checking the onError branch.
|
|
278
|
+
|
|
279
|
+
expect(_handlers.default.submissionErrorCalls).toEqual(1);
|
|
280
|
+
expect(_handlers.default.submissionErrorArgs[0]).toEqual(['an example error']);
|
|
281
|
+
expect(addErrorsCalls).toEqual(1);
|
|
282
|
+
expect(addErrorsArgs[0]).toEqual(['an example error']);
|
|
283
|
+
});
|
|
284
|
+
it('should handle no hub', function () {
|
|
285
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
286
|
+
hub: null
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
_onCYAAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
290
|
+
|
|
291
|
+
expect(setPagePointCalls).toEqual(1);
|
|
292
|
+
expect(setPagePointArgs[0]).toEqual('submit');
|
|
293
|
+
expect(_helpers.default.canCYASubmitCalls).toEqual(1);
|
|
294
|
+
expect(_utils.default.Format.formCalls).toEqual(1);
|
|
295
|
+
expect(_helpers.default.getSubmissionStatusCalls).toEqual(1);
|
|
296
|
+
expect(setDataCalls).toEqual(1);
|
|
297
|
+
expect(setDataArgs[0]).toEqual({
|
|
298
|
+
id: 'formId',
|
|
299
|
+
formStatus: 'Good to go!'
|
|
300
|
+
});
|
|
301
|
+
expect(MOCK_HOOKS.onSubmitCalls).toEqual(1);
|
|
302
|
+
expect(MOCK_HOOKS.onSubmitArgs[0]).toEqual({
|
|
303
|
+
type: _models.PageAction.TYPES.SUBMIT,
|
|
304
|
+
payload: {
|
|
305
|
+
id: 'formId',
|
|
306
|
+
formStatus: 'Good to go!'
|
|
307
|
+
}
|
|
308
|
+
}); // Checking the onSuccess branch.
|
|
309
|
+
|
|
310
|
+
expect(MOCK_HOOKS.onFormCompleteCalls).toEqual(1); // Checking the onError branch.
|
|
311
|
+
|
|
312
|
+
expect(_handlers.default.submissionErrorCalls).toEqual(1);
|
|
313
|
+
expect(_handlers.default.submissionErrorArgs[0]).toEqual(['an example error']);
|
|
314
|
+
expect(addErrorsCalls).toEqual(1);
|
|
315
|
+
expect(addErrorsArgs[0]).toEqual(['an example error']);
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
describe('with a page action of PageAction.TYPES.SAVE_AND_CONTINUE', function () {
|
|
319
|
+
it('should validate if action.validate is not defined', function () {
|
|
320
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
321
|
+
action: {
|
|
322
|
+
type: _models.PageAction.TYPES.SAVE_AND_CONTINUE
|
|
323
|
+
},
|
|
324
|
+
hub: _models.HubFormats.TASK
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
_onCYAAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
328
|
+
|
|
329
|
+
expect(_helpers.default.canCYASubmitCalls).toEqual(1); // Validating.
|
|
330
|
+
|
|
331
|
+
expect(_utils.default.Format.formCalls).toEqual(1);
|
|
332
|
+
expect(_helpers.default.getSubmissionStatusCalls).toEqual(1);
|
|
333
|
+
expect(setDataCalls).toEqual(1);
|
|
334
|
+
expect(setDataArgs[0]).toEqual({
|
|
335
|
+
id: 'formId',
|
|
336
|
+
formStatus: 'Good to go!'
|
|
337
|
+
});
|
|
338
|
+
expect(MOCK_HOOKS.onSubmitCalls).toEqual(1);
|
|
339
|
+
expect(MOCK_HOOKS.onSubmitArgs[0]).toEqual({
|
|
340
|
+
type: CUSTOM_ARGS.action.type,
|
|
341
|
+
payload: {
|
|
342
|
+
id: 'formId',
|
|
343
|
+
formStatus: 'Good to go!'
|
|
344
|
+
}
|
|
345
|
+
}); // Checking the onSuccess branch.
|
|
346
|
+
|
|
347
|
+
expect(onPageChangeCalls).toEqual(1);
|
|
348
|
+
expect(onPageChangeArgs[0]).toEqual(_models.FormPages.HUB); // Checking the onError branch.
|
|
349
|
+
|
|
350
|
+
expect(_handlers.default.submissionErrorCalls).toEqual(1);
|
|
351
|
+
expect(_handlers.default.submissionErrorArgs[0]).toEqual(['an example error']);
|
|
352
|
+
expect(addErrorsCalls).toEqual(1);
|
|
353
|
+
expect(addErrorsArgs[0]).toEqual(['an example error']);
|
|
354
|
+
});
|
|
355
|
+
it('should validate if action.validate is true', function () {
|
|
356
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
357
|
+
action: {
|
|
358
|
+
type: _models.PageAction.TYPES.SAVE_AND_CONTINUE,
|
|
359
|
+
validate: true
|
|
360
|
+
},
|
|
361
|
+
hub: _models.HubFormats.TASK
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
_onCYAAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
365
|
+
|
|
366
|
+
expect(_helpers.default.canCYASubmitCalls).toEqual(1); // Validating.
|
|
367
|
+
|
|
368
|
+
expect(_utils.default.Format.formCalls).toEqual(1);
|
|
369
|
+
expect(_helpers.default.getSubmissionStatusCalls).toEqual(1);
|
|
370
|
+
expect(setDataCalls).toEqual(1);
|
|
371
|
+
expect(setDataArgs[0]).toEqual({
|
|
372
|
+
id: 'formId',
|
|
373
|
+
formStatus: 'Good to go!'
|
|
374
|
+
});
|
|
375
|
+
expect(MOCK_HOOKS.onSubmitCalls).toEqual(1);
|
|
376
|
+
expect(MOCK_HOOKS.onSubmitArgs[0]).toEqual({
|
|
377
|
+
type: CUSTOM_ARGS.action.type,
|
|
378
|
+
payload: {
|
|
379
|
+
id: 'formId',
|
|
380
|
+
formStatus: 'Good to go!'
|
|
381
|
+
}
|
|
382
|
+
}); // Checking the onSuccess branch.
|
|
383
|
+
|
|
384
|
+
expect(onPageChangeCalls).toEqual(1);
|
|
385
|
+
expect(onPageChangeArgs[0]).toEqual(_models.FormPages.HUB); // Checking the onError branch.
|
|
386
|
+
|
|
387
|
+
expect(_handlers.default.submissionErrorCalls).toEqual(1);
|
|
388
|
+
expect(_handlers.default.submissionErrorArgs[0]).toEqual(['an example error']);
|
|
389
|
+
expect(addErrorsCalls).toEqual(1);
|
|
390
|
+
expect(addErrorsArgs[0]).toEqual(['an example error']);
|
|
391
|
+
});
|
|
392
|
+
it('should not validate if action.validate is false', function () {
|
|
393
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
394
|
+
action: {
|
|
395
|
+
type: _models.PageAction.TYPES.SAVE_AND_CONTINUE,
|
|
396
|
+
validate: false
|
|
397
|
+
},
|
|
398
|
+
hub: _models.HubFormats.TASK
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
_onCYAAction.default.apply(void 0, Object.values(CUSTOM_ARGS)); // Validation.
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
expect(_helpers.default.canCYASubmitCalls).toEqual(0); // Everything after this point should be normal, we just
|
|
405
|
+
// haven't validated this time round.
|
|
406
|
+
|
|
407
|
+
expect(_utils.default.Format.formCalls).toEqual(1);
|
|
408
|
+
expect(_helpers.default.getSubmissionStatusCalls).toEqual(1);
|
|
409
|
+
expect(setDataCalls).toEqual(1);
|
|
410
|
+
expect(setDataArgs[0]).toEqual({
|
|
411
|
+
id: 'formId',
|
|
412
|
+
formStatus: 'Good to go!'
|
|
413
|
+
});
|
|
414
|
+
expect(MOCK_HOOKS.onSubmitCalls).toEqual(1);
|
|
415
|
+
expect(MOCK_HOOKS.onSubmitArgs[0]).toEqual({
|
|
416
|
+
type: CUSTOM_ARGS.action.type,
|
|
417
|
+
payload: {
|
|
418
|
+
id: 'formId',
|
|
419
|
+
formStatus: 'Good to go!'
|
|
420
|
+
}
|
|
421
|
+
}); // Checking the onSuccess branch.
|
|
422
|
+
|
|
423
|
+
expect(onPageChangeCalls).toEqual(1);
|
|
424
|
+
expect(onPageChangeArgs[0]).toEqual(_models.FormPages.HUB); // Checking the onError branch.
|
|
425
|
+
|
|
426
|
+
expect(_handlers.default.submissionErrorCalls).toEqual(1);
|
|
427
|
+
expect(_handlers.default.submissionErrorArgs[0]).toEqual(['an example error']);
|
|
428
|
+
expect(addErrorsCalls).toEqual(1);
|
|
429
|
+
expect(addErrorsArgs[0]).toEqual(['an example error']);
|
|
430
|
+
});
|
|
431
|
+
});
|
|
432
|
+
describe('with an action type of PageAction.TYPES.SAVE_AND_RETURN', function () {
|
|
433
|
+
it('should validate if action.validate is not defined', function () {
|
|
434
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
435
|
+
action: {
|
|
436
|
+
type: _models.PageAction.TYPES.SAVE_AND_RETURN
|
|
437
|
+
},
|
|
438
|
+
hub: _models.HubFormats.TASK
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
_onCYAAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
442
|
+
|
|
443
|
+
expect(_helpers.default.canCYASubmitCalls).toEqual(1); // Validating.
|
|
444
|
+
|
|
445
|
+
expect(_utils.default.Format.formCalls).toEqual(1);
|
|
446
|
+
expect(_helpers.default.getSubmissionStatusCalls).toEqual(1);
|
|
447
|
+
expect(setDataCalls).toEqual(1);
|
|
448
|
+
expect(setDataArgs[0]).toEqual({
|
|
449
|
+
id: 'formId',
|
|
450
|
+
formStatus: 'Good to go!'
|
|
451
|
+
});
|
|
452
|
+
expect(MOCK_HOOKS.onSubmitCalls).toEqual(1);
|
|
453
|
+
expect(MOCK_HOOKS.onSubmitArgs[0]).toEqual({
|
|
454
|
+
type: CUSTOM_ARGS.action.type,
|
|
455
|
+
payload: {
|
|
456
|
+
id: 'formId',
|
|
457
|
+
formStatus: 'Good to go!'
|
|
458
|
+
}
|
|
459
|
+
}); // Checking the onSuccess branch.
|
|
460
|
+
|
|
461
|
+
expect(onPageChangeCalls).toEqual(1);
|
|
462
|
+
expect(onPageChangeArgs[0]).toEqual(_models.FormPages.HUB); // Checking the onError branch.
|
|
463
|
+
|
|
464
|
+
expect(_handlers.default.submissionErrorCalls).toEqual(1);
|
|
465
|
+
expect(_handlers.default.submissionErrorArgs[0]).toEqual(['an example error']);
|
|
466
|
+
expect(addErrorsCalls).toEqual(1);
|
|
467
|
+
expect(addErrorsArgs[0]).toEqual(['an example error']);
|
|
468
|
+
});
|
|
469
|
+
it('should validate if action.validate is true', function () {
|
|
470
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
471
|
+
action: {
|
|
472
|
+
type: _models.PageAction.TYPES.SAVE_AND_RETURN,
|
|
473
|
+
validate: true
|
|
474
|
+
},
|
|
475
|
+
hub: _models.HubFormats.TASK
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
_onCYAAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
479
|
+
|
|
480
|
+
expect(_helpers.default.canCYASubmitCalls).toEqual(1); // Validating.
|
|
481
|
+
|
|
482
|
+
expect(_utils.default.Format.formCalls).toEqual(1);
|
|
483
|
+
expect(_helpers.default.getSubmissionStatusCalls).toEqual(1);
|
|
484
|
+
expect(setDataCalls).toEqual(1);
|
|
485
|
+
expect(setDataArgs[0]).toEqual({
|
|
486
|
+
id: 'formId',
|
|
487
|
+
formStatus: 'Good to go!'
|
|
488
|
+
});
|
|
489
|
+
expect(MOCK_HOOKS.onSubmitCalls).toEqual(1);
|
|
490
|
+
expect(MOCK_HOOKS.onSubmitArgs[0]).toEqual({
|
|
491
|
+
type: CUSTOM_ARGS.action.type,
|
|
492
|
+
payload: {
|
|
493
|
+
id: 'formId',
|
|
494
|
+
formStatus: 'Good to go!'
|
|
495
|
+
}
|
|
496
|
+
}); // Checking the onSuccess branch.
|
|
497
|
+
|
|
498
|
+
expect(onPageChangeCalls).toEqual(1);
|
|
499
|
+
expect(onPageChangeArgs[0]).toEqual(_models.FormPages.HUB); // Checking the onError branch.
|
|
500
|
+
|
|
501
|
+
expect(_handlers.default.submissionErrorCalls).toEqual(1);
|
|
502
|
+
expect(_handlers.default.submissionErrorArgs[0]).toEqual(['an example error']);
|
|
503
|
+
expect(addErrorsCalls).toEqual(1);
|
|
504
|
+
expect(addErrorsArgs[0]).toEqual(['an example error']);
|
|
505
|
+
});
|
|
506
|
+
it('should not validate if action.validate is false', function () {
|
|
507
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
508
|
+
action: {
|
|
509
|
+
type: _models.PageAction.TYPES.SAVE_AND_RETURN,
|
|
510
|
+
validate: false
|
|
511
|
+
},
|
|
512
|
+
hub: _models.HubFormats.TASK
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
_onCYAAction.default.apply(void 0, Object.values(CUSTOM_ARGS)); // Validation.
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
expect(_helpers.default.canCYASubmitCalls).toEqual(0); // Everything after this point should be normal, we just
|
|
519
|
+
// haven't validated this time round.
|
|
520
|
+
|
|
521
|
+
expect(_utils.default.Format.formCalls).toEqual(1);
|
|
522
|
+
expect(_helpers.default.getSubmissionStatusCalls).toEqual(1);
|
|
523
|
+
expect(setDataCalls).toEqual(1);
|
|
524
|
+
expect(setDataArgs[0]).toEqual({
|
|
525
|
+
id: 'formId',
|
|
526
|
+
formStatus: 'Good to go!'
|
|
527
|
+
});
|
|
528
|
+
expect(MOCK_HOOKS.onSubmitCalls).toEqual(1);
|
|
529
|
+
expect(MOCK_HOOKS.onSubmitArgs[0]).toEqual({
|
|
530
|
+
type: CUSTOM_ARGS.action.type,
|
|
531
|
+
payload: {
|
|
532
|
+
id: 'formId',
|
|
533
|
+
formStatus: 'Good to go!'
|
|
534
|
+
}
|
|
535
|
+
}); // Checking the onSuccess branch.
|
|
536
|
+
|
|
537
|
+
expect(onPageChangeCalls).toEqual(1);
|
|
538
|
+
expect(onPageChangeArgs[0]).toEqual(_models.FormPages.HUB); // Checking the onError branch.
|
|
539
|
+
|
|
540
|
+
expect(_handlers.default.submissionErrorCalls).toEqual(1);
|
|
541
|
+
expect(_handlers.default.submissionErrorArgs[0]).toEqual(['an example error']);
|
|
542
|
+
expect(addErrorsCalls).toEqual(1);
|
|
543
|
+
expect(addErrorsArgs[0]).toEqual(['an example error']);
|
|
544
|
+
});
|
|
545
|
+
it('should call onPageChange with undefined if type is FormTypes.TASK', function () {
|
|
546
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
547
|
+
action: {
|
|
548
|
+
type: _models.PageAction.TYPES.SAVE_AND_RETURN,
|
|
549
|
+
validate: true
|
|
550
|
+
},
|
|
551
|
+
hub: _models.HubFormats.TASK,
|
|
552
|
+
type: _models.FormTypes.TASK
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
_onCYAAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
556
|
+
|
|
557
|
+
expect(_helpers.default.canCYASubmitCalls).toEqual(1); // Validating.
|
|
558
|
+
|
|
559
|
+
expect(_utils.default.Format.formCalls).toEqual(1);
|
|
560
|
+
expect(_helpers.default.getSubmissionStatusCalls).toEqual(1);
|
|
561
|
+
expect(setDataCalls).toEqual(1);
|
|
562
|
+
expect(setDataArgs[0]).toEqual({
|
|
563
|
+
id: 'formId',
|
|
564
|
+
formStatus: 'Good to go!'
|
|
565
|
+
});
|
|
566
|
+
expect(MOCK_HOOKS.onSubmitCalls).toEqual(1);
|
|
567
|
+
expect(MOCK_HOOKS.onSubmitArgs[0]).toEqual({
|
|
568
|
+
type: CUSTOM_ARGS.action.type,
|
|
569
|
+
payload: {
|
|
570
|
+
id: 'formId',
|
|
571
|
+
formStatus: 'Good to go!'
|
|
572
|
+
}
|
|
573
|
+
}); // Checking the onSuccess branch.
|
|
574
|
+
|
|
575
|
+
expect(onPageChangeCalls).toEqual(1);
|
|
576
|
+
expect(onPageChangeArgs[0]).toEqual(undefined); // Checking the onError branch.
|
|
577
|
+
|
|
578
|
+
expect(_handlers.default.submissionErrorCalls).toEqual(1);
|
|
579
|
+
expect(_handlers.default.submissionErrorArgs[0]).toEqual(['an example error']);
|
|
580
|
+
expect(addErrorsCalls).toEqual(1);
|
|
581
|
+
expect(addErrorsArgs[0]).toEqual(['an example error']);
|
|
582
|
+
});
|
|
583
|
+
});
|
|
584
|
+
it('should handle a page action type of PageAction.TYPES.NAVIGATE', function () {
|
|
585
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
586
|
+
action: {
|
|
587
|
+
type: _models.PageAction.TYPES.NAVIGATE,
|
|
588
|
+
page: 'page2'
|
|
589
|
+
}
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
_onCYAAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
593
|
+
|
|
594
|
+
expect(onPageChangeCalls).toEqual(1);
|
|
595
|
+
expect(onPageChangeArgs[0]).toEqual('page2');
|
|
596
|
+
});
|
|
597
|
+
it('should handle a page action type of PageAction.TYPES.CANCEL', function () {
|
|
598
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
599
|
+
action: {
|
|
600
|
+
type: _models.PageAction.TYPES.CANCEL
|
|
601
|
+
}
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
_onCYAAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
605
|
+
|
|
606
|
+
expect(MOCK_HOOKS.onCancelCalls).toEqual(1);
|
|
607
|
+
});
|
|
608
|
+
});
|
|
@@ -14,9 +14,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
14
14
|
// Global imports.
|
|
15
15
|
// Local imports.
|
|
16
16
|
var getFirstOf = function getFirstOf(config, data) {
|
|
17
|
-
var fieldValue;
|
|
18
|
-
|
|
19
17
|
if (config !== null && config !== void 0 && config.fields) {
|
|
18
|
+
var fieldValue;
|
|
20
19
|
config.fields.find(function (field) {
|
|
21
20
|
var fieldPath = _copReactComponents.Utils.interpolateString(field, data);
|
|
22
21
|
|
|
@@ -29,7 +28,7 @@ var getFirstOf = function getFirstOf(config, data) {
|
|
|
29
28
|
|
|
30
29
|
return false;
|
|
31
30
|
});
|
|
32
|
-
return fieldValue || '';
|
|
31
|
+
return fieldValue || (config.fallback ? _copReactComponents.Utils.interpolateString(config.fallback, data) : '');
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
return (config === null || config === void 0 ? void 0 : config.value) || null;
|
|
@@ -29,6 +29,15 @@ describe('Utils.Operate.addToFormData', function () {
|
|
|
29
29
|
var result = (0, _getFirstOf.default)(CONFIG, DATA);
|
|
30
30
|
expect(result).toEqual(CONFIG.value);
|
|
31
31
|
});
|
|
32
|
+
it('Should return the fallback if the requested fields are not found', function () {
|
|
33
|
+
var CONFIG = {
|
|
34
|
+
value: '2',
|
|
35
|
+
fields: ['nonExistent'],
|
|
36
|
+
fallback: "Test ${name}"
|
|
37
|
+
};
|
|
38
|
+
var result = (0, _getFirstOf.default)(CONFIG, DATA);
|
|
39
|
+
expect(result).toEqual("Test ".concat(DATA.name));
|
|
40
|
+
});
|
|
32
41
|
it('Should return the value of the passportNumber field given in config', function () {
|
|
33
42
|
var CONFIG = {
|
|
34
43
|
fields: ['passportNumber', 'anotherMadeUpId', 'otherIdDoc']
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ukhomeoffice/cop-react-form-renderer",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.65.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"clean": "rimraf dist",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"post-compile": "rimraf dist/*.test.* dist/**/*.test.* dist/**/*.stories.* dist/docs dist/assets"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@ukhomeoffice/cop-react-components": "^2.11.
|
|
19
|
+
"@ukhomeoffice/cop-react-components": "^2.11.2",
|
|
20
20
|
"axios": "^0.23.0",
|
|
21
21
|
"dayjs": "^1.11.0",
|
|
22
22
|
"govuk-frontend": "^4.3.1",
|