@ukhomeoffice/cop-react-form-renderer 5.0.0-alpha → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/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 +39 -13
- 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 +217 -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 +73 -22
- 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,583 @@
|
|
|
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 _onCYAAction = _interopRequireDefault(require("./onCYAAction"));
|
|
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
|
+
submissionErrorCalls: 0,
|
|
18
|
+
submissionErrorArgs: [],
|
|
19
|
+
submissionError: function submissionError(errors, addErrors) {
|
|
20
|
+
this.submissionErrorCalls += 1;
|
|
21
|
+
this.submissionErrorArgs.push(errors);
|
|
22
|
+
if (typeof addErrors === 'function') {
|
|
23
|
+
addErrors(errors);
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
reset: function reset() {
|
|
27
|
+
this.submissionErrorCalls = 0;
|
|
28
|
+
this.submissionErrorArgs = [];
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
jest.mock('./helpers', function () {
|
|
33
|
+
return {
|
|
34
|
+
canCYASubmitResult: true,
|
|
35
|
+
canCYASubmitCalls: 0,
|
|
36
|
+
canCYASubmit: function canCYASubmit() {
|
|
37
|
+
this.canCYASubmitCalls += 1;
|
|
38
|
+
return this.canCYASubmitResult;
|
|
39
|
+
},
|
|
40
|
+
getNextPageIdCalls: 0,
|
|
41
|
+
getNextPageId: function getNextPageId() {
|
|
42
|
+
this.getNextPageIdCalls += 1;
|
|
43
|
+
return 'page2';
|
|
44
|
+
},
|
|
45
|
+
getFormStateCalls: 0,
|
|
46
|
+
getFormState: function getFormState() {
|
|
47
|
+
this.getFormStateCalls += 1;
|
|
48
|
+
return {};
|
|
49
|
+
},
|
|
50
|
+
getSubmissionStatusCalls: 0,
|
|
51
|
+
getSubmissionStatus: function getSubmissionStatus() {
|
|
52
|
+
this.getSubmissionStatusCalls += 1;
|
|
53
|
+
return 'Good to go!';
|
|
54
|
+
},
|
|
55
|
+
reset: function reset() {
|
|
56
|
+
this.canCYASubmitCalls = 0;
|
|
57
|
+
this.canCYASubmitResult = true;
|
|
58
|
+
this.getFormStateCalls = 0;
|
|
59
|
+
this.getNextPageIdCalls = 0;
|
|
60
|
+
this.getFormStateCalls = 0;
|
|
61
|
+
this.getSubmissionStatusCalls = 0;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
jest.mock('../../utils', function () {
|
|
66
|
+
return {
|
|
67
|
+
Format: {
|
|
68
|
+
formCalls: 0,
|
|
69
|
+
form: function form() {
|
|
70
|
+
this.formCalls += 1;
|
|
71
|
+
return {
|
|
72
|
+
id: 'formId'
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
reset: function reset() {
|
|
77
|
+
this.Format.formCalls = 0;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
describe('components.FormRenderer.onCYAAction', function () {
|
|
82
|
+
var MOCK_HOOKS = {
|
|
83
|
+
onSubmitCalls: 0,
|
|
84
|
+
onSubmitArgs: [],
|
|
85
|
+
onSubmit: function onSubmit(type, payload, onSuccess, onError) {
|
|
86
|
+
this.onSubmitCalls += 1;
|
|
87
|
+
this.onSubmitArgs.push({
|
|
88
|
+
type: type,
|
|
89
|
+
payload: payload
|
|
90
|
+
});
|
|
91
|
+
if (typeof onSuccess === 'function') {
|
|
92
|
+
onSuccess();
|
|
93
|
+
}
|
|
94
|
+
// onError would not normally be called alongside
|
|
95
|
+
// onSuccess, we're just doing it here to make sure
|
|
96
|
+
// the expected function chain is called.
|
|
97
|
+
if (typeof onError === 'function') {
|
|
98
|
+
onError(['an example error']);
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
onFormCompleteCalls: 0,
|
|
102
|
+
onFormComplete: function onFormComplete() {
|
|
103
|
+
this.onFormCompleteCalls += 1;
|
|
104
|
+
},
|
|
105
|
+
onCancelCalls: 0,
|
|
106
|
+
onCancel: function onCancel() {
|
|
107
|
+
this.onCancelCalls += 1;
|
|
108
|
+
},
|
|
109
|
+
reset: function reset() {
|
|
110
|
+
this.onSubmitCalls = 0;
|
|
111
|
+
this.onSubmitArgs = [];
|
|
112
|
+
this.onFormCompleteCalls = 0;
|
|
113
|
+
this.onCancelCalls = 0;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
var setPagePointCalls = 0;
|
|
117
|
+
var setPagePointArgs = [];
|
|
118
|
+
var mockSetPagePoint = function mockSetPagePoint(point) {
|
|
119
|
+
setPagePointCalls += 1;
|
|
120
|
+
setPagePointArgs.push(point);
|
|
121
|
+
};
|
|
122
|
+
var setDataCalls = 0;
|
|
123
|
+
var setDataArgs = [];
|
|
124
|
+
var mockSetData = function mockSetData(data) {
|
|
125
|
+
setDataCalls += 1;
|
|
126
|
+
setDataArgs.push(data);
|
|
127
|
+
};
|
|
128
|
+
var onPageChangeCalls = 0;
|
|
129
|
+
var onPageChangeArgs = [];
|
|
130
|
+
var mockOnPageChange = function mockOnPageChange(pageId) {
|
|
131
|
+
onPageChangeCalls += 1;
|
|
132
|
+
onPageChangeArgs.push(pageId);
|
|
133
|
+
};
|
|
134
|
+
var addErrorsCalls = 0;
|
|
135
|
+
var addErrorsArgs = [];
|
|
136
|
+
var mockAddErrors = function mockAddErrors(errors) {
|
|
137
|
+
addErrorsCalls += 1;
|
|
138
|
+
addErrorsArgs.push(errors);
|
|
139
|
+
};
|
|
140
|
+
var COMPONENTS = [{
|
|
141
|
+
id: 'alpha',
|
|
142
|
+
fieldId: 'alpha'
|
|
143
|
+
}, {
|
|
144
|
+
id: 'bravo',
|
|
145
|
+
fieldId: 'bravo'
|
|
146
|
+
}, {
|
|
147
|
+
id: 'charlie',
|
|
148
|
+
fieldId: 'charlie'
|
|
149
|
+
}, {
|
|
150
|
+
id: 'delta',
|
|
151
|
+
fieldId: 'delta'
|
|
152
|
+
}];
|
|
153
|
+
var PAGES = [{
|
|
154
|
+
id: 'page1',
|
|
155
|
+
components: [_objectSpread({}, COMPONENTS[0]), _objectSpread({}, COMPONENTS[1])]
|
|
156
|
+
}, {
|
|
157
|
+
id: 'page2',
|
|
158
|
+
components: [_objectSpread({}, COMPONENTS[2]), _objectSpread({}, COMPONENTS[3])]
|
|
159
|
+
}];
|
|
160
|
+
var CURRENT_TASK = {
|
|
161
|
+
name: 'testTask',
|
|
162
|
+
fullPages: PAGES
|
|
163
|
+
};
|
|
164
|
+
var ARGS = {
|
|
165
|
+
setPagePoint: mockSetPagePoint,
|
|
166
|
+
action: {
|
|
167
|
+
type: _models.PageAction.TYPES.SUBMIT
|
|
168
|
+
},
|
|
169
|
+
pages: PAGES,
|
|
170
|
+
validate: function validate() {},
|
|
171
|
+
components: COMPONENTS,
|
|
172
|
+
data: {},
|
|
173
|
+
setData: mockSetData,
|
|
174
|
+
type: _models.FormTypes.FORM_WITH_TASK,
|
|
175
|
+
pageId: 'alpha',
|
|
176
|
+
currentTask: CURRENT_TASK,
|
|
177
|
+
hooks: MOCK_HOOKS,
|
|
178
|
+
addErrors: mockAddErrors,
|
|
179
|
+
hub: _models.HubFormats.TASK,
|
|
180
|
+
onPageChange: mockOnPageChange,
|
|
181
|
+
formState: _helpers.default.getFormState('alpha', PAGES, null)
|
|
182
|
+
};
|
|
183
|
+
beforeEach(function () {
|
|
184
|
+
_handlers.default.reset();
|
|
185
|
+
_helpers.default.reset();
|
|
186
|
+
_utils.default.reset();
|
|
187
|
+
MOCK_HOOKS.reset();
|
|
188
|
+
setPagePointCalls = 0;
|
|
189
|
+
setPagePointArgs = [];
|
|
190
|
+
setDataCalls = 0;
|
|
191
|
+
setDataArgs = [];
|
|
192
|
+
onPageChangeCalls = 0;
|
|
193
|
+
onPageChangeArgs = [];
|
|
194
|
+
addErrorsCalls = 0;
|
|
195
|
+
addErrorsArgs = [];
|
|
196
|
+
});
|
|
197
|
+
describe('with a page action of PageAction.TYPES.SUBMIT', function () {
|
|
198
|
+
it('should handle a hub format of HubFormats.CYA', function () {
|
|
199
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
200
|
+
hub: _models.HubFormats.CYA
|
|
201
|
+
});
|
|
202
|
+
_onCYAAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
203
|
+
expect(setPagePointCalls).toEqual(1);
|
|
204
|
+
expect(setPagePointArgs[0]).toEqual('submit');
|
|
205
|
+
expect(_helpers.default.canCYASubmitCalls).toEqual(1);
|
|
206
|
+
expect(_utils.default.Format.formCalls).toEqual(1);
|
|
207
|
+
expect(_helpers.default.getSubmissionStatusCalls).toEqual(1);
|
|
208
|
+
expect(setDataCalls).toEqual(1);
|
|
209
|
+
expect(setDataArgs[0]).toEqual({
|
|
210
|
+
id: 'formId',
|
|
211
|
+
formStatus: 'Good to go!'
|
|
212
|
+
});
|
|
213
|
+
expect(MOCK_HOOKS.onSubmitCalls).toEqual(1);
|
|
214
|
+
expect(MOCK_HOOKS.onSubmitArgs[0]).toEqual({
|
|
215
|
+
type: _models.PageAction.TYPES.SUBMIT,
|
|
216
|
+
payload: {
|
|
217
|
+
id: 'formId',
|
|
218
|
+
formStatus: 'Good to go!'
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
// Checking the onSuccess branch.
|
|
223
|
+
expect(MOCK_HOOKS.onFormCompleteCalls).toEqual(1);
|
|
224
|
+
|
|
225
|
+
// Checking the onError branch.
|
|
226
|
+
expect(_handlers.default.submissionErrorCalls).toEqual(1);
|
|
227
|
+
expect(_handlers.default.submissionErrorArgs[0]).toEqual(['an example error']);
|
|
228
|
+
expect(addErrorsCalls).toEqual(1);
|
|
229
|
+
expect(addErrorsArgs[0]).toEqual(['an example error']);
|
|
230
|
+
});
|
|
231
|
+
it('should handle a hub format of HubFormats.TASK', function () {
|
|
232
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
233
|
+
hub: _models.HubFormats.TASK
|
|
234
|
+
});
|
|
235
|
+
_onCYAAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
236
|
+
expect(setPagePointCalls).toEqual(1);
|
|
237
|
+
expect(setPagePointArgs[0]).toEqual('submit');
|
|
238
|
+
expect(_helpers.default.canCYASubmitCalls).toEqual(1);
|
|
239
|
+
expect(_utils.default.Format.formCalls).toEqual(1);
|
|
240
|
+
expect(_helpers.default.getSubmissionStatusCalls).toEqual(1);
|
|
241
|
+
expect(setDataCalls).toEqual(1);
|
|
242
|
+
expect(setDataArgs[0]).toEqual({
|
|
243
|
+
id: 'formId',
|
|
244
|
+
formStatus: 'Good to go!'
|
|
245
|
+
});
|
|
246
|
+
expect(MOCK_HOOKS.onSubmitCalls).toEqual(1);
|
|
247
|
+
expect(MOCK_HOOKS.onSubmitArgs[0]).toEqual({
|
|
248
|
+
type: _models.PageAction.TYPES.SUBMIT,
|
|
249
|
+
payload: {
|
|
250
|
+
id: 'formId',
|
|
251
|
+
formStatus: 'Good to go!'
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
// Checking the onSuccess branch.
|
|
256
|
+
expect(MOCK_HOOKS.onFormCompleteCalls).toEqual(1);
|
|
257
|
+
|
|
258
|
+
// Checking the onError branch.
|
|
259
|
+
expect(_handlers.default.submissionErrorCalls).toEqual(1);
|
|
260
|
+
expect(_handlers.default.submissionErrorArgs[0]).toEqual(['an example error']);
|
|
261
|
+
expect(addErrorsCalls).toEqual(1);
|
|
262
|
+
expect(addErrorsArgs[0]).toEqual(['an example error']);
|
|
263
|
+
});
|
|
264
|
+
it('should handle no hub', function () {
|
|
265
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
266
|
+
hub: null
|
|
267
|
+
});
|
|
268
|
+
_onCYAAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
269
|
+
expect(setPagePointCalls).toEqual(1);
|
|
270
|
+
expect(setPagePointArgs[0]).toEqual('submit');
|
|
271
|
+
expect(_helpers.default.canCYASubmitCalls).toEqual(1);
|
|
272
|
+
expect(_utils.default.Format.formCalls).toEqual(1);
|
|
273
|
+
expect(_helpers.default.getSubmissionStatusCalls).toEqual(1);
|
|
274
|
+
expect(setDataCalls).toEqual(1);
|
|
275
|
+
expect(setDataArgs[0]).toEqual({
|
|
276
|
+
id: 'formId',
|
|
277
|
+
formStatus: 'Good to go!'
|
|
278
|
+
});
|
|
279
|
+
expect(MOCK_HOOKS.onSubmitCalls).toEqual(1);
|
|
280
|
+
expect(MOCK_HOOKS.onSubmitArgs[0]).toEqual({
|
|
281
|
+
type: _models.PageAction.TYPES.SUBMIT,
|
|
282
|
+
payload: {
|
|
283
|
+
id: 'formId',
|
|
284
|
+
formStatus: 'Good to go!'
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
// Checking the onSuccess branch.
|
|
289
|
+
expect(MOCK_HOOKS.onFormCompleteCalls).toEqual(1);
|
|
290
|
+
|
|
291
|
+
// Checking the onError branch.
|
|
292
|
+
expect(_handlers.default.submissionErrorCalls).toEqual(1);
|
|
293
|
+
expect(_handlers.default.submissionErrorArgs[0]).toEqual(['an example error']);
|
|
294
|
+
expect(addErrorsCalls).toEqual(1);
|
|
295
|
+
expect(addErrorsArgs[0]).toEqual(['an example error']);
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
describe('with a page action of PageAction.TYPES.SAVE_AND_CONTINUE', function () {
|
|
299
|
+
it('should validate if action.validate is not defined', function () {
|
|
300
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
301
|
+
action: {
|
|
302
|
+
type: _models.PageAction.TYPES.SAVE_AND_CONTINUE
|
|
303
|
+
},
|
|
304
|
+
hub: _models.HubFormats.TASK
|
|
305
|
+
});
|
|
306
|
+
_onCYAAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
307
|
+
expect(_helpers.default.canCYASubmitCalls).toEqual(1); // Validating.
|
|
308
|
+
expect(_utils.default.Format.formCalls).toEqual(1);
|
|
309
|
+
expect(_helpers.default.getSubmissionStatusCalls).toEqual(1);
|
|
310
|
+
expect(setDataCalls).toEqual(1);
|
|
311
|
+
expect(setDataArgs[0]).toEqual({
|
|
312
|
+
id: 'formId',
|
|
313
|
+
formStatus: 'Good to go!'
|
|
314
|
+
});
|
|
315
|
+
expect(MOCK_HOOKS.onSubmitCalls).toEqual(1);
|
|
316
|
+
expect(MOCK_HOOKS.onSubmitArgs[0]).toEqual({
|
|
317
|
+
type: CUSTOM_ARGS.action.type,
|
|
318
|
+
payload: {
|
|
319
|
+
id: 'formId',
|
|
320
|
+
formStatus: 'Good to go!'
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
// Checking the onSuccess branch.
|
|
325
|
+
expect(onPageChangeCalls).toEqual(1);
|
|
326
|
+
expect(onPageChangeArgs[0]).toEqual(_models.FormPages.HUB);
|
|
327
|
+
|
|
328
|
+
// Checking the onError branch.
|
|
329
|
+
expect(_handlers.default.submissionErrorCalls).toEqual(1);
|
|
330
|
+
expect(_handlers.default.submissionErrorArgs[0]).toEqual(['an example error']);
|
|
331
|
+
expect(addErrorsCalls).toEqual(1);
|
|
332
|
+
expect(addErrorsArgs[0]).toEqual(['an example error']);
|
|
333
|
+
});
|
|
334
|
+
it('should validate if action.validate is true', function () {
|
|
335
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
336
|
+
action: {
|
|
337
|
+
type: _models.PageAction.TYPES.SAVE_AND_CONTINUE,
|
|
338
|
+
validate: true
|
|
339
|
+
},
|
|
340
|
+
hub: _models.HubFormats.TASK
|
|
341
|
+
});
|
|
342
|
+
_onCYAAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
343
|
+
expect(_helpers.default.canCYASubmitCalls).toEqual(1); // Validating.
|
|
344
|
+
expect(_utils.default.Format.formCalls).toEqual(1);
|
|
345
|
+
expect(_helpers.default.getSubmissionStatusCalls).toEqual(1);
|
|
346
|
+
expect(setDataCalls).toEqual(1);
|
|
347
|
+
expect(setDataArgs[0]).toEqual({
|
|
348
|
+
id: 'formId',
|
|
349
|
+
formStatus: 'Good to go!'
|
|
350
|
+
});
|
|
351
|
+
expect(MOCK_HOOKS.onSubmitCalls).toEqual(1);
|
|
352
|
+
expect(MOCK_HOOKS.onSubmitArgs[0]).toEqual({
|
|
353
|
+
type: CUSTOM_ARGS.action.type,
|
|
354
|
+
payload: {
|
|
355
|
+
id: 'formId',
|
|
356
|
+
formStatus: 'Good to go!'
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
// Checking the onSuccess branch.
|
|
361
|
+
expect(onPageChangeCalls).toEqual(1);
|
|
362
|
+
expect(onPageChangeArgs[0]).toEqual(_models.FormPages.HUB);
|
|
363
|
+
|
|
364
|
+
// Checking the onError branch.
|
|
365
|
+
expect(_handlers.default.submissionErrorCalls).toEqual(1);
|
|
366
|
+
expect(_handlers.default.submissionErrorArgs[0]).toEqual(['an example error']);
|
|
367
|
+
expect(addErrorsCalls).toEqual(1);
|
|
368
|
+
expect(addErrorsArgs[0]).toEqual(['an example error']);
|
|
369
|
+
});
|
|
370
|
+
it('should not validate if action.validate is false', function () {
|
|
371
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
372
|
+
action: {
|
|
373
|
+
type: _models.PageAction.TYPES.SAVE_AND_CONTINUE,
|
|
374
|
+
validate: false
|
|
375
|
+
},
|
|
376
|
+
hub: _models.HubFormats.TASK
|
|
377
|
+
});
|
|
378
|
+
_onCYAAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
379
|
+
|
|
380
|
+
// Validation.
|
|
381
|
+
expect(_helpers.default.canCYASubmitCalls).toEqual(0);
|
|
382
|
+
|
|
383
|
+
// Everything after this point should be normal, we just
|
|
384
|
+
// haven't validated this time round.
|
|
385
|
+
expect(_utils.default.Format.formCalls).toEqual(1);
|
|
386
|
+
expect(_helpers.default.getSubmissionStatusCalls).toEqual(1);
|
|
387
|
+
expect(setDataCalls).toEqual(1);
|
|
388
|
+
expect(setDataArgs[0]).toEqual({
|
|
389
|
+
id: 'formId',
|
|
390
|
+
formStatus: 'Good to go!'
|
|
391
|
+
});
|
|
392
|
+
expect(MOCK_HOOKS.onSubmitCalls).toEqual(1);
|
|
393
|
+
expect(MOCK_HOOKS.onSubmitArgs[0]).toEqual({
|
|
394
|
+
type: CUSTOM_ARGS.action.type,
|
|
395
|
+
payload: {
|
|
396
|
+
id: 'formId',
|
|
397
|
+
formStatus: 'Good to go!'
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
// Checking the onSuccess branch.
|
|
402
|
+
expect(onPageChangeCalls).toEqual(1);
|
|
403
|
+
expect(onPageChangeArgs[0]).toEqual(_models.FormPages.HUB);
|
|
404
|
+
|
|
405
|
+
// Checking the onError branch.
|
|
406
|
+
expect(_handlers.default.submissionErrorCalls).toEqual(1);
|
|
407
|
+
expect(_handlers.default.submissionErrorArgs[0]).toEqual(['an example error']);
|
|
408
|
+
expect(addErrorsCalls).toEqual(1);
|
|
409
|
+
expect(addErrorsArgs[0]).toEqual(['an example error']);
|
|
410
|
+
});
|
|
411
|
+
});
|
|
412
|
+
describe('with an action type of PageAction.TYPES.SAVE_AND_RETURN', function () {
|
|
413
|
+
it('should validate if action.validate is not defined', function () {
|
|
414
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
415
|
+
action: {
|
|
416
|
+
type: _models.PageAction.TYPES.SAVE_AND_RETURN
|
|
417
|
+
},
|
|
418
|
+
hub: _models.HubFormats.TASK
|
|
419
|
+
});
|
|
420
|
+
_onCYAAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
421
|
+
expect(_helpers.default.canCYASubmitCalls).toEqual(1); // Validating.
|
|
422
|
+
expect(_utils.default.Format.formCalls).toEqual(1);
|
|
423
|
+
expect(_helpers.default.getSubmissionStatusCalls).toEqual(1);
|
|
424
|
+
expect(setDataCalls).toEqual(1);
|
|
425
|
+
expect(setDataArgs[0]).toEqual({
|
|
426
|
+
id: 'formId',
|
|
427
|
+
formStatus: 'Good to go!'
|
|
428
|
+
});
|
|
429
|
+
expect(MOCK_HOOKS.onSubmitCalls).toEqual(1);
|
|
430
|
+
expect(MOCK_HOOKS.onSubmitArgs[0]).toEqual({
|
|
431
|
+
type: CUSTOM_ARGS.action.type,
|
|
432
|
+
payload: {
|
|
433
|
+
id: 'formId',
|
|
434
|
+
formStatus: 'Good to go!'
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
// Checking the onSuccess branch.
|
|
439
|
+
expect(onPageChangeCalls).toEqual(1);
|
|
440
|
+
expect(onPageChangeArgs[0]).toEqual(_models.FormPages.HUB);
|
|
441
|
+
|
|
442
|
+
// Checking the onError branch.
|
|
443
|
+
expect(_handlers.default.submissionErrorCalls).toEqual(1);
|
|
444
|
+
expect(_handlers.default.submissionErrorArgs[0]).toEqual(['an example error']);
|
|
445
|
+
expect(addErrorsCalls).toEqual(1);
|
|
446
|
+
expect(addErrorsArgs[0]).toEqual(['an example error']);
|
|
447
|
+
});
|
|
448
|
+
it('should validate if action.validate is true', function () {
|
|
449
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
450
|
+
action: {
|
|
451
|
+
type: _models.PageAction.TYPES.SAVE_AND_RETURN,
|
|
452
|
+
validate: true
|
|
453
|
+
},
|
|
454
|
+
hub: _models.HubFormats.TASK
|
|
455
|
+
});
|
|
456
|
+
_onCYAAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
457
|
+
expect(_helpers.default.canCYASubmitCalls).toEqual(1); // Validating.
|
|
458
|
+
expect(_utils.default.Format.formCalls).toEqual(1);
|
|
459
|
+
expect(_helpers.default.getSubmissionStatusCalls).toEqual(1);
|
|
460
|
+
expect(setDataCalls).toEqual(1);
|
|
461
|
+
expect(setDataArgs[0]).toEqual({
|
|
462
|
+
id: 'formId',
|
|
463
|
+
formStatus: 'Good to go!'
|
|
464
|
+
});
|
|
465
|
+
expect(MOCK_HOOKS.onSubmitCalls).toEqual(1);
|
|
466
|
+
expect(MOCK_HOOKS.onSubmitArgs[0]).toEqual({
|
|
467
|
+
type: CUSTOM_ARGS.action.type,
|
|
468
|
+
payload: {
|
|
469
|
+
id: 'formId',
|
|
470
|
+
formStatus: 'Good to go!'
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
// Checking the onSuccess branch.
|
|
475
|
+
expect(onPageChangeCalls).toEqual(1);
|
|
476
|
+
expect(onPageChangeArgs[0]).toEqual(_models.FormPages.HUB);
|
|
477
|
+
|
|
478
|
+
// Checking the onError branch.
|
|
479
|
+
expect(_handlers.default.submissionErrorCalls).toEqual(1);
|
|
480
|
+
expect(_handlers.default.submissionErrorArgs[0]).toEqual(['an example error']);
|
|
481
|
+
expect(addErrorsCalls).toEqual(1);
|
|
482
|
+
expect(addErrorsArgs[0]).toEqual(['an example error']);
|
|
483
|
+
});
|
|
484
|
+
it('should not validate if action.validate is false', function () {
|
|
485
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
486
|
+
action: {
|
|
487
|
+
type: _models.PageAction.TYPES.SAVE_AND_RETURN,
|
|
488
|
+
validate: false
|
|
489
|
+
},
|
|
490
|
+
hub: _models.HubFormats.TASK
|
|
491
|
+
});
|
|
492
|
+
_onCYAAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
493
|
+
|
|
494
|
+
// Validation.
|
|
495
|
+
expect(_helpers.default.canCYASubmitCalls).toEqual(0);
|
|
496
|
+
|
|
497
|
+
// Everything after this point should be normal, we just
|
|
498
|
+
// haven't validated this time round.
|
|
499
|
+
expect(_utils.default.Format.formCalls).toEqual(1);
|
|
500
|
+
expect(_helpers.default.getSubmissionStatusCalls).toEqual(1);
|
|
501
|
+
expect(setDataCalls).toEqual(1);
|
|
502
|
+
expect(setDataArgs[0]).toEqual({
|
|
503
|
+
id: 'formId',
|
|
504
|
+
formStatus: 'Good to go!'
|
|
505
|
+
});
|
|
506
|
+
expect(MOCK_HOOKS.onSubmitCalls).toEqual(1);
|
|
507
|
+
expect(MOCK_HOOKS.onSubmitArgs[0]).toEqual({
|
|
508
|
+
type: CUSTOM_ARGS.action.type,
|
|
509
|
+
payload: {
|
|
510
|
+
id: 'formId',
|
|
511
|
+
formStatus: 'Good to go!'
|
|
512
|
+
}
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
// Checking the onSuccess branch.
|
|
516
|
+
expect(onPageChangeCalls).toEqual(1);
|
|
517
|
+
expect(onPageChangeArgs[0]).toEqual(_models.FormPages.HUB);
|
|
518
|
+
|
|
519
|
+
// Checking the onError branch.
|
|
520
|
+
expect(_handlers.default.submissionErrorCalls).toEqual(1);
|
|
521
|
+
expect(_handlers.default.submissionErrorArgs[0]).toEqual(['an example error']);
|
|
522
|
+
expect(addErrorsCalls).toEqual(1);
|
|
523
|
+
expect(addErrorsArgs[0]).toEqual(['an example error']);
|
|
524
|
+
});
|
|
525
|
+
it('should call onPageChange with undefined if type is FormTypes.TASK', function () {
|
|
526
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
527
|
+
action: {
|
|
528
|
+
type: _models.PageAction.TYPES.SAVE_AND_RETURN,
|
|
529
|
+
validate: true
|
|
530
|
+
},
|
|
531
|
+
hub: _models.HubFormats.TASK,
|
|
532
|
+
type: _models.FormTypes.TASK
|
|
533
|
+
});
|
|
534
|
+
_onCYAAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
535
|
+
expect(_helpers.default.canCYASubmitCalls).toEqual(1); // Validating.
|
|
536
|
+
expect(_utils.default.Format.formCalls).toEqual(1);
|
|
537
|
+
expect(_helpers.default.getSubmissionStatusCalls).toEqual(1);
|
|
538
|
+
expect(setDataCalls).toEqual(1);
|
|
539
|
+
expect(setDataArgs[0]).toEqual({
|
|
540
|
+
id: 'formId',
|
|
541
|
+
formStatus: 'Good to go!'
|
|
542
|
+
});
|
|
543
|
+
expect(MOCK_HOOKS.onSubmitCalls).toEqual(1);
|
|
544
|
+
expect(MOCK_HOOKS.onSubmitArgs[0]).toEqual({
|
|
545
|
+
type: CUSTOM_ARGS.action.type,
|
|
546
|
+
payload: {
|
|
547
|
+
id: 'formId',
|
|
548
|
+
formStatus: 'Good to go!'
|
|
549
|
+
}
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
// Checking the onSuccess branch.
|
|
553
|
+
expect(onPageChangeCalls).toEqual(1);
|
|
554
|
+
expect(onPageChangeArgs[0]).toEqual(undefined);
|
|
555
|
+
|
|
556
|
+
// Checking the onError branch.
|
|
557
|
+
expect(_handlers.default.submissionErrorCalls).toEqual(1);
|
|
558
|
+
expect(_handlers.default.submissionErrorArgs[0]).toEqual(['an example error']);
|
|
559
|
+
expect(addErrorsCalls).toEqual(1);
|
|
560
|
+
expect(addErrorsArgs[0]).toEqual(['an example error']);
|
|
561
|
+
});
|
|
562
|
+
});
|
|
563
|
+
it('should handle a page action type of PageAction.TYPES.NAVIGATE', function () {
|
|
564
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
565
|
+
action: {
|
|
566
|
+
type: _models.PageAction.TYPES.NAVIGATE,
|
|
567
|
+
page: 'page2'
|
|
568
|
+
}
|
|
569
|
+
});
|
|
570
|
+
_onCYAAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
571
|
+
expect(onPageChangeCalls).toEqual(1);
|
|
572
|
+
expect(onPageChangeArgs[0]).toEqual('page2');
|
|
573
|
+
});
|
|
574
|
+
it('should handle a page action type of PageAction.TYPES.CANCEL', function () {
|
|
575
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
576
|
+
action: {
|
|
577
|
+
type: _models.PageAction.TYPES.CANCEL
|
|
578
|
+
}
|
|
579
|
+
});
|
|
580
|
+
_onCYAAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
581
|
+
expect(MOCK_HOOKS.onCancelCalls).toEqual(1);
|
|
582
|
+
});
|
|
583
|
+
});
|