@ukhomeoffice/cop-react-form-renderer 4.17.0 → 5.0.0-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/CheckYourAnswers/Answer.js +1 -14
- package/dist/components/CheckYourAnswers/CheckYourAnswers.js +19 -57
- package/dist/components/CheckYourAnswers/index.js +0 -3
- package/dist/components/CollectionPage/CollectionPage.js +8 -38
- package/dist/components/CollectionPage/index.js +0 -3
- package/dist/components/FormComponent/Collection.js +13 -54
- package/dist/components/FormComponent/Container.js +6 -30
- package/dist/components/FormComponent/FormComponent.js +14 -57
- package/dist/components/FormComponent/helpers/addLabel.js +4 -7
- package/dist/components/FormComponent/helpers/getComponentDisabled.js +0 -4
- package/dist/components/FormComponent/helpers/getComponentDisabled.test.js +0 -2
- package/dist/components/FormComponent/helpers/getComponentError.js +0 -6
- package/dist/components/FormComponent/helpers/getComponentError.test.js +0 -2
- package/dist/components/FormComponent/helpers/index.js +0 -4
- package/dist/components/FormComponent/index.js +0 -3
- package/dist/components/FormPage/FormPage.js +14 -45
- package/dist/components/FormPage/index.js +0 -3
- package/dist/components/FormRenderer/FormRenderer.js +106 -189
- package/dist/components/FormRenderer/handlers/cyaAction.js +0 -5
- package/dist/components/FormRenderer/handlers/getPageId.js +0 -2
- package/dist/components/FormRenderer/handlers/getPageId.test.js +1 -2
- package/dist/components/FormRenderer/handlers/handlers.test.js +1 -18
- package/dist/components/FormRenderer/handlers/index.js +0 -5
- package/dist/components/FormRenderer/handlers/navigate.js +0 -5
- package/dist/components/FormRenderer/handlers/submissionError.js +0 -2
- package/dist/components/FormRenderer/helpers/canActionProceed.js +0 -3
- package/dist/components/FormRenderer/helpers/canActionProceed.test.js +1 -3
- package/dist/components/FormRenderer/helpers/canCYASubmit.js +0 -2
- package/dist/components/FormRenderer/helpers/canCYASubmit.test.js +1 -5
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.js +0 -5
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.test.js +1 -2
- package/dist/components/FormRenderer/helpers/getCYA.js +0 -6
- package/dist/components/FormRenderer/helpers/getCYA.test.js +1 -3
- package/dist/components/FormRenderer/helpers/getFormState.js +0 -5
- package/dist/components/FormRenderer/helpers/getFormState.test.js +1 -3
- package/dist/components/FormRenderer/helpers/getNextPageId.js +0 -25
- package/dist/components/FormRenderer/helpers/getNextPageId.test.js +1 -4
- package/dist/components/FormRenderer/helpers/getPage.js +0 -5
- package/dist/components/FormRenderer/helpers/getPage.test.js +1 -3
- package/dist/components/FormRenderer/helpers/getRelevantPages.js +0 -6
- package/dist/components/FormRenderer/helpers/getRelevantPages.test.js +1 -3
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +0 -10
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +0 -6
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.js +6 -20
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.test.js +3 -8
- package/dist/components/FormRenderer/helpers/index.js +1 -11
- package/dist/components/FormRenderer/index.js +0 -3
- package/dist/components/PageActions/ActionButton.js +2 -17
- package/dist/components/PageActions/PageActions.js +3 -10
- package/dist/components/PageActions/index.js +0 -3
- package/dist/components/SummaryList/GroupAction.js +3 -24
- package/dist/components/SummaryList/RowAction.js +3 -23
- package/dist/components/SummaryList/SummaryList.js +6 -28
- package/dist/components/SummaryList/SummaryListRow.js +4 -8
- package/dist/components/SummaryList/SummaryListTitleRow.js +2 -7
- package/dist/components/SummaryList/helpers/getGroupActionAttributes.js +0 -3
- package/dist/components/SummaryList/helpers/getGroupActionAttributes.test.js +0 -6
- package/dist/components/SummaryList/helpers/getRowActionAttributes.js +0 -3
- package/dist/components/SummaryList/helpers/getRowActionAttributes.test.js +0 -6
- package/dist/components/SummaryList/helpers/index.js +0 -2
- package/dist/components/SummaryList/index.js +0 -3
- package/dist/components/TaskList/Task.js +7 -29
- package/dist/components/TaskList/TaskList.js +12 -33
- package/dist/components/TaskList/TaskState.js +2 -10
- package/dist/components/TaskList/index.js +0 -3
- package/dist/components/index.js +0 -6
- package/dist/context/HooksContext/HooksContext.js +14 -34
- package/dist/context/HooksContext/index.js +0 -5
- package/dist/context/ValidationContext/ValidationContext.js +8 -34
- package/dist/context/ValidationContext/index.js +0 -5
- package/dist/context/index.js +0 -3
- package/dist/hooks/index.js +0 -9
- package/dist/hooks/useAxios.js +8 -25
- package/dist/hooks/useGetRequest.js +13 -47
- package/dist/hooks/useHooks.js +2 -4
- package/dist/hooks/useRefData.js +8 -37
- package/dist/hooks/useValidation.js +2 -4
- package/dist/index.js +0 -6
- package/dist/models/PageAction.js +0 -3
- package/dist/models/TaskStates.js +0 -3
- package/dist/models/index.js +0 -9
- package/dist/utils/CheckYourAnswers/getCYAAction.js +1 -9
- package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.js +0 -10
- package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.js +0 -8
- package/dist/utils/CheckYourAnswers/getCYARow.js +1 -10
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.js +2 -20
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.js +0 -18
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +0 -20
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.js +0 -13
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +2 -22
- package/dist/utils/CheckYourAnswers/index.js +1 -3
- package/dist/utils/CheckYourAnswers/showComponentCYA.js +2 -11
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.js +0 -11
- package/dist/utils/CollectionPage/getCollectionPageActiveIndex.js +0 -6
- package/dist/utils/CollectionPage/index.js +1 -5
- package/dist/utils/CollectionPage/mergeCollectionPages.js +1 -12
- package/dist/utils/Component/cleanAttributes.js +1 -8
- package/dist/utils/Component/elevateNestedComponents.js +0 -3
- package/dist/utils/Component/getComponent.js +4 -68
- package/dist/utils/Component/getComponentTests/getComponent.autocomplete.test.js +6 -10
- package/dist/utils/Component/getComponentTests/getComponent.calculation.test.js +10 -28
- package/dist/utils/Component/getComponentTests/getComponent.checkboxes.test.js +6 -33
- package/dist/utils/Component/getComponentTests/getComponent.date.test.js +10 -27
- package/dist/utils/Component/getComponentTests/getComponent.details.test.js +4 -10
- package/dist/utils/Component/getComponentTests/getComponent.email.test.js +4 -21
- package/dist/utils/Component/getComponentTests/getComponent.file.test.js +4 -22
- package/dist/utils/Component/getComponentTests/getComponent.heading.test.js +3 -7
- package/dist/utils/Component/getComponentTests/getComponent.html.test.js +4 -10
- package/dist/utils/Component/getComponentTests/getComponent.insetText.test.js +3 -7
- package/dist/utils/Component/getComponentTests/getComponent.nested.test.js +6 -15
- package/dist/utils/Component/getComponentTests/getComponent.phoneNumber.test.js +4 -21
- package/dist/utils/Component/getComponentTests/getComponent.radios.test.js +6 -33
- package/dist/utils/Component/getComponentTests/getComponent.select.test.js +4 -21
- package/dist/utils/Component/getComponentTests/getComponent.text.test.js +4 -21
- package/dist/utils/Component/getComponentTests/getComponent.textarea.test.js +4 -21
- package/dist/utils/Component/getComponentTests/getComponent.time.test.js +10 -29
- package/dist/utils/Component/getComponentTests/getComponent.unknown.test.js +1 -2
- package/dist/utils/Component/getComponentTests/getComponent.warningText.test.js +3 -7
- package/dist/utils/Component/getDefaultValue.js +0 -7
- package/dist/utils/Component/index.js +0 -9
- package/dist/utils/Component/isEditable.js +1 -4
- package/dist/utils/Component/showComponent.js +1 -8
- package/dist/utils/Component/wrapInFormGroup.js +0 -7
- package/dist/utils/Condition/index.js +0 -5
- package/dist/utils/Condition/meetsAllConditions.js +0 -9
- package/dist/utils/Condition/meetsCondition.js +7 -19
- package/dist/utils/Condition/meetsOneCondition.js +1 -9
- package/dist/utils/Condition/setupConditions.js +0 -12
- package/dist/utils/Container/getEditableComponents.js +0 -7
- package/dist/utils/Container/index.js +0 -5
- package/dist/utils/Container/setupNesting.js +0 -11
- package/dist/utils/Container/showContainer.js +9 -18
- package/dist/utils/Data/applyFormula.js +2 -28
- package/dist/utils/Data/getAutocompleteSource.js +1 -4
- package/dist/utils/Data/getDataPath.js +3 -17
- package/dist/utils/Data/getOptions.js +0 -9
- package/dist/utils/Data/getSourceData.js +4 -19
- package/dist/utils/Data/index.js +1 -11
- package/dist/utils/Data/refDataToOptions.js +1 -12
- package/dist/utils/Data/setDataItem.js +0 -5
- package/dist/utils/Data/setupFormData.js +2 -20
- package/dist/utils/Data/setupRefDataUrlForComponent.js +0 -14
- package/dist/utils/FormPage/getFormPage.js +0 -15
- package/dist/utils/FormPage/getFormPages.js +0 -8
- package/dist/utils/FormPage/getPageActions.js +3 -18
- package/dist/utils/FormPage/getParagraphFromText.js +0 -3
- package/dist/utils/FormPage/index.js +0 -6
- package/dist/utils/FormPage/showFormPage.js +9 -18
- package/dist/utils/FormPage/showFormPageCYA.js +0 -5
- package/dist/utils/FormPage/useComponent.js +3 -18
- package/dist/utils/Format/formatData.js +0 -5
- package/dist/utils/Format/formatDataForComponent.js +1 -6
- package/dist/utils/Format/formatDataForForm.js +0 -8
- package/dist/utils/Format/formatDataForPage.js +1 -5
- package/dist/utils/Format/index.js +1 -6
- package/dist/utils/Hub/getFormHub.js +0 -8
- package/dist/utils/Hub/index.js +1 -3
- package/dist/utils/Meta/documents/getDocuments.js +1 -4
- package/dist/utils/Meta/documents/getDocuments.test.js +0 -9
- package/dist/utils/Meta/documents/index.js +1 -5
- package/dist/utils/Meta/documents/setDocumentForField.js +0 -11
- package/dist/utils/Meta/documents/setDocumentForField.test.js +0 -11
- package/dist/utils/Meta/index.js +2 -6
- package/dist/utils/Operate/checkValueIsTruthy.js +1 -7
- package/dist/utils/Operate/getIndexOfMatchingValueIn.js +7 -21
- package/dist/utils/Operate/index.js +0 -3
- package/dist/utils/Operate/persistValueInFormData.js +1 -8
- package/dist/utils/Operate/runPageOperations.js +3 -18
- package/dist/utils/Operate/setValueInFormData.js +2 -7
- package/dist/utils/Operate/shouldRun.js +1 -14
- package/dist/utils/Validate/additional/index.js +1 -18
- package/dist/utils/Validate/additional/index.test.js +0 -6
- package/dist/utils/Validate/additional/mustBeAfter.js +3 -8
- package/dist/utils/Validate/additional/mustBeAfter.test.js +0 -4
- package/dist/utils/Validate/additional/mustBeBefore.js +3 -8
- package/dist/utils/Validate/additional/mustBeBefore.test.js +0 -4
- package/dist/utils/Validate/additional/mustBeEarlierDateTime.js +5 -16
- package/dist/utils/Validate/additional/mustBeEarlierDateTime.test.js +0 -7
- package/dist/utils/Validate/additional/mustBeInTheFuture.js +3 -12
- package/dist/utils/Validate/additional/mustBeInTheFuture.test.js +0 -3
- package/dist/utils/Validate/additional/mustBeInThePast.js +5 -13
- package/dist/utils/Validate/additional/mustBeInThePast.test.js +0 -3
- package/dist/utils/Validate/additional/mustBeLessThan.js +0 -3
- package/dist/utils/Validate/additional/mustBeLessThan.test.js +0 -2
- package/dist/utils/Validate/additional/mustBeLongerThan.js +0 -3
- package/dist/utils/Validate/additional/mustBeLongerThan.test.js +0 -2
- package/dist/utils/Validate/additional/mustBeNumbersOnly.js +0 -4
- package/dist/utils/Validate/additional/mustBeNumbersOnly.test.js +0 -2
- package/dist/utils/Validate/additional/mustBeShorterThan.js +0 -3
- package/dist/utils/Validate/additional/mustBeShorterThan.test.js +0 -2
- package/dist/utils/Validate/additional/mustEnterAtLeastOne.js +0 -5
- package/dist/utils/Validate/additional/mustEnterAtLeastOne.test.js +0 -4
- package/dist/utils/Validate/additional/utils.js +8 -24
- package/dist/utils/Validate/index.js +1 -9
- package/dist/utils/Validate/validateCollection.js +0 -9
- package/dist/utils/Validate/validateComponent.js +2 -35
- package/dist/utils/Validate/validateContainer.js +0 -13
- package/dist/utils/Validate/validateDate.js +4 -36
- package/dist/utils/Validate/validateEmail.js +1 -7
- package/dist/utils/Validate/validatePage.js +0 -15
- package/dist/utils/Validate/validateRegex.js +0 -10
- package/dist/utils/Validate/validateRequired.js +0 -8
- package/dist/utils/Validate/validateTime.js +3 -20
- package/dist/utils/index.js +0 -19
- package/package.json +50 -34
- package/dist/components/CheckYourAnswers/Answer.test.js +0 -95
- package/dist/components/CheckYourAnswers/CheckYourAnswers.stories.mdx +0 -410
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +0 -680
- package/dist/components/CollectionPage/CollectionPage.test.js +0 -428
- package/dist/components/FormComponent/Collection.test.js +0 -381
- package/dist/components/FormComponent/Container.test.js +0 -423
- package/dist/components/FormComponent/FormComponent.stories.mdx +0 -184
- package/dist/components/FormComponent/FormComponent.test.js +0 -264
- package/dist/components/FormPage/FormPage.stories.mdx +0 -131
- package/dist/components/FormPage/FormPage.test.js +0 -368
- package/dist/components/FormRenderer/FormRenderer.stories.mdx +0 -183
- package/dist/components/FormRenderer/FormRenderer.test.js +0 -1006
- package/dist/components/PageActions/ActionButton.test.js +0 -116
- package/dist/components/PageActions/PageActions.stories.mdx +0 -74
- package/dist/components/PageActions/PageActions.test.js +0 -157
- package/dist/components/SummaryList/GroupAction.test.js +0 -94
- package/dist/components/SummaryList/RowAction.test.js +0 -94
- package/dist/components/SummaryList/SummaryList.stories.mdx +0 -90
- package/dist/components/SummaryList/SummaryList.test.js +0 -361
- package/dist/components/TaskList/Task.test.js +0 -194
- package/dist/components/TaskList/TaskList.stories.mdx +0 -164
- package/dist/components/TaskList/TaskList.test.js +0 -334
- package/dist/components/TaskList/TaskState.test.js +0 -104
- package/dist/context/HooksContext/HooksContext.test.js +0 -60
- package/dist/context/ValidationContext/ValidationContext.test.js +0 -98
- package/dist/json/areYouACivilServant.json +0 -7
- package/dist/json/firstForm.json +0 -94
- package/dist/json/grade.json +0 -108
- package/dist/json/group.data.json +0 -21
- package/dist/json/group.json +0 -402
- package/dist/json/groupOfRow.json +0 -137
- package/dist/json/groupOfRowData.json +0 -15
- package/dist/json/port.json +0 -346
- package/dist/json/saveAndContinue.json +0 -98
- package/dist/json/sublocation.json +0 -859
- package/dist/json/taskList.json +0 -265
- package/dist/json/team.json +0 -17351
- package/dist/json/terminal.json +0 -81
- package/dist/json/userProfile.data.json +0 -21
- package/dist/json/userProfile.json +0 -276
- package/dist/setupTests.js +0 -59
- package/dist/utils/CheckYourAnswers/getCYAAction.test.js +0 -139
- package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.test.js +0 -76
- package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.test.js +0 -59
- package/dist/utils/CheckYourAnswers/getCYARow.test.js +0 -256
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.test.js +0 -77
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.test.js +0 -199
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +0 -170
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.test.js +0 -323
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.test.js +0 -281
- package/dist/utils/CheckYourAnswers/showComponentCYA.test.js +0 -64
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.test.js +0 -41
- package/dist/utils/CollectionPage/getCollectionPageActiveIndex.test.js +0 -54
- package/dist/utils/CollectionPage/mergeCollectionPages.test.js +0 -131
- package/dist/utils/Component/cleanAttributes.test.js +0 -69
- package/dist/utils/Component/elevateNestedComponents.test.js +0 -92
- package/dist/utils/Component/getDefaultValue.test.js +0 -53
- package/dist/utils/Component/isEditable.test.js +0 -42
- package/dist/utils/Component/showComponent.test.js +0 -157
- package/dist/utils/Condition/meetsAllConditions.test.js +0 -62
- package/dist/utils/Condition/meetsCondition.test.js +0 -391
- package/dist/utils/Condition/meetsOneCondition.test.js +0 -101
- package/dist/utils/Condition/setupConditions.test.js +0 -35
- package/dist/utils/Container/getEditableComponents.test.js +0 -146
- package/dist/utils/Container/setupNesting.test.js +0 -92
- package/dist/utils/Container/showContainer.test.js +0 -179
- package/dist/utils/Data/applyFormula.test.js +0 -264
- package/dist/utils/Data/getAutocompleteSource.test.js +0 -146
- package/dist/utils/Data/getDataPath.test.js +0 -52
- package/dist/utils/Data/getOptions.test.js +0 -71
- package/dist/utils/Data/getSourceData.test.js +0 -141
- package/dist/utils/Data/refDataToOptions.test.js +0 -197
- package/dist/utils/Data/setDataItem.test.js +0 -112
- package/dist/utils/Data/setupFormData.test.js +0 -276
- package/dist/utils/Data/setupRefDataUrlForComponent.test.js +0 -133
- package/dist/utils/FormPage/getFormPage.test.js +0 -205
- package/dist/utils/FormPage/getFormPages.test.js +0 -98
- package/dist/utils/FormPage/getPageActions.test.js +0 -89
- package/dist/utils/FormPage/getParagraphFromText.test.js +0 -29
- package/dist/utils/FormPage/showFormPage.test.js +0 -182
- package/dist/utils/FormPage/showFormPageCYA.test.js +0 -30
- package/dist/utils/FormPage/useComponent.test.js +0 -169
- package/dist/utils/Format/formatData.test.js +0 -46
- package/dist/utils/Format/formatDataForComponent.test.js +0 -161
- package/dist/utils/Format/formatDataForForm.test.js +0 -78
- package/dist/utils/Format/formatDataForPage.test.js +0 -96
- package/dist/utils/Hub/getFormHub.test.js +0 -107
- package/dist/utils/Operate/checkValueIsTruthy.test.js +0 -44
- package/dist/utils/Operate/getIndexOfMatchingValueIn.test.js +0 -159
- package/dist/utils/Operate/persistValueInFormData.test.js +0 -106
- package/dist/utils/Operate/runPageOperations.test.js +0 -107
- package/dist/utils/Operate/setValueInFormData.test.js +0 -46
- package/dist/utils/Operate/shouldRun.test.js +0 -69
- package/dist/utils/Validate/validateCollection.test.js +0 -74
- package/dist/utils/Validate/validateComponent.test.js +0 -267
- package/dist/utils/Validate/validateContainer.test.js +0 -81
- package/dist/utils/Validate/validateDate.test.js +0 -118
- package/dist/utils/Validate/validateEmail.test.js +0 -57
- package/dist/utils/Validate/validatePage.test.js +0 -383
- package/dist/utils/Validate/validateRegex.test.js +0 -41
- package/dist/utils/Validate/validateRequired.test.js +0 -62
- package/dist/utils/Validate/validateTime.test.js +0 -61
|
@@ -4,59 +4,42 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getChildrenJsx = exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
9
|
-
|
|
10
8
|
var _react = _interopRequireDefault(require("react"));
|
|
11
|
-
|
|
12
9
|
var _models = require("../../models");
|
|
13
|
-
|
|
14
10
|
var _Data = _interopRequireDefault(require("../Data"));
|
|
15
|
-
|
|
16
11
|
var _cleanAttributes = _interopRequireDefault(require("./cleanAttributes"));
|
|
17
|
-
|
|
18
12
|
var _isEditable = _interopRequireDefault(require("./isEditable"));
|
|
19
|
-
|
|
20
13
|
var _FormComponent = _interopRequireDefault(require("../../components/FormComponent"));
|
|
21
|
-
|
|
22
14
|
var _wrapInFormGroup = _interopRequireDefault(require("./wrapInFormGroup"));
|
|
23
|
-
|
|
24
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
|
-
|
|
26
16
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
27
|
-
|
|
28
17
|
/**
|
|
29
18
|
* Separate function for each component type for the sake of
|
|
30
19
|
* code clarity - having the additional bits and pieces in the
|
|
31
20
|
* switch statement increases the cyclomatic complexity and
|
|
32
21
|
* makes it much harder to follow what's going on.
|
|
33
22
|
*/
|
|
23
|
+
|
|
34
24
|
var getAutocomplete = function getAutocomplete(config) {
|
|
35
25
|
var attrs = (0, _cleanAttributes.default)(config);
|
|
36
|
-
|
|
37
26
|
var source = _Data.default.getAutocompleteSource(config);
|
|
38
|
-
|
|
39
27
|
return /*#__PURE__*/_react.default.createElement(_copReactComponents.Autocomplete, _extends({}, attrs, {
|
|
40
28
|
source: source
|
|
41
29
|
}));
|
|
42
30
|
};
|
|
43
|
-
|
|
44
31
|
var getCheckboxes = function getCheckboxes(config) {
|
|
45
32
|
var options = [];
|
|
46
|
-
|
|
47
33
|
_Data.default.getOptions(config, function (val) {
|
|
48
34
|
options = val;
|
|
49
35
|
});
|
|
50
|
-
|
|
51
36
|
var attrs = (0, _cleanAttributes.default)(config);
|
|
52
37
|
return /*#__PURE__*/_react.default.createElement(_copReactComponents.Checkboxes, _extends({}, attrs, {
|
|
53
38
|
options: options
|
|
54
39
|
}));
|
|
55
40
|
};
|
|
56
|
-
|
|
57
41
|
var getCalculation = function getCalculation(config) {
|
|
58
42
|
var value = _Data.default.applyFormula(config);
|
|
59
|
-
|
|
60
43
|
if (typeof config.onChange === 'function') {
|
|
61
44
|
if (value !== config.value) {
|
|
62
45
|
config.onChange({
|
|
@@ -67,56 +50,45 @@ var getCalculation = function getCalculation(config) {
|
|
|
67
50
|
});
|
|
68
51
|
}
|
|
69
52
|
}
|
|
70
|
-
|
|
71
53
|
var attrs = (0, _cleanAttributes.default)(config, ['formula']);
|
|
72
54
|
return /*#__PURE__*/_react.default.createElement(_copReactComponents.TextInput, _extends({}, attrs, {
|
|
73
55
|
readonly: true
|
|
74
56
|
}));
|
|
75
57
|
};
|
|
76
|
-
|
|
77
58
|
var getDate = function getDate(config) {
|
|
78
59
|
var attrs = (0, _cleanAttributes.default)(config);
|
|
79
60
|
return /*#__PURE__*/_react.default.createElement(_copReactComponents.DateInput, attrs);
|
|
80
61
|
};
|
|
81
|
-
|
|
82
62
|
var getDetails = function getDetails(config) {
|
|
83
63
|
var attrs = (0, _cleanAttributes.default)(config);
|
|
84
64
|
var html = getHTML(config);
|
|
85
65
|
return /*#__PURE__*/_react.default.createElement(_copReactComponents.Details, attrs, html);
|
|
86
66
|
};
|
|
87
|
-
|
|
88
67
|
var getFileUpload = function getFileUpload(config) {
|
|
89
68
|
var attrs = (0, _cleanAttributes.default)(config);
|
|
90
69
|
return /*#__PURE__*/_react.default.createElement(_copReactComponents.FileUpload, attrs);
|
|
91
70
|
};
|
|
92
|
-
|
|
93
71
|
var getHeading = function getHeading(config) {
|
|
94
72
|
var attrs = (0, _cleanAttributes.default)(config);
|
|
95
73
|
return /*#__PURE__*/_react.default.createElement(_copReactComponents.Heading, attrs, config.content);
|
|
96
74
|
};
|
|
97
|
-
|
|
98
75
|
var getHTML = function getHTML(config) {
|
|
99
76
|
var attrs = (0, _cleanAttributes.default)(config);
|
|
100
77
|
return /*#__PURE__*/_react.default.createElement(_copReactComponents.Markup, attrs);
|
|
101
78
|
};
|
|
102
|
-
|
|
103
79
|
var getInsetText = function getInsetText(config) {
|
|
104
80
|
var attrs = (0, _cleanAttributes.default)(config);
|
|
105
81
|
return /*#__PURE__*/_react.default.createElement(_copReactComponents.InsetText, attrs, config.content);
|
|
106
82
|
};
|
|
107
|
-
|
|
108
83
|
var getRadios = function getRadios(config) {
|
|
109
84
|
var options = [];
|
|
110
|
-
|
|
111
85
|
_Data.default.getOptions(config, function (val) {
|
|
112
86
|
options = val;
|
|
113
87
|
});
|
|
114
|
-
|
|
115
88
|
options.forEach(function (option) {
|
|
116
89
|
if (!Array.isArray(option.nested)) {
|
|
117
90
|
return;
|
|
118
91
|
}
|
|
119
|
-
|
|
120
92
|
option.children = getChildrenJsx(config, option.nested);
|
|
121
93
|
});
|
|
122
94
|
var attrs = (0, _cleanAttributes.default)(config);
|
|
@@ -124,116 +96,88 @@ var getRadios = function getRadios(config) {
|
|
|
124
96
|
options: options
|
|
125
97
|
}));
|
|
126
98
|
};
|
|
127
|
-
|
|
128
99
|
var getTextArea = function getTextArea(config) {
|
|
129
100
|
var attrs = (0, _cleanAttributes.default)(config);
|
|
130
101
|
return /*#__PURE__*/_react.default.createElement(_copReactComponents.TextArea, attrs);
|
|
131
102
|
};
|
|
132
|
-
|
|
133
103
|
var getTextInput = function getTextInput(config) {
|
|
134
104
|
var attrs = (0, _cleanAttributes.default)(config);
|
|
135
105
|
return /*#__PURE__*/_react.default.createElement(_copReactComponents.TextInput, attrs);
|
|
136
106
|
};
|
|
137
|
-
|
|
138
107
|
var getTime = function getTime(config) {
|
|
139
108
|
var attrs = (0, _cleanAttributes.default)(config);
|
|
140
109
|
return /*#__PURE__*/_react.default.createElement(_copReactComponents.TimeInput, attrs);
|
|
141
110
|
};
|
|
142
|
-
|
|
143
111
|
var getSelect = function getSelect(config) {
|
|
144
112
|
var options = [];
|
|
145
|
-
|
|
146
113
|
_Data.default.getOptions(config, function (val) {
|
|
147
114
|
options = val;
|
|
148
115
|
});
|
|
149
|
-
|
|
150
116
|
var attrs = (0, _cleanAttributes.default)(config);
|
|
151
117
|
return /*#__PURE__*/_react.default.createElement(_copReactComponents.Select, _extends({}, attrs, {
|
|
152
118
|
options: options
|
|
153
119
|
}));
|
|
154
120
|
};
|
|
155
|
-
|
|
156
121
|
var getWarningText = function getWarningText(config) {
|
|
157
122
|
var attrs = (0, _cleanAttributes.default)(config);
|
|
158
123
|
return /*#__PURE__*/_react.default.createElement(_copReactComponents.WarningText, attrs, config.content);
|
|
159
124
|
};
|
|
160
|
-
|
|
161
125
|
var getComponentByType = function getComponentByType(config) {
|
|
162
126
|
switch (config.type) {
|
|
163
127
|
case _models.ComponentTypes.HTML:
|
|
164
128
|
return getHTML(config);
|
|
165
|
-
|
|
166
129
|
case _models.ComponentTypes.HEADING:
|
|
167
130
|
return getHeading(config);
|
|
168
|
-
|
|
169
131
|
case _models.ComponentTypes.INSET_TEXT:
|
|
170
132
|
return getInsetText(config);
|
|
171
|
-
|
|
172
133
|
case _models.ComponentTypes.TEXT:
|
|
173
134
|
case _models.ComponentTypes.EMAIL:
|
|
174
135
|
case _models.ComponentTypes.PHONE_NUMBER:
|
|
175
136
|
return getTextInput(config);
|
|
176
|
-
|
|
177
137
|
case _models.ComponentTypes.TEXT_AREA:
|
|
178
138
|
return getTextArea(config);
|
|
179
|
-
|
|
180
139
|
case _models.ComponentTypes.AUTOCOMPLETE:
|
|
181
140
|
return getAutocomplete(config);
|
|
182
|
-
|
|
183
141
|
case _models.ComponentTypes.RADIOS:
|
|
184
142
|
return getRadios(config);
|
|
185
|
-
|
|
186
143
|
case _models.ComponentTypes.CHECKBOXES:
|
|
187
144
|
return getCheckboxes(config);
|
|
188
|
-
|
|
189
145
|
case _models.ComponentTypes.DATE:
|
|
190
146
|
return getDate(config);
|
|
191
|
-
|
|
192
147
|
case _models.ComponentTypes.TIME:
|
|
193
148
|
return getTime(config);
|
|
194
|
-
|
|
195
149
|
case _models.ComponentTypes.FILE:
|
|
196
150
|
return getFileUpload(config);
|
|
197
|
-
|
|
198
151
|
case _models.ComponentTypes.WARNING:
|
|
199
152
|
return getWarningText(config);
|
|
200
|
-
|
|
201
153
|
case _models.ComponentTypes.SELECT:
|
|
202
154
|
return getSelect(config);
|
|
203
|
-
|
|
204
155
|
case _models.ComponentTypes.DETAILS:
|
|
205
156
|
return getDetails(config);
|
|
206
|
-
|
|
207
157
|
case _models.ComponentTypes.CALCULATION:
|
|
208
158
|
return getCalculation(config);
|
|
209
|
-
|
|
210
159
|
default:
|
|
211
160
|
{
|
|
212
161
|
return null;
|
|
213
162
|
}
|
|
214
163
|
}
|
|
215
164
|
};
|
|
165
|
+
|
|
216
166
|
/**
|
|
217
167
|
* Get single child component for a parent
|
|
218
168
|
* @param {*} parent the parent configuration
|
|
219
169
|
* @param {*} child the child configuration
|
|
220
170
|
*/
|
|
221
|
-
|
|
222
|
-
|
|
223
171
|
var getChildJsx = function getChildJsx(parent, child) {
|
|
224
172
|
if (parent.formData) {
|
|
225
173
|
var _parent$formData;
|
|
226
|
-
|
|
227
174
|
child.value = parent !== null && parent !== void 0 && (_parent$formData = parent.formData) !== null && _parent$formData !== void 0 && _parent$formData[child.fieldId] ? parent.formData[child.fieldId] : '';
|
|
228
175
|
}
|
|
229
|
-
|
|
230
176
|
if ('readonly' in child) delete child.readonly;
|
|
231
|
-
|
|
232
177
|
if (parent.readonly) {
|
|
233
178
|
child.readonly = parent.readonly;
|
|
234
179
|
return /*#__PURE__*/_react.default.createElement("div", null, getComponent(child, false));
|
|
235
180
|
}
|
|
236
|
-
|
|
237
181
|
return /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
238
182
|
component: child,
|
|
239
183
|
value: child.value,
|
|
@@ -242,13 +186,12 @@ var getChildJsx = function getChildJsx(parent, child) {
|
|
|
242
186
|
formData: parent.formData
|
|
243
187
|
});
|
|
244
188
|
};
|
|
189
|
+
|
|
245
190
|
/**
|
|
246
191
|
* Convert chidlrenConfigs into components
|
|
247
192
|
* @param {*} parentConfig parent component which the childrenConfigs will be under
|
|
248
193
|
* @param {*} childrenConfigs array of configurations for the child components
|
|
249
194
|
*/
|
|
250
|
-
|
|
251
|
-
|
|
252
195
|
var getChildrenJsx = function getChildrenJsx(parentConfig, childrenConfigs) {
|
|
253
196
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, childrenConfigs.map(function (config) {
|
|
254
197
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, {
|
|
@@ -257,8 +200,6 @@ var getChildrenJsx = function getChildrenJsx(parentConfig, childrenConfigs) {
|
|
|
257
200
|
}));
|
|
258
201
|
};
|
|
259
202
|
|
|
260
|
-
exports.getChildrenJsx = getChildrenJsx;
|
|
261
|
-
|
|
262
203
|
/**
|
|
263
204
|
* Get a renderable component, based on a configuration object.
|
|
264
205
|
* @param {object} config The configuration object for the component.
|
|
@@ -266,26 +207,21 @@ exports.getChildrenJsx = getChildrenJsx;
|
|
|
266
207
|
* @param {Function} fnOverride An optional override function for component rendering.
|
|
267
208
|
* @returns A renderable component.
|
|
268
209
|
*/
|
|
210
|
+
exports.getChildrenJsx = getChildrenJsx;
|
|
269
211
|
var getComponent = function getComponent(config) {
|
|
270
212
|
var wrap = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
271
213
|
var fnOverride = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
|
|
272
|
-
|
|
273
214
|
if (typeof fnOverride === 'function') {
|
|
274
215
|
var overrideComponent = fnOverride(config, wrap);
|
|
275
|
-
|
|
276
216
|
if (overrideComponent) {
|
|
277
217
|
return overrideComponent;
|
|
278
218
|
}
|
|
279
219
|
}
|
|
280
|
-
|
|
281
220
|
var component = getComponentByType(config);
|
|
282
|
-
|
|
283
221
|
if (component && wrap && (0, _isEditable.default)(config)) {
|
|
284
222
|
return (0, _wrapInFormGroup.default)(config, component);
|
|
285
223
|
}
|
|
286
|
-
|
|
287
224
|
return component;
|
|
288
225
|
};
|
|
289
|
-
|
|
290
226
|
var _default = getComponent;
|
|
291
227
|
exports.default = _default;
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _react = require("@testing-library/react");
|
|
4
|
-
|
|
5
4
|
var _models = require("../../../models");
|
|
6
|
-
|
|
7
5
|
var _getComponent = _interopRequireDefault(require("../getComponent"));
|
|
8
|
-
|
|
9
6
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
|
|
11
7
|
// Global imports
|
|
8
|
+
|
|
12
9
|
// Local imports
|
|
10
|
+
|
|
13
11
|
describe('utils.Component.get', function () {
|
|
14
12
|
it('should return an appropriately rendered autocomplete component', function () {
|
|
15
13
|
var ID = 'test-id';
|
|
@@ -26,10 +24,8 @@ describe('utils.Component.get', function () {
|
|
|
26
24
|
},
|
|
27
25
|
'data-testid': ID
|
|
28
26
|
};
|
|
29
|
-
|
|
30
27
|
var _render = (0, _react.render)((0, _getComponent.default)(COMPONENT)),
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
container = _render.container;
|
|
33
29
|
var formGroup = (0, _react.getByTestId)(container, ID);
|
|
34
30
|
expect(formGroup.tagName).toEqual('DIV');
|
|
35
31
|
expect(formGroup.classList).toContain('govuk-form-group');
|
|
@@ -45,7 +41,6 @@ describe('utils.Component.get', function () {
|
|
|
45
41
|
} else if (node.classList.contains('hods-autocomplete__outer-wrapper')) {
|
|
46
42
|
autocompleteWrapper = node;
|
|
47
43
|
var autocompleteInner = node.childNodes[0];
|
|
48
|
-
|
|
49
44
|
if (autocompleteInner instanceof Element) {
|
|
50
45
|
autocomplete = autocompleteInner;
|
|
51
46
|
autocomplete.childNodes.forEach(function (grandchild) {
|
|
@@ -56,7 +51,6 @@ describe('utils.Component.get', function () {
|
|
|
56
51
|
}
|
|
57
52
|
});
|
|
58
53
|
}
|
|
59
|
-
|
|
60
54
|
;
|
|
61
55
|
}
|
|
62
56
|
}
|
|
@@ -69,7 +63,9 @@ describe('utils.Component.get', function () {
|
|
|
69
63
|
expect(autocomplete).toBeDefined();
|
|
70
64
|
expect(autocomplete.tagName).toEqual('DIV');
|
|
71
65
|
expect(autocompleteInput).toBeDefined();
|
|
72
|
-
expect(autocompleteInput.id).toEqual(ID);
|
|
66
|
+
expect(autocompleteInput.id).toEqual(ID);
|
|
67
|
+
|
|
68
|
+
// TODO: Ensure that the onChange handler is fired.
|
|
73
69
|
// Not sure quite what this looks like yet so I'll address it later.
|
|
74
70
|
});
|
|
75
71
|
});
|
|
@@ -1,35 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
3
4
|
var _react = require("@testing-library/react");
|
|
4
|
-
|
|
5
5
|
var _models = require("../../../models");
|
|
6
|
-
|
|
7
6
|
var _getComponent = _interopRequireDefault(require("../getComponent"));
|
|
8
|
-
|
|
9
7
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
|
|
8
|
+
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 method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return 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; }
|
|
11
9
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
12
|
-
|
|
13
10
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
14
|
-
|
|
15
11
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
16
|
-
|
|
17
12
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
18
|
-
|
|
19
13
|
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
20
|
-
|
|
21
14
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
22
|
-
|
|
23
15
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
24
|
-
|
|
25
16
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
26
|
-
|
|
27
17
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
28
|
-
|
|
29
18
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
30
|
-
|
|
31
19
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
32
|
-
|
|
33
20
|
describe('utils.Component.get', function () {
|
|
34
21
|
var ID = 'test-id';
|
|
35
22
|
var FIELD_ID = 'field-id';
|
|
@@ -52,6 +39,7 @@ describe('utils.Component.get', function () {
|
|
|
52
39
|
afterEach(function () {
|
|
53
40
|
error.mockClear();
|
|
54
41
|
});
|
|
42
|
+
|
|
55
43
|
/**
|
|
56
44
|
* Iteratively test collction of positive test data objects each containing:
|
|
57
45
|
* config: object containing formula config
|
|
@@ -67,7 +55,6 @@ describe('utils.Component.get', function () {
|
|
|
67
55
|
* }
|
|
68
56
|
*
|
|
69
57
|
*/
|
|
70
|
-
|
|
71
58
|
[{
|
|
72
59
|
config: {
|
|
73
60
|
formula: {
|
|
@@ -142,11 +129,9 @@ describe('utils.Component.get', function () {
|
|
|
142
129
|
var target = _ref.target;
|
|
143
130
|
COMPONENT.formData[target.name] = target.value;
|
|
144
131
|
};
|
|
145
|
-
|
|
146
|
-
it("should render 'calculation' component with formula to given calculated value: ".concat(test.result), /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
132
|
+
it("should render 'calculation' component with formula to given calculated value: ".concat(test.result), /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
147
133
|
var _render, container, _getAllByTestId, _getAllByTestId2, formGroup, input, label;
|
|
148
|
-
|
|
149
|
-
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
134
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
150
135
|
while (1) {
|
|
151
136
|
switch (_context.prev = _context.next) {
|
|
152
137
|
case 0:
|
|
@@ -163,7 +148,6 @@ describe('utils.Component.get', function () {
|
|
|
163
148
|
expect(input.classList).toContain('hods-readonly');
|
|
164
149
|
expect(input.id).toEqual(ID);
|
|
165
150
|
expect("".concat(COMPONENT.formData[FIELD_ID])).toEqual(test.result);
|
|
166
|
-
|
|
167
151
|
case 13:
|
|
168
152
|
case "end":
|
|
169
153
|
return _context.stop();
|
|
@@ -172,6 +156,7 @@ describe('utils.Component.get', function () {
|
|
|
172
156
|
}, _callee);
|
|
173
157
|
})));
|
|
174
158
|
});
|
|
159
|
+
|
|
175
160
|
/**
|
|
176
161
|
* Iteratively test collction of negative test data objects each containing:
|
|
177
162
|
* config: object containing invalid formula config
|
|
@@ -187,7 +172,6 @@ describe('utils.Component.get', function () {
|
|
|
187
172
|
* }
|
|
188
173
|
*
|
|
189
174
|
*/
|
|
190
|
-
|
|
191
175
|
[{
|
|
192
176
|
error: "Missing 'formula' definition"
|
|
193
177
|
}, {
|
|
@@ -259,13 +243,11 @@ describe('utils.Component.get', function () {
|
|
|
259
243
|
}].forEach(function (test) {
|
|
260
244
|
it("should return an appropriately rendered calculation component with message ".concat(test.result), function () {
|
|
261
245
|
var _render2 = (0, _react.render)((0, _getComponent.default)(_objectSpread(_objectSpread({}, COMPONENT), test.config))),
|
|
262
|
-
|
|
263
|
-
|
|
246
|
+
container = _render2.container;
|
|
264
247
|
var _getAllByTestId3 = (0, _react.getAllByTestId)(container, ID),
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
248
|
+
_getAllByTestId4 = _slicedToArray(_getAllByTestId3, 2),
|
|
249
|
+
formGroup = _getAllByTestId4[0],
|
|
250
|
+
input = _getAllByTestId4[1];
|
|
269
251
|
expect(formGroup.tagName).toEqual('DIV');
|
|
270
252
|
expect(formGroup.classList).toContain('govuk-form-group');
|
|
271
253
|
var label = formGroup.childNodes[0];
|
|
@@ -1,25 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _react = require("@testing-library/react");
|
|
4
|
-
|
|
5
4
|
var _models = require("../../../models");
|
|
6
|
-
|
|
7
5
|
var _getComponent = _interopRequireDefault(require("../getComponent"));
|
|
8
|
-
|
|
9
6
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
|
|
11
7
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
12
|
-
|
|
13
8
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
14
|
-
|
|
15
9
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
16
|
-
|
|
17
10
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
18
|
-
|
|
19
11
|
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
20
|
-
|
|
21
12
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
22
|
-
|
|
23
13
|
describe('utils.Component.get', function () {
|
|
24
14
|
it('should return an appropriately rendered checkboxes component', function () {
|
|
25
15
|
var ID = 'test-id';
|
|
@@ -33,11 +23,9 @@ describe('utils.Component.get', function () {
|
|
|
33
23
|
label: 'Bravo'
|
|
34
24
|
}];
|
|
35
25
|
var ON_CHANGE_CALLS = [];
|
|
36
|
-
|
|
37
26
|
var ON_CHANGE = function ON_CHANGE(e) {
|
|
38
27
|
ON_CHANGE_CALLS.push(e.target);
|
|
39
28
|
};
|
|
40
|
-
|
|
41
29
|
var COMPONENT = {
|
|
42
30
|
type: _models.ComponentTypes.CHECKBOXES,
|
|
43
31
|
id: ID,
|
|
@@ -49,15 +37,12 @@ describe('utils.Component.get', function () {
|
|
|
49
37
|
onChange: ON_CHANGE,
|
|
50
38
|
'data-testid': ID
|
|
51
39
|
};
|
|
52
|
-
|
|
53
40
|
var _render = (0, _react.render)((0, _getComponent.default)(COMPONENT)),
|
|
54
|
-
|
|
55
|
-
|
|
41
|
+
container = _render.container;
|
|
56
42
|
var _getAllByTestId = (0, _react.getAllByTestId)(container, ID),
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
43
|
+
_getAllByTestId2 = _slicedToArray(_getAllByTestId, 2),
|
|
44
|
+
formGroup = _getAllByTestId2[0],
|
|
45
|
+
checkboxes = _getAllByTestId2[1];
|
|
61
46
|
expect(formGroup.tagName).toEqual('DIV');
|
|
62
47
|
expect(formGroup.classList).toContain('govuk-form-group');
|
|
63
48
|
var label = undefined;
|
|
@@ -79,7 +64,6 @@ describe('utils.Component.get', function () {
|
|
|
79
64
|
OPTIONS.forEach(function (_, index) {
|
|
80
65
|
var checkbox = checkboxes.childNodes[index];
|
|
81
66
|
expect(checkbox instanceof Element).toBeTruthy();
|
|
82
|
-
|
|
83
67
|
if (checkbox instanceof Element) {
|
|
84
68
|
checkboxItems.push(checkbox);
|
|
85
69
|
}
|
|
@@ -89,37 +73,26 @@ describe('utils.Component.get', function () {
|
|
|
89
73
|
var checkbox = checkboxItems[index];
|
|
90
74
|
expect(checkbox.tagName).toEqual('DIV');
|
|
91
75
|
expect(checkbox.classList).toContain('govuk-checkboxes__item');
|
|
92
|
-
|
|
93
76
|
var _checkbox$childNodes = _slicedToArray(checkbox.childNodes, 2),
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
77
|
+
input = _checkbox$childNodes[0],
|
|
78
|
+
label = _checkbox$childNodes[1];
|
|
97
79
|
expect(input.tagName).toEqual('INPUT');
|
|
98
80
|
expect(input.type).toEqual('checkbox');
|
|
99
81
|
expect(label.textContent).toEqual(option.label);
|
|
100
82
|
});
|
|
101
|
-
|
|
102
83
|
_react.fireEvent.click(checkboxItems[0].childNodes[0]); // alpha
|
|
103
|
-
|
|
104
|
-
|
|
105
84
|
expect(ON_CHANGE_CALLS.length).toEqual(1);
|
|
106
85
|
expect(ON_CHANGE_CALLS[0]).toMatchObject({
|
|
107
86
|
name: FIELD_ID,
|
|
108
87
|
value: [OPTIONS[0].value]
|
|
109
88
|
});
|
|
110
|
-
|
|
111
89
|
_react.fireEvent.click(checkboxItems[1].childNodes[0]); // beta
|
|
112
|
-
|
|
113
|
-
|
|
114
90
|
expect(ON_CHANGE_CALLS.length).toEqual(2);
|
|
115
91
|
expect(ON_CHANGE_CALLS[1]).toMatchObject({
|
|
116
92
|
name: FIELD_ID,
|
|
117
93
|
value: [OPTIONS[0].value, OPTIONS[1].value]
|
|
118
94
|
});
|
|
119
|
-
|
|
120
95
|
_react.fireEvent.click(checkboxItems[0].childNodes[0]); // alpha (unchecked this time)
|
|
121
|
-
|
|
122
|
-
|
|
123
96
|
expect(ON_CHANGE_CALLS.length).toEqual(3);
|
|
124
97
|
expect(ON_CHANGE_CALLS[2]).toMatchObject({
|
|
125
98
|
name: FIELD_ID,
|