@ukhomeoffice/cop-react-form-renderer 5.0.0-alpha → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/CheckYourAnswers/Answer.js +18 -7
- package/dist/components/CheckYourAnswers/Answer.test.js +137 -0
- package/dist/components/CheckYourAnswers/CheckYourAnswers.js +70 -46
- package/dist/components/CheckYourAnswers/CheckYourAnswers.stories.mdx +410 -0
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +551 -0
- package/dist/components/CollectionPage/CollectionPage.js +15 -10
- package/dist/components/CollectionPage/CollectionPage.test.js +382 -0
- package/dist/components/FormComponent/Collection.js +91 -48
- package/dist/components/FormComponent/Collection.scss +2 -1
- package/dist/components/FormComponent/Collection.test.js +807 -0
- package/dist/components/FormComponent/Container.js +35 -16
- package/dist/components/FormComponent/Container.test.js +370 -0
- package/dist/components/FormComponent/FormComponent.js +45 -14
- package/dist/components/FormComponent/FormComponent.stories.mdx +184 -0
- package/dist/components/FormComponent/FormComponent.test.js +226 -0
- package/dist/components/FormComponent/helpers/addLabel.js +5 -4
- package/dist/components/FormComponent/helpers/getComponentFieldSet.js +16 -0
- package/dist/components/FormComponent/helpers/getComponentFieldSet.test.js +29 -0
- package/dist/components/FormComponent/helpers/index.js +8 -1
- package/dist/components/FormPage/FormPage.js +69 -30
- package/dist/components/FormPage/FormPage.stories.mdx +155 -0
- package/dist/components/FormPage/FormPage.test.js +330 -0
- package/dist/components/FormRenderer/FormRenderer.js +142 -228
- package/dist/components/FormRenderer/FormRenderer.stories.mdx +183 -0
- package/dist/components/FormRenderer/FormRenderer.test.js +968 -0
- package/dist/components/FormRenderer/handlers/index.js +1 -2
- package/dist/components/FormRenderer/handlers/navigate.js +3 -1
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.js +35 -14
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.test.js +88 -5
- package/dist/components/FormRenderer/helpers/getCYA.js +11 -2
- package/dist/components/FormRenderer/helpers/getNextPageId.js +13 -7
- package/dist/components/FormRenderer/helpers/getRelevantPages.js +10 -2
- package/dist/components/FormRenderer/helpers/getRelevantPages.test.js +1 -1
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +2 -2
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +6 -2
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.js +171 -51
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.test.js +307 -24
- package/dist/components/FormRenderer/helpers/index.js +1 -2
- package/dist/components/FormRenderer/onCYAAction.js +108 -0
- package/dist/components/FormRenderer/onCYAAction.test.js +583 -0
- package/dist/components/FormRenderer/onPageAction.js +145 -0
- package/dist/components/FormRenderer/onPageAction.test.js +678 -0
- package/dist/components/FormRenderer/onTaskAction.js +48 -0
- package/dist/components/FormRenderer/onTaskAction.test.js +251 -0
- package/dist/components/PageActions/ActionButton.js +0 -3
- package/dist/components/PageActions/ActionButton.test.js +93 -0
- package/dist/components/PageActions/PageActions.js +2 -2
- package/dist/components/PageActions/PageActions.stories.mdx +74 -0
- package/dist/components/PageActions/PageActions.test.js +132 -0
- package/dist/components/SummaryList/GroupAction.js +2 -2
- package/dist/components/SummaryList/GroupAction.test.js +80 -0
- package/dist/components/SummaryList/RowAction.js +2 -2
- package/dist/components/SummaryList/RowAction.test.js +80 -0
- package/dist/components/SummaryList/SummaryList.js +29 -12
- package/dist/components/SummaryList/SummaryList.scss +19 -0
- package/dist/components/SummaryList/SummaryList.stories.mdx +90 -0
- package/dist/components/SummaryList/SummaryList.test.js +400 -0
- package/dist/components/SummaryList/SummaryListHeadingRow.js +30 -0
- package/dist/components/SummaryList/SummaryListRow.js +5 -2
- package/dist/components/SummaryList/helpers/getGroupActionAttributes.js +2 -1
- package/dist/components/SummaryList/helpers/getRowActionAttributes.js +2 -1
- package/dist/components/TaskList/Task.js +3 -3
- package/dist/components/TaskList/Task.test.js +167 -0
- package/dist/components/TaskList/TaskList.js +76 -23
- package/dist/components/TaskList/TaskList.stories.mdx +164 -0
- package/dist/components/TaskList/TaskList.test.js +389 -0
- package/dist/components/TaskList/TaskState.js +2 -2
- package/dist/components/TaskList/TaskState.test.js +86 -0
- package/dist/components/index.js +14 -0
- package/dist/context/HooksContext/HooksContext.js +72 -8
- package/dist/context/HooksContext/HooksContext.test.js +44 -0
- package/dist/context/ValidationContext/ValidationContext.js +38 -28
- package/dist/context/ValidationContext/ValidationContext.test.js +84 -0
- package/dist/hooks/useAxios.js +10 -12
- package/dist/hooks/useGetRequest.js +48 -49
- package/dist/hooks/useRefData.js +7 -4
- package/dist/index.js +34 -1
- package/dist/json/addressDetails.json +149 -0
- package/dist/json/areYouACivilServant.json +7 -0
- package/dist/json/firstForm.json +94 -0
- package/dist/json/grade.json +108 -0
- package/dist/json/group.data.json +21 -0
- package/dist/json/group.json +402 -0
- package/dist/json/groupOfRow.json +137 -0
- package/dist/json/groupOfRowData.json +15 -0
- package/dist/json/port.json +346 -0
- package/dist/json/saveAndContinue.json +98 -0
- package/dist/json/sublocation.json +859 -0
- package/dist/json/taskList.json +265 -0
- package/dist/json/team.json +17351 -0
- package/dist/json/terminal.json +81 -0
- package/dist/json/userProfile.data.json +21 -0
- package/dist/json/userProfile.json +276 -0
- package/dist/models/ComponentTypes.js +8 -0
- package/dist/models/PageAction.js +4 -1
- package/dist/models/TaskStates.js +10 -2
- package/dist/models/index.js +16 -1
- package/dist/setupTests.js +46 -0
- package/dist/utils/CheckYourAnswers/getCYAAction.js +5 -5
- package/dist/utils/CheckYourAnswers/getCYAAction.test.js +121 -0
- package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.js +6 -2
- package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.test.js +71 -0
- package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.js +6 -2
- package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.test.js +55 -0
- package/dist/utils/CheckYourAnswers/getCYARow.js +14 -11
- package/dist/utils/CheckYourAnswers/getCYARow.test.js +291 -0
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.js +4 -1
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.test.js +70 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.js +15 -10
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.test.js +288 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +94 -36
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +414 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.js +21 -7
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.test.js +486 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +11 -3
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.test.js +346 -0
- package/dist/utils/CheckYourAnswers/showComponentCYA.js +19 -3
- package/dist/utils/CheckYourAnswers/showComponentCYA.test.js +143 -0
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.js +5 -1
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.test.js +40 -0
- package/dist/utils/CollectionPage/getCollectionPageActiveIndex.test.js +53 -0
- package/dist/utils/CollectionPage/mergeCollectionPages.js +25 -17
- package/dist/utils/CollectionPage/mergeCollectionPages.test.js +130 -0
- package/dist/utils/Component/addShowWhen.js +44 -0
- package/dist/utils/Component/addShowWhen.test.js +216 -0
- package/dist/utils/Component/applyToComponentTree.js +71 -0
- package/dist/utils/Component/applyToComponentTree.test.js +127 -0
- package/dist/utils/Component/cleanAttributes.js +8 -2
- package/dist/utils/Component/cleanAttributes.test.js +68 -0
- package/dist/utils/Component/elevateNestedComponents.js +4 -1
- package/dist/utils/Component/elevateNestedComponents.test.js +122 -0
- package/dist/utils/Component/getComponent.js +80 -11
- package/dist/utils/Component/getComponentTests/getComponent.autocomplete.test.js +4 -4
- package/dist/utils/Component/getComponentTests/getComponent.calculation.test.js +25 -24
- package/dist/utils/Component/getComponentTests/getComponent.checkboxes.test.js +66 -5
- package/dist/utils/Component/getComponentTests/getComponent.date.test.js +2 -2
- package/dist/utils/Component/getComponentTests/getComponent.details.test.js +9 -7
- package/dist/utils/Component/getComponentTests/getComponent.email.test.js +3 -3
- package/dist/utils/Component/getComponentTests/getComponent.file.test.js +3 -3
- package/dist/utils/Component/getComponentTests/getComponent.list.test.js +44 -0
- package/dist/utils/Component/getComponentTests/{getComponent.textarea.test.js → getComponent.multifile.test.js} +29 -21
- package/dist/utils/Component/getComponentTests/getComponent.nested.test.js +159 -83
- package/dist/utils/Component/getComponentTests/getComponent.paragraph.test.js +43 -0
- package/dist/utils/Component/getComponentTests/getComponent.phoneNumber.test.js +3 -3
- package/dist/utils/Component/getComponentTests/getComponent.radios.test.js +55 -5
- package/dist/utils/Component/getComponentTests/getComponent.select.test.js +3 -9
- package/dist/utils/Component/getComponentTests/getComponent.text.test.js +3 -3
- package/dist/utils/Component/getComponentTests/getComponent.textArea.test.js +109 -0
- package/dist/utils/Component/getComponentTests/getComponent.time.test.js +7 -7
- package/dist/utils/Component/getDefaultValue.js +4 -1
- package/dist/utils/Component/getDefaultValue.test.js +50 -0
- package/dist/utils/Component/index.js +2 -0
- package/dist/utils/Component/isEditable.js +2 -2
- package/dist/utils/Component/isEditable.test.js +43 -0
- package/dist/utils/Component/optionIsSelected.js +22 -0
- package/dist/utils/Component/optionIsSelected.test.js +42 -0
- package/dist/utils/Component/setupContainerComponentsPath.js +40 -0
- package/dist/utils/Component/setupContainerComponentsPath.test.js +78 -0
- package/dist/utils/Component/showComponent.test.js +156 -0
- package/dist/utils/Component/wrapInFormGroup.js +1 -1
- package/dist/utils/Condition/meetsAllConditions.js +1 -1
- package/dist/utils/Condition/meetsAllConditions.test.js +61 -0
- package/dist/utils/Condition/meetsCondition.js +74 -4
- package/dist/utils/Condition/meetsCondition.test.js +763 -0
- package/dist/utils/Condition/meetsOneCondition.js +1 -1
- package/dist/utils/Condition/meetsOneCondition.test.js +100 -0
- package/dist/utils/Condition/setupConditions.js +6 -3
- package/dist/utils/Condition/setupConditions.test.js +33 -0
- package/dist/utils/Container/getEditableComponents.test.js +135 -0
- package/dist/utils/Container/setupNesting.js +21 -2
- package/dist/utils/Container/setupNesting.test.js +145 -0
- package/dist/utils/Container/showContainer.test.js +178 -0
- package/dist/utils/Data/applyFormula.js +20 -11
- package/dist/utils/Data/applyFormula.test.js +263 -0
- package/dist/utils/Data/getAutocompleteSource.js +6 -2
- package/dist/utils/Data/getAutocompleteSource.test.js +352 -0
- package/dist/utils/Data/getDataPath.test.js +48 -0
- package/dist/utils/Data/getOptions.js +17 -3
- package/dist/utils/Data/getOptions.test.js +140 -0
- package/dist/utils/Data/getSourceData.js +2 -2
- package/dist/utils/Data/getSourceData.test.js +153 -0
- package/dist/utils/Data/refDataToOptions.js +4 -1
- package/dist/utils/Data/refDataToOptions.test.js +196 -0
- package/dist/utils/Data/setDataItem.test.js +110 -0
- package/dist/utils/Data/setupFormData.js +39 -16
- package/dist/utils/Data/setupFormData.test.js +410 -0
- package/dist/utils/Data/setupRefDataUrlForComponent.js +4 -1
- package/dist/utils/Data/setupRefDataUrlForComponent.test.js +131 -0
- package/dist/utils/FormPage/applyConditionalProperties.js +35 -0
- package/dist/utils/FormPage/applyConditionalProperties.test.js +61 -0
- package/dist/utils/FormPage/getFormPage.js +5 -2
- package/dist/utils/FormPage/getFormPage.test.js +206 -0
- package/dist/utils/FormPage/getFormPages.js +4 -1
- package/dist/utils/FormPage/getFormPages.test.js +97 -0
- package/dist/utils/FormPage/getPageActions.js +8 -4
- package/dist/utils/FormPage/getPageActions.test.js +114 -0
- package/dist/utils/FormPage/getParagraphFromText.test.js +27 -0
- package/dist/utils/FormPage/index.js +2 -0
- package/dist/utils/FormPage/showFormPage.js +2 -2
- package/dist/utils/FormPage/showFormPage.test.js +180 -0
- package/dist/utils/FormPage/showFormPageCYA.js +1 -0
- package/dist/utils/FormPage/showFormPageCYA.test.js +28 -0
- package/dist/utils/FormPage/useComponent.js +29 -14
- package/dist/utils/FormPage/useComponent.test.js +167 -0
- package/dist/utils/Format/formatData.test.js +45 -0
- package/dist/utils/Format/formatDataForComponent.js +2 -1
- package/dist/utils/Format/formatDataForComponent.test.js +142 -0
- package/dist/utils/Format/formatDataForForm.js +4 -1
- package/dist/utils/Format/formatDataForForm.test.js +81 -0
- package/dist/utils/Format/formatDataForPage.test.js +99 -0
- package/dist/utils/Hub/getFormHub.test.js +105 -0
- package/dist/utils/Meta/documents/getDocuments.test.js +4 -1
- package/dist/utils/Meta/documents/index.js +2 -2
- package/dist/utils/Meta/documents/setDocumentsForField.js +31 -0
- package/dist/utils/Meta/documents/setDocumentsForField.test.js +59 -0
- package/dist/utils/Operate/checkValueIsTruthy.test.js +42 -0
- package/dist/utils/Operate/getFirstOf.js +31 -0
- package/dist/utils/Operate/getFirstOf.test.js +86 -0
- package/dist/utils/Operate/getIndexOfMatchingValueIn.test.js +163 -0
- package/dist/utils/Operate/persistValueInFormData.js +2 -1
- package/dist/utils/Operate/persistValueInFormData.test.js +115 -0
- package/dist/utils/Operate/runPageOperations.js +3 -1
- package/dist/utils/Operate/runPageOperations.test.js +105 -0
- package/dist/utils/Operate/setValueInFormData.test.js +44 -0
- package/dist/utils/Operate/shouldRun.js +16 -13
- package/dist/utils/Operate/shouldRun.test.js +66 -0
- package/dist/utils/Validate/additional/conditionallyRequired.js +24 -0
- package/dist/utils/Validate/additional/conditionallyRequired.test.js +73 -0
- package/dist/utils/Validate/additional/index.js +13 -4
- package/dist/utils/Validate/additional/mustBeAfter.js +8 -6
- package/dist/utils/Validate/additional/mustBeAfter.test.js +15 -1
- package/dist/utils/Validate/additional/mustBeBefore.js +9 -5
- package/dist/utils/Validate/additional/mustBeBefore.test.js +14 -0
- package/dist/utils/Validate/additional/mustBeEarlierDateTime.js +1 -1
- package/dist/utils/Validate/additional/mustBeEarlierDateTime.test.js +6 -3
- package/dist/utils/Validate/additional/mustBeGreaterThan.js +22 -0
- package/dist/utils/Validate/additional/mustBeGreaterThan.test.js +56 -0
- package/dist/utils/Validate/additional/mustBeInTheFuture.js +1 -1
- package/dist/utils/Validate/additional/mustBeInThePast.js +5 -5
- package/dist/utils/Validate/additional/mustBeLessThan.js +7 -6
- package/dist/utils/Validate/additional/mustBeLessThan.test.js +11 -1
- package/dist/utils/Validate/additional/mustBeNumbersOnly.js +9 -5
- package/dist/utils/Validate/additional/mustBeNumbersOnly.test.js +10 -2
- package/dist/utils/Validate/additional/mustEnterAtLeastOne.js +1 -0
- package/dist/utils/Validate/additional/mustEnterAtLeastOne.test.js +4 -1
- package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.js +19 -0
- package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.test.js +36 -0
- package/dist/utils/Validate/additional/mustSelectOnlyOne.js +29 -0
- package/dist/utils/Validate/additional/mustSelectOnlyOne.test.js +52 -0
- package/dist/utils/Validate/additional/utils.js +18 -18
- package/dist/utils/Validate/index.js +6 -0
- package/dist/utils/Validate/validateCollection.js +20 -5
- package/dist/utils/Validate/validateCollection.test.js +125 -0
- package/dist/utils/Validate/validateComponent.js +36 -20
- package/dist/utils/Validate/validateComponent.test.js +365 -0
- package/dist/utils/Validate/validateContainer.js +9 -3
- package/dist/utils/Validate/validateContainer.test.js +75 -0
- package/dist/utils/Validate/validateDate.js +4 -3
- package/dist/utils/Validate/validateDate.test.js +114 -0
- package/dist/utils/Validate/validateEmail.js +14 -1
- package/dist/utils/Validate/validateEmail.test.js +74 -0
- package/dist/utils/Validate/validateMultifile.js +32 -0
- package/dist/utils/Validate/validateMultifile.test.js +47 -0
- package/dist/utils/Validate/validatePage.js +12 -6
- package/dist/utils/Validate/validatePage.test.js +472 -0
- package/dist/utils/Validate/validateRegex.js +2 -5
- package/dist/utils/Validate/validateRegex.test.js +42 -0
- package/dist/utils/Validate/validateRequired.js +2 -4
- package/dist/utils/Validate/validateRequired.test.js +63 -0
- package/dist/utils/Validate/validateTextArea.js +37 -0
- package/dist/utils/Validate/validateTextArea.test.js +42 -0
- package/dist/utils/Validate/validateTime.js +2 -2
- package/dist/utils/Validate/validateTime.test.js +59 -0
- package/dist/utils/index.js +4 -1
- package/package.json +35 -50
- package/dist/utils/Meta/documents/setDocumentForField.js +0 -29
- package/dist/utils/Meta/documents/setDocumentForField.test.js +0 -49
|
@@ -0,0 +1,678 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _models = require("../../models");
|
|
4
|
+
var _utils = _interopRequireDefault(require("../../utils"));
|
|
5
|
+
var _handlers = _interopRequireDefault(require("./handlers"));
|
|
6
|
+
var _helpers = _interopRequireDefault(require("./helpers"));
|
|
7
|
+
var _onPageAction = _interopRequireDefault(require("./onPageAction"));
|
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
10
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
11
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
12
|
+
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; }
|
|
13
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
14
|
+
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); }
|
|
15
|
+
jest.mock('./handlers', function () {
|
|
16
|
+
return {
|
|
17
|
+
navigateCalls: 0,
|
|
18
|
+
navigate: function navigate() {
|
|
19
|
+
this.navigateCalls += 1;
|
|
20
|
+
},
|
|
21
|
+
submissionErrorCalls: 0,
|
|
22
|
+
submissionErrorArgs: [],
|
|
23
|
+
submissionError: function submissionError(errors, addErrors) {
|
|
24
|
+
this.submissionErrorCalls += 1;
|
|
25
|
+
this.submissionErrorArgs.push(errors);
|
|
26
|
+
if (typeof addErrors === 'function') {
|
|
27
|
+
addErrors(errors);
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
reset: function reset() {
|
|
31
|
+
this.navigateCalls = 0;
|
|
32
|
+
this.submissionErrorCalls = 0;
|
|
33
|
+
this.submissionErrorArgs = [];
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
jest.mock('./helpers', function () {
|
|
38
|
+
return {
|
|
39
|
+
canActionProceedCalls: 0,
|
|
40
|
+
canActionProceedResult: true,
|
|
41
|
+
canActionProceed: function canActionProceed(action, page, validator) {
|
|
42
|
+
this.canActionProceedCalls += 1;
|
|
43
|
+
if (typeof validator === 'function') {
|
|
44
|
+
validator();
|
|
45
|
+
}
|
|
46
|
+
return this.canActionProceedResult;
|
|
47
|
+
},
|
|
48
|
+
cleanHiddenNestedDataCalls: 0,
|
|
49
|
+
cleanHiddenNestedData: function cleanHiddenNestedData(patch) {
|
|
50
|
+
this.cleanHiddenNestedDataCalls += 1;
|
|
51
|
+
return patch;
|
|
52
|
+
},
|
|
53
|
+
getNextPageIdCalls: 0,
|
|
54
|
+
getNextPageId: function getNextPageId() {
|
|
55
|
+
this.getNextPageIdCalls += 1;
|
|
56
|
+
return 'page2';
|
|
57
|
+
},
|
|
58
|
+
getSubmissionStatusCalls: 0,
|
|
59
|
+
getSubmissionStatus: function getSubmissionStatus() {
|
|
60
|
+
this.getSubmissionStatusCalls += 1;
|
|
61
|
+
return 'Good to go!';
|
|
62
|
+
},
|
|
63
|
+
reset: function reset() {
|
|
64
|
+
this.canActionProceedCalls = 0;
|
|
65
|
+
this.canActionProceedResult = true;
|
|
66
|
+
this.canCYASubmitResult = true;
|
|
67
|
+
this.cleanHiddenNestedDataCalls = 0;
|
|
68
|
+
this.getFormStateCalls = 0;
|
|
69
|
+
this.getSubmissionStatusCalls = 0;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
jest.mock('../../utils', function () {
|
|
74
|
+
var originalModule = jest.requireActual('../../utils');
|
|
75
|
+
return _objectSpread(_objectSpread({}, originalModule.default), {}, {
|
|
76
|
+
Format: {
|
|
77
|
+
formCalls: 0,
|
|
78
|
+
form: function form(_form, data) {
|
|
79
|
+
this.formCalls += 1;
|
|
80
|
+
return data;
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
CollectionPage: {
|
|
84
|
+
duplicateActiveEntryCalls: 0,
|
|
85
|
+
duplicateActiveEntryResult: true,
|
|
86
|
+
duplicateActiveEntry: function duplicateActiveEntry() {
|
|
87
|
+
this.duplicateActiveEntryCalls += 1;
|
|
88
|
+
return this.duplicateActiveEntryResult;
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
reset: function reset() {
|
|
92
|
+
this.Format.formCalls = 0;
|
|
93
|
+
this.CollectionPage.duplicateActiveEntryCalls = 0;
|
|
94
|
+
this.duplicateActiveEntryResult = true;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
describe('components.FormRenderer.onPageAction', function () {
|
|
99
|
+
var MOCK_HOOKS = {
|
|
100
|
+
onSubmitCalls: 0,
|
|
101
|
+
onSubmitArgs: [],
|
|
102
|
+
onSubmit: function onSubmit(type, payload, onSuccess, onError, changedFieldName, changedFieldValue) {
|
|
103
|
+
this.onSubmitCalls += 1;
|
|
104
|
+
this.onSubmitArgs.push({
|
|
105
|
+
type: type,
|
|
106
|
+
payload: payload,
|
|
107
|
+
changedFieldName: changedFieldName,
|
|
108
|
+
changedFieldValue: changedFieldValue
|
|
109
|
+
});
|
|
110
|
+
if (typeof onSuccess === 'function') {
|
|
111
|
+
onSuccess();
|
|
112
|
+
}
|
|
113
|
+
// onError would not normally be called alongside
|
|
114
|
+
// onSuccess, we're just doing it here to make sure
|
|
115
|
+
// the expected function chain is called.
|
|
116
|
+
if (typeof onError === 'function') {
|
|
117
|
+
onError(['an example error']);
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
onFormCompleteCalls: 0,
|
|
121
|
+
onFormComplete: function onFormComplete() {
|
|
122
|
+
this.onFormCompleteCalls += 1;
|
|
123
|
+
},
|
|
124
|
+
onCancelCalls: 0,
|
|
125
|
+
onCancel: function onCancel() {
|
|
126
|
+
this.onCancelCalls += 1;
|
|
127
|
+
},
|
|
128
|
+
reset: function reset() {
|
|
129
|
+
this.onSubmitCalls = 0;
|
|
130
|
+
this.onSubmitArgs = [];
|
|
131
|
+
this.onFormCompleteCalls = 0;
|
|
132
|
+
this.onCancelCalls = 0;
|
|
133
|
+
this.onActionCalls = 0;
|
|
134
|
+
},
|
|
135
|
+
onActionCalls: 0,
|
|
136
|
+
onAction: function onAction(formData, patch) {
|
|
137
|
+
this.onActionCalls += 1;
|
|
138
|
+
return {
|
|
139
|
+
formData: formData,
|
|
140
|
+
patch: patch
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
var MOCK_VALIDATE = {
|
|
145
|
+
pageCalls: 0,
|
|
146
|
+
page: function page() {
|
|
147
|
+
MOCK_VALIDATE.pageCalls += 1;
|
|
148
|
+
},
|
|
149
|
+
reset: function reset() {
|
|
150
|
+
this.pageCalls = 0;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
var setPagePointCalls = 0;
|
|
154
|
+
var setPagePointArgs = [];
|
|
155
|
+
var mockSetPagePoint = function mockSetPagePoint(point) {
|
|
156
|
+
setPagePointCalls += 1;
|
|
157
|
+
setPagePointArgs.push(point);
|
|
158
|
+
};
|
|
159
|
+
var setDataCalls = 0;
|
|
160
|
+
var setDataArgs = [];
|
|
161
|
+
var mockSetData = function mockSetData(data) {
|
|
162
|
+
setDataCalls += 1;
|
|
163
|
+
setDataArgs.push(data);
|
|
164
|
+
};
|
|
165
|
+
var onPageChangeCalls = 0;
|
|
166
|
+
var onPageChangeArgs = [];
|
|
167
|
+
var mockOnPageChange = function mockOnPageChange(pageId) {
|
|
168
|
+
onPageChangeCalls += 1;
|
|
169
|
+
onPageChangeArgs.push(pageId);
|
|
170
|
+
};
|
|
171
|
+
var addErrorsArgs = [];
|
|
172
|
+
var mockAddErrors = function mockAddErrors(errors) {
|
|
173
|
+
addErrorsArgs.push(errors);
|
|
174
|
+
};
|
|
175
|
+
var setSubmittedArgs = [];
|
|
176
|
+
var mockSetSubmitted = function mockSetSubmitted(newSubmitted) {
|
|
177
|
+
setSubmittedArgs.push(newSubmitted);
|
|
178
|
+
};
|
|
179
|
+
var COMPONENTS = [{
|
|
180
|
+
id: 'alpha',
|
|
181
|
+
fieldId: 'alpha'
|
|
182
|
+
}, {
|
|
183
|
+
id: 'bravo',
|
|
184
|
+
fieldId: 'bravo'
|
|
185
|
+
}, {
|
|
186
|
+
id: 'charlie',
|
|
187
|
+
fieldId: 'charlie'
|
|
188
|
+
}, {
|
|
189
|
+
id: 'delta',
|
|
190
|
+
fieldId: 'delta'
|
|
191
|
+
}];
|
|
192
|
+
var PAGES = [{
|
|
193
|
+
id: 'page1',
|
|
194
|
+
components: [_objectSpread({}, COMPONENTS[0]), _objectSpread({}, COMPONENTS[1])]
|
|
195
|
+
}, {
|
|
196
|
+
id: 'page2',
|
|
197
|
+
components: [_objectSpread({}, COMPONENTS[2]), _objectSpread({}, COMPONENTS[3])]
|
|
198
|
+
}];
|
|
199
|
+
var CURRENT_TASK = {
|
|
200
|
+
name: 'testTask',
|
|
201
|
+
fullPages: PAGES
|
|
202
|
+
};
|
|
203
|
+
var ARGS = {
|
|
204
|
+
action: {
|
|
205
|
+
type: _models.PageAction.TYPES.NAVIGATE
|
|
206
|
+
},
|
|
207
|
+
patch: null,
|
|
208
|
+
patchLabel: {},
|
|
209
|
+
hooks: MOCK_HOOKS,
|
|
210
|
+
data: {},
|
|
211
|
+
formState: {
|
|
212
|
+
page: {
|
|
213
|
+
formData: {}
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
validate: MOCK_VALIDATE,
|
|
217
|
+
onPageChange: mockOnPageChange,
|
|
218
|
+
type: _models.FormTypes.FORM_WITH_TASK,
|
|
219
|
+
pages: PAGES,
|
|
220
|
+
components: COMPONENTS,
|
|
221
|
+
pageId: 'alpha',
|
|
222
|
+
setPagePoint: mockSetPagePoint,
|
|
223
|
+
currentTask: CURRENT_TASK,
|
|
224
|
+
setData: mockSetData,
|
|
225
|
+
hubDetails: {},
|
|
226
|
+
setSubmitted: mockSetSubmitted,
|
|
227
|
+
addErrors: mockAddErrors
|
|
228
|
+
};
|
|
229
|
+
beforeEach(function () {
|
|
230
|
+
_handlers.default.reset();
|
|
231
|
+
_helpers.default.reset();
|
|
232
|
+
_utils.default.reset();
|
|
233
|
+
MOCK_HOOKS.reset();
|
|
234
|
+
MOCK_VALIDATE.reset();
|
|
235
|
+
setPagePointCalls = 0;
|
|
236
|
+
setPagePointArgs = [];
|
|
237
|
+
setDataCalls = 0;
|
|
238
|
+
setDataArgs = [];
|
|
239
|
+
onPageChangeCalls = 0;
|
|
240
|
+
onPageChangeArgs = [];
|
|
241
|
+
addErrorsArgs = [];
|
|
242
|
+
setSubmittedArgs = [];
|
|
243
|
+
});
|
|
244
|
+
var preActionChecks = function preActionChecks() {
|
|
245
|
+
expect(_helpers.default.canActionProceedCalls).toEqual(1);
|
|
246
|
+
expect(MOCK_VALIDATE.pageCalls).toEqual(1);
|
|
247
|
+
expect(_helpers.default.cleanHiddenNestedDataCalls).toEqual(1);
|
|
248
|
+
};
|
|
249
|
+
var postActionChecks = function postActionChecks(argsUsed) {
|
|
250
|
+
expect(_utils.default.Format.formCalls).toEqual(1);
|
|
251
|
+
expect(_helpers.default.getSubmissionStatusCalls).toEqual(1);
|
|
252
|
+
// setData is always called once in the error callback
|
|
253
|
+
// for the onSubmit hook. It's called an extra time prior
|
|
254
|
+
// to this if patch is valid.
|
|
255
|
+
if (argsUsed.patch) {
|
|
256
|
+
expect(setDataCalls).toEqual(2);
|
|
257
|
+
var dataUsed = _objectSpread(_objectSpread(_objectSpread({}, argsUsed.data), argsUsed.patch), argsUsed.formState.page.formData);
|
|
258
|
+
var submissionData = _utils.default.Format.form(null, dataUsed, null);
|
|
259
|
+
submissionData.formStatus = _helpers.default.getSubmissionStatus();
|
|
260
|
+
expect(setDataArgs[0]).toEqual(submissionData);
|
|
261
|
+
} else {
|
|
262
|
+
expect(setDataCalls).toEqual(1);
|
|
263
|
+
}
|
|
264
|
+
expect(MOCK_HOOKS.onSubmitCalls).toEqual(1);
|
|
265
|
+
if (argsUsed.type === _models.FormTypes.HUB && Object.keys(argsUsed.patchLabel).length > 0) {
|
|
266
|
+
var firstKey = Object.keys(argsUsed.patchLabel)[0];
|
|
267
|
+
expect(MOCK_HOOKS.onSubmitArgs[0]).toMatchObject({
|
|
268
|
+
changedFieldName: firstKey,
|
|
269
|
+
changedFieldValue: argsUsed.patchLabel[firstKey]
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
expect(MOCK_HOOKS.onActionCalls).toEqual(1);
|
|
273
|
+
|
|
274
|
+
// Both the success and error paths of the onSubmit hook are tested
|
|
275
|
+
// together to make sure the correct function chains are called for
|
|
276
|
+
// each.
|
|
277
|
+
|
|
278
|
+
// The success path is tested per-action as it can differ slightly.
|
|
279
|
+
|
|
280
|
+
// Testing the error path.
|
|
281
|
+
expect(_handlers.default.submissionErrorCalls).toEqual(1);
|
|
282
|
+
expect(setDataArgs[setDataCalls - 1]).toEqual(argsUsed.data); // Data is reset in the case of an error.
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
it("should handle the ".concat(_models.PageAction.TYPES.CANCEL, " Page Action type"), function () {
|
|
286
|
+
var ACTION = {
|
|
287
|
+
type: _models.PageAction.TYPES.CANCEL
|
|
288
|
+
};
|
|
289
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
290
|
+
action: ACTION
|
|
291
|
+
});
|
|
292
|
+
_onPageAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
293
|
+
expect(MOCK_HOOKS.onCancelCalls).toEqual(1);
|
|
294
|
+
// Shouldn't get to the point of validation if
|
|
295
|
+
// action is a cancel action.
|
|
296
|
+
expect(_helpers.default.canActionProceedCalls).toEqual(0);
|
|
297
|
+
expect(MOCK_VALIDATE.pageCalls).toEqual(0);
|
|
298
|
+
});
|
|
299
|
+
it("should handle the ".concat(_models.PageAction.TYPES.NAVIGATE, " Page Action type"), function () {
|
|
300
|
+
var ACTION = {
|
|
301
|
+
type: _models.PageAction.TYPES.NAVIGATE
|
|
302
|
+
};
|
|
303
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
304
|
+
action: ACTION
|
|
305
|
+
});
|
|
306
|
+
_onPageAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
307
|
+
preActionChecks();
|
|
308
|
+
expect(_handlers.default.navigateCalls).toEqual(1);
|
|
309
|
+
expect(MOCK_HOOKS.onSubmitCalls).toEqual(0);
|
|
310
|
+
// Not doing the usual post-action checks here
|
|
311
|
+
// as a navigate action should stop at calling
|
|
312
|
+
// hooks.navigate.
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it("should handle the ".concat(_models.PageAction.TYPES.SUBMIT, " Page Action type"), function () {
|
|
316
|
+
var ACTION = {
|
|
317
|
+
type: _models.PageAction.TYPES.SUBMIT
|
|
318
|
+
};
|
|
319
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
320
|
+
action: ACTION
|
|
321
|
+
});
|
|
322
|
+
_onPageAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
323
|
+
preActionChecks();
|
|
324
|
+
expect(setPagePointCalls).toEqual(1);
|
|
325
|
+
expect(setPagePointArgs[0]).toEqual('submit');
|
|
326
|
+
postActionChecks(CUSTOM_ARGS);
|
|
327
|
+
});
|
|
328
|
+
it("should handle the ".concat(_models.PageAction.TYPES.SAVE_AND_NAVIGATE, " Page Action type"), function () {
|
|
329
|
+
var ACTION = {
|
|
330
|
+
type: _models.PageAction.TYPES.SAVE_AND_NAVIGATE
|
|
331
|
+
};
|
|
332
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
333
|
+
action: ACTION
|
|
334
|
+
});
|
|
335
|
+
_onPageAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
336
|
+
preActionChecks();
|
|
337
|
+
// All the actions does in this case is set a function
|
|
338
|
+
// to be called in the onSuccess callback for the onSubmit hook.
|
|
339
|
+
postActionChecks(CUSTOM_ARGS);
|
|
340
|
+
expect(_handlers.default.navigateCalls).toEqual(1);
|
|
341
|
+
});
|
|
342
|
+
it("should handle the ".concat(_models.PageAction.TYPES.COLLECTION_ADD, " Page Action type"), function () {
|
|
343
|
+
var FORM_STATE = {
|
|
344
|
+
page: {
|
|
345
|
+
formData: {
|
|
346
|
+
'testCollection': []
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
var ACTION = {
|
|
351
|
+
type: _models.PageAction.TYPES.COLLECTION_ADD,
|
|
352
|
+
collection: 'testCollection'
|
|
353
|
+
};
|
|
354
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
355
|
+
action: ACTION,
|
|
356
|
+
formState: FORM_STATE
|
|
357
|
+
});
|
|
358
|
+
_onPageAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
359
|
+
preActionChecks();
|
|
360
|
+
expect(FORM_STATE.page.formData["".concat(ACTION.collection, "ActiveId")]).toBeDefined();
|
|
361
|
+
postActionChecks(CUSTOM_ARGS);
|
|
362
|
+
|
|
363
|
+
// This action type also sets up a call to handlers.navigate
|
|
364
|
+
// that's called as part of the onSubmit hook's onSuccess callback.
|
|
365
|
+
expect(_handlers.default.navigateCalls).toEqual(1);
|
|
366
|
+
});
|
|
367
|
+
describe("should handle the ".concat(_models.PageAction.TYPES.COLLECTION_DUPLICATE, " Page Action type"), function () {
|
|
368
|
+
it("calling handlers.navigate if the duplication was successful", function () {
|
|
369
|
+
var FORM_STATE = {
|
|
370
|
+
page: {
|
|
371
|
+
formData: {
|
|
372
|
+
'testCollection': []
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
var ACTION = {
|
|
377
|
+
type: _models.PageAction.TYPES.COLLECTION_DUPLICATE,
|
|
378
|
+
collection: 'testCollection'
|
|
379
|
+
};
|
|
380
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
381
|
+
action: ACTION,
|
|
382
|
+
formState: FORM_STATE
|
|
383
|
+
});
|
|
384
|
+
_onPageAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
385
|
+
preActionChecks();
|
|
386
|
+
expect(_utils.default.CollectionPage.duplicateActiveEntryCalls).toEqual(1);
|
|
387
|
+
postActionChecks(CUSTOM_ARGS);
|
|
388
|
+
|
|
389
|
+
// This action type also sets up a call to handlers.navigate
|
|
390
|
+
// that's called as part of the onSubmit hook's onSuccess callback.
|
|
391
|
+
expect(_handlers.default.navigateCalls).toEqual(1);
|
|
392
|
+
});
|
|
393
|
+
it("calling onPageChange if the duplication was unsuccessful", function () {
|
|
394
|
+
var FORM_STATE = {
|
|
395
|
+
page: {
|
|
396
|
+
formData: {
|
|
397
|
+
'testCollection': []
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
var ACTION = {
|
|
402
|
+
type: _models.PageAction.TYPES.COLLECTION_DUPLICATE,
|
|
403
|
+
collection: 'testCollection'
|
|
404
|
+
};
|
|
405
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
406
|
+
action: ACTION,
|
|
407
|
+
formState: FORM_STATE
|
|
408
|
+
});
|
|
409
|
+
_utils.default.CollectionPage.duplicateActiveEntryResult = false;
|
|
410
|
+
_onPageAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
411
|
+
preActionChecks();
|
|
412
|
+
expect(_utils.default.CollectionPage.duplicateActiveEntryCalls).toEqual(1);
|
|
413
|
+
postActionChecks(CUSTOM_ARGS);
|
|
414
|
+
|
|
415
|
+
// The handlers.navigate callback shouldn't be set when
|
|
416
|
+
// duplication fails.
|
|
417
|
+
expect(_handlers.default.navigateCalls).toEqual(0);
|
|
418
|
+
// Instead we should be using the default onPageChange setup.
|
|
419
|
+
expect(onPageChangeCalls).toEqual(1);
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
describe("should handle the ".concat(_models.PageAction.TYPES.COLLECTION_REMOVE, " Page Action type"), function () {
|
|
423
|
+
it("should store a reference to the removed item if action.recordRemoval is true", function () {
|
|
424
|
+
var FORM_STATE = {
|
|
425
|
+
page: {
|
|
426
|
+
formData: {
|
|
427
|
+
testCollectionActiveId: 'removeMe',
|
|
428
|
+
testCollection: [{
|
|
429
|
+
id: 'removeMe'
|
|
430
|
+
}, {
|
|
431
|
+
id: 'leaveMeAlone'
|
|
432
|
+
}]
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
var ACTION = {
|
|
437
|
+
type: _models.PageAction.TYPES.COLLECTION_REMOVE,
|
|
438
|
+
collection: 'testCollection',
|
|
439
|
+
recordRemoval: true
|
|
440
|
+
};
|
|
441
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
442
|
+
action: ACTION,
|
|
443
|
+
formState: FORM_STATE
|
|
444
|
+
});
|
|
445
|
+
_onPageAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
446
|
+
preActionChecks();
|
|
447
|
+
expect(FORM_STATE.page.formData.testCollection).toEqual([{
|
|
448
|
+
id: 'leaveMeAlone'
|
|
449
|
+
}]);
|
|
450
|
+
expect(FORM_STATE.page.formData.testCollectionLastRemoved).toEqual({
|
|
451
|
+
id: 'removeMe'
|
|
452
|
+
});
|
|
453
|
+
postActionChecks(CUSTOM_ARGS);
|
|
454
|
+
|
|
455
|
+
// This action type uses the default onPageChange.
|
|
456
|
+
expect(onPageChangeCalls).toEqual(1);
|
|
457
|
+
});
|
|
458
|
+
it("should not store a reference to the removed item if action.recordRemoval is false", function () {
|
|
459
|
+
var FORM_STATE = {
|
|
460
|
+
page: {
|
|
461
|
+
formData: {
|
|
462
|
+
testCollectionActiveId: 'removeMe',
|
|
463
|
+
testCollection: [{
|
|
464
|
+
id: 'removeMe'
|
|
465
|
+
}, {
|
|
466
|
+
id: 'leaveMeAlone'
|
|
467
|
+
}]
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
var ACTION = {
|
|
472
|
+
type: _models.PageAction.TYPES.COLLECTION_REMOVE,
|
|
473
|
+
collection: 'testCollection',
|
|
474
|
+
recordRemoval: false
|
|
475
|
+
};
|
|
476
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
477
|
+
action: ACTION,
|
|
478
|
+
formState: FORM_STATE
|
|
479
|
+
});
|
|
480
|
+
_onPageAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
481
|
+
preActionChecks();
|
|
482
|
+
expect(FORM_STATE.page.formData.testCollection).toEqual([{
|
|
483
|
+
id: 'leaveMeAlone'
|
|
484
|
+
}]);
|
|
485
|
+
expect(FORM_STATE.page.formData.testCollectionLastRemoved).toBeUndefined();
|
|
486
|
+
postActionChecks(CUSTOM_ARGS);
|
|
487
|
+
|
|
488
|
+
// This action type uses the default onPageChange.
|
|
489
|
+
expect(onPageChangeCalls).toEqual(1);
|
|
490
|
+
});
|
|
491
|
+
it("should not store a reference to the removed item if action.recordRemoval is not defined", function () {
|
|
492
|
+
var FORM_STATE = {
|
|
493
|
+
page: {
|
|
494
|
+
formData: {
|
|
495
|
+
testCollectionActiveId: 'removeMe',
|
|
496
|
+
testCollection: [{
|
|
497
|
+
id: 'removeMe'
|
|
498
|
+
}, {
|
|
499
|
+
id: 'leaveMeAlone'
|
|
500
|
+
}]
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
};
|
|
504
|
+
var ACTION = {
|
|
505
|
+
type: _models.PageAction.TYPES.COLLECTION_REMOVE,
|
|
506
|
+
collection: 'testCollection'
|
|
507
|
+
};
|
|
508
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
509
|
+
action: ACTION,
|
|
510
|
+
formState: FORM_STATE
|
|
511
|
+
});
|
|
512
|
+
_onPageAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
513
|
+
preActionChecks();
|
|
514
|
+
expect(FORM_STATE.page.formData.testCollection).toEqual([{
|
|
515
|
+
id: 'leaveMeAlone'
|
|
516
|
+
}]);
|
|
517
|
+
expect(FORM_STATE.page.formData.testCollectionLastRemoved).toBeUndefined();
|
|
518
|
+
postActionChecks(CUSTOM_ARGS);
|
|
519
|
+
|
|
520
|
+
// This action type uses the default onPageChange.
|
|
521
|
+
expect(onPageChangeCalls).toEqual(1);
|
|
522
|
+
});
|
|
523
|
+
});
|
|
524
|
+
describe('if validation fails', function () {
|
|
525
|
+
var VALID_ACTIONS = Object.values(_models.PageAction.TYPES).filter(function (a) {
|
|
526
|
+
return a !== _models.PageAction.TYPES.CANCEL;
|
|
527
|
+
});
|
|
528
|
+
VALID_ACTIONS.forEach(function (actionType) {
|
|
529
|
+
it("should not continue for the ".concat(actionType, " action type"), function () {
|
|
530
|
+
var ACTION = {
|
|
531
|
+
type: actionType
|
|
532
|
+
};
|
|
533
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
534
|
+
action: ACTION
|
|
535
|
+
});
|
|
536
|
+
_helpers.default.canActionProceedResult = false;
|
|
537
|
+
_onPageAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
538
|
+
expect(_helpers.default.canActionProceedCalls).toEqual(1);
|
|
539
|
+
expect(MOCK_VALIDATE.pageCalls).toEqual(1);
|
|
540
|
+
// Validation fails so we expect to never reach
|
|
541
|
+
// the point of submission.
|
|
542
|
+
expect(MOCK_HOOKS.onSubmitCalls).toEqual(0);
|
|
543
|
+
});
|
|
544
|
+
});
|
|
545
|
+
});
|
|
546
|
+
describe('adding a field to formData if specified on the action', function () {
|
|
547
|
+
var VALID_ACTIONS = Object.values(_models.PageAction.TYPES).filter(function (a) {
|
|
548
|
+
return a !== _models.PageAction.TYPES.CANCEL && a !== _models.PageAction.TYPES.NAVIGATE;
|
|
549
|
+
});
|
|
550
|
+
VALID_ACTIONS.forEach(function (actionType) {
|
|
551
|
+
it("should work for the ".concat(actionType, " action type"), function () {
|
|
552
|
+
var FORM_STATE = {
|
|
553
|
+
page: {
|
|
554
|
+
formData: {
|
|
555
|
+
testCollection: []
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
};
|
|
559
|
+
var ACTION = {
|
|
560
|
+
type: actionType,
|
|
561
|
+
collection: 'testCollection',
|
|
562
|
+
addToFormData: {
|
|
563
|
+
field: 'alpha',
|
|
564
|
+
value: '123'
|
|
565
|
+
}
|
|
566
|
+
};
|
|
567
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
568
|
+
formState: FORM_STATE,
|
|
569
|
+
action: ACTION
|
|
570
|
+
});
|
|
571
|
+
_onPageAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
572
|
+
preActionChecks();
|
|
573
|
+
postActionChecks(CUSTOM_ARGS);
|
|
574
|
+
expect(FORM_STATE.page.formData).toMatchObject({
|
|
575
|
+
alpha: '123'
|
|
576
|
+
});
|
|
577
|
+
});
|
|
578
|
+
});
|
|
579
|
+
it("should work for the ".concat(_models.PageAction.TYPES.NAVIGATE, " action type"), function () {
|
|
580
|
+
var FORM_STATE = {
|
|
581
|
+
page: {
|
|
582
|
+
formData: {
|
|
583
|
+
testCollection: []
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
var ACTION = {
|
|
588
|
+
type: _models.PageAction.TYPES.NAVIGATE,
|
|
589
|
+
collection: 'testCollection',
|
|
590
|
+
addToFormData: {
|
|
591
|
+
field: 'alpha',
|
|
592
|
+
value: '123'
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
596
|
+
formState: FORM_STATE,
|
|
597
|
+
action: ACTION
|
|
598
|
+
});
|
|
599
|
+
_onPageAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
600
|
+
preActionChecks();
|
|
601
|
+
// Not doing the usual post-action checks here
|
|
602
|
+
// as a navigate action should stop at calling
|
|
603
|
+
// hooks.navigate.
|
|
604
|
+
expect(FORM_STATE.page.formData).toMatchObject({
|
|
605
|
+
alpha: '123'
|
|
606
|
+
});
|
|
607
|
+
});
|
|
608
|
+
it('should work for an array of formData', function () {
|
|
609
|
+
var FORM_STATE = {
|
|
610
|
+
page: {
|
|
611
|
+
formData: {
|
|
612
|
+
testCollection: []
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
};
|
|
616
|
+
var ACTION = {
|
|
617
|
+
type: _models.PageAction.TYPES.NAVIGATE,
|
|
618
|
+
collection: 'testCollection',
|
|
619
|
+
addToFormData: [{
|
|
620
|
+
field: 'alpha',
|
|
621
|
+
value: '123'
|
|
622
|
+
}, {
|
|
623
|
+
field: 'beta.gamma',
|
|
624
|
+
value: '456'
|
|
625
|
+
}]
|
|
626
|
+
};
|
|
627
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
628
|
+
formState: FORM_STATE,
|
|
629
|
+
action: ACTION
|
|
630
|
+
});
|
|
631
|
+
_onPageAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
632
|
+
preActionChecks();
|
|
633
|
+
// Not doing the usual post-action checks here
|
|
634
|
+
// as a navigate action should stop at calling
|
|
635
|
+
// hooks.navigate.
|
|
636
|
+
expect(FORM_STATE.page.formData).toMatchObject({
|
|
637
|
+
alpha: '123',
|
|
638
|
+
beta: {
|
|
639
|
+
gamma: '456'
|
|
640
|
+
}
|
|
641
|
+
});
|
|
642
|
+
});
|
|
643
|
+
});
|
|
644
|
+
describe('recording patchLabel fields correctly when it is defined', function () {
|
|
645
|
+
var VALID_ACTIONS = Object.values(_models.PageAction.TYPES).filter(function (a) {
|
|
646
|
+
return a !== _models.PageAction.TYPES.CANCEL && a !== _models.PageAction.TYPES.NAVIGATE;
|
|
647
|
+
});
|
|
648
|
+
VALID_ACTIONS.forEach(function (actionType) {
|
|
649
|
+
it("should work for the ".concat(actionType, " action type"), function () {
|
|
650
|
+
var FORM_STATE = {
|
|
651
|
+
page: {
|
|
652
|
+
formData: {
|
|
653
|
+
testCollection: []
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
var KEY = 'testField';
|
|
658
|
+
var VALUE = 'testValue';
|
|
659
|
+
var PATCH_LABEL = _defineProperty({}, KEY, VALUE);
|
|
660
|
+
var PATCH = _defineProperty({}, KEY, VALUE);
|
|
661
|
+
var ACTION = {
|
|
662
|
+
type: actionType,
|
|
663
|
+
collection: 'testCollection'
|
|
664
|
+
};
|
|
665
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
666
|
+
action: ACTION,
|
|
667
|
+
formState: FORM_STATE,
|
|
668
|
+
patch: PATCH,
|
|
669
|
+
patchLabel: PATCH_LABEL,
|
|
670
|
+
type: _models.FormTypes.HUB
|
|
671
|
+
});
|
|
672
|
+
_onPageAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
673
|
+
preActionChecks();
|
|
674
|
+
postActionChecks(CUSTOM_ARGS); // Specific check for patchLabel done in here.
|
|
675
|
+
});
|
|
676
|
+
});
|
|
677
|
+
});
|
|
678
|
+
});
|