@ukhomeoffice/cop-react-form-renderer 3.25.0 → 3.26.2
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.
|
@@ -152,6 +152,7 @@ var FormComponent = function FormComponent(_ref) {
|
|
|
152
152
|
content: _utils.default.interpolateString(component.content, formData),
|
|
153
153
|
hint: _utils.default.interpolateString(component.hint, formData),
|
|
154
154
|
cya_label: _utils.default.interpolateString(component.cya_label, formData),
|
|
155
|
+
suffix: _utils.default.interpolateString(component.suffix, formData),
|
|
155
156
|
options: options,
|
|
156
157
|
value: value || _utils.default.Component.defaultValue(component),
|
|
157
158
|
onChange: onComponentChangeExtended,
|
|
@@ -101,7 +101,7 @@ var DEFAULT_CLASS = 'hods-form';
|
|
|
101
101
|
exports.DEFAULT_CLASS = DEFAULT_CLASS;
|
|
102
102
|
|
|
103
103
|
var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
104
|
-
var _formState$
|
|
104
|
+
var _formState$page3;
|
|
105
105
|
|
|
106
106
|
var title = _ref2.title,
|
|
107
107
|
type = _ref2.type,
|
|
@@ -160,7 +160,7 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
160
160
|
hubDetails = _useState16[0],
|
|
161
161
|
setHubDetails = _useState16[1];
|
|
162
162
|
|
|
163
|
-
var _useState17 = (0, _react.useState)('
|
|
163
|
+
var _useState17 = (0, _react.useState)('load'),
|
|
164
164
|
_useState18 = _slicedToArray(_useState17, 2),
|
|
165
165
|
pagePoint = _useState18[0],
|
|
166
166
|
setPagePoint = _useState18[1]; // Set up hooks.
|
|
@@ -173,11 +173,25 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
173
173
|
var _useValidation = (0, _hooks.useValidation)(),
|
|
174
174
|
addErrors = _useValidation.addErrors,
|
|
175
175
|
clearErrors = _useValidation.clearErrors,
|
|
176
|
-
validate = _useValidation.validate; //
|
|
176
|
+
validate = _useValidation.validate; // Need to set submission data when going back
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
window.onpopstate = function () {
|
|
180
|
+
var _formState$page;
|
|
181
|
+
|
|
182
|
+
if (components && pages && data && (_formState$page = formState.page) !== null && _formState$page !== void 0 && _formState$page.formData && pagePoint === undefined) {
|
|
183
|
+
var submissionData = _utils.default.Format.form({
|
|
184
|
+
pages: pages,
|
|
185
|
+
components: components
|
|
186
|
+
}, _objectSpread(_objectSpread({}, data), formState.page.formData), _models.EventTypes.SUBMIT);
|
|
187
|
+
|
|
188
|
+
setData(submissionData);
|
|
189
|
+
}
|
|
190
|
+
}; // Setup data.
|
|
177
191
|
|
|
178
192
|
|
|
179
193
|
(0, _react.useEffect)(function () {
|
|
180
|
-
if (components && _pages && _data && (['
|
|
194
|
+
if (components && _pages && _data && (['load', 'submit'].includes(pagePoint) || viewOnly)) {
|
|
181
195
|
var _data$formStatus;
|
|
182
196
|
|
|
183
197
|
setData(_utils.default.Data.setupForm(_pages, components, _data));
|
|
@@ -279,7 +293,7 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
279
293
|
_handlers.default.navigate(action, pageId, onPageChange);
|
|
280
294
|
} else {
|
|
281
295
|
if (action.type === 'submit') {
|
|
282
|
-
setPagePoint('
|
|
296
|
+
setPagePoint('submit');
|
|
283
297
|
} // Save draft or submit.
|
|
284
298
|
|
|
285
299
|
|
|
@@ -358,7 +372,7 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
358
372
|
// Check to see whether the action is able to proceed, which in
|
|
359
373
|
// in the case of a submission will validate the fields in the page.
|
|
360
374
|
if (action.type === _models.PageAction.TYPES.SUBMIT) {
|
|
361
|
-
setPagePoint('
|
|
375
|
+
setPagePoint('submit');
|
|
362
376
|
|
|
363
377
|
if (_helpers.default.canCYASubmit(pages, validate.pages)) {
|
|
364
378
|
// Submit.
|
|
@@ -417,9 +431,9 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
417
431
|
}
|
|
418
432
|
|
|
419
433
|
if (action.type === _models.PageAction.TYPES.NAVIGATE) {
|
|
420
|
-
var _formState$
|
|
434
|
+
var _formState$page2;
|
|
421
435
|
|
|
422
|
-
onPageChange(_helpers.default.getNextPageId(type, pages, pageId, action, (_formState$
|
|
436
|
+
onPageChange(_helpers.default.getNextPageId(type, pages, pageId, action, (_formState$page2 = formState.page) === null || _formState$page2 === void 0 ? void 0 : _formState$page2.formData));
|
|
423
437
|
}
|
|
424
438
|
|
|
425
439
|
if (action.type === _models.PageAction.TYPES.CANCEL) {
|
|
@@ -437,7 +451,7 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
437
451
|
className: classes()
|
|
438
452
|
}, title && !hide_title && pageId === _models.FormPages.HUB && /*#__PURE__*/_react.default.createElement(_copReactComponents.LargeHeading, null, title), formState.cya && /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, _extends({
|
|
439
453
|
pages: _helpers.default.getRelevantPages(formState, pages, currentTask.fullPages)
|
|
440
|
-
}, cya, ((_formState$
|
|
454
|
+
}, cya, ((_formState$page3 = formState.page) === null || _formState$page3 === void 0 ? void 0 : _formState$page3.type) === _models.FormPages.PARTIAL_CYA && {
|
|
441
455
|
actions: formState.page.actions
|
|
442
456
|
}, formState.cya, {
|
|
443
457
|
onAction: onCYAAction,
|
|
@@ -34,6 +34,8 @@ var _userProfile = _interopRequireDefault(require("../../json/userProfile.json")
|
|
|
34
34
|
|
|
35
35
|
var _taskList = _interopRequireDefault(require("../../json/taskList.json"));
|
|
36
36
|
|
|
37
|
+
var _firstForm = _interopRequireDefault(require("../../json/firstForm.json"));
|
|
38
|
+
|
|
37
39
|
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); }
|
|
38
40
|
|
|
39
41
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -548,11 +550,44 @@ describe('components', function () {
|
|
|
548
550
|
}
|
|
549
551
|
}, _callee16);
|
|
550
552
|
})));
|
|
551
|
-
it('should
|
|
552
|
-
var
|
|
553
|
+
it('should render a cya page', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee18() {
|
|
554
|
+
var cya;
|
|
553
555
|
return regeneratorRuntime.wrap(function _callee18$(_context18) {
|
|
554
556
|
while (1) {
|
|
555
557
|
switch (_context18.prev = _context18.next) {
|
|
558
|
+
case 0:
|
|
559
|
+
_context18.next = 2;
|
|
560
|
+
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee17() {
|
|
561
|
+
return regeneratorRuntime.wrap(function _callee17$(_context17) {
|
|
562
|
+
while (1) {
|
|
563
|
+
switch (_context17.prev = _context17.next) {
|
|
564
|
+
case 0:
|
|
565
|
+
(0, _reactDom.render)( /*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _firstForm.default), container);
|
|
566
|
+
|
|
567
|
+
case 1:
|
|
568
|
+
case "end":
|
|
569
|
+
return _context17.stop();
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
}, _callee17);
|
|
573
|
+
})));
|
|
574
|
+
|
|
575
|
+
case 2:
|
|
576
|
+
cya = container.childNodes[0];
|
|
577
|
+
expect(cya.classList).toContain('hods-form');
|
|
578
|
+
|
|
579
|
+
case 4:
|
|
580
|
+
case "end":
|
|
581
|
+
return _context18.stop();
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
}, _callee18);
|
|
585
|
+
})));
|
|
586
|
+
it('should handle navigating between task list pages', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee20() {
|
|
587
|
+
var ON_SUBMIT_CALLS, ON_SUBMIT, HOOKS, taskList, firstTaskStatus, secondTaskStatus, firstTask, newPage, continueButton, cyaPageChange, modeChangeLink, changePage, cyaPage, finalSubmit;
|
|
588
|
+
return regeneratorRuntime.wrap(function _callee20$(_context20) {
|
|
589
|
+
while (1) {
|
|
590
|
+
switch (_context20.prev = _context20.next) {
|
|
556
591
|
case 0:
|
|
557
592
|
ON_SUBMIT_CALLS = [];
|
|
558
593
|
|
|
@@ -564,11 +599,11 @@ describe('components', function () {
|
|
|
564
599
|
HOOKS = {
|
|
565
600
|
onSubmit: ON_SUBMIT
|
|
566
601
|
};
|
|
567
|
-
|
|
568
|
-
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function
|
|
569
|
-
return regeneratorRuntime.wrap(function
|
|
602
|
+
_context20.next = 5;
|
|
603
|
+
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee19() {
|
|
604
|
+
return regeneratorRuntime.wrap(function _callee19$(_context19) {
|
|
570
605
|
while (1) {
|
|
571
|
-
switch (
|
|
606
|
+
switch (_context19.prev = _context19.next) {
|
|
572
607
|
case 0:
|
|
573
608
|
(0, _reactDom.render)( /*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, _taskList.default, {
|
|
574
609
|
hooks: HOOKS
|
|
@@ -576,10 +611,10 @@ describe('components', function () {
|
|
|
576
611
|
|
|
577
612
|
case 1:
|
|
578
613
|
case "end":
|
|
579
|
-
return
|
|
614
|
+
return _context19.stop();
|
|
580
615
|
}
|
|
581
616
|
}
|
|
582
|
-
},
|
|
617
|
+
}, _callee19);
|
|
583
618
|
})));
|
|
584
619
|
|
|
585
620
|
case 5:
|
|
@@ -632,6 +667,22 @@ describe('components', function () {
|
|
|
632
667
|
|
|
633
668
|
continueButton = newPage.childNodes[2].childNodes[0];
|
|
634
669
|
|
|
670
|
+
_react.fireEvent.click(continueButton, {}); //Click change to mode on CYA page
|
|
671
|
+
|
|
672
|
+
|
|
673
|
+
cyaPageChange = container.childNodes[0].childNodes[0];
|
|
674
|
+
modeChangeLink = cyaPageChange.childNodes[4].childNodes[0].childNodes[0].childNodes[2].childNodes[0].childNodes[0];
|
|
675
|
+
|
|
676
|
+
_react.fireEvent.click(modeChangeLink, {});
|
|
677
|
+
|
|
678
|
+
changePage = container.childNodes[0].childNodes[0];
|
|
679
|
+
expect(changePage.childNodes[0].textContent).toEqual('Event Mode'); // Click on radio for 'Air'
|
|
680
|
+
|
|
681
|
+
_react.fireEvent.click(changePage.childNodes[1].childNodes[2].childNodes[1].childNodes[0], {}); // Continue again to CYA page
|
|
682
|
+
|
|
683
|
+
|
|
684
|
+
continueButton = changePage.childNodes[2].childNodes[0];
|
|
685
|
+
|
|
635
686
|
_react.fireEvent.click(continueButton, {}); //Continue on from CYA page
|
|
636
687
|
|
|
637
688
|
|
|
@@ -652,21 +703,21 @@ describe('components', function () {
|
|
|
652
703
|
|
|
653
704
|
finalSubmit = ON_SUBMIT_CALLS[ON_SUBMIT_CALLS.length - 1];
|
|
654
705
|
expect(finalSubmit.date).toEqual('7-7-2022');
|
|
655
|
-
expect(finalSubmit.mode).toEqual('
|
|
706
|
+
expect(finalSubmit.mode).toEqual('air');
|
|
656
707
|
expect(finalSubmit.formStatus.tasks['Date, location and mode details'].complete).toEqual(true);
|
|
657
708
|
|
|
658
|
-
case
|
|
709
|
+
case 47:
|
|
659
710
|
case "end":
|
|
660
|
-
return
|
|
711
|
+
return _context20.stop();
|
|
661
712
|
}
|
|
662
713
|
}
|
|
663
|
-
},
|
|
714
|
+
}, _callee20);
|
|
664
715
|
})));
|
|
665
|
-
it('should go straight to CYA page if a complete task is selected', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function
|
|
716
|
+
it('should go straight to CYA page if a complete task is selected', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee22() {
|
|
666
717
|
var ON_SUBMIT, HOOKS, taskList, newPage;
|
|
667
|
-
return regeneratorRuntime.wrap(function
|
|
718
|
+
return regeneratorRuntime.wrap(function _callee22$(_context22) {
|
|
668
719
|
while (1) {
|
|
669
|
-
switch (
|
|
720
|
+
switch (_context22.prev = _context22.next) {
|
|
670
721
|
case 0:
|
|
671
722
|
ON_SUBMIT = function ON_SUBMIT(type, payload, onSuccess, onError) {
|
|
672
723
|
onSuccess();
|
|
@@ -675,11 +726,11 @@ describe('components', function () {
|
|
|
675
726
|
HOOKS = {
|
|
676
727
|
onSubmit: ON_SUBMIT
|
|
677
728
|
};
|
|
678
|
-
|
|
679
|
-
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function
|
|
680
|
-
return regeneratorRuntime.wrap(function
|
|
729
|
+
_context22.next = 4;
|
|
730
|
+
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee21() {
|
|
731
|
+
return regeneratorRuntime.wrap(function _callee21$(_context21) {
|
|
681
732
|
while (1) {
|
|
682
|
-
switch (
|
|
733
|
+
switch (_context21.prev = _context21.next) {
|
|
683
734
|
case 0:
|
|
684
735
|
(0, _reactDom.render)( /*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, _taskList.default, {
|
|
685
736
|
hooks: HOOKS
|
|
@@ -687,10 +738,10 @@ describe('components', function () {
|
|
|
687
738
|
|
|
688
739
|
case 1:
|
|
689
740
|
case "end":
|
|
690
|
-
return
|
|
741
|
+
return _context21.stop();
|
|
691
742
|
}
|
|
692
743
|
}
|
|
693
|
-
},
|
|
744
|
+
}, _callee21);
|
|
694
745
|
})));
|
|
695
746
|
|
|
696
747
|
case 4:
|
|
@@ -742,16 +793,16 @@ describe('components', function () {
|
|
|
742
793
|
|
|
743
794
|
case 17:
|
|
744
795
|
case "end":
|
|
745
|
-
return
|
|
796
|
+
return _context22.stop();
|
|
746
797
|
}
|
|
747
798
|
}
|
|
748
|
-
},
|
|
799
|
+
}, _callee22);
|
|
749
800
|
})));
|
|
750
|
-
it('should go to the last page of a complete task if noTaskCYAs specified', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function
|
|
801
|
+
it('should go to the last page of a complete task if noTaskCYAs specified', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee24() {
|
|
751
802
|
var ON_SUBMIT, HOOKS, TASK_LIST_WITH_NO_TASK_CYAS, taskList, newPage;
|
|
752
|
-
return regeneratorRuntime.wrap(function
|
|
803
|
+
return regeneratorRuntime.wrap(function _callee24$(_context24) {
|
|
753
804
|
while (1) {
|
|
754
|
-
switch (
|
|
805
|
+
switch (_context24.prev = _context24.next) {
|
|
755
806
|
case 0:
|
|
756
807
|
ON_SUBMIT = function ON_SUBMIT(type, payload, onSuccess, onError) {
|
|
757
808
|
onSuccess();
|
|
@@ -766,11 +817,11 @@ describe('components', function () {
|
|
|
766
817
|
type: 'save',
|
|
767
818
|
complete: true
|
|
768
819
|
};
|
|
769
|
-
|
|
770
|
-
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function
|
|
771
|
-
return regeneratorRuntime.wrap(function
|
|
820
|
+
_context24.next = 7;
|
|
821
|
+
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee23() {
|
|
822
|
+
return regeneratorRuntime.wrap(function _callee23$(_context23) {
|
|
772
823
|
while (1) {
|
|
773
|
-
switch (
|
|
824
|
+
switch (_context23.prev = _context23.next) {
|
|
774
825
|
case 0:
|
|
775
826
|
(0, _reactDom.render)( /*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, TASK_LIST_WITH_NO_TASK_CYAS, {
|
|
776
827
|
hooks: HOOKS
|
|
@@ -778,10 +829,10 @@ describe('components', function () {
|
|
|
778
829
|
|
|
779
830
|
case 1:
|
|
780
831
|
case "end":
|
|
781
|
-
return
|
|
832
|
+
return _context23.stop();
|
|
782
833
|
}
|
|
783
834
|
}
|
|
784
|
-
},
|
|
835
|
+
}, _callee23);
|
|
785
836
|
})));
|
|
786
837
|
|
|
787
838
|
case 7:
|
|
@@ -830,17 +881,17 @@ describe('components', function () {
|
|
|
830
881
|
|
|
831
882
|
case 19:
|
|
832
883
|
case "end":
|
|
833
|
-
return
|
|
884
|
+
return _context24.stop();
|
|
834
885
|
}
|
|
835
886
|
}
|
|
836
|
-
},
|
|
887
|
+
}, _callee24);
|
|
837
888
|
})));
|
|
838
|
-
it('should handle cancellation from a page', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function
|
|
889
|
+
it('should handle cancellation from a page', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee26() {
|
|
839
890
|
var ON_CANCEL_CALLS, ON_CANCEL, HOOKS, form, hub, _hub$childNodes5, civilServantList, link, page, cancel;
|
|
840
891
|
|
|
841
|
-
return regeneratorRuntime.wrap(function
|
|
892
|
+
return regeneratorRuntime.wrap(function _callee26$(_context26) {
|
|
842
893
|
while (1) {
|
|
843
|
-
switch (
|
|
894
|
+
switch (_context26.prev = _context26.next) {
|
|
844
895
|
case 0:
|
|
845
896
|
ON_CANCEL_CALLS = [];
|
|
846
897
|
|
|
@@ -851,11 +902,11 @@ describe('components', function () {
|
|
|
851
902
|
HOOKS = {
|
|
852
903
|
onCancel: ON_CANCEL
|
|
853
904
|
};
|
|
854
|
-
|
|
855
|
-
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function
|
|
856
|
-
return regeneratorRuntime.wrap(function
|
|
905
|
+
_context26.next = 5;
|
|
906
|
+
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee25() {
|
|
907
|
+
return regeneratorRuntime.wrap(function _callee25$(_context25) {
|
|
857
908
|
while (1) {
|
|
858
|
-
switch (
|
|
909
|
+
switch (_context25.prev = _context25.next) {
|
|
859
910
|
case 0:
|
|
860
911
|
(0, _reactDom.render)( /*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, _userProfile.default, {
|
|
861
912
|
data: _userProfileData.default,
|
|
@@ -864,10 +915,10 @@ describe('components', function () {
|
|
|
864
915
|
|
|
865
916
|
case 1:
|
|
866
917
|
case "end":
|
|
867
|
-
return
|
|
918
|
+
return _context25.stop();
|
|
868
919
|
}
|
|
869
920
|
}
|
|
870
|
-
},
|
|
921
|
+
}, _callee25);
|
|
871
922
|
})));
|
|
872
923
|
|
|
873
924
|
case 5:
|
|
@@ -891,10 +942,10 @@ describe('components', function () {
|
|
|
891
942
|
|
|
892
943
|
case 15:
|
|
893
944
|
case "end":
|
|
894
|
-
return
|
|
945
|
+
return _context26.stop();
|
|
895
946
|
}
|
|
896
947
|
}
|
|
897
|
-
},
|
|
948
|
+
}, _callee26);
|
|
898
949
|
})));
|
|
899
950
|
});
|
|
900
951
|
});
|