@ukhomeoffice/cop-react-form-renderer 5.14.0 → 5.14.4
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 +15 -15
- package/dist/components/CheckYourAnswers/Answer.test.js +94 -128
- package/dist/components/CheckYourAnswers/CheckYourAnswers.js +99 -129
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +291 -501
- package/dist/components/CheckYourAnswers/index.js +2 -3
- package/dist/components/CollectionPage/CollectionPage.js +64 -58
- package/dist/components/CollectionPage/CollectionPage.test.js +212 -238
- package/dist/components/CollectionPage/index.js +2 -3
- package/dist/components/FormComponent/Collection.js +77 -113
- package/dist/components/FormComponent/Collection.test.js +688 -787
- package/dist/components/FormComponent/Container.js +44 -43
- package/dist/components/FormComponent/Container.test.js +316 -346
- package/dist/components/FormComponent/FormComponent.js +58 -64
- package/dist/components/FormComponent/FormComponent.test.js +180 -219
- package/dist/components/FormComponent/helpers/addLabel.js +5 -9
- package/dist/components/FormComponent/helpers/getComponentDisabled.js +2 -3
- package/dist/components/FormComponent/helpers/getComponentDisabled.test.js +8 -8
- package/dist/components/FormComponent/helpers/getComponentError.js +4 -7
- package/dist/components/FormComponent/helpers/getComponentError.test.js +15 -15
- package/dist/components/FormComponent/helpers/getComponentFieldSet.js +2 -2
- package/dist/components/FormComponent/helpers/getComponentFieldSet.test.js +7 -7
- package/dist/components/FormComponent/helpers/index.js +5 -5
- package/dist/components/FormComponent/index.js +2 -3
- package/dist/components/FormPage/FormPage.js +65 -79
- package/dist/components/FormPage/FormPage.test.js +134 -170
- package/dist/components/FormPage/index.js +2 -3
- package/dist/components/FormRenderer/FormRenderer.js +151 -193
- package/dist/components/FormRenderer/FormRenderer.test.js +598 -920
- package/dist/components/FormRenderer/handlers/cyaAction.js +4 -5
- package/dist/components/FormRenderer/handlers/getPageId.js +2 -5
- package/dist/components/FormRenderer/handlers/getPageId.test.js +15 -15
- package/dist/components/FormRenderer/handlers/handlers.test.js +33 -33
- package/dist/components/FormRenderer/handlers/index.js +3 -4
- package/dist/components/FormRenderer/handlers/navigate.js +5 -6
- package/dist/components/FormRenderer/handlers/submissionError.js +2 -3
- package/dist/components/FormRenderer/helpers/canActionProceed.js +2 -3
- package/dist/components/FormRenderer/helpers/canActionProceed.test.js +10 -10
- package/dist/components/FormRenderer/helpers/canCYASubmit.js +2 -5
- package/dist/components/FormRenderer/helpers/canCYASubmit.test.js +17 -21
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.js +19 -27
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.test.js +17 -17
- package/dist/components/FormRenderer/helpers/getCYA.js +6 -9
- package/dist/components/FormRenderer/helpers/getCYA.test.js +12 -12
- package/dist/components/FormRenderer/helpers/getFormState.js +7 -10
- package/dist/components/FormRenderer/helpers/getFormState.test.js +11 -11
- package/dist/components/FormRenderer/helpers/getNextPageId.js +19 -34
- package/dist/components/FormRenderer/helpers/getNextPageId.test.js +68 -68
- package/dist/components/FormRenderer/helpers/getPage.js +3 -6
- package/dist/components/FormRenderer/helpers/getPage.test.js +12 -12
- package/dist/components/FormRenderer/helpers/getRelevantPages.js +9 -13
- package/dist/components/FormRenderer/helpers/getRelevantPages.test.js +15 -15
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +12 -13
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +98 -92
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.js +66 -66
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.test.js +72 -79
- package/dist/components/FormRenderer/helpers/index.js +3 -4
- package/dist/components/FormRenderer/index.js +2 -3
- package/dist/components/FormRenderer/onCYAAction.js +52 -62
- package/dist/components/FormRenderer/onCYAAction.test.js +146 -138
- package/dist/components/FormRenderer/onPageAction.js +48 -47
- package/dist/components/FormRenderer/onPageAction.test.js +219 -205
- package/dist/components/FormRenderer/onTaskAction.js +12 -17
- package/dist/components/FormRenderer/onTaskAction.test.js +94 -89
- package/dist/components/PageActions/ActionButton.js +15 -19
- package/dist/components/PageActions/ActionButton.test.js +58 -79
- package/dist/components/PageActions/PageActions.js +12 -13
- package/dist/components/PageActions/PageActions.test.js +88 -116
- package/dist/components/PageActions/index.js +2 -3
- package/dist/components/SummaryList/GroupAction.js +15 -23
- package/dist/components/SummaryList/GroupAction.test.js +41 -37
- package/dist/components/SummaryList/RowAction.js +14 -19
- package/dist/components/SummaryList/RowAction.test.js +41 -37
- package/dist/components/SummaryList/SummaryList.js +25 -30
- package/dist/components/SummaryList/SummaryList.test.js +160 -182
- package/dist/components/SummaryList/SummaryListHeadingRow.js +9 -8
- package/dist/components/SummaryList/SummaryListRow.js +9 -8
- package/dist/components/SummaryList/SummaryListTitleRow.js +8 -7
- package/dist/components/SummaryList/helpers/getGroupActionAttributes.js +5 -8
- package/dist/components/SummaryList/helpers/getGroupActionAttributes.test.js +24 -24
- package/dist/components/SummaryList/helpers/getRowActionAttributes.js +5 -8
- package/dist/components/SummaryList/helpers/getRowActionAttributes.test.js +24 -24
- package/dist/components/SummaryList/helpers/index.js +2 -2
- package/dist/components/SummaryList/index.js +2 -3
- package/dist/components/TaskList/Task.js +22 -33
- package/dist/components/TaskList/Task.test.js +84 -77
- package/dist/components/TaskList/TaskList.js +46 -75
- package/dist/components/TaskList/TaskList.test.js +118 -113
- package/dist/components/TaskList/TaskState.js +9 -9
- package/dist/components/TaskList/TaskState.test.js +56 -49
- package/dist/components/TaskList/index.js +2 -3
- package/dist/components/index.js +8 -8
- package/dist/context/HooksContext/HooksContext.js +59 -85
- package/dist/context/HooksContext/HooksContext.test.js +28 -36
- package/dist/context/HooksContext/index.js +4 -6
- package/dist/context/ValidationContext/ValidationContext.js +35 -76
- package/dist/context/ValidationContext/ValidationContext.test.js +50 -61
- package/dist/context/ValidationContext/index.js +4 -6
- package/dist/context/index.js +3 -3
- package/dist/hooks/index.js +10 -11
- package/dist/hooks/useAxios.js +17 -43
- package/dist/hooks/useGetRequest.js +65 -106
- package/dist/hooks/useHooks.js +2 -5
- package/dist/hooks/useRefData.js +30 -45
- package/dist/hooks/useValidation.js +2 -5
- package/dist/index.js +15 -17
- package/dist/models/CollectionLabels.js +2 -3
- package/dist/models/ComponentTypes.js +25 -26
- package/dist/models/EventTypes.js +5 -6
- package/dist/models/FormPages.js +5 -6
- package/dist/models/FormTypes.js +9 -10
- package/dist/models/HubFormats.js +4 -5
- package/dist/models/PageAction.js +45 -42
- package/dist/models/TaskStates.js +30 -31
- package/dist/models/index.js +11 -12
- package/dist/setupTests.js +20 -24
- package/dist/utils/CheckYourAnswers/getCYAAction.js +6 -7
- package/dist/utils/CheckYourAnswers/getCYAAction.test.js +53 -55
- package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.js +18 -20
- package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.test.js +21 -23
- package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.js +17 -21
- package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.test.js +18 -20
- package/dist/utils/CheckYourAnswers/getCYARow.js +8 -10
- package/dist/utils/CheckYourAnswers/getCYARow.test.js +72 -72
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.js +20 -27
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.test.js +16 -17
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.js +41 -47
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.test.js +72 -75
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +71 -78
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +133 -114
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.js +27 -23
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.test.js +112 -106
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +16 -23
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.test.js +77 -83
- package/dist/utils/CheckYourAnswers/index.js +3 -4
- package/dist/utils/CheckYourAnswers/showComponentCYA.js +7 -9
- package/dist/utils/CheckYourAnswers/showComponentCYA.test.js +25 -25
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.js +9 -16
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.test.js +19 -20
- package/dist/utils/CollectionPage/getCollectionPageActiveIndex.js +4 -8
- package/dist/utils/CollectionPage/getCollectionPageActiveIndex.test.js +15 -15
- package/dist/utils/CollectionPage/index.js +3 -4
- package/dist/utils/CollectionPage/mergeCollectionPages.js +26 -29
- package/dist/utils/CollectionPage/mergeCollectionPages.test.js +15 -15
- package/dist/utils/Component/addShowWhen.js +5 -10
- package/dist/utils/Component/addShowWhen.test.js +38 -38
- package/dist/utils/Component/applyToComponentTree.js +20 -22
- package/dist/utils/Component/applyToComponentTree.test.js +28 -33
- package/dist/utils/Component/cleanAttributes.js +11 -16
- package/dist/utils/Component/cleanAttributes.test.js +17 -18
- package/dist/utils/Component/elevateNestedComponents.js +7 -9
- package/dist/utils/Component/elevateNestedComponents.test.js +19 -19
- package/dist/utils/Component/getComponent.js +91 -99
- package/dist/utils/Component/getComponentTests/getComponent.autocomplete.test.js +19 -18
- package/dist/utils/Component/getComponentTests/getComponent.calculation.test.js +51 -63
- package/dist/utils/Component/getComponentTests/getComponent.checkboxes.test.js +41 -49
- package/dist/utils/Component/getComponentTests/getComponent.date.test.js +33 -37
- package/dist/utils/Component/getComponentTests/getComponent.details.test.js +21 -19
- package/dist/utils/Component/getComponentTests/getComponent.email.test.js +19 -23
- package/dist/utils/Component/getComponentTests/getComponent.file.test.js +23 -27
- package/dist/utils/Component/getComponentTests/getComponent.heading.test.js +12 -11
- package/dist/utils/Component/getComponentTests/getComponent.html.test.js +18 -16
- package/dist/utils/Component/getComponentTests/getComponent.insetText.test.js +10 -9
- package/dist/utils/Component/getComponentTests/getComponent.list.test.js +18 -16
- package/dist/utils/Component/getComponentTests/getComponent.multifile.test.js +24 -27
- package/dist/utils/Component/getComponentTests/getComponent.nested.test.js +156 -175
- package/dist/utils/Component/getComponentTests/getComponent.paragraph.test.js +18 -16
- package/dist/utils/Component/getComponentTests/getComponent.phoneNumber.test.js +19 -23
- package/dist/utils/Component/getComponentTests/getComponent.radios.test.js +59 -73
- package/dist/utils/Component/getComponentTests/getComponent.select.test.js +19 -23
- package/dist/utils/Component/getComponentTests/getComponent.text.test.js +19 -23
- package/dist/utils/Component/getComponentTests/getComponent.textArea.test.js +35 -41
- package/dist/utils/Component/getComponentTests/getComponent.time.test.js +24 -32
- package/dist/utils/Component/getComponentTests/getComponent.unknown.test.js +3 -3
- package/dist/utils/Component/getComponentTests/getComponent.warningText.test.js +10 -9
- package/dist/utils/Component/getDefaultValue.js +7 -9
- package/dist/utils/Component/getDefaultValue.test.js +14 -14
- package/dist/utils/Component/index.js +3 -4
- package/dist/utils/Component/isEditable.js +3 -7
- package/dist/utils/Component/isEditable.test.js +14 -15
- package/dist/utils/Component/optionIsSelected.js +2 -3
- package/dist/utils/Component/optionIsSelected.test.js +10 -10
- package/dist/utils/Component/setupContainerComponentsPath.js +30 -33
- package/dist/utils/Component/setupContainerComponentsPath.test.js +16 -16
- package/dist/utils/Component/showComponent.js +4 -6
- package/dist/utils/Component/showComponent.test.js +29 -29
- package/dist/utils/Component/wrapInFormGroup.js +6 -6
- package/dist/utils/Condition/index.js +3 -4
- package/dist/utils/Condition/meetsAllConditions.js +9 -10
- package/dist/utils/Condition/meetsAllConditions.test.js +18 -18
- package/dist/utils/Condition/meetsCondition.js +19 -27
- package/dist/utils/Condition/meetsCondition.test.js +377 -377
- package/dist/utils/Condition/meetsOneCondition.js +7 -8
- package/dist/utils/Condition/meetsOneCondition.test.js +17 -17
- package/dist/utils/Condition/setupConditions.js +15 -21
- package/dist/utils/Condition/setupConditions.test.js +8 -8
- package/dist/utils/Container/getEditableComponents.js +5 -8
- package/dist/utils/Container/getEditableComponents.test.js +44 -46
- package/dist/utils/Container/index.js +3 -4
- package/dist/utils/Container/setupNesting.js +17 -24
- package/dist/utils/Container/setupNesting.test.js +28 -31
- package/dist/utils/Container/showContainer.js +5 -10
- package/dist/utils/Container/showContainer.test.js +31 -31
- package/dist/utils/Data/applyFormula.js +41 -52
- package/dist/utils/Data/applyFormula.test.js +26 -26
- package/dist/utils/Data/getAutocompleteSource.js +11 -14
- package/dist/utils/Data/getAutocompleteSource.test.js +59 -59
- package/dist/utils/Data/getDataPath.js +21 -32
- package/dist/utils/Data/getDataPath.test.js +20 -20
- package/dist/utils/Data/getOptions.js +22 -28
- package/dist/utils/Data/getOptions.test.js +21 -21
- package/dist/utils/Data/getSourceData.js +7 -21
- package/dist/utils/Data/getSourceData.test.js +85 -81
- package/dist/utils/Data/index.js +3 -4
- package/dist/utils/Data/refDataToOptions.js +12 -17
- package/dist/utils/Data/refDataToOptions.test.js +20 -20
- package/dist/utils/Data/setDataItem.js +8 -10
- package/dist/utils/Data/setDataItem.test.js +38 -38
- package/dist/utils/Data/setupFormData.js +32 -48
- package/dist/utils/Data/setupFormData.test.js +99 -98
- package/dist/utils/Data/setupRefDataUrlForComponent.js +22 -30
- package/dist/utils/Data/setupRefDataUrlForComponent.test.js +28 -28
- package/dist/utils/FormPage/applyConditionalProperties.js +7 -12
- package/dist/utils/FormPage/applyConditionalProperties.test.js +16 -19
- package/dist/utils/FormPage/getFormPage.js +17 -19
- package/dist/utils/FormPage/getFormPage.test.js +49 -48
- package/dist/utils/FormPage/getFormPages.js +9 -15
- package/dist/utils/FormPage/getFormPages.test.js +22 -25
- package/dist/utils/FormPage/getPageActions.js +11 -19
- package/dist/utils/FormPage/getPageActions.test.js +33 -33
- package/dist/utils/FormPage/getParagraphFromText.js +6 -9
- package/dist/utils/FormPage/getParagraphFromText.test.js +7 -7
- package/dist/utils/FormPage/index.js +3 -4
- package/dist/utils/FormPage/showFormPage.js +5 -10
- package/dist/utils/FormPage/showFormPage.test.js +33 -33
- package/dist/utils/FormPage/showFormPageCYA.js +4 -5
- package/dist/utils/FormPage/showFormPageCYA.test.js +9 -9
- package/dist/utils/FormPage/useComponent.js +21 -29
- package/dist/utils/FormPage/useComponent.test.js +71 -73
- package/dist/utils/Format/formatData.js +2 -3
- package/dist/utils/Format/formatData.test.js +19 -19
- package/dist/utils/Format/formatDataForComponent.js +6 -9
- package/dist/utils/Format/formatDataForComponent.test.js +50 -78
- package/dist/utils/Format/formatDataForForm.js +7 -10
- package/dist/utils/Format/formatDataForForm.test.js +14 -17
- package/dist/utils/Format/formatDataForPage.js +4 -7
- package/dist/utils/Format/formatDataForPage.test.js +20 -25
- package/dist/utils/Format/index.js +3 -4
- package/dist/utils/Hub/getFormHub.js +3 -4
- package/dist/utils/Hub/getFormHub.test.js +29 -32
- package/dist/utils/Hub/index.js +3 -4
- package/dist/utils/Meta/constants.js +2 -4
- package/dist/utils/Meta/documents/getDocuments.js +2 -6
- package/dist/utils/Meta/documents/getDocuments.test.js +25 -17
- package/dist/utils/Meta/documents/index.js +3 -4
- package/dist/utils/Meta/documents/setDocumentsForField.js +16 -19
- package/dist/utils/Meta/documents/setDocumentsForField.test.js +69 -35
- package/dist/utils/Meta/index.js +3 -4
- package/dist/utils/Operate/checkValueIsTruthy.js +5 -6
- package/dist/utils/Operate/checkValueIsTruthy.test.js +17 -17
- package/dist/utils/Operate/getFirstOf.js +9 -10
- package/dist/utils/Operate/getFirstOf.test.js +33 -33
- package/dist/utils/Operate/getIndexOfMatchingValueIn.js +13 -14
- package/dist/utils/Operate/getIndexOfMatchingValueIn.test.js +47 -53
- package/dist/utils/Operate/index.js +3 -4
- package/dist/utils/Operate/persistValueInFormData.js +7 -8
- package/dist/utils/Operate/persistValueInFormData.test.js +23 -21
- package/dist/utils/Operate/runPageOperations.js +10 -11
- package/dist/utils/Operate/runPageOperations.test.js +36 -37
- package/dist/utils/Operate/setValueInFormData.js +6 -7
- package/dist/utils/Operate/setValueInFormData.test.js +17 -17
- package/dist/utils/Operate/shouldRun.js +9 -10
- package/dist/utils/Operate/shouldRun.test.js +22 -28
- package/dist/utils/Validate/additional/conditionallyRequired.js +5 -7
- package/dist/utils/Validate/additional/conditionallyRequired.test.js +19 -19
- package/dist/utils/Validate/additional/index.js +8 -9
- package/dist/utils/Validate/additional/index.test.js +13 -13
- package/dist/utils/Validate/additional/mustBeAfter.js +4 -5
- package/dist/utils/Validate/additional/mustBeAfter.test.js +41 -41
- package/dist/utils/Validate/additional/mustBeBefore.js +4 -5
- package/dist/utils/Validate/additional/mustBeBefore.test.js +29 -29
- package/dist/utils/Validate/additional/mustBeEarlierDateTime.js +8 -14
- package/dist/utils/Validate/additional/mustBeEarlierDateTime.test.js +34 -38
- package/dist/utils/Validate/additional/mustBeGreaterThan.js +3 -4
- package/dist/utils/Validate/additional/mustBeGreaterThan.test.js +19 -19
- package/dist/utils/Validate/additional/mustBeInTheFuture.js +5 -6
- package/dist/utils/Validate/additional/mustBeInTheFuture.test.js +13 -13
- package/dist/utils/Validate/additional/mustBeInThePast.js +6 -7
- package/dist/utils/Validate/additional/mustBeInThePast.test.js +13 -13
- package/dist/utils/Validate/additional/mustBeLessThan.js +3 -4
- package/dist/utils/Validate/additional/mustBeLessThan.test.js +18 -18
- package/dist/utils/Validate/additional/mustBeLongerThan.js +2 -3
- package/dist/utils/Validate/additional/mustBeLongerThan.test.js +17 -17
- package/dist/utils/Validate/additional/mustBeNumbersOnly.js +3 -4
- package/dist/utils/Validate/additional/mustBeNumbersOnly.test.js +21 -21
- package/dist/utils/Validate/additional/mustBeShorterThan.js +2 -3
- package/dist/utils/Validate/additional/mustBeShorterThan.test.js +17 -17
- package/dist/utils/Validate/additional/mustEnterAtLeastOne.js +4 -7
- package/dist/utils/Validate/additional/mustEnterAtLeastOne.test.js +15 -17
- package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.js +2 -3
- package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.test.js +13 -13
- package/dist/utils/Validate/additional/mustSelectOnlyOne.js +4 -7
- package/dist/utils/Validate/additional/mustSelectOnlyOne.test.js +29 -27
- package/dist/utils/Validate/additional/utils.js +9 -25
- package/dist/utils/Validate/index.js +3 -4
- package/dist/utils/Validate/validateCollection.js +22 -29
- package/dist/utils/Validate/validateCollection.test.js +85 -77
- package/dist/utils/Validate/validateComponent.js +19 -19
- package/dist/utils/Validate/validateComponent.test.js +169 -147
- package/dist/utils/Validate/validateContainer.js +16 -22
- package/dist/utils/Validate/validateContainer.test.js +52 -48
- package/dist/utils/Validate/validateDate.js +14 -21
- package/dist/utils/Validate/validateDate.test.js +28 -29
- package/dist/utils/Validate/validateEmail.js +8 -11
- package/dist/utils/Validate/validateEmail.test.js +26 -26
- package/dist/utils/Validate/validateMultifile.js +6 -10
- package/dist/utils/Validate/validateMultifile.test.js +17 -18
- package/dist/utils/Validate/validatePage.js +20 -22
- package/dist/utils/Validate/validatePage.test.js +146 -143
- package/dist/utils/Validate/validateRegex.js +6 -10
- package/dist/utils/Validate/validateRegex.test.js +17 -17
- package/dist/utils/Validate/validateRequired.js +6 -9
- package/dist/utils/Validate/validateRequired.test.js +19 -19
- package/dist/utils/Validate/validateTextArea.js +6 -9
- package/dist/utils/Validate/validateTextArea.test.js +21 -21
- package/dist/utils/Validate/validateTime.js +8 -16
- package/dist/utils/Validate/validateTime.test.js +15 -15
- package/dist/utils/index.js +10 -12
- package/package.json +9 -6
|
@@ -2,56 +2,50 @@
|
|
|
2
2
|
|
|
3
3
|
var _models = require("../../models");
|
|
4
4
|
var _validatePage = _interopRequireDefault(require("./validatePage"));
|
|
5
|
-
function _interopRequireDefault(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
required: required
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
describe('with FormPage', function () {
|
|
23
|
-
it('should return no error when the components array is null', function () {
|
|
24
|
-
var PAGE = {
|
|
5
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
6
|
+
// Local imports
|
|
7
|
+
|
|
8
|
+
describe('utils.Validate.Page', () => {
|
|
9
|
+
const setup = (id, type, label, required) => ({
|
|
10
|
+
id,
|
|
11
|
+
fieldId: id,
|
|
12
|
+
type,
|
|
13
|
+
label,
|
|
14
|
+
required
|
|
15
|
+
});
|
|
16
|
+
describe('with FormPage', () => {
|
|
17
|
+
it('should return no error when the components array is null', () => {
|
|
18
|
+
const PAGE = {
|
|
25
19
|
components: null,
|
|
26
20
|
formData: null
|
|
27
21
|
};
|
|
28
22
|
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
29
23
|
});
|
|
30
|
-
it('should return no error when the components array is empty',
|
|
31
|
-
|
|
24
|
+
it('should return no error when the components array is empty', () => {
|
|
25
|
+
const PAGE = {
|
|
32
26
|
components: [],
|
|
33
27
|
formData: null
|
|
34
28
|
};
|
|
35
29
|
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
36
30
|
});
|
|
37
|
-
describe('when there is no form data',
|
|
38
|
-
it('should return no errors when no components are required',
|
|
39
|
-
|
|
40
|
-
|
|
31
|
+
describe('when there is no form data', () => {
|
|
32
|
+
it('should return no errors when no components are required', () => {
|
|
33
|
+
const COMPONENTS = [setup('a', _models.ComponentTypes.TEXT, 'Alpha', false), setup('b', _models.ComponentTypes.TEXT, 'Bravo', false)];
|
|
34
|
+
const PAGE = {
|
|
41
35
|
components: COMPONENTS,
|
|
42
36
|
formData: null
|
|
43
37
|
};
|
|
44
38
|
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
45
39
|
});
|
|
46
|
-
it('should return an error for each required component',
|
|
47
|
-
|
|
40
|
+
it('should return an error for each required component', () => {
|
|
41
|
+
const COMPONENTS = [setup('a', _models.ComponentTypes.TEXT, 'Alpha', true), setup('b', _models.ComponentTypes.TEXT, 'Bravo', true), setup('c', _models.ComponentTypes.TEXT, 'Charlie', false),
|
|
48
42
|
// The only unrequired one
|
|
49
43
|
setup('d', _models.ComponentTypes.TEXT, 'Delta', true), setup('e', _models.ComponentTypes.TEXT, 'Echo', true)];
|
|
50
|
-
|
|
44
|
+
const PAGE = {
|
|
51
45
|
components: COMPONENTS,
|
|
52
46
|
formData: null
|
|
53
47
|
};
|
|
54
|
-
|
|
48
|
+
const RESULT = (0, _validatePage.default)(PAGE);
|
|
55
49
|
expect(RESULT.length).toEqual(4);
|
|
56
50
|
expect(RESULT[0]).toEqual({
|
|
57
51
|
id: 'a',
|
|
@@ -70,18 +64,18 @@ describe('utils.Validate.Page', function () {
|
|
|
70
64
|
error: 'Echo is required'
|
|
71
65
|
});
|
|
72
66
|
});
|
|
73
|
-
it('should return an error for each required component on a collection page',
|
|
74
|
-
|
|
67
|
+
it('should return an error for each required component on a collection page', () => {
|
|
68
|
+
const COMPONENTS = [setup('a', _models.ComponentTypes.TEXT, 'Alpha', true), setup('b', _models.ComponentTypes.TEXT, 'Bravo', true), setup('c', _models.ComponentTypes.TEXT, 'Charlie', false),
|
|
75
69
|
// The only unrequired one
|
|
76
70
|
setup('d', _models.ComponentTypes.TEXT, 'Delta', true), setup('e', _models.ComponentTypes.TEXT, 'Echo', true)];
|
|
77
|
-
|
|
71
|
+
const PAGE = {
|
|
78
72
|
components: COMPONENTS,
|
|
79
73
|
collection: {
|
|
80
74
|
name: 'testCollection'
|
|
81
75
|
},
|
|
82
76
|
formData: null
|
|
83
77
|
};
|
|
84
|
-
|
|
78
|
+
const RESULT = (0, _validatePage.default)(PAGE);
|
|
85
79
|
expect(RESULT.length).toEqual(4);
|
|
86
80
|
expect(RESULT[0]).toEqual({
|
|
87
81
|
id: 'a',
|
|
@@ -100,8 +94,8 @@ describe('utils.Validate.Page', function () {
|
|
|
100
94
|
error: 'Echo is required'
|
|
101
95
|
});
|
|
102
96
|
});
|
|
103
|
-
it('should return an error for each required component with interpolated label',
|
|
104
|
-
|
|
97
|
+
it('should return an error for each required component with interpolated label', () => {
|
|
98
|
+
const COMPONENTS = [
|
|
105
99
|
// eslint-disable-next-line no-template-curly-in-string
|
|
106
100
|
setup('a', _models.ComponentTypes.TEXT, 'Alpha ${tiger}', true),
|
|
107
101
|
// eslint-disable-next-line no-template-curly-in-string
|
|
@@ -112,7 +106,7 @@ describe('utils.Validate.Page', function () {
|
|
|
112
106
|
setup('d', _models.ComponentTypes.CHECKBOXES, 'Delta ${lion}', true),
|
|
113
107
|
// eslint-disable-next-line no-template-curly-in-string
|
|
114
108
|
setup('e', _models.ComponentTypes.FILE, 'Echo ${zoo}', true)];
|
|
115
|
-
|
|
109
|
+
const PAGE = {
|
|
116
110
|
components: COMPONENTS,
|
|
117
111
|
formData: {
|
|
118
112
|
tiger: 'Tiger',
|
|
@@ -122,114 +116,114 @@ describe('utils.Validate.Page', function () {
|
|
|
122
116
|
zoo: 'Zoo'
|
|
123
117
|
}
|
|
124
118
|
};
|
|
125
|
-
|
|
119
|
+
const RESULT = (0, _validatePage.default)(PAGE);
|
|
126
120
|
expect(RESULT.length).toEqual(5);
|
|
127
121
|
expect(RESULT[0]).toEqual({
|
|
128
122
|
id: 'a',
|
|
129
|
-
error:
|
|
123
|
+
error: `Alpha ${PAGE.formData.tiger} is required`
|
|
130
124
|
});
|
|
131
125
|
expect(RESULT[1]).toEqual({
|
|
132
126
|
id: 'b',
|
|
133
|
-
error:
|
|
127
|
+
error: `Bravo ${PAGE.formData.panther} is required`
|
|
134
128
|
});
|
|
135
129
|
expect(RESULT[2]).toEqual({
|
|
136
130
|
id: 'c',
|
|
137
|
-
error:
|
|
131
|
+
error: `Charlie ${PAGE.formData.eagle} is required`
|
|
138
132
|
});
|
|
139
133
|
expect(RESULT[3]).toEqual({
|
|
140
134
|
id: 'd',
|
|
141
|
-
error:
|
|
135
|
+
error: `Delta ${PAGE.formData.lion} is required`
|
|
142
136
|
});
|
|
143
137
|
expect(RESULT[4]).toEqual({
|
|
144
138
|
id: 'e',
|
|
145
|
-
error:
|
|
139
|
+
error: `Echo ${PAGE.formData.zoo} is required`
|
|
146
140
|
});
|
|
147
141
|
});
|
|
148
142
|
});
|
|
149
|
-
describe('when the form data is fully valid',
|
|
150
|
-
|
|
143
|
+
describe('when the form data is fully valid', () => {
|
|
144
|
+
const DATA = {
|
|
151
145
|
alpha: 'alpha.smith@digital.homeoffice.gov.uk',
|
|
152
146
|
bravo: 'bravo.jones@digital.homeoffice.gov.uk'
|
|
153
147
|
};
|
|
154
|
-
it('should return no errors when none of the components are required or email types',
|
|
155
|
-
|
|
156
|
-
|
|
148
|
+
it('should return no errors when none of the components are required or email types', () => {
|
|
149
|
+
const COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', false), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', false)];
|
|
150
|
+
const PAGE = {
|
|
157
151
|
components: COMPONENTS,
|
|
158
152
|
formData: DATA
|
|
159
153
|
};
|
|
160
154
|
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
161
155
|
});
|
|
162
|
-
it('should return no errors when all of the components are required but not email types',
|
|
163
|
-
|
|
164
|
-
|
|
156
|
+
it('should return no errors when all of the components are required but not email types', () => {
|
|
157
|
+
const COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', true), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', true)];
|
|
158
|
+
const PAGE = {
|
|
165
159
|
components: COMPONENTS,
|
|
166
160
|
formData: DATA
|
|
167
161
|
};
|
|
168
162
|
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
169
163
|
});
|
|
170
|
-
it('should return no errors when none of the components are required but are all email types',
|
|
171
|
-
|
|
172
|
-
|
|
164
|
+
it('should return no errors when none of the components are required but are all email types', () => {
|
|
165
|
+
const COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', false), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', false)];
|
|
166
|
+
const PAGE = {
|
|
173
167
|
components: COMPONENTS,
|
|
174
168
|
formData: DATA
|
|
175
169
|
};
|
|
176
170
|
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
177
171
|
});
|
|
178
|
-
it('should return no errors when all of the components are required and email types',
|
|
179
|
-
|
|
180
|
-
|
|
172
|
+
it('should return no errors when all of the components are required and email types', () => {
|
|
173
|
+
const COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', true)];
|
|
174
|
+
const PAGE = {
|
|
181
175
|
components: COMPONENTS,
|
|
182
176
|
formData: DATA
|
|
183
177
|
};
|
|
184
178
|
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
185
179
|
});
|
|
186
180
|
});
|
|
187
|
-
describe('when the form data has one field missing and includes an invalid email',
|
|
188
|
-
|
|
181
|
+
describe('when the form data has one field missing and includes an invalid email', () => {
|
|
182
|
+
const DATA = {
|
|
189
183
|
alpha: 'alpha.smith@digital.homeoffice.gov.uk',
|
|
190
184
|
bravo: 'bravo.jones@hotmail.com'
|
|
191
185
|
};
|
|
192
|
-
it('should return no errors when none of the components are required or email types',
|
|
193
|
-
|
|
194
|
-
|
|
186
|
+
it('should return no errors when none of the components are required or email types', () => {
|
|
187
|
+
const COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', false), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', false), setup('charlie', _models.ComponentTypes.TEXT, 'Charlie', false)];
|
|
188
|
+
const PAGE = {
|
|
195
189
|
components: COMPONENTS,
|
|
196
190
|
formData: null
|
|
197
191
|
};
|
|
198
192
|
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
199
193
|
});
|
|
200
|
-
it('should return an error for the missing field when all are required but not email types',
|
|
201
|
-
|
|
202
|
-
|
|
194
|
+
it('should return an error for the missing field when all are required but not email types', () => {
|
|
195
|
+
const COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', true), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', true), setup('charlie', _models.ComponentTypes.TEXT, 'Charlie', true)];
|
|
196
|
+
const PAGE = {
|
|
203
197
|
components: COMPONENTS,
|
|
204
198
|
formData: DATA
|
|
205
199
|
};
|
|
206
|
-
|
|
200
|
+
const RESULT = (0, _validatePage.default)(PAGE);
|
|
207
201
|
expect(RESULT.length).toEqual(1);
|
|
208
202
|
expect(RESULT[0]).toEqual({
|
|
209
203
|
id: 'charlie',
|
|
210
204
|
error: 'Charlie is required'
|
|
211
205
|
});
|
|
212
206
|
});
|
|
213
|
-
it('should return an error for the invalid email field when none are required but all email types',
|
|
214
|
-
|
|
215
|
-
|
|
207
|
+
it('should return an error for the invalid email field when none are required but all email types', () => {
|
|
208
|
+
const COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', false), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', false), setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie', false)];
|
|
209
|
+
const PAGE = {
|
|
216
210
|
components: COMPONENTS,
|
|
217
211
|
formData: DATA
|
|
218
212
|
};
|
|
219
|
-
|
|
213
|
+
const RESULT = (0, _validatePage.default)(PAGE);
|
|
220
214
|
expect(RESULT.length).toEqual(1);
|
|
221
215
|
expect(RESULT[0]).toEqual({
|
|
222
216
|
id: 'bravo',
|
|
223
217
|
error: 'Enter bravo in the correct format, like jane.doe@homeoffice.gov.uk'
|
|
224
218
|
});
|
|
225
219
|
});
|
|
226
|
-
it('should return an error for both invalid fields when all are required and email types',
|
|
227
|
-
|
|
228
|
-
|
|
220
|
+
it('should return an error for both invalid fields when all are required and email types', () => {
|
|
221
|
+
const COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', true), setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie', true)];
|
|
222
|
+
const PAGE = {
|
|
229
223
|
components: COMPONENTS,
|
|
230
224
|
formData: DATA
|
|
231
225
|
};
|
|
232
|
-
|
|
226
|
+
const RESULT = (0, _validatePage.default)(PAGE);
|
|
233
227
|
expect(RESULT.length).toEqual(2);
|
|
234
228
|
expect(RESULT[0]).toEqual({
|
|
235
229
|
id: 'bravo',
|
|
@@ -240,84 +234,87 @@ describe('utils.Validate.Page', function () {
|
|
|
240
234
|
error: 'Charlie is required'
|
|
241
235
|
});
|
|
242
236
|
});
|
|
243
|
-
it('should return an interpolated error for both invalid fields when all are required and email types',
|
|
244
|
-
|
|
237
|
+
it('should return an interpolated error for both invalid fields when all are required and email types', () => {
|
|
238
|
+
const COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true),
|
|
245
239
|
// eslint-disable-next-line no-template-curly-in-string
|
|
246
240
|
setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo ${lion}', true),
|
|
247
241
|
// eslint-disable-next-line no-template-curly-in-string
|
|
248
242
|
setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie ${panther}', true)];
|
|
249
|
-
|
|
243
|
+
const PAGE = {
|
|
250
244
|
components: COMPONENTS,
|
|
251
|
-
formData:
|
|
245
|
+
formData: {
|
|
246
|
+
...DATA,
|
|
252
247
|
lion: 'Lion',
|
|
253
248
|
panther: 'Panther'
|
|
254
|
-
}
|
|
249
|
+
}
|
|
255
250
|
};
|
|
256
|
-
|
|
251
|
+
const RESULT = (0, _validatePage.default)(PAGE);
|
|
257
252
|
expect(RESULT.length).toEqual(2);
|
|
258
253
|
expect(RESULT[0]).toEqual({
|
|
259
254
|
id: 'bravo',
|
|
260
|
-
error:
|
|
255
|
+
error: `Enter bravo ${PAGE.formData.lion} in the correct format, like jane.doe@homeoffice.gov.uk`
|
|
261
256
|
});
|
|
262
257
|
expect(RESULT[1]).toEqual({
|
|
263
258
|
id: 'charlie',
|
|
264
|
-
error:
|
|
259
|
+
error: `Charlie ${PAGE.formData.panther} is required`
|
|
265
260
|
});
|
|
266
261
|
});
|
|
267
262
|
});
|
|
268
263
|
});
|
|
269
|
-
describe('with CollectionPage',
|
|
270
|
-
|
|
264
|
+
describe('with CollectionPage', () => {
|
|
265
|
+
const COLLECTION = {
|
|
271
266
|
name: 'pageCollection'
|
|
272
267
|
};
|
|
273
|
-
describe('when the form data is fully valid',
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
268
|
+
describe('when the form data is fully valid', () => {
|
|
269
|
+
const DATA = {
|
|
270
|
+
[`${COLLECTION.name}ActiveId`]: '01',
|
|
271
|
+
[COLLECTION.name]: [{
|
|
272
|
+
id: '01',
|
|
273
|
+
alpha: 'alpha.smith@digital.homeoffice.gov.uk',
|
|
274
|
+
bravo: 'bravo.jones@digital.homeoffice.gov.uk'
|
|
275
|
+
}]
|
|
276
|
+
};
|
|
277
|
+
it('should return no errors when none of the components are required or email types', () => {
|
|
278
|
+
const COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', false), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', false)];
|
|
279
|
+
const PAGE = {
|
|
283
280
|
collection: COLLECTION,
|
|
284
281
|
components: COMPONENTS,
|
|
285
282
|
formData: DATA
|
|
286
283
|
};
|
|
287
284
|
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
288
285
|
});
|
|
289
|
-
it('should return no errors when all of the components are required but not email types',
|
|
290
|
-
|
|
291
|
-
|
|
286
|
+
it('should return no errors when all of the components are required but not email types', () => {
|
|
287
|
+
const COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', true), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', true)];
|
|
288
|
+
const PAGE = {
|
|
292
289
|
collection: COLLECTION,
|
|
293
290
|
components: COMPONENTS,
|
|
294
291
|
formData: DATA
|
|
295
292
|
};
|
|
296
293
|
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
297
294
|
});
|
|
298
|
-
it('should return no errors when none of the components are required but are all email types',
|
|
299
|
-
|
|
300
|
-
|
|
295
|
+
it('should return no errors when none of the components are required but are all email types', () => {
|
|
296
|
+
const COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', false), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', false)];
|
|
297
|
+
const PAGE = {
|
|
301
298
|
collection: COLLECTION,
|
|
302
299
|
components: COMPONENTS,
|
|
303
300
|
formData: DATA
|
|
304
301
|
};
|
|
305
302
|
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
306
303
|
});
|
|
307
|
-
it('should return no errors when all of the components are required and email types',
|
|
308
|
-
|
|
309
|
-
|
|
304
|
+
it('should return no errors when all of the components are required and email types', () => {
|
|
305
|
+
const COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', true)];
|
|
306
|
+
const PAGE = {
|
|
310
307
|
collection: COLLECTION,
|
|
311
308
|
components: COMPONENTS,
|
|
312
309
|
formData: DATA
|
|
313
310
|
};
|
|
314
311
|
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
315
312
|
});
|
|
316
|
-
it('should return an error for each required component on a collection page with a show_when that is true',
|
|
317
|
-
|
|
313
|
+
it('should return an error for each required component on a collection page with a show_when that is true', () => {
|
|
314
|
+
const COMPONENTS = [setup('a', _models.ComponentTypes.TEXT, 'Alpha', true), setup('b', _models.ComponentTypes.TEXT, 'Bravo', true), setup('c', _models.ComponentTypes.TEXT, 'Charlie', false),
|
|
318
315
|
// The only unrequired one
|
|
319
316
|
setup('d', _models.ComponentTypes.TEXT, 'Delta', true), setup('e', _models.ComponentTypes.TEXT, 'Echo', true)];
|
|
320
|
-
|
|
317
|
+
const PAGE = {
|
|
321
318
|
components: COMPONENTS,
|
|
322
319
|
collection: {
|
|
323
320
|
name: 'testCollection'
|
|
@@ -335,7 +332,7 @@ describe('utils.Validate.Page', function () {
|
|
|
335
332
|
}]
|
|
336
333
|
}
|
|
337
334
|
};
|
|
338
|
-
|
|
335
|
+
const RESULT = (0, _validatePage.default)(PAGE);
|
|
339
336
|
expect(RESULT.length).toEqual(4);
|
|
340
337
|
expect(RESULT[0]).toEqual({
|
|
341
338
|
id: 'a',
|
|
@@ -354,11 +351,11 @@ describe('utils.Validate.Page', function () {
|
|
|
354
351
|
error: 'Echo is required'
|
|
355
352
|
});
|
|
356
353
|
});
|
|
357
|
-
it('should return no errors on a collection page with a show_when that is false',
|
|
358
|
-
|
|
354
|
+
it('should return no errors on a collection page with a show_when that is false', () => {
|
|
355
|
+
const COMPONENTS = [setup('a', _models.ComponentTypes.TEXT, 'Alpha', true), setup('b', _models.ComponentTypes.TEXT, 'Bravo', true), setup('c', _models.ComponentTypes.TEXT, 'Charlie', false),
|
|
359
356
|
// The only unrequired one
|
|
360
357
|
setup('d', _models.ComponentTypes.TEXT, 'Delta', true), setup('e', _models.ComponentTypes.TEXT, 'Echo', true)];
|
|
361
|
-
|
|
358
|
+
const PAGE = {
|
|
362
359
|
components: COMPONENTS,
|
|
363
360
|
collection: {
|
|
364
361
|
name: 'testCollection'
|
|
@@ -376,62 +373,64 @@ describe('utils.Validate.Page', function () {
|
|
|
376
373
|
}]
|
|
377
374
|
}
|
|
378
375
|
};
|
|
379
|
-
|
|
376
|
+
const RESULT = (0, _validatePage.default)(PAGE);
|
|
380
377
|
expect(RESULT.length).toEqual(0);
|
|
381
378
|
});
|
|
382
379
|
});
|
|
383
|
-
describe('when the form data has one field missing and includes an invalid email',
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
380
|
+
describe('when the form data has one field missing and includes an invalid email', () => {
|
|
381
|
+
const DATA = {
|
|
382
|
+
[`${COLLECTION.name}ActiveId`]: '01',
|
|
383
|
+
[COLLECTION.name]: [{
|
|
384
|
+
id: '01',
|
|
385
|
+
alpha: 'alpha.smith@digital.homeoffice.gov.uk',
|
|
386
|
+
bravo: 'bravo.jones@hotmail.com'
|
|
387
|
+
}]
|
|
388
|
+
};
|
|
389
|
+
it('should return no errors when none of the components are required or email types', () => {
|
|
390
|
+
const COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', false), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', false), setup('charlie', _models.ComponentTypes.TEXT, 'Charlie', false)];
|
|
391
|
+
const PAGE = {
|
|
393
392
|
collection: COLLECTION,
|
|
394
393
|
components: COMPONENTS,
|
|
395
394
|
formData: null
|
|
396
395
|
};
|
|
397
396
|
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
398
397
|
});
|
|
399
|
-
it('should return an error for the missing field when all are required but not email types',
|
|
400
|
-
|
|
401
|
-
|
|
398
|
+
it('should return an error for the missing field when all are required but not email types', () => {
|
|
399
|
+
const COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', true), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', true), setup('charlie', _models.ComponentTypes.TEXT, 'Charlie', true)];
|
|
400
|
+
const PAGE = {
|
|
402
401
|
collection: COLLECTION,
|
|
403
402
|
components: COMPONENTS,
|
|
404
403
|
formData: DATA
|
|
405
404
|
};
|
|
406
|
-
|
|
405
|
+
const RESULT = (0, _validatePage.default)(PAGE);
|
|
407
406
|
expect(RESULT.length).toEqual(1);
|
|
408
407
|
expect(RESULT[0]).toEqual({
|
|
409
408
|
id: 'charlie',
|
|
410
409
|
error: 'Charlie is required'
|
|
411
410
|
});
|
|
412
411
|
});
|
|
413
|
-
it('should return an error for the invalid email field when none are required but all email types',
|
|
414
|
-
|
|
415
|
-
|
|
412
|
+
it('should return an error for the invalid email field when none are required but all email types', () => {
|
|
413
|
+
const COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', false), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', false), setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie', false)];
|
|
414
|
+
const PAGE = {
|
|
416
415
|
collection: COLLECTION,
|
|
417
416
|
components: COMPONENTS,
|
|
418
417
|
formData: DATA
|
|
419
418
|
};
|
|
420
|
-
|
|
419
|
+
const RESULT = (0, _validatePage.default)(PAGE);
|
|
421
420
|
expect(RESULT.length).toEqual(1);
|
|
422
421
|
expect(RESULT[0]).toEqual({
|
|
423
422
|
id: 'bravo',
|
|
424
423
|
error: 'Enter bravo in the correct format, like jane.doe@homeoffice.gov.uk'
|
|
425
424
|
});
|
|
426
425
|
});
|
|
427
|
-
it('should return an error for both invalid fields when all are required and email types',
|
|
428
|
-
|
|
429
|
-
|
|
426
|
+
it('should return an error for both invalid fields when all are required and email types', () => {
|
|
427
|
+
const COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', true), setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie', true)];
|
|
428
|
+
const PAGE = {
|
|
430
429
|
collection: COLLECTION,
|
|
431
430
|
components: COMPONENTS,
|
|
432
431
|
formData: DATA
|
|
433
432
|
};
|
|
434
|
-
|
|
433
|
+
const RESULT = (0, _validatePage.default)(PAGE);
|
|
435
434
|
expect(RESULT.length).toEqual(2);
|
|
436
435
|
expect(RESULT[0]).toEqual({
|
|
437
436
|
id: 'bravo',
|
|
@@ -442,29 +441,33 @@ describe('utils.Validate.Page', function () {
|
|
|
442
441
|
error: 'Charlie is required'
|
|
443
442
|
});
|
|
444
443
|
});
|
|
445
|
-
it('should return an interpolated error for both invalid fields when all are required and email types',
|
|
446
|
-
|
|
444
|
+
it('should return an interpolated error for both invalid fields when all are required and email types', () => {
|
|
445
|
+
const COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true),
|
|
447
446
|
// eslint-disable-next-line no-template-curly-in-string
|
|
448
447
|
setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo ${lion}', true),
|
|
449
448
|
// eslint-disable-next-line no-template-curly-in-string
|
|
450
449
|
setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie ${panther}', true)];
|
|
451
|
-
|
|
450
|
+
const PAGE = {
|
|
452
451
|
collection: COLLECTION,
|
|
453
452
|
components: COMPONENTS,
|
|
454
|
-
formData:
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
453
|
+
formData: {
|
|
454
|
+
...DATA,
|
|
455
|
+
[COLLECTION.name]: [{
|
|
456
|
+
...DATA[COLLECTION.name][0],
|
|
457
|
+
lion: 'Lion',
|
|
458
|
+
panther: 'Panther'
|
|
459
|
+
}]
|
|
460
|
+
}
|
|
458
461
|
};
|
|
459
|
-
|
|
462
|
+
const RESULT = (0, _validatePage.default)(PAGE);
|
|
460
463
|
expect(RESULT.length).toEqual(2);
|
|
461
464
|
expect(RESULT[0]).toEqual({
|
|
462
465
|
id: 'bravo',
|
|
463
|
-
error:
|
|
466
|
+
error: `Enter bravo ${PAGE.formData[COLLECTION.name][0].lion} in the correct format, like jane.doe@homeoffice.gov.uk`
|
|
464
467
|
});
|
|
465
468
|
expect(RESULT[1]).toEqual({
|
|
466
469
|
id: 'charlie',
|
|
467
|
-
error:
|
|
470
|
+
error: `Charlie ${PAGE.formData[COLLECTION.name][0].panther} is required`
|
|
468
471
|
});
|
|
469
472
|
});
|
|
470
473
|
});
|
|
@@ -15,21 +15,18 @@ exports.default = void 0;
|
|
|
15
15
|
* @param {array} customErrors The array of custom errors for the component.
|
|
16
16
|
* @returns An error if the value doesn't match the regex pattern.
|
|
17
17
|
*/
|
|
18
|
-
|
|
18
|
+
const validateRegex = (value, label, pattern, customErrors) => {
|
|
19
19
|
if (!value) {
|
|
20
20
|
return undefined;
|
|
21
21
|
}
|
|
22
22
|
if (typeof value === 'string') {
|
|
23
|
-
|
|
23
|
+
const regex = new RegExp(pattern);
|
|
24
24
|
if (regex.test(value)) {
|
|
25
25
|
return undefined;
|
|
26
26
|
}
|
|
27
27
|
if (Array.isArray(customErrors)) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return error.type === 'pattern';
|
|
31
|
-
});
|
|
32
|
-
if (result !== null && result !== void 0 && (_result$ = result[0]) !== null && _result$ !== void 0 && _result$.message) {
|
|
28
|
+
const result = customErrors.filter(error => error.type === 'pattern');
|
|
29
|
+
if (result?.[0]?.message) {
|
|
33
30
|
return result[0].message;
|
|
34
31
|
}
|
|
35
32
|
}
|
|
@@ -37,7 +34,6 @@ var validateRegex = function validateRegex(value, label, pattern, customErrors)
|
|
|
37
34
|
if (!label) {
|
|
38
35
|
return 'Component failed regex validation';
|
|
39
36
|
}
|
|
40
|
-
return
|
|
37
|
+
return `${label} failed regex validation`;
|
|
41
38
|
};
|
|
42
|
-
var _default = validateRegex;
|
|
43
|
-
exports.default = _default;
|
|
39
|
+
var _default = exports.default = validateRegex;
|