@ukhomeoffice/cop-react-form-renderer 6.14.0 → 6.14.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/README.md +5 -0
- package/dist/components/CheckYourAnswers/Answer.js +12 -11
- package/dist/components/CheckYourAnswers/Answer.test.js +132 -181
- package/dist/components/CheckYourAnswers/CheckYourAnswers.js +98 -133
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +544 -939
- package/dist/components/CheckYourAnswers/index.js +1 -1
- package/dist/components/CollectionPage/CollectionPage.js +62 -60
- package/dist/components/CollectionPage/CollectionPage.test.js +315 -365
- package/dist/components/CollectionPage/index.js +1 -1
- package/dist/components/CollectionSummary/BannerStrip.js +14 -14
- package/dist/components/CollectionSummary/BannerStrip.test.js +79 -74
- package/dist/components/CollectionSummary/CollectionSummary.js +75 -97
- package/dist/components/CollectionSummary/CollectionSummary.test.js +182 -166
- package/dist/components/CollectionSummary/Confirmation.js +15 -13
- package/dist/components/CollectionSummary/Confirmation.test.js +68 -63
- package/dist/components/CollectionSummary/RenderListView.js +34 -47
- package/dist/components/CollectionSummary/RenderListView.test.js +113 -111
- package/dist/components/CollectionSummary/SummaryCard.js +101 -133
- package/dist/components/CollectionSummary/SummaryCard.test.js +961 -993
- package/dist/components/CollectionSummary/SummaryCardButtons.js +25 -30
- package/dist/components/CollectionSummary/SummaryCardButtons.test.js +30 -28
- package/dist/components/CollectionSummary/SummaryCardDetails.js +59 -76
- package/dist/components/CollectionSummary/SummaryCardDetails.test.js +170 -180
- package/dist/components/CollectionSummary/SummaryCardValidationContext.js +31 -36
- package/dist/components/CollectionSummary/SummaryCardValidationContext.test.js +63 -75
- package/dist/components/CollectionSummary/index.js +1 -1
- package/dist/components/FormComponent/Collection.js +63 -100
- package/dist/components/FormComponent/Collection.test.js +907 -1080
- package/dist/components/FormComponent/Container.js +35 -29
- package/dist/components/FormComponent/Container.test.js +378 -409
- package/dist/components/FormComponent/FormComponent.js +59 -63
- package/dist/components/FormComponent/FormComponent.test.js +354 -415
- 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 +8 -8
- package/dist/components/FormComponent/helpers/getComponentError.js +3 -5
- package/dist/components/FormComponent/helpers/getComponentError.test.js +15 -15
- package/dist/components/FormComponent/helpers/getComponentFieldSet.js +3 -4
- 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 +1 -1
- package/dist/components/FormPage/FormPage.js +70 -93
- package/dist/components/FormPage/FormPage.test.js +150 -202
- package/dist/components/FormPage/index.js +1 -1
- package/dist/components/FormRenderer/FormRenderer.js +131 -173
- package/dist/components/FormRenderer/FormRenderer.test.js +732 -1114
- package/dist/components/FormRenderer/handlers/cyaAction.js +3 -3
- package/dist/components/FormRenderer/handlers/getPageId.js +1 -3
- 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 +2 -2
- package/dist/components/FormRenderer/handlers/navigate.js +4 -4
- 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 +16 -16
- package/dist/components/FormRenderer/helpers/canCYASubmit.js +1 -3
- package/dist/components/FormRenderer/helpers/canCYASubmit.test.js +17 -21
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.js +22 -25
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.test.js +21 -21
- package/dist/components/FormRenderer/helpers/getCYA.js +4 -6
- package/dist/components/FormRenderer/helpers/getCYA.test.js +12 -12
- package/dist/components/FormRenderer/helpers/getFormState.js +6 -8
- package/dist/components/FormRenderer/helpers/getFormState.test.js +11 -11
- package/dist/components/FormRenderer/helpers/getNextPageId.js +14 -25
- package/dist/components/FormRenderer/helpers/getNextPageId.test.js +68 -68
- package/dist/components/FormRenderer/helpers/getPage.js +2 -4
- package/dist/components/FormRenderer/helpers/getPage.test.js +12 -12
- package/dist/components/FormRenderer/helpers/getRelevantPages.js +7 -9
- package/dist/components/FormRenderer/helpers/getRelevantPages.test.js +15 -15
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +6 -6
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +104 -98
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.js +44 -51
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.test.js +68 -74
- package/dist/components/FormRenderer/helpers/index.js +2 -2
- package/dist/components/FormRenderer/index.js +1 -1
- package/dist/components/FormRenderer/onCYAAction.js +43 -44
- package/dist/components/FormRenderer/onCYAAction.test.js +126 -133
- package/dist/components/FormRenderer/onPageAction.js +26 -35
- package/dist/components/FormRenderer/onPageAction.test.js +177 -186
- package/dist/components/FormRenderer/onTaskAction.js +11 -12
- package/dist/components/FormRenderer/onTaskAction.test.js +63 -68
- package/dist/components/PageActions/ActionButton.js +14 -14
- package/dist/components/PageActions/ActionButton.test.js +57 -79
- package/dist/components/PageActions/PageActions.js +11 -11
- package/dist/components/PageActions/PageActions.test.js +87 -116
- package/dist/components/PageActions/index.js +1 -1
- package/dist/components/SummaryList/GroupAction.js +10 -18
- package/dist/components/SummaryList/GroupAction.test.js +38 -34
- package/dist/components/SummaryList/RowAction.js +12 -17
- package/dist/components/SummaryList/RowAction.test.js +38 -34
- package/dist/components/SummaryList/SummaryList.js +23 -25
- package/dist/components/SummaryList/SummaryList.test.js +162 -189
- package/dist/components/SummaryList/SummaryListHeadingRow.js +7 -5
- package/dist/components/SummaryList/SummaryListHeadingRowWithAction.js +7 -5
- package/dist/components/SummaryList/SummaryListRow.js +7 -5
- package/dist/components/SummaryList/SummaryListTitleRow.js +6 -4
- package/dist/components/SummaryList/helpers/getGroupActionAttributes.js +3 -5
- package/dist/components/SummaryList/helpers/getGroupActionAttributes.test.js +23 -23
- package/dist/components/SummaryList/helpers/getRowActionAttributes.js +3 -5
- package/dist/components/SummaryList/helpers/getRowActionAttributes.test.js +23 -23
- package/dist/components/SummaryList/helpers/index.js +2 -2
- package/dist/components/SummaryList/index.js +1 -1
- package/dist/components/TaskList/Task.js +20 -30
- package/dist/components/TaskList/Task.test.js +84 -77
- package/dist/components/TaskList/TaskList.js +56 -79
- package/dist/components/TaskList/TaskList.test.js +149 -149
- package/dist/components/TaskList/TaskState.js +8 -6
- package/dist/components/TaskList/TaskState.test.js +53 -46
- package/dist/components/TaskList/index.js +1 -1
- package/dist/components/index.js +8 -8
- package/dist/context/HooksContext/HooksContext.js +56 -79
- package/dist/context/HooksContext/HooksContext.test.js +27 -36
- package/dist/context/HooksContext/index.js +3 -4
- package/dist/context/ValidationContext/ValidationContext.js +44 -95
- package/dist/context/ValidationContext/ValidationContext.test.js +57 -69
- package/dist/context/ValidationContext/index.js +3 -4
- package/dist/context/index.js +3 -3
- package/dist/hooks/index.js +10 -11
- package/dist/hooks/useAxios.js +15 -41
- package/dist/hooks/useGetRequest.js +62 -98
- package/dist/hooks/useHooks.js +1 -3
- package/dist/hooks/useRefData.js +25 -37
- package/dist/hooks/useValidation.js +1 -3
- package/dist/index.js +14 -15
- 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 +29 -28
- package/dist/models/index.js +10 -10
- package/dist/setupTests.js +30 -31
- package/dist/utils/CheckYourAnswers/getCYAAction.js +5 -5
- package/dist/utils/CheckYourAnswers/getCYAAction.test.js +53 -55
- package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.js +12 -21
- package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.test.js +32 -33
- package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.js +15 -28
- package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.test.js +41 -42
- package/dist/utils/CheckYourAnswers/getCYARow.js +7 -7
- package/dist/utils/CheckYourAnswers/getCYARow.test.js +87 -87
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.js +19 -21
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.test.js +16 -17
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.js +27 -34
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.test.js +48 -52
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +76 -93
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +110 -115
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.js +11 -16
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.test.js +112 -106
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +14 -19
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.test.js +69 -73
- package/dist/utils/CheckYourAnswers/getSummaryListRowForDetails.js +7 -8
- package/dist/utils/CheckYourAnswers/getSummaryListRowForDetails.test.js +15 -16
- package/dist/utils/CheckYourAnswers/index.js +2 -2
- package/dist/utils/CheckYourAnswers/showComponentCYA.js +5 -5
- package/dist/utils/CheckYourAnswers/showComponentCYA.test.js +26 -26
- package/dist/utils/CollectionPage/addCollectionPageEntry.js +2 -2
- package/dist/utils/CollectionPage/addCollectionPageEntry.test.js +6 -6
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.js +3 -3
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.test.js +18 -19
- package/dist/utils/CollectionPage/duplicateCollectionPageEntry.js +13 -20
- package/dist/utils/CollectionPage/duplicateCollectionPageEntry.test.js +48 -39
- package/dist/utils/CollectionPage/getCollectionPageActiveId.js +2 -2
- package/dist/utils/CollectionPage/getCollectionPageActiveId.test.js +11 -11
- package/dist/utils/CollectionPage/getCollectionPageActiveIndex.js +7 -11
- package/dist/utils/CollectionPage/getCollectionPageActiveIndex.test.js +23 -23
- package/dist/utils/CollectionPage/getCollectionPageData.js +8 -12
- package/dist/utils/CollectionPage/getCollectionPageData.test.js +20 -20
- package/dist/utils/CollectionPage/getErrorsForCollection.js +20 -21
- package/dist/utils/CollectionPage/getErrorsForCollection.test.js +21 -23
- package/dist/utils/CollectionPage/getQuickEditPage.js +22 -23
- package/dist/utils/CollectionPage/getQuickEditPage.test.js +17 -18
- package/dist/utils/CollectionPage/index.js +2 -2
- package/dist/utils/CollectionPage/mergeCollectionPages.js +26 -35
- package/dist/utils/CollectionPage/mergeCollectionPages.test.js +18 -18
- package/dist/utils/CollectionPage/removeCollectionPageEntry.js +5 -7
- package/dist/utils/CollectionPage/removeCollectionPageEntry.test.js +11 -11
- package/dist/utils/CollectionPage/setCollectionPageData.js +10 -16
- package/dist/utils/CollectionPage/setCollectionPageData.test.js +25 -25
- package/dist/utils/Component/addShowWhen.js +5 -6
- package/dist/utils/Component/addShowWhen.test.js +38 -38
- package/dist/utils/Component/applyToComponentTree.js +12 -15
- package/dist/utils/Component/applyToComponentTree.test.js +28 -31
- package/dist/utils/Component/cleanAttributes.js +12 -11
- package/dist/utils/Component/cleanAttributes.test.js +17 -18
- package/dist/utils/Component/elevateNestedComponents.js +6 -6
- package/dist/utils/Component/elevateNestedComponents.test.js +34 -34
- package/dist/utils/Component/getComponent.js +79 -85
- package/dist/utils/Component/getComponentTests/getComponent.autocomplete.test.js +19 -18
- package/dist/utils/Component/getComponentTests/getComponent.calculation.test.js +41 -58
- package/dist/utils/Component/getComponentTests/getComponent.checkboxes.test.js +40 -49
- package/dist/utils/Component/getComponentTests/getComponent.date.test.js +24 -34
- package/dist/utils/Component/getComponentTests/getComponent.details.test.js +21 -19
- package/dist/utils/Component/getComponentTests/getComponent.email.test.js +18 -23
- package/dist/utils/Component/getComponentTests/getComponent.file.test.js +21 -26
- package/dist/utils/Component/getComponentTests/getComponent.heading.test.js +11 -10
- 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 +23 -27
- package/dist/utils/Component/getComponentTests/getComponent.nested.test.js +201 -226
- package/dist/utils/Component/getComponentTests/getComponent.paragraph.test.js +18 -16
- package/dist/utils/Component/getComponentTests/getComponent.phoneNumber.test.js +18 -23
- package/dist/utils/Component/getComponentTests/getComponent.radios.test.js +58 -73
- package/dist/utils/Component/getComponentTests/getComponent.select.test.js +18 -23
- package/dist/utils/Component/getComponentTests/getComponent.text.test.js +18 -23
- package/dist/utils/Component/getComponentTests/getComponent.textArea.test.js +32 -39
- package/dist/utils/Component/getComponentTests/getComponent.time.test.js +21 -30
- 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 +13 -13
- package/dist/utils/Component/getDefaultValueFromConfig.js +16 -20
- package/dist/utils/Component/getDefaultValueFromConfig.test.js +32 -32
- package/dist/utils/Component/index.js +2 -2
- package/dist/utils/Component/isEditable.js +2 -4
- package/dist/utils/Component/isEditable.test.js +14 -15
- package/dist/utils/Component/optionIsSelected.js +2 -4
- package/dist/utils/Component/optionIsSelected.test.js +12 -12
- package/dist/utils/Component/setupContainerComponentsPath.js +23 -28
- package/dist/utils/Component/setupContainerComponentsPath.test.js +12 -12
- package/dist/utils/Component/showComponent.js +2 -2
- package/dist/utils/Component/showComponent.test.js +29 -29
- package/dist/utils/Component/wrapInFormGroup.js +4 -4
- package/dist/utils/Condition/index.js +2 -2
- package/dist/utils/Condition/meetsAllConditions.js +9 -9
- package/dist/utils/Condition/meetsAllConditions.test.js +21 -21
- package/dist/utils/Condition/meetsCondition.js +17 -26
- package/dist/utils/Condition/meetsCondition.test.js +403 -403
- package/dist/utils/Condition/meetsOneCondition.js +6 -6
- package/dist/utils/Condition/meetsOneCondition.test.js +17 -17
- package/dist/utils/Condition/setupConditions.js +12 -15
- package/dist/utils/Condition/setupConditions.test.js +8 -8
- package/dist/utils/Container/getEditableComponents.js +4 -6
- package/dist/utils/Container/getEditableComponents.test.js +44 -46
- package/dist/utils/Container/index.js +2 -2
- package/dist/utils/Container/setupNesting.js +14 -15
- package/dist/utils/Container/setupNesting.test.js +20 -23
- package/dist/utils/Container/showContainer.js +4 -8
- package/dist/utils/Container/showContainer.test.js +31 -31
- package/dist/utils/Data/applyFormula.js +30 -44
- package/dist/utils/Data/applyFormula.test.js +21 -21
- package/dist/utils/Data/deleteValues.js +4 -8
- package/dist/utils/Data/deleteValues.test.js +11 -11
- package/dist/utils/Data/getAutocompleteSource.js +72 -63
- package/dist/utils/Data/getAutocompleteSource.test.js +106 -98
- package/dist/utils/Data/getDataPath.js +18 -28
- package/dist/utils/Data/getDataPath.test.js +13 -13
- package/dist/utils/Data/getOptions.js +35 -42
- package/dist/utils/Data/getOptions.test.js +37 -38
- package/dist/utils/Data/getSourceData.js +6 -19
- package/dist/utils/Data/getSourceData.test.js +85 -81
- package/dist/utils/Data/index.js +2 -2
- package/dist/utils/Data/nestInRefdataOptions.js +9 -12
- package/dist/utils/Data/nestInRefdataOptions.test.js +17 -17
- package/dist/utils/Data/refDataToOptions.js +9 -10
- package/dist/utils/Data/refDataToOptions.test.js +20 -20
- package/dist/utils/Data/setDataItem.js +7 -8
- package/dist/utils/Data/setDataItem.test.js +38 -38
- package/dist/utils/Data/setupFormData.js +13 -20
- package/dist/utils/Data/setupFormData.test.js +48 -47
- package/dist/utils/Data/setupRefDataUrlForComponent.js +11 -20
- package/dist/utils/Data/setupRefDataUrlForComponent.test.js +25 -25
- package/dist/utils/FormPage/applyConditionalProperties.js +7 -8
- package/dist/utils/FormPage/applyConditionalProperties.test.js +14 -15
- package/dist/utils/FormPage/getConditionalText.js +4 -4
- package/dist/utils/FormPage/getConditionalText.test.js +30 -30
- package/dist/utils/FormPage/getFormPage.js +12 -15
- package/dist/utils/FormPage/getFormPage.test.js +23 -24
- package/dist/utils/FormPage/getFormPages.js +8 -11
- package/dist/utils/FormPage/getFormPages.test.js +15 -16
- package/dist/utils/FormPage/getPageActions.js +10 -13
- package/dist/utils/FormPage/getPageActions.test.js +33 -33
- package/dist/utils/FormPage/getParagraphFromText.js +5 -7
- package/dist/utils/FormPage/getParagraphFromText.test.js +7 -7
- package/dist/utils/FormPage/index.js +3 -5
- package/dist/utils/FormPage/showFormPage.js +4 -8
- package/dist/utils/FormPage/showFormPage.test.js +33 -33
- package/dist/utils/FormPage/showFormPageCYA.js +2 -2
- package/dist/utils/FormPage/showFormPageCYA.test.js +9 -9
- package/dist/utils/FormPage/useComponent.js +15 -23
- package/dist/utils/FormPage/useComponent.test.js +49 -50
- package/dist/utils/Format/formatData.js +1 -1
- package/dist/utils/Format/formatData.test.js +19 -19
- package/dist/utils/Format/formatDataForComponent.js +6 -7
- package/dist/utils/Format/formatDataForComponent.test.js +50 -78
- package/dist/utils/Format/formatDataForForm.js +5 -6
- package/dist/utils/Format/formatDataForForm.test.js +14 -17
- package/dist/utils/Format/formatDataForPage.js +4 -5
- package/dist/utils/Format/formatDataForPage.test.js +20 -25
- package/dist/utils/Format/index.js +2 -2
- package/dist/utils/Hub/getFormHub.js +2 -2
- package/dist/utils/Hub/getFormHub.test.js +23 -24
- package/dist/utils/Hub/index.js +2 -2
- 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 +25 -17
- package/dist/utils/Meta/documents/index.js +2 -2
- package/dist/utils/Meta/documents/setDocumentsForField.js +12 -13
- package/dist/utils/Meta/documents/setDocumentsForField.test.js +70 -33
- package/dist/utils/Meta/index.js +2 -2
- package/dist/utils/Operate/checkValueIsTruthy.js +3 -3
- package/dist/utils/Operate/checkValueIsTruthy.test.js +17 -17
- package/dist/utils/Operate/deleteValueInFormData.js +2 -2
- package/dist/utils/Operate/deleteValueInFormData.test.js +15 -15
- package/dist/utils/Operate/getFirstOf.js +6 -6
- package/dist/utils/Operate/getFirstOf.test.js +32 -32
- package/dist/utils/Operate/getIndexOfMatchingValueIn.js +11 -11
- package/dist/utils/Operate/getIndexOfMatchingValueIn.test.js +47 -53
- package/dist/utils/Operate/getLength.js +9 -9
- package/dist/utils/Operate/getLength.test.js +19 -19
- package/dist/utils/Operate/index.js +2 -2
- package/dist/utils/Operate/persistValueInFormData.js +4 -4
- package/dist/utils/Operate/persistValueInFormData.test.js +23 -21
- package/dist/utils/Operate/runPageOperations.js +8 -8
- package/dist/utils/Operate/runPageOperations.test.js +24 -25
- package/dist/utils/Operate/setValueInFormData.js +3 -3
- package/dist/utils/Operate/setValueInFormData.test.js +17 -17
- package/dist/utils/Operate/shouldRun.js +7 -7
- package/dist/utils/Operate/shouldRun.test.js +22 -24
- package/dist/utils/Validate/additional/conditionallyPermittedChange.js +1 -1
- package/dist/utils/Validate/additional/conditionallyPermittedChange.test.js +15 -15
- package/dist/utils/Validate/additional/conditionallyRequired.js +4 -4
- package/dist/utils/Validate/additional/conditionallyRequired.test.js +19 -19
- package/dist/utils/Validate/additional/index.js +8 -8
- package/dist/utils/Validate/additional/index.test.js +22 -22
- package/dist/utils/Validate/additional/mustBeAfter.js +3 -3
- package/dist/utils/Validate/additional/mustBeAfter.test.js +41 -41
- package/dist/utils/Validate/additional/mustBeBefore.js +3 -3
- package/dist/utils/Validate/additional/mustBeBefore.test.js +29 -29
- package/dist/utils/Validate/additional/mustBeEarlierDateTime.js +8 -12
- package/dist/utils/Validate/additional/mustBeEarlierDateTime.test.js +37 -38
- package/dist/utils/Validate/additional/mustBeGreaterThan.js +2 -2
- package/dist/utils/Validate/additional/mustBeGreaterThan.test.js +19 -19
- package/dist/utils/Validate/additional/mustBeInTheFuture.js +3 -3
- package/dist/utils/Validate/additional/mustBeInTheFuture.test.js +13 -13
- package/dist/utils/Validate/additional/mustBeInThePast.js +4 -4
- package/dist/utils/Validate/additional/mustBeInThePast.test.js +13 -13
- package/dist/utils/Validate/additional/mustBeLessThan.js +2 -2
- package/dist/utils/Validate/additional/mustBeLessThan.test.js +18 -18
- package/dist/utils/Validate/additional/mustBeLongerThan.js +1 -1
- package/dist/utils/Validate/additional/mustBeLongerThan.test.js +17 -17
- package/dist/utils/Validate/additional/mustBeNumbersOnly.js +2 -2
- package/dist/utils/Validate/additional/mustBeNumbersOnly.test.js +21 -21
- package/dist/utils/Validate/additional/mustBeOneOf.js +1 -1
- package/dist/utils/Validate/additional/mustBeOneOf.test.js +13 -13
- package/dist/utils/Validate/additional/mustBeShorterThan.js +1 -1
- package/dist/utils/Validate/additional/mustBeShorterThan.test.js +17 -17
- package/dist/utils/Validate/additional/mustBeUniqueInCollection.js +5 -5
- package/dist/utils/Validate/additional/mustBeUniqueInCollection.test.js +35 -36
- package/dist/utils/Validate/additional/mustEnterAtLeastOne.js +2 -2
- package/dist/utils/Validate/additional/mustEnterAtLeastOne.test.js +15 -17
- package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.js +1 -1
- package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.test.js +13 -13
- package/dist/utils/Validate/additional/mustNotContainSql.js +3 -4
- package/dist/utils/Validate/additional/mustNotContainSql.test.js +15 -15
- package/dist/utils/Validate/additional/mustSelectOnlyOne.js +2 -2
- package/dist/utils/Validate/additional/mustSelectOnlyOne.test.js +29 -27
- package/dist/utils/Validate/additional/utils.js +9 -22
- package/dist/utils/Validate/index.js +2 -2
- package/dist/utils/Validate/validateCollection.js +18 -23
- package/dist/utils/Validate/validateCollection.test.js +75 -67
- package/dist/utils/Validate/validateComponent.js +19 -19
- package/dist/utils/Validate/validateComponent.test.js +179 -154
- package/dist/utils/Validate/validateContainer.js +14 -17
- package/dist/utils/Validate/validateContainer.test.js +59 -53
- package/dist/utils/Validate/validateDate.js +16 -22
- package/dist/utils/Validate/validateDate.test.js +31 -32
- package/dist/utils/Validate/validateEmail.js +7 -9
- package/dist/utils/Validate/validateEmail.test.js +27 -27
- package/dist/utils/Validate/validateMultifile.js +5 -7
- package/dist/utils/Validate/validateMultifile.test.js +17 -18
- package/dist/utils/Validate/validatePage.js +13 -18
- package/dist/utils/Validate/validatePage.test.js +198 -195
- package/dist/utils/Validate/validateRegex.js +3 -5
- package/dist/utils/Validate/validateRegex.test.js +15 -15
- package/dist/utils/Validate/validateRequired.js +4 -6
- package/dist/utils/Validate/validateRequired.test.js +19 -19
- package/dist/utils/Validate/validateTextArea.js +4 -6
- package/dist/utils/Validate/validateTextArea.test.js +21 -21
- package/dist/utils/Validate/validateTime.js +12 -19
- package/dist/utils/Validate/validateTime.test.js +27 -27
- package/dist/utils/index.js +5 -6
- package/package.json +2 -4
|
@@ -2,21 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
var _models = require("../../models");
|
|
4
4
|
var _formatDataForForm = _interopRequireDefault(require("./formatDataForForm"));
|
|
5
|
-
function _interopRequireDefault(
|
|
5
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
6
6
|
// Local imports
|
|
7
7
|
|
|
8
|
-
describe('utils',
|
|
9
|
-
describe('Format',
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var EVENT_TYPE = _models.EventTypes.SUBMIT;
|
|
19
|
-
var COMPONENTS = [setupField('alpha', {
|
|
8
|
+
describe('utils', () => {
|
|
9
|
+
describe('Format', () => {
|
|
10
|
+
const setupField = (fieldId, format) => ({
|
|
11
|
+
fieldId,
|
|
12
|
+
format
|
|
13
|
+
});
|
|
14
|
+
describe('formatDataForForm', () => {
|
|
15
|
+
it('should appropriately format entire form', () => {
|
|
16
|
+
const EVENT_TYPE = _models.EventTypes.SUBMIT;
|
|
17
|
+
const COMPONENTS = [setupField('alpha', {
|
|
20
18
|
type: 'lowercase',
|
|
21
19
|
on: _models.EventTypes.SUBMIT
|
|
22
20
|
}),
|
|
@@ -43,15 +41,14 @@ describe('utils', function () {
|
|
|
43
41
|
on: _models.EventTypes.SUBMIT
|
|
44
42
|
}) // Should not be formatted because of event type
|
|
45
43
|
];
|
|
46
|
-
|
|
47
|
-
var DATA = {
|
|
44
|
+
const DATA = {
|
|
48
45
|
alpha: 'AlPhA',
|
|
49
46
|
bravo: 'bRaVo',
|
|
50
47
|
charlie: 'CHArlie',
|
|
51
48
|
delta: 'deLTA',
|
|
52
49
|
foxtrot: 'FOXTROT'
|
|
53
50
|
};
|
|
54
|
-
|
|
51
|
+
const FORM = {
|
|
55
52
|
components: COMPONENTS.slice(0, 1),
|
|
56
53
|
pages: [{
|
|
57
54
|
components: COMPONENTS.slice(2, 3)
|
|
@@ -59,7 +56,7 @@ describe('utils', function () {
|
|
|
59
56
|
components: COMPONENTS.slice(4)
|
|
60
57
|
}]
|
|
61
58
|
};
|
|
62
|
-
|
|
59
|
+
const FORMATTED_DATA = (0, _formatDataForForm.default)(FORM, DATA, EVENT_TYPE);
|
|
63
60
|
expect(FORMATTED_DATA).toEqual({
|
|
64
61
|
alpha: 'alpha',
|
|
65
62
|
bravo: 'bRaVo',
|
|
@@ -13,7 +13,7 @@ var _formatDataForComponent = require("./formatDataForComponent");
|
|
|
13
13
|
* @param {object} data The top-level form data.
|
|
14
14
|
* @param {string} eventType What type of event initiated this call.
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
const formatDataForPage = (page, data, eventType) => {
|
|
17
17
|
(0, _formatDataForComponent.formatDataForComponents)(page.components, data, eventType);
|
|
18
18
|
};
|
|
19
19
|
|
|
@@ -23,9 +23,8 @@ var formatDataForPage = function formatDataForPage(page, data, eventType) {
|
|
|
23
23
|
* @param {object} data The top-level form data.
|
|
24
24
|
* @param {string} eventType What type of event initiated this call.
|
|
25
25
|
*/
|
|
26
|
-
|
|
27
|
-
pages.forEach(
|
|
28
|
-
return formatDataForPage(page, data, eventType);
|
|
29
|
-
});
|
|
26
|
+
const formatDataForPages = (pages, data, eventType) => {
|
|
27
|
+
pages.forEach(page => formatDataForPage(page, data, eventType));
|
|
30
28
|
};
|
|
29
|
+
exports.formatDataForPages = formatDataForPages;
|
|
31
30
|
var _default = exports.default = formatDataForPage;
|
|
@@ -1,24 +1,21 @@
|
|
|
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 _models = require("../../models");
|
|
5
4
|
var _formatDataForPage = _interopRequireWildcard(require("./formatDataForPage"));
|
|
6
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function
|
|
7
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" !=
|
|
5
|
+
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); }
|
|
6
|
+
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 && {}.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; }
|
|
8
7
|
// Local imports
|
|
9
8
|
|
|
10
|
-
describe('utils',
|
|
11
|
-
describe('Format',
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var EVENT_TYPE = _models.EventTypes.SUBMIT;
|
|
21
|
-
var COMPONENTS = [setupField('alpha', {
|
|
9
|
+
describe('utils', () => {
|
|
10
|
+
describe('Format', () => {
|
|
11
|
+
const setupField = (fieldId, format) => ({
|
|
12
|
+
fieldId,
|
|
13
|
+
format
|
|
14
|
+
});
|
|
15
|
+
describe('formatDataForPage', () => {
|
|
16
|
+
it('should appropriately format a page of components', () => {
|
|
17
|
+
const EVENT_TYPE = _models.EventTypes.SUBMIT;
|
|
18
|
+
const COMPONENTS = [setupField('alpha', {
|
|
22
19
|
type: 'lowercase',
|
|
23
20
|
on: _models.EventTypes.SUBMIT
|
|
24
21
|
}),
|
|
@@ -35,14 +32,13 @@ describe('utils', function () {
|
|
|
35
32
|
on: _models.EventTypes.BLUR
|
|
36
33
|
}) // Should not be formatted because of event type
|
|
37
34
|
];
|
|
38
|
-
|
|
39
|
-
var DATA = {
|
|
35
|
+
const DATA = {
|
|
40
36
|
alpha: 'AlPhA',
|
|
41
37
|
bravo: 'bRaVo',
|
|
42
38
|
charlie: 'CHArlie',
|
|
43
39
|
delta: 'deLTA'
|
|
44
40
|
};
|
|
45
|
-
|
|
41
|
+
const PAGE = {
|
|
46
42
|
components: COMPONENTS
|
|
47
43
|
};
|
|
48
44
|
(0, _formatDataForPage.default)(PAGE, DATA, EVENT_TYPE);
|
|
@@ -54,10 +50,10 @@ describe('utils', function () {
|
|
|
54
50
|
});
|
|
55
51
|
});
|
|
56
52
|
});
|
|
57
|
-
describe('formatDataForPages',
|
|
58
|
-
it('should appropriately format multiple pages',
|
|
59
|
-
|
|
60
|
-
|
|
53
|
+
describe('formatDataForPages', () => {
|
|
54
|
+
it('should appropriately format multiple pages', () => {
|
|
55
|
+
const EVENT_TYPE = _models.EventTypes.SUBMIT;
|
|
56
|
+
const COMPONENTS = [setupField('alpha', {
|
|
61
57
|
type: 'lowercase',
|
|
62
58
|
on: _models.EventTypes.SUBMIT
|
|
63
59
|
}),
|
|
@@ -74,14 +70,13 @@ describe('utils', function () {
|
|
|
74
70
|
on: _models.EventTypes.BLUR
|
|
75
71
|
}) // Should not be formatted because of event type
|
|
76
72
|
];
|
|
77
|
-
|
|
78
|
-
var DATA = {
|
|
73
|
+
const DATA = {
|
|
79
74
|
alpha: 'AlPhA',
|
|
80
75
|
bravo: 'bRaVo',
|
|
81
76
|
charlie: 'CHArlie',
|
|
82
77
|
delta: 'deLTA'
|
|
83
78
|
};
|
|
84
|
-
|
|
79
|
+
const PAGES = [{
|
|
85
80
|
components: COMPONENTS.slice(0, 1)
|
|
86
81
|
}, {
|
|
87
82
|
components: COMPONENTS.slice(2)
|
|
@@ -8,10 +8,10 @@ var _formatData = _interopRequireDefault(require("./formatData"));
|
|
|
8
8
|
var _formatDataForComponent = _interopRequireDefault(require("./formatDataForComponent"));
|
|
9
9
|
var _formatDataForForm = _interopRequireDefault(require("./formatDataForForm"));
|
|
10
10
|
var _formatDataForPage = _interopRequireDefault(require("./formatDataForPage"));
|
|
11
|
-
function _interopRequireDefault(
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
12
|
// Local imports
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
const Format = {
|
|
15
15
|
component: _formatDataForComponent.default,
|
|
16
16
|
data: _formatData.default,
|
|
17
17
|
form: _formatDataForForm.default,
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _models = require("../../models");
|
|
8
8
|
var _FormPage = _interopRequireDefault(require("../FormPage"));
|
|
9
|
-
function _interopRequireDefault(
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
10
|
// Local imports
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -22,7 +22,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
22
22
|
* The string "CYA" if the CYA screen should be used, or;
|
|
23
23
|
* A page configuration object if the CYA screen should not be used and components are defined.
|
|
24
24
|
*/
|
|
25
|
-
|
|
25
|
+
const getFormHub = (type, hub, components, formData) => {
|
|
26
26
|
if (type === _models.FormTypes.HUB && hub) {
|
|
27
27
|
if (hub.format === _models.HubFormats.CYA) {
|
|
28
28
|
return _models.HubFormats.CYA;
|
|
@@ -2,17 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
var _models = require("../../models");
|
|
4
4
|
var _getFormHub = _interopRequireDefault(require("./getFormHub"));
|
|
5
|
-
function _interopRequireDefault(
|
|
6
|
-
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); }
|
|
5
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
6
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
8
7
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
9
|
-
function _defineProperty(
|
|
10
|
-
function _toPropertyKey(
|
|
11
|
-
function _toPrimitive(
|
|
12
|
-
describe('utils',
|
|
13
|
-
describe('Hub',
|
|
14
|
-
describe('getFormHub',
|
|
15
|
-
|
|
8
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
9
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
10
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } // Local imports
|
|
11
|
+
describe('utils', () => {
|
|
12
|
+
describe('Hub', () => {
|
|
13
|
+
describe('getFormHub', () => {
|
|
14
|
+
const FORM_COMPONENTS = [{
|
|
16
15
|
id: 'a',
|
|
17
16
|
fieldId: 'a',
|
|
18
17
|
label: 'Alpha',
|
|
@@ -33,33 +32,33 @@ describe('utils', function () {
|
|
|
33
32
|
url: '${urls.refData}/v3/charlies'
|
|
34
33
|
}
|
|
35
34
|
}];
|
|
36
|
-
|
|
35
|
+
const FORM_DATA = {
|
|
37
36
|
urls: {
|
|
38
37
|
refData: 'https://ho.gov.uk/ref-data/'
|
|
39
38
|
}
|
|
40
39
|
};
|
|
41
|
-
[_models.FormTypes.CYA, _models.FormTypes.FORM, _models.FormTypes.WIZARD].forEach(
|
|
42
|
-
describe("when the FormType is \"".concat(formType, "\""),
|
|
43
|
-
it('should return undefined',
|
|
40
|
+
[_models.FormTypes.CYA, _models.FormTypes.FORM, _models.FormTypes.WIZARD].forEach(formType => {
|
|
41
|
+
describe("when the FormType is \"".concat(formType, "\""), () => {
|
|
42
|
+
it('should return undefined', () => {
|
|
44
43
|
expect((0, _getFormHub.default)(formType, {}, FORM_COMPONENTS, FORM_DATA)).toBeUndefined();
|
|
45
44
|
});
|
|
46
45
|
});
|
|
47
46
|
});
|
|
48
|
-
describe("when the FormType is \"".concat(_models.FormTypes.HUB, "\""),
|
|
49
|
-
it('should return undefined when there is no hub',
|
|
47
|
+
describe("when the FormType is \"".concat(_models.FormTypes.HUB, "\""), () => {
|
|
48
|
+
it('should return undefined when there is no hub', () => {
|
|
50
49
|
expect((0, _getFormHub.default)(_models.FormTypes.HUB, null, FORM_COMPONENTS, FORM_DATA)).toBeUndefined();
|
|
51
50
|
});
|
|
52
|
-
it("should return undefined when the format is not \"".concat(_models.HubFormats.CYA, "\" but hub also has no components"),
|
|
51
|
+
it("should return undefined when the format is not \"".concat(_models.HubFormats.CYA, "\" but hub also has no components"), () => {
|
|
53
52
|
expect((0, _getFormHub.default)(_models.FormTypes.HUB, {}, FORM_COMPONENTS, FORM_DATA)).toBeUndefined();
|
|
54
53
|
});
|
|
55
|
-
it("should return the string \"".concat(_models.HubFormats.CYA, "\" when the format is set to \"").concat(_models.HubFormats.CYA, "\""),
|
|
56
|
-
|
|
54
|
+
it("should return the string \"".concat(_models.HubFormats.CYA, "\" when the format is set to \"").concat(_models.HubFormats.CYA, "\""), () => {
|
|
55
|
+
const HUB = {
|
|
57
56
|
format: _models.HubFormats.CYA
|
|
58
57
|
};
|
|
59
58
|
expect((0, _getFormHub.default)(_models.FormTypes.HUB, HUB, FORM_COMPONENTS, FORM_DATA)).toEqual(_models.HubFormats.CYA);
|
|
60
59
|
});
|
|
61
|
-
it("should return an appropriate page when the format is not \"".concat(_models.HubFormats.CYA, "\" and hub contains components"),
|
|
62
|
-
|
|
60
|
+
it("should return an appropriate page when the format is not \"".concat(_models.HubFormats.CYA, "\" and hub contains components"), () => {
|
|
61
|
+
const HUB = {
|
|
63
62
|
title: 'Hub title',
|
|
64
63
|
components: ['Opening paragraph', {
|
|
65
64
|
type: 'heading',
|
|
@@ -69,7 +68,7 @@ describe('utils', function () {
|
|
|
69
68
|
use: 'a'
|
|
70
69
|
}]
|
|
71
70
|
};
|
|
72
|
-
|
|
71
|
+
const A = FORM_COMPONENTS[0];
|
|
73
72
|
expect((0, _getFormHub.default)(_models.FormTypes.HUB, HUB, FORM_COMPONENTS, FORM_DATA)).toEqual({
|
|
74
73
|
title: HUB.title,
|
|
75
74
|
components: [{
|
|
@@ -92,9 +91,9 @@ describe('utils', function () {
|
|
|
92
91
|
});
|
|
93
92
|
});
|
|
94
93
|
});
|
|
95
|
-
describe("when the FormType is \"".concat(_models.FormTypes.TASK, "\""),
|
|
96
|
-
it("should return the string \"".concat(_models.HubFormats.TASK, "\" when the format is set to \"").concat(_models.HubFormats.TASK, "\""),
|
|
97
|
-
|
|
94
|
+
describe("when the FormType is \"".concat(_models.FormTypes.TASK, "\""), () => {
|
|
95
|
+
it("should return the string \"".concat(_models.HubFormats.TASK, "\" when the format is set to \"").concat(_models.HubFormats.TASK, "\""), () => {
|
|
96
|
+
const HUB = {
|
|
98
97
|
format: _models.HubFormats.TASK
|
|
99
98
|
};
|
|
100
99
|
expect((0, _getFormHub.default)(_models.FormTypes.TASK, HUB, FORM_COMPONENTS, FORM_DATA)).toEqual(_models.HubFormats.TASK);
|
package/dist/utils/Hub/index.js
CHANGED
|
@@ -5,10 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _getFormHub = _interopRequireDefault(require("./getFormHub"));
|
|
8
|
-
function _interopRequireDefault(
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
9
|
// Local imports
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
const Hub = {
|
|
12
12
|
get: _getFormHub.default
|
|
13
13
|
};
|
|
14
14
|
var _default = exports.default = Hub;
|
|
@@ -4,5 +4,5 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.META_PROPERTY = exports.META_DOCUMENTS_PROPERTY = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const META_PROPERTY = exports.META_PROPERTY = 'meta';
|
|
8
|
+
const META_DOCUMENTS_PROPERTY = exports.META_DOCUMENTS_PROPERTY = 'documents';
|
|
@@ -7,7 +7,7 @@ exports.default = void 0;
|
|
|
7
7
|
var _constants = require("../constants");
|
|
8
8
|
// Local imports
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
const getDocuments = formData => {
|
|
11
11
|
var _formData$META_PROPER;
|
|
12
12
|
return (formData === null || formData === void 0 || (_formData$META_PROPER = formData[_constants.META_PROPERTY]) === null || _formData$META_PROPER === void 0 ? void 0 : _formData$META_PROPER[_constants.META_DOCUMENTS_PROPERTY]) || [];
|
|
13
13
|
};
|
|
@@ -2,36 +2,44 @@
|
|
|
2
2
|
|
|
3
3
|
var _constants = require("../constants");
|
|
4
4
|
var _getDocuments = _interopRequireDefault(require("./getDocuments"));
|
|
5
|
-
function _interopRequireDefault(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
9
|
-
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
10
|
-
describe('Utils.Meta.documents.get', function () {
|
|
11
|
-
it('should return an empty array if formData is null', function () {
|
|
5
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
6
|
+
describe('Utils.Meta.documents.get', () => {
|
|
7
|
+
it('should return an empty array if formData is null', () => {
|
|
12
8
|
expect((0, _getDocuments.default)(null)).toEqual([]);
|
|
13
9
|
});
|
|
14
|
-
it('should return an empty array if formData does not contain a meta property',
|
|
10
|
+
it('should return an empty array if formData does not contain a meta property', () => {
|
|
15
11
|
expect((0, _getDocuments.default)({})).toEqual([]);
|
|
16
12
|
});
|
|
17
|
-
it('should return an empty array if the meta property is undefined',
|
|
18
|
-
|
|
13
|
+
it('should return an empty array if the meta property is undefined', () => {
|
|
14
|
+
const FORM_DATA = {
|
|
15
|
+
[_constants.META_PROPERTY]: undefined
|
|
16
|
+
};
|
|
19
17
|
expect((0, _getDocuments.default)(FORM_DATA)).toEqual([]);
|
|
20
18
|
});
|
|
21
|
-
it('should return an empty array if the meta property contains no documents property',
|
|
22
|
-
|
|
19
|
+
it('should return an empty array if the meta property contains no documents property', () => {
|
|
20
|
+
const FORM_DATA = {
|
|
21
|
+
[_constants.META_PROPERTY]: {}
|
|
22
|
+
};
|
|
23
23
|
expect((0, _getDocuments.default)(FORM_DATA)).toEqual([]);
|
|
24
24
|
});
|
|
25
|
-
it('should return an empty array if the meta.documents property is undefined',
|
|
26
|
-
|
|
25
|
+
it('should return an empty array if the meta.documents property is undefined', () => {
|
|
26
|
+
const FORM_DATA = {
|
|
27
|
+
[_constants.META_PROPERTY]: {
|
|
28
|
+
[_constants.META_DOCUMENTS_PROPERTY]: undefined
|
|
29
|
+
}
|
|
30
|
+
};
|
|
27
31
|
expect((0, _getDocuments.default)(FORM_DATA)).toEqual([]);
|
|
28
32
|
});
|
|
29
|
-
it('should return the meta.documents property if it exists',
|
|
30
|
-
|
|
33
|
+
it('should return the meta.documents property if it exists', () => {
|
|
34
|
+
const DOCUMENTS = [{
|
|
31
35
|
field: 'alpha',
|
|
32
36
|
url: 'http://alpha-bravo.com/files/charlie'
|
|
33
37
|
}];
|
|
34
|
-
|
|
38
|
+
const FORM_DATA = {
|
|
39
|
+
[_constants.META_PROPERTY]: {
|
|
40
|
+
[_constants.META_DOCUMENTS_PROPERTY]: DOCUMENTS
|
|
41
|
+
}
|
|
42
|
+
};
|
|
35
43
|
expect((0, _getDocuments.default)(FORM_DATA)).toEqual(DOCUMENTS);
|
|
36
44
|
});
|
|
37
45
|
});
|
|
@@ -7,10 +7,10 @@ exports.default = void 0;
|
|
|
7
7
|
var _constants = require("../constants");
|
|
8
8
|
var _setDocumentsForField = _interopRequireDefault(require("./setDocumentsForField"));
|
|
9
9
|
var _getDocuments = _interopRequireDefault(require("./getDocuments"));
|
|
10
|
-
function _interopRequireDefault(
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
11
|
// Local imports
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
const documents = {
|
|
14
14
|
setForField: _setDocumentsForField.default,
|
|
15
15
|
get: _getDocuments.default,
|
|
16
16
|
name: _constants.META_DOCUMENTS_PROPERTY
|
|
@@ -6,25 +6,24 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _constants = require("../constants");
|
|
8
8
|
var _getDocuments = _interopRequireDefault(require("./getDocuments"));
|
|
9
|
-
function _interopRequireDefault(
|
|
10
|
-
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); }
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
10
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
12
11
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
13
|
-
function _defineProperty(
|
|
14
|
-
function _toPropertyKey(
|
|
15
|
-
function _toPrimitive(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return d.field !== field;
|
|
19
|
-
});
|
|
12
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
13
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
14
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } // Local imports
|
|
15
|
+
const setDocumentsForField = (documents, formData, field, allowMultiple) => {
|
|
16
|
+
const changedDocuments = allowMultiple ? (0, _getDocuments.default)(formData) : (0, _getDocuments.default)(formData).filter(d => d.field !== field);
|
|
20
17
|
if (Array.isArray(documents)) {
|
|
21
|
-
documents.forEach(
|
|
18
|
+
documents.forEach(document => {
|
|
22
19
|
changedDocuments.push(_objectSpread(_objectSpread({}, document), {}, {
|
|
23
|
-
field
|
|
20
|
+
field
|
|
24
21
|
}));
|
|
25
22
|
});
|
|
26
23
|
}
|
|
27
|
-
|
|
28
|
-
return _objectSpread(_objectSpread({}, existing), {},
|
|
24
|
+
const existing = formData ? formData[_constants.META_PROPERTY] : undefined;
|
|
25
|
+
return _objectSpread(_objectSpread({}, existing), {}, {
|
|
26
|
+
[_constants.META_DOCUMENTS_PROPERTY]: changedDocuments
|
|
27
|
+
});
|
|
29
28
|
};
|
|
30
29
|
var _default = exports.default = setDocumentsForField;
|
|
@@ -2,58 +2,95 @@
|
|
|
2
2
|
|
|
3
3
|
var _constants = require("../constants");
|
|
4
4
|
var _setDocumentsForField = _interopRequireDefault(require("./setDocumentsForField"));
|
|
5
|
-
function _interopRequireDefault(
|
|
6
|
-
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); }
|
|
5
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
6
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
8
7
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
9
|
-
function _defineProperty(
|
|
10
|
-
function _toPropertyKey(
|
|
11
|
-
function _toPrimitive(
|
|
12
|
-
describe('Utils.Meta.documents.add',
|
|
13
|
-
|
|
8
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
9
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
10
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
11
|
+
describe('Utils.Meta.documents.add', () => {
|
|
12
|
+
const ALPHA_DOCUMENT = {
|
|
14
13
|
field: 'alpha',
|
|
15
14
|
url: 'http://alpha-bravo.com/files/alpha'
|
|
16
15
|
};
|
|
17
|
-
|
|
16
|
+
const BRAVO_DOCUMENT = {
|
|
18
17
|
field: 'bravo',
|
|
19
18
|
url: 'http://alpha-bravo.com/files/bravo'
|
|
20
19
|
};
|
|
21
|
-
it('should return an appropriately set up object if formData is null',
|
|
22
|
-
expect((0, _setDocumentsForField.default)([ALPHA_DOCUMENT], null, ALPHA_DOCUMENT.field)).toEqual(
|
|
20
|
+
it('should return an appropriately set up object if formData is null', () => {
|
|
21
|
+
expect((0, _setDocumentsForField.default)([ALPHA_DOCUMENT], null, ALPHA_DOCUMENT.field)).toEqual({
|
|
22
|
+
[_constants.META_DOCUMENTS_PROPERTY]: [ALPHA_DOCUMENT]
|
|
23
|
+
});
|
|
23
24
|
});
|
|
24
|
-
it('should add a new document to the array',
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
it('should add a new document to the array', () => {
|
|
26
|
+
const FORM_DATA = {
|
|
27
|
+
[_constants.META_PROPERTY]: {
|
|
28
|
+
[_constants.META_DOCUMENTS_PROPERTY]: [ALPHA_DOCUMENT]
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
expect((0, _setDocumentsForField.default)([BRAVO_DOCUMENT], FORM_DATA, BRAVO_DOCUMENT.field)).toEqual({
|
|
32
|
+
[_constants.META_DOCUMENTS_PROPERTY]: [ALPHA_DOCUMENT, BRAVO_DOCUMENT]
|
|
33
|
+
});
|
|
27
34
|
});
|
|
28
|
-
it('should add multiple new documents to the array',
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
35
|
+
it('should add multiple new documents to the array', () => {
|
|
36
|
+
const FORM_DATA = {
|
|
37
|
+
[_constants.META_PROPERTY]: {
|
|
38
|
+
[_constants.META_DOCUMENTS_PROPERTY]: []
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const SECOND_DOCUMENT = _objectSpread({}, ALPHA_DOCUMENT);
|
|
42
|
+
expect((0, _setDocumentsForField.default)([ALPHA_DOCUMENT, SECOND_DOCUMENT], FORM_DATA, ALPHA_DOCUMENT.field)).toEqual({
|
|
43
|
+
[_constants.META_DOCUMENTS_PROPERTY]: [ALPHA_DOCUMENT, SECOND_DOCUMENT]
|
|
44
|
+
});
|
|
32
45
|
});
|
|
33
|
-
it('should replace an existing document with the same field',
|
|
34
|
-
|
|
35
|
-
|
|
46
|
+
it('should replace an existing document with the same field', () => {
|
|
47
|
+
const NEW_URL = 'http://replacement.com/files/alpha';
|
|
48
|
+
const NEW_ALPHA = {
|
|
36
49
|
field: ALPHA_DOCUMENT.field,
|
|
37
50
|
url: NEW_URL
|
|
38
51
|
};
|
|
39
|
-
|
|
40
|
-
|
|
52
|
+
const FORM_DATA = {
|
|
53
|
+
[_constants.META_PROPERTY]: {
|
|
54
|
+
[_constants.META_DOCUMENTS_PROPERTY]: [ALPHA_DOCUMENT]
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
expect((0, _setDocumentsForField.default)([NEW_ALPHA], FORM_DATA, NEW_ALPHA.field)).toEqual({
|
|
58
|
+
[_constants.META_DOCUMENTS_PROPERTY]: [NEW_ALPHA]
|
|
59
|
+
});
|
|
41
60
|
});
|
|
42
|
-
it('should add a document with the same field if allowMultiple is true',
|
|
43
|
-
|
|
44
|
-
|
|
61
|
+
it('should add a document with the same field if allowMultiple is true', () => {
|
|
62
|
+
const NEW_URL = 'http://replacement.com/files/alpha';
|
|
63
|
+
const NEW_ALPHA = {
|
|
45
64
|
field: ALPHA_DOCUMENT.field,
|
|
46
65
|
url: NEW_URL
|
|
47
66
|
};
|
|
48
|
-
|
|
49
|
-
|
|
67
|
+
const FORM_DATA = {
|
|
68
|
+
[_constants.META_PROPERTY]: {
|
|
69
|
+
[_constants.META_DOCUMENTS_PROPERTY]: [ALPHA_DOCUMENT]
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
expect((0, _setDocumentsForField.default)([NEW_ALPHA], FORM_DATA, NEW_ALPHA.field, true)).toEqual({
|
|
73
|
+
[_constants.META_DOCUMENTS_PROPERTY]: [ALPHA_DOCUMENT, NEW_ALPHA]
|
|
74
|
+
});
|
|
50
75
|
});
|
|
51
|
-
it('should handle a null document being passed where a document with that field already exists',
|
|
52
|
-
|
|
53
|
-
|
|
76
|
+
it('should handle a null document being passed where a document with that field already exists', () => {
|
|
77
|
+
const FORM_DATA = {
|
|
78
|
+
[_constants.META_PROPERTY]: {
|
|
79
|
+
[_constants.META_DOCUMENTS_PROPERTY]: [ALPHA_DOCUMENT]
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
expect((0, _setDocumentsForField.default)(null, FORM_DATA, ALPHA_DOCUMENT.field)).toEqual({
|
|
83
|
+
[_constants.META_DOCUMENTS_PROPERTY]: []
|
|
84
|
+
});
|
|
54
85
|
});
|
|
55
|
-
it('should handle a null document being passed where a document with that field does not already exist',
|
|
56
|
-
|
|
57
|
-
|
|
86
|
+
it('should handle a null document being passed where a document with that field does not already exist', () => {
|
|
87
|
+
const FORM_DATA = {
|
|
88
|
+
[_constants.META_PROPERTY]: {
|
|
89
|
+
[_constants.META_DOCUMENTS_PROPERTY]: [ALPHA_DOCUMENT]
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
expect((0, _setDocumentsForField.default)(null, FORM_DATA, BRAVO_DOCUMENT.field)).toEqual({
|
|
93
|
+
[_constants.META_DOCUMENTS_PROPERTY]: [ALPHA_DOCUMENT]
|
|
94
|
+
});
|
|
58
95
|
});
|
|
59
96
|
});
|
package/dist/utils/Meta/index.js
CHANGED
|
@@ -6,10 +6,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _constants = require("./constants");
|
|
8
8
|
var _documents = _interopRequireDefault(require("./documents"));
|
|
9
|
-
function _interopRequireDefault(
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
10
|
// Local imports
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
const Meta = {
|
|
13
13
|
documents: _documents.default,
|
|
14
14
|
name: _constants.META_PROPERTY
|
|
15
15
|
};
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
8
8
|
var _getSourceData = _interopRequireDefault(require("../Data/getSourceData"));
|
|
9
|
-
function _interopRequireDefault(
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
10
|
// Global imports.
|
|
11
11
|
|
|
12
12
|
// Local imports.
|
|
@@ -18,9 +18,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
18
18
|
* @param {object} data The page's formData.
|
|
19
19
|
* @returns true if the value is truthy, false if it isn't or doesn't exist.
|
|
20
20
|
*/
|
|
21
|
-
|
|
21
|
+
const checkValueIsTruthy = (config, data) => {
|
|
22
22
|
if (config !== null && config !== void 0 && config.field) {
|
|
23
|
-
|
|
23
|
+
const fieldPath = _copReactComponents.Utils.interpolateString(config.field, data);
|
|
24
24
|
return !!(0, _getSourceData.default)(data, fieldPath);
|
|
25
25
|
}
|
|
26
26
|
return false;
|