@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,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _shouldRun = _interopRequireDefault(require("./shouldRun"));
|
|
4
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
5
|
+
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); }
|
|
6
|
+
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; }
|
|
7
|
+
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; }
|
|
8
|
+
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; }
|
|
9
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
10
|
+
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); }
|
|
11
|
+
describe('Utils.Operate.shouldRun', function () {
|
|
12
|
+
var DATA = {
|
|
13
|
+
alpha: 'abc',
|
|
14
|
+
bravo: ''
|
|
15
|
+
};
|
|
16
|
+
it('Should return true if the run_when config is invalid', function () {
|
|
17
|
+
expect((0, _shouldRun.default)(null, DATA)).toEqual(true);
|
|
18
|
+
});
|
|
19
|
+
it('Should return true when the condition is \'changes\' and target value has changed', function () {
|
|
20
|
+
var CONFIG = {
|
|
21
|
+
condition: 'changes',
|
|
22
|
+
field: 'alpha'
|
|
23
|
+
};
|
|
24
|
+
var result = (0, _shouldRun.default)(CONFIG, DATA);
|
|
25
|
+
expect(result).toEqual(false); // Expect false as this is the first render.
|
|
26
|
+
result = (0, _shouldRun.default)(CONFIG, DATA);
|
|
27
|
+
expect(result).toEqual(false); // Expect false as the field hasn't changed.
|
|
28
|
+
result = (0, _shouldRun.default)(CONFIG, _objectSpread(_objectSpread({}, DATA), {}, {
|
|
29
|
+
alpha: 'bcd'
|
|
30
|
+
}));
|
|
31
|
+
expect(result).toEqual(true); // Expect true as the field's value has been updated.
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('Should return true when the condition is \'isTruthy\' and target value is truthy', function () {
|
|
35
|
+
var CONFIG = {
|
|
36
|
+
condition: 'isTruthy',
|
|
37
|
+
field: 'alpha'
|
|
38
|
+
};
|
|
39
|
+
var result = (0, _shouldRun.default)(CONFIG, DATA);
|
|
40
|
+
expect(result).toEqual(true);
|
|
41
|
+
});
|
|
42
|
+
it('Should return false when the condition is \'isTruthy\' and target value is falsy', function () {
|
|
43
|
+
var CONFIG = {
|
|
44
|
+
condition: 'isTruthy',
|
|
45
|
+
field: 'bravo'
|
|
46
|
+
};
|
|
47
|
+
var result = (0, _shouldRun.default)(CONFIG, DATA);
|
|
48
|
+
expect(result).toEqual(false);
|
|
49
|
+
});
|
|
50
|
+
it('Should return true when the condition is \'isFalsy\' and target value is falsy', function () {
|
|
51
|
+
var CONFIG = {
|
|
52
|
+
condition: 'isFalsy',
|
|
53
|
+
field: 'bravo'
|
|
54
|
+
};
|
|
55
|
+
var result = (0, _shouldRun.default)(CONFIG, DATA);
|
|
56
|
+
expect(result).toEqual(true);
|
|
57
|
+
});
|
|
58
|
+
it('Should return false when the condition is \'isFalsy\' and target value is truthy', function () {
|
|
59
|
+
var CONFIG = {
|
|
60
|
+
condition: 'isFalsy',
|
|
61
|
+
field: 'alpha'
|
|
62
|
+
};
|
|
63
|
+
var result = (0, _shouldRun.default)(CONFIG, DATA);
|
|
64
|
+
expect(result).toEqual(false);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Additional validator for the Container component type.
|
|
9
|
+
* @param {object} data the form data
|
|
10
|
+
* @param {object} config the config for the validation, must contain a property 'base' with the id of the conditionally required component and
|
|
11
|
+
* a property 'check' which if the corresponding component has a value will turn off the required check for 'base'
|
|
12
|
+
* @param {object} component the container component
|
|
13
|
+
* @returns true if the user has entered data into the 'base' field or entered a value into the 'check' field to turn off the validation
|
|
14
|
+
* otherwise returns false
|
|
15
|
+
*/
|
|
16
|
+
var conditionallyRequired = function conditionallyRequired(data, config, component) {
|
|
17
|
+
var _data$component$id, _data$component$id2;
|
|
18
|
+
var conditional = (_data$component$id = data[component.id]) === null || _data$component$id === void 0 ? void 0 : _data$component$id[config.base];
|
|
19
|
+
var checkFieldvalue = (_data$component$id2 = data[component.id]) === null || _data$component$id2 === void 0 ? void 0 : _data$component$id2[config.check];
|
|
20
|
+
var checkHasValue = checkFieldvalue && (checkFieldvalue === null || checkFieldvalue === void 0 ? void 0 : checkFieldvalue.length) > 0;
|
|
21
|
+
return !!(conditional || checkHasValue);
|
|
22
|
+
};
|
|
23
|
+
var _default = conditionallyRequired;
|
|
24
|
+
exports.default = _default;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _conditionallyRequired = _interopRequireDefault(require("./conditionallyRequired"));
|
|
4
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
5
|
+
describe('utils', function () {
|
|
6
|
+
describe('Validate', function () {
|
|
7
|
+
describe('additional', function () {
|
|
8
|
+
describe('conditionallyRequired', function () {
|
|
9
|
+
var CONFIG = {
|
|
10
|
+
base: 'componentOne',
|
|
11
|
+
check: 'componentTwo'
|
|
12
|
+
};
|
|
13
|
+
var COMPONENT = {
|
|
14
|
+
id: 'containerComponent',
|
|
15
|
+
fieldId: 'containerComponent',
|
|
16
|
+
type: 'container',
|
|
17
|
+
components: [{
|
|
18
|
+
id: 'componentOne',
|
|
19
|
+
type: 'text',
|
|
20
|
+
fieldId: 'componentOne'
|
|
21
|
+
}, {
|
|
22
|
+
id: 'componentTwo',
|
|
23
|
+
fieldId: 'componentTwo',
|
|
24
|
+
type: 'checkboxes'
|
|
25
|
+
}]
|
|
26
|
+
};
|
|
27
|
+
test('should pass if only the base field has a value', function () {
|
|
28
|
+
var DATA = {
|
|
29
|
+
containerComponent: {
|
|
30
|
+
componentOne: 'value'
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
expect((0, _conditionallyRequired.default)(DATA, CONFIG, COMPONENT)).toEqual(true);
|
|
34
|
+
});
|
|
35
|
+
test('should pass if the base and check fields have values', function () {
|
|
36
|
+
var DATA = {
|
|
37
|
+
containerComponent: {
|
|
38
|
+
componentOne: 'value',
|
|
39
|
+
componentTwo: 'value'
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
expect((0, _conditionallyRequired.default)(DATA, CONFIG, COMPONENT)).toEqual(true);
|
|
43
|
+
});
|
|
44
|
+
test('should pass if only the check field has a value', function () {
|
|
45
|
+
var DATA = {
|
|
46
|
+
containerComponent: {
|
|
47
|
+
componentTwo: 'value'
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
expect((0, _conditionallyRequired.default)(DATA, CONFIG, COMPONENT)).toEqual(true);
|
|
51
|
+
});
|
|
52
|
+
test('should pass if only the check field has a value and that value is an array', function () {
|
|
53
|
+
var DATA = {
|
|
54
|
+
containerComponent: {
|
|
55
|
+
componentTwo: ['value']
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
expect((0, _conditionallyRequired.default)(DATA, CONFIG, COMPONENT)).toEqual(true);
|
|
59
|
+
});
|
|
60
|
+
test('should fail if neither field has a value', function () {
|
|
61
|
+
var DATA = {
|
|
62
|
+
containerComponent: {}
|
|
63
|
+
};
|
|
64
|
+
expect((0, _conditionallyRequired.default)(DATA, CONFIG, COMPONENT)).toEqual(false);
|
|
65
|
+
});
|
|
66
|
+
test('should fail if there is no data', function () {
|
|
67
|
+
var DATA = {};
|
|
68
|
+
expect((0, _conditionallyRequired.default)(DATA, CONFIG, COMPONENT)).toEqual(false);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
var _conditionallyRequired = _interopRequireDefault(require("./conditionallyRequired"));
|
|
7
8
|
var _mustBeAfter = _interopRequireDefault(require("./mustBeAfter"));
|
|
8
9
|
var _mustBeBefore = _interopRequireDefault(require("./mustBeBefore"));
|
|
9
10
|
var _mustBeEarlierDateTime = _interopRequireDefault(require("./mustBeEarlierDateTime"));
|
|
@@ -11,13 +12,17 @@ var _mustBeInThePast = _interopRequireDefault(require("./mustBeInThePast"));
|
|
|
11
12
|
var _mustBeInTheFuture = _interopRequireDefault(require("./mustBeInTheFuture"));
|
|
12
13
|
var _mustBeLongerThan = _interopRequireDefault(require("./mustBeLongerThan"));
|
|
13
14
|
var _mustBeShorterThan = _interopRequireDefault(require("./mustBeShorterThan"));
|
|
14
|
-
var
|
|
15
|
-
var _mustBeNumbersOnly = _interopRequireDefault(require("./mustBeNumbersOnly"));
|
|
15
|
+
var _mustBeGreaterThan = _interopRequireDefault(require("./mustBeGreaterThan"));
|
|
16
16
|
var _mustBeLessThan = _interopRequireDefault(require("./mustBeLessThan"));
|
|
17
|
+
var _mustBeNumbersOnly = _interopRequireDefault(require("./mustBeNumbersOnly"));
|
|
18
|
+
var _mustEnterAtLeastOne = _interopRequireDefault(require("./mustEnterAtLeastOne"));
|
|
19
|
+
var _mustHaveLessThanDecimalPlaces = _interopRequireDefault(require("./mustHaveLessThanDecimalPlaces"));
|
|
20
|
+
var _mustSelectOnlyOne = _interopRequireDefault(require("./mustSelectOnlyOne"));
|
|
17
21
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
22
|
// Local imports
|
|
19
23
|
|
|
20
24
|
var functions = {
|
|
25
|
+
conditionallyRequired: _conditionallyRequired.default,
|
|
21
26
|
mustBeAfter: _mustBeAfter.default,
|
|
22
27
|
mustBeBefore: _mustBeBefore.default,
|
|
23
28
|
mustBeEarlierDateTime: _mustBeEarlierDateTime.default,
|
|
@@ -27,7 +32,10 @@ var functions = {
|
|
|
27
32
|
mustBeShorterThan: _mustBeShorterThan.default,
|
|
28
33
|
mustEnterAtLeastOne: _mustEnterAtLeastOne.default,
|
|
29
34
|
mustBeNumbersOnly: _mustBeNumbersOnly.default,
|
|
30
|
-
mustBeLessThan: _mustBeLessThan.default
|
|
35
|
+
mustBeLessThan: _mustBeLessThan.default,
|
|
36
|
+
mustBeGreaterThan: _mustBeGreaterThan.default,
|
|
37
|
+
mustHaveLessThanDecimalPlaces: _mustHaveLessThanDecimalPlaces.default,
|
|
38
|
+
mustSelectOnlyOne: _mustSelectOnlyOne.default
|
|
31
39
|
};
|
|
32
40
|
var additionalValidation = function additionalValidation(value, config, component) {
|
|
33
41
|
var fn = functions[config.function];
|
|
@@ -38,9 +46,10 @@ var additionalValidation = function additionalValidation(value, config, componen
|
|
|
38
46
|
};
|
|
39
47
|
var runAdditionalComponentValidation = function runAdditionalComponentValidation(component, value) {
|
|
40
48
|
// We only care when we have a value - if we don't have one but want one, set `required: true`.
|
|
49
|
+
// eslint-disable-next-line no-extra-boolean-cast
|
|
41
50
|
if (!!value) {
|
|
42
51
|
if (Array.isArray(component.additionalValidation)) {
|
|
43
|
-
var error
|
|
52
|
+
var error;
|
|
44
53
|
component.additionalValidation.forEach(function (config) {
|
|
45
54
|
// If we've already encountered an error, don't run any more validators.
|
|
46
55
|
if (!error) {
|
|
@@ -15,17 +15,19 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
15
15
|
_dayjs.default.extend(_customParseFormat.default);
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
18
|
+
* Checks that a date is after either:
|
|
19
|
+
* - A specified, fixed date.
|
|
20
|
+
* Or
|
|
21
|
+
* - An offset to the current date in days/months/years.
|
|
22
|
+
*
|
|
22
23
|
* @param {string} date - date string in a valid date format e.g. DD-MM-YYYY
|
|
24
|
+
* @param {string} config.date - fixed date string that date must be after, in the format DD-MM-YYYY
|
|
23
25
|
* @param {string} config.unit - day, month or year
|
|
24
26
|
* @param {number} config.value - number of the unit to be after
|
|
25
|
-
* @returns false if date is
|
|
27
|
+
* @returns false if date is not after the given date/offset or true if it is.
|
|
26
28
|
*/
|
|
27
29
|
var mustBeAfter = function mustBeAfter(date, config) {
|
|
28
|
-
var dateToCompare = (0, _dayjs.default)().add(config.value, config.unit);
|
|
30
|
+
var dateToCompare = config.date ? (0, _dayjs.default)((0, _utils.formatString)(config.date), _utils.DATE_FORMAT) : (0, _dayjs.default)().add(config.value, config.unit);
|
|
29
31
|
return (0, _dayjs.default)((0, _utils.formatString)(date), _utils.DATE_FORMAT).isAfter(dateToCompare);
|
|
30
32
|
};
|
|
31
33
|
var _default = mustBeAfter;
|
|
@@ -80,7 +80,7 @@ describe('utils', function () {
|
|
|
80
80
|
});
|
|
81
81
|
expect(result).toEqual(true);
|
|
82
82
|
});
|
|
83
|
-
test('should return
|
|
83
|
+
test('should return false given a date before the given number of days in the future', function () {
|
|
84
84
|
var date = (0, _dayjs.default)().add(250, 'day').format(_utils.DATE_FORMAT);
|
|
85
85
|
var result = (0, _mustBeAfter.default)(date, {
|
|
86
86
|
value: 275,
|
|
@@ -88,6 +88,20 @@ describe('utils', function () {
|
|
|
88
88
|
});
|
|
89
89
|
expect(result).toEqual(false);
|
|
90
90
|
});
|
|
91
|
+
test('should return false given a date before the specified fixed date', function () {
|
|
92
|
+
var date = (0, _dayjs.default)().format(_utils.DATE_FORMAT);
|
|
93
|
+
var result = (0, _mustBeAfter.default)(date, {
|
|
94
|
+
date: '01-01-5000'
|
|
95
|
+
});
|
|
96
|
+
expect(result).toEqual(false);
|
|
97
|
+
});
|
|
98
|
+
test('should return true given a date after the specified fixed date', function () {
|
|
99
|
+
var date = (0, _dayjs.default)().format(_utils.DATE_FORMAT);
|
|
100
|
+
var result = (0, _mustBeAfter.default)(date, {
|
|
101
|
+
date: '01-01-2000'
|
|
102
|
+
});
|
|
103
|
+
expect(result).toEqual(true);
|
|
104
|
+
});
|
|
91
105
|
});
|
|
92
106
|
});
|
|
93
107
|
});
|
|
@@ -15,15 +15,19 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
15
15
|
_dayjs.default.extend(_customParseFormat.default);
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
18
|
+
* Checks that a date is before either:
|
|
19
|
+
* - A specified, fixed date.
|
|
20
|
+
* Or
|
|
21
|
+
* - An offset to the current date in days/months/years.
|
|
22
|
+
*
|
|
23
|
+
* @param {string} date - date string in a valid date format e.g. DD-MM-YYYY
|
|
24
|
+
* @param {string} config.date - fixed date string that date must be before, in the format DD-MM-YYYY
|
|
21
25
|
* @param {string} config.unit - day, month or year
|
|
22
26
|
* @param {number} config.value - number of the unit to be before
|
|
23
|
-
* @returns
|
|
27
|
+
* @returns false if date is not before the given date/offset or true if it is.
|
|
24
28
|
*/
|
|
25
29
|
var mustBeBefore = function mustBeBefore(date, config) {
|
|
26
|
-
var dateToCompare = (0, _dayjs.default)().add(config.value, config.unit);
|
|
30
|
+
var dateToCompare = config.date ? (0, _dayjs.default)((0, _utils.formatString)(config.date), _utils.DATE_FORMAT) : (0, _dayjs.default)().add(config.value, config.unit);
|
|
27
31
|
return (0, _dayjs.default)((0, _utils.formatString)(date), _utils.DATE_FORMAT).isBefore(dateToCompare);
|
|
28
32
|
};
|
|
29
33
|
var _default = mustBeBefore;
|
|
@@ -56,6 +56,20 @@ describe('utils', function () {
|
|
|
56
56
|
});
|
|
57
57
|
expect(result).toEqual(false);
|
|
58
58
|
});
|
|
59
|
+
test('should return false given a date after the specified fixed date', function () {
|
|
60
|
+
var date = (0, _dayjs.default)().format(_utils.DATE_FORMAT);
|
|
61
|
+
var result = (0, _mustBeBefore.default)(date, {
|
|
62
|
+
date: '01-01-2000'
|
|
63
|
+
});
|
|
64
|
+
expect(result).toEqual(false);
|
|
65
|
+
});
|
|
66
|
+
test('should return true given a date before the specified fixed date', function () {
|
|
67
|
+
var date = (0, _dayjs.default)().format(_utils.DATE_FORMAT);
|
|
68
|
+
var result = (0, _mustBeBefore.default)(date, {
|
|
69
|
+
date: '01-01-5000'
|
|
70
|
+
});
|
|
71
|
+
expect(result).toEqual(true);
|
|
72
|
+
});
|
|
59
73
|
});
|
|
60
74
|
});
|
|
61
75
|
});
|
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
var _mustBeEarlierDateTime = _interopRequireDefault(require("./mustBeEarlierDateTime"));
|
|
4
4
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
5
|
+
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); }
|
|
5
6
|
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; }
|
|
6
7
|
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; }
|
|
7
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
|
+
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; }
|
|
9
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
10
|
+
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
11
|
describe('utils.Validate.additional.mustBeEarlierDateTime', function () {
|
|
9
12
|
var DATA = {
|
|
10
13
|
testContainer: {
|
|
@@ -92,13 +95,13 @@ describe('utils.Validate.additional.mustBeEarlierDateTime', function () {
|
|
|
92
95
|
expect(result).toEqual(true);
|
|
93
96
|
});
|
|
94
97
|
test('should return false if date & time are not in the past', function () {
|
|
95
|
-
var
|
|
98
|
+
var futureDATA = {
|
|
96
99
|
testContainer: {
|
|
97
100
|
testDate: '01-01-5000',
|
|
98
101
|
testTime: '00:00'
|
|
99
102
|
}
|
|
100
103
|
};
|
|
101
|
-
var result = (0, _mustBeEarlierDateTime.default)(
|
|
104
|
+
var result = (0, _mustBeEarlierDateTime.default)(futureDATA, CONFIG, CONTAINER);
|
|
102
105
|
expect(result).toEqual(false);
|
|
103
106
|
});
|
|
104
107
|
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* @param {*} value - the value to check.
|
|
9
|
+
* @param {number} config.value - the value must be greater than config.value.
|
|
10
|
+
* @returns true if value is greater than config.value, false if not.
|
|
11
|
+
*/
|
|
12
|
+
var mustBeGreaterThan = function mustBeGreaterThan(value, config) {
|
|
13
|
+
if (!value) {
|
|
14
|
+
// null, undefined and empty strings should be picked up by the required flag
|
|
15
|
+
// and not considered here as they would be valid for optional fields.
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
var finalValue = typeof value === 'string' ? value.replace(/,/g, '') : value;
|
|
19
|
+
return parseFloat(finalValue) > config.value;
|
|
20
|
+
};
|
|
21
|
+
var _default = mustBeGreaterThan;
|
|
22
|
+
exports.default = _default;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _mustBeGreaterThan = _interopRequireDefault(require("./mustBeGreaterThan"));
|
|
4
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
5
|
+
describe('utils', function () {
|
|
6
|
+
describe('Validate', function () {
|
|
7
|
+
describe('additional', function () {
|
|
8
|
+
describe('mustBeGreaterThan', function () {
|
|
9
|
+
test('should return true given a number greater than 10', function () {
|
|
10
|
+
var result = (0, _mustBeGreaterThan.default)('11', {
|
|
11
|
+
value: 10
|
|
12
|
+
});
|
|
13
|
+
expect(result).toEqual(true);
|
|
14
|
+
});
|
|
15
|
+
test('should return false if provided value less than or equal to 10', function () {
|
|
16
|
+
var result1 = (0, _mustBeGreaterThan.default)('9', {
|
|
17
|
+
value: 10
|
|
18
|
+
});
|
|
19
|
+
expect(result1).toBeFalsy();
|
|
20
|
+
var result2 = (0, _mustBeGreaterThan.default)('10', {
|
|
21
|
+
value: 10
|
|
22
|
+
});
|
|
23
|
+
expect(result2).toBeFalsy();
|
|
24
|
+
});
|
|
25
|
+
test('should correctly handle numbers with commas in', function () {
|
|
26
|
+
var result1 = (0, _mustBeGreaterThan.default)('999,999,999.99', {
|
|
27
|
+
value: 1000000000
|
|
28
|
+
});
|
|
29
|
+
expect(result1).toEqual(false);
|
|
30
|
+
var result2 = (0, _mustBeGreaterThan.default)('1,000,000,123', {
|
|
31
|
+
value: 1000000000
|
|
32
|
+
});
|
|
33
|
+
expect(result2).toEqual(true);
|
|
34
|
+
});
|
|
35
|
+
test('should return true when string is undefined', function () {
|
|
36
|
+
var result = (0, _mustBeGreaterThan.default)(undefined, {
|
|
37
|
+
value: 10
|
|
38
|
+
});
|
|
39
|
+
expect(result).toEqual(true);
|
|
40
|
+
});
|
|
41
|
+
test('should return true when string is empty', function () {
|
|
42
|
+
var result = (0, _mustBeGreaterThan.default)('', {
|
|
43
|
+
value: 10
|
|
44
|
+
});
|
|
45
|
+
expect(result).toEqual(true);
|
|
46
|
+
});
|
|
47
|
+
test('should return true when string is null', function () {
|
|
48
|
+
var result = (0, _mustBeGreaterThan.default)(null, {
|
|
49
|
+
value: 10
|
|
50
|
+
});
|
|
51
|
+
expect(result).toEqual(true);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -11,7 +11,7 @@ var _utils = require("./utils");
|
|
|
11
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
12
|
// Global Imports
|
|
13
13
|
|
|
14
|
-
//Local imports
|
|
14
|
+
// Local imports
|
|
15
15
|
|
|
16
16
|
_dayjs.default.extend(_customParseFormat.default);
|
|
17
17
|
_dayjs.default.extend(_isToday.default);
|
|
@@ -11,7 +11,7 @@ var _utils = require("./utils");
|
|
|
11
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
12
|
// Global imports
|
|
13
13
|
|
|
14
|
-
//Local imports
|
|
14
|
+
// Local imports
|
|
15
15
|
|
|
16
16
|
_dayjs.default.extend(_customParseFormat.default);
|
|
17
17
|
_dayjs.default.extend(_isToday.default);
|
|
@@ -25,12 +25,12 @@ _dayjs.default.extend(_isToday.default);
|
|
|
25
25
|
*/
|
|
26
26
|
var mustBeInThePast = function mustBeInThePast(date, config) {
|
|
27
27
|
var beforeToday = (0, _dayjs.default)((0, _utils.formatString)(date), _utils.DATE_FORMAT).isBefore((0, _dayjs.default)());
|
|
28
|
-
var
|
|
29
|
-
//dayjs classifies the current day as in the past so exclude it here
|
|
30
|
-
if (beforeToday && !
|
|
28
|
+
var dateIsToday = (0, _dayjs.default)((0, _utils.formatString)(date), _utils.DATE_FORMAT).isToday();
|
|
29
|
+
// dayjs classifies the current day as in the past so exclude it here
|
|
30
|
+
if (beforeToday && !dateIsToday) {
|
|
31
31
|
return true;
|
|
32
32
|
}
|
|
33
|
-
return
|
|
33
|
+
return dateIsToday && !!(config !== null && config !== void 0 && config.todayAllowed);
|
|
34
34
|
};
|
|
35
35
|
var _default = mustBeInThePast;
|
|
36
36
|
exports.default = _default;
|
|
@@ -5,17 +5,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
/**
|
|
8
|
-
* @param {
|
|
9
|
-
* @param {number} config.value - the
|
|
10
|
-
* @returns true if
|
|
8
|
+
* @param {*} value - the value to check.
|
|
9
|
+
* @param {number} config.value - the value must be equal or less than config.value.
|
|
10
|
+
* @returns true if value is equal to or less then config.value, false if not.
|
|
11
11
|
*/
|
|
12
|
-
var mustBeLessThan = function mustBeLessThan(
|
|
13
|
-
if (!
|
|
12
|
+
var mustBeLessThan = function mustBeLessThan(value, config) {
|
|
13
|
+
if (!value) {
|
|
14
14
|
// null, undefined and empty strings should be picked up by the required flag
|
|
15
15
|
// and not considered here as they would be valid for optional fields.
|
|
16
16
|
return true;
|
|
17
17
|
}
|
|
18
|
-
|
|
18
|
+
var finalValue = typeof value === 'string' ? value.replace(/,/g, '') : value;
|
|
19
|
+
return parseFloat(finalValue) < config.value;
|
|
19
20
|
};
|
|
20
21
|
var _default = mustBeLessThan;
|
|
21
22
|
exports.default = _default;
|
|
@@ -5,7 +5,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
5
5
|
describe('utils', function () {
|
|
6
6
|
describe('Validate', function () {
|
|
7
7
|
describe('additional', function () {
|
|
8
|
-
describe('
|
|
8
|
+
describe('mustBeLessThan', function () {
|
|
9
9
|
test('should return true given a number equal to or less than 1000000000', function () {
|
|
10
10
|
var result = (0, _mustBeLessThan.default)(999999999.999, {
|
|
11
11
|
value: 1000000000
|
|
@@ -18,6 +18,16 @@ describe('utils', function () {
|
|
|
18
18
|
});
|
|
19
19
|
expect(result).toBeFalsy();
|
|
20
20
|
});
|
|
21
|
+
test('should correctly handle numbers with commas in', function () {
|
|
22
|
+
var result1 = (0, _mustBeLessThan.default)('999,999,999.99', {
|
|
23
|
+
value: 1000000000
|
|
24
|
+
});
|
|
25
|
+
expect(result1).toEqual(true);
|
|
26
|
+
var result2 = (0, _mustBeLessThan.default)('1,000,000,123', {
|
|
27
|
+
value: 1000000000
|
|
28
|
+
});
|
|
29
|
+
expect(result2).toEqual(false);
|
|
30
|
+
});
|
|
21
31
|
test('should return true when string is undefined', function () {
|
|
22
32
|
var result = (0, _mustBeLessThan.default)(undefined, {
|
|
23
33
|
value: 3
|
|
@@ -5,16 +5,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Checks if a string contains only numberical characters.
|
|
9
|
+
* An optional flag in config can be used to allow commas.
|
|
10
|
+
* @param {*} value The value to check for only numerical characters.
|
|
11
|
+
* @param {object} config The config of the validation check.
|
|
12
|
+
* @returns true if value passes the regex, false if not.
|
|
9
13
|
*/
|
|
10
|
-
var mustBeNumbersOnly = function mustBeNumbersOnly(
|
|
11
|
-
|
|
12
|
-
if (!number) {
|
|
14
|
+
var mustBeNumbersOnly = function mustBeNumbersOnly(value, config) {
|
|
15
|
+
if (!value) {
|
|
13
16
|
// null, undefined and empty numbers should be picked up by the required flag
|
|
14
17
|
// and not considered here as they would be valid for optional fields.
|
|
15
18
|
return true;
|
|
16
19
|
}
|
|
17
|
-
|
|
20
|
+
var regex = config !== null && config !== void 0 && config.allowCommas ? /^[0-9,]*\.?[0-9]*$/ : /^[0-9]*\.?[0-9]*$/;
|
|
21
|
+
return regex.test(value);
|
|
18
22
|
};
|
|
19
23
|
var _default = mustBeNumbersOnly;
|
|
20
24
|
exports.default = _default;
|
|
@@ -14,10 +14,18 @@ describe('utils', function () {
|
|
|
14
14
|
var result = (0, _mustBeNumbersOnly.default)('123456.123');
|
|
15
15
|
expect(result).toEqual(true);
|
|
16
16
|
});
|
|
17
|
-
test('should return false if given number contains
|
|
18
|
-
var
|
|
17
|
+
test('should return false if given number contains commas and config does not allow them', function () {
|
|
18
|
+
var CONFIG = {};
|
|
19
|
+
var result = (0, _mustBeNumbersOnly.default)('1,234', CONFIG);
|
|
19
20
|
expect(result).toEqual(false);
|
|
20
21
|
});
|
|
22
|
+
test('should return true if given number contains commas and config allows them', function () {
|
|
23
|
+
var CONFIG = {
|
|
24
|
+
allowCommas: true
|
|
25
|
+
};
|
|
26
|
+
var result = (0, _mustBeNumbersOnly.default)('1,234', CONFIG);
|
|
27
|
+
expect(result).toEqual(true);
|
|
28
|
+
});
|
|
21
29
|
test('should return true when string is undefined', function () {
|
|
22
30
|
var result = (0, _mustBeNumbersOnly.default)(undefined);
|
|
23
31
|
expect(result).toEqual(true);
|
|
@@ -11,6 +11,7 @@ exports.default = void 0;
|
|
|
11
11
|
* @returns true if the user has entered data into at least one component within the collection
|
|
12
12
|
* otherwise returns false
|
|
13
13
|
*/
|
|
14
|
+
// eslint-disable-next-line arrow-body-style
|
|
14
15
|
var mustEnterAtLeastOne = function mustEnterAtLeastOne(data, _, component) {
|
|
15
16
|
var _component$components;
|
|
16
17
|
return (_component$components = component.components) === null || _component$components === void 0 ? void 0 : _component$components.some(function (inner) {
|
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
var _mustEnterAtLeastOne = _interopRequireDefault(require("./mustEnterAtLeastOne"));
|
|
4
4
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
5
|
-
function
|
|
5
|
+
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); }
|
|
6
|
+
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; }
|
|
7
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
8
|
+
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); }
|
|
6
9
|
describe('utils', function () {
|
|
7
10
|
describe('Validate', function () {
|
|
8
11
|
describe('additional', function () {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* @param {string} string - the string to check
|
|
9
|
+
* @param {number} config.maxDecimals - the maximum amount of decimal places to allow
|
|
10
|
+
* @returns true if string has less than maxDecimals decimal places else returns false
|
|
11
|
+
*/
|
|
12
|
+
var mustHaveLessThanDecimalPlaces = function mustHaveLessThanDecimalPlaces(string, config) {
|
|
13
|
+
if (!string || !string.includes('.')) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
return string.split('.')[1].length < config.maxDecimals;
|
|
17
|
+
};
|
|
18
|
+
var _default = mustHaveLessThanDecimalPlaces;
|
|
19
|
+
exports.default = _default;
|