@ukhomeoffice/cop-react-form-renderer 2.6.1 → 2.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/CheckYourAnswers/Answer.js +3 -1
- package/dist/components/CheckYourAnswers/Answer.test.js +3 -2
- package/dist/components/CheckYourAnswers/CheckYourAnswers.js +45 -5
- package/dist/components/CheckYourAnswers/CheckYourAnswers.scss +10 -0
- package/dist/components/CheckYourAnswers/CheckYourAnswers.stories.mdx +331 -269
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +74 -12
- package/dist/components/FormComponent/Container.test.js +89 -10
- package/dist/components/FormComponent/FormComponent.js +63 -14
- package/dist/components/FormRenderer/FormRenderer.test.js +1 -1
- package/dist/components/FormRenderer/helpers/canActionProceed.js +1 -1
- package/dist/components/FormRenderer/helpers/canCYASubmit.js +1 -1
- package/dist/components/SummaryList/GroupAction.js +68 -0
- package/dist/components/SummaryList/GroupAction.test.js +94 -0
- package/dist/components/SummaryList/SummaryList.js +15 -4
- package/dist/components/SummaryList/SummaryList.scss +29 -5
- package/dist/components/SummaryList/SummaryList.test.js +47 -4
- package/dist/components/SummaryList/helpers/getGroupActionAttributes.js +27 -0
- package/dist/components/SummaryList/helpers/getGroupActionAttributes.test.js +77 -0
- package/dist/json/groupOfRow.json +158 -0
- package/dist/json/groupOfRowData.json +15 -0
- package/dist/models/ComponentTypes.js +2 -0
- package/dist/utils/Component/getComponent.js +13 -5
- package/dist/utils/Component/getComponentTests/getComponent.file.test.js +81 -0
- package/dist/utils/Component/isEditable.js +1 -1
- package/dist/utils/Data/index.js +3 -0
- package/dist/utils/Data/setDataItem.js +29 -0
- package/dist/utils/Data/setDataItem.test.js +112 -0
- package/dist/utils/Validate/validatePage.js +7 -6
- package/dist/utils/Validate/validatePage.test.js +60 -12
- package/package.json +2 -2
|
@@ -11,11 +11,13 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
11
11
|
|
|
12
12
|
var _react = _interopRequireDefault(require("react"));
|
|
13
13
|
|
|
14
|
+
var _GroupAction = _interopRequireDefault(require("./GroupAction"));
|
|
15
|
+
|
|
14
16
|
var _RowAction = _interopRequireDefault(require("./RowAction"));
|
|
15
17
|
|
|
16
18
|
require("./SummaryList.scss");
|
|
17
19
|
|
|
18
|
-
var _excluded = ["rows", "noChangeAction", "classBlock", "classModifiers", "className"];
|
|
20
|
+
var _excluded = ["rows", "noChangeAction", "isGroup", "classBlock", "classModifiers", "className"];
|
|
19
21
|
|
|
20
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
23
|
|
|
@@ -31,6 +33,7 @@ exports.DEFAULT_CLASS = DEFAULT_CLASS;
|
|
|
31
33
|
var SummaryList = function SummaryList(_ref) {
|
|
32
34
|
var rows = _ref.rows,
|
|
33
35
|
noChangeAction = _ref.noChangeAction,
|
|
36
|
+
isGroup = _ref.isGroup,
|
|
34
37
|
classBlock = _ref.classBlock,
|
|
35
38
|
classModifiers = _ref.classModifiers,
|
|
36
39
|
className = _ref.className,
|
|
@@ -38,22 +41,30 @@ var SummaryList = function SummaryList(_ref) {
|
|
|
38
41
|
|
|
39
42
|
var classes = _copReactComponents.Utils.classBuilder(classBlock, classModifiers, className);
|
|
40
43
|
|
|
41
|
-
return /*#__PURE__*/_react.default.createElement("
|
|
44
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
45
|
+
className: "group-of-rows"
|
|
46
|
+
}, /*#__PURE__*/_react.default.createElement("dl", _extends({}, attrs, {
|
|
42
47
|
className: classes()
|
|
43
48
|
}), rows.map(function (row) {
|
|
49
|
+
var _row$component;
|
|
50
|
+
|
|
44
51
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
45
52
|
key: "".concat(row.pageId, "_").concat(row.fieldId),
|
|
46
53
|
className: classes('row')
|
|
47
54
|
}, /*#__PURE__*/_react.default.createElement("dt", {
|
|
48
55
|
className: classes('key')
|
|
49
|
-
}, row.key), /*#__PURE__*/_react.default.createElement("dd", {
|
|
56
|
+
}, row.key, !((_row$component = row.component) !== null && _row$component !== void 0 && _row$component.required) && " (optional)"), /*#__PURE__*/_react.default.createElement("dd", {
|
|
50
57
|
className: classes('value')
|
|
51
58
|
}, row.value), !noChangeAction && /*#__PURE__*/_react.default.createElement("dd", {
|
|
52
59
|
className: classes('actions')
|
|
53
60
|
}, row.action && /*#__PURE__*/_react.default.createElement(_RowAction.default, {
|
|
54
61
|
row: row
|
|
55
62
|
})));
|
|
56
|
-
})
|
|
63
|
+
}), isGroup && /*#__PURE__*/_react.default.createElement("div", {
|
|
64
|
+
className: "change-group-button"
|
|
65
|
+
}, /*#__PURE__*/_react.default.createElement(_GroupAction.default, {
|
|
66
|
+
group: rows[0]
|
|
67
|
+
}))));
|
|
57
68
|
};
|
|
58
69
|
|
|
59
70
|
SummaryList.propTypes = {
|
|
@@ -1,17 +1,41 @@
|
|
|
1
1
|
@import 'node_modules/govuk-frontend/govuk/_base';
|
|
2
2
|
@import 'node_modules/govuk-frontend/govuk/components/summary-list/_summary-list';
|
|
3
3
|
|
|
4
|
-
.govuk-summary-list__actions {
|
|
4
|
+
// .govuk-summary-list__actions {
|
|
5
|
+
// .govuk-link {
|
|
6
|
+
// float: right;
|
|
7
|
+
// color: govuk-colour('blue');
|
|
8
|
+
// cursor: pointer;
|
|
9
|
+
// }
|
|
10
|
+
// }
|
|
11
|
+
|
|
12
|
+
.changeRow {
|
|
5
13
|
.govuk-link {
|
|
14
|
+
float: right;
|
|
6
15
|
color: govuk-colour('blue');
|
|
7
16
|
cursor: pointer;
|
|
8
17
|
}
|
|
9
18
|
}
|
|
10
19
|
|
|
11
|
-
.
|
|
12
|
-
|
|
20
|
+
.group-of-rows {
|
|
21
|
+
position:relative;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.mobile-text{
|
|
25
|
+
text-transform: lowercase;
|
|
13
26
|
}
|
|
14
27
|
|
|
15
|
-
|
|
16
|
-
|
|
28
|
+
@media screen and (min-width: 640px) {
|
|
29
|
+
.change-group-button {
|
|
30
|
+
position: absolute;
|
|
31
|
+
top: -47px;
|
|
32
|
+
right: 0;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.mobile-text{
|
|
36
|
+
display:none;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
17
40
|
}
|
|
41
|
+
|
|
@@ -113,7 +113,7 @@ describe('components', function () {
|
|
|
113
113
|
value = _checkRow2[1],
|
|
114
114
|
actions = _checkRow2[2];
|
|
115
115
|
|
|
116
|
-
expect(key.textContent).toEqual(row.key);
|
|
116
|
+
expect(key.textContent).toEqual("".concat(row.key, " (optional)"));
|
|
117
117
|
expect(value.textContent).toEqual(row.value);
|
|
118
118
|
expect(actions.childNodes.length).toEqual(0);
|
|
119
119
|
});
|
|
@@ -148,7 +148,7 @@ describe('components', function () {
|
|
|
148
148
|
value = _checkRow4[1],
|
|
149
149
|
actions = _checkRow4[2];
|
|
150
150
|
|
|
151
|
-
expect(key.textContent).toEqual(row.key);
|
|
151
|
+
expect(key.textContent).toEqual("".concat(row.key, " (optional)"));
|
|
152
152
|
expect(value.childNodes.length).toEqual(1);
|
|
153
153
|
var valueDiv = value.childNodes[0];
|
|
154
154
|
expect(valueDiv.tagName).toEqual('DIV');
|
|
@@ -199,7 +199,7 @@ describe('components', function () {
|
|
|
199
199
|
value = _checkRow6[1],
|
|
200
200
|
actions = _checkRow6[2];
|
|
201
201
|
|
|
202
|
-
expect(key.textContent).toEqual(row.key);
|
|
202
|
+
expect(key.textContent).toEqual("".concat(row.key, " (optional)"));
|
|
203
203
|
expect(value.textContent).toEqual(row.value);
|
|
204
204
|
var a = actions.childNodes[0];
|
|
205
205
|
expect(a.textContent).toEqual(row.action.label);
|
|
@@ -240,7 +240,50 @@ describe('components', function () {
|
|
|
240
240
|
key = _checkRowNoChangeActi2[0],
|
|
241
241
|
value = _checkRowNoChangeActi2[1];
|
|
242
242
|
|
|
243
|
-
expect(key.textContent).toEqual(row.key);
|
|
243
|
+
expect(key.textContent).toEqual("".concat(row.key, " (optional)"));
|
|
244
|
+
expect(value.childNodes.length).toEqual(1);
|
|
245
|
+
var valueDiv = value.childNodes[0];
|
|
246
|
+
expect(valueDiv.tagName).toEqual('DIV');
|
|
247
|
+
expect(valueDiv.textContent).toEqual(VALUES[index]);
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
it('should render groups of rows corretly', function () {
|
|
251
|
+
var ID = 'test-id';
|
|
252
|
+
var VALUES = ['Alpha component value', 'Bravo component value', 'Charlie component value'];
|
|
253
|
+
var ISGROUP = true;
|
|
254
|
+
var ROWS = [{
|
|
255
|
+
pageId: 'p1',
|
|
256
|
+
fieldId: 'a',
|
|
257
|
+
key: 'Alpha',
|
|
258
|
+
value: /*#__PURE__*/_react2.default.createElement("div", null, VALUES[0])
|
|
259
|
+
}, {
|
|
260
|
+
pageId: 'p1',
|
|
261
|
+
fieldId: 'b',
|
|
262
|
+
key: 'Bravo',
|
|
263
|
+
value: /*#__PURE__*/_react2.default.createElement("div", null, VALUES[1])
|
|
264
|
+
}, {
|
|
265
|
+
pageId: 'p1',
|
|
266
|
+
fieldId: 'c',
|
|
267
|
+
key: 'Charlie',
|
|
268
|
+
value: /*#__PURE__*/_react2.default.createElement("div", null, VALUES[2])
|
|
269
|
+
}];
|
|
270
|
+
|
|
271
|
+
var _render6 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_SummaryList.default, {
|
|
272
|
+
"data-testid": ID,
|
|
273
|
+
rows: ROWS,
|
|
274
|
+
isGroup: ISGROUP
|
|
275
|
+
})),
|
|
276
|
+
container = _render6.container;
|
|
277
|
+
|
|
278
|
+
var summaryList = checkSummaryList(container, ID);
|
|
279
|
+
expect(summaryList.childNodes.length).toEqual(ROWS.length + 1);
|
|
280
|
+
ROWS.forEach(function (row, index) {
|
|
281
|
+
var _checkRow7 = checkRow(summaryList, index),
|
|
282
|
+
_checkRow8 = _slicedToArray(_checkRow7, 2),
|
|
283
|
+
key = _checkRow8[0],
|
|
284
|
+
value = _checkRow8[1];
|
|
285
|
+
|
|
286
|
+
expect(key.textContent).toEqual("".concat(row.key, " (optional)"));
|
|
244
287
|
expect(value.childNodes.length).toEqual(1);
|
|
245
288
|
var valueDiv = value.childNodes[0];
|
|
246
289
|
expect(valueDiv.tagName).toEqual('DIV');
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var getGroupActionAttributes = function getGroupActionAttributes(groupRow) {
|
|
9
|
+
if (groupRow && Object.prototype.hasOwnProperty.call(groupRow, 'action')) {
|
|
10
|
+
if (typeof groupRow.action.onAction === 'function') {
|
|
11
|
+
return {
|
|
12
|
+
onClick: function onClick() {
|
|
13
|
+
return groupRow.action.onAction(groupRow);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
} else if (groupRow.action.page) {
|
|
17
|
+
return {
|
|
18
|
+
href: "/".concat(groupRow.action.page)
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return {};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
var _default = getGroupActionAttributes;
|
|
27
|
+
exports.default = _default;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _getGroupActionAttributes = _interopRequireDefault(require("./getGroupActionAttributes"));
|
|
4
|
+
|
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
+
|
|
7
|
+
describe('components', function () {
|
|
8
|
+
describe('SummaryList', function () {
|
|
9
|
+
describe('helpers', function () {
|
|
10
|
+
describe('getGroupActionAttributes', function () {
|
|
11
|
+
it('should handle a null row', function () {
|
|
12
|
+
expect((0, _getGroupActionAttributes.default)(null)).toEqual({});
|
|
13
|
+
});
|
|
14
|
+
it('should handle a row without an action', function () {
|
|
15
|
+
expect((0, _getGroupActionAttributes.default)({})).toEqual({});
|
|
16
|
+
});
|
|
17
|
+
it('should handle a row with an empty action', function () {
|
|
18
|
+
var ROW = {
|
|
19
|
+
action: {}
|
|
20
|
+
};
|
|
21
|
+
expect((0, _getGroupActionAttributes.default)(ROW)).toEqual({});
|
|
22
|
+
});
|
|
23
|
+
it('should handle a row with a page', function () {
|
|
24
|
+
var PAGE = 'alpha';
|
|
25
|
+
var ROW = {
|
|
26
|
+
action: {
|
|
27
|
+
page: PAGE
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
expect((0, _getGroupActionAttributes.default)(ROW)).toEqual({
|
|
31
|
+
href: "/".concat(PAGE)
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
it('should handle a row with an onAction function', function () {
|
|
35
|
+
var ON_ACTION_CALLS = [];
|
|
36
|
+
|
|
37
|
+
var ON_ACTION = function ON_ACTION(row) {
|
|
38
|
+
ON_ACTION_CALLS.push(row);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
var ROW = {
|
|
42
|
+
action: {
|
|
43
|
+
onAction: ON_ACTION
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
var ATTRS = (0, _getGroupActionAttributes.default)(ROW);
|
|
47
|
+
expect(ATTRS.onClick).toBeDefined();
|
|
48
|
+
expect(ATTRS.href).not.toBeDefined();
|
|
49
|
+
ATTRS.onClick();
|
|
50
|
+
expect(ON_ACTION_CALLS.length).toEqual(1);
|
|
51
|
+
expect(ON_ACTION_CALLS[0]).toEqual(ROW);
|
|
52
|
+
});
|
|
53
|
+
it('should favour onAction over href', function () {
|
|
54
|
+
var ON_ACTION_CALLS = [];
|
|
55
|
+
|
|
56
|
+
var ON_ACTION = function ON_ACTION(row) {
|
|
57
|
+
ON_ACTION_CALLS.push(row);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
var HREF = 'http://alpha.homeoffice.gov.uk';
|
|
61
|
+
var ROW = {
|
|
62
|
+
action: {
|
|
63
|
+
href: HREF,
|
|
64
|
+
onAction: ON_ACTION
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
var ATTRS = (0, _getGroupActionAttributes.default)(ROW);
|
|
68
|
+
expect(ATTRS.onClick).toBeDefined();
|
|
69
|
+
expect(ATTRS.href).not.toBeDefined();
|
|
70
|
+
ATTRS.onClick();
|
|
71
|
+
expect(ON_ACTION_CALLS.length).toEqual(1);
|
|
72
|
+
expect(ON_ACTION_CALLS[0]).toEqual(ROW);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
});
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "userProfile",
|
|
3
|
+
"version": "1",
|
|
4
|
+
"name": "userProfile",
|
|
5
|
+
"title": "Your profile",
|
|
6
|
+
"type": "cya",
|
|
7
|
+
"components": [
|
|
8
|
+
{
|
|
9
|
+
"id": "firstName",
|
|
10
|
+
"fieldId": "firstName",
|
|
11
|
+
"label": "First name",
|
|
12
|
+
"type": "text",
|
|
13
|
+
"readonly": false,
|
|
14
|
+
"source": {
|
|
15
|
+
"field": "currentUser.givenName"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"id": "surname",
|
|
20
|
+
"fieldId": "surname",
|
|
21
|
+
"label": "Last name",
|
|
22
|
+
"type": "text",
|
|
23
|
+
"readonly": false,
|
|
24
|
+
"source": {
|
|
25
|
+
"field": "currentUser.familyName"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"id": "dateGroup",
|
|
30
|
+
"fieldId": "dateGroup",
|
|
31
|
+
"label": "Date",
|
|
32
|
+
"type": "date",
|
|
33
|
+
"required": true,
|
|
34
|
+
"readonly": false,
|
|
35
|
+
"source": {
|
|
36
|
+
"field": "dateGroupField"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"id": "timeGroup",
|
|
41
|
+
"fieldId": "timeGroup",
|
|
42
|
+
"label": "Time",
|
|
43
|
+
"type": "time",
|
|
44
|
+
"required": true,
|
|
45
|
+
"readonly": false,
|
|
46
|
+
"source": {
|
|
47
|
+
"field": "timeGroupField"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"id": "portGroup",
|
|
52
|
+
"fieldId": "portGroup",
|
|
53
|
+
"label": "Port",
|
|
54
|
+
"type": "text",
|
|
55
|
+
"required": true,
|
|
56
|
+
"readonly": false,
|
|
57
|
+
"source": {
|
|
58
|
+
"field": "portGroupField"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"id": "whereGroup",
|
|
63
|
+
"fieldId": "whereGroup",
|
|
64
|
+
"label": "Where did you see the incident take place",
|
|
65
|
+
"type": "text",
|
|
66
|
+
"required": true,
|
|
67
|
+
"readonly": false,
|
|
68
|
+
"source": {
|
|
69
|
+
"field": "whereGroupField"
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"id": "extraDetails",
|
|
74
|
+
"fieldId": "extraDetails",
|
|
75
|
+
"label": "Extra details",
|
|
76
|
+
"type": "textarea",
|
|
77
|
+
"readonly": false
|
|
78
|
+
}
|
|
79
|
+
],
|
|
80
|
+
"pages": [
|
|
81
|
+
{
|
|
82
|
+
"id": "names",
|
|
83
|
+
"name": "names",
|
|
84
|
+
"title": "Name",
|
|
85
|
+
"components": [
|
|
86
|
+
{
|
|
87
|
+
"use": "firstName"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"use": "surname"
|
|
91
|
+
}
|
|
92
|
+
],
|
|
93
|
+
"cya_link": {
|
|
94
|
+
"page": "names",
|
|
95
|
+
"aria_suffix": "names"
|
|
96
|
+
},
|
|
97
|
+
"actions": [
|
|
98
|
+
"submit"
|
|
99
|
+
]
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"id": "dateLocDet",
|
|
103
|
+
"name": "dateLocDetName",
|
|
104
|
+
"title": "Date and location details",
|
|
105
|
+
"components": [
|
|
106
|
+
{
|
|
107
|
+
"use": "dateGroup"
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"use": "timeGroup"
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
"use": "portGroup"
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"use": "whereGroup"
|
|
117
|
+
}
|
|
118
|
+
],
|
|
119
|
+
"cya_link": {
|
|
120
|
+
"page": "dateLocDet",
|
|
121
|
+
"aria_suffix": "Date and location details"
|
|
122
|
+
},
|
|
123
|
+
"actions": [
|
|
124
|
+
"submit"
|
|
125
|
+
]
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
"id": "additional-info",
|
|
129
|
+
"name": "additional-info",
|
|
130
|
+
"title": "Additional Information",
|
|
131
|
+
"components": [
|
|
132
|
+
{
|
|
133
|
+
"use": "extraDetails"
|
|
134
|
+
}
|
|
135
|
+
],
|
|
136
|
+
"cya_link": {
|
|
137
|
+
"page": "additional-info",
|
|
138
|
+
"aria_suffix": "Additional Information"
|
|
139
|
+
},
|
|
140
|
+
"actions": [
|
|
141
|
+
"submit"
|
|
142
|
+
]
|
|
143
|
+
}
|
|
144
|
+
],
|
|
145
|
+
"cya": {
|
|
146
|
+
"hide_page_titles": true,
|
|
147
|
+
"hide_actions": true,
|
|
148
|
+
"groups": [
|
|
149
|
+
{
|
|
150
|
+
"pageId": "dateLocDet"
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
"pageId": "names",
|
|
154
|
+
"title": "Names"
|
|
155
|
+
}
|
|
156
|
+
]
|
|
157
|
+
}
|
|
158
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"currentUser": {
|
|
3
|
+
"givenName": "John",
|
|
4
|
+
"familyName": "Smith"
|
|
5
|
+
},
|
|
6
|
+
"businessKey": "123456789",
|
|
7
|
+
"dateGroupField": "01-01-2022",
|
|
8
|
+
"timeGroupField": "14:57",
|
|
9
|
+
"portGroupField": "Glasgow",
|
|
10
|
+
"whereGroupField": "terminal",
|
|
11
|
+
"firstName": "sample",
|
|
12
|
+
"surname": "test",
|
|
13
|
+
"age": "12",
|
|
14
|
+
"extraDetails": "extra notes here"
|
|
15
|
+
}
|
|
@@ -9,6 +9,7 @@ var TYPE_CHECKBOXES = 'checkboxes';
|
|
|
9
9
|
var TYPE_CONTAINER = 'container';
|
|
10
10
|
var TYPE_DATE = 'date';
|
|
11
11
|
var TYPE_EMAIL = 'email';
|
|
12
|
+
var TYPE_FILE = 'file';
|
|
12
13
|
var TYPE_HEADING = 'heading';
|
|
13
14
|
var TYPE_HTML = 'html';
|
|
14
15
|
var TYPE_INSET_TEXT = 'inset-text';
|
|
@@ -23,6 +24,7 @@ var ComponentTypes = {
|
|
|
23
24
|
CONTAINER: TYPE_CONTAINER,
|
|
24
25
|
DATE: TYPE_DATE,
|
|
25
26
|
EMAIL: TYPE_EMAIL,
|
|
27
|
+
FILE: TYPE_FILE,
|
|
26
28
|
HEADING: TYPE_HEADING,
|
|
27
29
|
HTML: TYPE_HTML,
|
|
28
30
|
INSET_TEXT: TYPE_INSET_TEXT,
|
|
@@ -5,16 +5,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
|
|
10
8
|
var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
11
9
|
|
|
12
|
-
var
|
|
10
|
+
var _react = _interopRequireDefault(require("react"));
|
|
13
11
|
|
|
14
12
|
var _models = require("../../models");
|
|
15
13
|
|
|
16
14
|
var _Data = _interopRequireDefault(require("../Data"));
|
|
17
15
|
|
|
16
|
+
var _cleanAttributes = _interopRequireDefault(require("./cleanAttributes"));
|
|
17
|
+
|
|
18
18
|
var _isEditable = _interopRequireDefault(require("./isEditable"));
|
|
19
19
|
|
|
20
20
|
var _wrapInFormGroup = _interopRequireDefault(require("./wrapInFormGroup"));
|
|
@@ -57,6 +57,11 @@ var getDate = function getDate(config) {
|
|
|
57
57
|
return /*#__PURE__*/_react.default.createElement(_copReactComponents.DateInput, attrs);
|
|
58
58
|
};
|
|
59
59
|
|
|
60
|
+
var getFileUpload = function getFileUpload(config) {
|
|
61
|
+
var attrs = (0, _cleanAttributes.default)(config);
|
|
62
|
+
return /*#__PURE__*/_react.default.createElement(_copReactComponents.FileUpload, attrs);
|
|
63
|
+
};
|
|
64
|
+
|
|
60
65
|
var getHeading = function getHeading(config) {
|
|
61
66
|
var attrs = (0, _cleanAttributes.default)(config);
|
|
62
67
|
return /*#__PURE__*/_react.default.createElement(_copReactComponents.Heading, attrs, config.content);
|
|
@@ -125,14 +130,17 @@ var getComponentByType = function getComponentByType(config) {
|
|
|
125
130
|
case _models.ComponentTypes.RADIOS:
|
|
126
131
|
return getRadios(config);
|
|
127
132
|
|
|
133
|
+
case _models.ComponentTypes.CHECKBOXES:
|
|
134
|
+
return getCheckboxes(config);
|
|
135
|
+
|
|
128
136
|
case _models.ComponentTypes.DATE:
|
|
129
137
|
return getDate(config);
|
|
130
138
|
|
|
131
139
|
case _models.ComponentTypes.TIME:
|
|
132
140
|
return getTime(config);
|
|
133
141
|
|
|
134
|
-
case _models.ComponentTypes.
|
|
135
|
-
return
|
|
142
|
+
case _models.ComponentTypes.FILE:
|
|
143
|
+
return getFileUpload(config);
|
|
136
144
|
|
|
137
145
|
default:
|
|
138
146
|
{
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _react = require("@testing-library/react");
|
|
4
|
+
|
|
5
|
+
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
6
|
+
|
|
7
|
+
var _models = require("../../../models");
|
|
8
|
+
|
|
9
|
+
var _getComponent = _interopRequireDefault(require("../getComponent"));
|
|
10
|
+
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
|
|
13
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
14
|
+
|
|
15
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
16
|
+
|
|
17
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
18
|
+
|
|
19
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
20
|
+
|
|
21
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
22
|
+
|
|
23
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
24
|
+
|
|
25
|
+
describe('utils.Component.get', function () {
|
|
26
|
+
it('should return an appropriately rendered file component', function () {
|
|
27
|
+
var ID = 'test-id';
|
|
28
|
+
var FIELD_ID = 'field-id';
|
|
29
|
+
var LABEL = 'label';
|
|
30
|
+
var ON_CHANGE_CALLS = [];
|
|
31
|
+
|
|
32
|
+
var ON_CHANGE = function ON_CHANGE(e) {
|
|
33
|
+
ON_CHANGE_CALLS.push(e.target);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
var COMPONENT = {
|
|
37
|
+
type: _models.ComponentTypes.FILE,
|
|
38
|
+
id: ID,
|
|
39
|
+
fieldId: FIELD_ID,
|
|
40
|
+
label: LABEL,
|
|
41
|
+
onChange: ON_CHANGE,
|
|
42
|
+
'data-testid': ID
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
var _render = (0, _react.render)((0, _getComponent.default)(COMPONENT)),
|
|
46
|
+
container = _render.container;
|
|
47
|
+
|
|
48
|
+
var _getAllByTestId = (0, _react.getAllByTestId)(container, ID),
|
|
49
|
+
_getAllByTestId2 = _slicedToArray(_getAllByTestId, 2),
|
|
50
|
+
formGroup = _getAllByTestId2[0],
|
|
51
|
+
input = _getAllByTestId2[1];
|
|
52
|
+
|
|
53
|
+
expect(formGroup.tagName).toEqual('DIV');
|
|
54
|
+
expect(formGroup.classList).toContain('govuk-form-group');
|
|
55
|
+
var label = undefined;
|
|
56
|
+
formGroup.childNodes.forEach(function (node) {
|
|
57
|
+
// Check if it's an element.
|
|
58
|
+
if (node instanceof Element && node.tagName === 'LABEL') {
|
|
59
|
+
label = node;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
expect(label).toBeDefined();
|
|
63
|
+
expect(label.innerHTML).toContain(LABEL);
|
|
64
|
+
expect(label.getAttribute('for')).toEqual(ID);
|
|
65
|
+
expect(input.tagName).toEqual('INPUT');
|
|
66
|
+
expect(input.classList).toContain('hods-file-upload__select');
|
|
67
|
+
expect(input.id).toEqual("".concat(ID, "-select"));
|
|
68
|
+
var str = JSON.stringify({
|
|
69
|
+
alpha: 'bravo'
|
|
70
|
+
});
|
|
71
|
+
var blob = new Blob([str]);
|
|
72
|
+
var FILE = new File([blob], 'test.json', {
|
|
73
|
+
type: 'application/JSON'
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
_userEvent.default.upload(input, FILE);
|
|
77
|
+
|
|
78
|
+
expect(ON_CHANGE_CALLS.length).toEqual(1);
|
|
79
|
+
expect(input.files.length).toEqual(1);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -8,7 +8,7 @@ exports.default = exports.EDITABLE_TYPES = void 0;
|
|
|
8
8
|
var _models = require("../../models");
|
|
9
9
|
|
|
10
10
|
// Local imports
|
|
11
|
-
var EDITABLE_TYPES = [_models.ComponentTypes.AUTOCOMPLETE, _models.ComponentTypes.CHECKBOXES, _models.ComponentTypes.DATE, _models.ComponentTypes.EMAIL, _models.ComponentTypes.PHONE_NUMBER, _models.ComponentTypes.RADIOS, _models.ComponentTypes.TEXT, _models.ComponentTypes.TEXT_AREA, _models.ComponentTypes.TIME];
|
|
11
|
+
var EDITABLE_TYPES = [_models.ComponentTypes.AUTOCOMPLETE, _models.ComponentTypes.CHECKBOXES, _models.ComponentTypes.DATE, _models.ComponentTypes.EMAIL, _models.ComponentTypes.FILE, _models.ComponentTypes.PHONE_NUMBER, _models.ComponentTypes.RADIOS, _models.ComponentTypes.TEXT, _models.ComponentTypes.TEXT_AREA, _models.ComponentTypes.TIME];
|
|
12
12
|
exports.EDITABLE_TYPES = EDITABLE_TYPES;
|
|
13
13
|
|
|
14
14
|
var isEditable = function isEditable(options) {
|
package/dist/utils/Data/index.js
CHANGED
|
@@ -15,6 +15,8 @@ var _getSourceData = _interopRequireDefault(require("./getSourceData"));
|
|
|
15
15
|
|
|
16
16
|
var _refDataToOptions = _interopRequireDefault(require("./refDataToOptions"));
|
|
17
17
|
|
|
18
|
+
var _setDataItem = _interopRequireDefault(require("./setDataItem"));
|
|
19
|
+
|
|
18
20
|
var _setupFormData = _interopRequireDefault(require("./setupFormData"));
|
|
19
21
|
|
|
20
22
|
var _setupRefDataUrlForComponent = _interopRequireDefault(require("./setupRefDataUrlForComponent"));
|
|
@@ -31,6 +33,7 @@ var Data = {
|
|
|
31
33
|
setupUrl: _setupRefDataUrlForComponent.default,
|
|
32
34
|
toOptions: _refDataToOptions.default
|
|
33
35
|
},
|
|
36
|
+
setDataItem: _setDataItem.default,
|
|
34
37
|
setupForm: _setupFormData.default
|
|
35
38
|
};
|
|
36
39
|
var _default = Data;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
9
|
+
|
|
10
|
+
var setDataItem = function setDataItem(data, fieldId, value) {
|
|
11
|
+
if (fieldId && data) {
|
|
12
|
+
var parts = fieldId.split('.');
|
|
13
|
+
var leaf = parts.pop();
|
|
14
|
+
var node = data;
|
|
15
|
+
parts.forEach(function (part) {
|
|
16
|
+
if (!node[part] || _typeof(node[part]) !== 'object') {
|
|
17
|
+
node[part] = {};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
node = node[part];
|
|
21
|
+
});
|
|
22
|
+
node[leaf] = value;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return data;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
var _default = setDataItem;
|
|
29
|
+
exports.default = _default;
|