@ukhomeoffice/cop-react-form-renderer 5.14.0 → 5.14.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/CheckYourAnswers/Answer.js +15 -15
- package/dist/components/CheckYourAnswers/Answer.test.js +94 -128
- package/dist/components/CheckYourAnswers/CheckYourAnswers.js +99 -129
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +291 -501
- package/dist/components/CheckYourAnswers/index.js +2 -3
- package/dist/components/CollectionPage/CollectionPage.js +64 -58
- package/dist/components/CollectionPage/CollectionPage.test.js +212 -238
- package/dist/components/CollectionPage/index.js +2 -3
- package/dist/components/FormComponent/Collection.js +77 -113
- package/dist/components/FormComponent/Collection.test.js +688 -787
- package/dist/components/FormComponent/Container.js +44 -43
- package/dist/components/FormComponent/Container.test.js +316 -346
- package/dist/components/FormComponent/FormComponent.js +58 -64
- package/dist/components/FormComponent/FormComponent.test.js +180 -219
- package/dist/components/FormComponent/helpers/addLabel.js +5 -9
- package/dist/components/FormComponent/helpers/getComponentDisabled.js +2 -3
- package/dist/components/FormComponent/helpers/getComponentDisabled.test.js +8 -8
- package/dist/components/FormComponent/helpers/getComponentError.js +4 -7
- package/dist/components/FormComponent/helpers/getComponentError.test.js +15 -15
- package/dist/components/FormComponent/helpers/getComponentFieldSet.js +2 -2
- package/dist/components/FormComponent/helpers/getComponentFieldSet.test.js +7 -7
- package/dist/components/FormComponent/helpers/index.js +5 -5
- package/dist/components/FormComponent/index.js +2 -3
- package/dist/components/FormPage/FormPage.js +65 -79
- package/dist/components/FormPage/FormPage.test.js +134 -170
- package/dist/components/FormPage/index.js +2 -3
- package/dist/components/FormRenderer/FormRenderer.js +151 -193
- package/dist/components/FormRenderer/FormRenderer.test.js +598 -920
- package/dist/components/FormRenderer/handlers/cyaAction.js +4 -5
- package/dist/components/FormRenderer/handlers/getPageId.js +2 -5
- package/dist/components/FormRenderer/handlers/getPageId.test.js +15 -15
- package/dist/components/FormRenderer/handlers/handlers.test.js +33 -33
- package/dist/components/FormRenderer/handlers/index.js +3 -4
- package/dist/components/FormRenderer/handlers/navigate.js +5 -6
- package/dist/components/FormRenderer/handlers/submissionError.js +2 -3
- package/dist/components/FormRenderer/helpers/canActionProceed.js +2 -3
- package/dist/components/FormRenderer/helpers/canActionProceed.test.js +10 -10
- package/dist/components/FormRenderer/helpers/canCYASubmit.js +2 -5
- package/dist/components/FormRenderer/helpers/canCYASubmit.test.js +17 -21
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.js +19 -27
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.test.js +17 -17
- package/dist/components/FormRenderer/helpers/getCYA.js +6 -9
- package/dist/components/FormRenderer/helpers/getCYA.test.js +12 -12
- package/dist/components/FormRenderer/helpers/getFormState.js +7 -10
- package/dist/components/FormRenderer/helpers/getFormState.test.js +11 -11
- package/dist/components/FormRenderer/helpers/getNextPageId.js +19 -34
- package/dist/components/FormRenderer/helpers/getNextPageId.test.js +68 -68
- package/dist/components/FormRenderer/helpers/getPage.js +3 -6
- package/dist/components/FormRenderer/helpers/getPage.test.js +12 -12
- package/dist/components/FormRenderer/helpers/getRelevantPages.js +9 -13
- package/dist/components/FormRenderer/helpers/getRelevantPages.test.js +15 -15
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +12 -13
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +98 -92
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.js +66 -66
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.test.js +72 -79
- package/dist/components/FormRenderer/helpers/index.js +3 -4
- package/dist/components/FormRenderer/index.js +2 -3
- package/dist/components/FormRenderer/onCYAAction.js +52 -62
- package/dist/components/FormRenderer/onCYAAction.test.js +146 -138
- package/dist/components/FormRenderer/onPageAction.js +48 -47
- package/dist/components/FormRenderer/onPageAction.test.js +219 -205
- package/dist/components/FormRenderer/onTaskAction.js +12 -17
- package/dist/components/FormRenderer/onTaskAction.test.js +94 -89
- package/dist/components/PageActions/ActionButton.js +15 -19
- package/dist/components/PageActions/ActionButton.test.js +58 -79
- package/dist/components/PageActions/PageActions.js +12 -13
- package/dist/components/PageActions/PageActions.test.js +88 -116
- package/dist/components/PageActions/index.js +2 -3
- package/dist/components/SummaryList/GroupAction.js +15 -23
- package/dist/components/SummaryList/GroupAction.test.js +41 -37
- package/dist/components/SummaryList/RowAction.js +14 -19
- package/dist/components/SummaryList/RowAction.test.js +41 -37
- package/dist/components/SummaryList/SummaryList.js +25 -30
- package/dist/components/SummaryList/SummaryList.test.js +160 -182
- package/dist/components/SummaryList/SummaryListHeadingRow.js +9 -8
- package/dist/components/SummaryList/SummaryListRow.js +9 -8
- package/dist/components/SummaryList/SummaryListTitleRow.js +8 -7
- package/dist/components/SummaryList/helpers/getGroupActionAttributes.js +5 -8
- package/dist/components/SummaryList/helpers/getGroupActionAttributes.test.js +24 -24
- package/dist/components/SummaryList/helpers/getRowActionAttributes.js +5 -8
- package/dist/components/SummaryList/helpers/getRowActionAttributes.test.js +24 -24
- package/dist/components/SummaryList/helpers/index.js +2 -2
- package/dist/components/SummaryList/index.js +2 -3
- package/dist/components/TaskList/Task.js +22 -33
- package/dist/components/TaskList/Task.test.js +84 -77
- package/dist/components/TaskList/TaskList.js +46 -75
- package/dist/components/TaskList/TaskList.test.js +118 -113
- package/dist/components/TaskList/TaskState.js +9 -9
- package/dist/components/TaskList/TaskState.test.js +56 -49
- package/dist/components/TaskList/index.js +2 -3
- package/dist/components/index.js +8 -8
- package/dist/context/HooksContext/HooksContext.js +59 -85
- package/dist/context/HooksContext/HooksContext.test.js +28 -36
- package/dist/context/HooksContext/index.js +4 -6
- package/dist/context/ValidationContext/ValidationContext.js +35 -76
- package/dist/context/ValidationContext/ValidationContext.test.js +50 -61
- package/dist/context/ValidationContext/index.js +4 -6
- package/dist/context/index.js +3 -3
- package/dist/hooks/index.js +10 -11
- package/dist/hooks/useAxios.js +17 -43
- package/dist/hooks/useGetRequest.js +65 -106
- package/dist/hooks/useHooks.js +2 -5
- package/dist/hooks/useRefData.js +30 -45
- package/dist/hooks/useValidation.js +2 -5
- package/dist/index.js +15 -17
- package/dist/models/CollectionLabels.js +2 -3
- package/dist/models/ComponentTypes.js +25 -26
- package/dist/models/EventTypes.js +5 -6
- package/dist/models/FormPages.js +5 -6
- package/dist/models/FormTypes.js +9 -10
- package/dist/models/HubFormats.js +4 -5
- package/dist/models/PageAction.js +45 -42
- package/dist/models/TaskStates.js +30 -31
- package/dist/models/index.js +11 -12
- package/dist/setupTests.js +20 -24
- package/dist/utils/CheckYourAnswers/getCYAAction.js +6 -7
- package/dist/utils/CheckYourAnswers/getCYAAction.test.js +53 -55
- package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.js +18 -20
- package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.test.js +21 -23
- package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.js +17 -21
- package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.test.js +18 -20
- package/dist/utils/CheckYourAnswers/getCYARow.js +8 -10
- package/dist/utils/CheckYourAnswers/getCYARow.test.js +72 -72
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.js +20 -27
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.test.js +16 -17
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.js +41 -47
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.test.js +72 -75
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +71 -78
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +133 -114
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.js +27 -23
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.test.js +112 -106
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +16 -23
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.test.js +77 -83
- package/dist/utils/CheckYourAnswers/index.js +3 -4
- package/dist/utils/CheckYourAnswers/showComponentCYA.js +7 -9
- package/dist/utils/CheckYourAnswers/showComponentCYA.test.js +25 -25
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.js +9 -16
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.test.js +19 -20
- package/dist/utils/CollectionPage/getCollectionPageActiveIndex.js +4 -8
- package/dist/utils/CollectionPage/getCollectionPageActiveIndex.test.js +15 -15
- package/dist/utils/CollectionPage/index.js +3 -4
- package/dist/utils/CollectionPage/mergeCollectionPages.js +26 -29
- package/dist/utils/CollectionPage/mergeCollectionPages.test.js +15 -15
- package/dist/utils/Component/addShowWhen.js +5 -10
- package/dist/utils/Component/addShowWhen.test.js +38 -38
- package/dist/utils/Component/applyToComponentTree.js +20 -22
- package/dist/utils/Component/applyToComponentTree.test.js +28 -33
- package/dist/utils/Component/cleanAttributes.js +11 -16
- package/dist/utils/Component/cleanAttributes.test.js +17 -18
- package/dist/utils/Component/elevateNestedComponents.js +7 -9
- package/dist/utils/Component/elevateNestedComponents.test.js +19 -19
- package/dist/utils/Component/getComponent.js +91 -99
- package/dist/utils/Component/getComponentTests/getComponent.autocomplete.test.js +19 -18
- package/dist/utils/Component/getComponentTests/getComponent.calculation.test.js +51 -63
- package/dist/utils/Component/getComponentTests/getComponent.checkboxes.test.js +41 -49
- package/dist/utils/Component/getComponentTests/getComponent.date.test.js +33 -37
- package/dist/utils/Component/getComponentTests/getComponent.details.test.js +21 -19
- package/dist/utils/Component/getComponentTests/getComponent.email.test.js +19 -23
- package/dist/utils/Component/getComponentTests/getComponent.file.test.js +23 -27
- package/dist/utils/Component/getComponentTests/getComponent.heading.test.js +12 -11
- package/dist/utils/Component/getComponentTests/getComponent.html.test.js +18 -16
- package/dist/utils/Component/getComponentTests/getComponent.insetText.test.js +10 -9
- package/dist/utils/Component/getComponentTests/getComponent.list.test.js +18 -16
- package/dist/utils/Component/getComponentTests/getComponent.multifile.test.js +24 -27
- package/dist/utils/Component/getComponentTests/getComponent.nested.test.js +156 -175
- package/dist/utils/Component/getComponentTests/getComponent.paragraph.test.js +18 -16
- package/dist/utils/Component/getComponentTests/getComponent.phoneNumber.test.js +19 -23
- package/dist/utils/Component/getComponentTests/getComponent.radios.test.js +59 -73
- package/dist/utils/Component/getComponentTests/getComponent.select.test.js +19 -23
- package/dist/utils/Component/getComponentTests/getComponent.text.test.js +19 -23
- package/dist/utils/Component/getComponentTests/getComponent.textArea.test.js +35 -41
- package/dist/utils/Component/getComponentTests/getComponent.time.test.js +24 -32
- package/dist/utils/Component/getComponentTests/getComponent.unknown.test.js +3 -3
- package/dist/utils/Component/getComponentTests/getComponent.warningText.test.js +10 -9
- package/dist/utils/Component/getDefaultValue.js +7 -9
- package/dist/utils/Component/getDefaultValue.test.js +14 -14
- package/dist/utils/Component/index.js +3 -4
- package/dist/utils/Component/isEditable.js +3 -7
- package/dist/utils/Component/isEditable.test.js +14 -15
- package/dist/utils/Component/optionIsSelected.js +2 -3
- package/dist/utils/Component/optionIsSelected.test.js +10 -10
- package/dist/utils/Component/setupContainerComponentsPath.js +30 -33
- package/dist/utils/Component/setupContainerComponentsPath.test.js +16 -16
- package/dist/utils/Component/showComponent.js +4 -6
- package/dist/utils/Component/showComponent.test.js +29 -29
- package/dist/utils/Component/wrapInFormGroup.js +6 -6
- package/dist/utils/Condition/index.js +3 -4
- package/dist/utils/Condition/meetsAllConditions.js +9 -10
- package/dist/utils/Condition/meetsAllConditions.test.js +18 -18
- package/dist/utils/Condition/meetsCondition.js +19 -27
- package/dist/utils/Condition/meetsCondition.test.js +377 -377
- package/dist/utils/Condition/meetsOneCondition.js +7 -8
- package/dist/utils/Condition/meetsOneCondition.test.js +17 -17
- package/dist/utils/Condition/setupConditions.js +15 -21
- package/dist/utils/Condition/setupConditions.test.js +8 -8
- package/dist/utils/Container/getEditableComponents.js +5 -8
- package/dist/utils/Container/getEditableComponents.test.js +44 -46
- package/dist/utils/Container/index.js +3 -4
- package/dist/utils/Container/setupNesting.js +17 -24
- package/dist/utils/Container/setupNesting.test.js +28 -31
- package/dist/utils/Container/showContainer.js +5 -10
- package/dist/utils/Container/showContainer.test.js +31 -31
- package/dist/utils/Data/applyFormula.js +41 -52
- package/dist/utils/Data/applyFormula.test.js +26 -26
- package/dist/utils/Data/getAutocompleteSource.js +11 -14
- package/dist/utils/Data/getAutocompleteSource.test.js +59 -59
- package/dist/utils/Data/getDataPath.js +21 -32
- package/dist/utils/Data/getDataPath.test.js +20 -20
- package/dist/utils/Data/getOptions.js +22 -28
- package/dist/utils/Data/getOptions.test.js +21 -21
- package/dist/utils/Data/getSourceData.js +7 -21
- package/dist/utils/Data/getSourceData.test.js +85 -81
- package/dist/utils/Data/index.js +3 -4
- package/dist/utils/Data/refDataToOptions.js +12 -17
- package/dist/utils/Data/refDataToOptions.test.js +20 -20
- package/dist/utils/Data/setDataItem.js +8 -10
- package/dist/utils/Data/setDataItem.test.js +38 -38
- package/dist/utils/Data/setupFormData.js +32 -48
- package/dist/utils/Data/setupFormData.test.js +99 -98
- package/dist/utils/Data/setupRefDataUrlForComponent.js +22 -30
- package/dist/utils/Data/setupRefDataUrlForComponent.test.js +28 -28
- package/dist/utils/FormPage/applyConditionalProperties.js +7 -12
- package/dist/utils/FormPage/applyConditionalProperties.test.js +16 -19
- package/dist/utils/FormPage/getFormPage.js +17 -19
- package/dist/utils/FormPage/getFormPage.test.js +49 -48
- package/dist/utils/FormPage/getFormPages.js +9 -15
- package/dist/utils/FormPage/getFormPages.test.js +22 -25
- package/dist/utils/FormPage/getPageActions.js +11 -19
- package/dist/utils/FormPage/getPageActions.test.js +33 -33
- package/dist/utils/FormPage/getParagraphFromText.js +6 -9
- package/dist/utils/FormPage/getParagraphFromText.test.js +7 -7
- package/dist/utils/FormPage/index.js +3 -4
- package/dist/utils/FormPage/showFormPage.js +5 -10
- package/dist/utils/FormPage/showFormPage.test.js +33 -33
- package/dist/utils/FormPage/showFormPageCYA.js +4 -5
- package/dist/utils/FormPage/showFormPageCYA.test.js +9 -9
- package/dist/utils/FormPage/useComponent.js +21 -29
- package/dist/utils/FormPage/useComponent.test.js +71 -73
- package/dist/utils/Format/formatData.js +2 -3
- package/dist/utils/Format/formatData.test.js +19 -19
- package/dist/utils/Format/formatDataForComponent.js +6 -9
- package/dist/utils/Format/formatDataForComponent.test.js +50 -78
- package/dist/utils/Format/formatDataForForm.js +7 -10
- package/dist/utils/Format/formatDataForForm.test.js +14 -17
- package/dist/utils/Format/formatDataForPage.js +4 -7
- package/dist/utils/Format/formatDataForPage.test.js +20 -25
- package/dist/utils/Format/index.js +3 -4
- package/dist/utils/Hub/getFormHub.js +3 -4
- package/dist/utils/Hub/getFormHub.test.js +29 -32
- package/dist/utils/Hub/index.js +3 -4
- package/dist/utils/Meta/constants.js +2 -4
- package/dist/utils/Meta/documents/getDocuments.js +2 -6
- package/dist/utils/Meta/documents/getDocuments.test.js +25 -17
- package/dist/utils/Meta/documents/index.js +3 -4
- package/dist/utils/Meta/documents/setDocumentsForField.js +16 -19
- package/dist/utils/Meta/documents/setDocumentsForField.test.js +69 -35
- package/dist/utils/Meta/index.js +3 -4
- package/dist/utils/Operate/checkValueIsTruthy.js +5 -6
- package/dist/utils/Operate/checkValueIsTruthy.test.js +17 -17
- package/dist/utils/Operate/getFirstOf.js +9 -10
- package/dist/utils/Operate/getFirstOf.test.js +33 -33
- package/dist/utils/Operate/getIndexOfMatchingValueIn.js +13 -14
- package/dist/utils/Operate/getIndexOfMatchingValueIn.test.js +47 -53
- package/dist/utils/Operate/index.js +3 -4
- package/dist/utils/Operate/persistValueInFormData.js +7 -8
- package/dist/utils/Operate/persistValueInFormData.test.js +23 -21
- package/dist/utils/Operate/runPageOperations.js +10 -11
- package/dist/utils/Operate/runPageOperations.test.js +36 -37
- package/dist/utils/Operate/setValueInFormData.js +6 -7
- package/dist/utils/Operate/setValueInFormData.test.js +17 -17
- package/dist/utils/Operate/shouldRun.js +9 -10
- package/dist/utils/Operate/shouldRun.test.js +22 -28
- package/dist/utils/Validate/additional/conditionallyRequired.js +5 -7
- package/dist/utils/Validate/additional/conditionallyRequired.test.js +19 -19
- package/dist/utils/Validate/additional/index.js +8 -9
- package/dist/utils/Validate/additional/index.test.js +13 -13
- package/dist/utils/Validate/additional/mustBeAfter.js +4 -5
- package/dist/utils/Validate/additional/mustBeAfter.test.js +41 -41
- package/dist/utils/Validate/additional/mustBeBefore.js +4 -5
- package/dist/utils/Validate/additional/mustBeBefore.test.js +29 -29
- package/dist/utils/Validate/additional/mustBeEarlierDateTime.js +8 -14
- package/dist/utils/Validate/additional/mustBeEarlierDateTime.test.js +34 -38
- package/dist/utils/Validate/additional/mustBeGreaterThan.js +3 -4
- package/dist/utils/Validate/additional/mustBeGreaterThan.test.js +19 -19
- package/dist/utils/Validate/additional/mustBeInTheFuture.js +5 -6
- package/dist/utils/Validate/additional/mustBeInTheFuture.test.js +13 -13
- package/dist/utils/Validate/additional/mustBeInThePast.js +6 -7
- package/dist/utils/Validate/additional/mustBeInThePast.test.js +13 -13
- package/dist/utils/Validate/additional/mustBeLessThan.js +3 -4
- package/dist/utils/Validate/additional/mustBeLessThan.test.js +18 -18
- package/dist/utils/Validate/additional/mustBeLongerThan.js +2 -3
- package/dist/utils/Validate/additional/mustBeLongerThan.test.js +17 -17
- package/dist/utils/Validate/additional/mustBeNumbersOnly.js +3 -4
- package/dist/utils/Validate/additional/mustBeNumbersOnly.test.js +21 -21
- package/dist/utils/Validate/additional/mustBeShorterThan.js +2 -3
- package/dist/utils/Validate/additional/mustBeShorterThan.test.js +17 -17
- package/dist/utils/Validate/additional/mustEnterAtLeastOne.js +4 -7
- package/dist/utils/Validate/additional/mustEnterAtLeastOne.test.js +15 -17
- package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.js +2 -3
- package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.test.js +13 -13
- package/dist/utils/Validate/additional/mustSelectOnlyOne.js +4 -7
- package/dist/utils/Validate/additional/mustSelectOnlyOne.test.js +29 -27
- package/dist/utils/Validate/additional/utils.js +9 -25
- package/dist/utils/Validate/index.js +3 -4
- package/dist/utils/Validate/validateCollection.js +22 -29
- package/dist/utils/Validate/validateCollection.test.js +85 -77
- package/dist/utils/Validate/validateComponent.js +19 -19
- package/dist/utils/Validate/validateComponent.test.js +169 -147
- package/dist/utils/Validate/validateContainer.js +16 -22
- package/dist/utils/Validate/validateContainer.test.js +52 -48
- package/dist/utils/Validate/validateDate.js +14 -21
- package/dist/utils/Validate/validateDate.test.js +28 -29
- package/dist/utils/Validate/validateEmail.js +8 -11
- package/dist/utils/Validate/validateEmail.test.js +26 -26
- package/dist/utils/Validate/validateMultifile.js +6 -10
- package/dist/utils/Validate/validateMultifile.test.js +17 -18
- package/dist/utils/Validate/validatePage.js +20 -22
- package/dist/utils/Validate/validatePage.test.js +146 -143
- package/dist/utils/Validate/validateRegex.js +6 -10
- package/dist/utils/Validate/validateRegex.test.js +17 -17
- package/dist/utils/Validate/validateRequired.js +6 -9
- package/dist/utils/Validate/validateRequired.test.js +19 -19
- package/dist/utils/Validate/validateTextArea.js +6 -9
- package/dist/utils/Validate/validateTextArea.test.js +21 -21
- package/dist/utils/Validate/validateTime.js +8 -16
- package/dist/utils/Validate/validateTime.test.js +15 -15
- package/dist/utils/index.js +10 -12
- package/package.json +9 -6
|
@@ -9,799 +9,700 @@ var _utils = _interopRequireDefault(require("../../utils"));
|
|
|
9
9
|
var _Collection = require("./Collection");
|
|
10
10
|
var _Container = require("./Container");
|
|
11
11
|
var _FormComponent = _interopRequireDefault(require("./FormComponent"));
|
|
12
|
-
function _interopRequireDefault(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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 exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
describe('components.FormComponent.Collection', function () {
|
|
29
|
-
var ID = 'collection';
|
|
30
|
-
var TEXT_ID = 'text';
|
|
31
|
-
var TEXT_VALUE = 'alpha';
|
|
32
|
-
var FORM_DATA = _defineProperty({}, ID, [_defineProperty({
|
|
33
|
-
id: '1'
|
|
34
|
-
}, TEXT_ID, TEXT_VALUE)]);
|
|
35
|
-
var TEXT_COMPONENT = {
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
// Global imports
|
|
14
|
+
|
|
15
|
+
// Local imports
|
|
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 = {
|
|
36
28
|
id: TEXT_ID,
|
|
37
29
|
fieldId: TEXT_ID,
|
|
38
30
|
type: _models.ComponentTypes.TEXT,
|
|
39
31
|
label: 'Text component',
|
|
40
32
|
hint: 'Text hint'
|
|
41
33
|
};
|
|
42
|
-
it('should render a collection component appropriately',
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
NEW_TEXT_VALUE = 'bravo';
|
|
125
|
-
EVENT = {
|
|
126
|
-
target: {
|
|
127
|
-
name: TEXT_ID,
|
|
128
|
-
value: NEW_TEXT_VALUE
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
_react.fireEvent.change(input, EVENT);
|
|
132
|
-
|
|
133
|
-
// And confirm the formData has been changed.
|
|
134
|
-
expect(ON_CHANGE_EVENTS.length).toEqual(1);
|
|
135
|
-
expect(ON_CHANGE_EVENTS[0].target.name).toEqual(ID);
|
|
136
|
-
expect(ON_CHANGE_EVENTS[0].target.value[0][TEXT_ID]).toEqual(NEW_TEXT_VALUE);
|
|
137
|
-
case 14:
|
|
138
|
-
case "end":
|
|
139
|
-
return _context2.stop();
|
|
140
|
-
}
|
|
141
|
-
}, _callee2);
|
|
142
|
-
})));
|
|
143
|
-
it('should handle a null value appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
144
|
-
var COLLECTION, _renderWithValidation3, container, c, buttonGroup, button;
|
|
145
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
146
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
147
|
-
case 0:
|
|
148
|
-
COLLECTION = {
|
|
149
|
-
id: ID,
|
|
150
|
-
fieldId: ID,
|
|
151
|
-
type: _models.ComponentTypes.COLLECTION,
|
|
152
|
-
item: [TEXT_COMPONENT]
|
|
153
|
-
};
|
|
154
|
-
_renderWithValidation3 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
155
|
-
component: COLLECTION
|
|
156
|
-
})), container = _renderWithValidation3.container; // Check the container itself.
|
|
157
|
-
c = container.childNodes[0];
|
|
158
|
-
expect(c.tagName).toEqual('DIV');
|
|
159
|
-
expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
|
|
160
|
-
|
|
161
|
-
// And now make sure it has no children OTHER than the button to add an item.
|
|
162
|
-
expect(c.childNodes.length).toEqual(1);
|
|
163
|
-
buttonGroup = c.childNodes[0];
|
|
164
|
-
expect(buttonGroup.tagName).toEqual('DIV');
|
|
165
|
-
expect(buttonGroup.classList).toContain('hods-button-group');
|
|
166
|
-
button = buttonGroup.childNodes[0];
|
|
167
|
-
expect(button.tagName).toEqual('BUTTON');
|
|
168
|
-
expect(button.classList).toContain('hods-button');
|
|
169
|
-
expect(button.classList).toContain('hods-button--secondary');
|
|
170
|
-
expect(button.textContent).toContain(_models.CollectionLabels.add);
|
|
171
|
-
case 14:
|
|
172
|
-
case "end":
|
|
173
|
-
return _context3.stop();
|
|
174
|
-
}
|
|
175
|
-
}, _callee3);
|
|
176
|
-
})));
|
|
177
|
-
it('should handle a collection label appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
178
|
-
var LABEL, COLLECTION, _renderWithValidation4, container, c, _c$childNodes, title, buttonGroup, button;
|
|
179
|
-
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
180
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
181
|
-
case 0:
|
|
182
|
-
LABEL = 'Alpha Collection';
|
|
183
|
-
COLLECTION = {
|
|
184
|
-
id: ID,
|
|
185
|
-
fieldId: ID,
|
|
186
|
-
type: _models.ComponentTypes.COLLECTION,
|
|
187
|
-
item: [TEXT_COMPONENT],
|
|
188
|
-
label: LABEL
|
|
189
|
-
};
|
|
190
|
-
_renderWithValidation4 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
191
|
-
component: COLLECTION
|
|
192
|
-
})), container = _renderWithValidation4.container; // Check the container itself.
|
|
193
|
-
c = container.childNodes[0];
|
|
194
|
-
expect(c.tagName).toEqual('DIV');
|
|
195
|
-
expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
|
|
196
|
-
|
|
197
|
-
// And now make sure it has no children OTHER than the button to add an item.
|
|
198
|
-
expect(c.childNodes.length).toEqual(2);
|
|
199
|
-
_c$childNodes = _slicedToArray(c.childNodes, 2), title = _c$childNodes[0], buttonGroup = _c$childNodes[1];
|
|
200
|
-
expect(title.tagName).toEqual('LABEL');
|
|
201
|
-
expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__title"));
|
|
202
|
-
expect(title.getAttribute('for')).toEqual(ID);
|
|
203
|
-
expect(title.textContent).toContain(LABEL);
|
|
204
|
-
expect(buttonGroup.tagName).toEqual('DIV');
|
|
205
|
-
expect(buttonGroup.classList).toContain('hods-button-group');
|
|
206
|
-
button = buttonGroup.childNodes[0];
|
|
207
|
-
expect(button.tagName).toEqual('BUTTON');
|
|
208
|
-
expect(button.classList).toContain('hods-button');
|
|
209
|
-
expect(button.classList).toContain('hods-button--secondary');
|
|
210
|
-
expect(button.textContent).toContain(_models.CollectionLabels.add);
|
|
211
|
-
case 19:
|
|
212
|
-
case "end":
|
|
213
|
-
return _context4.stop();
|
|
214
|
-
}
|
|
215
|
-
}, _callee4);
|
|
216
|
-
})));
|
|
217
|
-
it('should handle the addition and removal of an item', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
218
|
-
var COLLECTION, container, c, addButton, item, label, removeButton;
|
|
219
|
-
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
220
|
-
while (1) switch (_context6.prev = _context6.next) {
|
|
221
|
-
case 0:
|
|
222
|
-
COLLECTION = {
|
|
223
|
-
id: ID,
|
|
224
|
-
fieldId: ID,
|
|
225
|
-
type: _models.ComponentTypes.COLLECTION,
|
|
226
|
-
item: [TEXT_COMPONENT]
|
|
227
|
-
};
|
|
228
|
-
container = document.createElement('div');
|
|
229
|
-
document.body.appendChild(container);
|
|
230
|
-
_context6.next = 5;
|
|
231
|
-
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
232
|
-
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
233
|
-
while (1) switch (_context5.prev = _context5.next) {
|
|
234
|
-
case 0:
|
|
235
|
-
(0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
236
|
-
component: COLLECTION
|
|
237
|
-
}), container);
|
|
238
|
-
case 1:
|
|
239
|
-
case "end":
|
|
240
|
-
return _context5.stop();
|
|
241
|
-
}
|
|
242
|
-
}, _callee5);
|
|
243
|
-
})));
|
|
244
|
-
case 5:
|
|
245
|
-
// Check the container itself.
|
|
246
|
-
c = container.childNodes[0];
|
|
247
|
-
expect(c.tagName).toEqual('DIV');
|
|
248
|
-
expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
|
|
249
|
-
|
|
250
|
-
// And now make sure it has no children OTHER than the button to add an item.
|
|
251
|
-
expect(c.childNodes.length).toEqual(1);
|
|
252
|
-
|
|
253
|
-
// Get hold of that "Add another" button and click it.
|
|
254
|
-
addButton = c.childNodes[0].childNodes[0];
|
|
255
|
-
_react.fireEvent.click(addButton, {});
|
|
256
|
-
|
|
257
|
-
// Make sure an item has been added.
|
|
258
|
-
expect(c.childNodes.length).toEqual(2);
|
|
259
|
-
item = c.childNodes[0];
|
|
260
|
-
label = item.childNodes[0];
|
|
261
|
-
expect(label.textContent).toContain(_utils.default.interpolateString(_models.CollectionLabels.item, {
|
|
262
|
-
index: 1
|
|
263
|
-
}));
|
|
264
|
-
|
|
265
|
-
// Get hold of the newly-add item's "Remove" button.
|
|
266
|
-
removeButton = label.childNodes[1];
|
|
267
|
-
expect(removeButton.tagName).toEqual('BUTTON');
|
|
268
|
-
expect(removeButton.classList).toContain('hods-button--secondary');
|
|
269
|
-
expect(removeButton.textContent).toContain(_models.CollectionLabels.remove);
|
|
270
|
-
|
|
271
|
-
// Click the "Remove" button
|
|
272
|
-
_react.fireEvent.click(removeButton, {});
|
|
273
|
-
|
|
274
|
-
// Make sure the item has been removed.
|
|
275
|
-
expect(c.childNodes.length).toEqual(1);
|
|
276
|
-
expect(c.childNodes[0].classList).toContain('hods-button-group');
|
|
277
|
-
case 22:
|
|
278
|
-
case "end":
|
|
279
|
-
return _context6.stop();
|
|
280
|
-
}
|
|
281
|
-
}, _callee6);
|
|
282
|
-
})));
|
|
283
|
-
it('should handle the alternative styling', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
|
284
|
-
var COLLECTION, container, c, addButton, item, label, removeButton;
|
|
285
|
-
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
286
|
-
while (1) switch (_context8.prev = _context8.next) {
|
|
287
|
-
case 0:
|
|
288
|
-
COLLECTION = {
|
|
289
|
-
id: ID,
|
|
290
|
-
fieldId: ID,
|
|
291
|
-
type: _models.ComponentTypes.COLLECTION,
|
|
292
|
-
item: [TEXT_COMPONENT],
|
|
293
|
-
removeLocation: 'end'
|
|
294
|
-
};
|
|
295
|
-
container = document.createElement('div');
|
|
296
|
-
document.body.appendChild(container);
|
|
297
|
-
_context8.next = 5;
|
|
298
|
-
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
299
|
-
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
300
|
-
while (1) switch (_context7.prev = _context7.next) {
|
|
301
|
-
case 0:
|
|
302
|
-
(0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
303
|
-
component: COLLECTION
|
|
304
|
-
}), container);
|
|
305
|
-
case 1:
|
|
306
|
-
case "end":
|
|
307
|
-
return _context7.stop();
|
|
308
|
-
}
|
|
309
|
-
}, _callee7);
|
|
310
|
-
})));
|
|
311
|
-
case 5:
|
|
312
|
-
// Check the container itself.
|
|
313
|
-
c = container.childNodes[0];
|
|
314
|
-
expect(c.tagName).toEqual('DIV');
|
|
315
|
-
expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
|
|
316
|
-
|
|
317
|
-
// And now make sure it has no children OTHER than the button to add an item.
|
|
318
|
-
expect(c.childNodes.length).toEqual(1);
|
|
319
|
-
|
|
320
|
-
// Get hold of that "Add another" button and click it.
|
|
321
|
-
addButton = c.childNodes[0].childNodes[0];
|
|
322
|
-
_react.fireEvent.click(addButton, {});
|
|
323
|
-
|
|
324
|
-
// Make sure an item has been added.
|
|
325
|
-
expect(c.childNodes.length).toEqual(2);
|
|
326
|
-
item = c.childNodes[0];
|
|
327
|
-
label = item.childNodes[0];
|
|
328
|
-
expect(label.textContent).toContain(_utils.default.interpolateString(_models.CollectionLabels.item, {
|
|
329
|
-
index: 1
|
|
330
|
-
}));
|
|
331
|
-
|
|
332
|
-
// Get hold of the newly-add item's "Remove" button.
|
|
333
|
-
removeButton = item.childNodes[2].childNodes[0];
|
|
334
|
-
expect(removeButton.tagName).toEqual('BUTTON');
|
|
335
|
-
expect(removeButton.classList).toContain('hods-button--secondary');
|
|
336
|
-
expect(removeButton.textContent).toContain(_models.CollectionLabels.remove);
|
|
337
|
-
|
|
338
|
-
// Click the "Remove" button
|
|
339
|
-
_react.fireEvent.click(removeButton, {});
|
|
340
|
-
|
|
341
|
-
// Make sure the item has been removed.
|
|
342
|
-
expect(c.childNodes.length).toEqual(1);
|
|
343
|
-
expect(c.childNodes[0].classList).toContain('hods-button-group');
|
|
344
|
-
case 22:
|
|
345
|
-
case "end":
|
|
346
|
-
return _context8.stop();
|
|
347
|
-
}
|
|
348
|
-
}, _callee8);
|
|
349
|
-
})));
|
|
350
|
-
it('should appropriately make child components of items readonly', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
|
|
351
|
-
var COLLECTION, _renderWithValidation5, container, c, item, _item$childNodes2, title, itemContainer, formGroup, label, hint, input;
|
|
352
|
-
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
353
|
-
while (1) switch (_context9.prev = _context9.next) {
|
|
354
|
-
case 0:
|
|
355
|
-
COLLECTION = {
|
|
356
|
-
id: ID,
|
|
357
|
-
fieldId: ID,
|
|
358
|
-
type: _models.ComponentTypes.COLLECTION,
|
|
359
|
-
item: [TEXT_COMPONENT],
|
|
360
|
-
readonly: true
|
|
361
|
-
};
|
|
362
|
-
_renderWithValidation5 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
363
|
-
component: COLLECTION,
|
|
364
|
-
value: FORM_DATA[ID],
|
|
365
|
-
formData: FORM_DATA
|
|
366
|
-
})), container = _renderWithValidation5.container; // Check the container itself.
|
|
367
|
-
c = container.childNodes[0];
|
|
368
|
-
expect(c.tagName).toEqual('DIV');
|
|
369
|
-
expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
|
|
370
|
-
|
|
371
|
-
// And now check the single text component within it.
|
|
372
|
-
item = c.childNodes[0];
|
|
373
|
-
expect(item.tagName).toEqual('DIV');
|
|
374
|
-
expect(item.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
|
|
375
|
-
_item$childNodes2 = _slicedToArray(item.childNodes, 2), title = _item$childNodes2[0], itemContainer = _item$childNodes2[1];
|
|
376
|
-
expect(title.tagName).toEqual('LABEL');
|
|
377
|
-
expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
|
|
378
|
-
expect(itemContainer.tagName).toEqual('DIV');
|
|
379
|
-
expect(itemContainer.classList).toContain(_Container.DEFAULT_CLASS);
|
|
380
|
-
formGroup = itemContainer.childNodes[0];
|
|
381
|
-
expect(formGroup.tagName).toEqual('DIV');
|
|
382
|
-
expect(formGroup.classList).toContain('govuk-form-group');
|
|
383
|
-
label = formGroup.childNodes[0];
|
|
384
|
-
expect(label.tagName).toEqual('LABEL');
|
|
385
|
-
expect(label.classList).toContain('govuk-label');
|
|
386
|
-
expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
387
|
-
expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
388
|
-
hint = formGroup.childNodes[1];
|
|
389
|
-
expect(hint.tagName).toEqual('DIV');
|
|
390
|
-
expect(hint.classList).toContain('govuk-hint');
|
|
391
|
-
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
392
|
-
input = formGroup.childNodes[2];
|
|
393
|
-
expect(input.tagName).toEqual('DIV'); // Now readonly, so a DIV.
|
|
394
|
-
expect(input.classList).toContain('hods-readonly'); // Now readonly, so hods-readonly
|
|
395
|
-
expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
396
|
-
expect(input.textContent).toEqual(TEXT_VALUE);
|
|
397
|
-
case 30:
|
|
398
|
-
case "end":
|
|
399
|
-
return _context9.stop();
|
|
400
|
-
}
|
|
401
|
-
}, _callee9);
|
|
402
|
-
})));
|
|
403
|
-
it('should render a collection component with minimumEntries appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
|
|
404
|
-
var COLLECTION, _renderWithValidation6, container, c, item, _item$childNodes3, title, itemContainer, formGroup, label, hint, input;
|
|
405
|
-
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
406
|
-
while (1) switch (_context10.prev = _context10.next) {
|
|
407
|
-
case 0:
|
|
408
|
-
COLLECTION = {
|
|
409
|
-
id: ID,
|
|
410
|
-
fieldId: ID,
|
|
411
|
-
type: _models.ComponentTypes.COLLECTION,
|
|
412
|
-
item: [TEXT_COMPONENT],
|
|
413
|
-
minimumEntries: 1
|
|
414
|
-
};
|
|
415
|
-
_renderWithValidation6 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
416
|
-
component: COLLECTION,
|
|
417
|
-
value: [],
|
|
418
|
-
formData: {}
|
|
419
|
-
})), container = _renderWithValidation6.container; // Check the container itself.
|
|
420
|
-
c = container.childNodes[0];
|
|
421
|
-
expect(c.tagName).toEqual('DIV');
|
|
422
|
-
expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
|
|
423
|
-
|
|
424
|
-
// And now check the single text component within it.
|
|
425
|
-
item = c.childNodes[0];
|
|
426
|
-
expect(item.tagName).toEqual('DIV');
|
|
427
|
-
expect(item.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
|
|
428
|
-
_item$childNodes3 = _slicedToArray(item.childNodes, 2), title = _item$childNodes3[0], itemContainer = _item$childNodes3[1];
|
|
429
|
-
expect(title.tagName).toEqual('LABEL');
|
|
430
|
-
expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
|
|
431
|
-
expect(itemContainer.tagName).toEqual('DIV');
|
|
432
|
-
expect(itemContainer.classList).toContain(_Container.DEFAULT_CLASS);
|
|
433
|
-
formGroup = itemContainer.childNodes[0];
|
|
434
|
-
expect(formGroup.tagName).toEqual('DIV');
|
|
435
|
-
expect(formGroup.classList).toContain('govuk-form-group');
|
|
436
|
-
label = formGroup.childNodes[0];
|
|
437
|
-
expect(label.tagName).toEqual('LABEL');
|
|
438
|
-
expect(label.classList).toContain('govuk-label');
|
|
439
|
-
expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
440
|
-
expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
441
|
-
hint = formGroup.childNodes[1];
|
|
442
|
-
expect(hint.tagName).toEqual('DIV');
|
|
443
|
-
expect(hint.classList).toContain('govuk-hint');
|
|
444
|
-
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
445
|
-
input = formGroup.childNodes[2];
|
|
446
|
-
expect(input.tagName).toEqual('INPUT');
|
|
447
|
-
expect(input.classList).toContain('govuk-input');
|
|
448
|
-
expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
449
|
-
expect(input.value).toEqual('');
|
|
450
|
-
case 30:
|
|
451
|
-
case "end":
|
|
452
|
-
return _context10.stop();
|
|
453
|
-
}
|
|
454
|
-
}, _callee10);
|
|
455
|
-
})));
|
|
456
|
-
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() {
|
|
457
|
-
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;
|
|
458
|
-
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
459
|
-
while (1) switch (_context11.prev = _context11.next) {
|
|
460
|
-
case 0:
|
|
461
|
-
FORM_DATA_TWO_ITEMS = [{
|
|
462
|
-
id: '1',
|
|
463
|
-
text: 'alpha',
|
|
464
|
-
textTwo: 'charlie'
|
|
465
|
-
}, {
|
|
466
|
-
id: '2',
|
|
467
|
-
text: 'beta',
|
|
468
|
-
textTwo: 'delta'
|
|
469
|
-
}];
|
|
470
|
-
TEXT_COMPONENT_TWO = {
|
|
471
|
-
id: 'textTwo',
|
|
472
|
-
fieldId: 'textTwo',
|
|
473
|
-
type: _models.ComponentTypes.TEXT,
|
|
474
|
-
label: 'Text component two',
|
|
475
|
-
hint: 'Text hint two'
|
|
476
|
-
};
|
|
477
|
-
COLLECTION = {
|
|
478
|
-
id: ID,
|
|
479
|
-
fieldId: ID,
|
|
480
|
-
type: _models.ComponentTypes.COLLECTION,
|
|
481
|
-
item: [TEXT_COMPONENT, TEXT_COMPONENT_TWO]
|
|
482
|
-
};
|
|
483
|
-
_renderWithValidation7 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
484
|
-
component: _objectSpread(_objectSpread({}, COLLECTION), {}, {
|
|
485
|
-
restrictHint: true
|
|
486
|
-
}),
|
|
487
|
-
value: FORM_DATA_TWO_ITEMS,
|
|
488
|
-
formData: FORM_DATA
|
|
489
|
-
})), container = _renderWithValidation7.container; // Check the container itself.
|
|
490
|
-
c = container.childNodes[0];
|
|
491
|
-
expect(c.tagName).toEqual('DIV');
|
|
492
|
-
expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
|
|
493
|
-
|
|
494
|
-
// And now check the first text component within it.
|
|
495
|
-
item = c.childNodes[0];
|
|
496
|
-
expect(item.tagName).toEqual('DIV');
|
|
497
|
-
expect(item.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
|
|
498
|
-
_item$childNodes4 = _slicedToArray(item.childNodes, 2), title = _item$childNodes4[0], itemContainer = _item$childNodes4[1];
|
|
499
|
-
expect(title.tagName).toEqual('LABEL');
|
|
500
|
-
expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
|
|
501
|
-
expect(itemContainer.tagName).toEqual('DIV');
|
|
502
|
-
expect(itemContainer.classList).toContain(_Container.DEFAULT_CLASS);
|
|
503
|
-
|
|
504
|
-
// First item component 1
|
|
505
|
-
formGroup = itemContainer.childNodes[0];
|
|
506
|
-
expect(formGroup.tagName).toEqual('DIV');
|
|
507
|
-
expect(formGroup.classList).toContain('govuk-form-group');
|
|
508
|
-
label = formGroup.childNodes[0];
|
|
509
|
-
expect(label.tagName).toEqual('LABEL');
|
|
510
|
-
expect(label.classList).toContain('govuk-label');
|
|
511
|
-
expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
512
|
-
expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
513
|
-
hint = formGroup.childNodes[1];
|
|
514
|
-
expect(hint.tagName).toEqual('DIV');
|
|
515
|
-
expect(hint.classList).toContain('govuk-hint');
|
|
516
|
-
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
517
|
-
input = formGroup.childNodes[2];
|
|
518
|
-
expect(input.tagName).toEqual('INPUT');
|
|
519
|
-
expect(input.classList).toContain('govuk-input');
|
|
520
|
-
expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
521
|
-
expect(input.value).toEqual(TEXT_VALUE);
|
|
522
|
-
|
|
523
|
-
// First item component 2
|
|
524
|
-
formGroup = itemContainer.childNodes[1];
|
|
525
|
-
expect(formGroup.tagName).toEqual('DIV');
|
|
526
|
-
expect(formGroup.classList).toContain('govuk-form-group');
|
|
527
|
-
label = formGroup.childNodes[0];
|
|
528
|
-
expect(label.tagName).toEqual('LABEL');
|
|
529
|
-
expect(label.classList).toContain('govuk-label');
|
|
530
|
-
expect(label.textContent).toEqual('Text component two (optional)');
|
|
531
|
-
expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].textTwo"));
|
|
532
|
-
hint = formGroup.childNodes[1];
|
|
533
|
-
expect(hint.tagName).toEqual('DIV');
|
|
534
|
-
expect(hint.classList).toContain('govuk-hint');
|
|
535
|
-
expect(hint.textContent).toEqual('Text hint two');
|
|
536
|
-
input = formGroup.childNodes[2];
|
|
537
|
-
expect(input.tagName).toEqual('INPUT');
|
|
538
|
-
expect(input.classList).toContain('govuk-input');
|
|
539
|
-
expect(input.id).toEqual("".concat(ID, "[0].textTwo"));
|
|
540
|
-
expect(input.value).toEqual('charlie');
|
|
541
|
-
|
|
542
|
-
// Check the second item and confirm there is no hint
|
|
543
|
-
itemTwo = c.childNodes[1];
|
|
544
|
-
expect(itemTwo.tagName).toEqual('DIV');
|
|
545
|
-
expect(itemTwo.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
|
|
546
|
-
_itemTwo$childNodes = _slicedToArray(itemTwo.childNodes, 2), titleTwo = _itemTwo$childNodes[0], itemContainerTwo = _itemTwo$childNodes[1];
|
|
547
|
-
expect(titleTwo.tagName).toEqual('LABEL');
|
|
548
|
-
expect(titleTwo.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
|
|
549
|
-
expect(itemContainerTwo.tagName).toEqual('DIV');
|
|
550
|
-
expect(itemContainerTwo.classList).toContain(_Container.DEFAULT_CLASS);
|
|
551
|
-
|
|
552
|
-
// Second item first component
|
|
553
|
-
formGroupTwo = itemContainerTwo.childNodes[0];
|
|
554
|
-
expect(formGroupTwo.tagName).toEqual('DIV');
|
|
555
|
-
expect(formGroupTwo.classList).toContain('govuk-form-group');
|
|
556
|
-
labelTwo = formGroupTwo.childNodes[0];
|
|
557
|
-
expect(labelTwo.tagName).toEqual('LABEL');
|
|
558
|
-
expect(labelTwo.classList).toContain('govuk-label');
|
|
559
|
-
expect(labelTwo.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
560
|
-
expect(labelTwo.getAttribute('for')).toEqual("".concat(ID, "[1].").concat(TEXT_ID));
|
|
561
|
-
hintTwo = formGroupTwo.childNodes[1];
|
|
562
|
-
expect(hintTwo.tagName).toEqual(undefined);
|
|
563
|
-
inputTwo = formGroupTwo.childNodes[2];
|
|
564
|
-
expect(inputTwo.tagName).toEqual('INPUT');
|
|
565
|
-
expect(inputTwo.classList).toContain('govuk-input');
|
|
566
|
-
expect(inputTwo.id).toEqual("".concat(ID, "[1].").concat(TEXT_ID));
|
|
567
|
-
expect(inputTwo.value).toEqual('beta');
|
|
568
|
-
|
|
569
|
-
// Second item second component
|
|
570
|
-
formGroupTwo = itemContainerTwo.childNodes[1];
|
|
571
|
-
expect(formGroupTwo.tagName).toEqual('DIV');
|
|
572
|
-
expect(formGroupTwo.classList).toContain('govuk-form-group');
|
|
573
|
-
labelTwo = formGroupTwo.childNodes[0];
|
|
574
|
-
expect(labelTwo.tagName).toEqual('LABEL');
|
|
575
|
-
expect(labelTwo.classList).toContain('govuk-label');
|
|
576
|
-
expect(labelTwo.textContent).toEqual('Text component two (optional)');
|
|
577
|
-
expect(labelTwo.getAttribute('for')).toEqual("".concat(ID, "[1].textTwo"));
|
|
578
|
-
hintTwo = formGroupTwo.childNodes[1];
|
|
579
|
-
expect(hintTwo.tagName).toEqual(undefined);
|
|
580
|
-
inputTwo = formGroupTwo.childNodes[2];
|
|
581
|
-
expect(inputTwo.tagName).toEqual('INPUT');
|
|
582
|
-
expect(inputTwo.classList).toContain('govuk-input');
|
|
583
|
-
expect(inputTwo.id).toEqual("".concat(ID, "[1].textTwo"));
|
|
584
|
-
expect(inputTwo.value).toEqual('delta');
|
|
585
|
-
case 87:
|
|
586
|
-
case "end":
|
|
587
|
-
return _context11.stop();
|
|
588
|
-
}
|
|
589
|
-
}, _callee11);
|
|
590
|
-
})));
|
|
591
|
-
it('should render a unique label for the first item(s) when firstOnlyLabel is defined', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
|
|
592
|
-
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;
|
|
593
|
-
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
594
|
-
while (1) switch (_context12.prev = _context12.next) {
|
|
595
|
-
case 0:
|
|
596
|
-
UNIQUE_FIRST_LABEL_ONE = 'justForTextOne';
|
|
597
|
-
UNIQUE_FIRST_LABEL_TWO = 'justForTextTwo';
|
|
598
|
-
FORM_DATA_TWO_ITEMS = [{
|
|
599
|
-
id: '1',
|
|
600
|
-
text: 'alpha',
|
|
601
|
-
textTwo: 'charlie'
|
|
602
|
-
}, {
|
|
603
|
-
id: '2',
|
|
604
|
-
text: 'beta',
|
|
605
|
-
textTwo: 'delta'
|
|
606
|
-
}];
|
|
607
|
-
TEXT_COMPONENT_TWO = {
|
|
608
|
-
id: 'textTwo',
|
|
609
|
-
fieldId: 'textTwo',
|
|
610
|
-
type: _models.ComponentTypes.TEXT,
|
|
611
|
-
label: 'Text component two',
|
|
612
|
-
hint: 'Text hint two',
|
|
613
|
-
firstOnlyLabel: UNIQUE_FIRST_LABEL_TWO
|
|
614
|
-
};
|
|
615
|
-
COLLECTION = {
|
|
616
|
-
id: ID,
|
|
617
|
-
fieldId: ID,
|
|
618
|
-
type: _models.ComponentTypes.COLLECTION,
|
|
619
|
-
item: [_objectSpread(_objectSpread({}, TEXT_COMPONENT), {}, {
|
|
620
|
-
firstOnlyLabel: UNIQUE_FIRST_LABEL_ONE
|
|
621
|
-
}), TEXT_COMPONENT_TWO]
|
|
622
|
-
};
|
|
623
|
-
_renderWithValidation8 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
624
|
-
component: _objectSpread(_objectSpread({}, COLLECTION), {}, {
|
|
625
|
-
restrictHint: true
|
|
626
|
-
}),
|
|
627
|
-
value: FORM_DATA_TWO_ITEMS,
|
|
628
|
-
formData: FORM_DATA
|
|
629
|
-
})), container = _renderWithValidation8.container; // Check the container itself.
|
|
630
|
-
c = container.childNodes[0];
|
|
631
|
-
expect(c.tagName).toEqual('DIV');
|
|
632
|
-
expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
|
|
633
|
-
|
|
634
|
-
// And now check the first text component within it.
|
|
635
|
-
item = c.childNodes[0];
|
|
636
|
-
expect(item.tagName).toEqual('DIV');
|
|
637
|
-
expect(item.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
|
|
638
|
-
_item$childNodes5 = _slicedToArray(item.childNodes, 2), title = _item$childNodes5[0], itemContainer = _item$childNodes5[1];
|
|
639
|
-
expect(title.tagName).toEqual('LABEL');
|
|
640
|
-
expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
|
|
641
|
-
expect(itemContainer.tagName).toEqual('DIV');
|
|
642
|
-
expect(itemContainer.classList).toContain(_Container.DEFAULT_CLASS);
|
|
643
|
-
|
|
644
|
-
// First item component 1
|
|
645
|
-
formGroup = itemContainer.childNodes[0];
|
|
646
|
-
expect(formGroup.tagName).toEqual('DIV');
|
|
647
|
-
expect(formGroup.classList).toContain('govuk-form-group');
|
|
648
|
-
label = formGroup.childNodes[0];
|
|
649
|
-
expect(label.tagName).toEqual('LABEL');
|
|
650
|
-
expect(label.classList).toContain('govuk-label');
|
|
651
|
-
expect(label.textContent).toEqual("".concat(UNIQUE_FIRST_LABEL_ONE, " (optional)"));
|
|
652
|
-
expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
653
|
-
hint = formGroup.childNodes[1];
|
|
654
|
-
expect(hint.tagName).toEqual('DIV');
|
|
655
|
-
expect(hint.classList).toContain('govuk-hint');
|
|
656
|
-
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
657
|
-
input = formGroup.childNodes[2];
|
|
658
|
-
expect(input.tagName).toEqual('INPUT');
|
|
659
|
-
expect(input.classList).toContain('govuk-input');
|
|
660
|
-
expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
661
|
-
expect(input.value).toEqual(TEXT_VALUE);
|
|
662
|
-
|
|
663
|
-
// First item component 2
|
|
664
|
-
formGroup = itemContainer.childNodes[1];
|
|
665
|
-
expect(formGroup.tagName).toEqual('DIV');
|
|
666
|
-
expect(formGroup.classList).toContain('govuk-form-group');
|
|
667
|
-
label = formGroup.childNodes[0];
|
|
668
|
-
expect(label.tagName).toEqual('LABEL');
|
|
669
|
-
expect(label.classList).toContain('govuk-label');
|
|
670
|
-
expect(label.textContent).toEqual("".concat(UNIQUE_FIRST_LABEL_TWO, " (optional)"));
|
|
671
|
-
expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].textTwo"));
|
|
672
|
-
hint = formGroup.childNodes[1];
|
|
673
|
-
expect(hint.tagName).toEqual('DIV');
|
|
674
|
-
expect(hint.classList).toContain('govuk-hint');
|
|
675
|
-
expect(hint.textContent).toEqual('Text hint two');
|
|
676
|
-
input = formGroup.childNodes[2];
|
|
677
|
-
expect(input.tagName).toEqual('INPUT');
|
|
678
|
-
expect(input.classList).toContain('govuk-input');
|
|
679
|
-
expect(input.id).toEqual("".concat(ID, "[0].textTwo"));
|
|
680
|
-
expect(input.value).toEqual('charlie');
|
|
681
|
-
|
|
682
|
-
// Check the second item and confirm there is no hint
|
|
683
|
-
itemTwo = c.childNodes[1];
|
|
684
|
-
expect(itemTwo.tagName).toEqual('DIV');
|
|
685
|
-
expect(itemTwo.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
|
|
686
|
-
_itemTwo$childNodes2 = _slicedToArray(itemTwo.childNodes, 2), titleTwo = _itemTwo$childNodes2[0], itemContainerTwo = _itemTwo$childNodes2[1];
|
|
687
|
-
expect(titleTwo.tagName).toEqual('LABEL');
|
|
688
|
-
expect(titleTwo.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
|
|
689
|
-
expect(itemContainerTwo.tagName).toEqual('DIV');
|
|
690
|
-
expect(itemContainerTwo.classList).toContain(_Container.DEFAULT_CLASS);
|
|
691
|
-
|
|
692
|
-
// Second item first component
|
|
693
|
-
formGroupTwo = itemContainerTwo.childNodes[0];
|
|
694
|
-
expect(formGroupTwo.tagName).toEqual('DIV');
|
|
695
|
-
expect(formGroupTwo.classList).toContain('govuk-form-group');
|
|
696
|
-
labelTwo = formGroupTwo.childNodes[0];
|
|
697
|
-
expect(labelTwo.tagName).toEqual('LABEL');
|
|
698
|
-
expect(labelTwo.classList).toContain('govuk-label');
|
|
699
|
-
expect(labelTwo.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
700
|
-
expect(labelTwo.getAttribute('for')).toEqual("".concat(ID, "[1].").concat(TEXT_ID));
|
|
701
|
-
hintTwo = formGroupTwo.childNodes[1];
|
|
702
|
-
expect(hintTwo.tagName).toEqual(undefined);
|
|
703
|
-
inputTwo = formGroupTwo.childNodes[2];
|
|
704
|
-
expect(inputTwo.tagName).toEqual('INPUT');
|
|
705
|
-
expect(inputTwo.classList).toContain('govuk-input');
|
|
706
|
-
expect(inputTwo.id).toEqual("".concat(ID, "[1].").concat(TEXT_ID));
|
|
707
|
-
expect(inputTwo.value).toEqual('beta');
|
|
708
|
-
|
|
709
|
-
// Second item second component
|
|
710
|
-
formGroupTwo = itemContainerTwo.childNodes[1];
|
|
711
|
-
expect(formGroupTwo.tagName).toEqual('DIV');
|
|
712
|
-
expect(formGroupTwo.classList).toContain('govuk-form-group');
|
|
713
|
-
labelTwo = formGroupTwo.childNodes[0];
|
|
714
|
-
expect(labelTwo.tagName).toEqual('LABEL');
|
|
715
|
-
expect(labelTwo.classList).toContain('govuk-label');
|
|
716
|
-
expect(labelTwo.textContent).toEqual('Text component two (optional)');
|
|
717
|
-
expect(labelTwo.getAttribute('for')).toEqual("".concat(ID, "[1].textTwo"));
|
|
718
|
-
hintTwo = formGroupTwo.childNodes[1];
|
|
719
|
-
expect(hintTwo.tagName).toEqual(undefined);
|
|
720
|
-
inputTwo = formGroupTwo.childNodes[2];
|
|
721
|
-
expect(inputTwo.tagName).toEqual('INPUT');
|
|
722
|
-
expect(inputTwo.classList).toContain('govuk-input');
|
|
723
|
-
expect(inputTwo.id).toEqual("".concat(ID, "[1].textTwo"));
|
|
724
|
-
expect(inputTwo.value).toEqual('delta');
|
|
725
|
-
case 89:
|
|
726
|
-
case "end":
|
|
727
|
-
return _context12.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(`${_Collection.DEFAULT_CLASS}__item`);
|
|
58
|
+
const [title, itemContainer] = item.childNodes;
|
|
59
|
+
expect(title.tagName).toEqual('LABEL');
|
|
60
|
+
expect(title.classList).toContain(`${_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(`${TEXT_COMPONENT.label} (optional)`);
|
|
70
|
+
expect(label.getAttribute('for')).toEqual(`${ID}[0].${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(`${ID}[0].${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
|
|
728
116
|
}
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
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(`${_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(`${_Collection.DEFAULT_CLASS}__item`);
|
|
311
|
+
const [title, itemContainer] = item.childNodes;
|
|
312
|
+
expect(title.tagName).toEqual('LABEL');
|
|
313
|
+
expect(title.classList).toContain(`${_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(`${TEXT_COMPONENT.label} (optional)`);
|
|
323
|
+
expect(label.getAttribute('for')).toEqual(`${ID}[0].${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(`${ID}[0].${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(`${_Collection.DEFAULT_CLASS}__item`);
|
|
359
|
+
const [title, itemContainer] = item.childNodes;
|
|
360
|
+
expect(title.tagName).toEqual('LABEL');
|
|
361
|
+
expect(title.classList).toContain(`${_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(`${TEXT_COMPONENT.label} (optional)`);
|
|
371
|
+
expect(label.getAttribute('for')).toEqual(`${ID}[0].${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(`${ID}[0].${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(`${_Collection.DEFAULT_CLASS}__item`);
|
|
425
|
+
const [title, itemContainer] = item.childNodes;
|
|
426
|
+
expect(title.tagName).toEqual('LABEL');
|
|
427
|
+
expect(title.classList).toContain(`${_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(`${TEXT_COMPONENT.label} (optional)`);
|
|
439
|
+
expect(label.getAttribute('for')).toEqual(`${ID}[0].${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(`${ID}[0].${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(`${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(`${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(`${_Collection.DEFAULT_CLASS}__item`);
|
|
473
|
+
const [titleTwo, itemContainerTwo] = itemTwo.childNodes;
|
|
474
|
+
expect(titleTwo.tagName).toEqual('LABEL');
|
|
475
|
+
expect(titleTwo.classList).toContain(`${_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(`${TEXT_COMPONENT.label} (optional)`);
|
|
487
|
+
expect(labelTwo.getAttribute('for')).toEqual(`${ID}[1].${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(`${ID}[1].${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(`${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(`${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(`${_Collection.DEFAULT_CLASS}__item`);
|
|
562
|
+
const [title, itemContainer] = item.childNodes;
|
|
563
|
+
expect(title.tagName).toEqual('LABEL');
|
|
564
|
+
expect(title.classList).toContain(`${_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(`${UNIQUE_FIRST_LABEL_ONE} (optional)`);
|
|
576
|
+
expect(label.getAttribute('for')).toEqual(`${ID}[0].${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(`${ID}[0].${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(`${UNIQUE_FIRST_LABEL_TWO} (optional)`);
|
|
595
|
+
expect(label.getAttribute('for')).toEqual(`${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(`${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(`${_Collection.DEFAULT_CLASS}__item`);
|
|
610
|
+
const [titleTwo, itemContainerTwo] = itemTwo.childNodes;
|
|
611
|
+
expect(titleTwo.tagName).toEqual('LABEL');
|
|
612
|
+
expect(titleTwo.classList).toContain(`${_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(`${TEXT_COMPONENT.label} (optional)`);
|
|
624
|
+
expect(labelTwo.getAttribute('for')).toEqual(`${ID}[1].${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(`${ID}[1].${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(`${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(`${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'
|
|
804
659
|
}
|
|
805
|
-
}
|
|
806
|
-
|
|
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
|
+
});
|
|
807
708
|
});
|