@ukhomeoffice/cop-react-form-renderer 6.5.1-peter → 6.7.0-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/CheckYourAnswers/Answer.js +12 -12
- package/dist/components/CheckYourAnswers/Answer.test.js +92 -127
- package/dist/components/CheckYourAnswers/CheckYourAnswers.js +101 -131
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +463 -769
- package/dist/components/CollectionPage/CollectionPage.js +73 -63
- package/dist/components/CollectionPage/CollectionPage.test.js +316 -366
- package/dist/components/CollectionSummary/BannerStrip.js +13 -13
- package/dist/components/CollectionSummary/BannerStrip.test.js +80 -76
- package/dist/components/CollectionSummary/CollectionSummary.js +97 -107
- package/dist/components/CollectionSummary/CollectionSummary.test.js +152 -142
- package/dist/components/CollectionSummary/Confirmation.js +14 -12
- package/dist/components/CollectionSummary/Confirmation.test.js +68 -63
- package/dist/components/CollectionSummary/RenderListView.js +45 -51
- package/dist/components/CollectionSummary/RenderListView.test.js +78 -77
- package/dist/components/CollectionSummary/SummaryCard.js +104 -135
- package/dist/components/CollectionSummary/SummaryCard.test.js +930 -962
- package/dist/components/CollectionSummary/SummaryCardDetails.js +72 -71
- package/dist/components/CollectionSummary/SummaryCardDetails.test.js +128 -135
- package/dist/components/CollectionSummary/SummaryCardValidationContext.js +30 -35
- package/dist/components/CollectionSummary/SummaryCardValidationContext.test.js +62 -74
- package/dist/components/FormComponent/Collection.js +74 -108
- package/dist/components/FormComponent/Collection.test.js +909 -1081
- package/dist/components/FormComponent/Container.js +40 -38
- package/dist/components/FormComponent/Container.test.js +314 -345
- package/dist/components/FormComponent/FormComponent.js +69 -72
- package/dist/components/FormComponent/FormComponent.test.js +353 -414
- package/dist/components/FormComponent/helpers/addLabel.js +4 -7
- package/dist/components/FormComponent/helpers/getComponentDisabled.js +1 -1
- package/dist/components/FormComponent/helpers/getComponentDisabled.test.js +7 -7
- package/dist/components/FormComponent/helpers/getComponentError.js +3 -5
- package/dist/components/FormComponent/helpers/getComponentError.test.js +14 -14
- package/dist/components/FormComponent/helpers/getComponentFieldSet.js +3 -4
- package/dist/components/FormComponent/helpers/getComponentFieldSet.test.js +6 -6
- package/dist/components/FormComponent/helpers/index.js +4 -4
- package/dist/components/FormPage/FormPage.js +65 -80
- package/dist/components/FormPage/FormPage.test.js +127 -163
- package/dist/components/FormRenderer/FormRenderer.js +143 -179
- package/dist/components/FormRenderer/FormRenderer.test.js +730 -1115
- package/dist/components/FormRenderer/handlers/cyaAction.js +2 -2
- package/dist/components/FormRenderer/handlers/getPageId.js +1 -3
- package/dist/components/FormRenderer/handlers/getPageId.test.js +14 -14
- package/dist/components/FormRenderer/handlers/handlers.test.js +32 -32
- package/dist/components/FormRenderer/handlers/index.js +1 -1
- package/dist/components/FormRenderer/handlers/navigate.js +3 -3
- package/dist/components/FormRenderer/handlers/submissionError.js +1 -1
- package/dist/components/FormRenderer/helpers/canActionProceed.js +1 -1
- package/dist/components/FormRenderer/helpers/canActionProceed.test.js +15 -15
- package/dist/components/FormRenderer/helpers/canCYASubmit.js +1 -3
- package/dist/components/FormRenderer/helpers/canCYASubmit.test.js +16 -20
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.js +17 -22
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.test.js +16 -16
- package/dist/components/FormRenderer/helpers/getCYA.js +3 -5
- package/dist/components/FormRenderer/helpers/getCYA.test.js +11 -11
- package/dist/components/FormRenderer/helpers/getFormState.js +5 -7
- package/dist/components/FormRenderer/helpers/getFormState.test.js +10 -10
- package/dist/components/FormRenderer/helpers/getNextPageId.js +13 -24
- package/dist/components/FormRenderer/helpers/getNextPageId.test.js +67 -67
- package/dist/components/FormRenderer/helpers/getPage.js +2 -4
- package/dist/components/FormRenderer/helpers/getPage.test.js +11 -11
- package/dist/components/FormRenderer/helpers/getRelevantPages.js +7 -9
- package/dist/components/FormRenderer/helpers/getRelevantPages.test.js +14 -14
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +5 -5
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +103 -97
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.js +62 -60
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.test.js +71 -78
- package/dist/components/FormRenderer/helpers/index.js +2 -4
- package/dist/components/FormRenderer/onCYAAction.js +59 -51
- package/dist/components/FormRenderer/onCYAAction.test.js +164 -152
- package/dist/components/FormRenderer/onPageAction.js +44 -47
- package/dist/components/FormRenderer/onPageAction.test.js +223 -213
- package/dist/components/FormRenderer/onTaskAction.js +9 -13
- package/dist/components/FormRenderer/onTaskAction.test.js +93 -88
- package/dist/components/PageActions/ActionButton.js +12 -15
- package/dist/components/PageActions/ActionButton.test.js +56 -78
- package/dist/components/PageActions/PageActions.js +10 -10
- package/dist/components/PageActions/PageActions.test.js +86 -115
- package/dist/components/SummaryList/GroupAction.js +9 -17
- package/dist/components/SummaryList/GroupAction.test.js +37 -33
- package/dist/components/SummaryList/RowAction.js +11 -16
- package/dist/components/SummaryList/RowAction.test.js +37 -33
- package/dist/components/SummaryList/SummaryList.js +21 -26
- package/dist/components/SummaryList/SummaryList.test.js +143 -166
- package/dist/components/SummaryList/SummaryListHeadingRow.js +6 -4
- package/dist/components/SummaryList/SummaryListRow.js +6 -4
- package/dist/components/SummaryList/SummaryListTitleRow.js +5 -3
- package/dist/components/SummaryList/helpers/getGroupActionAttributes.js +3 -5
- package/dist/components/SummaryList/helpers/getGroupActionAttributes.test.js +22 -22
- package/dist/components/SummaryList/helpers/getRowActionAttributes.js +3 -5
- package/dist/components/SummaryList/helpers/getRowActionAttributes.test.js +22 -22
- package/dist/components/SummaryList/helpers/index.js +1 -1
- package/dist/components/TaskList/Task.js +19 -29
- package/dist/components/TaskList/Task.test.js +83 -76
- package/dist/components/TaskList/TaskList.js +45 -71
- package/dist/components/TaskList/TaskList.test.js +113 -111
- package/dist/components/TaskList/TaskState.js +7 -5
- package/dist/components/TaskList/TaskState.test.js +52 -45
- package/dist/components/index.js +7 -7
- package/dist/context/HooksContext/HooksContext.js +57 -80
- package/dist/context/HooksContext/HooksContext.test.js +26 -35
- package/dist/context/HooksContext/index.js +3 -4
- package/dist/context/ValidationContext/ValidationContext.js +43 -94
- package/dist/context/ValidationContext/ValidationContext.test.js +56 -68
- package/dist/context/ValidationContext/index.js +3 -4
- package/dist/context/index.js +2 -2
- package/dist/hooks/index.js +9 -10
- package/dist/hooks/useAxios.js +14 -40
- package/dist/hooks/useGetRequest.js +61 -97
- package/dist/hooks/useHooks.js +1 -3
- package/dist/hooks/useRefData.js +26 -39
- package/dist/hooks/useValidation.js +1 -3
- package/dist/index.js +13 -14
- package/dist/models/CollectionLabels.js +1 -1
- package/dist/models/ComponentTypes.js +25 -25
- package/dist/models/EventTypes.js +4 -4
- package/dist/models/FormPages.js +4 -4
- package/dist/models/FormTypes.js +8 -8
- package/dist/models/HubFormats.js +3 -3
- package/dist/models/PageAction.js +44 -38
- package/dist/models/TaskStates.js +29 -28
- package/dist/models/index.js +9 -9
- package/dist/setupTests.js +30 -31
- package/dist/utils/CheckYourAnswers/getCYAAction.js +5 -5
- package/dist/utils/CheckYourAnswers/getCYAAction.test.js +52 -54
- package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.js +15 -25
- package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.test.js +33 -35
- package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.js +17 -31
- package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.test.js +42 -44
- package/dist/utils/CheckYourAnswers/getCYARow.js +6 -6
- package/dist/utils/CheckYourAnswers/getCYARow.test.js +86 -86
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.js +18 -24
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.test.js +15 -16
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.js +33 -36
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.test.js +58 -61
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +83 -89
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +164 -138
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.js +25 -20
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.test.js +103 -97
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +13 -18
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.test.js +70 -76
- package/dist/utils/CheckYourAnswers/getComponentRowForCYA.js +11 -11
- package/dist/utils/CheckYourAnswers/getComponentRowForCYA.test.js +7 -7
- package/dist/utils/CheckYourAnswers/index.js +1 -1
- package/dist/utils/CheckYourAnswers/showComponentCYA.js +4 -4
- package/dist/utils/CheckYourAnswers/showComponentCYA.test.js +25 -25
- package/dist/utils/CollectionPage/addCollectionPageEntry.js +2 -2
- package/dist/utils/CollectionPage/addCollectionPageEntry.test.js +5 -5
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.js +2 -2
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.test.js +17 -18
- package/dist/utils/CollectionPage/duplicateCollectionPageEntry.js +18 -20
- package/dist/utils/CollectionPage/duplicateCollectionPageEntry.test.js +55 -26
- package/dist/utils/CollectionPage/getCollectionPageActiveId.js +2 -2
- package/dist/utils/CollectionPage/getCollectionPageActiveId.test.js +10 -10
- package/dist/utils/CollectionPage/getCollectionPageActiveIndex.js +7 -11
- package/dist/utils/CollectionPage/getCollectionPageActiveIndex.test.js +22 -22
- package/dist/utils/CollectionPage/getCollectionPageData.js +8 -12
- package/dist/utils/CollectionPage/getCollectionPageData.test.js +19 -19
- package/dist/utils/CollectionPage/getErrorsForCollection.js +24 -24
- package/dist/utils/CollectionPage/getErrorsForCollection.test.js +20 -22
- package/dist/utils/CollectionPage/getQuickEditPage.js +36 -28
- package/dist/utils/CollectionPage/getQuickEditPage.test.js +26 -45
- package/dist/utils/CollectionPage/index.js +1 -1
- package/dist/utils/CollectionPage/mergeCollectionPages.js +31 -35
- package/dist/utils/CollectionPage/mergeCollectionPages.test.js +20 -20
- package/dist/utils/CollectionPage/removeCollectionPageEntry.js +4 -6
- package/dist/utils/CollectionPage/removeCollectionPageEntry.test.js +10 -10
- package/dist/utils/CollectionPage/setCollectionPageData.js +10 -16
- package/dist/utils/CollectionPage/setCollectionPageData.test.js +24 -24
- package/dist/utils/Component/addShowWhen.js +4 -8
- package/dist/utils/Component/addShowWhen.test.js +37 -37
- package/dist/utils/Component/applyToComponentTree.js +18 -18
- package/dist/utils/Component/applyToComponentTree.test.js +27 -32
- package/dist/utils/Component/cleanAttributes.js +10 -13
- package/dist/utils/Component/cleanAttributes.test.js +17 -18
- package/dist/utils/Component/elevateNestedComponents.js +5 -5
- package/dist/utils/Component/elevateNestedComponents.test.js +30 -30
- package/dist/utils/Component/getComponent.js +88 -94
- package/dist/utils/Component/getComponentTests/getComponent.autocomplete.test.js +18 -17
- package/dist/utils/Component/getComponentTests/getComponent.calculation.test.js +46 -59
- package/dist/utils/Component/getComponentTests/getComponent.checkboxes.test.js +39 -48
- package/dist/utils/Component/getComponentTests/getComponent.date.test.js +23 -33
- package/dist/utils/Component/getComponentTests/getComponent.details.test.js +20 -18
- package/dist/utils/Component/getComponentTests/getComponent.email.test.js +17 -22
- package/dist/utils/Component/getComponentTests/getComponent.file.test.js +20 -25
- package/dist/utils/Component/getComponentTests/getComponent.heading.test.js +10 -9
- package/dist/utils/Component/getComponentTests/getComponent.html.test.js +17 -15
- package/dist/utils/Component/getComponentTests/getComponent.insetText.test.js +9 -8
- package/dist/utils/Component/getComponentTests/getComponent.list.test.js +17 -15
- package/dist/utils/Component/getComponentTests/getComponent.multifile.test.js +22 -26
- package/dist/utils/Component/getComponentTests/getComponent.nested.test.js +155 -175
- package/dist/utils/Component/getComponentTests/getComponent.paragraph.test.js +17 -15
- package/dist/utils/Component/getComponentTests/getComponent.phoneNumber.test.js +17 -22
- package/dist/utils/Component/getComponentTests/getComponent.radios.test.js +57 -72
- package/dist/utils/Component/getComponentTests/getComponent.select.test.js +17 -22
- package/dist/utils/Component/getComponentTests/getComponent.text.test.js +17 -22
- package/dist/utils/Component/getComponentTests/getComponent.textArea.test.js +31 -38
- package/dist/utils/Component/getComponentTests/getComponent.time.test.js +20 -29
- package/dist/utils/Component/getComponentTests/getComponent.unknown.test.js +2 -2
- package/dist/utils/Component/getComponentTests/getComponent.warningText.test.js +9 -8
- package/dist/utils/Component/getDefaultValue.js +6 -8
- package/dist/utils/Component/getDefaultValue.test.js +12 -12
- package/dist/utils/Component/getDefaultValueFromConfig.js +22 -21
- package/dist/utils/Component/getDefaultValueFromConfig.test.js +31 -31
- package/dist/utils/Component/index.js +1 -1
- package/dist/utils/Component/isEditable.js +2 -4
- package/dist/utils/Component/isEditable.test.js +14 -15
- package/dist/utils/Component/optionIsSelected.js +1 -1
- package/dist/utils/Component/optionIsSelected.test.js +9 -9
- package/dist/utils/Component/setupContainerComponentsPath.js +27 -29
- package/dist/utils/Component/setupContainerComponentsPath.test.js +11 -11
- package/dist/utils/Component/showComponent.js +1 -1
- package/dist/utils/Component/showComponent.test.js +28 -28
- package/dist/utils/Component/wrapInFormGroup.js +2 -2
- package/dist/utils/Condition/index.js +1 -1
- package/dist/utils/Condition/meetsAllConditions.js +8 -8
- package/dist/utils/Condition/meetsAllConditions.test.js +20 -20
- package/dist/utils/Condition/meetsCondition.js +16 -25
- package/dist/utils/Condition/meetsCondition.test.js +402 -402
- package/dist/utils/Condition/meetsOneCondition.js +5 -5
- package/dist/utils/Condition/meetsOneCondition.test.js +16 -16
- package/dist/utils/Condition/setupConditions.js +13 -18
- package/dist/utils/Condition/setupConditions.test.js +7 -7
- package/dist/utils/Container/getEditableComponents.js +3 -5
- package/dist/utils/Container/getEditableComponents.test.js +43 -45
- package/dist/utils/Container/index.js +1 -1
- package/dist/utils/Container/setupNesting.js +16 -20
- package/dist/utils/Container/setupNesting.test.js +27 -30
- package/dist/utils/Container/showContainer.js +3 -7
- package/dist/utils/Container/showContainer.test.js +30 -30
- package/dist/utils/Data/applyFormula.js +38 -48
- package/dist/utils/Data/applyFormula.test.js +20 -20
- package/dist/utils/Data/getAutocompleteSource.js +18 -26
- package/dist/utils/Data/getAutocompleteSource.test.js +80 -86
- package/dist/utils/Data/getDataPath.js +18 -28
- package/dist/utils/Data/getDataPath.test.js +12 -12
- package/dist/utils/Data/getOptions.js +24 -30
- package/dist/utils/Data/getOptions.test.js +27 -27
- package/dist/utils/Data/getSourceData.js +6 -19
- package/dist/utils/Data/getSourceData.test.js +84 -80
- package/dist/utils/Data/index.js +1 -1
- package/dist/utils/Data/nestInRefdataOptions.js +9 -16
- package/dist/utils/Data/nestInRefdataOptions.test.js +16 -16
- package/dist/utils/Data/refDataToOptions.js +10 -13
- package/dist/utils/Data/refDataToOptions.test.js +19 -19
- package/dist/utils/Data/setDataItem.js +7 -8
- package/dist/utils/Data/setDataItem.test.js +37 -37
- package/dist/utils/Data/setupFormData.js +13 -21
- package/dist/utils/Data/setupFormData.test.js +51 -50
- package/dist/utils/Data/setupRefDataUrlForComponent.js +20 -26
- package/dist/utils/Data/setupRefDataUrlForComponent.test.js +24 -24
- package/dist/utils/FormPage/applyConditionalProperties.js +5 -9
- package/dist/utils/FormPage/applyConditionalProperties.test.js +15 -18
- package/dist/utils/FormPage/getConditionalText.js +3 -3
- package/dist/utils/FormPage/getConditionalText.test.js +29 -29
- package/dist/utils/FormPage/getFormPage.js +15 -16
- package/dist/utils/FormPage/getFormPage.test.js +47 -46
- package/dist/utils/FormPage/getFormPages.js +7 -12
- package/dist/utils/FormPage/getFormPages.test.js +20 -23
- package/dist/utils/FormPage/getPageActions.js +9 -15
- package/dist/utils/FormPage/getPageActions.test.js +32 -32
- package/dist/utils/FormPage/getParagraphFromText.js +5 -7
- package/dist/utils/FormPage/getParagraphFromText.test.js +6 -6
- package/dist/utils/FormPage/index.js +2 -4
- package/dist/utils/FormPage/showFormPage.js +3 -7
- package/dist/utils/FormPage/showFormPage.test.js +32 -32
- package/dist/utils/FormPage/showFormPageCYA.js +1 -1
- package/dist/utils/FormPage/showFormPageCYA.test.js +8 -8
- package/dist/utils/FormPage/useComponent.js +21 -28
- package/dist/utils/FormPage/useComponent.test.js +77 -79
- package/dist/utils/Format/formatData.js +1 -1
- package/dist/utils/Format/formatData.test.js +18 -18
- package/dist/utils/Format/formatDataForComponent.js +5 -6
- package/dist/utils/Format/formatDataForComponent.test.js +50 -78
- package/dist/utils/Format/formatDataForForm.js +6 -8
- package/dist/utils/Format/formatDataForForm.test.js +13 -16
- package/dist/utils/Format/formatDataForPage.js +4 -5
- package/dist/utils/Format/formatDataForPage.test.js +20 -25
- package/dist/utils/Format/index.js +1 -1
- package/dist/utils/Hub/getFormHub.js +1 -1
- package/dist/utils/Hub/getFormHub.test.js +28 -31
- package/dist/utils/Hub/index.js +1 -1
- package/dist/utils/Meta/constants.js +2 -2
- package/dist/utils/Meta/documents/getDocuments.js +1 -1
- package/dist/utils/Meta/documents/getDocuments.test.js +24 -16
- package/dist/utils/Meta/documents/index.js +1 -1
- package/dist/utils/Meta/documents/setDocumentsForField.js +14 -16
- package/dist/utils/Meta/documents/setDocumentsForField.test.js +68 -34
- package/dist/utils/Meta/index.js +1 -1
- package/dist/utils/Operate/checkValueIsTruthy.js +2 -2
- package/dist/utils/Operate/checkValueIsTruthy.test.js +16 -16
- package/dist/utils/Operate/getFirstOf.js +5 -5
- package/dist/utils/Operate/getFirstOf.test.js +31 -31
- package/dist/utils/Operate/getIndexOfMatchingValueIn.js +10 -10
- package/dist/utils/Operate/getIndexOfMatchingValueIn.test.js +46 -52
- package/dist/utils/Operate/index.js +1 -1
- package/dist/utils/Operate/persistValueInFormData.js +3 -3
- package/dist/utils/Operate/persistValueInFormData.test.js +22 -20
- package/dist/utils/Operate/runPageOperations.js +7 -7
- package/dist/utils/Operate/runPageOperations.test.js +35 -36
- package/dist/utils/Operate/setValueInFormData.js +2 -2
- package/dist/utils/Operate/setValueInFormData.test.js +16 -16
- package/dist/utils/Operate/shouldRun.js +6 -6
- package/dist/utils/Operate/shouldRun.test.js +21 -27
- package/dist/utils/Validate/additional/conditionallyRequired.js +4 -4
- package/dist/utils/Validate/additional/conditionallyRequired.test.js +18 -18
- package/dist/utils/Validate/additional/index.js +6 -6
- package/dist/utils/Validate/additional/index.test.js +12 -12
- package/dist/utils/Validate/additional/mustBeAfter.js +2 -2
- package/dist/utils/Validate/additional/mustBeAfter.test.js +40 -40
- package/dist/utils/Validate/additional/mustBeBefore.js +2 -2
- package/dist/utils/Validate/additional/mustBeBefore.test.js +28 -28
- package/dist/utils/Validate/additional/mustBeEarlierDateTime.js +7 -11
- package/dist/utils/Validate/additional/mustBeEarlierDateTime.test.js +37 -41
- package/dist/utils/Validate/additional/mustBeGreaterThan.js +2 -2
- package/dist/utils/Validate/additional/mustBeGreaterThan.test.js +18 -18
- package/dist/utils/Validate/additional/mustBeInTheFuture.js +2 -2
- package/dist/utils/Validate/additional/mustBeInTheFuture.test.js +12 -12
- package/dist/utils/Validate/additional/mustBeInThePast.js +3 -3
- package/dist/utils/Validate/additional/mustBeInThePast.test.js +12 -12
- package/dist/utils/Validate/additional/mustBeLessThan.js +2 -2
- package/dist/utils/Validate/additional/mustBeLessThan.test.js +17 -17
- package/dist/utils/Validate/additional/mustBeLongerThan.js +1 -1
- package/dist/utils/Validate/additional/mustBeLongerThan.test.js +16 -16
- package/dist/utils/Validate/additional/mustBeNumbersOnly.js +2 -2
- package/dist/utils/Validate/additional/mustBeNumbersOnly.test.js +20 -20
- package/dist/utils/Validate/additional/mustBeShorterThan.js +1 -1
- package/dist/utils/Validate/additional/mustBeShorterThan.test.js +16 -16
- package/dist/utils/Validate/additional/mustBeUniqueInCollection.js +8 -4
- package/dist/utils/Validate/additional/mustBeUniqueInCollection.test.js +64 -32
- package/dist/utils/Validate/additional/mustEnterAtLeastOne.js +2 -2
- package/dist/utils/Validate/additional/mustEnterAtLeastOne.test.js +14 -16
- package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.js +1 -1
- package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.test.js +12 -12
- package/dist/utils/Validate/additional/mustNotContainSql.js +3 -4
- package/dist/utils/Validate/additional/mustNotContainSql.test.js +14 -14
- package/dist/utils/Validate/additional/mustSelectOnlyOne.js +2 -2
- package/dist/utils/Validate/additional/mustSelectOnlyOne.test.js +28 -26
- package/dist/utils/Validate/additional/utils.js +9 -22
- package/dist/utils/Validate/index.js +1 -1
- package/dist/utils/Validate/validateCollection.js +19 -25
- package/dist/utils/Validate/validateCollection.test.js +74 -66
- package/dist/utils/Validate/validateComponent.js +17 -15
- package/dist/utils/Validate/validateComponent.test.js +167 -146
- package/dist/utils/Validate/validateContainer.js +15 -20
- package/dist/utils/Validate/validateContainer.test.js +58 -52
- package/dist/utils/Validate/validateDate.js +15 -21
- package/dist/utils/Validate/validateDate.test.js +31 -32
- package/dist/utils/Validate/validateEmail.js +6 -8
- package/dist/utils/Validate/validateEmail.test.js +25 -25
- package/dist/utils/Validate/validateMultifile.js +5 -7
- package/dist/utils/Validate/validateMultifile.test.js +17 -18
- package/dist/utils/Validate/validatePage.js +19 -22
- package/dist/utils/Validate/validatePage.test.js +215 -203
- package/dist/utils/Validate/validateRegex.js +3 -5
- package/dist/utils/Validate/validateRegex.test.js +14 -14
- package/dist/utils/Validate/validateRequired.js +4 -6
- package/dist/utils/Validate/validateRequired.test.js +18 -18
- package/dist/utils/Validate/validateTextArea.js +4 -6
- package/dist/utils/Validate/validateTextArea.test.js +20 -20
- package/dist/utils/Validate/validateTime.js +11 -18
- package/dist/utils/Validate/validateTime.test.js +16 -16
- package/dist/utils/index.js +7 -9
- package/package.json +2 -2
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/component-used-in-multiple-pages-data.json +0 -4
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/component-used-in-multiple-pages-form.json +0 -61
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/cop-airpax-after.json +0 -429
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/cop-airpax-before.json +0 -449
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/cop-airpax-form.json +0 -15219
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/cop-eab-2-data-after.json +0 -516
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/cop-eab-2-data-before.json +0 -593
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/cop-eab2-form.json +0 -15219
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/cop-mandec-data-after.json +0 -84
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/cop-mandec-data-before.json +0 -98
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/cop-mandec-form.json +0 -9158
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/data-with-collection-data-removed.json +0 -4
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/data-with-collections.json +0 -8
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/data-with-components-removed.json +0 -3
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/data-with-components.json +0 -5
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/data-with-entire-collection-removed.json +0 -3
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/data-with-nested-component-removed.json +0 -10
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/data-with-nested-components.json +0 -11
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/form-for-nested-components.json +0 -96
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/form-with-collections-delete-entire.json +0 -47
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/form-with-collections.json +0 -46
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/form-with-components.json +0 -48
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/test.json +0 -1605
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/test2.json +0 -205
- package/dist/components/FormRenderer/helpers/clearOutUncompletedRoutes.js +0 -206
- package/dist/components/FormRenderer/helpers/clearOutUncompletedRoutes.test.js +0 -143
- package/dist/components/FormRenderer/helpers/deleteNodeByPath.js +0 -26
- package/dist/components/FormRenderer/helpers/deleteNodeByPath.test.js +0 -56
|
@@ -10,1096 +10,924 @@ var _Collection = require("./Collection");
|
|
|
10
10
|
var _Container = require("./Container");
|
|
11
11
|
var _FormComponent = _interopRequireDefault(require("./FormComponent"));
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
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; }
|
|
16
|
-
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
17
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
18
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
19
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
20
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
21
|
-
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
22
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
23
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
24
|
-
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); }); }; }
|
|
25
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
26
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
27
|
-
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); } // Global imports
|
|
13
|
+
// Global imports
|
|
14
|
+
|
|
28
15
|
// Local imports
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
16
|
+
|
|
17
|
+
describe('components.FormComponent.Collection', () => {
|
|
18
|
+
const ID = 'collection';
|
|
19
|
+
const TEXT_ID = 'text';
|
|
20
|
+
const TEXT_VALUE = 'alpha';
|
|
21
|
+
const FORM_DATA = {
|
|
22
|
+
[ID]: [{
|
|
23
|
+
id: '1',
|
|
24
|
+
[TEXT_ID]: TEXT_VALUE
|
|
25
|
+
}]
|
|
26
|
+
};
|
|
27
|
+
const TEXT_COMPONENT = {
|
|
37
28
|
id: TEXT_ID,
|
|
38
29
|
fieldId: TEXT_ID,
|
|
39
30
|
type: _models.ComponentTypes.TEXT,
|
|
40
31
|
label: 'Text component',
|
|
41
32
|
hint: 'Text hint'
|
|
42
33
|
};
|
|
43
|
-
it('should render a collection component appropriately',
|
|
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
|
-
NEW_TEXT_VALUE = 'bravo';
|
|
126
|
-
EVENT = {
|
|
127
|
-
target: {
|
|
128
|
-
name: TEXT_ID,
|
|
129
|
-
value: NEW_TEXT_VALUE
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
_react.fireEvent.change(input, EVENT);
|
|
133
|
-
|
|
134
|
-
// And confirm the formData has been changed.
|
|
135
|
-
expect(ON_CHANGE_EVENTS.length).toEqual(1);
|
|
136
|
-
expect(ON_CHANGE_EVENTS[0].target.name).toEqual(ID);
|
|
137
|
-
expect(ON_CHANGE_EVENTS[0].target.value[0][TEXT_ID]).toEqual(NEW_TEXT_VALUE);
|
|
138
|
-
case 14:
|
|
139
|
-
case "end":
|
|
140
|
-
return _context2.stop();
|
|
141
|
-
}
|
|
142
|
-
}, _callee2);
|
|
143
|
-
})));
|
|
144
|
-
it('should handle a null value appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
145
|
-
var COLLECTION, _renderWithValidation3, container, c, buttonGroup, button;
|
|
146
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
147
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
148
|
-
case 0:
|
|
149
|
-
COLLECTION = {
|
|
150
|
-
id: ID,
|
|
151
|
-
fieldId: ID,
|
|
152
|
-
type: _models.ComponentTypes.COLLECTION,
|
|
153
|
-
item: [TEXT_COMPONENT]
|
|
154
|
-
};
|
|
155
|
-
_renderWithValidation3 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
156
|
-
component: COLLECTION
|
|
157
|
-
})), container = _renderWithValidation3.container; // Check the container itself.
|
|
158
|
-
c = container.childNodes[0];
|
|
159
|
-
expect(c.tagName).toEqual('DIV');
|
|
160
|
-
expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
|
|
161
|
-
|
|
162
|
-
// And now make sure it has no children OTHER than the button to add an item.
|
|
163
|
-
expect(c.childNodes.length).toEqual(1);
|
|
164
|
-
buttonGroup = c.childNodes[0];
|
|
165
|
-
expect(buttonGroup.tagName).toEqual('DIV');
|
|
166
|
-
expect(buttonGroup.classList).toContain('hods-button-group');
|
|
167
|
-
button = buttonGroup.childNodes[0];
|
|
168
|
-
expect(button.tagName).toEqual('BUTTON');
|
|
169
|
-
expect(button.classList).toContain('hods-button');
|
|
170
|
-
expect(button.classList).toContain('hods-button--secondary');
|
|
171
|
-
expect(button.textContent).toContain(_models.CollectionLabels.add);
|
|
172
|
-
case 14:
|
|
173
|
-
case "end":
|
|
174
|
-
return _context3.stop();
|
|
175
|
-
}
|
|
176
|
-
}, _callee3);
|
|
177
|
-
})));
|
|
178
|
-
it('should handle a collection label appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
179
|
-
var LABEL, COLLECTION, _renderWithValidation4, container, c, _c$childNodes, title, buttonGroup, button;
|
|
180
|
-
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
181
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
182
|
-
case 0:
|
|
183
|
-
LABEL = 'Alpha Collection';
|
|
184
|
-
COLLECTION = {
|
|
185
|
-
id: ID,
|
|
186
|
-
fieldId: ID,
|
|
187
|
-
type: _models.ComponentTypes.COLLECTION,
|
|
188
|
-
item: [TEXT_COMPONENT],
|
|
189
|
-
label: LABEL
|
|
190
|
-
};
|
|
191
|
-
_renderWithValidation4 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
192
|
-
component: COLLECTION
|
|
193
|
-
})), container = _renderWithValidation4.container; // Check the container itself.
|
|
194
|
-
c = container.childNodes[0];
|
|
195
|
-
expect(c.tagName).toEqual('DIV');
|
|
196
|
-
expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
|
|
197
|
-
|
|
198
|
-
// And now make sure it has no children OTHER than the button to add an item.
|
|
199
|
-
expect(c.childNodes.length).toEqual(2);
|
|
200
|
-
_c$childNodes = _slicedToArray(c.childNodes, 2), title = _c$childNodes[0], buttonGroup = _c$childNodes[1];
|
|
201
|
-
expect(title.tagName).toEqual('LABEL');
|
|
202
|
-
expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__title"));
|
|
203
|
-
expect(title.getAttribute('for')).toEqual(ID);
|
|
204
|
-
expect(title.textContent).toContain(LABEL);
|
|
205
|
-
expect(buttonGroup.tagName).toEqual('DIV');
|
|
206
|
-
expect(buttonGroup.classList).toContain('hods-button-group');
|
|
207
|
-
button = buttonGroup.childNodes[0];
|
|
208
|
-
expect(button.tagName).toEqual('BUTTON');
|
|
209
|
-
expect(button.classList).toContain('hods-button');
|
|
210
|
-
expect(button.classList).toContain('hods-button--secondary');
|
|
211
|
-
expect(button.textContent).toContain(_models.CollectionLabels.add);
|
|
212
|
-
case 19:
|
|
213
|
-
case "end":
|
|
214
|
-
return _context4.stop();
|
|
215
|
-
}
|
|
216
|
-
}, _callee4);
|
|
217
|
-
})));
|
|
218
|
-
it('should handle the addition and removal of an item', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
219
|
-
var COLLECTION, container, c, addButton, item, label, removeButton;
|
|
220
|
-
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
221
|
-
while (1) switch (_context6.prev = _context6.next) {
|
|
222
|
-
case 0:
|
|
223
|
-
COLLECTION = {
|
|
224
|
-
id: ID,
|
|
225
|
-
fieldId: ID,
|
|
226
|
-
type: _models.ComponentTypes.COLLECTION,
|
|
227
|
-
item: [TEXT_COMPONENT]
|
|
228
|
-
};
|
|
229
|
-
container = document.createElement('div');
|
|
230
|
-
document.body.appendChild(container);
|
|
231
|
-
_context6.next = 5;
|
|
232
|
-
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
233
|
-
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
234
|
-
while (1) switch (_context5.prev = _context5.next) {
|
|
235
|
-
case 0:
|
|
236
|
-
(0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
237
|
-
component: COLLECTION
|
|
238
|
-
}), container);
|
|
239
|
-
case 1:
|
|
240
|
-
case "end":
|
|
241
|
-
return _context5.stop();
|
|
242
|
-
}
|
|
243
|
-
}, _callee5);
|
|
244
|
-
})));
|
|
245
|
-
case 5:
|
|
246
|
-
// Check the container itself.
|
|
247
|
-
c = container.childNodes[0];
|
|
248
|
-
expect(c.tagName).toEqual('DIV');
|
|
249
|
-
expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
|
|
250
|
-
|
|
251
|
-
// And now make sure it has no children OTHER than the button to add an item.
|
|
252
|
-
expect(c.childNodes.length).toEqual(1);
|
|
253
|
-
|
|
254
|
-
// Get hold of that "Add another" button and click it.
|
|
255
|
-
addButton = c.childNodes[0].childNodes[0];
|
|
256
|
-
_react.fireEvent.click(addButton, {});
|
|
257
|
-
|
|
258
|
-
// Make sure an item has been added.
|
|
259
|
-
expect(c.childNodes.length).toEqual(2);
|
|
260
|
-
item = c.childNodes[0];
|
|
261
|
-
label = item.childNodes[0];
|
|
262
|
-
expect(label.textContent).toContain(_utils.default.interpolateString(_models.CollectionLabels.item, {
|
|
263
|
-
index: 1
|
|
264
|
-
}));
|
|
265
|
-
|
|
266
|
-
// Get hold of the newly-add item's "Remove" button.
|
|
267
|
-
removeButton = label.childNodes[1];
|
|
268
|
-
expect(removeButton.tagName).toEqual('BUTTON');
|
|
269
|
-
expect(removeButton.classList).toContain('hods-button--secondary');
|
|
270
|
-
expect(removeButton.textContent).toContain(_models.CollectionLabels.remove);
|
|
271
|
-
|
|
272
|
-
// Click the "Remove" button
|
|
273
|
-
_react.fireEvent.click(removeButton, {});
|
|
274
|
-
|
|
275
|
-
// Make sure the item has been removed.
|
|
276
|
-
expect(c.childNodes.length).toEqual(1);
|
|
277
|
-
expect(c.childNodes[0].classList).toContain('hods-button-group');
|
|
278
|
-
case 22:
|
|
279
|
-
case "end":
|
|
280
|
-
return _context6.stop();
|
|
281
|
-
}
|
|
282
|
-
}, _callee6);
|
|
283
|
-
})));
|
|
284
|
-
it('should handle the alternative styling', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
|
285
|
-
var COLLECTION, container, c, addButton, item, label, removeButton;
|
|
286
|
-
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
287
|
-
while (1) switch (_context8.prev = _context8.next) {
|
|
288
|
-
case 0:
|
|
289
|
-
COLLECTION = {
|
|
290
|
-
id: ID,
|
|
291
|
-
fieldId: ID,
|
|
292
|
-
type: _models.ComponentTypes.COLLECTION,
|
|
293
|
-
item: [TEXT_COMPONENT],
|
|
294
|
-
removeLocation: 'end'
|
|
295
|
-
};
|
|
296
|
-
container = document.createElement('div');
|
|
297
|
-
document.body.appendChild(container);
|
|
298
|
-
_context8.next = 5;
|
|
299
|
-
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
300
|
-
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
301
|
-
while (1) switch (_context7.prev = _context7.next) {
|
|
302
|
-
case 0:
|
|
303
|
-
(0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
304
|
-
component: COLLECTION
|
|
305
|
-
}), container);
|
|
306
|
-
case 1:
|
|
307
|
-
case "end":
|
|
308
|
-
return _context7.stop();
|
|
309
|
-
}
|
|
310
|
-
}, _callee7);
|
|
311
|
-
})));
|
|
312
|
-
case 5:
|
|
313
|
-
// Check the container itself.
|
|
314
|
-
c = container.childNodes[0];
|
|
315
|
-
expect(c.tagName).toEqual('DIV');
|
|
316
|
-
expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
|
|
317
|
-
|
|
318
|
-
// And now make sure it has no children OTHER than the button to add an item.
|
|
319
|
-
expect(c.childNodes.length).toEqual(1);
|
|
320
|
-
|
|
321
|
-
// Get hold of that "Add another" button and click it.
|
|
322
|
-
addButton = c.childNodes[0].childNodes[0];
|
|
323
|
-
_react.fireEvent.click(addButton, {});
|
|
324
|
-
|
|
325
|
-
// Make sure an item has been added.
|
|
326
|
-
expect(c.childNodes.length).toEqual(2);
|
|
327
|
-
item = c.childNodes[0];
|
|
328
|
-
label = item.childNodes[0];
|
|
329
|
-
expect(label.textContent).toContain(_utils.default.interpolateString(_models.CollectionLabels.item, {
|
|
330
|
-
index: 1
|
|
331
|
-
}));
|
|
332
|
-
|
|
333
|
-
// Get hold of the newly-add item's "Remove" button.
|
|
334
|
-
removeButton = item.childNodes[2].childNodes[0];
|
|
335
|
-
expect(removeButton.tagName).toEqual('BUTTON');
|
|
336
|
-
expect(removeButton.classList).toContain('hods-button--secondary');
|
|
337
|
-
expect(removeButton.textContent).toContain(_models.CollectionLabels.remove);
|
|
338
|
-
|
|
339
|
-
// Click the "Remove" button
|
|
340
|
-
_react.fireEvent.click(removeButton, {});
|
|
341
|
-
|
|
342
|
-
// Make sure the item has been removed.
|
|
343
|
-
expect(c.childNodes.length).toEqual(1);
|
|
344
|
-
expect(c.childNodes[0].classList).toContain('hods-button-group');
|
|
345
|
-
case 22:
|
|
346
|
-
case "end":
|
|
347
|
-
return _context8.stop();
|
|
348
|
-
}
|
|
349
|
-
}, _callee8);
|
|
350
|
-
})));
|
|
351
|
-
it('should appropriately make child components of items readonly', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
|
|
352
|
-
var COLLECTION, _renderWithValidation5, container, c, item, _item$childNodes2, title, itemContainer, formGroup, label, hint, input;
|
|
353
|
-
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
354
|
-
while (1) switch (_context9.prev = _context9.next) {
|
|
355
|
-
case 0:
|
|
356
|
-
COLLECTION = {
|
|
357
|
-
id: ID,
|
|
358
|
-
fieldId: ID,
|
|
359
|
-
type: _models.ComponentTypes.COLLECTION,
|
|
360
|
-
item: [TEXT_COMPONENT],
|
|
361
|
-
readonly: true
|
|
362
|
-
};
|
|
363
|
-
_renderWithValidation5 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
364
|
-
component: COLLECTION,
|
|
365
|
-
value: FORM_DATA[ID],
|
|
366
|
-
formData: FORM_DATA
|
|
367
|
-
})), container = _renderWithValidation5.container; // Check the container itself.
|
|
368
|
-
c = container.childNodes[0];
|
|
369
|
-
expect(c.tagName).toEqual('DIV');
|
|
370
|
-
expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
|
|
371
|
-
|
|
372
|
-
// And now check the single text component within it.
|
|
373
|
-
item = c.childNodes[0];
|
|
374
|
-
expect(item.tagName).toEqual('DIV');
|
|
375
|
-
expect(item.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
|
|
376
|
-
_item$childNodes2 = _slicedToArray(item.childNodes, 2), title = _item$childNodes2[0], itemContainer = _item$childNodes2[1];
|
|
377
|
-
expect(title.tagName).toEqual('LABEL');
|
|
378
|
-
expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
|
|
379
|
-
expect(itemContainer.tagName).toEqual('DIV');
|
|
380
|
-
expect(itemContainer.classList).toContain(_Container.DEFAULT_CLASS);
|
|
381
|
-
formGroup = itemContainer.childNodes[0];
|
|
382
|
-
expect(formGroup.tagName).toEqual('DIV');
|
|
383
|
-
expect(formGroup.classList).toContain('govuk-form-group');
|
|
384
|
-
label = formGroup.childNodes[0];
|
|
385
|
-
expect(label.tagName).toEqual('LABEL');
|
|
386
|
-
expect(label.classList).toContain('govuk-label');
|
|
387
|
-
expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
388
|
-
expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
389
|
-
hint = formGroup.childNodes[1];
|
|
390
|
-
expect(hint.tagName).toEqual('DIV');
|
|
391
|
-
expect(hint.classList).toContain('govuk-hint');
|
|
392
|
-
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
393
|
-
input = formGroup.childNodes[2];
|
|
394
|
-
expect(input.tagName).toEqual('DIV'); // Now readonly, so a DIV.
|
|
395
|
-
expect(input.classList).toContain('hods-readonly'); // Now readonly, so hods-readonly
|
|
396
|
-
expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
397
|
-
expect(input.textContent).toEqual(TEXT_VALUE);
|
|
398
|
-
case 30:
|
|
399
|
-
case "end":
|
|
400
|
-
return _context9.stop();
|
|
401
|
-
}
|
|
402
|
-
}, _callee9);
|
|
403
|
-
})));
|
|
404
|
-
it('should render a collection component with minimumEntries appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
|
|
405
|
-
var COLLECTION, _renderWithValidation6, container, c, item, _item$childNodes3, title, itemContainer, formGroup, label, hint, input;
|
|
406
|
-
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
407
|
-
while (1) switch (_context10.prev = _context10.next) {
|
|
408
|
-
case 0:
|
|
409
|
-
COLLECTION = {
|
|
410
|
-
id: ID,
|
|
411
|
-
fieldId: ID,
|
|
412
|
-
type: _models.ComponentTypes.COLLECTION,
|
|
413
|
-
item: [TEXT_COMPONENT],
|
|
414
|
-
minimumEntries: 1
|
|
415
|
-
};
|
|
416
|
-
_renderWithValidation6 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
417
|
-
component: COLLECTION,
|
|
418
|
-
value: [],
|
|
419
|
-
formData: {}
|
|
420
|
-
})), container = _renderWithValidation6.container; // Check the container itself.
|
|
421
|
-
c = container.childNodes[0];
|
|
422
|
-
expect(c.tagName).toEqual('DIV');
|
|
423
|
-
expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
|
|
424
|
-
|
|
425
|
-
// And now check the single text component within it.
|
|
426
|
-
item = c.childNodes[0];
|
|
427
|
-
expect(item.tagName).toEqual('DIV');
|
|
428
|
-
expect(item.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
|
|
429
|
-
_item$childNodes3 = _slicedToArray(item.childNodes, 2), title = _item$childNodes3[0], itemContainer = _item$childNodes3[1];
|
|
430
|
-
expect(title.tagName).toEqual('LABEL');
|
|
431
|
-
expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
|
|
432
|
-
expect(itemContainer.tagName).toEqual('DIV');
|
|
433
|
-
expect(itemContainer.classList).toContain(_Container.DEFAULT_CLASS);
|
|
434
|
-
formGroup = itemContainer.childNodes[0];
|
|
435
|
-
expect(formGroup.tagName).toEqual('DIV');
|
|
436
|
-
expect(formGroup.classList).toContain('govuk-form-group');
|
|
437
|
-
label = formGroup.childNodes[0];
|
|
438
|
-
expect(label.tagName).toEqual('LABEL');
|
|
439
|
-
expect(label.classList).toContain('govuk-label');
|
|
440
|
-
expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
441
|
-
expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
442
|
-
hint = formGroup.childNodes[1];
|
|
443
|
-
expect(hint.tagName).toEqual('DIV');
|
|
444
|
-
expect(hint.classList).toContain('govuk-hint');
|
|
445
|
-
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
446
|
-
input = formGroup.childNodes[2];
|
|
447
|
-
expect(input.tagName).toEqual('INPUT');
|
|
448
|
-
expect(input.classList).toContain('govuk-input');
|
|
449
|
-
expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
450
|
-
expect(input.value).toEqual('');
|
|
451
|
-
case 30:
|
|
452
|
-
case "end":
|
|
453
|
-
return _context10.stop();
|
|
454
|
-
}
|
|
455
|
-
}, _callee10);
|
|
456
|
-
})));
|
|
457
|
-
it('should render a collection component with only a hint on the first item(s) when restrictHint is truthy', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
|
|
458
|
-
var FORM_DATA_TWO_ITEMS, TEXT_COMPONENT_TWO, COLLECTION, _renderWithValidation7, container, c, item, _item$childNodes4, title, itemContainer, formGroup, label, hint, input, itemTwo, _itemTwo$childNodes, titleTwo, itemContainerTwo, formGroupTwo, labelTwo, hintTwo, inputTwo;
|
|
459
|
-
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
460
|
-
while (1) switch (_context11.prev = _context11.next) {
|
|
461
|
-
case 0:
|
|
462
|
-
FORM_DATA_TWO_ITEMS = [{
|
|
463
|
-
id: '1',
|
|
464
|
-
text: 'alpha',
|
|
465
|
-
textTwo: 'charlie'
|
|
466
|
-
}, {
|
|
467
|
-
id: '2',
|
|
468
|
-
text: 'beta',
|
|
469
|
-
textTwo: 'delta'
|
|
470
|
-
}];
|
|
471
|
-
TEXT_COMPONENT_TWO = {
|
|
472
|
-
id: 'textTwo',
|
|
473
|
-
fieldId: 'textTwo',
|
|
474
|
-
type: _models.ComponentTypes.TEXT,
|
|
475
|
-
label: 'Text component two',
|
|
476
|
-
hint: 'Text hint two'
|
|
477
|
-
};
|
|
478
|
-
COLLECTION = {
|
|
479
|
-
id: ID,
|
|
480
|
-
fieldId: ID,
|
|
481
|
-
type: _models.ComponentTypes.COLLECTION,
|
|
482
|
-
item: [TEXT_COMPONENT, TEXT_COMPONENT_TWO]
|
|
483
|
-
};
|
|
484
|
-
_renderWithValidation7 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
485
|
-
component: _objectSpread(_objectSpread({}, COLLECTION), {}, {
|
|
486
|
-
restrictHint: true
|
|
487
|
-
}),
|
|
488
|
-
value: FORM_DATA_TWO_ITEMS,
|
|
489
|
-
formData: FORM_DATA
|
|
490
|
-
})), container = _renderWithValidation7.container; // Check the container itself.
|
|
491
|
-
c = container.childNodes[0];
|
|
492
|
-
expect(c.tagName).toEqual('DIV');
|
|
493
|
-
expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
|
|
494
|
-
|
|
495
|
-
// And now check the first text component within it.
|
|
496
|
-
item = c.childNodes[0];
|
|
497
|
-
expect(item.tagName).toEqual('DIV');
|
|
498
|
-
expect(item.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
|
|
499
|
-
_item$childNodes4 = _slicedToArray(item.childNodes, 2), title = _item$childNodes4[0], itemContainer = _item$childNodes4[1];
|
|
500
|
-
expect(title.tagName).toEqual('LABEL');
|
|
501
|
-
expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
|
|
502
|
-
expect(itemContainer.tagName).toEqual('DIV');
|
|
503
|
-
expect(itemContainer.classList).toContain(_Container.DEFAULT_CLASS);
|
|
504
|
-
|
|
505
|
-
// First item component 1
|
|
506
|
-
formGroup = itemContainer.childNodes[0];
|
|
507
|
-
expect(formGroup.tagName).toEqual('DIV');
|
|
508
|
-
expect(formGroup.classList).toContain('govuk-form-group');
|
|
509
|
-
label = formGroup.childNodes[0];
|
|
510
|
-
expect(label.tagName).toEqual('LABEL');
|
|
511
|
-
expect(label.classList).toContain('govuk-label');
|
|
512
|
-
expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
513
|
-
expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
514
|
-
hint = formGroup.childNodes[1];
|
|
515
|
-
expect(hint.tagName).toEqual('DIV');
|
|
516
|
-
expect(hint.classList).toContain('govuk-hint');
|
|
517
|
-
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
518
|
-
input = formGroup.childNodes[2];
|
|
519
|
-
expect(input.tagName).toEqual('INPUT');
|
|
520
|
-
expect(input.classList).toContain('govuk-input');
|
|
521
|
-
expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
522
|
-
expect(input.value).toEqual(TEXT_VALUE);
|
|
523
|
-
|
|
524
|
-
// First item component 2
|
|
525
|
-
formGroup = itemContainer.childNodes[1];
|
|
526
|
-
expect(formGroup.tagName).toEqual('DIV');
|
|
527
|
-
expect(formGroup.classList).toContain('govuk-form-group');
|
|
528
|
-
label = formGroup.childNodes[0];
|
|
529
|
-
expect(label.tagName).toEqual('LABEL');
|
|
530
|
-
expect(label.classList).toContain('govuk-label');
|
|
531
|
-
expect(label.textContent).toEqual('Text component two (optional)');
|
|
532
|
-
expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].textTwo"));
|
|
533
|
-
hint = formGroup.childNodes[1];
|
|
534
|
-
expect(hint.tagName).toEqual('DIV');
|
|
535
|
-
expect(hint.classList).toContain('govuk-hint');
|
|
536
|
-
expect(hint.textContent).toEqual('Text hint two');
|
|
537
|
-
input = formGroup.childNodes[2];
|
|
538
|
-
expect(input.tagName).toEqual('INPUT');
|
|
539
|
-
expect(input.classList).toContain('govuk-input');
|
|
540
|
-
expect(input.id).toEqual("".concat(ID, "[0].textTwo"));
|
|
541
|
-
expect(input.value).toEqual('charlie');
|
|
542
|
-
|
|
543
|
-
// Check the second item and confirm there is no hint
|
|
544
|
-
itemTwo = c.childNodes[1];
|
|
545
|
-
expect(itemTwo.tagName).toEqual('DIV');
|
|
546
|
-
expect(itemTwo.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
|
|
547
|
-
_itemTwo$childNodes = _slicedToArray(itemTwo.childNodes, 2), titleTwo = _itemTwo$childNodes[0], itemContainerTwo = _itemTwo$childNodes[1];
|
|
548
|
-
expect(titleTwo.tagName).toEqual('LABEL');
|
|
549
|
-
expect(titleTwo.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
|
|
550
|
-
expect(itemContainerTwo.tagName).toEqual('DIV');
|
|
551
|
-
expect(itemContainerTwo.classList).toContain(_Container.DEFAULT_CLASS);
|
|
552
|
-
|
|
553
|
-
// Second item first component
|
|
554
|
-
formGroupTwo = itemContainerTwo.childNodes[0];
|
|
555
|
-
expect(formGroupTwo.tagName).toEqual('DIV');
|
|
556
|
-
expect(formGroupTwo.classList).toContain('govuk-form-group');
|
|
557
|
-
labelTwo = formGroupTwo.childNodes[0];
|
|
558
|
-
expect(labelTwo.tagName).toEqual('LABEL');
|
|
559
|
-
expect(labelTwo.classList).toContain('govuk-label');
|
|
560
|
-
expect(labelTwo.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
561
|
-
expect(labelTwo.getAttribute('for')).toEqual("".concat(ID, "[1].").concat(TEXT_ID));
|
|
562
|
-
hintTwo = formGroupTwo.childNodes[1];
|
|
563
|
-
expect(hintTwo.tagName).toEqual(undefined);
|
|
564
|
-
inputTwo = formGroupTwo.childNodes[2];
|
|
565
|
-
expect(inputTwo.tagName).toEqual('INPUT');
|
|
566
|
-
expect(inputTwo.classList).toContain('govuk-input');
|
|
567
|
-
expect(inputTwo.id).toEqual("".concat(ID, "[1].").concat(TEXT_ID));
|
|
568
|
-
expect(inputTwo.value).toEqual('beta');
|
|
569
|
-
|
|
570
|
-
// Second item second component
|
|
571
|
-
formGroupTwo = itemContainerTwo.childNodes[1];
|
|
572
|
-
expect(formGroupTwo.tagName).toEqual('DIV');
|
|
573
|
-
expect(formGroupTwo.classList).toContain('govuk-form-group');
|
|
574
|
-
labelTwo = formGroupTwo.childNodes[0];
|
|
575
|
-
expect(labelTwo.tagName).toEqual('LABEL');
|
|
576
|
-
expect(labelTwo.classList).toContain('govuk-label');
|
|
577
|
-
expect(labelTwo.textContent).toEqual('Text component two (optional)');
|
|
578
|
-
expect(labelTwo.getAttribute('for')).toEqual("".concat(ID, "[1].textTwo"));
|
|
579
|
-
hintTwo = formGroupTwo.childNodes[1];
|
|
580
|
-
expect(hintTwo.tagName).toEqual(undefined);
|
|
581
|
-
inputTwo = formGroupTwo.childNodes[2];
|
|
582
|
-
expect(inputTwo.tagName).toEqual('INPUT');
|
|
583
|
-
expect(inputTwo.classList).toContain('govuk-input');
|
|
584
|
-
expect(inputTwo.id).toEqual("".concat(ID, "[1].textTwo"));
|
|
585
|
-
expect(inputTwo.value).toEqual('delta');
|
|
586
|
-
case 87:
|
|
587
|
-
case "end":
|
|
588
|
-
return _context11.stop();
|
|
589
|
-
}
|
|
590
|
-
}, _callee11);
|
|
591
|
-
})));
|
|
592
|
-
it('should render a unique label for the first item(s) when firstOnlyLabel is defined', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
|
|
593
|
-
var UNIQUE_FIRST_LABEL_ONE, UNIQUE_FIRST_LABEL_TWO, FORM_DATA_TWO_ITEMS, TEXT_COMPONENT_TWO, COLLECTION, _renderWithValidation8, container, c, item, _item$childNodes5, title, itemContainer, formGroup, label, hint, input, itemTwo, _itemTwo$childNodes2, titleTwo, itemContainerTwo, formGroupTwo, labelTwo, hintTwo, inputTwo;
|
|
594
|
-
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
595
|
-
while (1) switch (_context12.prev = _context12.next) {
|
|
596
|
-
case 0:
|
|
597
|
-
UNIQUE_FIRST_LABEL_ONE = 'justForTextOne';
|
|
598
|
-
UNIQUE_FIRST_LABEL_TWO = 'justForTextTwo';
|
|
599
|
-
FORM_DATA_TWO_ITEMS = [{
|
|
600
|
-
id: '1',
|
|
601
|
-
text: 'alpha',
|
|
602
|
-
textTwo: 'charlie'
|
|
603
|
-
}, {
|
|
604
|
-
id: '2',
|
|
605
|
-
text: 'beta',
|
|
606
|
-
textTwo: 'delta'
|
|
607
|
-
}];
|
|
608
|
-
TEXT_COMPONENT_TWO = {
|
|
609
|
-
id: 'textTwo',
|
|
610
|
-
fieldId: 'textTwo',
|
|
611
|
-
type: _models.ComponentTypes.TEXT,
|
|
612
|
-
label: 'Text component two',
|
|
613
|
-
hint: 'Text hint two',
|
|
614
|
-
firstOnlyLabel: UNIQUE_FIRST_LABEL_TWO
|
|
615
|
-
};
|
|
616
|
-
COLLECTION = {
|
|
617
|
-
id: ID,
|
|
618
|
-
fieldId: ID,
|
|
619
|
-
type: _models.ComponentTypes.COLLECTION,
|
|
620
|
-
item: [_objectSpread(_objectSpread({}, TEXT_COMPONENT), {}, {
|
|
621
|
-
firstOnlyLabel: UNIQUE_FIRST_LABEL_ONE
|
|
622
|
-
}), TEXT_COMPONENT_TWO]
|
|
623
|
-
};
|
|
624
|
-
_renderWithValidation8 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
625
|
-
component: _objectSpread(_objectSpread({}, COLLECTION), {}, {
|
|
626
|
-
restrictHint: true
|
|
627
|
-
}),
|
|
628
|
-
value: FORM_DATA_TWO_ITEMS,
|
|
629
|
-
formData: FORM_DATA
|
|
630
|
-
})), container = _renderWithValidation8.container; // Check the container itself.
|
|
631
|
-
c = container.childNodes[0];
|
|
632
|
-
expect(c.tagName).toEqual('DIV');
|
|
633
|
-
expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
|
|
634
|
-
|
|
635
|
-
// And now check the first text component within it.
|
|
636
|
-
item = c.childNodes[0];
|
|
637
|
-
expect(item.tagName).toEqual('DIV');
|
|
638
|
-
expect(item.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
|
|
639
|
-
_item$childNodes5 = _slicedToArray(item.childNodes, 2), title = _item$childNodes5[0], itemContainer = _item$childNodes5[1];
|
|
640
|
-
expect(title.tagName).toEqual('LABEL');
|
|
641
|
-
expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
|
|
642
|
-
expect(itemContainer.tagName).toEqual('DIV');
|
|
643
|
-
expect(itemContainer.classList).toContain(_Container.DEFAULT_CLASS);
|
|
644
|
-
|
|
645
|
-
// First item component 1
|
|
646
|
-
formGroup = itemContainer.childNodes[0];
|
|
647
|
-
expect(formGroup.tagName).toEqual('DIV');
|
|
648
|
-
expect(formGroup.classList).toContain('govuk-form-group');
|
|
649
|
-
label = formGroup.childNodes[0];
|
|
650
|
-
expect(label.tagName).toEqual('LABEL');
|
|
651
|
-
expect(label.classList).toContain('govuk-label');
|
|
652
|
-
expect(label.textContent).toEqual("".concat(UNIQUE_FIRST_LABEL_ONE, " (optional)"));
|
|
653
|
-
expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
654
|
-
hint = formGroup.childNodes[1];
|
|
655
|
-
expect(hint.tagName).toEqual('DIV');
|
|
656
|
-
expect(hint.classList).toContain('govuk-hint');
|
|
657
|
-
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
658
|
-
input = formGroup.childNodes[2];
|
|
659
|
-
expect(input.tagName).toEqual('INPUT');
|
|
660
|
-
expect(input.classList).toContain('govuk-input');
|
|
661
|
-
expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
662
|
-
expect(input.value).toEqual(TEXT_VALUE);
|
|
663
|
-
|
|
664
|
-
// First item component 2
|
|
665
|
-
formGroup = itemContainer.childNodes[1];
|
|
666
|
-
expect(formGroup.tagName).toEqual('DIV');
|
|
667
|
-
expect(formGroup.classList).toContain('govuk-form-group');
|
|
668
|
-
label = formGroup.childNodes[0];
|
|
669
|
-
expect(label.tagName).toEqual('LABEL');
|
|
670
|
-
expect(label.classList).toContain('govuk-label');
|
|
671
|
-
expect(label.textContent).toEqual("".concat(UNIQUE_FIRST_LABEL_TWO, " (optional)"));
|
|
672
|
-
expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].textTwo"));
|
|
673
|
-
hint = formGroup.childNodes[1];
|
|
674
|
-
expect(hint.tagName).toEqual('DIV');
|
|
675
|
-
expect(hint.classList).toContain('govuk-hint');
|
|
676
|
-
expect(hint.textContent).toEqual('Text hint two');
|
|
677
|
-
input = formGroup.childNodes[2];
|
|
678
|
-
expect(input.tagName).toEqual('INPUT');
|
|
679
|
-
expect(input.classList).toContain('govuk-input');
|
|
680
|
-
expect(input.id).toEqual("".concat(ID, "[0].textTwo"));
|
|
681
|
-
expect(input.value).toEqual('charlie');
|
|
682
|
-
|
|
683
|
-
// Check the second item and confirm there is no hint
|
|
684
|
-
itemTwo = c.childNodes[1];
|
|
685
|
-
expect(itemTwo.tagName).toEqual('DIV');
|
|
686
|
-
expect(itemTwo.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
|
|
687
|
-
_itemTwo$childNodes2 = _slicedToArray(itemTwo.childNodes, 2), titleTwo = _itemTwo$childNodes2[0], itemContainerTwo = _itemTwo$childNodes2[1];
|
|
688
|
-
expect(titleTwo.tagName).toEqual('LABEL');
|
|
689
|
-
expect(titleTwo.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
|
|
690
|
-
expect(itemContainerTwo.tagName).toEqual('DIV');
|
|
691
|
-
expect(itemContainerTwo.classList).toContain(_Container.DEFAULT_CLASS);
|
|
692
|
-
|
|
693
|
-
// Second item first component
|
|
694
|
-
formGroupTwo = itemContainerTwo.childNodes[0];
|
|
695
|
-
expect(formGroupTwo.tagName).toEqual('DIV');
|
|
696
|
-
expect(formGroupTwo.classList).toContain('govuk-form-group');
|
|
697
|
-
labelTwo = formGroupTwo.childNodes[0];
|
|
698
|
-
expect(labelTwo.tagName).toEqual('LABEL');
|
|
699
|
-
expect(labelTwo.classList).toContain('govuk-label');
|
|
700
|
-
expect(labelTwo.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
701
|
-
expect(labelTwo.getAttribute('for')).toEqual("".concat(ID, "[1].").concat(TEXT_ID));
|
|
702
|
-
hintTwo = formGroupTwo.childNodes[1];
|
|
703
|
-
expect(hintTwo.tagName).toEqual(undefined);
|
|
704
|
-
inputTwo = formGroupTwo.childNodes[2];
|
|
705
|
-
expect(inputTwo.tagName).toEqual('INPUT');
|
|
706
|
-
expect(inputTwo.classList).toContain('govuk-input');
|
|
707
|
-
expect(inputTwo.id).toEqual("".concat(ID, "[1].").concat(TEXT_ID));
|
|
708
|
-
expect(inputTwo.value).toEqual('beta');
|
|
709
|
-
|
|
710
|
-
// Second item second component
|
|
711
|
-
formGroupTwo = itemContainerTwo.childNodes[1];
|
|
712
|
-
expect(formGroupTwo.tagName).toEqual('DIV');
|
|
713
|
-
expect(formGroupTwo.classList).toContain('govuk-form-group');
|
|
714
|
-
labelTwo = formGroupTwo.childNodes[0];
|
|
715
|
-
expect(labelTwo.tagName).toEqual('LABEL');
|
|
716
|
-
expect(labelTwo.classList).toContain('govuk-label');
|
|
717
|
-
expect(labelTwo.textContent).toEqual('Text component two (optional)');
|
|
718
|
-
expect(labelTwo.getAttribute('for')).toEqual("".concat(ID, "[1].textTwo"));
|
|
719
|
-
hintTwo = formGroupTwo.childNodes[1];
|
|
720
|
-
expect(hintTwo.tagName).toEqual(undefined);
|
|
721
|
-
inputTwo = formGroupTwo.childNodes[2];
|
|
722
|
-
expect(inputTwo.tagName).toEqual('INPUT');
|
|
723
|
-
expect(inputTwo.classList).toContain('govuk-input');
|
|
724
|
-
expect(inputTwo.id).toEqual("".concat(ID, "[1].textTwo"));
|
|
725
|
-
expect(inputTwo.value).toEqual('delta');
|
|
726
|
-
case 89:
|
|
727
|
-
case "end":
|
|
728
|
-
return _context12.stop();
|
|
729
|
-
}
|
|
730
|
-
}, _callee12);
|
|
731
|
-
})));
|
|
732
|
-
it('should handle the alternative styling with a background and padding on the subsequent item(s) when subsequentItemStyle is provided', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
|
|
733
|
-
var COLLECTION, container, c, addButton, item, label, secondItem, secondLabel;
|
|
734
|
-
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
735
|
-
while (1) switch (_context14.prev = _context14.next) {
|
|
736
|
-
case 0:
|
|
737
|
-
COLLECTION = {
|
|
738
|
-
id: ID,
|
|
739
|
-
fieldId: ID,
|
|
740
|
-
type: _models.ComponentTypes.COLLECTION,
|
|
741
|
-
item: [TEXT_COMPONENT],
|
|
742
|
-
subsequentItemStyle: {
|
|
743
|
-
background: 'white',
|
|
744
|
-
padding: '1px'
|
|
745
|
-
}
|
|
746
|
-
};
|
|
747
|
-
container = document.createElement('div');
|
|
748
|
-
document.body.appendChild(container);
|
|
749
|
-
_context14.next = 5;
|
|
750
|
-
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
|
|
751
|
-
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
752
|
-
while (1) switch (_context13.prev = _context13.next) {
|
|
753
|
-
case 0:
|
|
754
|
-
(0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
755
|
-
component: COLLECTION
|
|
756
|
-
}), container);
|
|
757
|
-
case 1:
|
|
758
|
-
case "end":
|
|
759
|
-
return _context13.stop();
|
|
760
|
-
}
|
|
761
|
-
}, _callee13);
|
|
762
|
-
})));
|
|
763
|
-
case 5:
|
|
764
|
-
// Check the container itself.
|
|
765
|
-
c = container.childNodes[0];
|
|
766
|
-
expect(c.tagName).toEqual('DIV');
|
|
767
|
-
expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
|
|
768
|
-
|
|
769
|
-
// And now make sure it has no children OTHER than the button to add an item.
|
|
770
|
-
expect(c.childNodes.length).toEqual(1);
|
|
771
|
-
|
|
772
|
-
// Get hold of that "Add another" button and click it.
|
|
773
|
-
addButton = c.childNodes[0].childNodes[0];
|
|
774
|
-
_react.fireEvent.click(addButton, {});
|
|
775
|
-
|
|
776
|
-
// Make sure an item has been added.
|
|
777
|
-
expect(c.childNodes.length).toEqual(2);
|
|
778
|
-
item = c.childNodes[0];
|
|
779
|
-
label = item.childNodes[0];
|
|
780
|
-
expect(label.textContent).toContain(_utils.default.interpolateString(_models.CollectionLabels.item, {
|
|
781
|
-
index: 1
|
|
782
|
-
}));
|
|
783
|
-
|
|
784
|
-
// Check to see if styling has been untouched for the first item
|
|
785
|
-
expect(item.style.background).toEqual('');
|
|
786
|
-
expect(item.style.padding).toEqual('');
|
|
787
|
-
|
|
788
|
-
// Get hold of that "Add another" button and click it.
|
|
789
|
-
_react.fireEvent.click(addButton, {});
|
|
790
|
-
|
|
791
|
-
// Make sure another item has been added.
|
|
792
|
-
expect(c.childNodes.length).toEqual(3);
|
|
793
|
-
secondItem = c.childNodes[1];
|
|
794
|
-
secondLabel = secondItem.childNodes[0];
|
|
795
|
-
expect(secondLabel.textContent).toContain(_utils.default.interpolateString(_models.CollectionLabels.secondItem, {
|
|
796
|
-
index: 2
|
|
797
|
-
}));
|
|
798
|
-
|
|
799
|
-
// Get hold of the second item and check background and padding has been applied.
|
|
800
|
-
expect(secondItem.style.background).toEqual('white');
|
|
801
|
-
expect(secondItem.style.padding).toEqual('1px');
|
|
802
|
-
case 24:
|
|
803
|
-
case "end":
|
|
804
|
-
return _context14.stop();
|
|
805
|
-
}
|
|
806
|
-
}, _callee14);
|
|
807
|
-
})));
|
|
808
|
-
it('should shift focus to most recent item on addition and removal of an item when focusOnAdd is true', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
|
|
809
|
-
var COLLECTION, container, c, addButton, item, label, secondItem, secondItemLabel, removeButton;
|
|
810
|
-
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
811
|
-
while (1) switch (_context16.prev = _context16.next) {
|
|
812
|
-
case 0:
|
|
813
|
-
COLLECTION = {
|
|
814
|
-
id: ID,
|
|
815
|
-
fieldId: ID,
|
|
816
|
-
type: _models.ComponentTypes.COLLECTION,
|
|
817
|
-
item: [TEXT_COMPONENT],
|
|
818
|
-
focusOnAdd: true
|
|
819
|
-
};
|
|
820
|
-
container = document.createElement('div');
|
|
821
|
-
document.body.appendChild(container);
|
|
822
|
-
_context16.next = 5;
|
|
823
|
-
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
|
|
824
|
-
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
|
825
|
-
while (1) switch (_context15.prev = _context15.next) {
|
|
826
|
-
case 0:
|
|
827
|
-
(0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
828
|
-
component: COLLECTION
|
|
829
|
-
}), container);
|
|
830
|
-
case 1:
|
|
831
|
-
case "end":
|
|
832
|
-
return _context15.stop();
|
|
833
|
-
}
|
|
834
|
-
}, _callee15);
|
|
835
|
-
})));
|
|
836
|
-
case 5:
|
|
837
|
-
// Check the container itself.
|
|
838
|
-
c = container.childNodes[0];
|
|
839
|
-
expect(c.tagName).toEqual('DIV');
|
|
840
|
-
expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
|
|
841
|
-
|
|
842
|
-
// And now make sure it has no children OTHER than the button to add an item.
|
|
843
|
-
expect(c.childNodes.length).toEqual(1);
|
|
844
|
-
|
|
845
|
-
// Get hold of that "Add another" button and click it.
|
|
846
|
-
addButton = c.childNodes[0].childNodes[0];
|
|
847
|
-
_react.fireEvent.click(addButton, {});
|
|
848
|
-
|
|
849
|
-
// Make sure an item has been added.
|
|
850
|
-
expect(c.childNodes.length).toEqual(2);
|
|
851
|
-
item = c.childNodes[0];
|
|
852
|
-
label = item.childNodes[0];
|
|
853
|
-
expect(label.textContent).toContain(_utils.default.interpolateString(_models.CollectionLabels.item, {
|
|
854
|
-
index: 1
|
|
855
|
-
}));
|
|
856
|
-
|
|
857
|
-
// Check to see if the item's text input is in focus
|
|
858
|
-
expect(document.activeElement === item.childNodes[1].childNodes[0].querySelector("input")).toEqual(true);
|
|
859
|
-
|
|
860
|
-
// Add another item and check if the second item has been added and it's input is in focus
|
|
861
|
-
_react.fireEvent.click(addButton, {});
|
|
862
|
-
secondItem = c.childNodes[1];
|
|
863
|
-
secondItemLabel = secondItem.childNodes[0];
|
|
864
|
-
expect(c.childNodes.length).toEqual(3);
|
|
865
|
-
expect(document.activeElement === secondItem.childNodes[1].childNodes[0].querySelector("input")).toEqual(true);
|
|
866
|
-
|
|
867
|
-
// Get hold of the second item's "Remove" button.
|
|
868
|
-
removeButton = secondItemLabel.childNodes[1];
|
|
869
|
-
expect(removeButton.tagName).toEqual('BUTTON');
|
|
870
|
-
expect(removeButton.classList).toContain('hods-button--secondary');
|
|
871
|
-
expect(removeButton.textContent).toContain(_models.CollectionLabels.remove);
|
|
872
|
-
|
|
873
|
-
// Click the "Remove" button
|
|
874
|
-
_react.fireEvent.click(removeButton, {});
|
|
875
|
-
|
|
876
|
-
// Make sure the second item has been removed.
|
|
877
|
-
expect(c.childNodes.length).toEqual(2);
|
|
878
|
-
expect(c.childNodes[1].classList).toContain('hods-button-group');
|
|
879
|
-
|
|
880
|
-
// Check to see if the first item is now in focus
|
|
881
|
-
expect(document.activeElement === item.childNodes[1].childNodes[0].querySelector("input")).toEqual(true);
|
|
882
|
-
case 29:
|
|
883
|
-
case "end":
|
|
884
|
-
return _context16.stop();
|
|
34
|
+
it('should render a collection component appropriately', async () => {
|
|
35
|
+
const COLLECTION = {
|
|
36
|
+
id: ID,
|
|
37
|
+
fieldId: ID,
|
|
38
|
+
type: _models.ComponentTypes.COLLECTION,
|
|
39
|
+
item: [TEXT_COMPONENT]
|
|
40
|
+
};
|
|
41
|
+
const {
|
|
42
|
+
container
|
|
43
|
+
} = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
44
|
+
component: COLLECTION,
|
|
45
|
+
value: FORM_DATA[ID],
|
|
46
|
+
formData: FORM_DATA
|
|
47
|
+
}));
|
|
48
|
+
|
|
49
|
+
// Check the container itself.
|
|
50
|
+
const c = container.childNodes[0];
|
|
51
|
+
expect(c.tagName).toEqual('DIV');
|
|
52
|
+
expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
|
|
53
|
+
|
|
54
|
+
// And now check the single text component within it.
|
|
55
|
+
const item = c.childNodes[0];
|
|
56
|
+
expect(item.tagName).toEqual('DIV');
|
|
57
|
+
expect(item.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
|
|
58
|
+
const [title, itemContainer] = item.childNodes;
|
|
59
|
+
expect(title.tagName).toEqual('LABEL');
|
|
60
|
+
expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
|
|
61
|
+
expect(itemContainer.tagName).toEqual('DIV');
|
|
62
|
+
expect(itemContainer.classList).toContain(_Container.DEFAULT_CLASS);
|
|
63
|
+
const formGroup = itemContainer.childNodes[0];
|
|
64
|
+
expect(formGroup.tagName).toEqual('DIV');
|
|
65
|
+
expect(formGroup.classList).toContain('govuk-form-group');
|
|
66
|
+
const label = formGroup.childNodes[0];
|
|
67
|
+
expect(label.tagName).toEqual('LABEL');
|
|
68
|
+
expect(label.classList).toContain('govuk-label');
|
|
69
|
+
expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
70
|
+
expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
71
|
+
const hint = formGroup.childNodes[1];
|
|
72
|
+
expect(hint.tagName).toEqual('DIV');
|
|
73
|
+
expect(hint.classList).toContain('govuk-hint');
|
|
74
|
+
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
75
|
+
const input = formGroup.childNodes[2];
|
|
76
|
+
expect(input.tagName).toEqual('INPUT');
|
|
77
|
+
expect(input.classList).toContain('govuk-input');
|
|
78
|
+
expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
79
|
+
expect(input.value).toEqual(TEXT_VALUE);
|
|
80
|
+
});
|
|
81
|
+
it('should handle a change to a component appropriately', async () => {
|
|
82
|
+
const ON_CHANGE_EVENTS = [];
|
|
83
|
+
const ON_CHANGE = e => {
|
|
84
|
+
ON_CHANGE_EVENTS.push(e);
|
|
85
|
+
};
|
|
86
|
+
const COLLECTION = {
|
|
87
|
+
id: ID,
|
|
88
|
+
fieldId: ID,
|
|
89
|
+
type: _models.ComponentTypes.COLLECTION,
|
|
90
|
+
item: [{
|
|
91
|
+
id: TEXT_ID,
|
|
92
|
+
fieldId: TEXT_ID,
|
|
93
|
+
type: _models.ComponentTypes.TEXT,
|
|
94
|
+
label: 'Text component'
|
|
95
|
+
}]
|
|
96
|
+
};
|
|
97
|
+
const {
|
|
98
|
+
container
|
|
99
|
+
} = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
100
|
+
component: COLLECTION,
|
|
101
|
+
value: FORM_DATA[ID],
|
|
102
|
+
formData: FORM_DATA,
|
|
103
|
+
onChange: ON_CHANGE
|
|
104
|
+
}));
|
|
105
|
+
|
|
106
|
+
// Get hold of the text input.
|
|
107
|
+
const c = container.childNodes[0];
|
|
108
|
+
const item = c.childNodes[0];
|
|
109
|
+
const formGroup = item.childNodes[1].childNodes[0];
|
|
110
|
+
const input = formGroup.childNodes[2];
|
|
111
|
+
const NEW_TEXT_VALUE = 'bravo';
|
|
112
|
+
const EVENT = {
|
|
113
|
+
target: {
|
|
114
|
+
name: TEXT_ID,
|
|
115
|
+
value: NEW_TEXT_VALUE
|
|
885
116
|
}
|
|
886
|
-
}
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
117
|
+
};
|
|
118
|
+
_react.fireEvent.change(input, EVENT);
|
|
119
|
+
|
|
120
|
+
// And confirm the formData has been changed.
|
|
121
|
+
expect(ON_CHANGE_EVENTS.length).toEqual(1);
|
|
122
|
+
expect(ON_CHANGE_EVENTS[0].target.name).toEqual(ID);
|
|
123
|
+
expect(ON_CHANGE_EVENTS[0].target.value[0][TEXT_ID]).toEqual(NEW_TEXT_VALUE);
|
|
124
|
+
});
|
|
125
|
+
it('should handle a null value appropriately', async () => {
|
|
126
|
+
const COLLECTION = {
|
|
127
|
+
id: ID,
|
|
128
|
+
fieldId: ID,
|
|
129
|
+
type: _models.ComponentTypes.COLLECTION,
|
|
130
|
+
item: [TEXT_COMPONENT]
|
|
131
|
+
};
|
|
132
|
+
const {
|
|
133
|
+
container
|
|
134
|
+
} = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
135
|
+
component: COLLECTION
|
|
136
|
+
}));
|
|
137
|
+
|
|
138
|
+
// Check the container itself.
|
|
139
|
+
const c = container.childNodes[0];
|
|
140
|
+
expect(c.tagName).toEqual('DIV');
|
|
141
|
+
expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
|
|
142
|
+
|
|
143
|
+
// And now make sure it has no children OTHER than the button to add an item.
|
|
144
|
+
expect(c.childNodes.length).toEqual(1);
|
|
145
|
+
const buttonGroup = c.childNodes[0];
|
|
146
|
+
expect(buttonGroup.tagName).toEqual('DIV');
|
|
147
|
+
expect(buttonGroup.classList).toContain('hods-button-group');
|
|
148
|
+
const button = buttonGroup.childNodes[0];
|
|
149
|
+
expect(button.tagName).toEqual('BUTTON');
|
|
150
|
+
expect(button.classList).toContain('hods-button');
|
|
151
|
+
expect(button.classList).toContain('hods-button--secondary');
|
|
152
|
+
expect(button.textContent).toContain(_models.CollectionLabels.add);
|
|
153
|
+
});
|
|
154
|
+
it('should handle a collection label appropriately', async () => {
|
|
155
|
+
const LABEL = 'Alpha Collection';
|
|
156
|
+
const COLLECTION = {
|
|
157
|
+
id: ID,
|
|
158
|
+
fieldId: ID,
|
|
159
|
+
type: _models.ComponentTypes.COLLECTION,
|
|
160
|
+
item: [TEXT_COMPONENT],
|
|
161
|
+
label: LABEL
|
|
162
|
+
};
|
|
163
|
+
const {
|
|
164
|
+
container
|
|
165
|
+
} = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
166
|
+
component: COLLECTION
|
|
167
|
+
}));
|
|
168
|
+
|
|
169
|
+
// Check the container itself.
|
|
170
|
+
const c = container.childNodes[0];
|
|
171
|
+
expect(c.tagName).toEqual('DIV');
|
|
172
|
+
expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
|
|
173
|
+
|
|
174
|
+
// And now make sure it has no children OTHER than the button to add an item.
|
|
175
|
+
expect(c.childNodes.length).toEqual(2);
|
|
176
|
+
const [title, buttonGroup] = c.childNodes;
|
|
177
|
+
expect(title.tagName).toEqual('LABEL');
|
|
178
|
+
expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__title"));
|
|
179
|
+
expect(title.getAttribute('for')).toEqual(ID);
|
|
180
|
+
expect(title.textContent).toContain(LABEL);
|
|
181
|
+
expect(buttonGroup.tagName).toEqual('DIV');
|
|
182
|
+
expect(buttonGroup.classList).toContain('hods-button-group');
|
|
183
|
+
const button = buttonGroup.childNodes[0];
|
|
184
|
+
expect(button.tagName).toEqual('BUTTON');
|
|
185
|
+
expect(button.classList).toContain('hods-button');
|
|
186
|
+
expect(button.classList).toContain('hods-button--secondary');
|
|
187
|
+
expect(button.textContent).toContain(_models.CollectionLabels.add);
|
|
188
|
+
});
|
|
189
|
+
it('should handle the addition and removal of an item', async () => {
|
|
190
|
+
const COLLECTION = {
|
|
191
|
+
id: ID,
|
|
192
|
+
fieldId: ID,
|
|
193
|
+
type: _models.ComponentTypes.COLLECTION,
|
|
194
|
+
item: [TEXT_COMPONENT]
|
|
195
|
+
};
|
|
196
|
+
const container = document.createElement('div');
|
|
197
|
+
document.body.appendChild(container);
|
|
198
|
+
await (0, _testUtils.act)(async () => {
|
|
199
|
+
(0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
200
|
+
component: COLLECTION
|
|
201
|
+
}), container);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
// Check the container itself.
|
|
205
|
+
const c = container.childNodes[0];
|
|
206
|
+
expect(c.tagName).toEqual('DIV');
|
|
207
|
+
expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
|
|
208
|
+
|
|
209
|
+
// And now make sure it has no children OTHER than the button to add an item.
|
|
210
|
+
expect(c.childNodes.length).toEqual(1);
|
|
211
|
+
|
|
212
|
+
// Get hold of that "Add another" button and click it.
|
|
213
|
+
const addButton = c.childNodes[0].childNodes[0];
|
|
214
|
+
_react.fireEvent.click(addButton, {});
|
|
215
|
+
|
|
216
|
+
// Make sure an item has been added.
|
|
217
|
+
expect(c.childNodes.length).toEqual(2);
|
|
218
|
+
const item = c.childNodes[0];
|
|
219
|
+
const label = item.childNodes[0];
|
|
220
|
+
expect(label.textContent).toContain(_utils.default.interpolateString(_models.CollectionLabels.item, {
|
|
221
|
+
index: 1
|
|
222
|
+
}));
|
|
223
|
+
|
|
224
|
+
// Get hold of the newly-add item's "Remove" button.
|
|
225
|
+
const removeButton = label.childNodes[1];
|
|
226
|
+
expect(removeButton.tagName).toEqual('BUTTON');
|
|
227
|
+
expect(removeButton.classList).toContain('hods-button--secondary');
|
|
228
|
+
expect(removeButton.textContent).toContain(_models.CollectionLabels.remove);
|
|
229
|
+
|
|
230
|
+
// Click the "Remove" button
|
|
231
|
+
_react.fireEvent.click(removeButton, {});
|
|
232
|
+
|
|
233
|
+
// Make sure the item has been removed.
|
|
234
|
+
expect(c.childNodes.length).toEqual(1);
|
|
235
|
+
expect(c.childNodes[0].classList).toContain('hods-button-group');
|
|
236
|
+
});
|
|
237
|
+
it('should handle the alternative styling', async () => {
|
|
238
|
+
const COLLECTION = {
|
|
239
|
+
id: ID,
|
|
240
|
+
fieldId: ID,
|
|
241
|
+
type: _models.ComponentTypes.COLLECTION,
|
|
242
|
+
item: [TEXT_COMPONENT],
|
|
243
|
+
removeLocation: 'end'
|
|
244
|
+
};
|
|
245
|
+
const container = document.createElement('div');
|
|
246
|
+
document.body.appendChild(container);
|
|
247
|
+
await (0, _testUtils.act)(async () => {
|
|
248
|
+
(0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
249
|
+
component: COLLECTION
|
|
250
|
+
}), container);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
// Check the container itself.
|
|
254
|
+
const c = container.childNodes[0];
|
|
255
|
+
expect(c.tagName).toEqual('DIV');
|
|
256
|
+
expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
|
|
257
|
+
|
|
258
|
+
// And now make sure it has no children OTHER than the button to add an item.
|
|
259
|
+
expect(c.childNodes.length).toEqual(1);
|
|
260
|
+
|
|
261
|
+
// Get hold of that "Add another" button and click it.
|
|
262
|
+
const addButton = c.childNodes[0].childNodes[0];
|
|
263
|
+
_react.fireEvent.click(addButton, {});
|
|
264
|
+
|
|
265
|
+
// Make sure an item has been added.
|
|
266
|
+
expect(c.childNodes.length).toEqual(2);
|
|
267
|
+
const item = c.childNodes[0];
|
|
268
|
+
const label = item.childNodes[0];
|
|
269
|
+
expect(label.textContent).toContain(_utils.default.interpolateString(_models.CollectionLabels.item, {
|
|
270
|
+
index: 1
|
|
271
|
+
}));
|
|
272
|
+
|
|
273
|
+
// Get hold of the newly-add item's "Remove" button.
|
|
274
|
+
const removeButton = item.childNodes[2].childNodes[0];
|
|
275
|
+
expect(removeButton.tagName).toEqual('BUTTON');
|
|
276
|
+
expect(removeButton.classList).toContain('hods-button--secondary');
|
|
277
|
+
expect(removeButton.textContent).toContain(_models.CollectionLabels.remove);
|
|
278
|
+
|
|
279
|
+
// Click the "Remove" button
|
|
280
|
+
_react.fireEvent.click(removeButton, {});
|
|
281
|
+
|
|
282
|
+
// Make sure the item has been removed.
|
|
283
|
+
expect(c.childNodes.length).toEqual(1);
|
|
284
|
+
expect(c.childNodes[0].classList).toContain('hods-button-group');
|
|
285
|
+
});
|
|
286
|
+
it('should appropriately make child components of items readonly', async () => {
|
|
287
|
+
const COLLECTION = {
|
|
288
|
+
id: ID,
|
|
289
|
+
fieldId: ID,
|
|
290
|
+
type: _models.ComponentTypes.COLLECTION,
|
|
291
|
+
item: [TEXT_COMPONENT],
|
|
292
|
+
readonly: true
|
|
293
|
+
};
|
|
294
|
+
const {
|
|
295
|
+
container
|
|
296
|
+
} = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
297
|
+
component: COLLECTION,
|
|
298
|
+
value: FORM_DATA[ID],
|
|
299
|
+
formData: FORM_DATA
|
|
300
|
+
}));
|
|
301
|
+
|
|
302
|
+
// Check the container itself.
|
|
303
|
+
const c = container.childNodes[0];
|
|
304
|
+
expect(c.tagName).toEqual('DIV');
|
|
305
|
+
expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
|
|
306
|
+
|
|
307
|
+
// And now check the single text component within it.
|
|
308
|
+
const item = c.childNodes[0];
|
|
309
|
+
expect(item.tagName).toEqual('DIV');
|
|
310
|
+
expect(item.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
|
|
311
|
+
const [title, itemContainer] = item.childNodes;
|
|
312
|
+
expect(title.tagName).toEqual('LABEL');
|
|
313
|
+
expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
|
|
314
|
+
expect(itemContainer.tagName).toEqual('DIV');
|
|
315
|
+
expect(itemContainer.classList).toContain(_Container.DEFAULT_CLASS);
|
|
316
|
+
const formGroup = itemContainer.childNodes[0];
|
|
317
|
+
expect(formGroup.tagName).toEqual('DIV');
|
|
318
|
+
expect(formGroup.classList).toContain('govuk-form-group');
|
|
319
|
+
const label = formGroup.childNodes[0];
|
|
320
|
+
expect(label.tagName).toEqual('LABEL');
|
|
321
|
+
expect(label.classList).toContain('govuk-label');
|
|
322
|
+
expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
323
|
+
expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
324
|
+
const hint = formGroup.childNodes[1];
|
|
325
|
+
expect(hint.tagName).toEqual('DIV');
|
|
326
|
+
expect(hint.classList).toContain('govuk-hint');
|
|
327
|
+
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
328
|
+
const input = formGroup.childNodes[2];
|
|
329
|
+
expect(input.tagName).toEqual('DIV'); // Now readonly, so a DIV.
|
|
330
|
+
expect(input.classList).toContain('hods-readonly'); // Now readonly, so hods-readonly
|
|
331
|
+
expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
332
|
+
expect(input.textContent).toEqual(TEXT_VALUE);
|
|
333
|
+
});
|
|
334
|
+
it('should render a collection component with minimumEntries appropriately', async () => {
|
|
335
|
+
const COLLECTION = {
|
|
336
|
+
id: ID,
|
|
337
|
+
fieldId: ID,
|
|
338
|
+
type: _models.ComponentTypes.COLLECTION,
|
|
339
|
+
item: [TEXT_COMPONENT],
|
|
340
|
+
minimumEntries: 1
|
|
341
|
+
};
|
|
342
|
+
const {
|
|
343
|
+
container
|
|
344
|
+
} = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
345
|
+
component: COLLECTION,
|
|
346
|
+
value: [],
|
|
347
|
+
formData: {}
|
|
348
|
+
}));
|
|
349
|
+
|
|
350
|
+
// Check the container itself.
|
|
351
|
+
const c = container.childNodes[0];
|
|
352
|
+
expect(c.tagName).toEqual('DIV');
|
|
353
|
+
expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
|
|
354
|
+
|
|
355
|
+
// And now check the single text component within it.
|
|
356
|
+
const item = c.childNodes[0];
|
|
357
|
+
expect(item.tagName).toEqual('DIV');
|
|
358
|
+
expect(item.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
|
|
359
|
+
const [title, itemContainer] = item.childNodes;
|
|
360
|
+
expect(title.tagName).toEqual('LABEL');
|
|
361
|
+
expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
|
|
362
|
+
expect(itemContainer.tagName).toEqual('DIV');
|
|
363
|
+
expect(itemContainer.classList).toContain(_Container.DEFAULT_CLASS);
|
|
364
|
+
const formGroup = itemContainer.childNodes[0];
|
|
365
|
+
expect(formGroup.tagName).toEqual('DIV');
|
|
366
|
+
expect(formGroup.classList).toContain('govuk-form-group');
|
|
367
|
+
const label = formGroup.childNodes[0];
|
|
368
|
+
expect(label.tagName).toEqual('LABEL');
|
|
369
|
+
expect(label.classList).toContain('govuk-label');
|
|
370
|
+
expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
371
|
+
expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
372
|
+
const hint = formGroup.childNodes[1];
|
|
373
|
+
expect(hint.tagName).toEqual('DIV');
|
|
374
|
+
expect(hint.classList).toContain('govuk-hint');
|
|
375
|
+
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
376
|
+
const input = formGroup.childNodes[2];
|
|
377
|
+
expect(input.tagName).toEqual('INPUT');
|
|
378
|
+
expect(input.classList).toContain('govuk-input');
|
|
379
|
+
expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
380
|
+
expect(input.value).toEqual('');
|
|
381
|
+
});
|
|
382
|
+
it('should render a collection component with only a hint on the first item(s) when restrictHint is truthy', async () => {
|
|
383
|
+
const FORM_DATA_TWO_ITEMS = [{
|
|
384
|
+
id: '1',
|
|
385
|
+
text: 'alpha',
|
|
386
|
+
textTwo: 'charlie'
|
|
387
|
+
}, {
|
|
388
|
+
id: '2',
|
|
389
|
+
text: 'beta',
|
|
390
|
+
textTwo: 'delta'
|
|
391
|
+
}];
|
|
392
|
+
const TEXT_COMPONENT_TWO = {
|
|
393
|
+
id: 'textTwo',
|
|
394
|
+
fieldId: 'textTwo',
|
|
395
|
+
type: _models.ComponentTypes.TEXT,
|
|
396
|
+
label: 'Text component two',
|
|
397
|
+
hint: 'Text hint two'
|
|
398
|
+
};
|
|
399
|
+
const COLLECTION = {
|
|
400
|
+
id: ID,
|
|
401
|
+
fieldId: ID,
|
|
402
|
+
type: _models.ComponentTypes.COLLECTION,
|
|
403
|
+
item: [TEXT_COMPONENT, TEXT_COMPONENT_TWO]
|
|
404
|
+
};
|
|
405
|
+
const {
|
|
406
|
+
container
|
|
407
|
+
} = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
408
|
+
component: {
|
|
409
|
+
...COLLECTION,
|
|
410
|
+
restrictHint: true
|
|
411
|
+
},
|
|
412
|
+
value: FORM_DATA_TWO_ITEMS,
|
|
413
|
+
formData: FORM_DATA
|
|
414
|
+
}));
|
|
415
|
+
|
|
416
|
+
// Check the container itself.
|
|
417
|
+
const c = container.childNodes[0];
|
|
418
|
+
expect(c.tagName).toEqual('DIV');
|
|
419
|
+
expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
|
|
420
|
+
|
|
421
|
+
// And now check the first text component within it.
|
|
422
|
+
const item = c.childNodes[0];
|
|
423
|
+
expect(item.tagName).toEqual('DIV');
|
|
424
|
+
expect(item.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
|
|
425
|
+
const [title, itemContainer] = item.childNodes;
|
|
426
|
+
expect(title.tagName).toEqual('LABEL');
|
|
427
|
+
expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
|
|
428
|
+
expect(itemContainer.tagName).toEqual('DIV');
|
|
429
|
+
expect(itemContainer.classList).toContain(_Container.DEFAULT_CLASS);
|
|
430
|
+
|
|
431
|
+
// First item component 1
|
|
432
|
+
let formGroup = itemContainer.childNodes[0];
|
|
433
|
+
expect(formGroup.tagName).toEqual('DIV');
|
|
434
|
+
expect(formGroup.classList).toContain('govuk-form-group');
|
|
435
|
+
let label = formGroup.childNodes[0];
|
|
436
|
+
expect(label.tagName).toEqual('LABEL');
|
|
437
|
+
expect(label.classList).toContain('govuk-label');
|
|
438
|
+
expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
439
|
+
expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
440
|
+
let hint = formGroup.childNodes[1];
|
|
441
|
+
expect(hint.tagName).toEqual('DIV');
|
|
442
|
+
expect(hint.classList).toContain('govuk-hint');
|
|
443
|
+
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
444
|
+
let input = formGroup.childNodes[2];
|
|
445
|
+
expect(input.tagName).toEqual('INPUT');
|
|
446
|
+
expect(input.classList).toContain('govuk-input');
|
|
447
|
+
expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
448
|
+
expect(input.value).toEqual(TEXT_VALUE);
|
|
449
|
+
|
|
450
|
+
// First item component 2
|
|
451
|
+
formGroup = itemContainer.childNodes[1];
|
|
452
|
+
expect(formGroup.tagName).toEqual('DIV');
|
|
453
|
+
expect(formGroup.classList).toContain('govuk-form-group');
|
|
454
|
+
label = formGroup.childNodes[0];
|
|
455
|
+
expect(label.tagName).toEqual('LABEL');
|
|
456
|
+
expect(label.classList).toContain('govuk-label');
|
|
457
|
+
expect(label.textContent).toEqual('Text component two (optional)');
|
|
458
|
+
expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].textTwo"));
|
|
459
|
+
hint = formGroup.childNodes[1];
|
|
460
|
+
expect(hint.tagName).toEqual('DIV');
|
|
461
|
+
expect(hint.classList).toContain('govuk-hint');
|
|
462
|
+
expect(hint.textContent).toEqual('Text hint two');
|
|
463
|
+
input = formGroup.childNodes[2];
|
|
464
|
+
expect(input.tagName).toEqual('INPUT');
|
|
465
|
+
expect(input.classList).toContain('govuk-input');
|
|
466
|
+
expect(input.id).toEqual("".concat(ID, "[0].textTwo"));
|
|
467
|
+
expect(input.value).toEqual('charlie');
|
|
468
|
+
|
|
469
|
+
// Check the second item and confirm there is no hint
|
|
470
|
+
const itemTwo = c.childNodes[1];
|
|
471
|
+
expect(itemTwo.tagName).toEqual('DIV');
|
|
472
|
+
expect(itemTwo.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
|
|
473
|
+
const [titleTwo, itemContainerTwo] = itemTwo.childNodes;
|
|
474
|
+
expect(titleTwo.tagName).toEqual('LABEL');
|
|
475
|
+
expect(titleTwo.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
|
|
476
|
+
expect(itemContainerTwo.tagName).toEqual('DIV');
|
|
477
|
+
expect(itemContainerTwo.classList).toContain(_Container.DEFAULT_CLASS);
|
|
478
|
+
|
|
479
|
+
// Second item first component
|
|
480
|
+
let formGroupTwo = itemContainerTwo.childNodes[0];
|
|
481
|
+
expect(formGroupTwo.tagName).toEqual('DIV');
|
|
482
|
+
expect(formGroupTwo.classList).toContain('govuk-form-group');
|
|
483
|
+
let labelTwo = formGroupTwo.childNodes[0];
|
|
484
|
+
expect(labelTwo.tagName).toEqual('LABEL');
|
|
485
|
+
expect(labelTwo.classList).toContain('govuk-label');
|
|
486
|
+
expect(labelTwo.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
487
|
+
expect(labelTwo.getAttribute('for')).toEqual("".concat(ID, "[1].").concat(TEXT_ID));
|
|
488
|
+
let hintTwo = formGroupTwo.childNodes[1];
|
|
489
|
+
expect(hintTwo.tagName).toEqual(undefined);
|
|
490
|
+
let inputTwo = formGroupTwo.childNodes[2];
|
|
491
|
+
expect(inputTwo.tagName).toEqual('INPUT');
|
|
492
|
+
expect(inputTwo.classList).toContain('govuk-input');
|
|
493
|
+
expect(inputTwo.id).toEqual("".concat(ID, "[1].").concat(TEXT_ID));
|
|
494
|
+
expect(inputTwo.value).toEqual('beta');
|
|
495
|
+
|
|
496
|
+
// Second item second component
|
|
497
|
+
formGroupTwo = itemContainerTwo.childNodes[1];
|
|
498
|
+
expect(formGroupTwo.tagName).toEqual('DIV');
|
|
499
|
+
expect(formGroupTwo.classList).toContain('govuk-form-group');
|
|
500
|
+
labelTwo = formGroupTwo.childNodes[0];
|
|
501
|
+
expect(labelTwo.tagName).toEqual('LABEL');
|
|
502
|
+
expect(labelTwo.classList).toContain('govuk-label');
|
|
503
|
+
expect(labelTwo.textContent).toEqual('Text component two (optional)');
|
|
504
|
+
expect(labelTwo.getAttribute('for')).toEqual("".concat(ID, "[1].textTwo"));
|
|
505
|
+
hintTwo = formGroupTwo.childNodes[1];
|
|
506
|
+
expect(hintTwo.tagName).toEqual(undefined);
|
|
507
|
+
inputTwo = formGroupTwo.childNodes[2];
|
|
508
|
+
expect(inputTwo.tagName).toEqual('INPUT');
|
|
509
|
+
expect(inputTwo.classList).toContain('govuk-input');
|
|
510
|
+
expect(inputTwo.id).toEqual("".concat(ID, "[1].textTwo"));
|
|
511
|
+
expect(inputTwo.value).toEqual('delta');
|
|
512
|
+
});
|
|
513
|
+
it('should render a unique label for the first item(s) when firstOnlyLabel is defined', async () => {
|
|
514
|
+
const UNIQUE_FIRST_LABEL_ONE = 'justForTextOne';
|
|
515
|
+
const UNIQUE_FIRST_LABEL_TWO = 'justForTextTwo';
|
|
516
|
+
const FORM_DATA_TWO_ITEMS = [{
|
|
517
|
+
id: '1',
|
|
518
|
+
text: 'alpha',
|
|
519
|
+
textTwo: 'charlie'
|
|
520
|
+
}, {
|
|
521
|
+
id: '2',
|
|
522
|
+
text: 'beta',
|
|
523
|
+
textTwo: 'delta'
|
|
524
|
+
}];
|
|
525
|
+
const TEXT_COMPONENT_TWO = {
|
|
526
|
+
id: 'textTwo',
|
|
527
|
+
fieldId: 'textTwo',
|
|
528
|
+
type: _models.ComponentTypes.TEXT,
|
|
529
|
+
label: 'Text component two',
|
|
530
|
+
hint: 'Text hint two',
|
|
531
|
+
firstOnlyLabel: UNIQUE_FIRST_LABEL_TWO
|
|
532
|
+
};
|
|
533
|
+
const COLLECTION = {
|
|
534
|
+
id: ID,
|
|
535
|
+
fieldId: ID,
|
|
536
|
+
type: _models.ComponentTypes.COLLECTION,
|
|
537
|
+
item: [{
|
|
538
|
+
...TEXT_COMPONENT,
|
|
539
|
+
firstOnlyLabel: UNIQUE_FIRST_LABEL_ONE
|
|
540
|
+
}, TEXT_COMPONENT_TWO]
|
|
541
|
+
};
|
|
542
|
+
const {
|
|
543
|
+
container
|
|
544
|
+
} = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
545
|
+
component: {
|
|
546
|
+
...COLLECTION,
|
|
547
|
+
restrictHint: true
|
|
548
|
+
},
|
|
549
|
+
value: FORM_DATA_TWO_ITEMS,
|
|
550
|
+
formData: FORM_DATA
|
|
551
|
+
}));
|
|
552
|
+
|
|
553
|
+
// Check the container itself.
|
|
554
|
+
const c = container.childNodes[0];
|
|
555
|
+
expect(c.tagName).toEqual('DIV');
|
|
556
|
+
expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
|
|
557
|
+
|
|
558
|
+
// And now check the first text component within it.
|
|
559
|
+
const item = c.childNodes[0];
|
|
560
|
+
expect(item.tagName).toEqual('DIV');
|
|
561
|
+
expect(item.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
|
|
562
|
+
const [title, itemContainer] = item.childNodes;
|
|
563
|
+
expect(title.tagName).toEqual('LABEL');
|
|
564
|
+
expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
|
|
565
|
+
expect(itemContainer.tagName).toEqual('DIV');
|
|
566
|
+
expect(itemContainer.classList).toContain(_Container.DEFAULT_CLASS);
|
|
567
|
+
|
|
568
|
+
// First item component 1
|
|
569
|
+
let formGroup = itemContainer.childNodes[0];
|
|
570
|
+
expect(formGroup.tagName).toEqual('DIV');
|
|
571
|
+
expect(formGroup.classList).toContain('govuk-form-group');
|
|
572
|
+
let label = formGroup.childNodes[0];
|
|
573
|
+
expect(label.tagName).toEqual('LABEL');
|
|
574
|
+
expect(label.classList).toContain('govuk-label');
|
|
575
|
+
expect(label.textContent).toEqual("".concat(UNIQUE_FIRST_LABEL_ONE, " (optional)"));
|
|
576
|
+
expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
577
|
+
let hint = formGroup.childNodes[1];
|
|
578
|
+
expect(hint.tagName).toEqual('DIV');
|
|
579
|
+
expect(hint.classList).toContain('govuk-hint');
|
|
580
|
+
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
581
|
+
let input = formGroup.childNodes[2];
|
|
582
|
+
expect(input.tagName).toEqual('INPUT');
|
|
583
|
+
expect(input.classList).toContain('govuk-input');
|
|
584
|
+
expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
585
|
+
expect(input.value).toEqual(TEXT_VALUE);
|
|
586
|
+
|
|
587
|
+
// First item component 2
|
|
588
|
+
formGroup = itemContainer.childNodes[1];
|
|
589
|
+
expect(formGroup.tagName).toEqual('DIV');
|
|
590
|
+
expect(formGroup.classList).toContain('govuk-form-group');
|
|
591
|
+
label = formGroup.childNodes[0];
|
|
592
|
+
expect(label.tagName).toEqual('LABEL');
|
|
593
|
+
expect(label.classList).toContain('govuk-label');
|
|
594
|
+
expect(label.textContent).toEqual("".concat(UNIQUE_FIRST_LABEL_TWO, " (optional)"));
|
|
595
|
+
expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].textTwo"));
|
|
596
|
+
hint = formGroup.childNodes[1];
|
|
597
|
+
expect(hint.tagName).toEqual('DIV');
|
|
598
|
+
expect(hint.classList).toContain('govuk-hint');
|
|
599
|
+
expect(hint.textContent).toEqual('Text hint two');
|
|
600
|
+
input = formGroup.childNodes[2];
|
|
601
|
+
expect(input.tagName).toEqual('INPUT');
|
|
602
|
+
expect(input.classList).toContain('govuk-input');
|
|
603
|
+
expect(input.id).toEqual("".concat(ID, "[0].textTwo"));
|
|
604
|
+
expect(input.value).toEqual('charlie');
|
|
605
|
+
|
|
606
|
+
// Check the second item and confirm there is no hint
|
|
607
|
+
const itemTwo = c.childNodes[1];
|
|
608
|
+
expect(itemTwo.tagName).toEqual('DIV');
|
|
609
|
+
expect(itemTwo.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
|
|
610
|
+
const [titleTwo, itemContainerTwo] = itemTwo.childNodes;
|
|
611
|
+
expect(titleTwo.tagName).toEqual('LABEL');
|
|
612
|
+
expect(titleTwo.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
|
|
613
|
+
expect(itemContainerTwo.tagName).toEqual('DIV');
|
|
614
|
+
expect(itemContainerTwo.classList).toContain(_Container.DEFAULT_CLASS);
|
|
615
|
+
|
|
616
|
+
// Second item first component
|
|
617
|
+
let formGroupTwo = itemContainerTwo.childNodes[0];
|
|
618
|
+
expect(formGroupTwo.tagName).toEqual('DIV');
|
|
619
|
+
expect(formGroupTwo.classList).toContain('govuk-form-group');
|
|
620
|
+
let labelTwo = formGroupTwo.childNodes[0];
|
|
621
|
+
expect(labelTwo.tagName).toEqual('LABEL');
|
|
622
|
+
expect(labelTwo.classList).toContain('govuk-label');
|
|
623
|
+
expect(labelTwo.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
624
|
+
expect(labelTwo.getAttribute('for')).toEqual("".concat(ID, "[1].").concat(TEXT_ID));
|
|
625
|
+
let hintTwo = formGroupTwo.childNodes[1];
|
|
626
|
+
expect(hintTwo.tagName).toEqual(undefined);
|
|
627
|
+
let inputTwo = formGroupTwo.childNodes[2];
|
|
628
|
+
expect(inputTwo.tagName).toEqual('INPUT');
|
|
629
|
+
expect(inputTwo.classList).toContain('govuk-input');
|
|
630
|
+
expect(inputTwo.id).toEqual("".concat(ID, "[1].").concat(TEXT_ID));
|
|
631
|
+
expect(inputTwo.value).toEqual('beta');
|
|
632
|
+
|
|
633
|
+
// Second item second component
|
|
634
|
+
formGroupTwo = itemContainerTwo.childNodes[1];
|
|
635
|
+
expect(formGroupTwo.tagName).toEqual('DIV');
|
|
636
|
+
expect(formGroupTwo.classList).toContain('govuk-form-group');
|
|
637
|
+
labelTwo = formGroupTwo.childNodes[0];
|
|
638
|
+
expect(labelTwo.tagName).toEqual('LABEL');
|
|
639
|
+
expect(labelTwo.classList).toContain('govuk-label');
|
|
640
|
+
expect(labelTwo.textContent).toEqual('Text component two (optional)');
|
|
641
|
+
expect(labelTwo.getAttribute('for')).toEqual("".concat(ID, "[1].textTwo"));
|
|
642
|
+
hintTwo = formGroupTwo.childNodes[1];
|
|
643
|
+
expect(hintTwo.tagName).toEqual(undefined);
|
|
644
|
+
inputTwo = formGroupTwo.childNodes[2];
|
|
645
|
+
expect(inputTwo.tagName).toEqual('INPUT');
|
|
646
|
+
expect(inputTwo.classList).toContain('govuk-input');
|
|
647
|
+
expect(inputTwo.id).toEqual("".concat(ID, "[1].textTwo"));
|
|
648
|
+
expect(inputTwo.value).toEqual('delta');
|
|
649
|
+
});
|
|
650
|
+
it('should handle the alternative styling with a background and padding on the subsequent item(s) when subsequentItemStyle is provided', async () => {
|
|
651
|
+
const COLLECTION = {
|
|
652
|
+
id: ID,
|
|
653
|
+
fieldId: ID,
|
|
654
|
+
type: _models.ComponentTypes.COLLECTION,
|
|
655
|
+
item: [TEXT_COMPONENT],
|
|
656
|
+
subsequentItemStyle: {
|
|
657
|
+
background: 'white',
|
|
658
|
+
padding: '1px'
|
|
964
659
|
}
|
|
965
|
-
}
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
660
|
+
};
|
|
661
|
+
const container = document.createElement('div');
|
|
662
|
+
document.body.appendChild(container);
|
|
663
|
+
await (0, _testUtils.act)(async () => {
|
|
664
|
+
(0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
665
|
+
component: COLLECTION
|
|
666
|
+
}), container);
|
|
667
|
+
});
|
|
668
|
+
|
|
669
|
+
// Check the container itself.
|
|
670
|
+
const c = container.childNodes[0];
|
|
671
|
+
expect(c.tagName).toEqual('DIV');
|
|
672
|
+
expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
|
|
673
|
+
|
|
674
|
+
// And now make sure it has no children OTHER than the button to add an item.
|
|
675
|
+
expect(c.childNodes.length).toEqual(1);
|
|
676
|
+
|
|
677
|
+
// Get hold of that "Add another" button and click it.
|
|
678
|
+
const addButton = c.childNodes[0].childNodes[0];
|
|
679
|
+
_react.fireEvent.click(addButton, {});
|
|
680
|
+
|
|
681
|
+
// Make sure an item has been added.
|
|
682
|
+
expect(c.childNodes.length).toEqual(2);
|
|
683
|
+
const item = c.childNodes[0];
|
|
684
|
+
const label = item.childNodes[0];
|
|
685
|
+
expect(label.textContent).toContain(_utils.default.interpolateString(_models.CollectionLabels.item, {
|
|
686
|
+
index: 1
|
|
687
|
+
}));
|
|
688
|
+
|
|
689
|
+
// Check to see if styling has been untouched for the first item
|
|
690
|
+
expect(item.style.background).toEqual('');
|
|
691
|
+
expect(item.style.padding).toEqual('');
|
|
692
|
+
|
|
693
|
+
// Get hold of that "Add another" button and click it.
|
|
694
|
+
_react.fireEvent.click(addButton, {});
|
|
695
|
+
|
|
696
|
+
// Make sure another item has been added.
|
|
697
|
+
expect(c.childNodes.length).toEqual(3);
|
|
698
|
+
const secondItem = c.childNodes[1];
|
|
699
|
+
const secondLabel = secondItem.childNodes[0];
|
|
700
|
+
expect(secondLabel.textContent).toContain(_utils.default.interpolateString(_models.CollectionLabels.secondItem, {
|
|
701
|
+
index: 2
|
|
702
|
+
}));
|
|
703
|
+
|
|
704
|
+
// Get hold of the second item and check background and padding has been applied.
|
|
705
|
+
expect(secondItem.style.background).toEqual('white');
|
|
706
|
+
expect(secondItem.style.padding).toEqual('1px');
|
|
707
|
+
});
|
|
708
|
+
it('should shift focus to most recent item on addition and removal of an item when focusOnAdd is true', async () => {
|
|
709
|
+
const COLLECTION = {
|
|
710
|
+
id: ID,
|
|
711
|
+
fieldId: ID,
|
|
712
|
+
type: _models.ComponentTypes.COLLECTION,
|
|
713
|
+
item: [TEXT_COMPONENT],
|
|
714
|
+
focusOnAdd: true
|
|
715
|
+
};
|
|
716
|
+
const container = document.createElement('div');
|
|
717
|
+
document.body.appendChild(container);
|
|
718
|
+
await (0, _testUtils.act)(async () => {
|
|
719
|
+
(0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
720
|
+
component: COLLECTION
|
|
721
|
+
}), container);
|
|
722
|
+
});
|
|
723
|
+
|
|
724
|
+
// Check the container itself.
|
|
725
|
+
const c = container.childNodes[0];
|
|
726
|
+
expect(c.tagName).toEqual('DIV');
|
|
727
|
+
expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
|
|
728
|
+
|
|
729
|
+
// And now make sure it has no children OTHER than the button to add an item.
|
|
730
|
+
expect(c.childNodes.length).toEqual(1);
|
|
731
|
+
|
|
732
|
+
// Get hold of that "Add another" button and click it.
|
|
733
|
+
const addButton = c.childNodes[0].childNodes[0];
|
|
734
|
+
_react.fireEvent.click(addButton, {});
|
|
735
|
+
|
|
736
|
+
// Make sure an item has been added.
|
|
737
|
+
expect(c.childNodes.length).toEqual(2);
|
|
738
|
+
const item = c.childNodes[0];
|
|
739
|
+
const label = item.childNodes[0];
|
|
740
|
+
expect(label.textContent).toContain(_utils.default.interpolateString(_models.CollectionLabels.item, {
|
|
741
|
+
index: 1
|
|
742
|
+
}));
|
|
743
|
+
|
|
744
|
+
// Check to see if the item's text input is in focus
|
|
745
|
+
expect(document.activeElement === item.childNodes[1].childNodes[0].querySelector("input")).toEqual(true);
|
|
746
|
+
|
|
747
|
+
// Add another item and check if the second item has been added and it's input is in focus
|
|
748
|
+
_react.fireEvent.click(addButton, {});
|
|
749
|
+
const secondItem = c.childNodes[1];
|
|
750
|
+
const secondItemLabel = secondItem.childNodes[0];
|
|
751
|
+
expect(c.childNodes.length).toEqual(3);
|
|
752
|
+
expect(document.activeElement === secondItem.childNodes[1].childNodes[0].querySelector("input")).toEqual(true);
|
|
753
|
+
|
|
754
|
+
// Get hold of the second item's "Remove" button.
|
|
755
|
+
const removeButton = secondItemLabel.childNodes[1];
|
|
756
|
+
expect(removeButton.tagName).toEqual('BUTTON');
|
|
757
|
+
expect(removeButton.classList).toContain('hods-button--secondary');
|
|
758
|
+
expect(removeButton.textContent).toContain(_models.CollectionLabels.remove);
|
|
759
|
+
|
|
760
|
+
// Click the "Remove" button
|
|
761
|
+
_react.fireEvent.click(removeButton, {});
|
|
762
|
+
|
|
763
|
+
// Make sure the second item has been removed.
|
|
764
|
+
expect(c.childNodes.length).toEqual(2);
|
|
765
|
+
expect(c.childNodes[1].classList).toContain('hods-button-group');
|
|
766
|
+
|
|
767
|
+
// Check to see if the first item is now in focus
|
|
768
|
+
expect(document.activeElement === item.childNodes[1].childNodes[0].querySelector("input")).toEqual(true);
|
|
769
|
+
});
|
|
770
|
+
it('should not focus on first item when minimumEntries is 1 and focus on added item instead when focusOnAdd is true', async () => {
|
|
771
|
+
const COLLECTION = {
|
|
772
|
+
id: ID,
|
|
773
|
+
fieldId: ID,
|
|
774
|
+
type: _models.ComponentTypes.COLLECTION,
|
|
775
|
+
item: [TEXT_COMPONENT],
|
|
776
|
+
focusOnAdd: true,
|
|
777
|
+
minimumEntries: 1
|
|
778
|
+
};
|
|
779
|
+
const container = document.createElement('div');
|
|
780
|
+
document.body.appendChild(container);
|
|
781
|
+
await (0, _testUtils.act)(async () => {
|
|
782
|
+
(0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
783
|
+
component: COLLECTION
|
|
784
|
+
}), container);
|
|
785
|
+
});
|
|
786
|
+
|
|
787
|
+
// Check the container itself.
|
|
788
|
+
const c = container.childNodes[0];
|
|
789
|
+
expect(c.tagName).toEqual('DIV');
|
|
790
|
+
expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
|
|
791
|
+
|
|
792
|
+
// And now check the single text component within it.
|
|
793
|
+
const item = c.childNodes[0];
|
|
794
|
+
expect(item.tagName).toEqual('DIV');
|
|
795
|
+
expect(item.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
|
|
796
|
+
const [title, itemContainer] = item.childNodes;
|
|
797
|
+
expect(title.tagName).toEqual('LABEL');
|
|
798
|
+
expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
|
|
799
|
+
expect(itemContainer.tagName).toEqual('DIV');
|
|
800
|
+
expect(itemContainer.classList).toContain(_Container.DEFAULT_CLASS);
|
|
801
|
+
const formGroup = itemContainer.childNodes[0];
|
|
802
|
+
expect(formGroup.tagName).toEqual('DIV');
|
|
803
|
+
expect(formGroup.classList).toContain('govuk-form-group');
|
|
804
|
+
const label = formGroup.childNodes[0];
|
|
805
|
+
expect(label.tagName).toEqual('LABEL');
|
|
806
|
+
expect(label.classList).toContain('govuk-label');
|
|
807
|
+
expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
808
|
+
expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
809
|
+
const hint = formGroup.childNodes[1];
|
|
810
|
+
expect(hint.tagName).toEqual('DIV');
|
|
811
|
+
expect(hint.classList).toContain('govuk-hint');
|
|
812
|
+
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
813
|
+
const input = formGroup.childNodes[2];
|
|
814
|
+
expect(input.tagName).toEqual('INPUT');
|
|
815
|
+
expect(input.classList).toContain('govuk-input');
|
|
816
|
+
expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
817
|
+
expect(input.value).toEqual('');
|
|
818
|
+
|
|
819
|
+
// Check to see if the item's text input is not in focus
|
|
820
|
+
expect(document.activeElement === item.childNodes[1].childNodes[0].querySelector("input")).toEqual(false);
|
|
821
|
+
|
|
822
|
+
// Get hold of that "Add another" button and click it.
|
|
823
|
+
const addButton = c.childNodes[1].childNodes[0];
|
|
824
|
+
_react.fireEvent.click(addButton, {});
|
|
825
|
+
|
|
826
|
+
// Check if the second item has been added and it's input is in focus
|
|
827
|
+
const secondItem = c.childNodes[1];
|
|
828
|
+
expect(c.childNodes.length).toEqual(3);
|
|
829
|
+
expect(document.activeElement === secondItem.childNodes[1].childNodes[0].querySelector("input")).toEqual(true);
|
|
830
|
+
});
|
|
831
|
+
it('should display the initial cta add label and revert to default cta label on subsequent additions', async () => {
|
|
832
|
+
const COLLECTION = {
|
|
833
|
+
id: ID,
|
|
834
|
+
fieldId: ID,
|
|
835
|
+
type: _models.ComponentTypes.COLLECTION,
|
|
836
|
+
item: [TEXT_COMPONENT],
|
|
837
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
838
|
+
labels: {
|
|
839
|
+
add: 'Add another item',
|
|
840
|
+
initial: 'Add an item',
|
|
841
|
+
item: 'Item ${index}'
|
|
1027
842
|
}
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
// Get hold of that "Add another" button and click it.
|
|
1073
|
-
addButton = c.childNodes[0].childNodes[0];
|
|
1074
|
-
expect(addButton.textContent).toContain('Add an item');
|
|
1075
|
-
_react.fireEvent.click(addButton, {});
|
|
1076
|
-
|
|
1077
|
-
// Make sure an item has been added.
|
|
1078
|
-
expect(c.childNodes.length).toEqual(2);
|
|
1079
|
-
item = c.childNodes[0];
|
|
1080
|
-
label = item.childNodes[0];
|
|
1081
|
-
expect(label.textContent).toContain(_utils.default.interpolateString(_models.CollectionLabels.item, {
|
|
1082
|
-
index: 1
|
|
1083
|
-
}));
|
|
1084
|
-
|
|
1085
|
-
// Check label of subsequent call to action button has updated
|
|
1086
|
-
expect(addButton.textContent).toContain('Add another item');
|
|
1087
|
-
|
|
1088
|
-
// Get hold of the newly-add item's "Remove" button.
|
|
1089
|
-
removeButton = label.childNodes[1];
|
|
1090
|
-
expect(removeButton.tagName).toEqual('BUTTON');
|
|
1091
|
-
expect(removeButton.classList).toContain('hods-button--secondary');
|
|
1092
|
-
expect(removeButton.textContent).toContain(_models.CollectionLabels.remove);
|
|
1093
|
-
|
|
1094
|
-
// Click the "Remove" button
|
|
1095
|
-
_react.fireEvent.click(removeButton, {});
|
|
1096
|
-
|
|
1097
|
-
// Check label of subsequent call to action button has updated
|
|
1098
|
-
expect(addButton.textContent).toContain('Add an item');
|
|
1099
|
-
case 23:
|
|
1100
|
-
case "end":
|
|
1101
|
-
return _context22.stop();
|
|
843
|
+
};
|
|
844
|
+
const container = document.createElement('div');
|
|
845
|
+
document.body.appendChild(container);
|
|
846
|
+
await (0, _testUtils.act)(async () => {
|
|
847
|
+
(0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
848
|
+
component: COLLECTION
|
|
849
|
+
}), container);
|
|
850
|
+
});
|
|
851
|
+
|
|
852
|
+
// Check the container itself.
|
|
853
|
+
const c = container.childNodes[0];
|
|
854
|
+
expect(c.tagName).toEqual('DIV');
|
|
855
|
+
expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
|
|
856
|
+
|
|
857
|
+
// And now make sure it has no children OTHER than the button to add an item.
|
|
858
|
+
expect(c.childNodes.length).toEqual(1);
|
|
859
|
+
|
|
860
|
+
// Get hold of that "Add another" button and click it.
|
|
861
|
+
const addButton = c.childNodes[0].childNodes[0];
|
|
862
|
+
expect(addButton.textContent).toContain('Add an item');
|
|
863
|
+
_react.fireEvent.click(addButton, {});
|
|
864
|
+
|
|
865
|
+
// Make sure an item has been added.
|
|
866
|
+
expect(c.childNodes.length).toEqual(2);
|
|
867
|
+
const item = c.childNodes[0];
|
|
868
|
+
const label = item.childNodes[0];
|
|
869
|
+
expect(label.textContent).toContain(_utils.default.interpolateString(_models.CollectionLabels.item, {
|
|
870
|
+
index: 1
|
|
871
|
+
}));
|
|
872
|
+
|
|
873
|
+
// Check label of subsequent call to action button has updated
|
|
874
|
+
expect(addButton.textContent).toContain('Add another item');
|
|
875
|
+
});
|
|
876
|
+
it('should revert back to the initial cta add label on adding and removing an item', async () => {
|
|
877
|
+
const COLLECTION = {
|
|
878
|
+
id: ID,
|
|
879
|
+
fieldId: ID,
|
|
880
|
+
type: _models.ComponentTypes.COLLECTION,
|
|
881
|
+
item: [TEXT_COMPONENT],
|
|
882
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
883
|
+
labels: {
|
|
884
|
+
add: 'Add another item',
|
|
885
|
+
initial: 'Add an item',
|
|
886
|
+
item: 'Item ${index}'
|
|
1102
887
|
}
|
|
1103
|
-
}
|
|
1104
|
-
|
|
888
|
+
};
|
|
889
|
+
const container = document.createElement('div');
|
|
890
|
+
document.body.appendChild(container);
|
|
891
|
+
await (0, _testUtils.act)(async () => {
|
|
892
|
+
(0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
893
|
+
component: COLLECTION
|
|
894
|
+
}), container);
|
|
895
|
+
});
|
|
896
|
+
|
|
897
|
+
// Check the container itself.
|
|
898
|
+
const c = container.childNodes[0];
|
|
899
|
+
expect(c.tagName).toEqual('DIV');
|
|
900
|
+
expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
|
|
901
|
+
|
|
902
|
+
// And now make sure it has no children OTHER than the button to add an item.
|
|
903
|
+
expect(c.childNodes.length).toEqual(1);
|
|
904
|
+
|
|
905
|
+
// Get hold of that "Add another" button and click it.
|
|
906
|
+
const addButton = c.childNodes[0].childNodes[0];
|
|
907
|
+
expect(addButton.textContent).toContain('Add an item');
|
|
908
|
+
_react.fireEvent.click(addButton, {});
|
|
909
|
+
|
|
910
|
+
// Make sure an item has been added.
|
|
911
|
+
expect(c.childNodes.length).toEqual(2);
|
|
912
|
+
const item = c.childNodes[0];
|
|
913
|
+
const label = item.childNodes[0];
|
|
914
|
+
expect(label.textContent).toContain(_utils.default.interpolateString(_models.CollectionLabels.item, {
|
|
915
|
+
index: 1
|
|
916
|
+
}));
|
|
917
|
+
|
|
918
|
+
// Check label of subsequent call to action button has updated
|
|
919
|
+
expect(addButton.textContent).toContain('Add another item');
|
|
920
|
+
|
|
921
|
+
// Get hold of the newly-add item's "Remove" button.
|
|
922
|
+
const removeButton = label.childNodes[1];
|
|
923
|
+
expect(removeButton.tagName).toEqual('BUTTON');
|
|
924
|
+
expect(removeButton.classList).toContain('hods-button--secondary');
|
|
925
|
+
expect(removeButton.textContent).toContain(_models.CollectionLabels.remove);
|
|
926
|
+
|
|
927
|
+
// Click the "Remove" button
|
|
928
|
+
_react.fireEvent.click(removeButton, {});
|
|
929
|
+
|
|
930
|
+
// Check label of subsequent call to action button has updated
|
|
931
|
+
expect(addButton.textContent).toContain('Add an item');
|
|
932
|
+
});
|
|
1105
933
|
});
|