@ukhomeoffice/cop-react-form-renderer 5.44.1-alpha → 5.45.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/CollectionSummary/CollectionSummary.js +72 -30
- package/dist/components/CollectionSummary/CollectionSummary.test.js +52 -13
- package/dist/components/CollectionSummary/SummaryCard.js +9 -4
- package/dist/components/CollectionSummary/SummaryCard.test.js +257 -86
- package/dist/components/CollectionSummary/SummaryCardValidationContext.js +72 -0
- package/dist/components/CollectionSummary/SummaryCardValidationContext.test.js +98 -0
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +1 -2
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +0 -20
- package/package.json +2 -2
|
@@ -10,8 +10,10 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
10
10
|
var _PageAction = require("../../models/PageAction");
|
|
11
11
|
var _utils = _interopRequireDefault(require("../../utils"));
|
|
12
12
|
var _ActionButton = _interopRequireDefault(require("../PageActions/ActionButton"));
|
|
13
|
+
var _hooks = require("../../hooks");
|
|
13
14
|
var _Confirmation = _interopRequireDefault(require("./Confirmation"));
|
|
14
15
|
var _SummaryCard = _interopRequireDefault(require("./SummaryCard"));
|
|
16
|
+
var _SummaryCardValidationContext = _interopRequireDefault(require("./SummaryCardValidationContext"));
|
|
15
17
|
require("./CollectionSummary.scss");
|
|
16
18
|
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); }
|
|
17
19
|
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; }
|
|
@@ -30,6 +32,19 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } // Global
|
|
|
30
32
|
// Local imports.
|
|
31
33
|
// Styles.
|
|
32
34
|
var DEFAULT_ADD_BUTTON_LABEL = exports.DEFAULT_ADD_BUTTON_LABEL = 'Add';
|
|
35
|
+
|
|
36
|
+
// A note about validation.
|
|
37
|
+
//
|
|
38
|
+
// A Collection Summary validates each entry whenever the list of entries changes
|
|
39
|
+
// in any way. This was required as duplicating entries can lead to entries being
|
|
40
|
+
// invalid as soon as they are created - something that is impossible to flag
|
|
41
|
+
// to the user given that validation currently only occurs in onPageAction.
|
|
42
|
+
//
|
|
43
|
+
// The Summary Cards themselves are wrapped in their own custom Validation Contexts,
|
|
44
|
+
// see (SummaryCardValidationContext.jsx). These contexts are provided with any
|
|
45
|
+
// errors found by the summary and allow the Summary Card to keep any Quick Edit
|
|
46
|
+
// errors local to the Quick Edit page.
|
|
47
|
+
|
|
33
48
|
var CollectionSummary = function CollectionSummary(_ref) {
|
|
34
49
|
var _config$confirmation, _config$confirmation2;
|
|
35
50
|
var config = _ref.config,
|
|
@@ -37,14 +52,14 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
37
52
|
onAction = _ref.onAction,
|
|
38
53
|
onChange = _ref.onChange,
|
|
39
54
|
pages = _ref.pages;
|
|
40
|
-
var
|
|
55
|
+
var _useValidation = (0, _hooks.useValidation)(),
|
|
56
|
+
errors = _useValidation.errors,
|
|
57
|
+
addErrors = _useValidation.addErrors,
|
|
58
|
+
clearErrors = _useValidation.clearErrors;
|
|
59
|
+
var _useState = (0, _react.useState)(null),
|
|
41
60
|
_useState2 = _slicedToArray(_useState, 2),
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
var _useState3 = (0, _react.useState)(null),
|
|
45
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
46
|
-
entryToDelete = _useState4[0],
|
|
47
|
-
setEntryToDelete = _useState4[1];
|
|
61
|
+
entryToDelete = _useState2[0],
|
|
62
|
+
setEntryToDelete = _useState2[1];
|
|
48
63
|
var data = (0, _react.useMemo)(function () {
|
|
49
64
|
return _utils.default.CollectionPage.getData(config.collectionName, formData) || [];
|
|
50
65
|
}, [formData]);
|
|
@@ -55,21 +70,46 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
55
70
|
return ((_page$collection = page.collection) === null || _page$collection === void 0 ? void 0 : _page$collection.name) === config.collectionName;
|
|
56
71
|
});
|
|
57
72
|
}, [pages]);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
73
|
+
var validateEntries = function validateEntries() {
|
|
74
|
+
// We only clear errors if it's not empty to avoid
|
|
75
|
+
// triggering a race condition with the 'data' memo
|
|
76
|
+
// above.
|
|
77
|
+
if (errors.length > 0) {
|
|
78
|
+
clearErrors();
|
|
62
79
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
80
|
+
var allErrors = [];
|
|
81
|
+
data.forEach(function (entry) {
|
|
82
|
+
// Validation of a collection page uses the data from the
|
|
83
|
+
// active entry, so here we have to set the active ID before
|
|
84
|
+
// validating.
|
|
85
|
+
var childPages = masterPage === null || masterPage === void 0 ? void 0 : masterPage.childPages.map(function (page) {
|
|
86
|
+
return _objectSpread(_objectSpread({}, page), {}, {
|
|
87
|
+
formData: _objectSpread(_objectSpread({}, masterPage.formData), {}, _defineProperty({}, "".concat(config.collectionName, "ActiveId"), entry.id))
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
var allPagesErrors = (childPages === null || childPages === void 0 ? void 0 : childPages.flatMap(function (page) {
|
|
91
|
+
return _utils.default.Validate.page(page);
|
|
92
|
+
})) || [];
|
|
93
|
+
// For each error we found, add the entryId so we know what Summary Card
|
|
94
|
+
// we have to pass it to.
|
|
95
|
+
var entryErrors = allPagesErrors.map(function (e) {
|
|
96
|
+
return _objectSpread(_objectSpread({}, e), {}, {
|
|
97
|
+
entryId: entry.id
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
allErrors = allErrors.concat(entryErrors);
|
|
67
101
|
});
|
|
68
|
-
|
|
69
|
-
|
|
102
|
+
// We only add allErrors if it's not empty to avoid
|
|
103
|
+
// triggering a race condition with the 'data' memo
|
|
104
|
+
// above.
|
|
105
|
+
if (allErrors.length > 0) {
|
|
106
|
+
addErrors(allErrors);
|
|
107
|
+
}
|
|
70
108
|
};
|
|
109
|
+
(0, _react.useEffect)(function () {
|
|
110
|
+
validateEntries();
|
|
111
|
+
}, [data]);
|
|
71
112
|
var onSummaryCardChange = function onSummaryCardChange(page, entryId) {
|
|
72
|
-
removeDuplicatedEntry(entryId);
|
|
73
113
|
if (typeof onAction !== 'function') {
|
|
74
114
|
return;
|
|
75
115
|
}
|
|
@@ -84,12 +124,7 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
84
124
|
};
|
|
85
125
|
var onDuplicate = function onDuplicate(entry) {
|
|
86
126
|
var _config$card;
|
|
87
|
-
|
|
88
|
-
if (newEntryId) {
|
|
89
|
-
var newData = [].concat(duplicatedEntries, [newEntryId]);
|
|
90
|
-
localStorage.setItem('duplicatedEntries', JSON.stringify(newData));
|
|
91
|
-
setDuplicatedEntries(newData);
|
|
92
|
-
}
|
|
127
|
+
_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) || []);
|
|
93
128
|
var parentCollection = config.collectionName.split('.').shift();
|
|
94
129
|
// Report the whole top-level collection as being changed. We have to do this
|
|
95
130
|
// because of how patch is applied to formData on a page submission.
|
|
@@ -100,6 +135,7 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
100
135
|
value: _utils.default.CollectionPage.getData(parentCollection, formData)
|
|
101
136
|
}
|
|
102
137
|
});
|
|
138
|
+
validateEntries();
|
|
103
139
|
}
|
|
104
140
|
};
|
|
105
141
|
var onDeleteConfirm = function onDeleteConfirm() {
|
|
@@ -119,6 +155,7 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
119
155
|
});
|
|
120
156
|
}
|
|
121
157
|
setEntryToDelete(null);
|
|
158
|
+
validateEntries();
|
|
122
159
|
};
|
|
123
160
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
124
161
|
id: config.fieldId
|
|
@@ -151,7 +188,10 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
151
188
|
onAction: onAction
|
|
152
189
|
}), data.map(function (entry, index) {
|
|
153
190
|
var key = "".concat(config.fieldId, ".summaryCard").concat(entry.id);
|
|
154
|
-
return /*#__PURE__*/_react.default.createElement(
|
|
191
|
+
return /*#__PURE__*/_react.default.createElement(_SummaryCardValidationContext.default, {
|
|
192
|
+
entryId: entry.id,
|
|
193
|
+
topLevelErrors: errors
|
|
194
|
+
}, /*#__PURE__*/_react.default.createElement(_SummaryCard.default, {
|
|
155
195
|
id: key,
|
|
156
196
|
key: key,
|
|
157
197
|
entryData: _objectSpread(_objectSpread({}, entry), {}, {
|
|
@@ -165,15 +205,17 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
165
205
|
return setEntryToDelete(entry);
|
|
166
206
|
},
|
|
167
207
|
pages: pages,
|
|
168
|
-
onQuickEdit: function onQuickEdit(target
|
|
169
|
-
|
|
170
|
-
onChange(target);
|
|
208
|
+
onQuickEdit: function onQuickEdit(target) {
|
|
209
|
+
validateEntries();
|
|
210
|
+
return onChange(target);
|
|
171
211
|
},
|
|
172
212
|
parentCollectionName: config.collectionName.split('.').shift(),
|
|
173
213
|
formData: formData,
|
|
174
214
|
classModifiers: entry === entryToDelete ? ['deleting-summary-card'] : [''],
|
|
175
|
-
|
|
176
|
-
|
|
215
|
+
inError: errors.filter(function (e) {
|
|
216
|
+
return e.entryId === entry.id;
|
|
217
|
+
}).length > 0
|
|
218
|
+
}));
|
|
177
219
|
}));
|
|
178
220
|
};
|
|
179
221
|
CollectionSummary.propTypes = {
|
|
@@ -4,6 +4,7 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
|
|
|
4
4
|
var _react = _interopRequireDefault(require("react"));
|
|
5
5
|
var _react2 = require("@testing-library/react");
|
|
6
6
|
var _setupTests = require("../../setupTests");
|
|
7
|
+
var _hooks = require("../../hooks");
|
|
7
8
|
var _CollectionSummary = _interopRequireWildcard(require("./CollectionSummary"));
|
|
8
9
|
var _Confirmation = require("./Confirmation");
|
|
9
10
|
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); }
|
|
@@ -28,11 +29,30 @@ describe('components.CollectionSummary.CollectionSummary', function () {
|
|
|
28
29
|
var FORM_DATA = {
|
|
29
30
|
testCollectionActiveId: '001',
|
|
30
31
|
testCollection: [{
|
|
31
|
-
id: '000'
|
|
32
|
+
id: '000',
|
|
33
|
+
testText: 'value'
|
|
32
34
|
}, {
|
|
33
35
|
id: '001'
|
|
34
36
|
}]
|
|
35
37
|
};
|
|
38
|
+
var PAGES = [{
|
|
39
|
+
id: 'testPage',
|
|
40
|
+
title: 'Test page',
|
|
41
|
+
collection: {
|
|
42
|
+
name: 'testCollection'
|
|
43
|
+
},
|
|
44
|
+
components: [{
|
|
45
|
+
id: 'testText',
|
|
46
|
+
fieldId: 'testText',
|
|
47
|
+
type: 'text',
|
|
48
|
+
required: true,
|
|
49
|
+
custom_errors: [{
|
|
50
|
+
type: 'required',
|
|
51
|
+
message: 'testText is required'
|
|
52
|
+
}]
|
|
53
|
+
}],
|
|
54
|
+
formData: FORM_DATA
|
|
55
|
+
}];
|
|
36
56
|
var ON_ACTION = function ON_ACTION() {};
|
|
37
57
|
var checkSetup = function checkSetup(container) {
|
|
38
58
|
var summaryDiv = container.children[0];
|
|
@@ -51,13 +71,32 @@ describe('components.CollectionSummary.CollectionSummary', function () {
|
|
|
51
71
|
expect(summary.children[0].id).toEqual("".concat(CONFIG.fieldId, ".summaryCard").concat(FORM_DATA.testCollection[0].id));
|
|
52
72
|
expect(summary.children[1].id).toEqual("".concat(CONFIG.fieldId, ".summaryCard").concat(FORM_DATA.testCollection[1].id));
|
|
53
73
|
});
|
|
74
|
+
it('should correctly raise errors found when validating entries', function () {
|
|
75
|
+
var ErrorCheckComponent = function ErrorCheckComponent() {
|
|
76
|
+
var _useValidation = (0, _hooks.useValidation)(),
|
|
77
|
+
errors = _useValidation.errors;
|
|
78
|
+
return /*#__PURE__*/_react.default.createElement("div", null, Array.isArray(errors) && "errors is an array of length ".concat(errors.length), (errors === null || errors === void 0 ? void 0 : errors.length) > 0 && errors.map(function (e) {
|
|
79
|
+
return e.error;
|
|
80
|
+
}));
|
|
81
|
+
};
|
|
82
|
+
var _renderWithValidation2 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(ErrorCheckComponent, null), /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
|
|
83
|
+
config: CONFIG,
|
|
84
|
+
formData: FORM_DATA,
|
|
85
|
+
onAction: ON_ACTION,
|
|
86
|
+
pages: PAGES
|
|
87
|
+
}))),
|
|
88
|
+
container = _renderWithValidation2.container;
|
|
89
|
+
var errorChecker = container.children[0];
|
|
90
|
+
expect(errorChecker.textContent).toContain('errors is an array of length 1');
|
|
91
|
+
expect(errorChecker.textContent).toContain('testText is required');
|
|
92
|
+
});
|
|
54
93
|
it('should render a confirmation when a SummaryCard\'s delete button is pressed', function () {
|
|
55
|
-
var
|
|
94
|
+
var _renderWithValidation3 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
|
|
56
95
|
config: CONFIG,
|
|
57
96
|
formData: FORM_DATA,
|
|
58
97
|
onAction: ON_ACTION
|
|
59
98
|
})),
|
|
60
|
-
container =
|
|
99
|
+
container = _renderWithValidation3.container;
|
|
61
100
|
var summary = checkSetup(container);
|
|
62
101
|
expect(summary.children.length).toEqual(2);
|
|
63
102
|
var card = summary.children[0];
|
|
@@ -81,12 +120,12 @@ describe('components.CollectionSummary.CollectionSummary', function () {
|
|
|
81
120
|
title: 'Title'
|
|
82
121
|
}
|
|
83
122
|
};
|
|
84
|
-
var
|
|
123
|
+
var _renderWithValidation4 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
|
|
85
124
|
config: CONFIG_WITH_BUTTON,
|
|
86
125
|
formData: FORM_DATA,
|
|
87
126
|
onAction: ON_ACTION
|
|
88
127
|
})),
|
|
89
|
-
container =
|
|
128
|
+
container = _renderWithValidation4.container;
|
|
90
129
|
var summary = checkSetup(container);
|
|
91
130
|
expect(summary.children.length).toEqual(3); // The button and a card for each item.
|
|
92
131
|
expect(summary.children[0].id).toEqual("".concat(CONFIG_WITH_BUTTON.fieldId, ".addButton"));
|
|
@@ -105,12 +144,12 @@ describe('components.CollectionSummary.CollectionSummary', function () {
|
|
|
105
144
|
title: 'Title'
|
|
106
145
|
}
|
|
107
146
|
};
|
|
108
|
-
var
|
|
147
|
+
var _renderWithValidation5 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
|
|
109
148
|
config: CONFIG_WITH_BUTTON,
|
|
110
149
|
formData: FORM_DATA,
|
|
111
150
|
onAction: ON_ACTION
|
|
112
151
|
})),
|
|
113
|
-
container =
|
|
152
|
+
container = _renderWithValidation5.container;
|
|
114
153
|
var summary = checkSetup(container);
|
|
115
154
|
expect(summary.children.length).toEqual(3); // The button and a card for each item.
|
|
116
155
|
expect(summary.children[0].id).toEqual("".concat(CONFIG_WITH_BUTTON.fieldId, ".addButton"));
|
|
@@ -118,12 +157,12 @@ describe('components.CollectionSummary.CollectionSummary', function () {
|
|
|
118
157
|
expect(summary.children[0].tagName).toEqual('BUTTON');
|
|
119
158
|
});
|
|
120
159
|
it('should apply the expected class name to the summary card when delete button is pressed', function () {
|
|
121
|
-
var
|
|
160
|
+
var _renderWithValidation6 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
|
|
122
161
|
config: CONFIG,
|
|
123
162
|
formData: FORM_DATA,
|
|
124
163
|
onAction: ON_ACTION
|
|
125
164
|
})),
|
|
126
|
-
container =
|
|
165
|
+
container = _renderWithValidation6.container;
|
|
127
166
|
var summary = checkSetup(container);
|
|
128
167
|
expect(summary.children.length).toEqual(2);
|
|
129
168
|
var card = summary.children[0];
|
|
@@ -134,12 +173,12 @@ describe('components.CollectionSummary.CollectionSummary', function () {
|
|
|
134
173
|
expect(card.className).toContain('deleting-summary-card');
|
|
135
174
|
});
|
|
136
175
|
it('should focus on the delete button in the confirmation panel', function () {
|
|
137
|
-
var
|
|
176
|
+
var _renderWithValidation7 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
|
|
138
177
|
config: CONFIG,
|
|
139
178
|
formData: FORM_DATA,
|
|
140
179
|
onAction: ON_ACTION
|
|
141
180
|
})),
|
|
142
|
-
container =
|
|
181
|
+
container = _renderWithValidation7.container;
|
|
143
182
|
var summary = checkSetup(container);
|
|
144
183
|
expect(summary.children.length).toEqual(2);
|
|
145
184
|
var card = summary.children[0];
|
|
@@ -150,12 +189,12 @@ describe('components.CollectionSummary.CollectionSummary', function () {
|
|
|
150
189
|
expect(document.activeElement).toEqual(confirmButton);
|
|
151
190
|
});
|
|
152
191
|
it('should have the role "alert" in the confirmation panel', function () {
|
|
153
|
-
var
|
|
192
|
+
var _renderWithValidation8 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
|
|
154
193
|
config: CONFIG,
|
|
155
194
|
formData: FORM_DATA,
|
|
156
195
|
onAction: ON_ACTION
|
|
157
196
|
})),
|
|
158
|
-
container =
|
|
197
|
+
container = _renderWithValidation8.container;
|
|
159
198
|
var summary = checkSetup(container);
|
|
160
199
|
expect(summary.children.length).toEqual(2);
|
|
161
200
|
var card = summary.children[0];
|
|
@@ -65,10 +65,14 @@ var SummaryCard = function SummaryCard(_ref) {
|
|
|
65
65
|
var classes = _copReactComponents.Utils.classBuilder(DEFAULT_CLASS, classModifiers, isDuplicated ? 'duplicated' : '');
|
|
66
66
|
var quickEditPage = (0, _react.useMemo)(function () {
|
|
67
67
|
return (0, _getQuickEditPage.default)(config.quickEdit, pages, entryData);
|
|
68
|
-
}, [pages, config, entryData]);
|
|
68
|
+
}, [pages, config, entryData, quickEdit]);
|
|
69
|
+
|
|
70
|
+
// The validation context used here is a custom one for Summary Cards,
|
|
71
|
+
// not the standard context. See SummaryCardValidationContext.jsx.
|
|
69
72
|
var _useValidation = (0, _hooks.useValidation)(),
|
|
70
|
-
|
|
71
|
-
|
|
73
|
+
addErrors = _useValidation.addErrors,
|
|
74
|
+
resetQuickEditErrors = _useValidation.resetQuickEditErrors,
|
|
75
|
+
validate = _useValidation.validate;
|
|
72
76
|
var _useHooks = (0, _hooks.useHooks)(),
|
|
73
77
|
hooks = _useHooks.hooks;
|
|
74
78
|
var _onAction = /*#__PURE__*/function () {
|
|
@@ -81,6 +85,7 @@ var SummaryCard = function SummaryCard(_ref) {
|
|
|
81
85
|
setQuickEdit(function (prevState) {
|
|
82
86
|
return !prevState;
|
|
83
87
|
});
|
|
88
|
+
resetQuickEditErrors === null || resetQuickEditErrors === void 0 || resetQuickEditErrors();
|
|
84
89
|
}
|
|
85
90
|
if (!(action.type === 'save' && typeof onQuickEdit === 'function' && Object.keys(patch).length)) {
|
|
86
91
|
_context.next = 10;
|
|
@@ -113,7 +118,7 @@ var SummaryCard = function SummaryCard(_ref) {
|
|
|
113
118
|
name: parentCollectionName,
|
|
114
119
|
value: allData
|
|
115
120
|
}
|
|
116
|
-
}
|
|
121
|
+
});
|
|
117
122
|
setQuickEdit(function (prevState) {
|
|
118
123
|
return !prevState;
|
|
119
124
|
});
|
|
@@ -8,15 +8,16 @@ var _testUtils = require("react-dom/test-utils");
|
|
|
8
8
|
var _setupTests = require("../../setupTests");
|
|
9
9
|
var _SummaryCard = _interopRequireWildcard(require("./SummaryCard"));
|
|
10
10
|
var _BannerStrip = require("./BannerStrip");
|
|
11
|
+
var _SummaryCardValidationContext = _interopRequireDefault(require("./SummaryCardValidationContext"));
|
|
11
12
|
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); }
|
|
12
13
|
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; }
|
|
13
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
15
15
|
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; }
|
|
16
16
|
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; }
|
|
17
17
|
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; }
|
|
18
18
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
19
19
|
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); }
|
|
20
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
20
21
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
21
22
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } // Global imports.
|
|
22
23
|
// Local imports.
|
|
@@ -679,6 +680,176 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
679
680
|
expect(headerActionDiv.children.length).toEqual(0);
|
|
680
681
|
});
|
|
681
682
|
});
|
|
683
|
+
describe('Quick Edit errors', function () {
|
|
684
|
+
var CUSTOM_ENTRY = {
|
|
685
|
+
id: '123',
|
|
686
|
+
testText: 'value'
|
|
687
|
+
};
|
|
688
|
+
var CONFIG = {
|
|
689
|
+
quickEdit: {
|
|
690
|
+
components: [{
|
|
691
|
+
use: 'testText'
|
|
692
|
+
}]
|
|
693
|
+
}
|
|
694
|
+
};
|
|
695
|
+
var PAGES = [{
|
|
696
|
+
id: 'parentPage',
|
|
697
|
+
name: 'parentPage',
|
|
698
|
+
components: [{
|
|
699
|
+
id: 'testText',
|
|
700
|
+
type: 'text',
|
|
701
|
+
label: 'Test text',
|
|
702
|
+
fieldId: 'testText',
|
|
703
|
+
required: true,
|
|
704
|
+
use: 'testText',
|
|
705
|
+
cya_label: 'Test text',
|
|
706
|
+
full_path: 'testText',
|
|
707
|
+
custom_errors: [{
|
|
708
|
+
type: 'required',
|
|
709
|
+
message: 'Custom error message'
|
|
710
|
+
}]
|
|
711
|
+
}],
|
|
712
|
+
formData: {
|
|
713
|
+
parents: [{
|
|
714
|
+
id: '123',
|
|
715
|
+
index: 0
|
|
716
|
+
}]
|
|
717
|
+
}
|
|
718
|
+
}];
|
|
719
|
+
it('should initally show errors passed in from top-level', function () {
|
|
720
|
+
var TOP_LEVEL_ERRORS = [{
|
|
721
|
+
id: 'testText',
|
|
722
|
+
entryId: '123',
|
|
723
|
+
error: 'top-level error message'
|
|
724
|
+
}];
|
|
725
|
+
var _renderWithValidation22 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCardValidationContext.default, {
|
|
726
|
+
entryId: CUSTOM_ENTRY.id,
|
|
727
|
+
topLevelErrors: TOP_LEVEL_ERRORS
|
|
728
|
+
}, /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
|
|
729
|
+
id: ID,
|
|
730
|
+
entryData: CUSTOM_ENTRY,
|
|
731
|
+
config: CONFIG,
|
|
732
|
+
pages: PAGES,
|
|
733
|
+
parentCollectionName: "parent",
|
|
734
|
+
formData: {},
|
|
735
|
+
masterPage: {
|
|
736
|
+
childPages: []
|
|
737
|
+
},
|
|
738
|
+
isDuplicated: true
|
|
739
|
+
}))),
|
|
740
|
+
container = _renderWithValidation22.container;
|
|
741
|
+
var _checkSetup21 = checkSetup(container),
|
|
742
|
+
headerActionDiv = _checkSetup21.headerActionDiv;
|
|
743
|
+
expect(headerActionDiv.children.length).toEqual(1);
|
|
744
|
+
|
|
745
|
+
// Shows edit button but no quick edit
|
|
746
|
+
var editButton = headerActionDiv.children[0];
|
|
747
|
+
expect(editButton.tagName).toEqual('BUTTON');
|
|
748
|
+
expect(editButton.textContent).toEqual('Quick Edit');
|
|
749
|
+
expect(container.childNodes[0].childNodes.length).toEqual(2); // Quick edit hidden
|
|
750
|
+
|
|
751
|
+
// shows quickedit once clicked
|
|
752
|
+
_react.fireEvent.click(editButton, {});
|
|
753
|
+
expect(container.childNodes[0].childNodes.length).toEqual(3); // Quick edit shown
|
|
754
|
+
var quickEdit = container.childNodes[0].childNodes[1];
|
|
755
|
+
expect(quickEdit.textContent).toContain('Test text');
|
|
756
|
+
|
|
757
|
+
// quick edit is showing top-level error
|
|
758
|
+
var errorSummary = quickEdit.childNodes[0];
|
|
759
|
+
expect(errorSummary.textContent).toContain(TOP_LEVEL_ERRORS[0].error);
|
|
760
|
+
});
|
|
761
|
+
it('should only show errors from validation when it happens, ignoring top-level errors', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
762
|
+
var TOP_LEVEL_ERRORS, _renderWithValidation23, container, _checkSetup22, headerActionDiv, editButton, quickEdit, errorSummary, component, componentInput, quickEditButtons, saveButton;
|
|
763
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
764
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
765
|
+
case 0:
|
|
766
|
+
TOP_LEVEL_ERRORS = [{
|
|
767
|
+
id: 'testText',
|
|
768
|
+
entryId: '123',
|
|
769
|
+
error: 'top-level error message'
|
|
770
|
+
}];
|
|
771
|
+
_renderWithValidation23 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCardValidationContext.default, {
|
|
772
|
+
entryId: CUSTOM_ENTRY.id,
|
|
773
|
+
topLevelErrors: TOP_LEVEL_ERRORS
|
|
774
|
+
}, /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
|
|
775
|
+
id: ID,
|
|
776
|
+
entryData: CUSTOM_ENTRY,
|
|
777
|
+
config: CONFIG,
|
|
778
|
+
pages: PAGES,
|
|
779
|
+
parentCollectionName: "parent",
|
|
780
|
+
formData: {},
|
|
781
|
+
masterPage: {
|
|
782
|
+
childPages: []
|
|
783
|
+
},
|
|
784
|
+
onQuickEdit: function onQuickEdit() {},
|
|
785
|
+
isDuplicated: true
|
|
786
|
+
}))), container = _renderWithValidation23.container;
|
|
787
|
+
_checkSetup22 = checkSetup(container), headerActionDiv = _checkSetup22.headerActionDiv;
|
|
788
|
+
expect(headerActionDiv.children.length).toEqual(1);
|
|
789
|
+
|
|
790
|
+
// Shows edit button but no quick edit
|
|
791
|
+
editButton = headerActionDiv.children[0];
|
|
792
|
+
expect(editButton.tagName).toEqual('BUTTON');
|
|
793
|
+
expect(editButton.textContent).toEqual('Quick Edit');
|
|
794
|
+
expect(container.childNodes[0].childNodes.length).toEqual(2); // Quick edit hidden
|
|
795
|
+
|
|
796
|
+
// shows quickedit once clicked
|
|
797
|
+
_react.fireEvent.click(editButton, {});
|
|
798
|
+
expect(container.childNodes[0].childNodes.length).toEqual(3); // Quick edit shown
|
|
799
|
+
quickEdit = container.childNodes[0].childNodes[1];
|
|
800
|
+
expect(quickEdit.textContent).toContain('Test text');
|
|
801
|
+
|
|
802
|
+
// quick edit is initially showing top-level error
|
|
803
|
+
errorSummary = quickEdit.childNodes[0];
|
|
804
|
+
expect(errorSummary.textContent).toContain(TOP_LEVEL_ERRORS[0].error);
|
|
805
|
+
|
|
806
|
+
// remove value from required text component
|
|
807
|
+
component = quickEdit.childNodes[2];
|
|
808
|
+
componentInput = component.childNodes[3];
|
|
809
|
+
_context3.next = 18;
|
|
810
|
+
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
811
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
812
|
+
while (1) switch (_context.prev = _context.next) {
|
|
813
|
+
case 0:
|
|
814
|
+
_react.fireEvent.change(componentInput, {
|
|
815
|
+
target: {
|
|
816
|
+
value: ''
|
|
817
|
+
}
|
|
818
|
+
});
|
|
819
|
+
case 1:
|
|
820
|
+
case "end":
|
|
821
|
+
return _context.stop();
|
|
822
|
+
}
|
|
823
|
+
}, _callee);
|
|
824
|
+
})));
|
|
825
|
+
case 18:
|
|
826
|
+
// click 'save' to trigger validation, which will fail as the component
|
|
827
|
+
// cleared above is marked as 'required'.
|
|
828
|
+
quickEditButtons = quickEdit.childNodes[3];
|
|
829
|
+
saveButton = quickEditButtons.childNodes[0];
|
|
830
|
+
expect(saveButton.textContent).toContain('Save');
|
|
831
|
+
_context3.next = 23;
|
|
832
|
+
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
833
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
834
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
835
|
+
case 0:
|
|
836
|
+
_react.fireEvent.click(saveButton, {});
|
|
837
|
+
case 1:
|
|
838
|
+
case "end":
|
|
839
|
+
return _context2.stop();
|
|
840
|
+
}
|
|
841
|
+
}, _callee2);
|
|
842
|
+
})));
|
|
843
|
+
case 23:
|
|
844
|
+
// quick edit should now be showing the errors from validation
|
|
845
|
+
expect(errorSummary.textContent).toContain('Custom error message');
|
|
846
|
+
case 24:
|
|
847
|
+
case "end":
|
|
848
|
+
return _context3.stop();
|
|
849
|
+
}
|
|
850
|
+
}, _callee3);
|
|
851
|
+
})));
|
|
852
|
+
});
|
|
682
853
|
describe('Quick Edit save changes', function () {
|
|
683
854
|
var CONFIG = {
|
|
684
855
|
quickEdit: {
|
|
@@ -715,7 +886,7 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
715
886
|
}
|
|
716
887
|
}];
|
|
717
888
|
it('should render correctly', function () {
|
|
718
|
-
var
|
|
889
|
+
var _renderWithValidation24 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
|
|
719
890
|
id: ID,
|
|
720
891
|
entryData: ENTRY,
|
|
721
892
|
config: CONFIG,
|
|
@@ -727,9 +898,9 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
727
898
|
},
|
|
728
899
|
isDuplicated: true
|
|
729
900
|
})),
|
|
730
|
-
container =
|
|
731
|
-
var
|
|
732
|
-
headerActionDiv =
|
|
901
|
+
container = _renderWithValidation24.container;
|
|
902
|
+
var _checkSetup23 = checkSetup(container),
|
|
903
|
+
headerActionDiv = _checkSetup23.headerActionDiv;
|
|
733
904
|
expect(headerActionDiv.children.length).toEqual(1);
|
|
734
905
|
|
|
735
906
|
// Shows edit button but no quick edit
|
|
@@ -763,7 +934,7 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
763
934
|
return ON_SUBMIT_CALLS.push(patch);
|
|
764
935
|
}
|
|
765
936
|
};
|
|
766
|
-
var
|
|
937
|
+
var _renderWithValidation25 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
|
|
767
938
|
id: ID,
|
|
768
939
|
entryData: ENTRY,
|
|
769
940
|
config: CONFIG,
|
|
@@ -777,9 +948,9 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
777
948
|
}), {
|
|
778
949
|
hooks: hooks
|
|
779
950
|
}),
|
|
780
|
-
container =
|
|
781
|
-
var
|
|
782
|
-
headerActionDiv =
|
|
951
|
+
container = _renderWithValidation25.container;
|
|
952
|
+
var _checkSetup24 = checkSetup(container),
|
|
953
|
+
headerActionDiv = _checkSetup24.headerActionDiv;
|
|
783
954
|
|
|
784
955
|
// Shows edit button but no quick edit
|
|
785
956
|
var editButton = headerActionDiv.children[0];
|
|
@@ -792,10 +963,10 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
792
963
|
_react.fireEvent.click(saveButton, {});
|
|
793
964
|
expect(ON_SUBMIT_CALLS.length).toEqual(0);
|
|
794
965
|
});
|
|
795
|
-
it('should return after local validation if errors are present', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
796
|
-
var ON_SUBMIT_CALLS, hooks, ON_QUICK_EDIT_CALLS, ON_QUICK_EDIT,
|
|
797
|
-
return _regeneratorRuntime().wrap(function
|
|
798
|
-
while (1) switch (
|
|
966
|
+
it('should return after local validation if errors are present', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
967
|
+
var ON_SUBMIT_CALLS, hooks, ON_QUICK_EDIT_CALLS, ON_QUICK_EDIT, _renderWithValidation26, container, _checkSetup25, headerActionDiv, editButton, quickEdit, component, componentInput, quickEditButtons, saveButton;
|
|
968
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
969
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
799
970
|
case 0:
|
|
800
971
|
ON_SUBMIT_CALLS = [];
|
|
801
972
|
hooks = {
|
|
@@ -804,11 +975,11 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
804
975
|
}
|
|
805
976
|
};
|
|
806
977
|
ON_QUICK_EDIT_CALLS = [];
|
|
807
|
-
ON_QUICK_EDIT = function ON_QUICK_EDIT(
|
|
808
|
-
var target =
|
|
978
|
+
ON_QUICK_EDIT = function ON_QUICK_EDIT(_ref5) {
|
|
979
|
+
var target = _ref5.target;
|
|
809
980
|
ON_QUICK_EDIT_CALLS.push(target);
|
|
810
981
|
};
|
|
811
|
-
|
|
982
|
+
_renderWithValidation26 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
|
|
812
983
|
id: ID,
|
|
813
984
|
entryData: _objectSpread(_objectSpread({}, ENTRY), {}, {
|
|
814
985
|
index: 0
|
|
@@ -828,8 +999,8 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
828
999
|
isDuplicated: true
|
|
829
1000
|
}), {
|
|
830
1001
|
hooks: hooks
|
|
831
|
-
}), container =
|
|
832
|
-
|
|
1002
|
+
}), container = _renderWithValidation26.container;
|
|
1003
|
+
_checkSetup25 = checkSetup(container), headerActionDiv = _checkSetup25.headerActionDiv;
|
|
833
1004
|
editButton = headerActionDiv.children[0];
|
|
834
1005
|
_react.fireEvent.click(editButton, {});
|
|
835
1006
|
quickEdit = container.childNodes[0].childNodes[1];
|
|
@@ -837,10 +1008,10 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
837
1008
|
componentInput = component.childNodes[2];
|
|
838
1009
|
quickEditButtons = quickEdit.childNodes[2];
|
|
839
1010
|
saveButton = quickEditButtons.childNodes[0]; // Field has validation to force the length of this field to be greater than 2 so this should fail
|
|
840
|
-
|
|
841
|
-
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
842
|
-
return _regeneratorRuntime().wrap(function
|
|
843
|
-
while (1) switch (
|
|
1011
|
+
_context6.next = 15;
|
|
1012
|
+
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
1013
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
1014
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
844
1015
|
case 0:
|
|
845
1016
|
_react.fireEvent.change(componentInput, {
|
|
846
1017
|
target: {
|
|
@@ -849,36 +1020,36 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
849
1020
|
});
|
|
850
1021
|
case 1:
|
|
851
1022
|
case "end":
|
|
852
|
-
return
|
|
1023
|
+
return _context4.stop();
|
|
853
1024
|
}
|
|
854
|
-
},
|
|
1025
|
+
}, _callee4);
|
|
855
1026
|
})));
|
|
856
1027
|
case 15:
|
|
857
|
-
|
|
858
|
-
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
859
|
-
return _regeneratorRuntime().wrap(function
|
|
860
|
-
while (1) switch (
|
|
1028
|
+
_context6.next = 17;
|
|
1029
|
+
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
1030
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
1031
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
861
1032
|
case 0:
|
|
862
1033
|
_react.fireEvent.click(saveButton, {});
|
|
863
1034
|
case 1:
|
|
864
1035
|
case "end":
|
|
865
|
-
return
|
|
1036
|
+
return _context5.stop();
|
|
866
1037
|
}
|
|
867
|
-
},
|
|
1038
|
+
}, _callee5);
|
|
868
1039
|
})));
|
|
869
1040
|
case 17:
|
|
870
1041
|
expect(ON_SUBMIT_CALLS.length).toEqual(0);
|
|
871
1042
|
expect(ON_QUICK_EDIT_CALLS.length).toEqual(0);
|
|
872
1043
|
case 19:
|
|
873
1044
|
case "end":
|
|
874
|
-
return
|
|
1045
|
+
return _context6.stop();
|
|
875
1046
|
}
|
|
876
|
-
},
|
|
1047
|
+
}, _callee6);
|
|
877
1048
|
})));
|
|
878
|
-
it('should run hook validation when a value changes and local validation is passed', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
879
|
-
var ON_SUBMIT_CALLS, hooks, ON_QUICK_EDIT_CALLS, ON_QUICK_EDIT,
|
|
880
|
-
return _regeneratorRuntime().wrap(function
|
|
881
|
-
while (1) switch (
|
|
1049
|
+
it('should run hook validation when a value changes and local validation is passed', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
|
1050
|
+
var ON_SUBMIT_CALLS, hooks, ON_QUICK_EDIT_CALLS, ON_QUICK_EDIT, _renderWithValidation27, container, _checkSetup26, headerActionDiv, editButton, quickEdit, component, componentInput, quickEditButtons, saveButton;
|
|
1051
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
1052
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
882
1053
|
case 0:
|
|
883
1054
|
ON_SUBMIT_CALLS = [];
|
|
884
1055
|
hooks = {
|
|
@@ -891,11 +1062,11 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
891
1062
|
}
|
|
892
1063
|
};
|
|
893
1064
|
ON_QUICK_EDIT_CALLS = [];
|
|
894
|
-
ON_QUICK_EDIT = function ON_QUICK_EDIT(
|
|
895
|
-
var target =
|
|
1065
|
+
ON_QUICK_EDIT = function ON_QUICK_EDIT(_ref9) {
|
|
1066
|
+
var target = _ref9.target;
|
|
896
1067
|
ON_QUICK_EDIT_CALLS.push(target);
|
|
897
1068
|
};
|
|
898
|
-
|
|
1069
|
+
_renderWithValidation27 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
|
|
899
1070
|
id: ID,
|
|
900
1071
|
entryData: ENTRY,
|
|
901
1072
|
config: CONFIG,
|
|
@@ -913,8 +1084,8 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
913
1084
|
isDuplicated: true
|
|
914
1085
|
}), {
|
|
915
1086
|
hooks: hooks
|
|
916
|
-
}), container =
|
|
917
|
-
|
|
1087
|
+
}), container = _renderWithValidation27.container;
|
|
1088
|
+
_checkSetup26 = checkSetup(container), headerActionDiv = _checkSetup26.headerActionDiv;
|
|
918
1089
|
editButton = headerActionDiv.children[0];
|
|
919
1090
|
_react.fireEvent.click(editButton, {});
|
|
920
1091
|
quickEdit = container.childNodes[0].childNodes[1]; // Make a change
|
|
@@ -927,17 +1098,17 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
927
1098
|
});
|
|
928
1099
|
quickEditButtons = quickEdit.childNodes[2];
|
|
929
1100
|
saveButton = quickEditButtons.childNodes[0];
|
|
930
|
-
|
|
931
|
-
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
932
|
-
return _regeneratorRuntime().wrap(function
|
|
933
|
-
while (1) switch (
|
|
1101
|
+
_context8.next = 16;
|
|
1102
|
+
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
1103
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
1104
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
934
1105
|
case 0:
|
|
935
1106
|
_react.fireEvent.click(saveButton, {});
|
|
936
1107
|
case 1:
|
|
937
1108
|
case "end":
|
|
938
|
-
return
|
|
1109
|
+
return _context7.stop();
|
|
939
1110
|
}
|
|
940
|
-
},
|
|
1111
|
+
}, _callee7);
|
|
941
1112
|
})));
|
|
942
1113
|
case 16:
|
|
943
1114
|
expect(ON_SUBMIT_CALLS[0]).toEqual({
|
|
@@ -946,14 +1117,14 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
946
1117
|
expect(ON_QUICK_EDIT_CALLS.length).toEqual(0);
|
|
947
1118
|
case 18:
|
|
948
1119
|
case "end":
|
|
949
|
-
return
|
|
1120
|
+
return _context8.stop();
|
|
950
1121
|
}
|
|
951
|
-
},
|
|
1122
|
+
}, _callee8);
|
|
952
1123
|
})));
|
|
953
|
-
it('should apply changes if no errors are present', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
954
|
-
var isDuplicatedValue, ON_SUBMIT_CALLS, hooks, ON_QUICK_EDIT_CALLS, ON_QUICK_EDIT,
|
|
955
|
-
return _regeneratorRuntime().wrap(function
|
|
956
|
-
while (1) switch (
|
|
1124
|
+
it('should apply changes if no errors are present', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
|
|
1125
|
+
var isDuplicatedValue, ON_SUBMIT_CALLS, hooks, ON_QUICK_EDIT_CALLS, ON_QUICK_EDIT, _renderWithValidation28, container, _checkSetup27, headerActionDiv, editButton, quickEdit, component, componentInput, quickEditButtons, saveButton;
|
|
1126
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
1127
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
957
1128
|
case 0:
|
|
958
1129
|
isDuplicatedValue = true;
|
|
959
1130
|
ON_SUBMIT_CALLS = [];
|
|
@@ -963,12 +1134,12 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
963
1134
|
}
|
|
964
1135
|
};
|
|
965
1136
|
ON_QUICK_EDIT_CALLS = [];
|
|
966
|
-
ON_QUICK_EDIT = function ON_QUICK_EDIT(
|
|
967
|
-
var target =
|
|
1137
|
+
ON_QUICK_EDIT = function ON_QUICK_EDIT(_ref12) {
|
|
1138
|
+
var target = _ref12.target;
|
|
968
1139
|
ON_QUICK_EDIT_CALLS.push(target);
|
|
969
1140
|
isDuplicatedValue = false;
|
|
970
1141
|
};
|
|
971
|
-
|
|
1142
|
+
_renderWithValidation28 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
|
|
972
1143
|
id: ID,
|
|
973
1144
|
entryData: {
|
|
974
1145
|
index: 0,
|
|
@@ -989,8 +1160,8 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
989
1160
|
isDuplicated: isDuplicatedValue
|
|
990
1161
|
}), {
|
|
991
1162
|
hooks: hooks
|
|
992
|
-
}), container =
|
|
993
|
-
|
|
1163
|
+
}), container = _renderWithValidation28.container;
|
|
1164
|
+
_checkSetup27 = checkSetup(container), headerActionDiv = _checkSetup27.headerActionDiv;
|
|
994
1165
|
editButton = headerActionDiv.children[0];
|
|
995
1166
|
_react.fireEvent.click(editButton, {});
|
|
996
1167
|
quickEdit = container.childNodes[0].childNodes[1]; // Make a change that will be accepted
|
|
@@ -1003,17 +1174,17 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
1003
1174
|
});
|
|
1004
1175
|
quickEditButtons = quickEdit.childNodes[2];
|
|
1005
1176
|
saveButton = quickEditButtons.childNodes[0];
|
|
1006
|
-
|
|
1007
|
-
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1008
|
-
return _regeneratorRuntime().wrap(function
|
|
1009
|
-
while (1) switch (
|
|
1177
|
+
_context10.next = 17;
|
|
1178
|
+
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
|
|
1179
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
1180
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
1010
1181
|
case 0:
|
|
1011
1182
|
_react.fireEvent.click(saveButton, {});
|
|
1012
1183
|
case 1:
|
|
1013
1184
|
case "end":
|
|
1014
|
-
return
|
|
1185
|
+
return _context9.stop();
|
|
1015
1186
|
}
|
|
1016
|
-
},
|
|
1187
|
+
}, _callee9);
|
|
1017
1188
|
})));
|
|
1018
1189
|
case 17:
|
|
1019
1190
|
expect(ON_QUICK_EDIT_CALLS.length).toEqual(1);
|
|
@@ -1026,9 +1197,9 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
1026
1197
|
expect(isDuplicatedValue).toBe(false);
|
|
1027
1198
|
case 20:
|
|
1028
1199
|
case "end":
|
|
1029
|
-
return
|
|
1200
|
+
return _context10.stop();
|
|
1030
1201
|
}
|
|
1031
|
-
},
|
|
1202
|
+
}, _callee10);
|
|
1032
1203
|
})));
|
|
1033
1204
|
});
|
|
1034
1205
|
describe('Details prop behavior', function () {
|
|
@@ -1038,7 +1209,7 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
1038
1209
|
title: 'Title',
|
|
1039
1210
|
details: DETAILS
|
|
1040
1211
|
};
|
|
1041
|
-
var
|
|
1212
|
+
var _renderWithValidation29 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
|
|
1042
1213
|
id: ID,
|
|
1043
1214
|
entryData: ENTRY,
|
|
1044
1215
|
config: CONFIG,
|
|
@@ -1049,9 +1220,9 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
1049
1220
|
childPages: []
|
|
1050
1221
|
}
|
|
1051
1222
|
})),
|
|
1052
|
-
container =
|
|
1053
|
-
var
|
|
1054
|
-
headerContentDiv =
|
|
1223
|
+
container = _renderWithValidation29.container;
|
|
1224
|
+
var _checkSetup28 = checkSetup(container),
|
|
1225
|
+
headerContentDiv = _checkSetup28.headerContentDiv;
|
|
1055
1226
|
var headerDetails = headerContentDiv.children[1];
|
|
1056
1227
|
expect(headerDetails.tagName).toEqual('DIV');
|
|
1057
1228
|
expect(headerDetails.classList).toContain(classes('header-content-detail'));
|
|
@@ -1062,7 +1233,7 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
1062
1233
|
title: 'Title',
|
|
1063
1234
|
details: ''
|
|
1064
1235
|
};
|
|
1065
|
-
var
|
|
1236
|
+
var _renderWithValidation30 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
|
|
1066
1237
|
id: ID,
|
|
1067
1238
|
entryData: ENTRY,
|
|
1068
1239
|
config: CONFIG,
|
|
@@ -1073,9 +1244,9 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
1073
1244
|
childPages: []
|
|
1074
1245
|
}
|
|
1075
1246
|
})),
|
|
1076
|
-
container =
|
|
1077
|
-
var
|
|
1078
|
-
headerContentDiv =
|
|
1247
|
+
container = _renderWithValidation30.container;
|
|
1248
|
+
var _checkSetup29 = checkSetup(container),
|
|
1249
|
+
headerContentDiv = _checkSetup29.headerContentDiv;
|
|
1079
1250
|
// If no details are provided, we expect only the header title to be rendered.
|
|
1080
1251
|
expect(headerContentDiv.children.length).toEqual(1);
|
|
1081
1252
|
var headerTitle = headerContentDiv.children[0];
|
|
@@ -1090,7 +1261,7 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
1090
1261
|
title: 'Title',
|
|
1091
1262
|
details: DETAILS
|
|
1092
1263
|
};
|
|
1093
|
-
var
|
|
1264
|
+
var _renderWithValidation31 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
|
|
1094
1265
|
id: ID,
|
|
1095
1266
|
entryData: INTERPOLATED_ENTRY,
|
|
1096
1267
|
config: CONFIG,
|
|
@@ -1101,9 +1272,9 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
1101
1272
|
childPages: []
|
|
1102
1273
|
}
|
|
1103
1274
|
})),
|
|
1104
|
-
container =
|
|
1105
|
-
var
|
|
1106
|
-
headerContentDiv =
|
|
1275
|
+
container = _renderWithValidation31.container;
|
|
1276
|
+
var _checkSetup30 = checkSetup(container),
|
|
1277
|
+
headerContentDiv = _checkSetup30.headerContentDiv;
|
|
1107
1278
|
var headerDetails = headerContentDiv.children[1];
|
|
1108
1279
|
var expectedInterpolatedString = _copReactComponents.Utils.interpolateString(DETAILS, INTERPOLATED_ENTRY);
|
|
1109
1280
|
expect(headerDetails.textContent).toEqual(expectedInterpolatedString);
|
|
@@ -1112,7 +1283,7 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
1112
1283
|
var CONFIG = {
|
|
1113
1284
|
title: 'Title'
|
|
1114
1285
|
};
|
|
1115
|
-
var
|
|
1286
|
+
var _renderWithValidation32 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
|
|
1116
1287
|
id: ID,
|
|
1117
1288
|
entryData: ENTRY,
|
|
1118
1289
|
config: CONFIG,
|
|
@@ -1123,9 +1294,9 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
1123
1294
|
childPages: []
|
|
1124
1295
|
}
|
|
1125
1296
|
})),
|
|
1126
|
-
container =
|
|
1127
|
-
var
|
|
1128
|
-
headerContentDiv =
|
|
1297
|
+
container = _renderWithValidation32.container;
|
|
1298
|
+
var _checkSetup31 = checkSetup(container),
|
|
1299
|
+
headerContentDiv = _checkSetup31.headerContentDiv;
|
|
1129
1300
|
var headerDetails = headerContentDiv.querySelector("#".concat(ID, ".titleDetail"));
|
|
1130
1301
|
expect(headerDetails).toBeNull();
|
|
1131
1302
|
});
|
|
@@ -1135,7 +1306,7 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
1135
1306
|
title: 'Title',
|
|
1136
1307
|
details: DETAILS
|
|
1137
1308
|
};
|
|
1138
|
-
var
|
|
1309
|
+
var _renderWithValidation33 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
|
|
1139
1310
|
id: ID,
|
|
1140
1311
|
entryData: ENTRY,
|
|
1141
1312
|
config: CONFIG,
|
|
@@ -1147,7 +1318,7 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
1147
1318
|
childPages: []
|
|
1148
1319
|
}
|
|
1149
1320
|
})),
|
|
1150
|
-
container =
|
|
1321
|
+
container = _renderWithValidation33.container;
|
|
1151
1322
|
var detailsComponent = container.querySelector('.details');
|
|
1152
1323
|
expect(detailsComponent).toBeNull();
|
|
1153
1324
|
});
|
|
@@ -1177,7 +1348,7 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
1177
1348
|
var CONFIG = {
|
|
1178
1349
|
title: 'Title'
|
|
1179
1350
|
};
|
|
1180
|
-
var
|
|
1351
|
+
var _renderWithValidation34 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
|
|
1181
1352
|
id: ID,
|
|
1182
1353
|
entryData: ENTRY,
|
|
1183
1354
|
config: CONFIG,
|
|
@@ -1188,7 +1359,7 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
1188
1359
|
childPages: []
|
|
1189
1360
|
}
|
|
1190
1361
|
})),
|
|
1191
|
-
container =
|
|
1362
|
+
container = _renderWithValidation34.container;
|
|
1192
1363
|
|
|
1193
1364
|
// Function to find an element by its text content
|
|
1194
1365
|
function getByTextContent(parent, text) {
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
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
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
10
|
+
var _utils = _interopRequireDefault(require("../../utils"));
|
|
11
|
+
var _ValidationContext = require("../../context/ValidationContext");
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
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); }
|
|
14
|
+
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; }
|
|
15
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
16
|
+
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."); }
|
|
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
|
+
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; }
|
|
19
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
20
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } /* eslint-disable react/jsx-no-constructed-context-values, no-shadow */ // Global imports
|
|
21
|
+
// Local imports
|
|
22
|
+
var SummaryCardValidationContextProvider = function SummaryCardValidationContextProvider(_ref) {
|
|
23
|
+
var entryId = _ref.entryId,
|
|
24
|
+
topLevelErrors = _ref.topLevelErrors,
|
|
25
|
+
children = _ref.children;
|
|
26
|
+
// Errors raised from the Collection Summary.
|
|
27
|
+
var initialErrors = topLevelErrors.filter(function (e) {
|
|
28
|
+
return e.entryId === entryId;
|
|
29
|
+
}) || [];
|
|
30
|
+
// Errors raised locally, via the Quick Edit page.
|
|
31
|
+
var _useState = (0, _react.useState)(null),
|
|
32
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
33
|
+
errors = _useState2[0],
|
|
34
|
+
setErrors = _useState2[1];
|
|
35
|
+
var resetQuickEditErrors = function resetQuickEditErrors() {
|
|
36
|
+
// By setting errors to 'null' here we go back to using
|
|
37
|
+
// whatever topLevelErrors are passed in for us.
|
|
38
|
+
setErrors(null);
|
|
39
|
+
};
|
|
40
|
+
var addErrors = function addErrors(addedErrors) {
|
|
41
|
+
var newErrors = errors !== null && errors !== void 0 ? errors : [];
|
|
42
|
+
setErrors(newErrors.concat(addedErrors));
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// This validate is only used by the Quick Edit page
|
|
46
|
+
// on the Summary Card.
|
|
47
|
+
var validate = {
|
|
48
|
+
page: function page(_page) {
|
|
49
|
+
var pageErrors = _utils.default.Validate.page(_page);
|
|
50
|
+
setErrors(pageErrors);
|
|
51
|
+
return pageErrors;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
return /*#__PURE__*/_react.default.createElement(_ValidationContext.ValidationContext.Provider, {
|
|
55
|
+
value: {
|
|
56
|
+
addErrors: addErrors,
|
|
57
|
+
errors: errors === null ? [].concat(initialErrors) : errors,
|
|
58
|
+
resetQuickEditErrors: resetQuickEditErrors,
|
|
59
|
+
validate: validate
|
|
60
|
+
}
|
|
61
|
+
}, children);
|
|
62
|
+
};
|
|
63
|
+
var _default = exports.default = SummaryCardValidationContextProvider;
|
|
64
|
+
SummaryCardValidationContextProvider.propTypes = {
|
|
65
|
+
entryId: _propTypes.default.string.isRequired,
|
|
66
|
+
topLevelErrors: _propTypes.default.arrayOf(_propTypes.default.shape({})),
|
|
67
|
+
children: _propTypes.default.node
|
|
68
|
+
};
|
|
69
|
+
SummaryCardValidationContextProvider.defaultProps = {
|
|
70
|
+
topLevelErrors: [],
|
|
71
|
+
children: null
|
|
72
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
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
|
+
var _react = require("@testing-library/react");
|
|
5
|
+
var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
6
|
+
var _react2 = _interopRequireWildcard(require("react"));
|
|
7
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
8
|
+
var _hooks = require("../../hooks");
|
|
9
|
+
var _SummaryCardValidationContext = _interopRequireDefault(require("./SummaryCardValidationContext"));
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
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); }
|
|
12
|
+
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; }
|
|
13
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
14
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
15
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } // Global imports
|
|
16
|
+
// Local imports
|
|
17
|
+
var TestComponent = function TestComponent(_ref) {
|
|
18
|
+
var customErrors = _ref.customErrors;
|
|
19
|
+
var _useValidation = (0, _hooks.useValidation)(),
|
|
20
|
+
addErrors = _useValidation.addErrors,
|
|
21
|
+
errors = _useValidation.errors,
|
|
22
|
+
resetQuickEditErrors = _useValidation.resetQuickEditErrors,
|
|
23
|
+
validate = _useValidation.validate;
|
|
24
|
+
(0, _react2.useEffect)(function () {
|
|
25
|
+
if (customErrors) {
|
|
26
|
+
addErrors(customErrors);
|
|
27
|
+
}
|
|
28
|
+
}, [customErrors]);
|
|
29
|
+
return /*#__PURE__*/_react2.default.createElement(_react2.default.Fragment, null, typeof addErrors === 'function' && /*#__PURE__*/_react2.default.createElement("span", null, "addErrors is a function"), typeof resetQuickEditErrors === 'function' && /*#__PURE__*/_react2.default.createElement("span", null, "resetQuickEditErrors is a function"), typeof validate.page === 'function' && /*#__PURE__*/_react2.default.createElement("span", null, "validate.page is a function"), Array.isArray(errors) && /*#__PURE__*/_react2.default.createElement("span", null, "errors is an array of length ", errors.length), (errors === null || errors === void 0 ? void 0 : errors.length) > 0 && /*#__PURE__*/_react2.default.createElement(_copReactComponents.ErrorSummary, {
|
|
30
|
+
errors: errors
|
|
31
|
+
}));
|
|
32
|
+
};
|
|
33
|
+
describe('context.SummaryCardValidationContext', function () {
|
|
34
|
+
it('should appropriately set up the context', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
35
|
+
var _render, container;
|
|
36
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
37
|
+
while (1) switch (_context.prev = _context.next) {
|
|
38
|
+
case 0:
|
|
39
|
+
_render = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_SummaryCardValidationContext.default, {
|
|
40
|
+
entryId: "123",
|
|
41
|
+
topLevelErrors: []
|
|
42
|
+
}, /*#__PURE__*/_react2.default.createElement(TestComponent, null))), container = _render.container;
|
|
43
|
+
expect(container.childNodes.length).toEqual(4);
|
|
44
|
+
expect(container.textContent).toContain('addErrors is a function');
|
|
45
|
+
expect(container.textContent).toContain('resetQuickEditErrors is a function');
|
|
46
|
+
expect(container.textContent).toContain('validate.page is a function');
|
|
47
|
+
expect(container.textContent).toContain('errors is an array of length 0');
|
|
48
|
+
case 6:
|
|
49
|
+
case "end":
|
|
50
|
+
return _context.stop();
|
|
51
|
+
}
|
|
52
|
+
}, _callee);
|
|
53
|
+
})));
|
|
54
|
+
it('should correctly filter out top-level errors not for this card', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
55
|
+
var TOP_LEVEL_ERRORS, _render2, container;
|
|
56
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
57
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
58
|
+
case 0:
|
|
59
|
+
TOP_LEVEL_ERRORS = [{
|
|
60
|
+
id: 'testid',
|
|
61
|
+
entryId: '123',
|
|
62
|
+
error: 'error message one'
|
|
63
|
+
}, {
|
|
64
|
+
id: 'testid',
|
|
65
|
+
entryId: '456',
|
|
66
|
+
error: 'error message two'
|
|
67
|
+
}, {
|
|
68
|
+
id: 'testid',
|
|
69
|
+
entryId: '123',
|
|
70
|
+
error: 'error message three'
|
|
71
|
+
}, {
|
|
72
|
+
id: 'testid',
|
|
73
|
+
error: 'error message four'
|
|
74
|
+
}];
|
|
75
|
+
_render2 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_SummaryCardValidationContext.default, {
|
|
76
|
+
entryId: "123",
|
|
77
|
+
topLevelErrors: TOP_LEVEL_ERRORS
|
|
78
|
+
}, /*#__PURE__*/_react2.default.createElement(TestComponent, null))), container = _render2.container;
|
|
79
|
+
expect(container.childNodes.length).toEqual(5);
|
|
80
|
+
expect(container.textContent).toContain('addErrors is a function');
|
|
81
|
+
expect(container.textContent).toContain('resetQuickEditErrors is a function');
|
|
82
|
+
expect(container.textContent).toContain('validate.page is a function');
|
|
83
|
+
expect(container.textContent).toContain('errors is an array of length 2');
|
|
84
|
+
expect(container.textContent).toContain('error message one');
|
|
85
|
+
expect(container.textContent).toContain('error message three');
|
|
86
|
+
case 9:
|
|
87
|
+
case "end":
|
|
88
|
+
return _context2.stop();
|
|
89
|
+
}
|
|
90
|
+
}, _callee2);
|
|
91
|
+
})));
|
|
92
|
+
});
|
|
93
|
+
TestComponent.propTypes = {
|
|
94
|
+
customErrors: _propTypes.default.arrayOf(_propTypes.default.shape({}))
|
|
95
|
+
};
|
|
96
|
+
TestComponent.defaultProps = {
|
|
97
|
+
customErrors: null
|
|
98
|
+
};
|
|
@@ -9,7 +9,6 @@ var _getNextPageId = _interopRequireDefault(require("./getNextPageId"));
|
|
|
9
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
10
|
var getSubmissionStatus = function getSubmissionStatus(formType, pages, currentPageId, action, formData, currentTask, isCompleted, sections) {
|
|
11
11
|
if (formType === _models.FormTypes.TASK || formType === _models.FormTypes.FORM_WITH_TASK) {
|
|
12
|
-
var _currentTask$pages;
|
|
13
12
|
var formStatus = formData.formStatus || {};
|
|
14
13
|
formStatus.tasks = formStatus.tasks || {};
|
|
15
14
|
formStatus.tasks[currentTask.name] = formStatus.tasks[currentTask.name] || {};
|
|
@@ -43,7 +42,7 @@ var getSubmissionStatus = function getSubmissionStatus(formType, pages, currentP
|
|
|
43
42
|
complete: false,
|
|
44
43
|
currentPage: (0, _getNextPageId.default)(formType, pages, currentPageId, action, formData)
|
|
45
44
|
};
|
|
46
|
-
} else
|
|
45
|
+
} else {
|
|
47
46
|
formStatus.tasks[currentTask.name] = {
|
|
48
47
|
complete: !!(action !== null && action !== void 0 && action.complete),
|
|
49
48
|
currentPage: currentPageId
|
|
@@ -275,26 +275,6 @@ describe('components', function () {
|
|
|
275
275
|
})
|
|
276
276
|
});
|
|
277
277
|
});
|
|
278
|
-
it('should not update the current task state if the current page does not belong in the task', function () {
|
|
279
|
-
var CUSTOM_FORM_TYPE = _models.FormTypes.FORM_WITH_TASK;
|
|
280
|
-
var ACTION = _models.PageAction.DEFAULTS.saveAndContinue;
|
|
281
|
-
var CURRENT_TASK = {
|
|
282
|
-
name: 'test-task',
|
|
283
|
-
pages: ['page-a']
|
|
284
|
-
};
|
|
285
|
-
var CURRENT_PAGE_ID = 'page-b';
|
|
286
|
-
var CUSTOM_FORM_DATA = {
|
|
287
|
-
formStatus: {
|
|
288
|
-
tasks: {
|
|
289
|
-
'test-task': {
|
|
290
|
-
complete: false,
|
|
291
|
-
currentPage: 'page-a'
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
};
|
|
296
|
-
expect((0, _getSubmissionStatus.default)(CUSTOM_FORM_TYPE, PAGES, CURRENT_PAGE_ID, ACTION, CUSTOM_FORM_DATA, CURRENT_TASK, true, [])).toMatchObject(CUSTOM_FORM_DATA.formStatus);
|
|
297
|
-
});
|
|
298
278
|
});
|
|
299
279
|
});
|
|
300
280
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ukhomeoffice/cop-react-form-renderer",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.45.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"clean": "rimraf dist",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"post-compile": "rimraf dist/*.test.* dist/**/*.test.* dist/**/*.stories.* dist/docs dist/assets"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@ukhomeoffice/cop-react-components": "^3.15.
|
|
19
|
+
"@ukhomeoffice/cop-react-components": "^3.15.7",
|
|
20
20
|
"axios": "^0.23.0",
|
|
21
21
|
"dayjs": "^1.11.0",
|
|
22
22
|
"govuk-frontend": "^4.3.1",
|