@ukhomeoffice/cop-react-form-renderer 6.14.0 → 6.14.1
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 +19 -27
- package/dist/utils/Data/getAutocompleteSource.test.js +76 -81
- 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
|
@@ -1,426 +1,365 @@
|
|
|
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 _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
5
4
|
var _react = _interopRequireDefault(require("react"));
|
|
6
5
|
var _setupTests = require("../../setupTests");
|
|
7
6
|
var _FormComponent = _interopRequireDefault(require("./FormComponent"));
|
|
8
7
|
var _models = require("../../models");
|
|
9
|
-
function _interopRequireDefault(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
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
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
// Global imports
|
|
10
|
+
|
|
13
11
|
// Local imports
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
};
|
|
325
|
-
DATA = {
|
|
326
|
-
component: 'existing value'
|
|
327
|
-
};
|
|
328
|
-
ON_CHANGE_ARGS = [];
|
|
329
|
-
ON_CHANGE_COUNT = 0;
|
|
330
|
-
ON_CHANGE = function ON_CHANGE(_ref11) {
|
|
331
|
-
var target = _ref11.target;
|
|
332
|
-
ON_CHANGE_ARGS.push(target);
|
|
333
|
-
ON_CHANGE_COUNT += 1;
|
|
334
|
-
};
|
|
335
|
-
_renderWithValidation9 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
336
|
-
"data-testid": ID,
|
|
337
|
-
component: COMPONENT,
|
|
338
|
-
value: DATA[ID],
|
|
339
|
-
onChange: ON_CHANGE,
|
|
340
|
-
formData: DATA
|
|
341
|
-
})), container = _renderWithValidation9.container;
|
|
342
|
-
expect(ON_CHANGE_COUNT).toEqual(0);
|
|
343
|
-
formGroup = container.childNodes[0];
|
|
344
|
-
input = formGroup.childNodes[2];
|
|
345
|
-
expect(input.value).toEqual(DATA[ID]);
|
|
346
|
-
case 11:
|
|
347
|
-
case "end":
|
|
348
|
-
return _context9.stop();
|
|
349
|
-
}
|
|
350
|
-
}, _callee9);
|
|
351
|
-
})));
|
|
352
|
-
it('should correctly handle a nested file input on change event within a nested container', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
|
|
353
|
-
var ID, NESTED_CONTAINER_ID, NESTED_ID, COMPONENT, DATA, ON_CHANGE_ARGS, ON_CHANGE_COUNT, ON_CHANGE, _renderWithValidation10, container, c, formGroup, fieldSet, input, FILE_EXTENSION, FILE_NAME, FILE_TYPE, str, blob, FILE;
|
|
354
|
-
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
355
|
-
while (1) switch (_context10.prev = _context10.next) {
|
|
356
|
-
case 0:
|
|
357
|
-
ID = 'component';
|
|
358
|
-
NESTED_CONTAINER_ID = 'nested-container-component';
|
|
359
|
-
NESTED_ID = 'nested-component';
|
|
360
|
-
COMPONENT = {
|
|
361
|
-
id: ID,
|
|
362
|
-
fieldId: ID,
|
|
363
|
-
type: _models.ComponentTypes.CHECKBOXES,
|
|
364
|
-
label: 'Checkboxes component',
|
|
365
|
-
data: {
|
|
366
|
-
options: [{
|
|
367
|
-
value: 'EPSILON',
|
|
368
|
-
label: 'Epsilon Label'
|
|
369
|
-
}, {
|
|
370
|
-
value: 'GAMMA',
|
|
371
|
-
label: 'Gamma Label',
|
|
372
|
-
nested: [{
|
|
373
|
-
id: NESTED_CONTAINER_ID,
|
|
374
|
-
fieldId: NESTED_CONTAINER_ID,
|
|
375
|
-
type: _models.ComponentTypes.CONTAINER,
|
|
376
|
-
components: [{
|
|
377
|
-
id: NESTED_ID,
|
|
378
|
-
fieldId: NESTED_ID,
|
|
379
|
-
label: 'File upload',
|
|
380
|
-
type: _models.ComponentTypes.FILE
|
|
381
|
-
}]
|
|
382
|
-
}]
|
|
383
|
-
}]
|
|
384
|
-
}
|
|
385
|
-
};
|
|
386
|
-
DATA = {
|
|
387
|
-
component: 'GAMMA'
|
|
388
|
-
};
|
|
389
|
-
ON_CHANGE_ARGS = [];
|
|
390
|
-
ON_CHANGE_COUNT = 0;
|
|
391
|
-
ON_CHANGE = function ON_CHANGE(_ref13) {
|
|
392
|
-
var target = _ref13.target;
|
|
393
|
-
ON_CHANGE_ARGS.push(target);
|
|
394
|
-
ON_CHANGE_COUNT += 1;
|
|
395
|
-
};
|
|
396
|
-
_renderWithValidation10 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
397
|
-
"data-testid": ID,
|
|
398
|
-
component: COMPONENT,
|
|
399
|
-
value: DATA[ID],
|
|
400
|
-
onChange: ON_CHANGE,
|
|
401
|
-
formData: DATA
|
|
402
|
-
})), container = _renderWithValidation10.container; // Get hold of the file input.
|
|
403
|
-
c = container.childNodes[0];
|
|
404
|
-
formGroup = c.childNodes[0];
|
|
405
|
-
fieldSet = formGroup.childNodes[2];
|
|
406
|
-
input = fieldSet.childNodes[2].childNodes[0].childNodes[0].childNodes[2].childNodes[0];
|
|
407
|
-
FILE_EXTENSION = 'json';
|
|
408
|
-
FILE_NAME = "test.".concat(FILE_EXTENSION);
|
|
409
|
-
FILE_TYPE = 'application/JSON';
|
|
410
|
-
str = JSON.stringify({
|
|
411
|
-
alpha: 'bravo'
|
|
412
|
-
});
|
|
413
|
-
blob = new Blob([str]);
|
|
414
|
-
FILE = new File([blob], FILE_NAME, {
|
|
415
|
-
type: FILE_TYPE
|
|
416
|
-
});
|
|
417
|
-
_userEvent.default.upload(input, FILE);
|
|
418
|
-
expect(ON_CHANGE_COUNT).toEqual(3);
|
|
419
|
-
case 21:
|
|
420
|
-
case "end":
|
|
421
|
-
return _context10.stop();
|
|
12
|
+
|
|
13
|
+
describe('components', () => {
|
|
14
|
+
describe('FormComponent', () => {
|
|
15
|
+
it('should render a text component appropriately', async () => {
|
|
16
|
+
const ID = 'component';
|
|
17
|
+
const VALUE = 'Text value';
|
|
18
|
+
const COMPONENT = {
|
|
19
|
+
id: ID,
|
|
20
|
+
fieldId: ID,
|
|
21
|
+
type: 'text',
|
|
22
|
+
label: 'Text component',
|
|
23
|
+
hint: 'Text hint'
|
|
24
|
+
};
|
|
25
|
+
const ON_CHANGE = () => {};
|
|
26
|
+
const {
|
|
27
|
+
container
|
|
28
|
+
} = (0, _setupTests.renderWithValidation)(/*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
29
|
+
"data-testid": ID,
|
|
30
|
+
component: COMPONENT,
|
|
31
|
+
value: VALUE,
|
|
32
|
+
onChange: ON_CHANGE
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
// text components are wrapper in a FormGroup by default.
|
|
36
|
+
const formGroup = container.childNodes[0];
|
|
37
|
+
expect(formGroup.tagName).toEqual('DIV');
|
|
38
|
+
expect(formGroup.classList).toContain('govuk-form-group');
|
|
39
|
+
const label = formGroup.childNodes[0];
|
|
40
|
+
expect(label.tagName).toEqual('LABEL');
|
|
41
|
+
expect(label.classList).toContain('govuk-label');
|
|
42
|
+
expect(label.textContent).toEqual("".concat(COMPONENT.label, " (optional)"));
|
|
43
|
+
expect(label.getAttribute('for')).toEqual(ID);
|
|
44
|
+
const hint = formGroup.childNodes[1];
|
|
45
|
+
expect(hint.tagName).toEqual('DIV');
|
|
46
|
+
expect(hint.classList).toContain('govuk-hint');
|
|
47
|
+
expect(hint.textContent).toEqual(COMPONENT.hint);
|
|
48
|
+
const input = formGroup.childNodes[2];
|
|
49
|
+
expect(input.tagName).toEqual('INPUT');
|
|
50
|
+
expect(input.classList).toContain('govuk-input');
|
|
51
|
+
expect(input.id).toEqual(ID);
|
|
52
|
+
expect(input.value).toEqual(VALUE);
|
|
53
|
+
});
|
|
54
|
+
it('should render a text component appropriately with wrap turned off', async () => {
|
|
55
|
+
const ID = 'component';
|
|
56
|
+
const VALUE = 'Text value';
|
|
57
|
+
const COMPONENT = {
|
|
58
|
+
id: ID,
|
|
59
|
+
fieldId: ID,
|
|
60
|
+
type: 'text',
|
|
61
|
+
label: 'Text component',
|
|
62
|
+
hint: 'Text hint'
|
|
63
|
+
};
|
|
64
|
+
const ON_CHANGE = () => {};
|
|
65
|
+
const {
|
|
66
|
+
container
|
|
67
|
+
} = (0, _setupTests.renderWithValidation)(/*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
68
|
+
"data-testid": ID,
|
|
69
|
+
component: COMPONENT,
|
|
70
|
+
wrap: false,
|
|
71
|
+
value: VALUE,
|
|
72
|
+
onChange: ON_CHANGE
|
|
73
|
+
}));
|
|
74
|
+
|
|
75
|
+
// With wrap = false, there should be no form group.
|
|
76
|
+
const input = container.childNodes[0];
|
|
77
|
+
expect(input.tagName).toEqual('INPUT');
|
|
78
|
+
expect(input.classList).toContain('govuk-input');
|
|
79
|
+
expect(input.id).toEqual(ID);
|
|
80
|
+
expect(input.value).toEqual(VALUE);
|
|
81
|
+
});
|
|
82
|
+
it('should render an html component appropriately', async () => {
|
|
83
|
+
const ID = 'component';
|
|
84
|
+
const COMPONENT = {
|
|
85
|
+
type: 'html',
|
|
86
|
+
tagName: 'p',
|
|
87
|
+
content: 'HTML content'
|
|
88
|
+
};
|
|
89
|
+
const {
|
|
90
|
+
container
|
|
91
|
+
} = (0, _setupTests.renderWithValidation)(/*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
92
|
+
"data-testid": ID,
|
|
93
|
+
component: COMPONENT
|
|
94
|
+
}));
|
|
95
|
+
const p = container.childNodes[0];
|
|
96
|
+
expect(p.tagName).toEqual('P');
|
|
97
|
+
expect(p.textContent).toEqual(COMPONENT.content);
|
|
98
|
+
});
|
|
99
|
+
it('should render an overridden html component appropriately', async () => {
|
|
100
|
+
const hooks = {
|
|
101
|
+
onGetComponent: (config, wrap) => /*#__PURE__*/_react.default.createElement("div", null, "".concat(config.type, " | ").concat(config.tagName, " | ").concat(config.content, " | ").concat(wrap))
|
|
102
|
+
};
|
|
103
|
+
const ID = 'component';
|
|
104
|
+
const COMPONENT = {
|
|
105
|
+
type: 'html',
|
|
106
|
+
tagName: 'p',
|
|
107
|
+
content: 'HTML content'
|
|
108
|
+
};
|
|
109
|
+
const {
|
|
110
|
+
container
|
|
111
|
+
} = (0, _setupTests.renderWithValidation)(/*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
112
|
+
"data-testid": ID,
|
|
113
|
+
component: COMPONENT
|
|
114
|
+
}), {
|
|
115
|
+
hooks
|
|
116
|
+
});
|
|
117
|
+
const div = container.childNodes[0];
|
|
118
|
+
expect(div.tagName).toEqual('DIV');
|
|
119
|
+
expect(div.textContent).toEqual("".concat(COMPONENT.type, " | ").concat(COMPONENT.tagName, " | ").concat(COMPONENT.content, " | true"));
|
|
120
|
+
});
|
|
121
|
+
it('should render an overridden html component appropriately and pass through onAction', async () => {
|
|
122
|
+
const hooks = {
|
|
123
|
+
onGetComponent: (config, wrap) => /*#__PURE__*/_react.default.createElement("div", null, "".concat(config.type, " | ").concat(config.tagName, " | ").concat(config.content, " | ").concat(wrap, " | ").concat(config.onAction))
|
|
124
|
+
};
|
|
125
|
+
const ID = 'component';
|
|
126
|
+
const COMPONENT = {
|
|
127
|
+
type: 'html',
|
|
128
|
+
tagName: 'p',
|
|
129
|
+
content: 'HTML content'
|
|
130
|
+
};
|
|
131
|
+
const {
|
|
132
|
+
container
|
|
133
|
+
} = (0, _setupTests.renderWithValidation)(/*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
134
|
+
"data-testid": ID,
|
|
135
|
+
component: COMPONENT,
|
|
136
|
+
onAction: "() => {}"
|
|
137
|
+
}), {
|
|
138
|
+
hooks
|
|
139
|
+
});
|
|
140
|
+
const div = container.childNodes[0];
|
|
141
|
+
expect(div.tagName).toEqual('DIV');
|
|
142
|
+
expect(div.textContent).toEqual("".concat(COMPONENT.type, " | ").concat(COMPONENT.tagName, " | ").concat(COMPONENT.content, " | true | () => {}"));
|
|
143
|
+
});
|
|
144
|
+
it('should render the correct html component when the override returns null', async () => {
|
|
145
|
+
const hooks = {
|
|
146
|
+
onGetComponent: () => null
|
|
147
|
+
};
|
|
148
|
+
const ID = 'component';
|
|
149
|
+
const COMPONENT = {
|
|
150
|
+
type: 'html',
|
|
151
|
+
tagName: 'p',
|
|
152
|
+
content: 'HTML content'
|
|
153
|
+
};
|
|
154
|
+
const {
|
|
155
|
+
container
|
|
156
|
+
} = (0, _setupTests.renderWithValidation)(/*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
157
|
+
"data-testid": ID,
|
|
158
|
+
component: COMPONENT
|
|
159
|
+
}), {
|
|
160
|
+
hooks
|
|
161
|
+
});
|
|
162
|
+
const p = container.childNodes[0];
|
|
163
|
+
expect(p.tagName).toEqual('P');
|
|
164
|
+
expect(p.textContent).toEqual(COMPONENT.content);
|
|
165
|
+
});
|
|
166
|
+
it('should render a text component appropriately with interpolated label', async () => {
|
|
167
|
+
const ID = 'component';
|
|
168
|
+
const VALUE = 'Text value';
|
|
169
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
170
|
+
const COMPONENT = {
|
|
171
|
+
id: ID,
|
|
172
|
+
fieldId: ID,
|
|
173
|
+
type: 'text',
|
|
174
|
+
label: '${text} Text component',
|
|
175
|
+
cya_label: '${text} Text component',
|
|
176
|
+
hint: 'Text hint'
|
|
177
|
+
};
|
|
178
|
+
const DATA = {
|
|
179
|
+
text: 'Interpolated'
|
|
180
|
+
};
|
|
181
|
+
const ON_CHANGE = () => {};
|
|
182
|
+
const {
|
|
183
|
+
container
|
|
184
|
+
} = (0, _setupTests.renderWithValidation)(/*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
185
|
+
"data-testid": ID,
|
|
186
|
+
component: COMPONENT,
|
|
187
|
+
value: VALUE,
|
|
188
|
+
onChange: ON_CHANGE,
|
|
189
|
+
formData: DATA
|
|
190
|
+
}));
|
|
191
|
+
|
|
192
|
+
// text components are wrapper in a FormGroup by default.
|
|
193
|
+
const formGroup = container.childNodes[0];
|
|
194
|
+
expect(formGroup.tagName).toEqual('DIV');
|
|
195
|
+
expect(formGroup.classList).toContain('govuk-form-group');
|
|
196
|
+
const label = formGroup.childNodes[0];
|
|
197
|
+
expect(label.tagName).toEqual('LABEL');
|
|
198
|
+
expect(label.classList).toContain('govuk-label');
|
|
199
|
+
expect(label.textContent).toEqual('Interpolated Text component (optional)');
|
|
200
|
+
expect(label.getAttribute('for')).toEqual(ID);
|
|
201
|
+
const hint = formGroup.childNodes[1];
|
|
202
|
+
expect(hint.tagName).toEqual('DIV');
|
|
203
|
+
expect(hint.classList).toContain('govuk-hint');
|
|
204
|
+
expect(hint.textContent).toEqual(COMPONENT.hint);
|
|
205
|
+
const input = formGroup.childNodes[2];
|
|
206
|
+
expect(input.tagName).toEqual('INPUT');
|
|
207
|
+
expect(input.classList).toContain('govuk-input');
|
|
208
|
+
expect(input.id).toEqual(ID);
|
|
209
|
+
expect(input.value).toEqual(VALUE);
|
|
210
|
+
});
|
|
211
|
+
it('should correctly handle a component\'s default value when it has no existing value', async () => {
|
|
212
|
+
const ID = 'component';
|
|
213
|
+
const COMPONENT = {
|
|
214
|
+
id: ID,
|
|
215
|
+
fieldId: ID,
|
|
216
|
+
type: 'text',
|
|
217
|
+
label: 'Text component',
|
|
218
|
+
defaultValue: 'default text'
|
|
219
|
+
};
|
|
220
|
+
const DATA = {};
|
|
221
|
+
const ON_CHANGE_ARGS = [];
|
|
222
|
+
let ON_CHANGE_COUNT = 0;
|
|
223
|
+
const ON_CHANGE = _ref => {
|
|
224
|
+
let {
|
|
225
|
+
target
|
|
226
|
+
} = _ref;
|
|
227
|
+
ON_CHANGE_ARGS.push(target);
|
|
228
|
+
ON_CHANGE_COUNT += 1;
|
|
229
|
+
DATA[target.name] = target.value;
|
|
230
|
+
};
|
|
231
|
+
const {
|
|
232
|
+
container,
|
|
233
|
+
rerender
|
|
234
|
+
} = (0, _setupTests.renderWithValidation)(/*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
235
|
+
"data-testid": ID,
|
|
236
|
+
component: COMPONENT,
|
|
237
|
+
value: DATA[ID],
|
|
238
|
+
onChange: ON_CHANGE,
|
|
239
|
+
formData: DATA
|
|
240
|
+
}));
|
|
241
|
+
expect(ON_CHANGE_COUNT).toEqual(1);
|
|
242
|
+
expect(ON_CHANGE_ARGS[0]).toMatchObject({
|
|
243
|
+
name: 'component',
|
|
244
|
+
value: COMPONENT.defaultValue
|
|
245
|
+
});
|
|
246
|
+
const formGroup = container.childNodes[0];
|
|
247
|
+
const input = formGroup.childNodes[2];
|
|
248
|
+
(0, _setupTests.rerenderWithValidation)(rerender, /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
249
|
+
"data-testid": ID,
|
|
250
|
+
component: COMPONENT,
|
|
251
|
+
value: DATA[ID],
|
|
252
|
+
onChange: ON_CHANGE,
|
|
253
|
+
formData: DATA
|
|
254
|
+
}));
|
|
255
|
+
// Input should only be updated once the changes caused
|
|
256
|
+
// by onChange have had another render to propagate down.
|
|
257
|
+
expect(input.value).toEqual(COMPONENT.defaultValue);
|
|
258
|
+
});
|
|
259
|
+
it('should correctly handle a component\'s default value when it has an existing value', async () => {
|
|
260
|
+
const ID = 'component';
|
|
261
|
+
const COMPONENT = {
|
|
262
|
+
id: ID,
|
|
263
|
+
fieldId: ID,
|
|
264
|
+
type: 'text',
|
|
265
|
+
label: 'Text component',
|
|
266
|
+
defaultValue: 'default text'
|
|
267
|
+
};
|
|
268
|
+
const DATA = {
|
|
269
|
+
component: 'existing value'
|
|
270
|
+
};
|
|
271
|
+
const ON_CHANGE_ARGS = [];
|
|
272
|
+
let ON_CHANGE_COUNT = 0;
|
|
273
|
+
const ON_CHANGE = _ref2 => {
|
|
274
|
+
let {
|
|
275
|
+
target
|
|
276
|
+
} = _ref2;
|
|
277
|
+
ON_CHANGE_ARGS.push(target);
|
|
278
|
+
ON_CHANGE_COUNT += 1;
|
|
279
|
+
};
|
|
280
|
+
const {
|
|
281
|
+
container
|
|
282
|
+
} = (0, _setupTests.renderWithValidation)(/*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
283
|
+
"data-testid": ID,
|
|
284
|
+
component: COMPONENT,
|
|
285
|
+
value: DATA[ID],
|
|
286
|
+
onChange: ON_CHANGE,
|
|
287
|
+
formData: DATA
|
|
288
|
+
}));
|
|
289
|
+
expect(ON_CHANGE_COUNT).toEqual(0);
|
|
290
|
+
const formGroup = container.childNodes[0];
|
|
291
|
+
const input = formGroup.childNodes[2];
|
|
292
|
+
expect(input.value).toEqual(DATA[ID]);
|
|
293
|
+
});
|
|
294
|
+
it('should correctly handle a nested file input on change event within a nested container', async () => {
|
|
295
|
+
const ID = 'component';
|
|
296
|
+
const NESTED_CONTAINER_ID = 'nested-container-component';
|
|
297
|
+
const NESTED_ID = 'nested-component';
|
|
298
|
+
const COMPONENT = {
|
|
299
|
+
id: ID,
|
|
300
|
+
fieldId: ID,
|
|
301
|
+
type: _models.ComponentTypes.CHECKBOXES,
|
|
302
|
+
label: 'Checkboxes component',
|
|
303
|
+
data: {
|
|
304
|
+
options: [{
|
|
305
|
+
value: 'EPSILON',
|
|
306
|
+
label: 'Epsilon Label'
|
|
307
|
+
}, {
|
|
308
|
+
value: 'GAMMA',
|
|
309
|
+
label: 'Gamma Label',
|
|
310
|
+
nested: [{
|
|
311
|
+
id: NESTED_CONTAINER_ID,
|
|
312
|
+
fieldId: NESTED_CONTAINER_ID,
|
|
313
|
+
type: _models.ComponentTypes.CONTAINER,
|
|
314
|
+
components: [{
|
|
315
|
+
id: NESTED_ID,
|
|
316
|
+
fieldId: NESTED_ID,
|
|
317
|
+
label: 'File upload',
|
|
318
|
+
type: _models.ComponentTypes.FILE
|
|
319
|
+
}]
|
|
320
|
+
}]
|
|
321
|
+
}]
|
|
422
322
|
}
|
|
423
|
-
}
|
|
424
|
-
|
|
323
|
+
};
|
|
324
|
+
const DATA = {
|
|
325
|
+
component: 'GAMMA'
|
|
326
|
+
};
|
|
327
|
+
const ON_CHANGE_ARGS = [];
|
|
328
|
+
let ON_CHANGE_COUNT = 0;
|
|
329
|
+
const ON_CHANGE = _ref3 => {
|
|
330
|
+
let {
|
|
331
|
+
target
|
|
332
|
+
} = _ref3;
|
|
333
|
+
ON_CHANGE_ARGS.push(target);
|
|
334
|
+
ON_CHANGE_COUNT += 1;
|
|
335
|
+
};
|
|
336
|
+
const {
|
|
337
|
+
container
|
|
338
|
+
} = (0, _setupTests.renderWithValidation)(/*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
339
|
+
"data-testid": ID,
|
|
340
|
+
component: COMPONENT,
|
|
341
|
+
value: DATA[ID],
|
|
342
|
+
onChange: ON_CHANGE,
|
|
343
|
+
formData: DATA
|
|
344
|
+
}));
|
|
345
|
+
|
|
346
|
+
// Get hold of the file input.
|
|
347
|
+
const c = container.childNodes[0];
|
|
348
|
+
const formGroup = c.childNodes[0];
|
|
349
|
+
const fieldSet = formGroup.childNodes[2];
|
|
350
|
+
const input = fieldSet.childNodes[2].childNodes[0].childNodes[0].childNodes[2].childNodes[0];
|
|
351
|
+
const FILE_EXTENSION = 'json';
|
|
352
|
+
const FILE_NAME = "test.".concat(FILE_EXTENSION);
|
|
353
|
+
const FILE_TYPE = 'application/JSON';
|
|
354
|
+
const str = JSON.stringify({
|
|
355
|
+
alpha: 'bravo'
|
|
356
|
+
});
|
|
357
|
+
const blob = new Blob([str]);
|
|
358
|
+
const FILE = new File([blob], FILE_NAME, {
|
|
359
|
+
type: FILE_TYPE
|
|
360
|
+
});
|
|
361
|
+
_userEvent.default.upload(input, FILE);
|
|
362
|
+
expect(ON_CHANGE_COUNT).toEqual(3);
|
|
363
|
+
});
|
|
425
364
|
});
|
|
426
365
|
});
|