@ukhomeoffice/cop-react-form-renderer 6.11.1 → 6.12.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/README.md +8 -0
- package/dist/components/CheckYourAnswers/Answer.js +1 -1
- package/dist/components/CheckYourAnswers/CheckYourAnswers.js +6 -2
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +131 -50
- package/dist/components/CollectionPage/CollectionPage.js +2 -1
- package/dist/components/CollectionSummary/CollectionSummary.js +6 -4
- package/dist/components/CollectionSummary/CollectionSummary.scss +5 -0
- package/dist/components/CollectionSummary/CollectionSummary.test.js +60 -36
- package/dist/components/CollectionSummary/RenderListView.js +18 -6
- package/dist/components/CollectionSummary/RenderListView.scss +9 -0
- package/dist/components/CollectionSummary/RenderListView.test.js +42 -5
- package/dist/components/CollectionSummary/SummaryCard.js +6 -4
- package/dist/components/CollectionSummary/SummaryCard.scss +6 -0
- package/dist/components/CollectionSummary/SummaryCard.test.js +5 -5
- package/dist/components/CollectionSummary/SummaryCardDetails.js +3 -2
- package/dist/components/CollectionSummary/SummaryCardDetails.scss +2 -0
- package/dist/components/FormComponent/Collection.js +2 -1
- package/dist/components/FormComponent/Collection.scss +1 -1
- package/dist/components/FormComponent/Container.js +2 -0
- package/dist/components/FormComponent/Container.scss +15 -0
- package/dist/components/FormComponent/FormComponent.js +1 -1
- package/dist/components/FormPage/FormPage.js +19 -7
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.js +25 -13
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.test.js +59 -1
- package/dist/components/FormRenderer/onPageAction.js +5 -1
- package/dist/json/actions.json +17 -0
- package/dist/json/actionsNoSave.json +17 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +7 -4
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +39 -0
- package/dist/utils/CheckYourAnswers/showComponentCYA.js +1 -1
- package/dist/utils/CollectionPage/duplicateCollectionPageEntry.js +2 -1
- package/dist/utils/CollectionPage/mergeCollectionPages.test.js +0 -26
- package/dist/utils/CollectionPage/setCollectionPageData.js +2 -1
- package/dist/utils/Data/deleteValues.js +22 -0
- package/dist/utils/Data/deleteValues.test.js +57 -0
- package/dist/utils/Data/getAutocompleteSource.test.js +14 -5
- package/dist/utils/Data/getOptions.js +2 -1
- package/dist/utils/Data/getOptions.test.js +26 -8
- package/dist/utils/Data/index.js +2 -0
- package/dist/utils/Operate/deleteValueInFormData.js +26 -0
- package/dist/utils/Operate/deleteValueInFormData.test.js +60 -0
- package/dist/utils/Operate/runPageOperations.js +2 -0
- package/dist/utils/Validate/additional/conditionallyPermittedChange.js +25 -0
- package/dist/utils/Validate/additional/conditionallyPermittedChange.test.js +33 -0
- package/dist/utils/Validate/additional/index.js +6 -1
- package/dist/utils/Validate/additional/index.test.js +66 -0
- package/dist/utils/Validate/additional/mustBeOneOf.js +21 -0
- package/dist/utils/Validate/additional/mustBeOneOf.test.js +36 -0
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -9,10 +9,18 @@ It uses components from [COP React Design System](https://github.com/UKHomeOffic
|
|
|
9
9
|
- `@ukhomeoffice/cop-react-components` - and offers various styles of forms. These are showcased inside of
|
|
10
10
|
a [yarn storybook](Storybook) within the project.
|
|
11
11
|
|
|
12
|
+
To get started run `nvm use` to switch to currently supported node version (if your using node version manager). Otherwise, install node version specified in `.nvmrc`.
|
|
13
|
+
|
|
14
|
+
This library uses the yarn package manager. To install this you will need to run `npm install --global yarn` on the supported version of node.
|
|
15
|
+
|
|
12
16
|
## Available Scripts
|
|
13
17
|
|
|
14
18
|
In the project directory, you can run:
|
|
15
19
|
|
|
20
|
+
### `yarn install`
|
|
21
|
+
|
|
22
|
+
Installs the package.json dependencies.
|
|
23
|
+
|
|
16
24
|
### `yarn lint`
|
|
17
25
|
|
|
18
26
|
Runs `eslint` against the project to check for coding issues.
|
|
@@ -22,7 +22,7 @@ var Answer = function Answer(_ref) {
|
|
|
22
22
|
formData = _ref.formData,
|
|
23
23
|
placeholder = _ref.placeholder;
|
|
24
24
|
if (!value) {
|
|
25
|
-
var placeholderValue = (component === null || component === void 0 ? void 0 : component.cyaPlaceholder
|
|
25
|
+
var placeholderValue = Object.prototype.hasOwnProperty.call(component || {}, 'cyaPlaceholder') ? component === null || component === void 0 ? void 0 : component.cyaPlaceholder : placeholder;
|
|
26
26
|
return placeholderValue || /*#__PURE__*/_react.default.createElement(_VisuallyHidden.default, null, "No answer");
|
|
27
27
|
}
|
|
28
28
|
if (!component) {
|
|
@@ -207,7 +207,9 @@ var CheckYourAnswers = function CheckYourAnswers(_ref) {
|
|
|
207
207
|
isGroup: isGroup(page.id)
|
|
208
208
|
}));
|
|
209
209
|
}), !hide_actions && /*#__PURE__*/_react.default.createElement(_PageActions.default, {
|
|
210
|
-
actions: actions
|
|
210
|
+
actions: actions === null || actions === void 0 ? void 0 : actions.filter(function (action) {
|
|
211
|
+
return _utils.default.Component.show(action, _pages[_pages.length - 1].formData);
|
|
212
|
+
}),
|
|
211
213
|
onAction: function onAction(action) {
|
|
212
214
|
return _onAction(action);
|
|
213
215
|
}
|
|
@@ -223,7 +225,9 @@ CheckYourAnswers.propTypes = {
|
|
|
223
225
|
noGroupAction: _propTypes.default.bool,
|
|
224
226
|
onAction: _propTypes.default.func.isRequired,
|
|
225
227
|
onRowAction: _propTypes.default.func.isRequired,
|
|
226
|
-
pages: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
228
|
+
pages: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
229
|
+
formData: _propTypes.default.shape({}).isRequired
|
|
230
|
+
})).isRequired,
|
|
227
231
|
sections: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
228
232
|
name: _propTypes.default.string.isRequired,
|
|
229
233
|
tasks: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
@@ -13,6 +13,8 @@ var _userProfile = _interopRequireDefault(require("../../json/userProfile.json")
|
|
|
13
13
|
var _groupData = _interopRequireDefault(require("../../json/group.data.json"));
|
|
14
14
|
var _group = _interopRequireDefault(require("../../json/group.json"));
|
|
15
15
|
var _groupOfRow = _interopRequireDefault(require("../../json/groupOfRow.json"));
|
|
16
|
+
var _actions = _interopRequireDefault(require("../../json/actions.json"));
|
|
17
|
+
var _actionsNoSave = _interopRequireDefault(require("../../json/actionsNoSave.json"));
|
|
16
18
|
var _models = require("../../models");
|
|
17
19
|
var _setupTests = require("../../setupTests");
|
|
18
20
|
var _utils = _interopRequireDefault(require("../../utils"));
|
|
@@ -673,12 +675,12 @@ describe('components', function () {
|
|
|
673
675
|
}
|
|
674
676
|
}, _callee26);
|
|
675
677
|
})));
|
|
676
|
-
it('should
|
|
677
|
-
var GROUP_PAGES, cya,
|
|
678
|
+
it('should show a conditional button', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
|
|
679
|
+
var GROUP_PAGES, cya, hodsButtonDiv, submitButton, saveButton;
|
|
678
680
|
return _regeneratorRuntime().wrap(function _callee28$(_context28) {
|
|
679
681
|
while (1) switch (_context28.prev = _context28.next) {
|
|
680
682
|
case 0:
|
|
681
|
-
GROUP_PAGES = _utils.default.FormPage.getAll(_groupOfRow.default.pages, _groupOfRow.default.components, {});
|
|
683
|
+
GROUP_PAGES = _utils.default.FormPage.getAll(_groupOfRow.default.pages, _groupOfRow.default.components, _objectSpread({}, DATA));
|
|
682
684
|
_context28.next = 3;
|
|
683
685
|
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
|
|
684
686
|
return _regeneratorRuntime().wrap(function _callee27$(_context27) {
|
|
@@ -686,8 +688,10 @@ describe('components', function () {
|
|
|
686
688
|
case 0:
|
|
687
689
|
(0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, {
|
|
688
690
|
pages: GROUP_PAGES,
|
|
691
|
+
onRowAction: ON_ROW_ACTION,
|
|
692
|
+
onAction: ON_ACTION,
|
|
689
693
|
groups: _groupOfRow.default.cya.groups,
|
|
690
|
-
|
|
694
|
+
actions: _actions.default
|
|
691
695
|
}), container);
|
|
692
696
|
case 1:
|
|
693
697
|
case "end":
|
|
@@ -695,6 +699,83 @@ describe('components', function () {
|
|
|
695
699
|
}
|
|
696
700
|
}, _callee27);
|
|
697
701
|
})));
|
|
702
|
+
case 3:
|
|
703
|
+
cya = checkCYA(container);
|
|
704
|
+
hodsButtonDiv = cya.childNodes[7];
|
|
705
|
+
expect(hodsButtonDiv.classList).toContain('hods-button-group');
|
|
706
|
+
submitButton = hodsButtonDiv.childNodes[0];
|
|
707
|
+
expect(submitButton.tagName).toEqual('BUTTON');
|
|
708
|
+
expect(submitButton.textContent).toEqual('Submit');
|
|
709
|
+
saveButton = hodsButtonDiv.childNodes[1];
|
|
710
|
+
expect(saveButton.tagName).toEqual('BUTTON');
|
|
711
|
+
expect(saveButton.textContent).toEqual('Save and return later');
|
|
712
|
+
case 12:
|
|
713
|
+
case "end":
|
|
714
|
+
return _context28.stop();
|
|
715
|
+
}
|
|
716
|
+
}, _callee28);
|
|
717
|
+
})));
|
|
718
|
+
it('should not show a conditional button', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
|
|
719
|
+
var GROUP_PAGES, cya, hodsButtonDiv, submitButton, saveButton;
|
|
720
|
+
return _regeneratorRuntime().wrap(function _callee30$(_context30) {
|
|
721
|
+
while (1) switch (_context30.prev = _context30.next) {
|
|
722
|
+
case 0:
|
|
723
|
+
GROUP_PAGES = _utils.default.FormPage.getAll(_groupOfRow.default.pages, _groupOfRow.default.components, _objectSpread({}, DATA));
|
|
724
|
+
_context30.next = 3;
|
|
725
|
+
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
|
|
726
|
+
return _regeneratorRuntime().wrap(function _callee29$(_context29) {
|
|
727
|
+
while (1) switch (_context29.prev = _context29.next) {
|
|
728
|
+
case 0:
|
|
729
|
+
(0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, {
|
|
730
|
+
pages: GROUP_PAGES,
|
|
731
|
+
onRowAction: ON_ROW_ACTION,
|
|
732
|
+
onAction: ON_ACTION,
|
|
733
|
+
groups: _groupOfRow.default.cya.groups,
|
|
734
|
+
actions: _actionsNoSave.default
|
|
735
|
+
}), container);
|
|
736
|
+
case 1:
|
|
737
|
+
case "end":
|
|
738
|
+
return _context29.stop();
|
|
739
|
+
}
|
|
740
|
+
}, _callee29);
|
|
741
|
+
})));
|
|
742
|
+
case 3:
|
|
743
|
+
cya = checkCYA(container);
|
|
744
|
+
hodsButtonDiv = cya.childNodes[7];
|
|
745
|
+
expect(hodsButtonDiv.classList).toContain('hods-button-group');
|
|
746
|
+
submitButton = hodsButtonDiv.childNodes[0];
|
|
747
|
+
expect(submitButton.tagName).toEqual('BUTTON');
|
|
748
|
+
expect(submitButton.textContent).toEqual('Submit');
|
|
749
|
+
saveButton = hodsButtonDiv.childNodes[1];
|
|
750
|
+
expect(saveButton).toEqual(undefined);
|
|
751
|
+
case 11:
|
|
752
|
+
case "end":
|
|
753
|
+
return _context30.stop();
|
|
754
|
+
}
|
|
755
|
+
}, _callee30);
|
|
756
|
+
})));
|
|
757
|
+
it('should render empty optional fields with a placeholder value when provided', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
|
|
758
|
+
var GROUP_PAGES, cya, namesGroup, firstNameRow, surname;
|
|
759
|
+
return _regeneratorRuntime().wrap(function _callee32$(_context32) {
|
|
760
|
+
while (1) switch (_context32.prev = _context32.next) {
|
|
761
|
+
case 0:
|
|
762
|
+
GROUP_PAGES = _utils.default.FormPage.getAll(_groupOfRow.default.pages, _groupOfRow.default.components, {});
|
|
763
|
+
_context32.next = 3;
|
|
764
|
+
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
|
|
765
|
+
return _regeneratorRuntime().wrap(function _callee31$(_context31) {
|
|
766
|
+
while (1) switch (_context31.prev = _context31.next) {
|
|
767
|
+
case 0:
|
|
768
|
+
(0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, {
|
|
769
|
+
pages: GROUP_PAGES,
|
|
770
|
+
groups: _groupOfRow.default.cya.groups,
|
|
771
|
+
optionalFieldPlaceholder: "Not entered"
|
|
772
|
+
}), container);
|
|
773
|
+
case 1:
|
|
774
|
+
case "end":
|
|
775
|
+
return _context31.stop();
|
|
776
|
+
}
|
|
777
|
+
}, _callee31);
|
|
778
|
+
})));
|
|
698
779
|
case 3:
|
|
699
780
|
cya = checkCYA(container);
|
|
700
781
|
namesGroup = cya.childNodes[2];
|
|
@@ -712,14 +793,14 @@ describe('components', function () {
|
|
|
712
793
|
expect(surname.childNodes[1].tagName).toEqual('DD');
|
|
713
794
|
case 17:
|
|
714
795
|
case "end":
|
|
715
|
-
return
|
|
796
|
+
return _context32.stop();
|
|
716
797
|
}
|
|
717
|
-
},
|
|
798
|
+
}, _callee32);
|
|
718
799
|
})));
|
|
719
|
-
it('should show page components corrently with interpolated title and cya_label, if label is missing', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
800
|
+
it('should show page components corrently with interpolated title and cya_label, if label is missing', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34() {
|
|
720
801
|
var _PAGES, _COMPONENTS, T_PAGES, cya, _cya$childNodes7, cyaTitle, cyaChildNode, names, _names$childNodes3, firstName, surname, _firstName$childNodes, label;
|
|
721
|
-
return _regeneratorRuntime().wrap(function
|
|
722
|
-
while (1) switch (
|
|
802
|
+
return _regeneratorRuntime().wrap(function _callee34$(_context34) {
|
|
803
|
+
while (1) switch (_context34.prev = _context34.next) {
|
|
723
804
|
case 0:
|
|
724
805
|
_PAGES = [].concat(_userProfile.default.pages); // eslint-disable-next-line no-template-curly-in-string
|
|
725
806
|
_PAGES[0] = _objectSpread(_objectSpread({}, _PAGES[0]), {}, {
|
|
@@ -733,10 +814,10 @@ describe('components', function () {
|
|
|
733
814
|
cya_label: "Text ${currentUser.familyName}"
|
|
734
815
|
});
|
|
735
816
|
T_PAGES = _utils.default.FormPage.getAll(_PAGES, _COMPONENTS, DATA);
|
|
736
|
-
|
|
737
|
-
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
738
|
-
return _regeneratorRuntime().wrap(function
|
|
739
|
-
while (1) switch (
|
|
817
|
+
_context34.next = 7;
|
|
818
|
+
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
|
|
819
|
+
return _regeneratorRuntime().wrap(function _callee33$(_context33) {
|
|
820
|
+
while (1) switch (_context33.prev = _context33.next) {
|
|
740
821
|
case 0:
|
|
741
822
|
(0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, {
|
|
742
823
|
pages: T_PAGES,
|
|
@@ -745,9 +826,9 @@ describe('components', function () {
|
|
|
745
826
|
}), container);
|
|
746
827
|
case 1:
|
|
747
828
|
case "end":
|
|
748
|
-
return
|
|
829
|
+
return _context33.stop();
|
|
749
830
|
}
|
|
750
|
-
},
|
|
831
|
+
}, _callee33);
|
|
751
832
|
})));
|
|
752
833
|
case 7:
|
|
753
834
|
cya = checkCYA(container);
|
|
@@ -762,14 +843,14 @@ describe('components', function () {
|
|
|
762
843
|
checkRow(surname, 'Last name', 'Smith', false);
|
|
763
844
|
case 17:
|
|
764
845
|
case "end":
|
|
765
|
-
return
|
|
846
|
+
return _context34.stop();
|
|
766
847
|
}
|
|
767
|
-
},
|
|
848
|
+
}, _callee34);
|
|
768
849
|
})));
|
|
769
|
-
it('should show page components corrently with no label, if label and cya_label are missing', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
850
|
+
it('should show page components corrently with no label, if label and cya_label are missing', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36() {
|
|
770
851
|
var _PAGES, _COMPONENTS, T_PAGES, cya, _cya$childNodes8, cyaChildNode, names, _names$childNodes4, firstName, surname, _firstName$childNodes2, label;
|
|
771
|
-
return _regeneratorRuntime().wrap(function
|
|
772
|
-
while (1) switch (
|
|
852
|
+
return _regeneratorRuntime().wrap(function _callee36$(_context36) {
|
|
853
|
+
while (1) switch (_context36.prev = _context36.next) {
|
|
773
854
|
case 0:
|
|
774
855
|
_PAGES = [].concat(_userProfile.default.pages);
|
|
775
856
|
_COMPONENTS = [].concat(_userProfile.default.components);
|
|
@@ -779,10 +860,10 @@ describe('components', function () {
|
|
|
779
860
|
cya_label: undefined
|
|
780
861
|
});
|
|
781
862
|
T_PAGES = _utils.default.FormPage.getAll(_PAGES, _COMPONENTS, _objectSpread({}, DATA));
|
|
782
|
-
|
|
783
|
-
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
784
|
-
return _regeneratorRuntime().wrap(function
|
|
785
|
-
while (1) switch (
|
|
863
|
+
_context36.next = 6;
|
|
864
|
+
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35() {
|
|
865
|
+
return _regeneratorRuntime().wrap(function _callee35$(_context35) {
|
|
866
|
+
while (1) switch (_context35.prev = _context35.next) {
|
|
786
867
|
case 0:
|
|
787
868
|
(0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, {
|
|
788
869
|
pages: T_PAGES,
|
|
@@ -791,9 +872,9 @@ describe('components', function () {
|
|
|
791
872
|
}), container);
|
|
792
873
|
case 1:
|
|
793
874
|
case "end":
|
|
794
|
-
return
|
|
875
|
+
return _context35.stop();
|
|
795
876
|
}
|
|
796
|
-
},
|
|
877
|
+
}, _callee35);
|
|
797
878
|
})));
|
|
798
879
|
case 6:
|
|
799
880
|
cya = checkCYA(container);
|
|
@@ -807,14 +888,14 @@ describe('components', function () {
|
|
|
807
888
|
checkRow(surname, 'Last name', 'Smith', false);
|
|
808
889
|
case 15:
|
|
809
890
|
case "end":
|
|
810
|
-
return
|
|
891
|
+
return _context36.stop();
|
|
811
892
|
}
|
|
812
|
-
},
|
|
893
|
+
}, _callee36);
|
|
813
894
|
})));
|
|
814
|
-
it('should show task list in CYA style and hide pages from skipped tasks', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
895
|
+
it('should show task list in CYA style and hide pages from skipped tasks', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38() {
|
|
815
896
|
var sections, taskHeading1, namesPageHeading;
|
|
816
|
-
return _regeneratorRuntime().wrap(function
|
|
817
|
-
while (1) switch (
|
|
897
|
+
return _regeneratorRuntime().wrap(function _callee38$(_context38) {
|
|
898
|
+
while (1) switch (_context38.prev = _context38.next) {
|
|
818
899
|
case 0:
|
|
819
900
|
sections = [{
|
|
820
901
|
name: 'These are your tasks',
|
|
@@ -828,10 +909,10 @@ describe('components', function () {
|
|
|
828
909
|
pages: ['grade']
|
|
829
910
|
}]
|
|
830
911
|
}];
|
|
831
|
-
|
|
832
|
-
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
833
|
-
return _regeneratorRuntime().wrap(function
|
|
834
|
-
while (1) switch (
|
|
912
|
+
_context38.next = 3;
|
|
913
|
+
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37() {
|
|
914
|
+
return _regeneratorRuntime().wrap(function _callee37$(_context37) {
|
|
915
|
+
while (1) switch (_context37.prev = _context37.next) {
|
|
835
916
|
case 0:
|
|
836
917
|
(0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, {
|
|
837
918
|
pages: PAGES,
|
|
@@ -843,9 +924,9 @@ describe('components', function () {
|
|
|
843
924
|
}), container);
|
|
844
925
|
case 1:
|
|
845
926
|
case "end":
|
|
846
|
-
return
|
|
927
|
+
return _context37.stop();
|
|
847
928
|
}
|
|
848
|
-
},
|
|
929
|
+
}, _callee37);
|
|
849
930
|
})));
|
|
850
931
|
case 3:
|
|
851
932
|
taskHeading1 = container.childNodes[0].childNodes[0];
|
|
@@ -859,21 +940,21 @@ describe('components', function () {
|
|
|
859
940
|
expect(container.childNodes[0].childNodes.length).toEqual(2); // second task skipped so not shown
|
|
860
941
|
case 12:
|
|
861
942
|
case "end":
|
|
862
|
-
return
|
|
943
|
+
return _context38.stop();
|
|
863
944
|
}
|
|
864
|
-
},
|
|
945
|
+
}, _callee38);
|
|
865
946
|
})));
|
|
866
|
-
it('Show answers from multiple address fields into in one DL correctly when hideBlankRows is true', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
947
|
+
it('Show answers from multiple address fields into in one DL correctly when hideBlankRows is true', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40() {
|
|
867
948
|
var ADDRESS_DATA, GROUP_PAGES, cya, groupedComponent, keyGroup, valueGroup, changeButtonDiv, changeButton;
|
|
868
|
-
return _regeneratorRuntime().wrap(function
|
|
869
|
-
while (1) switch (
|
|
949
|
+
return _regeneratorRuntime().wrap(function _callee40$(_context40) {
|
|
950
|
+
while (1) switch (_context40.prev = _context40.next) {
|
|
870
951
|
case 0:
|
|
871
952
|
ADDRESS_DATA = _utils.default.Data.setupForm(_group.default.pages, _group.default.components, _groupData.default);
|
|
872
953
|
GROUP_PAGES = _utils.default.FormPage.getAll(_group.default.pages, _group.default.components, _objectSpread({}, ADDRESS_DATA));
|
|
873
|
-
|
|
874
|
-
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
875
|
-
return _regeneratorRuntime().wrap(function
|
|
876
|
-
while (1) switch (
|
|
954
|
+
_context40.next = 4;
|
|
955
|
+
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39() {
|
|
956
|
+
return _regeneratorRuntime().wrap(function _callee39$(_context39) {
|
|
957
|
+
while (1) switch (_context39.prev = _context39.next) {
|
|
877
958
|
case 0:
|
|
878
959
|
(0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, {
|
|
879
960
|
pages: GROUP_PAGES,
|
|
@@ -884,9 +965,9 @@ describe('components', function () {
|
|
|
884
965
|
}), container);
|
|
885
966
|
case 1:
|
|
886
967
|
case "end":
|
|
887
|
-
return
|
|
968
|
+
return _context39.stop();
|
|
888
969
|
}
|
|
889
|
-
},
|
|
970
|
+
}, _callee39);
|
|
890
971
|
})));
|
|
891
972
|
case 4:
|
|
892
973
|
cya = checkCYA(container);
|
|
@@ -908,9 +989,9 @@ describe('components', function () {
|
|
|
908
989
|
expect(changeButton.textContent).toEqual('Change address details');
|
|
909
990
|
case 21:
|
|
910
991
|
case "end":
|
|
911
|
-
return
|
|
992
|
+
return _context40.stop();
|
|
912
993
|
}
|
|
913
|
-
},
|
|
994
|
+
}, _callee40);
|
|
914
995
|
})));
|
|
915
996
|
});
|
|
916
997
|
});
|
|
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.default = exports.DEFAULT_CLASS = void 0;
|
|
8
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _uuid = require("uuid");
|
|
10
11
|
var _utils = _interopRequireDefault(require("../../utils"));
|
|
11
12
|
var _FormPage = _interopRequireDefault(require("../FormPage"));
|
|
12
13
|
var _FormPage2 = require("../FormPage/FormPage");
|
|
@@ -104,7 +105,7 @@ var CollectionPage = function CollectionPage(_ref) {
|
|
|
104
105
|
// If there is no active entry in the collection, we create
|
|
105
106
|
// a new entry and generate a new ID for it.
|
|
106
107
|
// This ID becomes the active ID for the collection.
|
|
107
|
-
var newId =
|
|
108
|
+
var newId = (0, _uuid.v4)();
|
|
108
109
|
reportActiveIdChange(newId);
|
|
109
110
|
reportChange([].concat(data, [_defineProperty({
|
|
110
111
|
id: newId
|
|
@@ -252,7 +252,9 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
252
252
|
classModifiers: ['secondary']
|
|
253
253
|
},
|
|
254
254
|
onAction: onAction
|
|
255
|
-
}),
|
|
255
|
+
}), /*#__PURE__*/_react.default.createElement("ul", {
|
|
256
|
+
className: "collection-summary-card-list"
|
|
257
|
+
}, data.map(function (entry, index) {
|
|
256
258
|
var isInError = errors.filter(function (e) {
|
|
257
259
|
return e.entryId === entry.id;
|
|
258
260
|
}).length > 0;
|
|
@@ -260,7 +262,7 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
260
262
|
focusOn: (toFocusOn === null || toFocusOn === void 0 ? void 0 : toFocusOn.id) === entry.id
|
|
261
263
|
});
|
|
262
264
|
var key = "".concat(config.fieldId, ".summaryCard").concat(entry.id);
|
|
263
|
-
return /*#__PURE__*/_react.default.createElement(_SummaryCardValidationContext.default, {
|
|
265
|
+
return /*#__PURE__*/_react.default.createElement("li", null, /*#__PURE__*/_react.default.createElement(_SummaryCardValidationContext.default, {
|
|
264
266
|
entryId: entry.id,
|
|
265
267
|
topLevelErrors: errors,
|
|
266
268
|
clearTopLevelErrorsForCard: function clearTopLevelErrorsForCard() {
|
|
@@ -296,8 +298,8 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
296
298
|
inError: errors.filter(function (e) {
|
|
297
299
|
return e.entryId === entry.id;
|
|
298
300
|
}).length > 0
|
|
299
|
-
}));
|
|
300
|
-
}), config.card.listView && config.addButton && /*#__PURE__*/_react.default.createElement(_ActionButton.default, {
|
|
301
|
+
})));
|
|
302
|
+
})), config.card.listView && config.addButton && /*#__PURE__*/_react.default.createElement(_ActionButton.default, {
|
|
301
303
|
id: "".concat(config.fieldId, ".addButton"),
|
|
302
304
|
action: {
|
|
303
305
|
collection: config.collectionName,
|
|
@@ -57,9 +57,23 @@ describe('components.CollectionSummary.CollectionSummary', function () {
|
|
|
57
57
|
}];
|
|
58
58
|
var ON_ACTION = function ON_ACTION() {};
|
|
59
59
|
var checkSetup = function checkSetup(container) {
|
|
60
|
+
var withAddButton = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
60
61
|
var summaryDiv = container.children[0];
|
|
61
62
|
expect(summaryDiv.tagName).toEqual('DIV');
|
|
62
|
-
|
|
63
|
+
var cardList = withAddButton ? summaryDiv.children[1] : summaryDiv.children[0];
|
|
64
|
+
expect(cardList.tagName).toEqual('UL');
|
|
65
|
+
expect(cardList.classList).toContain('collection-summary-card-list');
|
|
66
|
+
var cards = Array.from(cardList.children, function (child) {
|
|
67
|
+
expect(child.tagName).toEqual('LI');
|
|
68
|
+
return child.children[0] || null;
|
|
69
|
+
}).filter(function (c) {
|
|
70
|
+
return !!c;
|
|
71
|
+
});
|
|
72
|
+
return {
|
|
73
|
+
summaryDiv: summaryDiv,
|
|
74
|
+
cardList: cardList,
|
|
75
|
+
cards: cards
|
|
76
|
+
};
|
|
63
77
|
};
|
|
64
78
|
it('should correctly render a CollectionSummary component', function () {
|
|
65
79
|
var _renderWithValidation = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
|
|
@@ -68,10 +82,11 @@ describe('components.CollectionSummary.CollectionSummary', function () {
|
|
|
68
82
|
onAction: ON_ACTION
|
|
69
83
|
})),
|
|
70
84
|
container = _renderWithValidation.container;
|
|
71
|
-
var
|
|
72
|
-
|
|
73
|
-
expect(
|
|
74
|
-
expect(
|
|
85
|
+
var _checkSetup = checkSetup(container),
|
|
86
|
+
cards = _checkSetup.cards;
|
|
87
|
+
expect(cards.length).toEqual(2);
|
|
88
|
+
expect(cards[0].id).toEqual("".concat(CONFIG.fieldId, ".summaryCard").concat(FORM_DATA.testCollection[0].id));
|
|
89
|
+
expect(cards[1].id).toEqual("".concat(CONFIG.fieldId, ".summaryCard").concat(FORM_DATA.testCollection[1].id));
|
|
75
90
|
});
|
|
76
91
|
it('should focus on the most recently duplicated item', function () {
|
|
77
92
|
var customConfig = {
|
|
@@ -145,14 +160,16 @@ describe('components.CollectionSummary.CollectionSummary', function () {
|
|
|
145
160
|
onAction: ON_ACTION
|
|
146
161
|
})),
|
|
147
162
|
container = _renderWithValidation4.container;
|
|
148
|
-
var
|
|
149
|
-
|
|
150
|
-
|
|
163
|
+
var _checkSetup2 = checkSetup(container),
|
|
164
|
+
summaryDiv = _checkSetup2.summaryDiv,
|
|
165
|
+
cards = _checkSetup2.cards;
|
|
166
|
+
expect(cards.length).toEqual(2);
|
|
167
|
+
var card = cards[0];
|
|
151
168
|
var deleteButton = card.children[0].children[1].children[0];
|
|
152
169
|
_react2.fireEvent.click(deleteButton, {});
|
|
153
|
-
expect(
|
|
154
|
-
expect(
|
|
155
|
-
expect(
|
|
170
|
+
expect(summaryDiv.children.length).toEqual(2); // Now with a confirmation.
|
|
171
|
+
expect(summaryDiv.children[0].id).toEqual("".concat(CONFIG.fieldId, ".confirmation"));
|
|
172
|
+
expect(summaryDiv.children[0].classList).toContain(_Confirmation.DEFAULT_CLASS);
|
|
156
173
|
});
|
|
157
174
|
describe('Add Another button', function () {
|
|
158
175
|
it('should render with an Add button if one is configured', function () {
|
|
@@ -174,11 +191,12 @@ describe('components.CollectionSummary.CollectionSummary', function () {
|
|
|
174
191
|
onAction: ON_ACTION
|
|
175
192
|
})),
|
|
176
193
|
container = _renderWithValidation5.container;
|
|
177
|
-
var
|
|
178
|
-
|
|
179
|
-
expect(
|
|
180
|
-
expect(
|
|
181
|
-
expect(
|
|
194
|
+
var _checkSetup3 = checkSetup(container, true),
|
|
195
|
+
summaryDiv = _checkSetup3.summaryDiv;
|
|
196
|
+
expect(summaryDiv.children.length).toEqual(2); // The button and card list.
|
|
197
|
+
expect(summaryDiv.children[0].id).toEqual("".concat(CONFIG_WITH_BUTTON.fieldId, ".addButton"));
|
|
198
|
+
expect(summaryDiv.children[0].textContent).toEqual(CONFIG_WITH_BUTTON.addButton.label);
|
|
199
|
+
expect(summaryDiv.children[0].tagName).toEqual('BUTTON');
|
|
182
200
|
});
|
|
183
201
|
it('should use the default button label if none is provided', function () {
|
|
184
202
|
var CONFIG_WITH_BUTTON = {
|
|
@@ -198,11 +216,12 @@ describe('components.CollectionSummary.CollectionSummary', function () {
|
|
|
198
216
|
onAction: ON_ACTION
|
|
199
217
|
})),
|
|
200
218
|
container = _renderWithValidation6.container;
|
|
201
|
-
var
|
|
202
|
-
|
|
203
|
-
expect(
|
|
204
|
-
expect(
|
|
205
|
-
expect(
|
|
219
|
+
var _checkSetup4 = checkSetup(container, true),
|
|
220
|
+
summaryDiv = _checkSetup4.summaryDiv;
|
|
221
|
+
expect(summaryDiv.children.length).toEqual(2); // The button and card list.
|
|
222
|
+
expect(summaryDiv.children[0].id).toEqual("".concat(CONFIG_WITH_BUTTON.fieldId, ".addButton"));
|
|
223
|
+
expect(summaryDiv.children[0].textContent).toEqual(_CollectionSummary.DEFAULT_ADD_BUTTON_LABEL);
|
|
224
|
+
expect(summaryDiv.children[0].tagName).toEqual('BUTTON');
|
|
206
225
|
});
|
|
207
226
|
it('should apply the expected class name to the summary card when delete button is pressed', function () {
|
|
208
227
|
var _renderWithValidation7 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
|
|
@@ -211,9 +230,10 @@ describe('components.CollectionSummary.CollectionSummary', function () {
|
|
|
211
230
|
onAction: ON_ACTION
|
|
212
231
|
})),
|
|
213
232
|
container = _renderWithValidation7.container;
|
|
214
|
-
var
|
|
215
|
-
|
|
216
|
-
|
|
233
|
+
var _checkSetup5 = checkSetup(container),
|
|
234
|
+
cards = _checkSetup5.cards;
|
|
235
|
+
expect(cards.length).toEqual(2);
|
|
236
|
+
var card = cards[0];
|
|
217
237
|
var deleteButton = card.children[0].children[1].children[0];
|
|
218
238
|
_react2.fireEvent.click(deleteButton, {});
|
|
219
239
|
var confirmation = container.querySelector(".".concat(_Confirmation.DEFAULT_CLASS));
|
|
@@ -227,9 +247,10 @@ describe('components.CollectionSummary.CollectionSummary', function () {
|
|
|
227
247
|
onAction: ON_ACTION
|
|
228
248
|
})),
|
|
229
249
|
container = _renderWithValidation8.container;
|
|
230
|
-
var
|
|
231
|
-
|
|
232
|
-
|
|
250
|
+
var _checkSetup6 = checkSetup(container),
|
|
251
|
+
cards = _checkSetup6.cards;
|
|
252
|
+
expect(cards.length).toEqual(2);
|
|
253
|
+
var card = cards[0];
|
|
233
254
|
var deleteButton = card.children[0].children[1].children[0];
|
|
234
255
|
_react2.fireEvent.click(deleteButton, {});
|
|
235
256
|
var confirmButton = container.querySelector(".".concat(_Confirmation.DEFAULT_CLASS, " button.hods-button--warning"));
|
|
@@ -243,9 +264,10 @@ describe('components.CollectionSummary.CollectionSummary', function () {
|
|
|
243
264
|
onAction: ON_ACTION
|
|
244
265
|
})),
|
|
245
266
|
container = _renderWithValidation9.container;
|
|
246
|
-
var
|
|
247
|
-
|
|
248
|
-
|
|
267
|
+
var _checkSetup7 = checkSetup(container),
|
|
268
|
+
cards = _checkSetup7.cards;
|
|
269
|
+
expect(cards.length).toEqual(2);
|
|
270
|
+
var card = cards[0];
|
|
249
271
|
var deleteButton = card.children[0].children[1].children[0];
|
|
250
272
|
_react2.fireEvent.click(deleteButton, {});
|
|
251
273
|
var confirmation = container.querySelector(".".concat(_Confirmation.DEFAULT_CLASS));
|
|
@@ -270,9 +292,10 @@ describe('components.CollectionSummary.CollectionSummary', function () {
|
|
|
270
292
|
})),
|
|
271
293
|
container = _renderWithValidation10.container,
|
|
272
294
|
getByText = _renderWithValidation10.getByText;
|
|
273
|
-
var
|
|
274
|
-
|
|
275
|
-
|
|
295
|
+
var _checkSetup8 = checkSetup(container),
|
|
296
|
+
cards = _checkSetup8.cards;
|
|
297
|
+
expect(cards.length).toEqual(2);
|
|
298
|
+
var card = cards[0];
|
|
276
299
|
var deleteButton = card.querySelector('.govuk-summary-card__actions li:last-child button');
|
|
277
300
|
_react2.fireEvent.click(deleteButton);
|
|
278
301
|
var confirmation = container.querySelector(".".concat(_Confirmation.DEFAULT_CLASS));
|
|
@@ -302,9 +325,10 @@ describe('components.CollectionSummary.CollectionSummary', function () {
|
|
|
302
325
|
})),
|
|
303
326
|
container = _renderWithValidation11.container,
|
|
304
327
|
getByText = _renderWithValidation11.getByText;
|
|
305
|
-
var
|
|
306
|
-
|
|
307
|
-
|
|
328
|
+
var _checkSetup9 = checkSetup(container),
|
|
329
|
+
cards = _checkSetup9.cards;
|
|
330
|
+
expect(cards.length).toEqual(2);
|
|
331
|
+
var card = cards[0];
|
|
308
332
|
var deleteButton = card.querySelector('.govuk-summary-card__actions li:last-child button');
|
|
309
333
|
_react2.fireEvent.click(deleteButton);
|
|
310
334
|
var confirmation = container.querySelector(".".concat(_Confirmation.DEFAULT_CLASS));
|