@ukhomeoffice/cop-react-form-renderer 5.26.1 → 5.27.1
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/CheckYourAnswers.js +3 -3
- package/dist/components/CollectionPage/CollectionPage.test.js +2 -1
- package/dist/components/FormComponent/Collection.js +3 -1
- package/dist/components/FormPage/FormPage.js +1 -1
- package/dist/components/FormPage/FormPage.test.js +2 -1
- package/dist/components/FormRenderer/FormRenderer.test.js +38 -63
- package/dist/utils/Component/getComponentTests/getComponent.date.test.js +37 -37
- package/dist/utils/Component/getComponentTests/getComponent.nested.test.js +3 -3
- package/dist/utils/Component/getComponentTests/getComponent.time.test.js +1 -1
- package/dist/utils/FormPage/getPageTitle.js +33 -0
- package/dist/utils/FormPage/getPageTitle.test.js +116 -0
- package/dist/utils/FormPage/index.js +2 -0
- package/package.json +2 -2
|
@@ -135,14 +135,14 @@ var CheckYourAnswers = function CheckYourAnswers(_ref) {
|
|
|
135
135
|
var getPageHeading = function getPageHeading(page, size) {
|
|
136
136
|
var _page$cya_link;
|
|
137
137
|
if (!((_page$cya_link = page.cya_link) !== null && _page$cya_link !== void 0 && _page$cya_link.singleChangeLink) || noChangeAction) {
|
|
138
|
-
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, size === 's' && /*#__PURE__*/_react.default.createElement(_copReactComponents.SmallHeading, null, _utils.default.
|
|
138
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, size === 's' && /*#__PURE__*/_react.default.createElement(_copReactComponents.SmallHeading, null, _utils.default.FormPage.getTitle(page.title, page.formData)), size === 'm' && /*#__PURE__*/_react.default.createElement(_copReactComponents.MediumHeading, null, _utils.default.FormPage.getTitle(page.title, page.formData)));
|
|
139
139
|
}
|
|
140
140
|
var headingAction = (0, _getCYAAction.default)(false, page, onRowAction);
|
|
141
141
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
142
142
|
className: "heading-with-action"
|
|
143
143
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
144
144
|
className: "heading-text"
|
|
145
|
-
}, size === 's' && /*#__PURE__*/_react.default.createElement(_copReactComponents.SmallHeading, null, _utils.default.
|
|
145
|
+
}, size === 's' && /*#__PURE__*/_react.default.createElement(_copReactComponents.SmallHeading, null, _utils.default.FormPage.getTitle(page.title, page.formData)), size === 'm' && /*#__PURE__*/_react.default.createElement(_copReactComponents.MediumHeading, null, _utils.default.FormPage.getTitle(page.title, page.formData))), /*#__PURE__*/_react.default.createElement("div", {
|
|
146
146
|
className: "heading-action"
|
|
147
147
|
}, /*#__PURE__*/_react.default.createElement(_RowAction.default, {
|
|
148
148
|
row: {
|
|
@@ -191,7 +191,7 @@ var CheckYourAnswers = function CheckYourAnswers(_ref) {
|
|
|
191
191
|
key: pageIndex
|
|
192
192
|
}, showHeading && getPageHeading(page, 'm'), isGroup(page.id) && /*#__PURE__*/_react.default.createElement("div", {
|
|
193
193
|
className: "group-title"
|
|
194
|
-
}, /*#__PURE__*/_react.default.createElement(_copReactComponents.MediumHeading, null, currentGroup.title || page.title)), /*#__PURE__*/_react.default.createElement(_SummaryList.default, {
|
|
194
|
+
}, /*#__PURE__*/_react.default.createElement(_copReactComponents.MediumHeading, null, currentGroup.title || _utils.default.FormPage.getTitle(page.title, page.formData))), /*#__PURE__*/_react.default.createElement(_SummaryList.default, {
|
|
195
195
|
className: className,
|
|
196
196
|
rows: page.rows,
|
|
197
197
|
classModifiers: summaryListClassModifiers,
|
|
@@ -4,6 +4,7 @@ var _react = require("@testing-library/react");
|
|
|
4
4
|
var _react2 = _interopRequireDefault(require("react"));
|
|
5
5
|
var _models = require("../../models");
|
|
6
6
|
var _setupTests = require("../../setupTests");
|
|
7
|
+
var _utils = _interopRequireDefault(require("../../utils"));
|
|
7
8
|
var _ActionButton = require("../PageActions/ActionButton");
|
|
8
9
|
var _CollectionPage = _interopRequireWildcard(require("./CollectionPage"));
|
|
9
10
|
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); }
|
|
@@ -222,7 +223,7 @@ describe('components.CollectionPage', function () {
|
|
|
222
223
|
expect(page.classList).toContain(_CollectionPage.DEFAULT_CLASS);
|
|
223
224
|
heading = page.childNodes[0];
|
|
224
225
|
expect(heading.classList).toContain('govuk-heading-l');
|
|
225
|
-
expect(heading.textContent).toEqual(PAGE.title);
|
|
226
|
+
expect(heading.textContent).toEqual(_utils.default.FormPage.getTitle(PAGE.title, PAGE.formData));
|
|
226
227
|
checkInputField(page.childNodes[1], TEXT.fieldId, "".concat(TEXT.label, " (optional)"), TEXT.hint, VALUE);
|
|
227
228
|
checkFormButtonGroup(page.childNodes[2], [_ActionButton.DEFAULT_LABEL]);
|
|
228
229
|
case 9:
|
|
@@ -193,7 +193,9 @@ var Collection = function Collection(_ref) {
|
|
|
193
193
|
onChange: onCollectionChange,
|
|
194
194
|
onTopLevelChange: onTopLevelChange,
|
|
195
195
|
wrap: wrap
|
|
196
|
-
}), removeStyle === 'end' && /*#__PURE__*/_react.default.createElement(_copReactComponents.ButtonGroup,
|
|
196
|
+
}), removeStyle === 'end' && /*#__PURE__*/_react.default.createElement(_copReactComponents.ButtonGroup, {
|
|
197
|
+
className: "govuk-!-margin-top-1"
|
|
198
|
+
}, /*#__PURE__*/_react.default.createElement(_copReactComponents.Button, {
|
|
197
199
|
onClick: function onClick() {
|
|
198
200
|
return onRemoveItem(item);
|
|
199
201
|
},
|
|
@@ -86,7 +86,7 @@ var FormPage = function FormPage(_ref) {
|
|
|
86
86
|
}) : action;
|
|
87
87
|
});
|
|
88
88
|
formPage.formData = _utils.default.Operate.runPageOperations(formPage, _objectSpread(_objectSpread({}, formPage.formData), patch), onWrapperChange || onPageChange);
|
|
89
|
-
var headingContent = page.title ? /*#__PURE__*/_react.default.createElement(_copReactComponents.LargeHeading, null, _utils.default.
|
|
89
|
+
var headingContent = page.title ? /*#__PURE__*/_react.default.createElement(_copReactComponents.LargeHeading, null, _utils.default.FormPage.getTitle(page.title, page.formData)) : /*#__PURE__*/_react.default.createElement(_copReactComponents.Label, {
|
|
90
90
|
id: page.id,
|
|
91
91
|
required: page.required,
|
|
92
92
|
hideOptionalSuffix: page.hideOptionalSuffix
|
|
@@ -5,6 +5,7 @@ var _react = require("@testing-library/react");
|
|
|
5
5
|
var _react2 = _interopRequireDefault(require("react"));
|
|
6
6
|
var _models = require("../../models");
|
|
7
7
|
var _setupTests = require("../../setupTests");
|
|
8
|
+
var _utils = _interopRequireDefault(require("../../utils"));
|
|
8
9
|
var _ActionButton = require("../PageActions/ActionButton");
|
|
9
10
|
var _FormPage = _interopRequireWildcard(require("./FormPage"));
|
|
10
11
|
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); }
|
|
@@ -208,7 +209,7 @@ describe('components.FormPage', function () {
|
|
|
208
209
|
expect(page.classList).toContain(_FormPage.DEFAULT_CLASS);
|
|
209
210
|
heading = page.childNodes[0];
|
|
210
211
|
expect(heading.classList).toContain('govuk-heading-l');
|
|
211
|
-
expect(heading.textContent).toEqual(PAGE.title);
|
|
212
|
+
expect(heading.textContent).toEqual(_utils.default.FormPage.getTitle(PAGE.title, PAGE.formData));
|
|
212
213
|
checkInputField(page.childNodes[1], TEXT.fieldId, "".concat(TEXT.label, " (optional)"), TEXT.hint, VALUE);
|
|
213
214
|
checkFormButtonGroup(page.childNodes[2], [_ActionButton.DEFAULT_LABEL]);
|
|
214
215
|
case 9:
|
|
@@ -33,6 +33,27 @@ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefine
|
|
|
33
33
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } // Global imports
|
|
34
34
|
// Local imports
|
|
35
35
|
// JSON
|
|
36
|
+
var setDate = function setDate(element, date) {
|
|
37
|
+
var items = element.children;
|
|
38
|
+
_react.fireEvent.change(items[0].childNodes[0].childNodes[1], {
|
|
39
|
+
target: {
|
|
40
|
+
name: 'date-day',
|
|
41
|
+
value: date[0]
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
_react.fireEvent.change(items[1].childNodes[0].childNodes[1], {
|
|
45
|
+
target: {
|
|
46
|
+
name: 'date-month',
|
|
47
|
+
value: date[1]
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
_react.fireEvent.change(items[2].childNodes[0].childNodes[1], {
|
|
51
|
+
target: {
|
|
52
|
+
name: 'date-year',
|
|
53
|
+
value: date[2]
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
};
|
|
36
57
|
describe('components', function () {
|
|
37
58
|
describe('FormRenderer', function () {
|
|
38
59
|
var mockAxios = new _axiosMockAdapter.default(_axios.default);
|
|
@@ -414,7 +435,7 @@ describe('components', function () {
|
|
|
414
435
|
}
|
|
415
436
|
}, _callee14);
|
|
416
437
|
})));
|
|
417
|
-
it('should render a
|
|
438
|
+
it('should render a task list', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
|
|
418
439
|
var taskList;
|
|
419
440
|
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
420
441
|
while (1) switch (_context16.prev = _context16.next) {
|
|
@@ -466,7 +487,7 @@ describe('components', function () {
|
|
|
466
487
|
}
|
|
467
488
|
}, _callee18);
|
|
468
489
|
})));
|
|
469
|
-
it('should load
|
|
490
|
+
it('should load task list with notes', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
|
|
470
491
|
var ON_SUBMIT_CALLS, ON_SUBMIT, HOOKS, TASK_LIST_WITH_NOTES, taskList;
|
|
471
492
|
return _regeneratorRuntime().wrap(function _callee20$(_context20) {
|
|
472
493
|
while (1) switch (_context20.prev = _context20.next) {
|
|
@@ -514,7 +535,7 @@ describe('components', function () {
|
|
|
514
535
|
}
|
|
515
536
|
}, _callee20);
|
|
516
537
|
})));
|
|
517
|
-
it('should not load
|
|
538
|
+
it('should not load task list with notes', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
|
|
518
539
|
var ON_SUBMIT_CALLS, ON_SUBMIT, HOOKS, TASK_LIST_WITH_NOTES, taskList;
|
|
519
540
|
return _regeneratorRuntime().wrap(function _callee22$(_context22) {
|
|
520
541
|
while (1) switch (_context22.prev = _context22.next) {
|
|
@@ -567,7 +588,7 @@ describe('components', function () {
|
|
|
567
588
|
}, _callee22);
|
|
568
589
|
})));
|
|
569
590
|
it('should handle navigating between task list pages', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
|
|
570
|
-
var ON_SUBMIT_CALLS, ON_SUBMIT, HOOKS, taskList, firstTaskStatus, secondTaskStatus, firstTask, newPage, continueButton, seaButton, cyaPageChange, modeChangeLink, changePage, airButton, cyaPage, finalSubmit;
|
|
591
|
+
var ON_SUBMIT_CALLS, ON_SUBMIT, HOOKS, taskList, firstTaskStatus, secondTaskStatus, firstTask, newPage, fieldset, continueButton, seaButton, cyaPageChange, modeChangeLink, changePage, airButton, cyaPage, finalSubmit;
|
|
571
592
|
return _regeneratorRuntime().wrap(function _callee24$(_context24) {
|
|
572
593
|
while (1) switch (_context24.prev = _context24.next) {
|
|
573
594
|
case 0:
|
|
@@ -608,24 +629,8 @@ describe('components', function () {
|
|
|
608
629
|
// Fill first page and navigate
|
|
609
630
|
newPage = container.childNodes[0].childNodes[0];
|
|
610
631
|
expect(newPage.childNodes[0].textContent).toEqual('Event Date');
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
name: 'date-day',
|
|
614
|
-
value: '7'
|
|
615
|
-
}
|
|
616
|
-
});
|
|
617
|
-
_react.fireEvent.change(newPage.childNodes[1].childNodes[0].childNodes[2].childNodes[1].childNodes[1], {
|
|
618
|
-
target: {
|
|
619
|
-
name: 'date-month',
|
|
620
|
-
value: '7'
|
|
621
|
-
}
|
|
622
|
-
});
|
|
623
|
-
_react.fireEvent.change(newPage.childNodes[1].childNodes[0].childNodes[2].childNodes[2].childNodes[1], {
|
|
624
|
-
target: {
|
|
625
|
-
name: 'date-year',
|
|
626
|
-
value: '2022'
|
|
627
|
-
}
|
|
628
|
-
});
|
|
632
|
+
fieldset = newPage.childNodes[1].childNodes[0]; // child nodes of fieldset are legend and date
|
|
633
|
+
setDate(fieldset.children[1], ['7', '7', '2022']);
|
|
629
634
|
continueButton = newPage.childNodes[2].childNodes[0];
|
|
630
635
|
_react.fireEvent.click(continueButton, {});
|
|
631
636
|
|
|
@@ -676,14 +681,14 @@ describe('components', function () {
|
|
|
676
681
|
expect(finalSubmit.date).toEqual('7-7-2022');
|
|
677
682
|
expect(finalSubmit.mode).toEqual('air');
|
|
678
683
|
expect(finalSubmit.formStatus.tasks['Date, location and mode details'].complete).toEqual(true);
|
|
679
|
-
case
|
|
684
|
+
case 53:
|
|
680
685
|
case "end":
|
|
681
686
|
return _context24.stop();
|
|
682
687
|
}
|
|
683
688
|
}, _callee24);
|
|
684
689
|
})));
|
|
685
690
|
it('should go straight to CYA page if a complete task is selected', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
|
|
686
|
-
var ON_SUBMIT, HOOKS, taskList, newPage;
|
|
691
|
+
var ON_SUBMIT, HOOKS, taskList, newPage, fieldset;
|
|
687
692
|
return _regeneratorRuntime().wrap(function _callee26$(_context26) {
|
|
688
693
|
while (1) switch (_context26.prev = _context26.next) {
|
|
689
694
|
case 0:
|
|
@@ -713,24 +718,10 @@ describe('components', function () {
|
|
|
713
718
|
|
|
714
719
|
// Fill first page and navigate
|
|
715
720
|
newPage = container.childNodes[0].childNodes[0];
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
}
|
|
721
|
-
});
|
|
722
|
-
_react.fireEvent.change(newPage.childNodes[1].childNodes[0].childNodes[2].childNodes[1].childNodes[1], {
|
|
723
|
-
target: {
|
|
724
|
-
name: 'date-month',
|
|
725
|
-
value: '7'
|
|
726
|
-
}
|
|
727
|
-
});
|
|
728
|
-
_react.fireEvent.change(newPage.childNodes[1].childNodes[0].childNodes[2].childNodes[2].childNodes[1], {
|
|
729
|
-
target: {
|
|
730
|
-
name: 'date-year',
|
|
731
|
-
value: '2022'
|
|
732
|
-
}
|
|
733
|
-
});
|
|
721
|
+
fieldset = newPage.childNodes[1].childNodes[0];
|
|
722
|
+
setDate(fieldset.children[1], ['7', '7', '2022']);
|
|
723
|
+
// child nodes of fieldset are legend and date
|
|
724
|
+
|
|
734
725
|
_react.fireEvent.click(newPage.childNodes[2].childNodes[0], {});
|
|
735
726
|
|
|
736
727
|
// Fill second page and navigate
|
|
@@ -746,7 +737,7 @@ describe('components', function () {
|
|
|
746
737
|
|
|
747
738
|
// Should be at CYA page
|
|
748
739
|
expect(container.childNodes[0].childNodes[0].childNodes[0].textContent).toEqual('Check your answers');
|
|
749
|
-
case
|
|
740
|
+
case 16:
|
|
750
741
|
case "end":
|
|
751
742
|
return _context26.stop();
|
|
752
743
|
}
|
|
@@ -803,7 +794,7 @@ describe('components', function () {
|
|
|
803
794
|
}, _callee28);
|
|
804
795
|
})));
|
|
805
796
|
it('should go to the first page of a complete task if noTaskCYAs specified', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
|
|
806
|
-
var ON_SUBMIT, HOOKS, TASK_LIST_WITH_NO_TASK_CYAS, taskList, newPage;
|
|
797
|
+
var ON_SUBMIT, HOOKS, TASK_LIST_WITH_NO_TASK_CYAS, taskList, newPage, fieldset;
|
|
807
798
|
return _regeneratorRuntime().wrap(function _callee30$(_context30) {
|
|
808
799
|
while (1) switch (_context30.prev = _context30.next) {
|
|
809
800
|
case 0:
|
|
@@ -839,24 +830,8 @@ describe('components', function () {
|
|
|
839
830
|
|
|
840
831
|
// Fill first page and navigate
|
|
841
832
|
newPage = container.childNodes[0].childNodes[0];
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
name: 'date-day',
|
|
845
|
-
value: '7'
|
|
846
|
-
}
|
|
847
|
-
});
|
|
848
|
-
_react.fireEvent.change(newPage.childNodes[1].childNodes[0].childNodes[2].childNodes[1].childNodes[1], {
|
|
849
|
-
target: {
|
|
850
|
-
name: 'date-month',
|
|
851
|
-
value: '7'
|
|
852
|
-
}
|
|
853
|
-
});
|
|
854
|
-
_react.fireEvent.change(newPage.childNodes[1].childNodes[0].childNodes[2].childNodes[2].childNodes[1], {
|
|
855
|
-
target: {
|
|
856
|
-
name: 'date-year',
|
|
857
|
-
value: '2022'
|
|
858
|
-
}
|
|
859
|
-
});
|
|
833
|
+
fieldset = newPage.childNodes[1].childNodes[0];
|
|
834
|
+
setDate(fieldset.children[1], ['7', '7', '2022']);
|
|
860
835
|
_react.fireEvent.click(newPage.childNodes[2].childNodes[0], {});
|
|
861
836
|
|
|
862
837
|
// Fill second page
|
|
@@ -870,7 +845,7 @@ describe('components', function () {
|
|
|
870
845
|
|
|
871
846
|
// Should be on the first page
|
|
872
847
|
expect(container.childNodes[0].childNodes[0].childNodes[0].textContent).toEqual('Event Date');
|
|
873
|
-
case
|
|
848
|
+
case 18:
|
|
874
849
|
case "end":
|
|
875
850
|
return _context30.stop();
|
|
876
851
|
}
|
|
@@ -28,53 +28,53 @@ describe('utils.Component.get', function () {
|
|
|
28
28
|
onChange: ON_CHANGE,
|
|
29
29
|
'data-testid': ID
|
|
30
30
|
};
|
|
31
|
+
var checkDateField = function checkDateField(node, option) {
|
|
32
|
+
expect(node.tagName).toEqual('DIV');
|
|
33
|
+
expect(node.classList).toContain('govuk-date-input__item');
|
|
34
|
+
var group = node.childNodes[0]; // form group
|
|
35
|
+
var _group$childNodes = _slicedToArray(group.childNodes, 2),
|
|
36
|
+
label = _group$childNodes[0],
|
|
37
|
+
input = _group$childNodes[1];
|
|
38
|
+
expect(label.tagName).toEqual('LABEL');
|
|
39
|
+
expect(label.classList).toContain('govuk-label');
|
|
40
|
+
expect(label.textContent).toEqual(option.label);
|
|
41
|
+
expect(input.tagName).toEqual('INPUT');
|
|
42
|
+
expect(input.id).toEqual(option.id);
|
|
43
|
+
return input;
|
|
44
|
+
};
|
|
31
45
|
var _render = (0, _react.render)((0, _getComponent.default)(COMPONENT)),
|
|
32
46
|
container = _render.container;
|
|
33
47
|
var _getAllByTestId = (0, _react.getAllByTestId)(container, ID),
|
|
34
48
|
_getAllByTestId2 = _slicedToArray(_getAllByTestId, 2),
|
|
35
49
|
formGroup = _getAllByTestId2[0],
|
|
36
|
-
|
|
50
|
+
dateInput = _getAllByTestId2[1];
|
|
37
51
|
expect(formGroup.tagName).toEqual('DIV');
|
|
38
52
|
expect(formGroup.classList).toContain('govuk-form-group');
|
|
39
53
|
var label = formGroup.childNodes[0];
|
|
40
54
|
expect(label.innerHTML).toContain(LABEL);
|
|
41
55
|
expect(label.getAttribute('for')).toEqual(ID);
|
|
42
|
-
expect(
|
|
43
|
-
expect(
|
|
44
|
-
expect(
|
|
45
|
-
var
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
expect(monthlabel.textContent).toEqual('Month');
|
|
62
|
-
var monthinput = monthitem.childNodes[1];
|
|
63
|
-
expect(monthinput.tagName).toEqual('INPUT');
|
|
64
|
-
expect(monthinput.id).toEqual("".concat(ID, "-month"));
|
|
65
|
-
var yearitem = dateinput.childNodes[2];
|
|
66
|
-
expect(yearitem.tagName).toEqual('DIV');
|
|
67
|
-
expect(yearitem.classList).toContain('govuk-date-input__item');
|
|
68
|
-
var yearlabel = yearitem.childNodes[0];
|
|
69
|
-
expect(yearlabel.tagName).toEqual('LABEL');
|
|
70
|
-
expect(yearlabel.classList).toContain('govuk-label');
|
|
71
|
-
expect(yearlabel.textContent).toEqual('Year');
|
|
72
|
-
var yearinput = yearitem.childNodes[1];
|
|
73
|
-
expect(yearinput.tagName).toEqual('INPUT');
|
|
74
|
-
expect(yearinput.id).toEqual("".concat(ID, "-year"));
|
|
56
|
+
expect(dateInput.tagName).toEqual('DIV');
|
|
57
|
+
expect(dateInput.classList).toContain('govuk-date-input');
|
|
58
|
+
expect(dateInput.id).toEqual(ID);
|
|
59
|
+
var _dateInput$childNodes = _slicedToArray(dateInput.childNodes, 3),
|
|
60
|
+
dayItem = _dateInput$childNodes[0],
|
|
61
|
+
monthItem = _dateInput$childNodes[1],
|
|
62
|
+
yearItem = _dateInput$childNodes[2];
|
|
63
|
+
var dayInput = checkDateField(dayItem, {
|
|
64
|
+
id: "".concat(ID, "-day"),
|
|
65
|
+
label: 'Day'
|
|
66
|
+
});
|
|
67
|
+
var monthInput = checkDateField(monthItem, {
|
|
68
|
+
id: "".concat(ID, "-month"),
|
|
69
|
+
label: 'Month'
|
|
70
|
+
});
|
|
71
|
+
var yearInput = checkDateField(yearItem, {
|
|
72
|
+
id: "".concat(ID, "-year"),
|
|
73
|
+
label: 'Year'
|
|
74
|
+
});
|
|
75
75
|
|
|
76
76
|
// Add something to the day and make sure it fires.
|
|
77
|
-
_react.fireEvent.change(
|
|
77
|
+
_react.fireEvent.change(dayInput, {
|
|
78
78
|
target: {
|
|
79
79
|
name: "".concat(FIELD_ID, "-day"),
|
|
80
80
|
value: '5'
|
|
@@ -86,7 +86,7 @@ describe('utils.Component.get', function () {
|
|
|
86
86
|
value: '5--'
|
|
87
87
|
});
|
|
88
88
|
// And now the month...
|
|
89
|
-
_react.fireEvent.change(
|
|
89
|
+
_react.fireEvent.change(monthInput, {
|
|
90
90
|
target: {
|
|
91
91
|
name: "".concat(FIELD_ID, "-month"),
|
|
92
92
|
value: '11'
|
|
@@ -98,7 +98,7 @@ describe('utils.Component.get', function () {
|
|
|
98
98
|
value: '5-11-'
|
|
99
99
|
});
|
|
100
100
|
// And finally the year.
|
|
101
|
-
_react.fireEvent.change(
|
|
101
|
+
_react.fireEvent.change(yearInput, {
|
|
102
102
|
target: {
|
|
103
103
|
name: "".concat(FIELD_ID, "-year"),
|
|
104
104
|
value: '2022'
|
|
@@ -63,9 +63,9 @@ describe('utils.Component.get', function () {
|
|
|
63
63
|
expect(input2.tagName).toEqual('DIV');
|
|
64
64
|
expect(input2.classList).toContain('govuk-date-input');
|
|
65
65
|
expect(input2.id).toEqual(ID2);
|
|
66
|
-
expect(input2.childNodes[0].childNodes[1].value).toEqual('1');
|
|
67
|
-
expect(input2.childNodes[1].childNodes[1].value).toEqual('2');
|
|
68
|
-
expect(input2.childNodes[2].childNodes[1].value).toEqual('2022');
|
|
66
|
+
expect(input2.childNodes[0].childNodes[0].childNodes[1].value).toEqual('1');
|
|
67
|
+
expect(input2.childNodes[1].childNodes[0].childNodes[1].value).toEqual('2');
|
|
68
|
+
expect(input2.childNodes[2].childNodes[0].childNodes[1].value).toEqual('2022');
|
|
69
69
|
case 35:
|
|
70
70
|
case "end":
|
|
71
71
|
return _context.stop();
|
|
@@ -61,7 +61,7 @@ describe('utils.Component.get', function () {
|
|
|
61
61
|
}].forEach(function (part) {
|
|
62
62
|
expect(part.item.tagName).toEqual('DIV');
|
|
63
63
|
expect(part.item.classList).toContain('govuk-date-input__item');
|
|
64
|
-
var _part$item$childNodes = _slicedToArray(part.item.childNodes, 2),
|
|
64
|
+
var _part$item$childNodes = _slicedToArray(part.item.childNodes[0].childNodes, 2),
|
|
65
65
|
inputLabel = _part$item$childNodes[0],
|
|
66
66
|
input = _part$item$childNodes[1];
|
|
67
67
|
expect(inputLabel.tagName).toEqual('LABEL');
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
8
|
+
var _meetsAllConditions = _interopRequireDefault(require("../Condition/meetsAllConditions"));
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
// Global imports.
|
|
11
|
+
|
|
12
|
+
// Local imports.
|
|
13
|
+
|
|
14
|
+
var getPageTitle = function getPageTitle(title, formData) {
|
|
15
|
+
if (typeof title === 'string') {
|
|
16
|
+
return _copReactComponents.Utils.interpolateString(title, formData);
|
|
17
|
+
}
|
|
18
|
+
if (!Array.isArray(title)) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
var shownOption = title.find(function (option) {
|
|
22
|
+
if (typeof option === 'string') {
|
|
23
|
+
// This is intended to allow a plain string 'fallback' option in the array.
|
|
24
|
+
// As such, it should be the last option in the array as any options after
|
|
25
|
+
// it will not be considered.
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
return (0, _meetsAllConditions.default)(option.show_when, formData);
|
|
29
|
+
});
|
|
30
|
+
return typeof shownOption === 'string' ? _copReactComponents.Utils.interpolateString(shownOption, formData) : _copReactComponents.Utils.interpolateString(shownOption.title, formData);
|
|
31
|
+
};
|
|
32
|
+
var _default = getPageTitle;
|
|
33
|
+
exports.default = _default;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _getPageTitle = _interopRequireDefault(require("./getPageTitle"));
|
|
4
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
5
|
+
describe('utils.FormPage.getPageTitle', function () {
|
|
6
|
+
var FORM_DATA = {
|
|
7
|
+
testField: 'Alpha',
|
|
8
|
+
testField2: 'yes'
|
|
9
|
+
};
|
|
10
|
+
it('should return null if title is not defined', function () {
|
|
11
|
+
var result = (0, _getPageTitle.default)(null, FORM_DATA);
|
|
12
|
+
expect(result).toEqual(null);
|
|
13
|
+
});
|
|
14
|
+
it('should return the defined page title if it\'s just a string', function () {
|
|
15
|
+
var PAGE = {
|
|
16
|
+
title: 'Page title'
|
|
17
|
+
};
|
|
18
|
+
var result = (0, _getPageTitle.default)(PAGE.title, FORM_DATA);
|
|
19
|
+
expect(result).toEqual('Page title');
|
|
20
|
+
});
|
|
21
|
+
it('should return a correctly interpolated title', function () {
|
|
22
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
23
|
+
var PAGE = {
|
|
24
|
+
title: '${testField} title'
|
|
25
|
+
};
|
|
26
|
+
var result = (0, _getPageTitle.default)(PAGE.title, FORM_DATA);
|
|
27
|
+
expect(result).toEqual("".concat(FORM_DATA.testField, " title"));
|
|
28
|
+
});
|
|
29
|
+
it('should return the title that has it\'s conditions met', function () {
|
|
30
|
+
var PAGE = {
|
|
31
|
+
title: [{
|
|
32
|
+
title: 'First title',
|
|
33
|
+
show_when: [{
|
|
34
|
+
field: 'testField2',
|
|
35
|
+
op: '=',
|
|
36
|
+
value: 'no'
|
|
37
|
+
}]
|
|
38
|
+
}, {
|
|
39
|
+
title: 'Second title',
|
|
40
|
+
show_when: [{
|
|
41
|
+
field: 'testField2',
|
|
42
|
+
op: '=',
|
|
43
|
+
value: 'yes'
|
|
44
|
+
}]
|
|
45
|
+
}]
|
|
46
|
+
};
|
|
47
|
+
var result = (0, _getPageTitle.default)(PAGE.title, FORM_DATA);
|
|
48
|
+
expect(result).toEqual('Second title');
|
|
49
|
+
});
|
|
50
|
+
it('should return a plain string title if one is encountered in the array', function () {
|
|
51
|
+
var PAGE = {
|
|
52
|
+
title: [{
|
|
53
|
+
title: 'First title',
|
|
54
|
+
show_when: [{
|
|
55
|
+
field: 'testField2',
|
|
56
|
+
op: '=',
|
|
57
|
+
value: 'notTheValue'
|
|
58
|
+
}]
|
|
59
|
+
}, {
|
|
60
|
+
title: 'Second title',
|
|
61
|
+
show_when: [{
|
|
62
|
+
field: 'testField2',
|
|
63
|
+
op: '=',
|
|
64
|
+
value: 'notTheValue'
|
|
65
|
+
}]
|
|
66
|
+
}, "Default title"]
|
|
67
|
+
};
|
|
68
|
+
var result = (0, _getPageTitle.default)(PAGE.title, FORM_DATA);
|
|
69
|
+
expect(result).toEqual('Default title');
|
|
70
|
+
});
|
|
71
|
+
it('should correctly interpolate a plain string option in the title array', function () {
|
|
72
|
+
var PAGE = {
|
|
73
|
+
title: [{
|
|
74
|
+
title: 'First title',
|
|
75
|
+
show_when: [{
|
|
76
|
+
field: 'testField2',
|
|
77
|
+
op: '=',
|
|
78
|
+
value: 'notTheValue'
|
|
79
|
+
}]
|
|
80
|
+
}, {
|
|
81
|
+
title: 'Second title',
|
|
82
|
+
show_when: [{
|
|
83
|
+
field: 'testField2',
|
|
84
|
+
op: '=',
|
|
85
|
+
value: 'notTheValue'
|
|
86
|
+
}]
|
|
87
|
+
},
|
|
88
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
89
|
+
"${testField} title"]
|
|
90
|
+
};
|
|
91
|
+
var result = (0, _getPageTitle.default)(PAGE.title, FORM_DATA);
|
|
92
|
+
expect(result).toEqual("".concat(FORM_DATA.testField, " title"));
|
|
93
|
+
});
|
|
94
|
+
it('should correctly interpolate a conditional title', function () {
|
|
95
|
+
var PAGE = {
|
|
96
|
+
title: [{
|
|
97
|
+
title: 'First title',
|
|
98
|
+
show_when: [{
|
|
99
|
+
field: 'testField2',
|
|
100
|
+
op: '=',
|
|
101
|
+
value: 'no'
|
|
102
|
+
}]
|
|
103
|
+
}, {
|
|
104
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
105
|
+
title: '${testField} title',
|
|
106
|
+
show_when: [{
|
|
107
|
+
field: 'testField2',
|
|
108
|
+
op: '=',
|
|
109
|
+
value: 'yes'
|
|
110
|
+
}]
|
|
111
|
+
}]
|
|
112
|
+
};
|
|
113
|
+
var result = (0, _getPageTitle.default)(PAGE.title, FORM_DATA);
|
|
114
|
+
expect(result).toEqual("".concat(FORM_DATA.testField, " title"));
|
|
115
|
+
});
|
|
116
|
+
});
|
|
@@ -7,6 +7,7 @@ exports.default = void 0;
|
|
|
7
7
|
var _applyConditionalProperties = _interopRequireDefault(require("./applyConditionalProperties"));
|
|
8
8
|
var _getFormPage = _interopRequireDefault(require("./getFormPage"));
|
|
9
9
|
var _getFormPages = _interopRequireDefault(require("./getFormPages"));
|
|
10
|
+
var _getPageTitle = _interopRequireDefault(require("./getPageTitle"));
|
|
10
11
|
var _showFormPage = _interopRequireDefault(require("./showFormPage"));
|
|
11
12
|
var _showFormPageCYA = _interopRequireDefault(require("./showFormPageCYA"));
|
|
12
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -14,6 +15,7 @@ var FormPage = {
|
|
|
14
15
|
applyConditionalProperties: _applyConditionalProperties.default,
|
|
15
16
|
get: _getFormPage.default,
|
|
16
17
|
getAll: _getFormPages.default,
|
|
18
|
+
getTitle: _getPageTitle.default,
|
|
17
19
|
show: _showFormPage.default,
|
|
18
20
|
showCYA: _showFormPageCYA.default
|
|
19
21
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ukhomeoffice/cop-react-form-renderer",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.27.1",
|
|
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": "^3.
|
|
19
|
+
"@ukhomeoffice/cop-react-components": "^3.14.2",
|
|
20
20
|
"axios": "^0.23.0",
|
|
21
21
|
"dayjs": "^1.11.0",
|
|
22
22
|
"govuk-frontend": "^4.3.1",
|