@ukhomeoffice/cop-react-form-renderer 5.83.3 → 5.84.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.
@@ -19,9 +19,11 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
19
19
  var Answer = function Answer(_ref) {
20
20
  var value = _ref.value,
21
21
  component = _ref.component,
22
- formData = _ref.formData;
22
+ formData = _ref.formData,
23
+ placeholder = _ref.placeholder;
23
24
  if (!value) {
24
- return /*#__PURE__*/_react.default.createElement(_VisuallyHidden.default, null, "No answer");
25
+ var placeholderValue = (component === null || component === void 0 ? void 0 : component.cyaPlaceholder) || placeholder;
26
+ return placeholderValue || /*#__PURE__*/_react.default.createElement(_VisuallyHidden.default, null, "No answer");
25
27
  }
26
28
  if (!component) {
27
29
  return Object.prototype.hasOwnProperty.call(value, 'label') ? value.label : value;
@@ -36,13 +38,17 @@ var Answer = function Answer(_ref) {
36
38
  });
37
39
  };
38
40
  Answer.propTypes = {
39
- component: _propTypes.default.shape({}),
41
+ component: _propTypes.default.shape({
42
+ cyaPlaceholder: _propTypes.default.string
43
+ }),
40
44
  formData: _propTypes.default.shape({}),
41
- value: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.shape({})])
45
+ value: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.shape({})]),
46
+ placeholder: _propTypes.default.string
42
47
  };
43
48
  Answer.defaultProps = {
44
49
  component: null,
45
50
  formData: null,
46
- value: null
51
+ value: null,
52
+ placeholder: null
47
53
  };
48
54
  var _default = exports.default = Answer;
@@ -75,31 +75,84 @@ describe('components', function () {
75
75
  }
76
76
  }, _callee3);
77
77
  })));
78
- it('should handle a null component and an object value', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
79
- var VALUE, COMPONENT, _renderWithValidation4, container;
78
+ it('should show a placeholder value for components without a value', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
79
+ var VALUE, PLACEHOLDER, COMPONENT, _renderWithValidation4, container, answer;
80
80
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
81
81
  while (1) switch (_context4.prev = _context4.next) {
82
+ case 0:
83
+ VALUE = '';
84
+ PLACEHOLDER = 'Not entered';
85
+ COMPONENT = {
86
+ id: 'alpha',
87
+ fieldId: 'alpha',
88
+ type: 'text',
89
+ label: 'Alpha'
90
+ };
91
+ _renderWithValidation4 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_Answer.default, {
92
+ value: VALUE,
93
+ component: COMPONENT,
94
+ placeholder: PLACEHOLDER
95
+ })), container = _renderWithValidation4.container;
96
+ answer = container.childNodes[0];
97
+ expect(answer.textContent).toEqual(PLACEHOLDER);
98
+ case 6:
99
+ case "end":
100
+ return _context4.stop();
101
+ }
102
+ }, _callee4);
103
+ })));
104
+ it('should use a component\'s placeholder value if one is defined', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
105
+ var VALUE, GLOBAL_PLACEHOLDER, COMPONENT, _renderWithValidation5, container, answer;
106
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
107
+ while (1) switch (_context5.prev = _context5.next) {
108
+ case 0:
109
+ VALUE = '';
110
+ GLOBAL_PLACEHOLDER = 'Not entered';
111
+ COMPONENT = {
112
+ id: 'alpha',
113
+ fieldId: 'alpha',
114
+ type: 'text',
115
+ label: 'Alpha',
116
+ cyaPlaceholder: 'Alpha not entered'
117
+ };
118
+ _renderWithValidation5 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_Answer.default, {
119
+ value: VALUE,
120
+ component: COMPONENT,
121
+ placeholder: GLOBAL_PLACEHOLDER
122
+ })), container = _renderWithValidation5.container;
123
+ answer = container.childNodes[0];
124
+ expect(answer.textContent).toEqual(COMPONENT.cyaPlaceholder);
125
+ case 6:
126
+ case "end":
127
+ return _context5.stop();
128
+ }
129
+ }, _callee5);
130
+ })));
131
+ it('should handle a null component and an object value', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
132
+ var VALUE, COMPONENT, _renderWithValidation6, container;
133
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
134
+ while (1) switch (_context6.prev = _context6.next) {
82
135
  case 0:
83
136
  VALUE = {
84
137
  label: 'A label',
85
138
  value: 'a_value'
86
139
  };
87
140
  COMPONENT = null;
88
- _renderWithValidation4 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_Answer.default, {
141
+ _renderWithValidation6 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_Answer.default, {
89
142
  value: VALUE,
90
143
  component: COMPONENT
91
- })), container = _renderWithValidation4.container;
144
+ })), container = _renderWithValidation6.container;
92
145
  expect(container.textContent).toEqual(VALUE.label);
93
146
  case 4:
94
147
  case "end":
95
- return _context4.stop();
148
+ return _context6.stop();
96
149
  }
97
- }, _callee4);
150
+ }, _callee6);
98
151
  })));
99
- it('should handle a component that requires interpolation', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
100
- var VALUE, DATA, COMPONENT, _renderWithValidation5, container, answer;
101
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
102
- while (1) switch (_context5.prev = _context5.next) {
152
+ it('should handle a component that requires interpolation', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
153
+ var VALUE, DATA, COMPONENT, _renderWithValidation7, container, answer;
154
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
155
+ while (1) switch (_context7.prev = _context7.next) {
103
156
  case 0:
104
157
  VALUE = 'beta';
105
158
  DATA = {
@@ -119,20 +172,20 @@ describe('components', function () {
119
172
  }]
120
173
  }
121
174
  };
122
- _renderWithValidation5 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_Answer.default, {
175
+ _renderWithValidation7 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_Answer.default, {
123
176
  value: VALUE,
124
177
  component: COMPONENT,
125
178
  formData: DATA
126
- })), container = _renderWithValidation5.container;
179
+ })), container = _renderWithValidation7.container;
127
180
  answer = container.childNodes[0];
128
181
  expect(answer.tagName).toEqual('DIV');
129
182
  expect(answer.classList).toContain(_Readonly.DEFAULT_CLASS);
130
183
  expect(answer.textContent).toEqual('hardcoded delta');
131
184
  case 8:
132
185
  case "end":
133
- return _context5.stop();
186
+ return _context7.stop();
134
187
  }
135
- }, _callee5);
188
+ }, _callee7);
136
189
  })));
137
190
  });
138
191
  });
@@ -51,7 +51,8 @@ var CheckYourAnswers = function CheckYourAnswers(_ref) {
51
51
  groups = _ref.groups,
52
52
  sections = _ref.sections,
53
53
  type = _ref.type,
54
- hideBlankRows = _ref.hideBlankRows;
54
+ hideBlankRows = _ref.hideBlankRows,
55
+ optionalFieldPlaceholder = _ref.optionalFieldPlaceholder;
55
56
  var _useState = (0, _react.useState)([]),
56
57
  _useState2 = _slicedToArray(_useState, 2),
57
58
  pages = _useState2[0],
@@ -73,7 +74,8 @@ var CheckYourAnswers = function CheckYourAnswers(_ref) {
73
74
  key: "".concat(pageIndex, "_").concat(index),
74
75
  value: row.value,
75
76
  component: row.component,
76
- formData: page.formData
77
+ formData: page.formData,
78
+ placeholder: optionalFieldPlaceholder
77
79
  })
78
80
  });
79
81
  });
@@ -233,7 +235,8 @@ CheckYourAnswers.propTypes = {
233
235
  summaryListClassModifiers: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
234
236
  title: _propTypes.default.string,
235
237
  type: _propTypes.default.string,
236
- hideBlankRows: _propTypes.default.bool
238
+ hideBlankRows: _propTypes.default.bool,
239
+ optionalFieldPlaceholder: _propTypes.default.string
237
240
  };
238
241
  CheckYourAnswers.defaultProps = {
239
242
  actions: [],
@@ -247,6 +250,7 @@ CheckYourAnswers.defaultProps = {
247
250
  summaryListClassModifiers: null,
248
251
  title: DEFAULT_TITLE,
249
252
  type: null,
250
- hideBlankRows: false
253
+ hideBlankRows: false,
254
+ optionalFieldPlaceholder: null
251
255
  };
252
256
  var _default = exports.default = CheckYourAnswers;
@@ -673,10 +673,53 @@ describe('components', function () {
673
673
  }
674
674
  }, _callee26);
675
675
  })));
676
- it('should show page components corrently with interpolated title and cya_label, if label is missing', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
677
- var _PAGES, _COMPONENTS, T_PAGES, cya, _cya$childNodes7, cyaTitle, cyaChildNode, names, _names$childNodes3, firstName, surname, _firstName$childNodes, label;
676
+ it('should render empty optional fields with a placeholder value when provided', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
677
+ var GROUP_PAGES, cya, namesGroup, firstNameRow, surname;
678
678
  return _regeneratorRuntime().wrap(function _callee28$(_context28) {
679
679
  while (1) switch (_context28.prev = _context28.next) {
680
+ case 0:
681
+ GROUP_PAGES = _utils.default.FormPage.getAll(_groupOfRow.default.pages, _groupOfRow.default.components, {});
682
+ _context28.next = 3;
683
+ return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
684
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
685
+ while (1) switch (_context27.prev = _context27.next) {
686
+ case 0:
687
+ (0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, {
688
+ pages: GROUP_PAGES,
689
+ groups: _groupOfRow.default.cya.groups,
690
+ optionalFieldPlaceholder: "Not entered"
691
+ }), container);
692
+ case 1:
693
+ case "end":
694
+ return _context27.stop();
695
+ }
696
+ }, _callee27);
697
+ })));
698
+ case 3:
699
+ cya = checkCYA(container);
700
+ namesGroup = cya.childNodes[2];
701
+ firstNameRow = namesGroup.childNodes[0].childNodes[0];
702
+ expect(firstNameRow.childNodes.length).toEqual(2);
703
+ expect(firstNameRow.childNodes[0].textContent).toEqual('First name (optional)');
704
+ expect(firstNameRow.childNodes[0].tagName).toEqual('DT');
705
+ expect(firstNameRow.childNodes[1].textContent).toEqual('Not entered');
706
+ expect(firstNameRow.childNodes[1].tagName).toEqual('DD');
707
+ surname = namesGroup.childNodes[0].childNodes[1];
708
+ expect(surname.childNodes.length).toEqual(2);
709
+ expect(surname.childNodes[0].textContent).toEqual('Last name (optional)');
710
+ expect(surname.childNodes[0].tagName).toEqual('DT');
711
+ expect(surname.childNodes[1].textContent).toEqual('Not entered');
712
+ expect(surname.childNodes[1].tagName).toEqual('DD');
713
+ case 17:
714
+ case "end":
715
+ return _context28.stop();
716
+ }
717
+ }, _callee28);
718
+ })));
719
+ it('should show page components corrently with interpolated title and cya_label, if label is missing', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
720
+ var _PAGES, _COMPONENTS, T_PAGES, cya, _cya$childNodes7, cyaTitle, cyaChildNode, names, _names$childNodes3, firstName, surname, _firstName$childNodes, label;
721
+ return _regeneratorRuntime().wrap(function _callee30$(_context30) {
722
+ while (1) switch (_context30.prev = _context30.next) {
680
723
  case 0:
681
724
  _PAGES = [].concat(_userProfile.default.pages); // eslint-disable-next-line no-template-curly-in-string
682
725
  _PAGES[0] = _objectSpread(_objectSpread({}, _PAGES[0]), {}, {
@@ -690,10 +733,10 @@ describe('components', function () {
690
733
  cya_label: "Text ${currentUser.familyName}"
691
734
  });
692
735
  T_PAGES = _utils.default.FormPage.getAll(_PAGES, _COMPONENTS, DATA);
693
- _context28.next = 7;
694
- return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
695
- return _regeneratorRuntime().wrap(function _callee27$(_context27) {
696
- while (1) switch (_context27.prev = _context27.next) {
736
+ _context30.next = 7;
737
+ return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
738
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
739
+ while (1) switch (_context29.prev = _context29.next) {
697
740
  case 0:
698
741
  (0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, {
699
742
  pages: T_PAGES,
@@ -702,9 +745,9 @@ describe('components', function () {
702
745
  }), container);
703
746
  case 1:
704
747
  case "end":
705
- return _context27.stop();
748
+ return _context29.stop();
706
749
  }
707
- }, _callee27);
750
+ }, _callee29);
708
751
  })));
709
752
  case 7:
710
753
  cya = checkCYA(container);
@@ -719,14 +762,14 @@ describe('components', function () {
719
762
  checkRow(surname, 'Last name', 'Smith', false);
720
763
  case 17:
721
764
  case "end":
722
- return _context28.stop();
765
+ return _context30.stop();
723
766
  }
724
- }, _callee28);
767
+ }, _callee30);
725
768
  })));
726
- it('should show page components corrently with no label, if label and cya_label are missing', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
769
+ it('should show page components corrently with no label, if label and cya_label are missing', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
727
770
  var _PAGES, _COMPONENTS, T_PAGES, cya, _cya$childNodes8, cyaChildNode, names, _names$childNodes4, firstName, surname, _firstName$childNodes2, label;
728
- return _regeneratorRuntime().wrap(function _callee30$(_context30) {
729
- while (1) switch (_context30.prev = _context30.next) {
771
+ return _regeneratorRuntime().wrap(function _callee32$(_context32) {
772
+ while (1) switch (_context32.prev = _context32.next) {
730
773
  case 0:
731
774
  _PAGES = [].concat(_userProfile.default.pages);
732
775
  _COMPONENTS = [].concat(_userProfile.default.components);
@@ -736,10 +779,10 @@ describe('components', function () {
736
779
  cya_label: undefined
737
780
  });
738
781
  T_PAGES = _utils.default.FormPage.getAll(_PAGES, _COMPONENTS, _objectSpread({}, DATA));
739
- _context30.next = 6;
740
- return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
741
- return _regeneratorRuntime().wrap(function _callee29$(_context29) {
742
- while (1) switch (_context29.prev = _context29.next) {
782
+ _context32.next = 6;
783
+ return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
784
+ return _regeneratorRuntime().wrap(function _callee31$(_context31) {
785
+ while (1) switch (_context31.prev = _context31.next) {
743
786
  case 0:
744
787
  (0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, {
745
788
  pages: T_PAGES,
@@ -748,9 +791,9 @@ describe('components', function () {
748
791
  }), container);
749
792
  case 1:
750
793
  case "end":
751
- return _context29.stop();
794
+ return _context31.stop();
752
795
  }
753
- }, _callee29);
796
+ }, _callee31);
754
797
  })));
755
798
  case 6:
756
799
  cya = checkCYA(container);
@@ -764,14 +807,14 @@ describe('components', function () {
764
807
  checkRow(surname, 'Last name', 'Smith', false);
765
808
  case 15:
766
809
  case "end":
767
- return _context30.stop();
810
+ return _context32.stop();
768
811
  }
769
- }, _callee30);
812
+ }, _callee32);
770
813
  })));
771
- it('should show task list in CYA style and hide pages from skipped tasks', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
814
+ it('should show task list in CYA style and hide pages from skipped tasks', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34() {
772
815
  var sections, taskHeading1, namesPageHeading;
773
- return _regeneratorRuntime().wrap(function _callee32$(_context32) {
774
- while (1) switch (_context32.prev = _context32.next) {
816
+ return _regeneratorRuntime().wrap(function _callee34$(_context34) {
817
+ while (1) switch (_context34.prev = _context34.next) {
775
818
  case 0:
776
819
  sections = [{
777
820
  name: 'These are your tasks',
@@ -785,10 +828,10 @@ describe('components', function () {
785
828
  pages: ['grade']
786
829
  }]
787
830
  }];
788
- _context32.next = 3;
789
- return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
790
- return _regeneratorRuntime().wrap(function _callee31$(_context31) {
791
- while (1) switch (_context31.prev = _context31.next) {
831
+ _context34.next = 3;
832
+ return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
833
+ return _regeneratorRuntime().wrap(function _callee33$(_context33) {
834
+ while (1) switch (_context33.prev = _context33.next) {
792
835
  case 0:
793
836
  (0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, {
794
837
  pages: PAGES,
@@ -800,9 +843,9 @@ describe('components', function () {
800
843
  }), container);
801
844
  case 1:
802
845
  case "end":
803
- return _context31.stop();
846
+ return _context33.stop();
804
847
  }
805
- }, _callee31);
848
+ }, _callee33);
806
849
  })));
807
850
  case 3:
808
851
  taskHeading1 = container.childNodes[0].childNodes[0];
@@ -816,21 +859,21 @@ describe('components', function () {
816
859
  expect(container.childNodes[0].childNodes.length).toEqual(2); // second task skipped so not shown
817
860
  case 12:
818
861
  case "end":
819
- return _context32.stop();
862
+ return _context34.stop();
820
863
  }
821
- }, _callee32);
864
+ }, _callee34);
822
865
  })));
823
- it('Show answers from multiple address fields into in one DL correctly when hideBlankRows is true', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34() {
866
+ it('Show answers from multiple address fields into in one DL correctly when hideBlankRows is true', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36() {
824
867
  var ADDRESS_DATA, GROUP_PAGES, cya, groupedComponent, keyGroup, valueGroup, changeButtonDiv, changeButton;
825
- return _regeneratorRuntime().wrap(function _callee34$(_context34) {
826
- while (1) switch (_context34.prev = _context34.next) {
868
+ return _regeneratorRuntime().wrap(function _callee36$(_context36) {
869
+ while (1) switch (_context36.prev = _context36.next) {
827
870
  case 0:
828
871
  ADDRESS_DATA = _utils.default.Data.setupForm(_group.default.pages, _group.default.components, _groupData.default);
829
872
  GROUP_PAGES = _utils.default.FormPage.getAll(_group.default.pages, _group.default.components, _objectSpread({}, ADDRESS_DATA));
830
- _context34.next = 4;
831
- return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
832
- return _regeneratorRuntime().wrap(function _callee33$(_context33) {
833
- while (1) switch (_context33.prev = _context33.next) {
873
+ _context36.next = 4;
874
+ return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35() {
875
+ return _regeneratorRuntime().wrap(function _callee35$(_context35) {
876
+ while (1) switch (_context35.prev = _context35.next) {
834
877
  case 0:
835
878
  (0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, {
836
879
  pages: GROUP_PAGES,
@@ -841,9 +884,9 @@ describe('components', function () {
841
884
  }), container);
842
885
  case 1:
843
886
  case "end":
844
- return _context33.stop();
887
+ return _context35.stop();
845
888
  }
846
- }, _callee33);
889
+ }, _callee35);
847
890
  })));
848
891
  case 4:
849
892
  cya = checkCYA(container);
@@ -865,9 +908,9 @@ describe('components', function () {
865
908
  expect(changeButton.textContent).toEqual('Change address details');
866
909
  case 21:
867
910
  case "end":
868
- return _context34.stop();
911
+ return _context36.stop();
869
912
  }
870
- }, _callee34);
913
+ }, _callee36);
871
914
  })));
872
915
  });
873
916
  });
@@ -47,7 +47,7 @@ var DEFAULT_DUPLICATE_BUTTON_LABEL = exports.DEFAULT_DUPLICATE_BUTTON_LABEL = 'D
47
47
  var DEFAULT_DETAILS_TITLE = exports.DEFAULT_DETAILS_TITLE = 'Full details';
48
48
  var DEFAULT_CHANGE_BUTTON_CLASS = exports.DEFAULT_CHANGE_BUTTON_CLASS = 'secondary';
49
49
  var SummaryCard = function SummaryCard(_ref) {
50
- var _config$changeAction2, _config$changeAction3, _config$changeAction4, _config$deleteAction, _config$deleteAction2, _config$duplicateActi, _config$duplicateActi2;
50
+ var _config$changeAction2, _config$changeAction3, _config$changeAction4, _config$deleteAction, _config$deleteAction2, _config$duplicateActi, _config$duplicateActi2, _config$fullDetails;
51
51
  var id = _ref.id,
52
52
  entryData = _ref.entryData,
53
53
  config = _ref.config,
@@ -233,7 +233,8 @@ var SummaryCard = function SummaryCard(_ref) {
233
233
  masterPage: masterPage,
234
234
  childCollections: childCollections,
235
235
  formData: formData,
236
- entryData: entryData
236
+ entryData: entryData,
237
+ optionalFieldPlaceholder: ((_config$fullDetails = config.fullDetails) === null || _config$fullDetails === void 0 ? void 0 : _config$fullDetails.optionalFieldPlaceholder) || ''
237
238
  }))));
238
239
  };
239
240
  SummaryCard.propTypes = {
@@ -268,7 +269,10 @@ SummaryCard.propTypes = {
268
269
  }),
269
270
  detailsTitle: _propTypes.default.string,
270
271
  listView: _propTypes.default.bool,
271
- focusOn: _propTypes.default.bool
272
+ focusOn: _propTypes.default.bool,
273
+ fullDetails: _propTypes.default.shape({
274
+ optionalFieldPlaceholder: _propTypes.default.string
275
+ })
272
276
  }).isRequired,
273
277
  masterPage: _propTypes.default.shape({
274
278
  childPages: _propTypes.default.arrayOf(_propTypes.default.shape({
@@ -33,7 +33,8 @@ var SummaryCardDetails = function SummaryCardDetails(_ref) {
33
33
  formData = _ref.formData,
34
34
  entryData = _ref.entryData,
35
35
  classModifiers = _ref.classModifiers,
36
- hideChildSectionTitles = _ref.hideChildSectionTitles;
36
+ hideChildSectionTitles = _ref.hideChildSectionTitles,
37
+ optionalFieldPlaceholder = _ref.optionalFieldPlaceholder;
37
38
  var classes = _utils.default.classBuilder(DEFAULT_CLASS, classModifiers);
38
39
  var childMasterPages = (0, _react.useMemo)(function () {
39
40
  return childCollections.map(function (childName) {
@@ -74,7 +75,7 @@ var SummaryCardDetails = function SummaryCardDetails(_ref) {
74
75
  var modEntry = _objectSpread(_objectSpread({}, entryData), _defineProperty({}, subComponent.fieldId, (_entryData$component$ = entryData[component.fieldId]) === null || _entryData$component$ === void 0 ? void 0 : _entryData$component$[subComponent.fieldId]));
75
76
  return (0, _getSummaryListRowForDetails.default)(childPage, _objectSpread(_objectSpread({}, subComponent), {
76
77
  label: subComponent.key
77
- }), classes, modEntry);
78
+ }), classes, modEntry, optionalFieldPlaceholder);
78
79
  }));
79
80
  }
80
81
  if (component.type === _models.ComponentTypes.COLLECTION) {
@@ -96,7 +97,7 @@ var SummaryCardDetails = function SummaryCardDetails(_ref) {
96
97
  var modEntry = _objectSpread(_objectSpread({}, entryData), _defineProperty({}, subComponent.fieldId, (_entryData$component$2 = entryData[component.fieldId]) === null || _entryData$component$2 === void 0 ? void 0 : _entryData$component$2[subComponent.fieldId]));
97
98
  var rowContent = (0, _getSummaryListRowForDetails.default)(childPage, _objectSpread(_objectSpread({}, subComponent), {
98
99
  label: subComponent.key
99
- }), classes, modEntry);
100
+ }), classes, modEntry, optionalFieldPlaceholder);
100
101
  // Because collections are flat, we need to identify the subsequent titles (2, 3, 4... etc) in order to apply appropriate spacing
101
102
  if (subComponent.type === 'title') {
102
103
  collectionHeadingIndex += 1;
@@ -119,7 +120,7 @@ var SummaryCardDetails = function SummaryCardDetails(_ref) {
119
120
  '--column': columnIndex + 1,
120
121
  '--row': rowIndex
121
122
  }
122
- }, (0, _getSummaryListRowForDetails.default)(childPage, component, classes, entryData));
123
+ }, (0, _getSummaryListRowForDetails.default)(childPage, component, classes, entryData, optionalFieldPlaceholder));
123
124
  });
124
125
  }).filter(function (e) {
125
126
  return !!e;
@@ -200,11 +201,13 @@ SummaryCardDetails.propTypes = {
200
201
  formData: _propTypes.default.shape({}).isRequired,
201
202
  entryData: _propTypes.default.shape({}).isRequired,
202
203
  classModifiers: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
203
- hideChildSectionTitles: _propTypes.default.bool
204
+ hideChildSectionTitles: _propTypes.default.bool,
205
+ optionalFieldPlaceholder: _propTypes.default.string
204
206
  };
205
207
  SummaryCardDetails.defaultProps = {
206
208
  childCollections: [],
207
209
  classModifiers: null,
208
- hideChildSectionTitles: false
210
+ hideChildSectionTitles: false,
211
+ optionalFieldPlaceholder: null
209
212
  };
210
213
  var _default = exports.default = SummaryCardDetails;
@@ -16,7 +16,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
16
16
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
17
17
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
18
18
  function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } // Local imports
19
- var getSummaryListRowForDetails = function getSummaryListRowForDetails(page, component, customClasses, entryData) {
19
+ var getSummaryListRowForDetails = function getSummaryListRowForDetails(page, component, customClasses, entryData, optionalFieldPlaceholder) {
20
20
  var modifiedPage = _objectSpread(_objectSpread({}, page), {}, {
21
21
  formData: _objectSpread(_objectSpread({}, page.formData), entryData)
22
22
  });
@@ -31,7 +31,8 @@ var getSummaryListRowForDetails = function getSummaryListRowForDetails(page, com
31
31
  value: /*#__PURE__*/_react.default.createElement(_Answer.default, {
32
32
  value: row.value || component.value,
33
33
  component: row.component,
34
- formData: modifiedPage.formData
34
+ formData: modifiedPage.formData,
35
+ placeholder: optionalFieldPlaceholder
35
36
  }),
36
37
  required: row.required
37
38
  },
@@ -1,41 +1,56 @@
1
1
  "use strict";
2
2
 
3
- var _getCYARowsForPage = _interopRequireDefault(require("./getCYARowsForPage"));
3
+ var _getSummaryListRowForDetails = _interopRequireDefault(require("./getSummaryListRowForDetails"));
4
4
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
5
- describe('utils.CheckYourAnswers.getCYARowsForPage', function () {
5
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
6
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
7
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
8
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
9
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
10
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
11
+ describe('utils.CheckYourAnswers.getSummaryListRowForDetails', function () {
6
12
  var COMPONENT_A = {
7
13
  type: 'text',
8
14
  id: 'a',
9
15
  fieldId: 'a',
10
16
  label: 'Alpha'
11
17
  };
12
- var COMPONENT_B = {
13
- type: 'text',
14
- id: 'b',
15
- fieldId: 'b',
16
- label: 'Bravo'
18
+ var TITLE = {
19
+ type: 'title',
20
+ key: 'Bravo'
17
21
  };
18
22
  var PAGE = {
19
23
  id: 'page',
20
- components: [COMPONENT_A, COMPONENT_B],
24
+ components: [COMPONENT_A],
21
25
  formData: {
22
- a: 'Alpha Value',
23
- b: 'Bravo Value'
26
+ a: 'Alpha Value'
24
27
  }
25
28
  };
26
- var ON_ACTION = function ON_ACTION() {};
27
- it('should get rows for a page with readonly text components', function () {
28
- var rows = (0, _getCYARowsForPage.default)(PAGE, ON_ACTION);
29
- expect(rows.length).toEqual(2);
30
- expect(rows[0]).toEqual(expect.objectContaining({
31
- fieldId: COMPONENT_A.fieldId,
32
- key: COMPONENT_A.label,
33
- value: 'Alpha Value'
34
- }));
35
- expect(rows[1]).toEqual(expect.objectContaining({
36
- fieldId: COMPONENT_B.fieldId,
37
- key: COMPONENT_B.label,
38
- value: 'Bravo Value'
39
- }));
29
+ it('should get a summary list row for a component', function () {
30
+ var row = (0, _getSummaryListRowForDetails.default)(PAGE, COMPONENT_A, null, {});
31
+ expect(row.props.row.key).toEqual(COMPONENT_A.label);
32
+ expect(row.props.row.value.props).toMatchObject({
33
+ component: COMPONENT_A,
34
+ value: PAGE.formData[COMPONENT_A.fieldId]
35
+ });
36
+ });
37
+ it('should get a summary list title row for a component with a type of title', function () {
38
+ var row = (0, _getSummaryListRowForDetails.default)(PAGE, TITLE, null, {});
39
+ expect(row.props.title).toEqual(TITLE.key);
40
+ });
41
+ it('should use a placeholder value for empty optional fields if one is provided', function () {
42
+ var CUSTOM_PAGE = _objectSpread(_objectSpread({}, PAGE), {}, {
43
+ components: [{
44
+ type: 'text',
45
+ fieldId: 'componentA',
46
+ label: 'Component A',
47
+ required: false
48
+ }]
49
+ });
50
+ var summaryListRow = (0, _getSummaryListRowForDetails.default)(CUSTOM_PAGE, CUSTOM_PAGE.components[0], null, {}, 'Not entered');
51
+ expect(summaryListRow.props.row.key).toEqual('Component A');
52
+ expect(summaryListRow.props.row.value.props).toMatchObject({
53
+ placeholder: 'Not entered'
54
+ });
40
55
  });
41
56
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "5.83.3",
3
+ "version": "5.84.1",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",