@ukhomeoffice/cop-react-form-renderer 5.45.1 → 5.45.2-alpha
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 +12 -12
- package/dist/components/CheckYourAnswers/Answer.test.js +92 -127
- package/dist/components/CheckYourAnswers/CheckYourAnswers.js +101 -131
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +464 -769
- package/dist/components/CollectionPage/CollectionPage.js +66 -58
- package/dist/components/CollectionPage/CollectionPage.test.js +300 -342
- package/dist/components/CollectionSummary/BannerStrip.js +12 -12
- package/dist/components/CollectionSummary/BannerStrip.test.js +63 -59
- package/dist/components/CollectionSummary/CollectionSummary.js +60 -75
- package/dist/components/CollectionSummary/CollectionSummary.test.js +102 -96
- package/dist/components/CollectionSummary/Confirmation.js +14 -12
- package/dist/components/CollectionSummary/Confirmation.test.js +68 -63
- package/dist/components/CollectionSummary/SummaryCard.js +93 -133
- package/dist/components/CollectionSummary/SummaryCard.test.js +902 -924
- package/dist/components/CollectionSummary/SummaryCardValidationContext.js +23 -29
- package/dist/components/CollectionSummary/SummaryCardValidationContext.test.js +61 -73
- package/dist/components/FormComponent/Collection.js +73 -107
- package/dist/components/FormComponent/Collection.test.js +809 -945
- package/dist/components/FormComponent/Container.js +40 -38
- package/dist/components/FormComponent/Container.test.js +314 -345
- package/dist/components/FormComponent/FormComponent.js +67 -70
- package/dist/components/FormComponent/FormComponent.test.js +284 -342
- package/dist/components/FormComponent/helpers/addLabel.js +4 -7
- package/dist/components/FormComponent/helpers/getComponentDisabled.js +1 -1
- package/dist/components/FormComponent/helpers/getComponentDisabled.test.js +7 -7
- package/dist/components/FormComponent/helpers/getComponentError.js +3 -5
- package/dist/components/FormComponent/helpers/getComponentError.test.js +14 -14
- package/dist/components/FormComponent/helpers/getComponentFieldSet.js +3 -4
- package/dist/components/FormComponent/helpers/getComponentFieldSet.test.js +6 -6
- package/dist/components/FormComponent/helpers/index.js +4 -4
- package/dist/components/FormPage/FormPage.js +65 -80
- package/dist/components/FormPage/FormPage.test.js +127 -163
- package/dist/components/FormRenderer/FormRenderer.js +142 -178
- package/dist/components/FormRenderer/FormRenderer.test.js +730 -1115
- package/dist/components/FormRenderer/handlers/cyaAction.js +2 -2
- package/dist/components/FormRenderer/handlers/getPageId.js +1 -3
- package/dist/components/FormRenderer/handlers/getPageId.test.js +14 -14
- package/dist/components/FormRenderer/handlers/handlers.test.js +32 -32
- package/dist/components/FormRenderer/handlers/index.js +1 -1
- package/dist/components/FormRenderer/handlers/navigate.js +3 -3
- package/dist/components/FormRenderer/handlers/submissionError.js +1 -1
- package/dist/components/FormRenderer/helpers/canActionProceed.js +1 -1
- package/dist/components/FormRenderer/helpers/canActionProceed.test.js +9 -9
- package/dist/components/FormRenderer/helpers/canCYASubmit.js +1 -3
- package/dist/components/FormRenderer/helpers/canCYASubmit.test.js +16 -20
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.js +17 -22
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.test.js +16 -16
- package/dist/components/FormRenderer/helpers/getCYA.js +3 -5
- package/dist/components/FormRenderer/helpers/getCYA.test.js +11 -11
- package/dist/components/FormRenderer/helpers/getFormState.js +5 -7
- package/dist/components/FormRenderer/helpers/getFormState.test.js +10 -10
- package/dist/components/FormRenderer/helpers/getNextPageId.js +13 -24
- package/dist/components/FormRenderer/helpers/getNextPageId.test.js +67 -67
- package/dist/components/FormRenderer/helpers/getPage.js +2 -4
- package/dist/components/FormRenderer/helpers/getPage.test.js +11 -11
- package/dist/components/FormRenderer/helpers/getRelevantPages.js +7 -9
- package/dist/components/FormRenderer/helpers/getRelevantPages.test.js +14 -14
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +5 -5
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +97 -91
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.js +62 -60
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.test.js +71 -73
- package/dist/components/FormRenderer/helpers/index.js +1 -1
- package/dist/components/FormRenderer/onCYAAction.js +59 -51
- package/dist/components/FormRenderer/onCYAAction.test.js +164 -152
- package/dist/components/FormRenderer/onPageAction.js +43 -39
- package/dist/components/FormRenderer/onPageAction.test.js +223 -206
- package/dist/components/FormRenderer/onTaskAction.js +9 -13
- package/dist/components/FormRenderer/onTaskAction.test.js +93 -88
- package/dist/components/PageActions/ActionButton.js +12 -15
- package/dist/components/PageActions/ActionButton.test.js +56 -78
- package/dist/components/PageActions/PageActions.js +10 -10
- package/dist/components/PageActions/PageActions.test.js +86 -115
- package/dist/components/SummaryList/GroupAction.js +9 -17
- package/dist/components/SummaryList/GroupAction.test.js +37 -33
- package/dist/components/SummaryList/RowAction.js +11 -16
- package/dist/components/SummaryList/RowAction.test.js +37 -33
- package/dist/components/SummaryList/SummaryList.js +21 -26
- package/dist/components/SummaryList/SummaryList.test.js +143 -166
- package/dist/components/SummaryList/SummaryListHeadingRow.js +6 -4
- package/dist/components/SummaryList/SummaryListRow.js +6 -4
- package/dist/components/SummaryList/SummaryListTitleRow.js +5 -3
- package/dist/components/SummaryList/helpers/getGroupActionAttributes.js +3 -5
- package/dist/components/SummaryList/helpers/getGroupActionAttributes.test.js +22 -22
- package/dist/components/SummaryList/helpers/getRowActionAttributes.js +3 -5
- package/dist/components/SummaryList/helpers/getRowActionAttributes.test.js +22 -22
- package/dist/components/SummaryList/helpers/index.js +1 -1
- package/dist/components/TaskList/Task.js +19 -29
- package/dist/components/TaskList/Task.test.js +83 -76
- package/dist/components/TaskList/TaskList.js +45 -71
- package/dist/components/TaskList/TaskList.test.js +113 -111
- package/dist/components/TaskList/TaskState.js +7 -5
- package/dist/components/TaskList/TaskState.test.js +52 -45
- package/dist/components/index.js +7 -7
- package/dist/context/HooksContext/HooksContext.js +58 -79
- package/dist/context/HooksContext/HooksContext.test.js +26 -35
- package/dist/context/HooksContext/index.js +3 -4
- package/dist/context/ValidationContext/ValidationContext.js +32 -72
- package/dist/context/ValidationContext/ValidationContext.test.js +47 -59
- package/dist/context/ValidationContext/index.js +3 -4
- package/dist/context/index.js +2 -2
- package/dist/hooks/index.js +9 -10
- package/dist/hooks/useAxios.js +14 -40
- package/dist/hooks/useGetRequest.js +61 -97
- package/dist/hooks/useHooks.js +1 -3
- package/dist/hooks/useRefData.js +26 -39
- package/dist/hooks/useValidation.js +1 -3
- package/dist/index.js +13 -14
- package/dist/models/CollectionLabels.js +1 -1
- package/dist/models/ComponentTypes.js +25 -25
- package/dist/models/EventTypes.js +4 -4
- package/dist/models/FormPages.js +4 -4
- package/dist/models/FormTypes.js +8 -8
- package/dist/models/HubFormats.js +3 -3
- package/dist/models/PageAction.js +44 -38
- package/dist/models/TaskStates.js +30 -28
- package/dist/models/index.js +9 -9
- package/dist/setupTests.js +30 -31
- package/dist/utils/CheckYourAnswers/getCYAAction.js +5 -5
- package/dist/utils/CheckYourAnswers/getCYAAction.test.js +52 -54
- package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.js +15 -25
- package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.test.js +33 -35
- package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.js +17 -31
- package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.test.js +42 -44
- package/dist/utils/CheckYourAnswers/getCYARow.js +6 -6
- package/dist/utils/CheckYourAnswers/getCYARow.test.js +86 -86
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.js +18 -24
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.test.js +15 -16
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.js +33 -36
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.test.js +58 -60
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +79 -88
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +146 -124
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.js +25 -20
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.test.js +103 -97
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +13 -18
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.test.js +70 -76
- package/dist/utils/CheckYourAnswers/index.js +1 -1
- package/dist/utils/CheckYourAnswers/showComponentCYA.js +4 -4
- package/dist/utils/CheckYourAnswers/showComponentCYA.test.js +24 -24
- package/dist/utils/CollectionPage/addCollectionPageEntry.js +1 -1
- package/dist/utils/CollectionPage/addCollectionPageEntry.test.js +5 -5
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.js +2 -2
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.test.js +17 -17
- package/dist/utils/CollectionPage/duplicateCollectionPageEntry.js +9 -18
- package/dist/utils/CollectionPage/duplicateCollectionPageEntry.test.js +27 -22
- package/dist/utils/CollectionPage/getCollectionPageActiveId.js +2 -2
- package/dist/utils/CollectionPage/getCollectionPageActiveId.test.js +10 -10
- package/dist/utils/CollectionPage/getCollectionPageActiveIndex.js +7 -11
- package/dist/utils/CollectionPage/getCollectionPageActiveIndex.test.js +22 -22
- package/dist/utils/CollectionPage/getCollectionPageData.js +8 -12
- package/dist/utils/CollectionPage/getCollectionPageData.test.js +19 -19
- package/dist/utils/CollectionPage/getQuickEditPage.js +19 -19
- package/dist/utils/CollectionPage/getQuickEditPage.test.js +12 -16
- package/dist/utils/CollectionPage/index.js +1 -1
- package/dist/utils/CollectionPage/mergeCollectionPages.js +29 -30
- package/dist/utils/CollectionPage/mergeCollectionPages.test.js +17 -17
- package/dist/utils/CollectionPage/removeCollectionPageEntry.js +4 -6
- package/dist/utils/CollectionPage/removeCollectionPageEntry.test.js +10 -10
- package/dist/utils/CollectionPage/setCollectionPageData.js +8 -12
- package/dist/utils/CollectionPage/setCollectionPageData.test.js +17 -17
- package/dist/utils/Component/addShowWhen.js +4 -8
- package/dist/utils/Component/addShowWhen.test.js +37 -37
- package/dist/utils/Component/applyToComponentTree.js +18 -18
- package/dist/utils/Component/applyToComponentTree.test.js +27 -32
- package/dist/utils/Component/cleanAttributes.js +10 -13
- package/dist/utils/Component/cleanAttributes.test.js +17 -18
- package/dist/utils/Component/elevateNestedComponents.js +5 -5
- package/dist/utils/Component/elevateNestedComponents.test.js +30 -30
- package/dist/utils/Component/getComponent.js +88 -94
- package/dist/utils/Component/getComponentTests/getComponent.autocomplete.test.js +18 -17
- package/dist/utils/Component/getComponentTests/getComponent.calculation.test.js +46 -59
- package/dist/utils/Component/getComponentTests/getComponent.checkboxes.test.js +39 -48
- package/dist/utils/Component/getComponentTests/getComponent.date.test.js +23 -33
- package/dist/utils/Component/getComponentTests/getComponent.details.test.js +20 -18
- package/dist/utils/Component/getComponentTests/getComponent.email.test.js +17 -22
- package/dist/utils/Component/getComponentTests/getComponent.file.test.js +20 -25
- package/dist/utils/Component/getComponentTests/getComponent.heading.test.js +10 -9
- package/dist/utils/Component/getComponentTests/getComponent.html.test.js +17 -15
- package/dist/utils/Component/getComponentTests/getComponent.insetText.test.js +9 -8
- package/dist/utils/Component/getComponentTests/getComponent.list.test.js +17 -15
- package/dist/utils/Component/getComponentTests/getComponent.multifile.test.js +22 -26
- package/dist/utils/Component/getComponentTests/getComponent.nested.test.js +155 -175
- package/dist/utils/Component/getComponentTests/getComponent.paragraph.test.js +17 -15
- package/dist/utils/Component/getComponentTests/getComponent.phoneNumber.test.js +17 -22
- package/dist/utils/Component/getComponentTests/getComponent.radios.test.js +57 -70
- package/dist/utils/Component/getComponentTests/getComponent.select.test.js +17 -22
- package/dist/utils/Component/getComponentTests/getComponent.text.test.js +17 -22
- package/dist/utils/Component/getComponentTests/getComponent.textArea.test.js +31 -38
- package/dist/utils/Component/getComponentTests/getComponent.time.test.js +20 -29
- package/dist/utils/Component/getComponentTests/getComponent.unknown.test.js +2 -2
- package/dist/utils/Component/getComponentTests/getComponent.warningText.test.js +9 -8
- package/dist/utils/Component/getDefaultValue.js +6 -8
- package/dist/utils/Component/getDefaultValue.test.js +12 -12
- package/dist/utils/Component/getDefaultValueFromConfig.js +22 -21
- package/dist/utils/Component/getDefaultValueFromConfig.test.js +31 -31
- package/dist/utils/Component/index.js +1 -1
- package/dist/utils/Component/isEditable.js +2 -4
- package/dist/utils/Component/isEditable.test.js +14 -15
- package/dist/utils/Component/optionIsSelected.js +1 -1
- package/dist/utils/Component/optionIsSelected.test.js +9 -9
- package/dist/utils/Component/setupContainerComponentsPath.js +27 -29
- package/dist/utils/Component/setupContainerComponentsPath.test.js +11 -11
- package/dist/utils/Component/showComponent.js +1 -1
- package/dist/utils/Component/showComponent.test.js +28 -28
- package/dist/utils/Component/wrapInFormGroup.js +2 -2
- package/dist/utils/Condition/index.js +1 -1
- package/dist/utils/Condition/meetsAllConditions.js +7 -7
- package/dist/utils/Condition/meetsAllConditions.test.js +17 -17
- package/dist/utils/Condition/meetsCondition.js +14 -17
- package/dist/utils/Condition/meetsCondition.test.js +376 -376
- package/dist/utils/Condition/meetsOneCondition.js +5 -5
- package/dist/utils/Condition/meetsOneCondition.test.js +16 -16
- package/dist/utils/Condition/setupConditions.js +13 -18
- package/dist/utils/Condition/setupConditions.test.js +7 -7
- package/dist/utils/Container/getEditableComponents.js +3 -5
- package/dist/utils/Container/getEditableComponents.test.js +43 -45
- package/dist/utils/Container/index.js +1 -1
- package/dist/utils/Container/setupNesting.js +16 -20
- package/dist/utils/Container/setupNesting.test.js +27 -30
- package/dist/utils/Container/showContainer.js +3 -7
- package/dist/utils/Container/showContainer.test.js +30 -30
- package/dist/utils/Data/applyFormula.js +38 -48
- package/dist/utils/Data/applyFormula.test.js +20 -20
- package/dist/utils/Data/getAutocompleteSource.js +18 -26
- package/dist/utils/Data/getAutocompleteSource.test.js +80 -86
- package/dist/utils/Data/getDataPath.js +18 -28
- package/dist/utils/Data/getDataPath.test.js +12 -12
- package/dist/utils/Data/getOptions.js +19 -25
- package/dist/utils/Data/getOptions.test.js +20 -20
- package/dist/utils/Data/getSourceData.js +6 -19
- package/dist/utils/Data/getSourceData.test.js +84 -80
- package/dist/utils/Data/index.js +1 -1
- package/dist/utils/Data/refDataToOptions.js +10 -13
- package/dist/utils/Data/refDataToOptions.test.js +19 -19
- package/dist/utils/Data/setDataItem.js +7 -8
- package/dist/utils/Data/setDataItem.test.js +37 -37
- package/dist/utils/Data/setupFormData.js +13 -21
- package/dist/utils/Data/setupFormData.test.js +51 -50
- package/dist/utils/Data/setupRefDataUrlForComponent.js +20 -26
- package/dist/utils/Data/setupRefDataUrlForComponent.test.js +24 -24
- package/dist/utils/FormPage/applyConditionalProperties.js +5 -9
- package/dist/utils/FormPage/applyConditionalProperties.test.js +15 -18
- package/dist/utils/FormPage/getFormPage.js +15 -16
- package/dist/utils/FormPage/getFormPage.test.js +47 -46
- package/dist/utils/FormPage/getFormPages.js +7 -12
- package/dist/utils/FormPage/getFormPages.test.js +20 -23
- package/dist/utils/FormPage/getPageActions.js +9 -15
- package/dist/utils/FormPage/getPageActions.test.js +32 -32
- package/dist/utils/FormPage/getPageTitle.js +2 -2
- package/dist/utils/FormPage/getPageTitle.test.js +22 -22
- package/dist/utils/FormPage/getParagraphFromText.js +5 -7
- package/dist/utils/FormPage/getParagraphFromText.test.js +6 -6
- package/dist/utils/FormPage/index.js +1 -1
- package/dist/utils/FormPage/showFormPage.js +3 -7
- package/dist/utils/FormPage/showFormPage.test.js +32 -32
- package/dist/utils/FormPage/showFormPageCYA.js +1 -1
- package/dist/utils/FormPage/showFormPageCYA.test.js +8 -8
- package/dist/utils/FormPage/useComponent.js +21 -28
- package/dist/utils/FormPage/useComponent.test.js +78 -79
- package/dist/utils/Format/formatData.js +1 -1
- package/dist/utils/Format/formatData.test.js +18 -18
- package/dist/utils/Format/formatDataForComponent.js +5 -6
- package/dist/utils/Format/formatDataForComponent.test.js +50 -77
- package/dist/utils/Format/formatDataForForm.js +6 -8
- package/dist/utils/Format/formatDataForForm.test.js +13 -15
- package/dist/utils/Format/formatDataForPage.js +4 -5
- package/dist/utils/Format/formatDataForPage.test.js +20 -23
- package/dist/utils/Format/index.js +1 -1
- package/dist/utils/Hub/getFormHub.js +1 -1
- package/dist/utils/Hub/getFormHub.test.js +28 -31
- package/dist/utils/Hub/index.js +1 -1
- package/dist/utils/Meta/constants.js +2 -2
- package/dist/utils/Meta/documents/getDocuments.js +1 -1
- package/dist/utils/Meta/documents/getDocuments.test.js +24 -16
- package/dist/utils/Meta/documents/index.js +1 -1
- package/dist/utils/Meta/documents/setDocumentsForField.js +14 -16
- package/dist/utils/Meta/documents/setDocumentsForField.test.js +68 -34
- package/dist/utils/Meta/index.js +1 -1
- package/dist/utils/Operate/checkValueIsTruthy.js +2 -2
- package/dist/utils/Operate/checkValueIsTruthy.test.js +16 -16
- package/dist/utils/Operate/getFirstOf.js +5 -5
- package/dist/utils/Operate/getFirstOf.test.js +31 -31
- package/dist/utils/Operate/getIndexOfMatchingValueIn.js +10 -10
- package/dist/utils/Operate/getIndexOfMatchingValueIn.test.js +46 -46
- package/dist/utils/Operate/index.js +1 -1
- package/dist/utils/Operate/persistValueInFormData.js +3 -3
- package/dist/utils/Operate/persistValueInFormData.test.js +22 -20
- package/dist/utils/Operate/runPageOperations.js +7 -7
- package/dist/utils/Operate/runPageOperations.test.js +35 -36
- package/dist/utils/Operate/setValueInFormData.js +2 -2
- package/dist/utils/Operate/setValueInFormData.test.js +16 -16
- package/dist/utils/Operate/shouldRun.js +6 -6
- package/dist/utils/Operate/shouldRun.test.js +21 -26
- package/dist/utils/Validate/additional/conditionallyRequired.js +4 -4
- package/dist/utils/Validate/additional/conditionallyRequired.test.js +18 -18
- package/dist/utils/Validate/additional/index.js +6 -6
- package/dist/utils/Validate/additional/index.test.js +12 -12
- package/dist/utils/Validate/additional/mustBeAfter.js +2 -2
- package/dist/utils/Validate/additional/mustBeAfter.test.js +40 -40
- package/dist/utils/Validate/additional/mustBeBefore.js +2 -2
- package/dist/utils/Validate/additional/mustBeBefore.test.js +28 -28
- package/dist/utils/Validate/additional/mustBeEarlierDateTime.js +7 -11
- package/dist/utils/Validate/additional/mustBeEarlierDateTime.test.js +37 -41
- package/dist/utils/Validate/additional/mustBeGreaterThan.js +2 -2
- package/dist/utils/Validate/additional/mustBeGreaterThan.test.js +18 -18
- package/dist/utils/Validate/additional/mustBeInTheFuture.js +2 -2
- package/dist/utils/Validate/additional/mustBeInTheFuture.test.js +12 -12
- package/dist/utils/Validate/additional/mustBeInThePast.js +3 -3
- package/dist/utils/Validate/additional/mustBeInThePast.test.js +12 -12
- package/dist/utils/Validate/additional/mustBeLessThan.js +2 -2
- package/dist/utils/Validate/additional/mustBeLessThan.test.js +17 -17
- package/dist/utils/Validate/additional/mustBeLongerThan.js +1 -1
- package/dist/utils/Validate/additional/mustBeLongerThan.test.js +16 -16
- package/dist/utils/Validate/additional/mustBeNumbersOnly.js +2 -2
- package/dist/utils/Validate/additional/mustBeNumbersOnly.test.js +20 -20
- package/dist/utils/Validate/additional/mustBeShorterThan.js +1 -1
- package/dist/utils/Validate/additional/mustBeShorterThan.test.js +16 -16
- package/dist/utils/Validate/additional/mustEnterAtLeastOne.js +2 -2
- package/dist/utils/Validate/additional/mustEnterAtLeastOne.test.js +14 -16
- package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.js +1 -1
- package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.test.js +12 -12
- package/dist/utils/Validate/additional/mustNotContainSql.js +3 -4
- package/dist/utils/Validate/additional/mustNotContainSql.test.js +14 -14
- package/dist/utils/Validate/additional/mustSelectOnlyOne.js +2 -2
- package/dist/utils/Validate/additional/mustSelectOnlyOne.test.js +28 -26
- package/dist/utils/Validate/additional/utils.js +9 -22
- package/dist/utils/Validate/index.js +1 -1
- package/dist/utils/Validate/validateCollection.js +19 -25
- package/dist/utils/Validate/validateCollection.test.js +74 -66
- package/dist/utils/Validate/validateComponent.js +17 -15
- package/dist/utils/Validate/validateComponent.test.js +167 -146
- package/dist/utils/Validate/validateContainer.js +14 -19
- package/dist/utils/Validate/validateContainer.test.js +49 -45
- package/dist/utils/Validate/validateDate.js +11 -17
- package/dist/utils/Validate/validateDate.test.js +28 -29
- package/dist/utils/Validate/validateEmail.js +6 -8
- package/dist/utils/Validate/validateEmail.test.js +25 -25
- package/dist/utils/Validate/validateMultifile.js +5 -7
- package/dist/utils/Validate/validateMultifile.test.js +17 -18
- package/dist/utils/Validate/validatePage.js +17 -18
- package/dist/utils/Validate/validatePage.test.js +185 -182
- package/dist/utils/Validate/validateRegex.js +3 -5
- package/dist/utils/Validate/validateRegex.test.js +14 -14
- package/dist/utils/Validate/validateRequired.js +4 -6
- package/dist/utils/Validate/validateRequired.test.js +18 -18
- package/dist/utils/Validate/validateTextArea.js +4 -6
- package/dist/utils/Validate/validateTextArea.test.js +20 -20
- package/dist/utils/Validate/validateTime.js +7 -14
- package/dist/utils/Validate/validateTime.test.js +14 -14
- package/dist/utils/index.js +7 -9
- package/package.json +1 -1
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
@@ -8,99 +7,79 @@ exports.default = exports.HooksContext = exports.ALLOWED_HOOKS = void 0;
|
|
|
8
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
10
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function
|
|
12
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" !=
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return {
|
|
27
|
-
formData: formData,
|
|
28
|
-
patch: patch
|
|
29
|
-
};
|
|
30
|
-
},
|
|
31
|
-
onChange: function onChange(data) {},
|
|
32
|
-
onFormComplete: function onFormComplete() {},
|
|
33
|
-
onFormLoad: function onFormLoad(setCurrentTask) {},
|
|
34
|
-
onGetComponent: function onGetComponent(config, wrap) {
|
|
35
|
-
return null;
|
|
36
|
-
},
|
|
37
|
-
onGetCYA: function onGetCYA(config) {
|
|
38
|
-
return null;
|
|
39
|
-
},
|
|
10
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
11
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
12
|
+
/* eslint-disable no-unused-vars, react/jsx-no-constructed-context-values, react/function-component-definition */
|
|
13
|
+
// Global imports
|
|
14
|
+
|
|
15
|
+
const DEFAULT_HOOKS = {
|
|
16
|
+
onAction: (formData, patch) => ({
|
|
17
|
+
formData,
|
|
18
|
+
patch
|
|
19
|
+
}),
|
|
20
|
+
onChange: data => {},
|
|
21
|
+
onFormComplete: () => {},
|
|
22
|
+
onFormLoad: setCurrentTask => {},
|
|
23
|
+
onGetComponent: (config, wrap) => null,
|
|
24
|
+
onGetCYA: config => null,
|
|
40
25
|
// onGetCYARows should return either a single row, or an array of rows for the given component.
|
|
41
26
|
// If it returns null then Form Renderer will attempt to get the default rows for the component.
|
|
42
|
-
onGetCYARows:
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return pageId;
|
|
48
|
-
},
|
|
49
|
-
onRequest: function onRequest(req) {
|
|
50
|
-
return req;
|
|
51
|
-
},
|
|
52
|
-
onSubmit: function onSubmit(type, payload, onSuccess, onError) {
|
|
27
|
+
onGetCYARows: (page, component, onAction) => null,
|
|
28
|
+
onGoingBack: () => {},
|
|
29
|
+
onPageChange: (pageId, state) => pageId,
|
|
30
|
+
onRequest: req => req,
|
|
31
|
+
onSubmit: (type, payload, onSuccess, onError) => {
|
|
53
32
|
if (typeof onSuccess === 'function') onSuccess();
|
|
54
33
|
},
|
|
55
|
-
onValidate:
|
|
56
|
-
return errors;
|
|
57
|
-
},
|
|
34
|
+
onValidate: (page, errors) => errors,
|
|
58
35
|
// Returns the list of errors already found in FR by default.
|
|
59
|
-
onCancel:
|
|
36
|
+
onCancel: data => {} // Consuming application must provide function to action, else this does nothing.
|
|
60
37
|
};
|
|
61
38
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
var addHook = function addHook(name, hook) {
|
|
39
|
+
const ALLOWED_HOOKS = exports.ALLOWED_HOOKS = Object.keys(DEFAULT_HOOKS);
|
|
40
|
+
const HooksContext = exports.HooksContext = /*#__PURE__*/(0, _react.createContext)();
|
|
41
|
+
const HooksContextProvider = _ref => {
|
|
42
|
+
let {
|
|
43
|
+
overrides,
|
|
44
|
+
children
|
|
45
|
+
} = _ref;
|
|
46
|
+
const [hooks, setHooks] = (0, _react.useState)({
|
|
47
|
+
onAction: (overrides === null || overrides === void 0 ? void 0 : overrides.onAction) || DEFAULT_HOOKS.onAction,
|
|
48
|
+
onChange: (overrides === null || overrides === void 0 ? void 0 : overrides.onChange) || DEFAULT_HOOKS.onChange,
|
|
49
|
+
onFormComplete: (overrides === null || overrides === void 0 ? void 0 : overrides.onFormComplete) || DEFAULT_HOOKS.onFormComplete,
|
|
50
|
+
onFormLoad: (overrides === null || overrides === void 0 ? void 0 : overrides.onFormLoad) || DEFAULT_HOOKS.onFormLoad,
|
|
51
|
+
onGetComponent: (overrides === null || overrides === void 0 ? void 0 : overrides.onGetComponent) || DEFAULT_HOOKS.onGetComponent,
|
|
52
|
+
onGetCYA: (overrides === null || overrides === void 0 ? void 0 : overrides.onGetCYA) || DEFAULT_HOOKS.onGetCYA,
|
|
53
|
+
onGetCYARows: (overrides === null || overrides === void 0 ? void 0 : overrides.onGetCYARows) || DEFAULT_HOOKS.onGetCYARows,
|
|
54
|
+
onGoingBack: (overrides === null || overrides === void 0 ? void 0 : overrides.onGoingBack) || DEFAULT_HOOKS.onGoingBack,
|
|
55
|
+
onPageChange: (overrides === null || overrides === void 0 ? void 0 : overrides.onPageChange) || DEFAULT_HOOKS.onPageChange,
|
|
56
|
+
onRequest: (overrides === null || overrides === void 0 ? void 0 : overrides.onRequest) || DEFAULT_HOOKS.onRequest,
|
|
57
|
+
onSubmit: (overrides === null || overrides === void 0 ? void 0 : overrides.onSubmit) || DEFAULT_HOOKS.onSubmit,
|
|
58
|
+
onValidate: (overrides === null || overrides === void 0 ? void 0 : overrides.onValidate) || DEFAULT_HOOKS.onValidate,
|
|
59
|
+
onCancel: (overrides === null || overrides === void 0 ? void 0 : overrides.onCancel) || DEFAULT_HOOKS.onCancel
|
|
60
|
+
});
|
|
61
|
+
const addHook = (name, hook) => {
|
|
86
62
|
if (ALLOWED_HOOKS.includes(name)) {
|
|
87
|
-
setHooks(
|
|
88
|
-
|
|
89
|
-
|
|
63
|
+
setHooks(prev => ({
|
|
64
|
+
...prev,
|
|
65
|
+
[name]: hook || DEFAULT_HOOKS[name] // Don't allow it to be undefined.
|
|
66
|
+
}));
|
|
90
67
|
}
|
|
91
68
|
};
|
|
92
|
-
|
|
69
|
+
|
|
70
|
+
const removeHook = name => {
|
|
93
71
|
if (ALLOWED_HOOKS.includes(name)) {
|
|
94
|
-
setHooks(
|
|
95
|
-
|
|
96
|
-
|
|
72
|
+
setHooks(prev => ({
|
|
73
|
+
...prev,
|
|
74
|
+
[name]: DEFAULT_HOOKS[name]
|
|
75
|
+
}));
|
|
97
76
|
}
|
|
98
77
|
};
|
|
99
78
|
return /*#__PURE__*/_react.default.createElement(HooksContext.Provider, {
|
|
100
79
|
value: {
|
|
101
|
-
hooks
|
|
102
|
-
addHook
|
|
103
|
-
removeHook
|
|
80
|
+
hooks,
|
|
81
|
+
addHook,
|
|
82
|
+
removeHook
|
|
104
83
|
}
|
|
105
84
|
}, children);
|
|
106
85
|
};
|
|
@@ -1,45 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
3
|
var _react = require("@testing-library/react");
|
|
5
4
|
var _react2 = _interopRequireDefault(require("react"));
|
|
6
5
|
var _hooks = require("../../hooks");
|
|
7
6
|
var _HooksContext = _interopRequireWildcard(require("./HooksContext"));
|
|
8
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function
|
|
9
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" !=
|
|
7
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
8
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
10
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } // Global imports
|
|
10
|
+
// Global imports
|
|
11
|
+
|
|
14
12
|
// Local imports
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}));
|
|
13
|
+
|
|
14
|
+
const TestComponent = () => {
|
|
15
|
+
const {
|
|
16
|
+
hooks,
|
|
17
|
+
addHook,
|
|
18
|
+
removeHook
|
|
19
|
+
} = (0, _hooks.useHooks)();
|
|
20
|
+
return /*#__PURE__*/_react2.default.createElement(_react2.default.Fragment, null, typeof addHook === 'function' && /*#__PURE__*/_react2.default.createElement("span", null, "addHook is a function"), typeof removeHook === 'function' && /*#__PURE__*/_react2.default.createElement("span", null, "removeHook is a function"), Object.keys(hooks).map(key => typeof hooks[key] === 'function' && /*#__PURE__*/_react2.default.createElement("span", {
|
|
21
|
+
key: key
|
|
22
|
+
}, key, " is a function")));
|
|
25
23
|
};
|
|
26
|
-
describe('context.ValidationContext',
|
|
27
|
-
it('should appropriately set up the context',
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
});
|
|
39
|
-
case 5:
|
|
40
|
-
case "end":
|
|
41
|
-
return _context.stop();
|
|
42
|
-
}
|
|
43
|
-
}, _callee);
|
|
44
|
-
})));
|
|
24
|
+
describe('context.ValidationContext', () => {
|
|
25
|
+
it('should appropriately set up the context', async () => {
|
|
26
|
+
const {
|
|
27
|
+
container
|
|
28
|
+
} = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_HooksContext.default, null, /*#__PURE__*/_react2.default.createElement(TestComponent, null)));
|
|
29
|
+
expect(container.childNodes.length).toEqual(2 + _HooksContext.ALLOWED_HOOKS.length);
|
|
30
|
+
expect(container.textContent).toContain('addHook is a function');
|
|
31
|
+
expect(container.textContent).toContain('removeHook is a function');
|
|
32
|
+
_HooksContext.ALLOWED_HOOKS.forEach(hook => {
|
|
33
|
+
expect(container.textContent).toContain("".concat(hook, " is a function"));
|
|
34
|
+
});
|
|
35
|
+
});
|
|
45
36
|
});
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
Object.defineProperty(exports, "HooksContext", {
|
|
8
7
|
enumerable: true,
|
|
9
|
-
get: function
|
|
8
|
+
get: function () {
|
|
10
9
|
return _HooksContext.HooksContext;
|
|
11
10
|
}
|
|
12
11
|
});
|
|
13
12
|
exports.default = void 0;
|
|
14
13
|
var _HooksContext = _interopRequireWildcard(require("./HooksContext"));
|
|
15
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function
|
|
16
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" !=
|
|
14
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
15
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
17
16
|
var _default = exports.default = _HooksContext.default;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
@@ -10,87 +9,48 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
10
9
|
var _utils = _interopRequireDefault(require("../../utils"));
|
|
11
10
|
var _hooks = require("../../hooks");
|
|
12
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function
|
|
14
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" !=
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
19
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
20
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
21
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
22
|
-
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
23
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } /* eslint-disable react/jsx-no-constructed-context-values, no-shadow */ // Global imports
|
|
12
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
13
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
14
|
+
/* eslint-disable react/jsx-no-constructed-context-values, no-shadow */
|
|
15
|
+
// Global imports
|
|
16
|
+
|
|
24
17
|
// Local imports
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
case "end":
|
|
46
|
-
return _context.stop();
|
|
47
|
-
}
|
|
48
|
-
}, _callee);
|
|
49
|
-
}));
|
|
50
|
-
return function addErrors(_x) {
|
|
51
|
-
return _ref2.apply(this, arguments);
|
|
52
|
-
};
|
|
53
|
-
}();
|
|
54
|
-
var clearErrors = /*#__PURE__*/function () {
|
|
55
|
-
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
56
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
57
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
58
|
-
case 0:
|
|
59
|
-
setErrors([]);
|
|
60
|
-
case 1:
|
|
61
|
-
case "end":
|
|
62
|
-
return _context2.stop();
|
|
63
|
-
}
|
|
64
|
-
}, _callee2);
|
|
65
|
-
}));
|
|
66
|
-
return function clearErrors() {
|
|
67
|
-
return _ref3.apply(this, arguments);
|
|
68
|
-
};
|
|
69
|
-
}();
|
|
70
|
-
var validate = {
|
|
71
|
-
page: function page(_page) {
|
|
72
|
-
var pageErrors = _utils.default.Validate.page(_page);
|
|
73
|
-
var allErrors = hooks.onValidate(_page, pageErrors);
|
|
18
|
+
|
|
19
|
+
const ValidationContext = exports.ValidationContext = /*#__PURE__*/(0, _react.createContext)();
|
|
20
|
+
const ValidationContextProvider = _ref => {
|
|
21
|
+
let {
|
|
22
|
+
children
|
|
23
|
+
} = _ref;
|
|
24
|
+
const {
|
|
25
|
+
hooks
|
|
26
|
+
} = (0, _hooks.useHooks)();
|
|
27
|
+
const [errors, setErrors] = (0, _react.useState)([]);
|
|
28
|
+
const addErrors = async errors => {
|
|
29
|
+
setErrors(prev => [].concat(prev, errors).filter(e => !!e));
|
|
30
|
+
};
|
|
31
|
+
const clearErrors = async () => {
|
|
32
|
+
setErrors([]);
|
|
33
|
+
};
|
|
34
|
+
const validate = {
|
|
35
|
+
page: page => {
|
|
36
|
+
const pageErrors = _utils.default.Validate.page(page);
|
|
37
|
+
const allErrors = hooks.onValidate(page, pageErrors);
|
|
74
38
|
setErrors(allErrors);
|
|
75
39
|
return allErrors;
|
|
76
40
|
},
|
|
77
|
-
pages:
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
});
|
|
81
|
-
var allErrors = _pages.flatMap(function (page, index) {
|
|
82
|
-
return hooks.onValidate(page, allPagesErrors[index]);
|
|
83
|
-
});
|
|
41
|
+
pages: pages => {
|
|
42
|
+
const allPagesErrors = pages.map(page => _utils.default.Validate.page(page));
|
|
43
|
+
const allErrors = pages.flatMap((page, index) => hooks.onValidate(page, allPagesErrors[index]));
|
|
84
44
|
setErrors(allErrors);
|
|
85
45
|
return allErrors;
|
|
86
46
|
}
|
|
87
47
|
};
|
|
88
48
|
return /*#__PURE__*/_react.default.createElement(ValidationContext.Provider, {
|
|
89
49
|
value: {
|
|
90
|
-
errors
|
|
91
|
-
addErrors
|
|
92
|
-
clearErrors
|
|
93
|
-
validate
|
|
50
|
+
errors,
|
|
51
|
+
addErrors,
|
|
52
|
+
clearErrors,
|
|
53
|
+
validate
|
|
94
54
|
}
|
|
95
55
|
}, children);
|
|
96
56
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
3
|
var _react = require("@testing-library/react");
|
|
5
4
|
var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
6
5
|
var _react2 = _interopRequireWildcard(require("react"));
|
|
@@ -9,20 +8,23 @@ var _hooks = require("../../hooks");
|
|
|
9
8
|
var _ValidationContext = _interopRequireDefault(require("./ValidationContext"));
|
|
10
9
|
var _HooksContext = _interopRequireDefault(require("../HooksContext"));
|
|
11
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function
|
|
13
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" !=
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } // Global imports
|
|
11
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
12
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
13
|
+
// Global imports
|
|
14
|
+
|
|
17
15
|
// Local imports
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
|
|
17
|
+
const TestComponent = _ref => {
|
|
18
|
+
let {
|
|
19
|
+
customErrors
|
|
20
|
+
} = _ref;
|
|
21
|
+
const {
|
|
22
|
+
addErrors,
|
|
23
|
+
clearErrors,
|
|
24
|
+
errors,
|
|
25
|
+
validate
|
|
26
|
+
} = (0, _hooks.useValidation)();
|
|
27
|
+
(0, _react2.useEffect)(() => {
|
|
26
28
|
if (customErrors) {
|
|
27
29
|
addErrors(customErrors);
|
|
28
30
|
}
|
|
@@ -31,51 +33,37 @@ var TestComponent = function TestComponent(_ref) {
|
|
|
31
33
|
errors: errors
|
|
32
34
|
}));
|
|
33
35
|
};
|
|
34
|
-
describe('context.ValidationContext',
|
|
35
|
-
it('should appropriately set up the context',
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
expect(container.textContent).toContain('addErrors is a function');
|
|
66
|
-
expect(container.textContent).toContain('clearErrors is a function');
|
|
67
|
-
expect(container.textContent).toContain('validate.page is a function');
|
|
68
|
-
expect(container.textContent).toContain('errors is an array of length 1');
|
|
69
|
-
errorSummary = container.childNodes[4];
|
|
70
|
-
expect(errorSummary.tagName).toEqual('DIV');
|
|
71
|
-
expect(errorSummary.classList).toContain('govuk-error-summary');
|
|
72
|
-
expect(errorSummary.textContent).toContain(CUSTOM_ERRORS[0].error);
|
|
73
|
-
case 11:
|
|
74
|
-
case "end":
|
|
75
|
-
return _context2.stop();
|
|
76
|
-
}
|
|
77
|
-
}, _callee2);
|
|
78
|
-
})));
|
|
36
|
+
describe('context.ValidationContext', () => {
|
|
37
|
+
it('should appropriately set up the context', async () => {
|
|
38
|
+
const {
|
|
39
|
+
container
|
|
40
|
+
} = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_HooksContext.default, null, /*#__PURE__*/_react2.default.createElement(_ValidationContext.default, null, /*#__PURE__*/_react2.default.createElement(TestComponent, null))));
|
|
41
|
+
expect(container.childNodes.length).toEqual(4);
|
|
42
|
+
expect(container.textContent).toContain('addErrors is a function');
|
|
43
|
+
expect(container.textContent).toContain('clearErrors is a function');
|
|
44
|
+
expect(container.textContent).toContain('validate.page is a function');
|
|
45
|
+
expect(container.textContent).toContain('errors is an array of length 0');
|
|
46
|
+
});
|
|
47
|
+
it('should appropriately handle errors', async () => {
|
|
48
|
+
const CUSTOM_ERRORS = [{
|
|
49
|
+
id: 'alpha',
|
|
50
|
+
error: 'Alpha is required'
|
|
51
|
+
}];
|
|
52
|
+
const {
|
|
53
|
+
container
|
|
54
|
+
} = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_HooksContext.default, null, /*#__PURE__*/_react2.default.createElement(_ValidationContext.default, null, /*#__PURE__*/_react2.default.createElement(TestComponent, {
|
|
55
|
+
customErrors: CUSTOM_ERRORS
|
|
56
|
+
}))));
|
|
57
|
+
expect(container.childNodes.length).toEqual(5);
|
|
58
|
+
expect(container.textContent).toContain('addErrors is a function');
|
|
59
|
+
expect(container.textContent).toContain('clearErrors is a function');
|
|
60
|
+
expect(container.textContent).toContain('validate.page is a function');
|
|
61
|
+
expect(container.textContent).toContain('errors is an array of length 1');
|
|
62
|
+
const errorSummary = container.childNodes[4];
|
|
63
|
+
expect(errorSummary.tagName).toEqual('DIV');
|
|
64
|
+
expect(errorSummary.classList).toContain('govuk-error-summary');
|
|
65
|
+
expect(errorSummary.textContent).toContain(CUSTOM_ERRORS[0].error);
|
|
66
|
+
});
|
|
79
67
|
});
|
|
80
68
|
TestComponent.propTypes = {
|
|
81
69
|
customErrors: _propTypes.default.arrayOf(_propTypes.default.shape({}))
|