@ukhomeoffice/cop-react-form-renderer 3.3.2-alpha → 3.3.4
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 +1 -1
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +112 -0
- package/dist/components/FormComponent/FormComponent.js +1 -0
- package/dist/components/FormComponent/FormComponent.test.js +57 -0
- package/dist/hooks/useRefData.js +5 -3
- package/dist/utils/CheckYourAnswers/getCYARow.js +4 -1
- package/dist/utils/CheckYourAnswers/getCYARow.test.js +56 -0
- package/dist/utils/Data/refDataToOptions.js +21 -5
- package/dist/utils/Data/refDataToOptions.test.js +68 -0
- package/dist/utils/Data/setupRefDataUrlForComponent.js +36 -6
- package/dist/utils/Data/setupRefDataUrlForComponent.test.js +51 -1
- package/dist/utils/FormPage/getFormPage.js +1 -1
- package/dist/utils/FormPage/getFormPage.test.js +1 -1
- package/dist/utils/FormPage/useComponent.js +1 -1
- package/dist/utils/FormPage/useComponent.test.js +32 -2
- package/package.json +1 -1
|
@@ -154,7 +154,7 @@ var CheckYourAnswers = function CheckYourAnswers(_ref) {
|
|
|
154
154
|
isGroup(page.id) ? hideActionButtons = true : hideActionButtons = noChangeAction;
|
|
155
155
|
return /*#__PURE__*/_react.default.createElement(_react.Fragment, {
|
|
156
156
|
key: pageIndex
|
|
157
|
-
}, !hide_page_titles && page.title && !isGroup(page.id) && /*#__PURE__*/_react.default.createElement(_copReactComponents.MediumHeading, null, page.title), isGroup(page.id) && /*#__PURE__*/_react.default.createElement("div", {
|
|
157
|
+
}, !hide_page_titles && page.title && !isGroup(page.id) && /*#__PURE__*/_react.default.createElement(_copReactComponents.MediumHeading, null, _utils.default.interpolateString(page.title, page.formData)), isGroup(page.id) && /*#__PURE__*/_react.default.createElement("div", {
|
|
158
158
|
className: "group-title"
|
|
159
159
|
}, /*#__PURE__*/_react.default.createElement(_copReactComponents.MediumHeading, null, currentGroup.title || page.title)), /*#__PURE__*/_react.default.createElement(_SummaryList.default, {
|
|
160
160
|
className: className,
|
|
@@ -495,5 +495,117 @@ describe('components', function () {
|
|
|
495
495
|
}
|
|
496
496
|
}, _callee16);
|
|
497
497
|
})));
|
|
498
|
+
it('should show page components corrently with interpolated title and cya_label, if label is missing', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee18() {
|
|
499
|
+
var _PAGES, _COMPONENTS, T_PAGES, cya, _cya$childNodes5, cyaTitle, cyaChildNode, names, _names$childNodes3, firstName, surname, _firstName$childNodes, label, value;
|
|
500
|
+
|
|
501
|
+
return regeneratorRuntime.wrap(function _callee18$(_context18) {
|
|
502
|
+
while (1) {
|
|
503
|
+
switch (_context18.prev = _context18.next) {
|
|
504
|
+
case 0:
|
|
505
|
+
_PAGES = [].concat(_userProfile.default.pages); // eslint-disable-next-line no-template-curly-in-string
|
|
506
|
+
|
|
507
|
+
_PAGES[0] = _objectSpread(_objectSpread({}, _PAGES[0]), {}, {
|
|
508
|
+
title: 'Alpha ID: ${businessKey}'
|
|
509
|
+
});
|
|
510
|
+
_COMPONENTS = [].concat(_userProfile.default.components);
|
|
511
|
+
_COMPONENTS[0] = _objectSpread(_objectSpread({}, _COMPONENTS[0]), {}, {
|
|
512
|
+
label: undefined,
|
|
513
|
+
required: true,
|
|
514
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
515
|
+
cya_label: "Text ${currentUser.familyName}"
|
|
516
|
+
});
|
|
517
|
+
T_PAGES = _utils.default.FormPage.getAll(_PAGES, _COMPONENTS, DATA);
|
|
518
|
+
_context18.next = 7;
|
|
519
|
+
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee17() {
|
|
520
|
+
return regeneratorRuntime.wrap(function _callee17$(_context17) {
|
|
521
|
+
while (1) {
|
|
522
|
+
switch (_context17.prev = _context17.next) {
|
|
523
|
+
case 0:
|
|
524
|
+
(0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, {
|
|
525
|
+
pages: T_PAGES,
|
|
526
|
+
onRowAction: ON_ROW_ACTION,
|
|
527
|
+
onAction: ON_ACTION
|
|
528
|
+
}), container);
|
|
529
|
+
|
|
530
|
+
case 1:
|
|
531
|
+
case "end":
|
|
532
|
+
return _context17.stop();
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
}, _callee17);
|
|
536
|
+
})));
|
|
537
|
+
|
|
538
|
+
case 7:
|
|
539
|
+
cya = checkCYA(container);
|
|
540
|
+
_cya$childNodes5 = _slicedToArray(cya.childNodes, 3), cyaTitle = _cya$childNodes5[1], cyaChildNode = _cya$childNodes5[2];
|
|
541
|
+
expect(cyaTitle.textContent).toEqual('Alpha ID: 123456789');
|
|
542
|
+
names = cyaChildNode.childNodes[0];
|
|
543
|
+
expect(names.tagName).toEqual('DL');
|
|
544
|
+
expect(names.classList).toContain("govuk-!-margin-bottom-".concat(_CheckYourAnswers.DEFAULT_MARGIN_BOTTOM));
|
|
545
|
+
_names$childNodes3 = _slicedToArray(names.childNodes, 2), firstName = _names$childNodes3[0], surname = _names$childNodes3[1];
|
|
546
|
+
_firstName$childNodes = _slicedToArray(firstName.childNodes, 2), label = _firstName$childNodes[0], value = _firstName$childNodes[1];
|
|
547
|
+
expect(label.textContent).toEqual('Text Smith');
|
|
548
|
+
checkRow(surname, 'Last name', 'Smith', false);
|
|
549
|
+
|
|
550
|
+
case 17:
|
|
551
|
+
case "end":
|
|
552
|
+
return _context18.stop();
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
}, _callee18);
|
|
556
|
+
})));
|
|
557
|
+
it('should show page components corrently with no label, if label and cya_label are missing', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee20() {
|
|
558
|
+
var _PAGES, _COMPONENTS, T_PAGES, cya, _cya$childNodes6, cyaChildNode, names, _names$childNodes4, firstName, surname, _firstName$childNodes2, label, value;
|
|
559
|
+
|
|
560
|
+
return regeneratorRuntime.wrap(function _callee20$(_context20) {
|
|
561
|
+
while (1) {
|
|
562
|
+
switch (_context20.prev = _context20.next) {
|
|
563
|
+
case 0:
|
|
564
|
+
_PAGES = [].concat(_userProfile.default.pages);
|
|
565
|
+
_COMPONENTS = [].concat(_userProfile.default.components);
|
|
566
|
+
_COMPONENTS[0] = _objectSpread(_objectSpread({}, _COMPONENTS[0]), {}, {
|
|
567
|
+
label: undefined,
|
|
568
|
+
required: true,
|
|
569
|
+
cya_label: undefined
|
|
570
|
+
});
|
|
571
|
+
T_PAGES = _utils.default.FormPage.getAll(_PAGES, _COMPONENTS, _objectSpread({}, DATA));
|
|
572
|
+
_context20.next = 6;
|
|
573
|
+
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee19() {
|
|
574
|
+
return regeneratorRuntime.wrap(function _callee19$(_context19) {
|
|
575
|
+
while (1) {
|
|
576
|
+
switch (_context19.prev = _context19.next) {
|
|
577
|
+
case 0:
|
|
578
|
+
(0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, {
|
|
579
|
+
pages: T_PAGES,
|
|
580
|
+
onRowAction: ON_ROW_ACTION,
|
|
581
|
+
onAction: ON_ACTION
|
|
582
|
+
}), container);
|
|
583
|
+
|
|
584
|
+
case 1:
|
|
585
|
+
case "end":
|
|
586
|
+
return _context19.stop();
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}, _callee19);
|
|
590
|
+
})));
|
|
591
|
+
|
|
592
|
+
case 6:
|
|
593
|
+
cya = checkCYA(container);
|
|
594
|
+
_cya$childNodes6 = _slicedToArray(cya.childNodes, 2), cyaChildNode = _cya$childNodes6[1];
|
|
595
|
+
names = cyaChildNode.childNodes[0];
|
|
596
|
+
expect(names.tagName).toEqual('DL');
|
|
597
|
+
expect(names.classList).toContain("govuk-!-margin-bottom-".concat(_CheckYourAnswers.DEFAULT_MARGIN_BOTTOM));
|
|
598
|
+
_names$childNodes4 = _slicedToArray(names.childNodes, 2), firstName = _names$childNodes4[0], surname = _names$childNodes4[1];
|
|
599
|
+
_firstName$childNodes2 = _slicedToArray(firstName.childNodes, 2), label = _firstName$childNodes2[0], value = _firstName$childNodes2[1];
|
|
600
|
+
expect(label.textContent).toEqual("");
|
|
601
|
+
checkRow(surname, 'Last name', 'Smith', false);
|
|
602
|
+
|
|
603
|
+
case 15:
|
|
604
|
+
case "end":
|
|
605
|
+
return _context20.stop();
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
}, _callee20);
|
|
609
|
+
})));
|
|
498
610
|
});
|
|
499
611
|
});
|
|
@@ -143,6 +143,7 @@ var FormComponent = function FormComponent(_ref) {
|
|
|
143
143
|
label: _utils.default.interpolateString(component.label, formData),
|
|
144
144
|
content: _utils.default.interpolateString(component.content, formData),
|
|
145
145
|
hint: _utils.default.interpolateString(component.hint, formData),
|
|
146
|
+
cya_label: _utils.default.interpolateString(component.cya_label, formData),
|
|
146
147
|
options: options,
|
|
147
148
|
value: value || _utils.default.Component.defaultValue(component),
|
|
148
149
|
onChange: onComponentChangeExtended,
|
|
@@ -203,5 +203,62 @@ describe('components', function () {
|
|
|
203
203
|
}
|
|
204
204
|
}, _callee5);
|
|
205
205
|
})));
|
|
206
|
+
it('should render a text component appropriately with interpolated label', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() {
|
|
207
|
+
var ID, VALUE, COMPONENT, DATA, ON_CHANGE, _renderWithValidation6, container, formGroup, label, hint, input;
|
|
208
|
+
|
|
209
|
+
return regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
210
|
+
while (1) {
|
|
211
|
+
switch (_context6.prev = _context6.next) {
|
|
212
|
+
case 0:
|
|
213
|
+
ID = 'component';
|
|
214
|
+
VALUE = 'Text value'; // eslint-disable-next-line no-template-curly-in-string
|
|
215
|
+
|
|
216
|
+
COMPONENT = {
|
|
217
|
+
id: ID,
|
|
218
|
+
fieldId: ID,
|
|
219
|
+
type: 'text',
|
|
220
|
+
label: '${text} Text component',
|
|
221
|
+
cya_label: '${text} Text component',
|
|
222
|
+
hint: 'Text hint'
|
|
223
|
+
};
|
|
224
|
+
DATA = {
|
|
225
|
+
text: 'Interpolated'
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
ON_CHANGE = function ON_CHANGE() {};
|
|
229
|
+
|
|
230
|
+
_renderWithValidation6 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
231
|
+
"data-testid": ID,
|
|
232
|
+
component: COMPONENT,
|
|
233
|
+
value: VALUE,
|
|
234
|
+
onChange: ON_CHANGE,
|
|
235
|
+
formData: DATA
|
|
236
|
+
})), container = _renderWithValidation6.container; // text components are wrapper in a FormGroup by default.
|
|
237
|
+
|
|
238
|
+
formGroup = container.childNodes[0];
|
|
239
|
+
expect(formGroup.tagName).toEqual('DIV');
|
|
240
|
+
expect(formGroup.classList).toContain('govuk-form-group');
|
|
241
|
+
label = formGroup.childNodes[0];
|
|
242
|
+
expect(label.tagName).toEqual('LABEL');
|
|
243
|
+
expect(label.classList).toContain('govuk-label');
|
|
244
|
+
expect(label.textContent).toEqual('Interpolated Text component (optional)');
|
|
245
|
+
expect(label.getAttribute('for')).toEqual(ID);
|
|
246
|
+
hint = formGroup.childNodes[1];
|
|
247
|
+
expect(hint.tagName).toEqual('SPAN');
|
|
248
|
+
expect(hint.classList).toContain('govuk-hint');
|
|
249
|
+
expect(hint.textContent).toEqual(COMPONENT.hint);
|
|
250
|
+
input = formGroup.childNodes[2];
|
|
251
|
+
expect(input.tagName).toEqual('INPUT');
|
|
252
|
+
expect(input.classList).toContain('govuk-input');
|
|
253
|
+
expect(input.id).toEqual(ID);
|
|
254
|
+
expect(input.value).toEqual(VALUE);
|
|
255
|
+
|
|
256
|
+
case 23:
|
|
257
|
+
case "end":
|
|
258
|
+
return _context6.stop();
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}, _callee6);
|
|
262
|
+
})));
|
|
206
263
|
});
|
|
207
264
|
});
|
package/dist/hooks/useRefData.js
CHANGED
|
@@ -7,6 +7,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.default = exports.STATUS_LOADING = exports.STATUS_COMPLETE = void 0;
|
|
9
9
|
|
|
10
|
+
var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
11
|
+
|
|
10
12
|
var _react = require("react");
|
|
11
13
|
|
|
12
14
|
var _Data = _interopRequireDefault(require("../utils/Data"));
|
|
@@ -40,7 +42,7 @@ var getRefDataUrl = function getRefDataUrl(component) {
|
|
|
40
42
|
var data = component.data;
|
|
41
43
|
|
|
42
44
|
if (data && !data.options) {
|
|
43
|
-
return data.url;
|
|
45
|
+
return _copReactComponents.Utils.interpolateString(data.url, component.formData);
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
return undefined;
|
|
@@ -66,13 +68,13 @@ var useRefData = function useRefData(component) {
|
|
|
66
68
|
(0, _react.useEffect)(function () {
|
|
67
69
|
if (!url) {
|
|
68
70
|
if (component.data && component.data.options) {
|
|
69
|
-
setData(_Data.default.refData.toOptions(component.data.options));
|
|
71
|
+
setData(_Data.default.refData.toOptions(component.data.options, component.item));
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
setStatus(STATUS_COMPLETE);
|
|
73
75
|
} else if (_status === _useGetRequest2.STATUS_FETCHED) {
|
|
74
76
|
if (_data) {
|
|
75
|
-
setData(_Data.default.refData.toOptions(_data.data));
|
|
77
|
+
setData(_Data.default.refData.toOptions(_data.data, component.item));
|
|
76
78
|
}
|
|
77
79
|
|
|
78
80
|
setStatus(STATUS_COMPLETE);
|
|
@@ -5,12 +5,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
+
var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
9
|
+
|
|
8
10
|
var _Component = _interopRequireDefault(require("../Component"));
|
|
9
11
|
|
|
10
12
|
var _getCYAAction = _interopRequireDefault(require("./getCYAAction"));
|
|
11
13
|
|
|
12
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
15
|
|
|
16
|
+
// Global imports
|
|
14
17
|
// Local imports
|
|
15
18
|
|
|
16
19
|
/**
|
|
@@ -35,7 +38,7 @@ var getCYARow = function getCYARow(page, component, onAction) {
|
|
|
35
38
|
id: component.id,
|
|
36
39
|
fieldId: component.fieldId,
|
|
37
40
|
full_path: component.full_path,
|
|
38
|
-
key: component.label || component.cya_label,
|
|
41
|
+
key: _copReactComponents.Utils.interpolateString(component.label || component.cya_label, page.formData),
|
|
39
42
|
required: component.required,
|
|
40
43
|
component: _Component.default.editable(component) ? component : undefined,
|
|
41
44
|
value: value || '',
|
|
@@ -195,6 +195,62 @@ describe('utils', function () {
|
|
|
195
195
|
var ROW = (0, _getCYARow.default)(PAGE, COMPONENT, function () {});
|
|
196
196
|
expect(ROW.component.data.options[0].nested[0].value).toBeUndefined();
|
|
197
197
|
});
|
|
198
|
+
it('should get an appropriate row for a readonly text component with no value and interpolated label', function () {
|
|
199
|
+
var PAGE = {
|
|
200
|
+
id: 'page',
|
|
201
|
+
formData: {
|
|
202
|
+
text: 'Smith'
|
|
203
|
+
}
|
|
204
|
+
}; // eslint-disable-next-line no-template-curly-in-string
|
|
205
|
+
|
|
206
|
+
var COMPONENT = {
|
|
207
|
+
type: 'text',
|
|
208
|
+
readonly: true,
|
|
209
|
+
id: 'a',
|
|
210
|
+
fieldId: 'a',
|
|
211
|
+
label: 'Alpha ${text}'
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
var ON_ACTION = function ON_ACTION() {};
|
|
215
|
+
|
|
216
|
+
expect((0, _getCYARow.default)(PAGE, COMPONENT, ON_ACTION)).toEqual({
|
|
217
|
+
pageId: PAGE.id,
|
|
218
|
+
id: COMPONENT.id,
|
|
219
|
+
fieldId: COMPONENT.fieldId,
|
|
220
|
+
key: 'Alpha Smith',
|
|
221
|
+
value: '',
|
|
222
|
+
component: COMPONENT,
|
|
223
|
+
action: null
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
it('should use the interolated cya_label where there is no label', function () {
|
|
227
|
+
var PAGE = {
|
|
228
|
+
id: 'page',
|
|
229
|
+
formData: {
|
|
230
|
+
a: 'Bravo'
|
|
231
|
+
}
|
|
232
|
+
}; // eslint-disable-next-line no-template-curly-in-string
|
|
233
|
+
|
|
234
|
+
var COMPONENT = {
|
|
235
|
+
type: 'text',
|
|
236
|
+
readonly: true,
|
|
237
|
+
id: 'a',
|
|
238
|
+
fieldId: 'a',
|
|
239
|
+
cya_label: 'CYA Alpha ${a}'
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
var ON_ACTION = function ON_ACTION() {};
|
|
243
|
+
|
|
244
|
+
var ROW = (0, _getCYARow.default)(PAGE, COMPONENT, ON_ACTION);
|
|
245
|
+
(0, _setupTests.expectObjectLike)(ROW, {
|
|
246
|
+
pageId: PAGE.id,
|
|
247
|
+
fieldId: COMPONENT.fieldId,
|
|
248
|
+
key: 'CYA Alpha Bravo',
|
|
249
|
+
action: null,
|
|
250
|
+
component: COMPONENT,
|
|
251
|
+
value: 'Bravo'
|
|
252
|
+
});
|
|
253
|
+
});
|
|
198
254
|
});
|
|
199
255
|
});
|
|
200
256
|
});
|
|
@@ -11,22 +11,38 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
11
11
|
|
|
12
12
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
13
13
|
|
|
14
|
+
var getValueAndLabel = function getValueAndLabel(opt, itemStructure) {
|
|
15
|
+
var _value;
|
|
16
|
+
|
|
17
|
+
var value = opt.value || opt.id;
|
|
18
|
+
var label = opt.label || opt.name;
|
|
19
|
+
|
|
20
|
+
if (itemStructure) {
|
|
21
|
+
value = opt[itemStructure.value] || value;
|
|
22
|
+
label = opt[itemStructure.label] || label;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
value: (_value = value) === null || _value === void 0 ? void 0 : _value.toString(),
|
|
27
|
+
label: label
|
|
28
|
+
};
|
|
29
|
+
};
|
|
14
30
|
/**
|
|
15
31
|
* Converts ref data items to options.
|
|
16
32
|
* @param {Array} refDataItems An array of ref data items.
|
|
33
|
+
* @param {Object} itemStructure The structure of the item.
|
|
17
34
|
* @returns An array of options.
|
|
18
35
|
*/
|
|
19
|
-
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
var refDataToOptions = function refDataToOptions(refDataItems, itemStructure) {
|
|
20
39
|
if (Array.isArray(refDataItems)) {
|
|
21
40
|
return refDataItems.map(function (opt) {
|
|
22
41
|
if (typeof opt === 'string') {
|
|
23
42
|
return opt;
|
|
24
43
|
}
|
|
25
44
|
|
|
26
|
-
return _objectSpread(_objectSpread({}, opt),
|
|
27
|
-
value: opt.id || opt.value,
|
|
28
|
-
label: opt.name || opt.label
|
|
29
|
-
});
|
|
45
|
+
return _objectSpread(_objectSpread({}, opt), getValueAndLabel(opt, itemStructure));
|
|
30
46
|
});
|
|
31
47
|
}
|
|
32
48
|
|
|
@@ -124,6 +124,74 @@ describe('utils', function () {
|
|
|
124
124
|
type: 'Delta'
|
|
125
125
|
}]);
|
|
126
126
|
});
|
|
127
|
+
it('can handle refData with custom value and label properties', function () {
|
|
128
|
+
var REF_DATA = [{
|
|
129
|
+
id: 1,
|
|
130
|
+
displayName: 'Alpha'
|
|
131
|
+
}, {
|
|
132
|
+
id: 2,
|
|
133
|
+
displayName: 'Bravo'
|
|
134
|
+
}, {
|
|
135
|
+
id: 3,
|
|
136
|
+
displayName: 'Charlie'
|
|
137
|
+
}];
|
|
138
|
+
var ITEM_STRUCTURE = {
|
|
139
|
+
value: 'id',
|
|
140
|
+
label: 'displayName'
|
|
141
|
+
};
|
|
142
|
+
expect((0, _refDataToOptions.default)(REF_DATA, ITEM_STRUCTURE)).toEqual([{
|
|
143
|
+
id: 1,
|
|
144
|
+
displayName: 'Alpha',
|
|
145
|
+
value: '1',
|
|
146
|
+
label: 'Alpha'
|
|
147
|
+
}, {
|
|
148
|
+
id: 2,
|
|
149
|
+
displayName: 'Bravo',
|
|
150
|
+
value: '2',
|
|
151
|
+
label: 'Bravo'
|
|
152
|
+
}, {
|
|
153
|
+
id: 3,
|
|
154
|
+
displayName: 'Charlie',
|
|
155
|
+
value: '3',
|
|
156
|
+
label: 'Charlie'
|
|
157
|
+
}]);
|
|
158
|
+
});
|
|
159
|
+
it('can handle refData with missing custom value and label properties', function () {
|
|
160
|
+
var REF_DATA = [{
|
|
161
|
+
id: 1,
|
|
162
|
+
name: 'Alpha'
|
|
163
|
+
}, {
|
|
164
|
+
id: 2,
|
|
165
|
+
name: 'Bravo',
|
|
166
|
+
displayName: 'Bravo Zulu'
|
|
167
|
+
}, {
|
|
168
|
+
id: 3,
|
|
169
|
+
objId: 'chaz',
|
|
170
|
+
name: 'Charlie'
|
|
171
|
+
}];
|
|
172
|
+
var ITEM_STRUCTURE = {
|
|
173
|
+
value: 'objId',
|
|
174
|
+
label: 'displayName'
|
|
175
|
+
};
|
|
176
|
+
expect((0, _refDataToOptions.default)(REF_DATA, ITEM_STRUCTURE)).toEqual([{
|
|
177
|
+
id: 1,
|
|
178
|
+
name: 'Alpha',
|
|
179
|
+
value: '1',
|
|
180
|
+
label: 'Alpha'
|
|
181
|
+
}, {
|
|
182
|
+
id: 2,
|
|
183
|
+
name: 'Bravo',
|
|
184
|
+
displayName: 'Bravo Zulu',
|
|
185
|
+
value: '2',
|
|
186
|
+
label: 'Bravo Zulu'
|
|
187
|
+
}, {
|
|
188
|
+
id: 3,
|
|
189
|
+
objId: 'chaz',
|
|
190
|
+
name: 'Charlie',
|
|
191
|
+
value: 'chaz',
|
|
192
|
+
label: 'Charlie'
|
|
193
|
+
}]);
|
|
194
|
+
});
|
|
127
195
|
});
|
|
128
196
|
});
|
|
129
197
|
});
|
|
@@ -7,19 +7,49 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
9
9
|
|
|
10
|
+
var _models = require("../../models");
|
|
11
|
+
|
|
10
12
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
11
13
|
|
|
12
14
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
13
15
|
|
|
14
16
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
15
17
|
|
|
18
|
+
var setupRefDataForContainer = function setupRefDataForContainer(container, data) {
|
|
19
|
+
return _objectSpread(_objectSpread({}, container), {}, {
|
|
20
|
+
components: setupRefDataUrlForComponents(container.components, data)
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
var setupRefDataForCollection = function setupRefDataForCollection(collection, data) {
|
|
25
|
+
return _objectSpread(_objectSpread({}, collection), {}, {
|
|
26
|
+
item: setupRefDataUrlForComponents(collection.item, data)
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
var setupRefDataUrlForComponents = function setupRefDataUrlForComponents(components, data) {
|
|
31
|
+
return components.map(function (component) {
|
|
32
|
+
return setupRefDataUrlForComponent(component, data);
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
|
|
16
36
|
var setupRefDataUrlForComponent = function setupRefDataUrlForComponent(component, data) {
|
|
17
|
-
if (component
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
37
|
+
if (component) {
|
|
38
|
+
if (component.type === _models.ComponentTypes.CONTAINER) {
|
|
39
|
+
return setupRefDataForContainer(component, data);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (component.type === _models.ComponentTypes.COLLECTION) {
|
|
43
|
+
return setupRefDataForCollection(component, data);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (component.data && component.data.url) {
|
|
47
|
+
return _objectSpread(_objectSpread({}, component), {}, {
|
|
48
|
+
data: _objectSpread(_objectSpread({}, component.data), {}, {
|
|
49
|
+
url: _copReactComponents.Utils.interpolateString(component.data.url, data)
|
|
50
|
+
})
|
|
51
|
+
});
|
|
52
|
+
}
|
|
23
53
|
}
|
|
24
54
|
|
|
25
55
|
return component;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _models = require("../../models");
|
|
4
|
+
|
|
3
5
|
var _setupRefDataUrlForComponent = _interopRequireDefault(require("./setupRefDataUrlForComponent"));
|
|
4
6
|
|
|
5
7
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -34,7 +36,7 @@ describe('utils', function () {
|
|
|
34
36
|
};
|
|
35
37
|
expect((0, _setupRefDataUrlForComponent.default)(COMPONENT, DATA)).toEqual(COMPONENT);
|
|
36
38
|
});
|
|
37
|
-
it('should appropriately
|
|
39
|
+
it('should appropriately update the component URL', function () {
|
|
38
40
|
var COMPONENT = {
|
|
39
41
|
id: 'component',
|
|
40
42
|
// eslint-disable-next-line no-template-curly-in-string
|
|
@@ -78,6 +80,54 @@ describe('utils', function () {
|
|
|
78
80
|
}
|
|
79
81
|
});
|
|
80
82
|
});
|
|
83
|
+
it('should appropriately update the component URLs within a container', function () {
|
|
84
|
+
var COMPONENT = {
|
|
85
|
+
id: 'component',
|
|
86
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
87
|
+
data: {
|
|
88
|
+
url: '${urls.refData}/v1/teams'
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
var CONTAINER = {
|
|
92
|
+
id: 'container',
|
|
93
|
+
type: _models.ComponentTypes.CONTAINER,
|
|
94
|
+
components: [COMPONENT]
|
|
95
|
+
};
|
|
96
|
+
expect((0, _setupRefDataUrlForComponent.default)(CONTAINER, DATA)).toEqual({
|
|
97
|
+
id: CONTAINER.id,
|
|
98
|
+
type: CONTAINER.type,
|
|
99
|
+
components: [{
|
|
100
|
+
id: COMPONENT.id,
|
|
101
|
+
data: {
|
|
102
|
+
url: "".concat(DATA.urls.refData, "/v1/teams")
|
|
103
|
+
}
|
|
104
|
+
}]
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
it('should appropriately update the component URLs within a collection', function () {
|
|
108
|
+
var COMPONENT = {
|
|
109
|
+
id: 'component',
|
|
110
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
111
|
+
data: {
|
|
112
|
+
url: '${urls.refData}/v1/teams'
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
var COLLECTION = {
|
|
116
|
+
id: 'container',
|
|
117
|
+
type: _models.ComponentTypes.COLLECTION,
|
|
118
|
+
item: [COMPONENT]
|
|
119
|
+
};
|
|
120
|
+
expect((0, _setupRefDataUrlForComponent.default)(COLLECTION, DATA)).toEqual({
|
|
121
|
+
id: COLLECTION.id,
|
|
122
|
+
type: COLLECTION.type,
|
|
123
|
+
item: [{
|
|
124
|
+
id: COMPONENT.id,
|
|
125
|
+
data: {
|
|
126
|
+
url: "".concat(DATA.urls.refData, "/v1/teams")
|
|
127
|
+
}
|
|
128
|
+
}]
|
|
129
|
+
});
|
|
130
|
+
});
|
|
81
131
|
});
|
|
82
132
|
});
|
|
83
133
|
});
|
|
@@ -48,7 +48,7 @@ var getFormPage = function getFormPage(pageOptions, formComponents, formData) {
|
|
|
48
48
|
ret = _objectSpread({}, componentOptions);
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
return formData
|
|
51
|
+
return formData ? _Data.default.refData.setupUrl(ret, formData) : ret;
|
|
52
52
|
});
|
|
53
53
|
var actions = (0, _getPageActions.default)(pageOptions);
|
|
54
54
|
return _Container.default.setup(_objectSpread(_objectSpread({}, pageOptions), {}, {
|
|
@@ -26,7 +26,7 @@ var useComponent = function useComponent(toUse, formComponents) {
|
|
|
26
26
|
if (formComponent) {
|
|
27
27
|
var fieldId = toUse.fieldId || formComponent.fieldId;
|
|
28
28
|
return _objectSpread(_objectSpread(_objectSpread({}, formComponent), toUse), {}, {
|
|
29
|
-
cya_label: formComponent.label,
|
|
29
|
+
cya_label: formComponent.label || formComponent.cya_label,
|
|
30
30
|
fieldId: fieldId
|
|
31
31
|
});
|
|
32
32
|
}
|
|
@@ -28,6 +28,11 @@ describe('utils', function () {
|
|
|
28
28
|
fieldId: 'c',
|
|
29
29
|
label: 'Charlie',
|
|
30
30
|
type: 'text'
|
|
31
|
+
}, {
|
|
32
|
+
id: 'd',
|
|
33
|
+
fieldId: 'd',
|
|
34
|
+
cya_label: 'Delta',
|
|
35
|
+
type: 'text'
|
|
31
36
|
}];
|
|
32
37
|
it('should handle a null toUse configuration', function () {
|
|
33
38
|
var TO_USE = null;
|
|
@@ -35,8 +40,8 @@ describe('utils', function () {
|
|
|
35
40
|
});
|
|
36
41
|
it('should handle an unrecognised component reference', function () {
|
|
37
42
|
var TO_USE = {
|
|
38
|
-
use: '
|
|
39
|
-
label: '
|
|
43
|
+
use: 'e',
|
|
44
|
+
label: 'Echo'
|
|
40
45
|
};
|
|
41
46
|
expect((0, _useComponent.default)(TO_USE, FORM_COMPONENTS)).toEqual(TO_USE);
|
|
42
47
|
});
|
|
@@ -77,6 +82,31 @@ describe('utils', function () {
|
|
|
77
82
|
label: TO_USE.label
|
|
78
83
|
}));
|
|
79
84
|
});
|
|
85
|
+
it('should allow the form component cya_label, if label is empty', function () {
|
|
86
|
+
var TO_USE = {
|
|
87
|
+
use: 'd',
|
|
88
|
+
label: ''
|
|
89
|
+
};
|
|
90
|
+
var A = FORM_COMPONENTS[3];
|
|
91
|
+
expect((0, _useComponent.default)(TO_USE, FORM_COMPONENTS)).toEqual(_objectSpread(_objectSpread({
|
|
92
|
+
use: 'd'
|
|
93
|
+
}, A), {}, {
|
|
94
|
+
cya_label: A.cya_label,
|
|
95
|
+
label: TO_USE.label
|
|
96
|
+
}));
|
|
97
|
+
});
|
|
98
|
+
it('should allow the form component cya_label, if label is not given', function () {
|
|
99
|
+
var TO_USE = {
|
|
100
|
+
use: 'd'
|
|
101
|
+
};
|
|
102
|
+
var A = FORM_COMPONENTS[3];
|
|
103
|
+
expect((0, _useComponent.default)(TO_USE, FORM_COMPONENTS)).toEqual(_objectSpread(_objectSpread({
|
|
104
|
+
use: 'd'
|
|
105
|
+
}, A), {}, {
|
|
106
|
+
cya_label: A.cya_label,
|
|
107
|
+
label: TO_USE.label
|
|
108
|
+
}));
|
|
109
|
+
});
|
|
80
110
|
});
|
|
81
111
|
});
|
|
82
112
|
});
|