@ukhomeoffice/cop-react-form-renderer 5.62.1 → 5.65.0
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/CollectionSummary/BannerStrip.js +3 -2
- package/dist/components/CollectionSummary/BannerStrip.test.js +39 -4
- package/dist/components/CollectionSummary/CollectionSummary.js +71 -33
- package/dist/components/CollectionSummary/CollectionSummary.test.js +40 -80
- package/dist/components/CollectionSummary/RenderListView.js +9 -7
- package/dist/components/CollectionSummary/RenderListView.scss +4 -0
- package/dist/components/CollectionSummary/RenderListView.test.js +13 -4
- package/dist/components/CollectionSummary/SummaryCard.js +26 -17
- package/dist/components/CollectionSummary/SummaryCard.test.js +177 -146
- package/dist/components/CollectionSummary/SummaryCardDetails.js +16 -0
- package/dist/components/CollectionSummary/SummaryCardDetails.test.js +77 -8
- package/dist/components/CollectionSummary/SummaryCardValidationContext.js +15 -5
- package/dist/components/CollectionSummary/SummaryCardValidationContext.test.js +5 -4
- package/dist/components/FormRenderer/onPageAction.js +6 -1
- package/dist/components/FormRenderer/onPageAction.test.js +18 -4
- package/dist/context/ValidationContext/ValidationContext.js +51 -5
- package/dist/context/ValidationContext/ValidationContext.test.js +16 -7
- package/dist/utils/CollectionPage/duplicateCollectionPageEntry.js +13 -1
- package/dist/utils/CollectionPage/duplicateCollectionPageEntry.test.js +17 -2
- package/dist/utils/Validate/validatePage.js +6 -1
- package/dist/utils/Validate/validatePage.test.js +44 -0
- package/package.json +1 -1
|
@@ -31,13 +31,14 @@ var BannerStrip = function BannerStrip(_ref) {
|
|
|
31
31
|
className: classes()
|
|
32
32
|
}, filteredBanners.map(function (banner, index) {
|
|
33
33
|
var bannerId = "".concat(id, "-banner-").concat(index);
|
|
34
|
-
if (typeof banner === 'string') {
|
|
34
|
+
if (typeof banner === 'string' || banner.type === 'plain') {
|
|
35
|
+
var bannerText = typeof banner === 'string' ? banner : banner.text;
|
|
35
36
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
36
37
|
id: bannerId,
|
|
37
38
|
key: bannerId,
|
|
38
39
|
className: classes('banner')
|
|
39
40
|
}, /*#__PURE__*/_react.default.createElement(_copReactComponents.Markup, {
|
|
40
|
-
content: _utils.default.interpolateString(
|
|
41
|
+
content: _utils.default.interpolateString(bannerText, formData)
|
|
41
42
|
}));
|
|
42
43
|
}
|
|
43
44
|
return /*#__PURE__*/_react.default.createElement(_copReactComponents.Tag, {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
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); }
|
|
4
3
|
var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
5
4
|
var _react = _interopRequireDefault(require("react"));
|
|
6
5
|
var _setupTests = require("../../setupTests");
|
|
@@ -8,10 +7,13 @@ var _BannerStrip = _interopRequireWildcard(require("./BannerStrip"));
|
|
|
8
7
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
9
8
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
10
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
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); }
|
|
11
|
+
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; }
|
|
12
|
+
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; }
|
|
13
|
+
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; }
|
|
14
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
15
|
+
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); } // Global imports.
|
|
13
16
|
// Local imports.
|
|
14
|
-
|
|
15
17
|
describe('components.CollectionSummary.BannerStrip', function () {
|
|
16
18
|
var ID = 'testBanner';
|
|
17
19
|
var BANNERS = ['Banner 1', 'Banner 2'];
|
|
@@ -123,4 +125,37 @@ describe('components.CollectionSummary.BannerStrip', function () {
|
|
|
123
125
|
expect(plainStringBanner.classList.contains(classes('banner'))).toBe(true);
|
|
124
126
|
expect(plainStringBanner.textContent).toEqual(PLAIN_STRING_BANNER);
|
|
125
127
|
});
|
|
128
|
+
it('should correctly render banners based on their show_whens', function () {
|
|
129
|
+
var CUSTOM_BANNERS = [{
|
|
130
|
+
type: 'plain',
|
|
131
|
+
text: 'A banner',
|
|
132
|
+
show_when: [{
|
|
133
|
+
field: 'testField',
|
|
134
|
+
op: '=',
|
|
135
|
+
value: '123'
|
|
136
|
+
}]
|
|
137
|
+
}, {
|
|
138
|
+
type: 'plain',
|
|
139
|
+
text: BANNERS[1]
|
|
140
|
+
}];
|
|
141
|
+
var CUSTOM_FORM_DATA = _objectSpread(_objectSpread({}, FORM_DATA), {}, {
|
|
142
|
+
testField: 'abc'
|
|
143
|
+
});
|
|
144
|
+
var _renderWithValidation6 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_BannerStrip.default, {
|
|
145
|
+
id: ID,
|
|
146
|
+
banners: CUSTOM_BANNERS,
|
|
147
|
+
formData: CUSTOM_FORM_DATA
|
|
148
|
+
})),
|
|
149
|
+
container = _renderWithValidation6.container;
|
|
150
|
+
var bannerStripDiv = checkSetup(container);
|
|
151
|
+
expect(bannerStripDiv.tagName).toEqual('DIV');
|
|
152
|
+
expect(bannerStripDiv.classList).toContain(_BannerStrip.DEFAULT_CLASS);
|
|
153
|
+
expect(bannerStripDiv.children.length).toEqual(1); // One banner should be hidden.
|
|
154
|
+
|
|
155
|
+
// Only the second banner should be visible.
|
|
156
|
+
var secondBanner = bannerStripDiv.children[0];
|
|
157
|
+
expect(secondBanner.tagName).toEqual('DIV');
|
|
158
|
+
expect(secondBanner.classList).toContain(classes('banner'));
|
|
159
|
+
expect(secondBanner.textContent).toEqual(CUSTOM_BANNERS[1].text);
|
|
160
|
+
});
|
|
126
161
|
});
|
|
@@ -9,18 +9,21 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
9
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
10
|
var _hooks = require("../../hooks");
|
|
11
11
|
var _PageAction = require("../../models/PageAction");
|
|
12
|
+
var _elevateNestedComponents = _interopRequireDefault(require("../../utils/Component/elevateNestedComponents"));
|
|
12
13
|
var _utils = _interopRequireDefault(require("../../utils"));
|
|
13
14
|
var _getCYARow = _interopRequireDefault(require("../../utils/CheckYourAnswers/getCYARow"));
|
|
14
|
-
var _elevateNestedComponents = _interopRequireDefault(require("../../utils/Component/elevateNestedComponents"));
|
|
15
15
|
var _Answer = _interopRequireDefault(require("../CheckYourAnswers/Answer"));
|
|
16
16
|
var _ActionButton = _interopRequireDefault(require("../PageActions/ActionButton"));
|
|
17
17
|
var _Confirmation = _interopRequireDefault(require("./Confirmation"));
|
|
18
18
|
var _SummaryCard = _interopRequireDefault(require("./SummaryCard"));
|
|
19
19
|
var _SummaryCardValidationContext = _interopRequireDefault(require("./SummaryCardValidationContext"));
|
|
20
20
|
require("./CollectionSummary.scss");
|
|
21
|
+
var _excluded = ["isDuplicate"];
|
|
21
22
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
22
23
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
23
24
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
26
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
24
27
|
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; }
|
|
25
28
|
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; }
|
|
26
29
|
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; }
|
|
@@ -55,10 +58,15 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
55
58
|
onAction = _ref.onAction,
|
|
56
59
|
onChange = _ref.onChange,
|
|
57
60
|
pages = _ref.pages;
|
|
61
|
+
var _useHooks = (0, _hooks.useHooks)(),
|
|
62
|
+
hooks = _useHooks.hooks;
|
|
58
63
|
var _useValidation = (0, _hooks.useValidation)(),
|
|
59
64
|
errors = _useValidation.errors,
|
|
60
65
|
addErrors = _useValidation.addErrors,
|
|
61
|
-
clearErrors = _useValidation.clearErrors
|
|
66
|
+
clearErrors = _useValidation.clearErrors,
|
|
67
|
+
queuedErrors = _useValidation.queuedErrors,
|
|
68
|
+
enqueueErrors = _useValidation.enqueueErrors,
|
|
69
|
+
dequeueErrors = _useValidation.dequeueErrors;
|
|
62
70
|
var _useState = (0, _react.useState)(null),
|
|
63
71
|
_useState2 = _slicedToArray(_useState, 2),
|
|
64
72
|
entryToDelete = _useState2[0],
|
|
@@ -98,15 +106,13 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
98
106
|
return [];
|
|
99
107
|
}, [masterPage, formData, entryToDelete, config.card.listView]);
|
|
100
108
|
var validateEntries = function validateEntries() {
|
|
101
|
-
|
|
102
|
-
// We only clear errors if it's not empty to avoid
|
|
109
|
+
// We only clear queuedErrors if it's not empty to avoid
|
|
103
110
|
// triggering a race condition with the 'data' memo
|
|
104
111
|
// above.
|
|
105
|
-
if (
|
|
106
|
-
|
|
107
|
-
return e.
|
|
112
|
+
if (queuedErrors.length > 0) {
|
|
113
|
+
dequeueErrors(function (e) {
|
|
114
|
+
return e.raisedBy === config.id;
|
|
108
115
|
});
|
|
109
|
-
clearErrors();
|
|
110
116
|
}
|
|
111
117
|
var allErrors = [];
|
|
112
118
|
data.forEach(function (entry) {
|
|
@@ -119,25 +125,25 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
119
125
|
});
|
|
120
126
|
});
|
|
121
127
|
var allPagesErrors = (childPages === null || childPages === void 0 ? void 0 : childPages.flatMap(function (page) {
|
|
122
|
-
|
|
128
|
+
var pageErrors = _utils.default.Validate.page(page);
|
|
129
|
+
return hooks.onValidate(page, pageErrors);
|
|
123
130
|
})) || [];
|
|
124
131
|
// For each error we found, add the entryId so we know what Summary Card
|
|
125
132
|
// we have to pass it to.
|
|
126
133
|
var entryErrors = allPagesErrors.map(function (e) {
|
|
127
134
|
return _objectSpread(_objectSpread({}, e), {}, {
|
|
128
|
-
entryId: entry.id
|
|
135
|
+
entryId: entry.id,
|
|
136
|
+
showFor: config.id,
|
|
137
|
+
raisedBy: config.id
|
|
129
138
|
});
|
|
130
139
|
});
|
|
131
140
|
allErrors = allErrors.concat(entryErrors);
|
|
132
141
|
});
|
|
133
|
-
if
|
|
134
|
-
allErrors = allErrors.concat(stored);
|
|
135
|
-
}
|
|
136
|
-
// We only add allErrors if it's not empty to avoid
|
|
142
|
+
// We only queue allErrors if it's not empty to avoid
|
|
137
143
|
// triggering a race condition with the 'data' memo
|
|
138
144
|
// above.
|
|
139
145
|
if (allErrors.length > 0) {
|
|
140
|
-
|
|
146
|
+
enqueueErrors(allErrors);
|
|
141
147
|
}
|
|
142
148
|
};
|
|
143
149
|
(0, _react.useEffect)(function () {
|
|
@@ -147,22 +153,35 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
147
153
|
validateEntries();
|
|
148
154
|
}
|
|
149
155
|
}, [data]);
|
|
150
|
-
var
|
|
151
|
-
if (typeof onAction
|
|
152
|
-
|
|
156
|
+
var onSummaryCardFullEdit = function onSummaryCardFullEdit(page, entryId) {
|
|
157
|
+
if (typeof onAction === 'function') {
|
|
158
|
+
var newData = [].concat(data);
|
|
159
|
+
var entryIndex = data.findIndex(function (e) {
|
|
160
|
+
return e.id === entryId;
|
|
161
|
+
});
|
|
162
|
+
var _data$entryIndex = data[entryIndex],
|
|
163
|
+
isDuplicate = _data$entryIndex.isDuplicate,
|
|
164
|
+
newEntry = _objectWithoutProperties(_data$entryIndex, _excluded);
|
|
165
|
+
newData[entryIndex] = _objectSpread({}, newEntry);
|
|
166
|
+
onAction({
|
|
167
|
+
type: _PageAction.PageActionTypes.SAVE_AND_NAVIGATE,
|
|
168
|
+
page: page,
|
|
169
|
+
addToFormData: [{
|
|
170
|
+
field: "".concat(config.collectionName.split('.').pop(), "ActiveId"),
|
|
171
|
+
value: entryId
|
|
172
|
+
}, {
|
|
173
|
+
field: config.collectionName,
|
|
174
|
+
value: newData,
|
|
175
|
+
isCollection: true
|
|
176
|
+
}]
|
|
177
|
+
});
|
|
153
178
|
}
|
|
154
|
-
onAction({
|
|
155
|
-
type: _PageAction.PageActionTypes.SAVE_AND_NAVIGATE,
|
|
156
|
-
page: page,
|
|
157
|
-
addToFormData: {
|
|
158
|
-
field: "".concat(config.collectionName.split('.').pop(), "ActiveId"),
|
|
159
|
-
value: entryId
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
179
|
};
|
|
163
180
|
var onDuplicate = function onDuplicate(entry) {
|
|
164
181
|
var _config$card;
|
|
165
|
-
_utils.default.CollectionPage.duplicateEntry(config.collectionName, formData, entry.id, ((_config$card = config.card) === null || _config$card === void 0 || (_config$card = _config$card.duplicateAction) === null || _config$card === void 0 ? void 0 : _config$card.fieldsToIgnore) || []
|
|
182
|
+
_utils.default.CollectionPage.duplicateEntry(config.collectionName, formData, entry.id, ((_config$card = config.card) === null || _config$card === void 0 || (_config$card = _config$card.duplicateAction) === null || _config$card === void 0 ? void 0 : _config$card.fieldsToIgnore) || [], {
|
|
183
|
+
isDuplicate: true
|
|
184
|
+
});
|
|
166
185
|
var parentCollection = config.collectionName.split('.').shift();
|
|
167
186
|
// Report the whole top-level collection as being changed. We have to do this
|
|
168
187
|
// because of how patch is applied to formData on a page submission.
|
|
@@ -216,7 +235,9 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
216
235
|
id: config.fieldId
|
|
217
236
|
}, entryToDelete && /*#__PURE__*/_react.default.createElement(_Confirmation.default, {
|
|
218
237
|
id: "".concat(config.fieldId, ".confirmation"),
|
|
219
|
-
message: _utils.default.interpolateString((_config$confirmation = config.confirmation) === null || _config$confirmation === void 0 ? void 0 : _config$confirmation.message, entryToDelete)
|
|
238
|
+
message: _utils.default.interpolateString((_config$confirmation = config.confirmation) === null || _config$confirmation === void 0 ? void 0 : _config$confirmation.message, _objectSpread(_objectSpread({}, entryToDelete), {}, {
|
|
239
|
+
index: entryToDelete.index + 1
|
|
240
|
+
})) || null,
|
|
220
241
|
confirmLabel: _utils.default.interpolateString((_config$confirmation2 = config.confirmation) === null || _config$confirmation2 === void 0 ? void 0 : _config$confirmation2.label, entryToDelete) || null,
|
|
221
242
|
onConfirm: onDeleteConfirm,
|
|
222
243
|
onCancel: function onCancel() {
|
|
@@ -247,11 +268,18 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
247
268
|
var isInError = errors.filter(function (e) {
|
|
248
269
|
return e.entryId === entry.id;
|
|
249
270
|
}).length > 0;
|
|
250
|
-
var finalConfig = _objectSpread(_objectSpread({}, config.card), isInError && config.errorCard ? config.errorCard : {});
|
|
271
|
+
var finalConfig = _objectSpread(_objectSpread(_objectSpread({}, config.card), entry.isDuplicate && config.duplicatedCard ? config.duplicatedCard : {}), isInError && config.errorCard ? config.errorCard : {});
|
|
251
272
|
var key = "".concat(config.fieldId, ".summaryCard").concat(entry.id);
|
|
252
273
|
return /*#__PURE__*/_react.default.createElement(_SummaryCardValidationContext.default, {
|
|
253
274
|
entryId: entry.id,
|
|
254
|
-
topLevelErrors: errors
|
|
275
|
+
topLevelErrors: errors,
|
|
276
|
+
clearTopLevelErrorsForCard: function clearTopLevelErrorsForCard() {
|
|
277
|
+
var newErrors = errors.filter(function (e) {
|
|
278
|
+
return e.entryId !== entry.id;
|
|
279
|
+
});
|
|
280
|
+
clearErrors();
|
|
281
|
+
addErrors(newErrors);
|
|
282
|
+
}
|
|
255
283
|
}, /*#__PURE__*/_react.default.createElement(_SummaryCard.default, {
|
|
256
284
|
id: key,
|
|
257
285
|
key: key,
|
|
@@ -260,10 +288,12 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
260
288
|
}),
|
|
261
289
|
masterPage: masterPage,
|
|
262
290
|
config: finalConfig || {},
|
|
263
|
-
|
|
291
|
+
onFullEdit: onSummaryCardFullEdit,
|
|
264
292
|
onDuplicate: onDuplicate,
|
|
265
293
|
onDelete: function onDelete() {
|
|
266
|
-
return setEntryToDelete(entry)
|
|
294
|
+
return setEntryToDelete(_objectSpread(_objectSpread({}, entry), {}, {
|
|
295
|
+
index: index
|
|
296
|
+
}));
|
|
267
297
|
},
|
|
268
298
|
onQuickEdit: function onQuickEdit(target) {
|
|
269
299
|
validateEntries();
|
|
@@ -272,7 +302,7 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
272
302
|
parentCollectionName: config.collectionName.split('.').shift(),
|
|
273
303
|
childCollections: config.childCollections || [],
|
|
274
304
|
formData: formData,
|
|
275
|
-
classModifiers: entry === entryToDelete ? ['deleting-summary-card'] : [''],
|
|
305
|
+
classModifiers: entry.id === (entryToDelete === null || entryToDelete === void 0 ? void 0 : entryToDelete.id) ? ['deleting-summary-card'] : [''],
|
|
276
306
|
inError: errors.filter(function (e) {
|
|
277
307
|
return e.entryId === entry.id;
|
|
278
308
|
}).length > 0
|
|
@@ -315,6 +345,14 @@ CollectionSummary.propTypes = {
|
|
|
315
345
|
fieldsToIgnore: _propTypes.default.arrayOf(_propTypes.default.string)
|
|
316
346
|
})
|
|
317
347
|
}),
|
|
348
|
+
duplicatedCard: _propTypes.default.shape({
|
|
349
|
+
banners: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.shape({})])),
|
|
350
|
+
title: _propTypes.default.string,
|
|
351
|
+
details: _propTypes.default.string,
|
|
352
|
+
duplicateAction: _propTypes.default.shape({
|
|
353
|
+
fieldsToIgnore: _propTypes.default.arrayOf(_propTypes.default.string)
|
|
354
|
+
})
|
|
355
|
+
}),
|
|
318
356
|
confirmation: _propTypes.default.shape({
|
|
319
357
|
message: _propTypes.default.string,
|
|
320
358
|
label: _propTypes.default.string,
|
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
var _react = _interopRequireDefault(require("react"));
|
|
4
4
|
var _react2 = require("@testing-library/react");
|
|
5
5
|
var _setupTests = require("../../setupTests");
|
|
6
|
-
var _context = require("../../context");
|
|
7
|
-
var _ValidationContext = require("../../context/ValidationContext");
|
|
8
6
|
var _hooks = require("../../hooks");
|
|
9
7
|
var _CollectionSummary = _interopRequireWildcard(require("./CollectionSummary"));
|
|
10
8
|
var _Confirmation = require("./Confirmation");
|
|
@@ -75,11 +73,11 @@ describe('components.CollectionSummary.CollectionSummary', function () {
|
|
|
75
73
|
expect(summary.children[0].id).toEqual("".concat(CONFIG.fieldId, ".summaryCard").concat(FORM_DATA.testCollection[0].id));
|
|
76
74
|
expect(summary.children[1].id).toEqual("".concat(CONFIG.fieldId, ".summaryCard").concat(FORM_DATA.testCollection[1].id));
|
|
77
75
|
});
|
|
78
|
-
it('should correctly
|
|
76
|
+
it('should correctly queue errors found when validating entries', function () {
|
|
79
77
|
var ErrorCheckComponent = function ErrorCheckComponent() {
|
|
80
78
|
var _useValidation = (0, _hooks.useValidation)(),
|
|
81
|
-
|
|
82
|
-
return /*#__PURE__*/_react.default.createElement("div", null, Array.isArray(
|
|
79
|
+
queuedErrors = _useValidation.queuedErrors;
|
|
80
|
+
return /*#__PURE__*/_react.default.createElement("div", null, Array.isArray(queuedErrors) && "queuedErrors is an array of length ".concat(queuedErrors.length), (queuedErrors === null || queuedErrors === void 0 ? void 0 : queuedErrors.length) > 0 && queuedErrors.map(function (e) {
|
|
83
81
|
return e.error;
|
|
84
82
|
}));
|
|
85
83
|
};
|
|
@@ -91,7 +89,7 @@ describe('components.CollectionSummary.CollectionSummary', function () {
|
|
|
91
89
|
}))),
|
|
92
90
|
container = _renderWithValidation2.container;
|
|
93
91
|
var errorChecker = container.children[0];
|
|
94
|
-
expect(errorChecker.textContent).toContain('
|
|
92
|
+
expect(errorChecker.textContent).toContain('queuedErrors is an array of length 1');
|
|
95
93
|
expect(errorChecker.textContent).toContain('testText is required');
|
|
96
94
|
});
|
|
97
95
|
it('should render a confirmation when a SummaryCard\'s delete button is pressed', function () {
|
|
@@ -110,80 +108,6 @@ describe('components.CollectionSummary.CollectionSummary', function () {
|
|
|
110
108
|
expect(summary.children[0].id).toEqual("".concat(CONFIG.fieldId, ".confirmation"));
|
|
111
109
|
expect(summary.children[0].classList).toContain(_Confirmation.DEFAULT_CLASS);
|
|
112
110
|
});
|
|
113
|
-
it('should keep higher level errors that relate to the CollectionSummary', function () {
|
|
114
|
-
var errors = [{
|
|
115
|
-
id: 'testSummary',
|
|
116
|
-
error: 'add at least one'
|
|
117
|
-
}];
|
|
118
|
-
var clearErrorCount = 0;
|
|
119
|
-
var errorsAdded = [];
|
|
120
|
-
var clearErrors = function clearErrors() {
|
|
121
|
-
clearErrorCount += 1;
|
|
122
|
-
};
|
|
123
|
-
var addErrors = function addErrors(newErrors) {
|
|
124
|
-
errorsAdded = errorsAdded.concat(newErrors);
|
|
125
|
-
};
|
|
126
|
-
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_context.HooksContextProvider, null, /*#__PURE__*/_react.default.createElement(_ValidationContext.ValidationContext.Provider, {
|
|
127
|
-
value: {
|
|
128
|
-
errors: errors,
|
|
129
|
-
clearErrors: clearErrors,
|
|
130
|
-
addErrors: addErrors,
|
|
131
|
-
validate: function validate() {}
|
|
132
|
-
}
|
|
133
|
-
}, /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
|
|
134
|
-
config: _objectSpread(_objectSpread({}, CONFIG), {}, {
|
|
135
|
-
required: true
|
|
136
|
-
}),
|
|
137
|
-
formData: _objectSpread(_objectSpread({}, FORM_DATA), {}, {
|
|
138
|
-
testCollection: [{
|
|
139
|
-
id: '000',
|
|
140
|
-
testText: 'value'
|
|
141
|
-
}]
|
|
142
|
-
}),
|
|
143
|
-
onAction: ON_ACTION,
|
|
144
|
-
pages: PAGES
|
|
145
|
-
}))));
|
|
146
|
-
expect(clearErrorCount).toEqual(1);
|
|
147
|
-
expect(errorsAdded[0]).toEqual({
|
|
148
|
-
id: 'testSummary',
|
|
149
|
-
error: 'add at least one'
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
it('should ignore higher level errors that do not relate to the CollectionSummary', function () {
|
|
153
|
-
var errors = [{
|
|
154
|
-
id: 'somethingElse',
|
|
155
|
-
error: 'add at least one'
|
|
156
|
-
}];
|
|
157
|
-
var clearErrorCount = 0;
|
|
158
|
-
var errorsAdded = [];
|
|
159
|
-
var clearErrors = function clearErrors() {
|
|
160
|
-
clearErrorCount += 1;
|
|
161
|
-
};
|
|
162
|
-
var addErrors = function addErrors(newErrors) {
|
|
163
|
-
errorsAdded = errorsAdded.concat(newErrors);
|
|
164
|
-
};
|
|
165
|
-
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_context.HooksContextProvider, null, /*#__PURE__*/_react.default.createElement(_ValidationContext.ValidationContext.Provider, {
|
|
166
|
-
value: {
|
|
167
|
-
errors: errors,
|
|
168
|
-
clearErrors: clearErrors,
|
|
169
|
-
addErrors: addErrors
|
|
170
|
-
}
|
|
171
|
-
}, /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
|
|
172
|
-
config: _objectSpread(_objectSpread({}, CONFIG), {}, {
|
|
173
|
-
required: true
|
|
174
|
-
}),
|
|
175
|
-
formData: _objectSpread(_objectSpread({}, FORM_DATA), {}, {
|
|
176
|
-
testCollection: [{
|
|
177
|
-
id: '000',
|
|
178
|
-
testText: 'value'
|
|
179
|
-
}]
|
|
180
|
-
}),
|
|
181
|
-
onAction: ON_ACTION,
|
|
182
|
-
pages: PAGES
|
|
183
|
-
}))));
|
|
184
|
-
expect(clearErrorCount).toEqual(1);
|
|
185
|
-
expect(errorsAdded.length).toEqual(0);
|
|
186
|
-
});
|
|
187
111
|
describe('Add Another button', function () {
|
|
188
112
|
it('should render with an Add button if one is configured', function () {
|
|
189
113
|
var CONFIG_WITH_BUTTON = {
|
|
@@ -313,5 +237,41 @@ describe('components.CollectionSummary.CollectionSummary', function () {
|
|
|
313
237
|
expect(fieldElement).not.toBeNull();
|
|
314
238
|
});
|
|
315
239
|
});
|
|
240
|
+
it('should correctly render field values in confirmation view with index', function () {
|
|
241
|
+
var listViewConfig = _objectSpread(_objectSpread({}, CONFIG), {}, {
|
|
242
|
+
card: _objectSpread(_objectSpread({}, CONFIG.card), {}, {
|
|
243
|
+
listView: true
|
|
244
|
+
}),
|
|
245
|
+
confirmation: {
|
|
246
|
+
displayFields: ['testText'],
|
|
247
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
248
|
+
message: 'Test confirmation message with index number ${index}'
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
var _renderWithValidation10 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
|
|
252
|
+
config: listViewConfig,
|
|
253
|
+
formData: FORM_DATA,
|
|
254
|
+
onAction: ON_ACTION,
|
|
255
|
+
pages: PAGES
|
|
256
|
+
})),
|
|
257
|
+
container = _renderWithValidation10.container,
|
|
258
|
+
getByText = _renderWithValidation10.getByText;
|
|
259
|
+
var summary = checkSetup(container);
|
|
260
|
+
expect(summary.children.length).toEqual(2);
|
|
261
|
+
var card = summary.children[0];
|
|
262
|
+
var deleteButton = card.querySelector('.govuk-summary-card__actions li:last-child button');
|
|
263
|
+
_react2.fireEvent.click(deleteButton);
|
|
264
|
+
var confirmation = container.querySelector(".".concat(_Confirmation.DEFAULT_CLASS));
|
|
265
|
+
expect(confirmation).toBeTruthy();
|
|
266
|
+
listViewConfig.confirmation.displayFields.forEach(function (field) {
|
|
267
|
+
var fieldValue = FORM_DATA.testCollection[0][field];
|
|
268
|
+
var fieldElement = getByText(fieldValue);
|
|
269
|
+
expect(fieldElement).not.toBeNull();
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
// Check if the confirmation message contains the index
|
|
273
|
+
var confirmationMessage = confirmation.querySelector('h2').textContent;
|
|
274
|
+
expect(confirmationMessage).toContain("Test confirmation message with index number 1");
|
|
275
|
+
});
|
|
316
276
|
});
|
|
317
277
|
});
|
|
@@ -31,7 +31,7 @@ var RenderListView = function RenderListView(_ref) {
|
|
|
31
31
|
var id = _ref.id,
|
|
32
32
|
entryData = _ref.entryData,
|
|
33
33
|
config = _ref.config,
|
|
34
|
-
|
|
34
|
+
onFullEdit = _ref.onFullEdit,
|
|
35
35
|
onDelete = _ref.onDelete,
|
|
36
36
|
masterPage = _ref.masterPage,
|
|
37
37
|
classModifiers = _ref.classModifiers;
|
|
@@ -50,21 +50,22 @@ var RenderListView = function RenderListView(_ref) {
|
|
|
50
50
|
className: classes('actions')
|
|
51
51
|
}, /*#__PURE__*/_react.default.createElement("li", {
|
|
52
52
|
className: classes('action')
|
|
53
|
-
}, config.changeAction && typeof
|
|
53
|
+
}, config.changeAction && typeof onFullEdit === 'function' && /*#__PURE__*/_react.default.createElement("div", {
|
|
54
54
|
className: "govuk-link",
|
|
55
55
|
onClick: function onClick() {
|
|
56
|
-
return
|
|
56
|
+
return onFullEdit(config.changeAction.page, entryData.id);
|
|
57
57
|
},
|
|
58
58
|
onKeyDown: function onKeyDown(e) {
|
|
59
59
|
if (e.key === 'Enter' || e.key === ' ') {
|
|
60
|
-
|
|
60
|
+
onFullEdit(config.changeAction.page, entryData.id);
|
|
61
61
|
}
|
|
62
62
|
},
|
|
63
63
|
role: "button",
|
|
64
64
|
tabIndex: 0,
|
|
65
65
|
style: {
|
|
66
66
|
cursor: 'pointer'
|
|
67
|
-
}
|
|
67
|
+
},
|
|
68
|
+
"aria-label": config.changeAction.label
|
|
68
69
|
}, config.changeAction.label || DEFAULT_CHANGE_BUTTON_LABEL)), /*#__PURE__*/_react.default.createElement("li", {
|
|
69
70
|
className: classes('action')
|
|
70
71
|
}, config.deleteAction && typeof onDelete === 'function' && /*#__PURE__*/_react.default.createElement(_copReactComponents.Button, {
|
|
@@ -72,7 +73,8 @@ var RenderListView = function RenderListView(_ref) {
|
|
|
72
73
|
onClick: function onClick() {
|
|
73
74
|
return onDelete(entryData);
|
|
74
75
|
},
|
|
75
|
-
classModifiers: config.deleteAction.classModifiers || DEFAULT_DELETE_BUTTON_CLASS
|
|
76
|
+
classModifiers: config.deleteAction.classModifiers || DEFAULT_DELETE_BUTTON_CLASS,
|
|
77
|
+
"aria-label": config.deleteAction.label
|
|
76
78
|
}, config.deleteAction.label || DEFAULT_DELETE_BUTTON_LABEL)))), /*#__PURE__*/_react.default.createElement("div", {
|
|
77
79
|
className: classes('content')
|
|
78
80
|
}, /*#__PURE__*/_react.default.createElement("dl", {
|
|
@@ -117,7 +119,7 @@ RenderListView.propTypes = {
|
|
|
117
119
|
}),
|
|
118
120
|
listView: _propTypes.default.bool
|
|
119
121
|
}).isRequired,
|
|
120
|
-
|
|
122
|
+
onFullEdit: _propTypes.default.func.isRequired,
|
|
121
123
|
onDelete: _propTypes.default.func.isRequired,
|
|
122
124
|
masterPage: _propTypes.default.shape({
|
|
123
125
|
childPages: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
@@ -179,6 +179,10 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
|
|
|
179
179
|
.govuk-summary-card {
|
|
180
180
|
@include govuk-responsive-margin(6, "bottom");
|
|
181
181
|
border: 1px solid $govuk-border-colour;
|
|
182
|
+
|
|
183
|
+
&--deleting-summary-card {
|
|
184
|
+
background-color: #FCF0EE;
|
|
185
|
+
}
|
|
182
186
|
}
|
|
183
187
|
|
|
184
188
|
.govuk-summary-card__title-wrapper {
|
|
@@ -114,7 +114,7 @@ describe('components.CollectionSummary.RenderListView', function () {
|
|
|
114
114
|
id: ID,
|
|
115
115
|
entryData: ENTRY,
|
|
116
116
|
config: CONFIG,
|
|
117
|
-
|
|
117
|
+
onFullEdit: ON_CHANGE,
|
|
118
118
|
onDelete: ON_DELETE,
|
|
119
119
|
masterPage: MASTER_PAGE,
|
|
120
120
|
getComponentRow: getComponentRow
|
|
@@ -155,7 +155,7 @@ describe('components.CollectionSummary.RenderListView', function () {
|
|
|
155
155
|
id: ID,
|
|
156
156
|
entryData: ENTRY,
|
|
157
157
|
config: CONFIG,
|
|
158
|
-
|
|
158
|
+
onFullEdit: ON_CHANGE,
|
|
159
159
|
onDelete: ON_DELETE,
|
|
160
160
|
masterPage: MASTER_PAGE,
|
|
161
161
|
getComponentRow: getComponentRow
|
|
@@ -184,18 +184,23 @@ describe('components.CollectionSummary.RenderListView', function () {
|
|
|
184
184
|
id: ID,
|
|
185
185
|
entryData: ENTRY,
|
|
186
186
|
config: CONFIG,
|
|
187
|
-
|
|
187
|
+
onFullEdit: ON_CHANGE,
|
|
188
188
|
onDelete: ON_DELETE,
|
|
189
189
|
masterPage: MASTER_PAGE,
|
|
190
190
|
getComponentRow: getComponentRow
|
|
191
191
|
})),
|
|
192
|
-
container = _renderWithValidation3.container
|
|
192
|
+
container = _renderWithValidation3.container,
|
|
193
|
+
queryByRole = _renderWithValidation3.queryByRole;
|
|
193
194
|
var listViewDiv = container.querySelector('.govuk-summary-card');
|
|
194
195
|
expect(listViewDiv).not.toBeNull();
|
|
195
196
|
|
|
196
197
|
// Check for change button
|
|
197
198
|
var changeLink = listViewDiv.querySelector('.govuk-link');
|
|
198
199
|
expect(changeLink.textContent).toEqual(CONFIG.changeAction.label);
|
|
200
|
+
var changeButton = queryByRole('button', {
|
|
201
|
+
name: CONFIG.changeAction.label
|
|
202
|
+
});
|
|
203
|
+
expect(changeButton).toBeTruthy();
|
|
199
204
|
_react.fireEvent.click(changeLink, {});
|
|
200
205
|
expect(onChangeCalls).toEqual(1);
|
|
201
206
|
expect(onChangeArgs[0]).toMatchObject({
|
|
@@ -206,6 +211,10 @@ describe('components.CollectionSummary.RenderListView', function () {
|
|
|
206
211
|
// Check for delete button
|
|
207
212
|
var deleteButton = listViewDiv.querySelector('[id$=".deleteButton"]');
|
|
208
213
|
expect(deleteButton.textContent).toEqual(CONFIG.deleteAction.label);
|
|
214
|
+
var deleteButtonElement = queryByRole('button', {
|
|
215
|
+
name: CONFIG.deleteAction.label
|
|
216
|
+
});
|
|
217
|
+
expect(deleteButtonElement).toBeTruthy();
|
|
209
218
|
_react.fireEvent.click(deleteButton, {});
|
|
210
219
|
expect(onDeleteCalls).toEqual(1);
|
|
211
220
|
expect(onDeleteArgs[0]).toEqual(ENTRY);
|