@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
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _getUpdatedSectionStates = _interopRequireDefault(require("./getUpdatedSectionStates"));
|
|
4
3
|
var _models = require("../../../models");
|
|
4
|
+
var _getUpdatedSectionStates = _interopRequireDefault(require("./getUpdatedSectionStates"));
|
|
5
5
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
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); }
|
|
7
|
+
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; }
|
|
8
|
+
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; }
|
|
9
|
+
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; }
|
|
10
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
11
|
+
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); }
|
|
8
12
|
describe('components.FormRenderer.helpers.getUpdatedSectionStates', function () {
|
|
9
13
|
describe('sequential tasks', function () {
|
|
10
14
|
it("should set all tasks to '".concat(_models.TaskStates.TYPES.CANNOT_START_YET, "' excluding the first which should be '").concat(_models.TaskStates.TYPES.NOT_STARTED, "'"), function () {
|
|
@@ -31,11 +35,11 @@ describe('components.FormRenderer.helpers.getUpdatedSectionStates', function ()
|
|
|
31
35
|
}]
|
|
32
36
|
}];
|
|
33
37
|
var updatedSections = (0, _getUpdatedSectionStates.default)(SECTIONS, {});
|
|
34
|
-
expect(updatedSections[0][0].state).toEqual(_models.TaskStates.TYPES.NOT_STARTED);
|
|
35
|
-
expect(updatedSections[0][1].state).toEqual(_models.TaskStates.TYPES.CANNOT_START_YET);
|
|
36
|
-
expect(updatedSections[1][0].state).toEqual(_models.TaskStates.TYPES.CANNOT_START_YET);
|
|
37
|
-
expect(updatedSections[1][1].state).toEqual(_models.TaskStates.TYPES.CANNOT_START_YET);
|
|
38
|
-
expect(updatedSections[1][2].state).toEqual(_models.TaskStates.TYPES.CANNOT_START_YET);
|
|
38
|
+
expect(updatedSections[0].tasks[0].state).toEqual(_models.TaskStates.TYPES.NOT_STARTED);
|
|
39
|
+
expect(updatedSections[0].tasks[1].state).toEqual(_models.TaskStates.TYPES.CANNOT_START_YET);
|
|
40
|
+
expect(updatedSections[1].tasks[0].state).toEqual(_models.TaskStates.TYPES.CANNOT_START_YET);
|
|
41
|
+
expect(updatedSections[1].tasks[1].state).toEqual(_models.TaskStates.TYPES.CANNOT_START_YET);
|
|
42
|
+
expect(updatedSections[1].tasks[2].state).toEqual(_models.TaskStates.TYPES.CANNOT_START_YET);
|
|
39
43
|
});
|
|
40
44
|
it("should set tasks after any '".concat(_models.TaskStates.TYPES.COMPLETE, "' ones to '").concat(_models.TaskStates.TYPES.NOT_STARTED, "'"), function () {
|
|
41
45
|
var SECTIONS = [{
|
|
@@ -54,8 +58,8 @@ describe('components.FormRenderer.helpers.getUpdatedSectionStates', function ()
|
|
|
54
58
|
}
|
|
55
59
|
};
|
|
56
60
|
var updatedSections = (0, _getUpdatedSectionStates.default)(SECTIONS, TASKS);
|
|
57
|
-
expect(updatedSections[0][0].state).toEqual(_models.TaskStates.TYPES.COMPLETE);
|
|
58
|
-
expect(updatedSections[0][1].state).toEqual(_models.TaskStates.TYPES.NOT_STARTED);
|
|
61
|
+
expect(updatedSections[0].tasks[0].state).toEqual(_models.TaskStates.TYPES.COMPLETE);
|
|
62
|
+
expect(updatedSections[0].tasks[1].state).toEqual(_models.TaskStates.TYPES.NOT_STARTED);
|
|
59
63
|
});
|
|
60
64
|
it("should set tasks after any '".concat(_models.TaskStates.TYPES.COMPLETE, "' ones to '").concat(_models.TaskStates.TYPES.NOT_STARTED, " across different sections'"), function () {
|
|
61
65
|
var SECTIONS = [{
|
|
@@ -86,10 +90,10 @@ describe('components.FormRenderer.helpers.getUpdatedSectionStates', function ()
|
|
|
86
90
|
}
|
|
87
91
|
};
|
|
88
92
|
var updatedSections = (0, _getUpdatedSectionStates.default)(SECTIONS, TASKS);
|
|
89
|
-
expect(updatedSections[0][0].state).toEqual(_models.TaskStates.TYPES.COMPLETE);
|
|
90
|
-
expect(updatedSections[0][1].state).toEqual(_models.TaskStates.TYPES.COMPLETE);
|
|
91
|
-
expect(updatedSections[1][0].state).toEqual(_models.TaskStates.TYPES.NOT_STARTED);
|
|
92
|
-
expect(updatedSections[1][1].state).toEqual(_models.TaskStates.TYPES.CANNOT_START_YET);
|
|
93
|
+
expect(updatedSections[0].tasks[0].state).toEqual(_models.TaskStates.TYPES.COMPLETE);
|
|
94
|
+
expect(updatedSections[0].tasks[1].state).toEqual(_models.TaskStates.TYPES.COMPLETE);
|
|
95
|
+
expect(updatedSections[1].tasks[0].state).toEqual(_models.TaskStates.TYPES.NOT_STARTED);
|
|
96
|
+
expect(updatedSections[1].tasks[1].state).toEqual(_models.TaskStates.TYPES.CANNOT_START_YET);
|
|
93
97
|
});
|
|
94
98
|
it("should set tasks to '".concat(_models.TaskStates.TYPES.IN_PROGRESS, "' if they have a current page but are not complete"), function () {
|
|
95
99
|
var SECTIONS = [{
|
|
@@ -109,9 +113,207 @@ describe('components.FormRenderer.helpers.getUpdatedSectionStates', function ()
|
|
|
109
113
|
}
|
|
110
114
|
};
|
|
111
115
|
var updatedSections = (0, _getUpdatedSectionStates.default)(SECTIONS, TASKS);
|
|
112
|
-
expect(updatedSections[0][0].state).toEqual(_models.TaskStates.TYPES.IN_PROGRESS);
|
|
113
|
-
expect(updatedSections[0][1].state).toEqual(_models.TaskStates.TYPES.CANNOT_START_YET);
|
|
116
|
+
expect(updatedSections[0].tasks[0].state).toEqual(_models.TaskStates.TYPES.IN_PROGRESS);
|
|
117
|
+
expect(updatedSections[0].tasks[1].state).toEqual(_models.TaskStates.TYPES.CANNOT_START_YET);
|
|
118
|
+
});
|
|
119
|
+
it("should set the status of any tasks in a section with a failed show_when to '".concat(_models.TaskStates.TYPES.SKIPPED, "'"), function () {
|
|
120
|
+
var SECTIONS = [{
|
|
121
|
+
name: 'Add event details',
|
|
122
|
+
tasks: [{
|
|
123
|
+
name: 'Date, location and mode details',
|
|
124
|
+
pages: ['eventDate', 'eventMode']
|
|
125
|
+
}, {
|
|
126
|
+
name: 'Officer and agency details',
|
|
127
|
+
pages: ['officeDetails']
|
|
128
|
+
}]
|
|
129
|
+
}, {
|
|
130
|
+
name: 'Add people details',
|
|
131
|
+
show_when: {
|
|
132
|
+
field: 'field',
|
|
133
|
+
op: '=',
|
|
134
|
+
value: 'showMe'
|
|
135
|
+
},
|
|
136
|
+
tasks: [{
|
|
137
|
+
name: 'People details',
|
|
138
|
+
pages: ['firstName', 'surname']
|
|
139
|
+
}, {
|
|
140
|
+
name: 'Immigration details',
|
|
141
|
+
pages: ['immigrationDate']
|
|
142
|
+
}]
|
|
143
|
+
}];
|
|
144
|
+
var TASKS = {
|
|
145
|
+
'Date, location and mode details': {
|
|
146
|
+
complete: true
|
|
147
|
+
},
|
|
148
|
+
'Officer and agency details': {
|
|
149
|
+
complete: true
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
var DATA = {
|
|
153
|
+
field: 'hideMe'
|
|
154
|
+
};
|
|
155
|
+
var updatedSections = (0, _getUpdatedSectionStates.default)(SECTIONS, TASKS, false, DATA);
|
|
156
|
+
expect(updatedSections[0].tasks[0].state).toEqual(_models.TaskStates.TYPES.COMPLETE);
|
|
157
|
+
expect(updatedSections[0].tasks[1].state).toEqual(_models.TaskStates.TYPES.COMPLETE);
|
|
158
|
+
expect(updatedSections[1].skipped).toEqual(true);
|
|
159
|
+
expect(updatedSections[1].tasks[0].state).toEqual(_models.TaskStates.TYPES.SKIPPED);
|
|
160
|
+
expect(updatedSections[1].tasks[1].state).toEqual(_models.TaskStates.TYPES.SKIPPED);
|
|
161
|
+
});
|
|
162
|
+
it("should set the status of any tasks with a failed show_when to '".concat(_models.TaskStates.TYPES.SKIPPED, "'"), function () {
|
|
163
|
+
var SECTIONS = [{
|
|
164
|
+
name: 'Add event details',
|
|
165
|
+
tasks: [{
|
|
166
|
+
name: 'Date, location and mode details',
|
|
167
|
+
pages: ['eventDate', 'eventMode'],
|
|
168
|
+
show_when: {
|
|
169
|
+
field: 'field',
|
|
170
|
+
op: '=',
|
|
171
|
+
value: 'showMe'
|
|
172
|
+
}
|
|
173
|
+
}, {
|
|
174
|
+
name: 'Officer and agency details',
|
|
175
|
+
pages: ['officeDetails'],
|
|
176
|
+
show_when: {
|
|
177
|
+
field: 'field',
|
|
178
|
+
op: '=',
|
|
179
|
+
value: 'hideMe'
|
|
180
|
+
}
|
|
181
|
+
}]
|
|
182
|
+
}];
|
|
183
|
+
var DATA = {
|
|
184
|
+
field: 'hideMe'
|
|
185
|
+
};
|
|
186
|
+
var updatedSections = (0, _getUpdatedSectionStates.default)(SECTIONS, {}, false, DATA);
|
|
187
|
+
expect(updatedSections[0].tasks[0].state).toEqual(_models.TaskStates.TYPES.SKIPPED);
|
|
188
|
+
expect(updatedSections[0].tasks[1].state).toEqual(_models.TaskStates.TYPES.NOT_STARTED);
|
|
189
|
+
});
|
|
190
|
+
it("should set the status of any tasks to '".concat(_models.TaskStates.TYPES.NOT_STARTED, "' if previous tasks within a section have been skipped"), function () {
|
|
191
|
+
var SECTIONS = [{
|
|
192
|
+
name: 'Add event details',
|
|
193
|
+
tasks: [{
|
|
194
|
+
name: 'task one',
|
|
195
|
+
pages: ['eventDate', 'eventMode'],
|
|
196
|
+
show_when: {
|
|
197
|
+
field: 'field',
|
|
198
|
+
op: '=',
|
|
199
|
+
value: 'hideMe'
|
|
200
|
+
}
|
|
201
|
+
}, {
|
|
202
|
+
name: 'task two',
|
|
203
|
+
pages: ['eventDate', 'eventMode'],
|
|
204
|
+
show_when: {
|
|
205
|
+
field: 'field',
|
|
206
|
+
op: '=',
|
|
207
|
+
value: 'showMe'
|
|
208
|
+
}
|
|
209
|
+
}, {
|
|
210
|
+
name: 'task three',
|
|
211
|
+
pages: ['eventDate', 'eventMode'],
|
|
212
|
+
show_when: {
|
|
213
|
+
field: 'field',
|
|
214
|
+
op: '=',
|
|
215
|
+
value: 'showMe'
|
|
216
|
+
}
|
|
217
|
+
}, {
|
|
218
|
+
name: 'task four',
|
|
219
|
+
pages: ['officeDetails'],
|
|
220
|
+
show_when: {
|
|
221
|
+
field: 'field',
|
|
222
|
+
op: '=',
|
|
223
|
+
value: 'hideMe'
|
|
224
|
+
}
|
|
225
|
+
}]
|
|
226
|
+
}];
|
|
227
|
+
var DATA = {
|
|
228
|
+
field: 'hideMe'
|
|
229
|
+
};
|
|
230
|
+
var TASKS = {
|
|
231
|
+
'task one': {
|
|
232
|
+
complete: true
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
var updatedSections = (0, _getUpdatedSectionStates.default)(SECTIONS, TASKS, false, DATA);
|
|
236
|
+
expect(updatedSections[0].tasks[0].state).toEqual(_models.TaskStates.TYPES.COMPLETE);
|
|
237
|
+
expect(updatedSections[0].tasks[1].state).toEqual(_models.TaskStates.TYPES.SKIPPED);
|
|
238
|
+
expect(updatedSections[0].tasks[2].state).toEqual(_models.TaskStates.TYPES.SKIPPED);
|
|
239
|
+
expect(updatedSections[0].tasks[3].state).toEqual(_models.TaskStates.TYPES.NOT_STARTED);
|
|
114
240
|
});
|
|
241
|
+
it("should set the status of any tasks to '".concat(_models.TaskStates.TYPES.NOT_STARTED, "' if previous tasks within the last section have been skipped"), function () {
|
|
242
|
+
var SECTIONS = [{
|
|
243
|
+
name: 'Add event details',
|
|
244
|
+
tasks: [{
|
|
245
|
+
name: 'task one',
|
|
246
|
+
pages: ['eventDate', 'eventMode'],
|
|
247
|
+
show_when: {
|
|
248
|
+
field: 'field',
|
|
249
|
+
op: '=',
|
|
250
|
+
value: 'showMe'
|
|
251
|
+
}
|
|
252
|
+
}, {
|
|
253
|
+
name: 'task two',
|
|
254
|
+
pages: ['officeDetails'],
|
|
255
|
+
show_when: {
|
|
256
|
+
field: 'field',
|
|
257
|
+
op: '=',
|
|
258
|
+
value: 'hideMe'
|
|
259
|
+
}
|
|
260
|
+
}]
|
|
261
|
+
}, {
|
|
262
|
+
name: 'Add people details',
|
|
263
|
+
tasks: [{
|
|
264
|
+
name: 'task three',
|
|
265
|
+
pages: ['eventDate', 'eventMode']
|
|
266
|
+
}]
|
|
267
|
+
}];
|
|
268
|
+
var DATA = {
|
|
269
|
+
field: 'showMe'
|
|
270
|
+
};
|
|
271
|
+
var TASKS = {
|
|
272
|
+
'task one': {
|
|
273
|
+
complete: true
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
var updatedSections = (0, _getUpdatedSectionStates.default)(SECTIONS, TASKS, false, DATA);
|
|
277
|
+
expect(updatedSections[0].tasks[0].state).toEqual(_models.TaskStates.TYPES.COMPLETE);
|
|
278
|
+
expect(updatedSections[0].tasks[1].state).toEqual(_models.TaskStates.TYPES.SKIPPED);
|
|
279
|
+
expect(updatedSections[1].tasks[0].state).toEqual(_models.TaskStates.TYPES.NOT_STARTED);
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
it("should set the status of any tasks to '".concat(_models.TaskStates.TYPES.NOT_STARTED, "' if previous tasks have been skipped"), function () {
|
|
283
|
+
var SECTIONS = [{
|
|
284
|
+
name: 'Add event details',
|
|
285
|
+
show_when: {
|
|
286
|
+
field: 'field',
|
|
287
|
+
op: '=',
|
|
288
|
+
value: 'showMe'
|
|
289
|
+
},
|
|
290
|
+
tasks: [{
|
|
291
|
+
name: 'Date, location and mode details',
|
|
292
|
+
pages: ['eventDate', 'eventMode']
|
|
293
|
+
}, {
|
|
294
|
+
name: 'Officer and agency details',
|
|
295
|
+
pages: ['officeDetails']
|
|
296
|
+
}]
|
|
297
|
+
}, {
|
|
298
|
+
name: 'Add people details',
|
|
299
|
+
tasks: [{
|
|
300
|
+
name: 'People details',
|
|
301
|
+
pages: ['firstName', 'surname']
|
|
302
|
+
}, {
|
|
303
|
+
name: 'Immigration details',
|
|
304
|
+
pages: ['immigrationDate']
|
|
305
|
+
}]
|
|
306
|
+
}];
|
|
307
|
+
var TASKS = {};
|
|
308
|
+
var DATA = {
|
|
309
|
+
field: 'hideMe'
|
|
310
|
+
};
|
|
311
|
+
var updatedSections = (0, _getUpdatedSectionStates.default)(SECTIONS, TASKS, false, DATA);
|
|
312
|
+
expect(updatedSections[0].skipped).toEqual(true);
|
|
313
|
+
expect(updatedSections[0].tasks[0].state).toEqual(_models.TaskStates.TYPES.SKIPPED);
|
|
314
|
+
expect(updatedSections[0].tasks[1].state).toEqual(_models.TaskStates.TYPES.SKIPPED);
|
|
315
|
+
expect(updatedSections[1].tasks[0].state).toEqual(_models.TaskStates.TYPES.NOT_STARTED);
|
|
316
|
+
expect(updatedSections[1].tasks[1].state).toEqual(_models.TaskStates.TYPES.CANNOT_START_YET);
|
|
115
317
|
});
|
|
116
318
|
describe('non-sequential tasks', function () {
|
|
117
319
|
var NON_SEQUENTIAL = true;
|
|
@@ -136,10 +338,10 @@ describe('components.FormRenderer.helpers.getUpdatedSectionStates', function ()
|
|
|
136
338
|
}];
|
|
137
339
|
it("should set all states to '".concat(_models.TaskStates.TYPES.NOT_STARTED, "', except any that depend on others"), function () {
|
|
138
340
|
var RESULT = (0, _getUpdatedSectionStates.default)(SECTIONS, {}, NON_SEQUENTIAL);
|
|
139
|
-
expect(RESULT[0][0].state).toEqual(_models.TaskStates.TYPES.NOT_STARTED); // Alpha
|
|
140
|
-
expect(RESULT[0][1].state).toEqual(_models.TaskStates.TYPES.NOT_STARTED); // Bravo
|
|
141
|
-
expect(RESULT[1][0].state).toEqual(_models.TaskStates.TYPES.CANNOT_START_YET); // Charlie
|
|
142
|
-
expect(RESULT[2][0].state).toEqual(_models.TaskStates.TYPES.NOT_STARTED); // Delta
|
|
341
|
+
expect(RESULT[0].tasks[0].state).toEqual(_models.TaskStates.TYPES.NOT_STARTED); // Alpha
|
|
342
|
+
expect(RESULT[0].tasks[1].state).toEqual(_models.TaskStates.TYPES.NOT_STARTED); // Bravo
|
|
343
|
+
expect(RESULT[1].tasks[0].state).toEqual(_models.TaskStates.TYPES.CANNOT_START_YET); // Charlie
|
|
344
|
+
expect(RESULT[2].tasks[0].state).toEqual(_models.TaskStates.TYPES.NOT_STARTED); // Delta
|
|
143
345
|
});
|
|
144
346
|
|
|
145
347
|
it('should keep dependent state unable to start if any dependencies are not complete', function () {
|
|
@@ -148,13 +350,13 @@ describe('components.FormRenderer.helpers.getUpdatedSectionStates', function ()
|
|
|
148
350
|
complete: true
|
|
149
351
|
}
|
|
150
352
|
}, NON_SEQUENTIAL);
|
|
151
|
-
expect(ALPHA_COMPLETE[1][0].state).toEqual(_models.TaskStates.TYPES.CANNOT_START_YET); // Charlie
|
|
353
|
+
expect(ALPHA_COMPLETE[1].tasks[0].state).toEqual(_models.TaskStates.TYPES.CANNOT_START_YET); // Charlie
|
|
152
354
|
var BRAVO_COMPLETE = (0, _getUpdatedSectionStates.default)(SECTIONS, {
|
|
153
355
|
Bravo: {
|
|
154
356
|
complete: true
|
|
155
357
|
}
|
|
156
358
|
}, NON_SEQUENTIAL);
|
|
157
|
-
expect(BRAVO_COMPLETE[1][0].state).toEqual(_models.TaskStates.TYPES.CANNOT_START_YET); // Charlie
|
|
359
|
+
expect(BRAVO_COMPLETE[1].tasks[0].state).toEqual(_models.TaskStates.TYPES.CANNOT_START_YET); // Charlie
|
|
158
360
|
});
|
|
159
361
|
|
|
160
362
|
it('should allow dependent state to start if all dependencies are complete', function () {
|
|
@@ -168,8 +370,89 @@ describe('components.FormRenderer.helpers.getUpdatedSectionStates', function ()
|
|
|
168
370
|
'Delta': {}
|
|
169
371
|
};
|
|
170
372
|
var RESULT = (0, _getUpdatedSectionStates.default)(SECTIONS, TASKS, NON_SEQUENTIAL);
|
|
171
|
-
expect(RESULT[1][0].state).toEqual(_models.TaskStates.TYPES.NOT_STARTED); // Charlie
|
|
172
|
-
expect(RESULT[2][0].state).toEqual(_models.TaskStates.TYPES.NOT_STARTED); // Delta
|
|
373
|
+
expect(RESULT[1].tasks[0].state).toEqual(_models.TaskStates.TYPES.NOT_STARTED); // Charlie
|
|
374
|
+
expect(RESULT[2].tasks[0].state).toEqual(_models.TaskStates.TYPES.NOT_STARTED); // Delta
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
it('should not allow dependent state to start if incomplete dependencies are skipped, but skipped are not ignored', function () {
|
|
378
|
+
var TASKS = {
|
|
379
|
+
'Alpha': {
|
|
380
|
+
complete: true
|
|
381
|
+
},
|
|
382
|
+
'Bravo': {
|
|
383
|
+
complete: false,
|
|
384
|
+
state: _models.TaskStates.TYPES.SKIPPED
|
|
385
|
+
},
|
|
386
|
+
'Delta': {}
|
|
387
|
+
};
|
|
388
|
+
var RESULT = (0, _getUpdatedSectionStates.default)(SECTIONS, TASKS, NON_SEQUENTIAL);
|
|
389
|
+
expect(RESULT[1].tasks[0].state).toEqual(_models.TaskStates.TYPES.CANNOT_START_YET); // Charlie
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
it('should allow dependent state to start if incomplete dependencies are skipped, and skipped are ignored', function () {
|
|
393
|
+
var SKIPPABLE_SECTIONS = [SECTIONS[0], _objectSpread(_objectSpread({}, SECTIONS[1]), {}, {
|
|
394
|
+
tasks: [_objectSpread(_objectSpread({}, SECTIONS[1].tasks[0]), {}, {
|
|
395
|
+
ignoreSkipped: true
|
|
396
|
+
})]
|
|
397
|
+
}), SECTIONS[2]];
|
|
398
|
+
var TASKS = {
|
|
399
|
+
'Alpha': {
|
|
400
|
+
complete: true
|
|
401
|
+
},
|
|
402
|
+
'Bravo': {
|
|
403
|
+
complete: false,
|
|
404
|
+
state: _models.TaskStates.TYPES.SKIPPED
|
|
405
|
+
},
|
|
406
|
+
'Delta': {}
|
|
407
|
+
};
|
|
408
|
+
var RESULT = (0, _getUpdatedSectionStates.default)(SKIPPABLE_SECTIONS, TASKS, NON_SEQUENTIAL);
|
|
409
|
+
expect(RESULT[1].tasks[0].state).toEqual(_models.TaskStates.TYPES.NOT_STARTED); // Charlie
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
it('should automatically skip tasks that are not shown', function () {
|
|
413
|
+
var SHOW_WHEN_SECTIONS = [{
|
|
414
|
+
name: 'First',
|
|
415
|
+
tasks: [{
|
|
416
|
+
name: 'Alpha'
|
|
417
|
+
}]
|
|
418
|
+
}, {
|
|
419
|
+
name: 'Second',
|
|
420
|
+
tasks: [{
|
|
421
|
+
name: 'Bravo',
|
|
422
|
+
show_when: [{
|
|
423
|
+
field: 'echo',
|
|
424
|
+
op: '=',
|
|
425
|
+
value: 'foxtrot'
|
|
426
|
+
}, {
|
|
427
|
+
field: 'golf',
|
|
428
|
+
op: '=',
|
|
429
|
+
value: 'indigo'
|
|
430
|
+
} // shouldn't be shown
|
|
431
|
+
]
|
|
432
|
+
}]
|
|
433
|
+
}, {
|
|
434
|
+
name: 'Third',
|
|
435
|
+
tasks: [{
|
|
436
|
+
name: 'Charlie',
|
|
437
|
+
depends_on: ['Alpha', 'Bravo'],
|
|
438
|
+
ignoreSkipped: true
|
|
439
|
+
}]
|
|
440
|
+
}];
|
|
441
|
+
var TASKS = {
|
|
442
|
+
'Alpha': {
|
|
443
|
+
complete: true
|
|
444
|
+
},
|
|
445
|
+
'Bravo': {
|
|
446
|
+
complete: false
|
|
447
|
+
},
|
|
448
|
+
'Delta': {}
|
|
449
|
+
};
|
|
450
|
+
var DATA = {
|
|
451
|
+
echo: 'foxtrot',
|
|
452
|
+
golf: 'hotel'
|
|
453
|
+
};
|
|
454
|
+
var RESULT = (0, _getUpdatedSectionStates.default)(SHOW_WHEN_SECTIONS, TASKS, NON_SEQUENTIAL, DATA);
|
|
455
|
+
expect(RESULT[2].tasks[0].state).toEqual(_models.TaskStates.TYPES.NOT_STARTED); // Charlie
|
|
173
456
|
});
|
|
174
457
|
});
|
|
175
458
|
});
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.default = void 0;
|
|
7
7
|
var _canActionProceed = _interopRequireDefault(require("./canActionProceed"));
|
|
8
8
|
var _canCYASubmit = _interopRequireDefault(require("./canCYASubmit"));
|
|
9
9
|
var _cleanHiddenNestedData = _interopRequireDefault(require("./cleanHiddenNestedData"));
|
|
@@ -27,6 +27,5 @@ var helpers = {
|
|
|
27
27
|
getSubmissionStatus: _getSubmissionStatus.default,
|
|
28
28
|
getUpdatedSectionStates: _getUpdatedSectionStates.default
|
|
29
29
|
};
|
|
30
|
-
exports.helpers = helpers;
|
|
31
30
|
var _default = helpers;
|
|
32
31
|
exports.default = _default;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _models = require("../../models");
|
|
8
|
+
var _utils = _interopRequireDefault(require("../../utils"));
|
|
9
|
+
var _handlers = _interopRequireDefault(require("./handlers"));
|
|
10
|
+
var _helpers = _interopRequireDefault(require("./helpers"));
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
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); }
|
|
13
|
+
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; }
|
|
14
|
+
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; }
|
|
15
|
+
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; }
|
|
16
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
17
|
+
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); }
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @param {*} action
|
|
21
|
+
*/
|
|
22
|
+
var onCYAAction = function onCYAAction(setPagePoint, action, pages, validate, components, data, setData, type, pageId, currentTask, hooks, addErrors, hub, onPageChange, formState) {
|
|
23
|
+
// Check to see whether the action is able to proceed, which in
|
|
24
|
+
// in the case of a submission will validate the fields in the page.
|
|
25
|
+
if (action.type === _models.PageAction.TYPES.SUBMIT && hub !== _models.HubFormats.TASK) {
|
|
26
|
+
setPagePoint('submit');
|
|
27
|
+
if (_helpers.default.canCYASubmit(pages, validate.pages)) {
|
|
28
|
+
// Submit.
|
|
29
|
+
var submissionData = _utils.default.Format.form({
|
|
30
|
+
pages: pages,
|
|
31
|
+
components: components
|
|
32
|
+
}, _objectSpread({}, data), _models.EventTypes.SUBMIT);
|
|
33
|
+
submissionData.formStatus = _helpers.default.getSubmissionStatus(type, pages, pageId, action, submissionData, currentTask, true);
|
|
34
|
+
setData(submissionData);
|
|
35
|
+
// Now submit the data to the backend...
|
|
36
|
+
hooks.onSubmit(action.type, submissionData, function () {
|
|
37
|
+
return hooks.onFormComplete();
|
|
38
|
+
}, function (errors) {
|
|
39
|
+
return _handlers.default.submissionError(errors, addErrors);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (action.type === _models.PageAction.TYPES.SAVE_AND_CONTINUE && hub === _models.HubFormats.TASK) {
|
|
44
|
+
var shouldValidate = !(Object.prototype.hasOwnProperty.call(action, 'validate') && !action.validate);
|
|
45
|
+
var canSubmit = shouldValidate ? _helpers.default.canCYASubmit(currentTask.fullPages, validate.pages) : true;
|
|
46
|
+
if (canSubmit) {
|
|
47
|
+
var _submissionData = _utils.default.Format.form({
|
|
48
|
+
pages: pages,
|
|
49
|
+
components: components
|
|
50
|
+
}, _objectSpread({}, data), _models.EventTypes.SUBMIT);
|
|
51
|
+
_submissionData.formStatus = _helpers.default.getSubmissionStatus(type, pages, pageId, action, _submissionData, currentTask, true);
|
|
52
|
+
setData(_submissionData);
|
|
53
|
+
hooks.onSubmit(action.type, _submissionData, function () {
|
|
54
|
+
return onPageChange(_models.FormPages.HUB);
|
|
55
|
+
}, function (errors) {
|
|
56
|
+
return _handlers.default.submissionError(errors, addErrors);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (action.type === _models.PageAction.TYPES.SUBMIT && hub === _models.HubFormats.TASK) {
|
|
61
|
+
setPagePoint('submit');
|
|
62
|
+
if (_helpers.default.canCYASubmit(currentTask.fullPages, validate.pages)) {
|
|
63
|
+
// Submit.
|
|
64
|
+
var _submissionData2 = _utils.default.Format.form({
|
|
65
|
+
pages: pages,
|
|
66
|
+
components: components
|
|
67
|
+
}, _objectSpread({}, data), _models.EventTypes.SUBMIT);
|
|
68
|
+
_submissionData2.formStatus = _helpers.default.getSubmissionStatus(type, pages, pageId, action, _submissionData2, currentTask, true);
|
|
69
|
+
setData(_submissionData2);
|
|
70
|
+
// Now submit the data to the backend...
|
|
71
|
+
hooks.onSubmit(action.type, _submissionData2, function () {
|
|
72
|
+
return hooks.onFormComplete();
|
|
73
|
+
}, function (errors) {
|
|
74
|
+
return _handlers.default.submissionError(errors, addErrors);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (action.type === _models.PageAction.TYPES.SAVE_AND_RETURN) {
|
|
79
|
+
var _shouldValidate = !(Object.prototype.hasOwnProperty.call(action, 'validate') && !action.validate);
|
|
80
|
+
var _canSubmit = _shouldValidate ? _helpers.default.canCYASubmit(currentTask.fullPages, validate.pages) : true;
|
|
81
|
+
if (_canSubmit) {
|
|
82
|
+
var _submissionData3 = _utils.default.Format.form({
|
|
83
|
+
pages: pages,
|
|
84
|
+
components: components
|
|
85
|
+
}, _objectSpread({}, data), _models.EventTypes.SUBMIT);
|
|
86
|
+
_submissionData3.formStatus = _helpers.default.getSubmissionStatus(type, pages, pageId, action, _submissionData3, currentTask, false);
|
|
87
|
+
setData(_submissionData3);
|
|
88
|
+
hooks.onSubmit(action.type, _submissionData3, function () {
|
|
89
|
+
if (type === _models.FormTypes.TASK) {
|
|
90
|
+
onPageChange(undefined);
|
|
91
|
+
} else {
|
|
92
|
+
onPageChange(_models.FormPages.HUB);
|
|
93
|
+
}
|
|
94
|
+
}, function (errors) {
|
|
95
|
+
return _handlers.default.submissionError(errors, addErrors);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (action.type === _models.PageAction.TYPES.NAVIGATE) {
|
|
100
|
+
var _formState$page;
|
|
101
|
+
onPageChange(_helpers.default.getNextPageId(type, pages, pageId, action, (_formState$page = formState.page) === null || _formState$page === void 0 ? void 0 : _formState$page.formData));
|
|
102
|
+
}
|
|
103
|
+
if (action.type === _models.PageAction.TYPES.CANCEL) {
|
|
104
|
+
hooks.onCancel();
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
var _default = onCYAAction;
|
|
108
|
+
exports.default = _default;
|