@ukhomeoffice/cop-react-form-renderer 4.18.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
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _models = require("../../models");
|
|
4
|
-
|
|
5
|
-
var _validateContainer = _interopRequireDefault(require("./validateContainer"));
|
|
6
|
-
|
|
7
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
|
-
|
|
9
|
-
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; }
|
|
10
|
-
|
|
11
|
-
describe('utils.Validate.Container', function () {
|
|
12
|
-
var setup = function setup(id, type, label, required, additionalValidation) {
|
|
13
|
-
return {
|
|
14
|
-
id: id,
|
|
15
|
-
fieldId: id,
|
|
16
|
-
type: type,
|
|
17
|
-
label: label,
|
|
18
|
-
required: required,
|
|
19
|
-
additionalValidation: additionalValidation
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
it('should return an empty array when the component is null', function () {
|
|
24
|
-
expect((0, _validateContainer.default)(null, {})).toEqual([]);
|
|
25
|
-
});
|
|
26
|
-
it('should return an empty array when the container has an undefined components array', function () {
|
|
27
|
-
var ID = 'container';
|
|
28
|
-
var LABEL = 'field';
|
|
29
|
-
var CONTAINER = setup(ID, _models.ComponentTypes.CONTAINER, LABEL, false);
|
|
30
|
-
expect((0, _validateContainer.default)(CONTAINER, null)).toEqual([]);
|
|
31
|
-
});
|
|
32
|
-
it('should return an empty array when the container has no components', function () {
|
|
33
|
-
var ID = 'container';
|
|
34
|
-
var LABEL = 'field';
|
|
35
|
-
var CONTAINER = setup(ID, _models.ComponentTypes.CONTAINER, LABEL, false);
|
|
36
|
-
CONTAINER.components = [];
|
|
37
|
-
expect((0, _validateContainer.default)(CONTAINER, null)).toEqual([]);
|
|
38
|
-
});
|
|
39
|
-
it('should return an empty array when the container has only valid components', function () {
|
|
40
|
-
var EMAIL_ID = 'email';
|
|
41
|
-
var EMAIL_LABEL = 'Email';
|
|
42
|
-
var EMAIL = setup(EMAIL_ID, _models.ComponentTypes.EMAIL, EMAIL_LABEL, false);
|
|
43
|
-
var ID = 'container';
|
|
44
|
-
var LABEL = 'field';
|
|
45
|
-
var CONTAINER = setup(ID, _models.ComponentTypes.CONTAINER, LABEL, false);
|
|
46
|
-
CONTAINER.components = [EMAIL];
|
|
47
|
-
|
|
48
|
-
var DATA = _defineProperty({}, ID, _defineProperty({}, EMAIL_ID, 'alpha.bravo@digital.homeoffice.gov.uk'));
|
|
49
|
-
|
|
50
|
-
expect((0, _validateContainer.default)(CONTAINER, DATA)).toEqual([]);
|
|
51
|
-
});
|
|
52
|
-
it('should return an array containing an error when the container has an invalid component', function () {
|
|
53
|
-
var EMAIL_ID = 'email';
|
|
54
|
-
var EMAIL_LABEL = 'Email';
|
|
55
|
-
var EMAIL = setup(EMAIL_ID, _models.ComponentTypes.EMAIL, EMAIL_LABEL, false);
|
|
56
|
-
var ID = 'container';
|
|
57
|
-
var LABEL = 'field';
|
|
58
|
-
var CONTAINER = setup(ID, _models.ComponentTypes.CONTAINER, LABEL, false);
|
|
59
|
-
CONTAINER.components = [EMAIL];
|
|
60
|
-
|
|
61
|
-
var DATA = _defineProperty({}, ID, _defineProperty({}, EMAIL_ID, 'alpha.bravo@digital.homeoffice.com'));
|
|
62
|
-
|
|
63
|
-
expect((0, _validateContainer.default)(CONTAINER, DATA)).toEqual([{
|
|
64
|
-
id: "".concat(ID, ".").concat(EMAIL_ID),
|
|
65
|
-
error: "Enter ".concat(EMAIL_LABEL.toLowerCase(), " in the correct format, like jane.doe@homeoffice.gov.uk")
|
|
66
|
-
}]);
|
|
67
|
-
});
|
|
68
|
-
it('should apply optional validators when specified', function () {
|
|
69
|
-
var ID = 'container';
|
|
70
|
-
var DATA = {};
|
|
71
|
-
var ADDITIONAL_VALIDATION = [{
|
|
72
|
-
function: 'mustEnterAtLeastOne',
|
|
73
|
-
message: 'Must enter at least one'
|
|
74
|
-
}];
|
|
75
|
-
var COMPONENT = setup(ID, _models.ComponentTypes.DATE, null, false, ADDITIONAL_VALIDATION);
|
|
76
|
-
expect((0, _validateContainer.default)(COMPONENT, DATA)).toEqual({
|
|
77
|
-
error: 'Must enter at least one',
|
|
78
|
-
id: ID
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
});
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
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); }
|
|
4
|
-
|
|
5
|
-
var _validateDate = _interopRequireWildcard(require("./validateDate"));
|
|
6
|
-
|
|
7
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
8
|
-
|
|
9
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
10
|
-
|
|
11
|
-
describe('utils', function () {
|
|
12
|
-
describe('Validate', function () {
|
|
13
|
-
describe('date', function () {
|
|
14
|
-
test('should return no error when the value is an empty string', function () {
|
|
15
|
-
expect((0, _validateDate.default)('', 'DD-MM-YYYY')).toEqual({
|
|
16
|
-
message: undefined,
|
|
17
|
-
propsInError: undefined
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
test('should return undefined if a date string is valid', function () {
|
|
21
|
-
var output = (0, _validateDate.default)('28-02-2024', 'DD-MM-YYYY');
|
|
22
|
-
expect(output).toEqual({
|
|
23
|
-
message: undefined,
|
|
24
|
-
propsInError: undefined
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
test('should return undefined to a correct leap year date', function () {
|
|
28
|
-
var output = (0, _validateDate.default)('29-02-2024', 'DD-MM-YYYY');
|
|
29
|
-
expect(output).toEqual({
|
|
30
|
-
message: undefined,
|
|
31
|
-
propsInError: undefined
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
test('should validate false if NOT a leap year & 29 Feb is entered', function () {
|
|
35
|
-
var output = (0, _validateDate.default)('29-02-2023', 'DD-MM-YYYY');
|
|
36
|
-
expect(output).toEqual({
|
|
37
|
-
message: 'Day must be between 1 and 28',
|
|
38
|
-
propsInError: {
|
|
39
|
-
day: true
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
test('should return an error if no year is given', function () {
|
|
44
|
-
var output = (0, _validateDate.default)('29-02-', 'DD-MM-YYYY');
|
|
45
|
-
expect(output).toEqual({
|
|
46
|
-
message: 'Date must include a year',
|
|
47
|
-
propsInError: {
|
|
48
|
-
year: true
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
test('should return an error if the year contains less than 4 numbers', function () {
|
|
53
|
-
var output = (0, _validateDate.default)('29-02-20', 'DD-MM-YYYY');
|
|
54
|
-
expect(output).toEqual({
|
|
55
|
-
message: 'Year must be 4 numbers',
|
|
56
|
-
propsInError: {
|
|
57
|
-
year: true
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
test('should return an error if the year contains more than 4 numbers', function () {
|
|
62
|
-
var output = (0, _validateDate.default)('29-02-20202', 'DD-MM-YYYY');
|
|
63
|
-
expect(output).toEqual({
|
|
64
|
-
message: 'Year must be 4 numbers',
|
|
65
|
-
propsInError: {
|
|
66
|
-
year: true
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
test('should return an error if no month is given', function () {
|
|
71
|
-
var output = (0, _validateDate.default)('29--2020', 'DD-MM-YYYY');
|
|
72
|
-
expect(output).toEqual({
|
|
73
|
-
message: 'Date must include a month',
|
|
74
|
-
propsInError: {
|
|
75
|
-
month: true
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
test('should return an error if the month is not between 1 and 12', function () {
|
|
80
|
-
var output = (0, _validateDate.default)('29-14-2020', 'DD-MM-YYYY');
|
|
81
|
-
expect(output).toEqual({
|
|
82
|
-
message: 'Month must be between 1 and 12',
|
|
83
|
-
propsInError: {
|
|
84
|
-
month: true
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
test('should return an error if no day is given', function () {
|
|
89
|
-
var output = (0, _validateDate.default)('-03-2020', 'DD-MM-YYYY');
|
|
90
|
-
expect(output).toEqual({
|
|
91
|
-
message: 'Date must include a day',
|
|
92
|
-
propsInError: {
|
|
93
|
-
day: true
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
test('should return an error if the day is not between 1 and 31', function () {
|
|
98
|
-
var output = (0, _validateDate.default)('45-12-2020', 'DD-MM-YYYY');
|
|
99
|
-
expect(output).toEqual({
|
|
100
|
-
message: 'Day must be between 1 and 31',
|
|
101
|
-
propsInError: {
|
|
102
|
-
day: true
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
test('should correctly identify the maximum numbers of days in a given month and year', function () {
|
|
107
|
-
var max = (0, _validateDate.maxMonthDays)('02', '2024');
|
|
108
|
-
expect(max).toEqual(29);
|
|
109
|
-
max = (0, _validateDate.maxMonthDays)('02', '2023');
|
|
110
|
-
expect(max).toEqual(28);
|
|
111
|
-
max = (0, _validateDate.maxMonthDays)('06', '2023');
|
|
112
|
-
expect(max).toEqual(30);
|
|
113
|
-
max = (0, _validateDate.maxMonthDays)('07', '2023');
|
|
114
|
-
expect(max).toEqual(31);
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
});
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _validateEmail = _interopRequireDefault(require("./validateEmail"));
|
|
4
|
-
|
|
5
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
-
|
|
7
|
-
// Local imports
|
|
8
|
-
describe('utils', function () {
|
|
9
|
-
describe('Validate', function () {
|
|
10
|
-
describe('email', function () {
|
|
11
|
-
var LABEL = 'Component';
|
|
12
|
-
var ERROR = "Enter ".concat(LABEL.toLowerCase(), " in the correct format, like jane.doe@homeoffice.gov.uk"); // Valid values
|
|
13
|
-
|
|
14
|
-
it('should return no error when the value is a valid .gov.uk address', function () {
|
|
15
|
-
expect((0, _validateEmail.default)('alpha@homeoffice.gov.uk', LABEL)).toBeUndefined();
|
|
16
|
-
});
|
|
17
|
-
it('should return no error when the value is a capitalised digital.homeoffice.gov.uk address', function () {
|
|
18
|
-
expect((0, _validateEmail.default)('ALPHA.BRAVO@DIGITAL.HOMEOFFICE.GOV.UK', LABEL)).toBeUndefined();
|
|
19
|
-
});
|
|
20
|
-
it('should return no error when the value is an empty string', function () {
|
|
21
|
-
expect((0, _validateEmail.default)('', LABEL)).toBeUndefined();
|
|
22
|
-
}); // Invalid values
|
|
23
|
-
|
|
24
|
-
it('should return an error when the value is an empty object', function () {
|
|
25
|
-
expect((0, _validateEmail.default)({}, LABEL)).toEqual(ERROR);
|
|
26
|
-
});
|
|
27
|
-
it('should return an error when the value is an array', function () {
|
|
28
|
-
expect((0, _validateEmail.default)(['bob'], LABEL)).toEqual(ERROR);
|
|
29
|
-
});
|
|
30
|
-
it('should return an error when the value is numeric', function () {
|
|
31
|
-
expect((0, _validateEmail.default)(24, LABEL)).toEqual(ERROR);
|
|
32
|
-
});
|
|
33
|
-
it('should return an error when the value is in the wrong domain', function () {
|
|
34
|
-
expect((0, _validateEmail.default)('alpha@domain.com', LABEL)).toEqual(ERROR);
|
|
35
|
-
});
|
|
36
|
-
it('should return an error when the domain contains spaces', function () {
|
|
37
|
-
expect((0, _validateEmail.default)('alpha.bravo@digital homeoffice.gov.uk', LABEL)).toEqual(ERROR);
|
|
38
|
-
});
|
|
39
|
-
it('should return an error when the value has no TLD', function () {
|
|
40
|
-
expect((0, _validateEmail.default)('alpha.bravo@homeoffice', LABEL)).toEqual(ERROR);
|
|
41
|
-
});
|
|
42
|
-
it('should return an error when there is no name', function () {
|
|
43
|
-
expect((0, _validateEmail.default)('@homeoffice.gov.uk', LABEL)).toEqual(ERROR);
|
|
44
|
-
});
|
|
45
|
-
it('should return an error when there is no @ symbol', function () {
|
|
46
|
-
expect((0, _validateEmail.default)('alpha.bravo.homeoffice.gov.uk', LABEL)).toEqual(ERROR);
|
|
47
|
-
});
|
|
48
|
-
it('should return an error when the name contains spaces', function () {
|
|
49
|
-
expect((0, _validateEmail.default)('alpha bravo@digital.homeoffice.gov.uk', LABEL)).toEqual(ERROR);
|
|
50
|
-
});
|
|
51
|
-
it('should use a default label when none is specified', function () {
|
|
52
|
-
var DEFAULT_ERROR = 'Enter email address in the correct format, like jane.doe@homeoffice.gov.uk';
|
|
53
|
-
expect((0, _validateEmail.default)(['bob'], undefined)).toEqual(DEFAULT_ERROR);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
});
|
|
@@ -1,383 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _models = require("../../models");
|
|
4
|
-
|
|
5
|
-
var _validatePage = _interopRequireDefault(require("./validatePage"));
|
|
6
|
-
|
|
7
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
|
-
|
|
9
|
-
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; }
|
|
10
|
-
|
|
11
|
-
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; }
|
|
12
|
-
|
|
13
|
-
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; }
|
|
14
|
-
|
|
15
|
-
describe('utils.Validate.Page', function () {
|
|
16
|
-
describe('with FormPage', function () {
|
|
17
|
-
var setup = function setup(id, type, label, required) {
|
|
18
|
-
return {
|
|
19
|
-
id: id,
|
|
20
|
-
fieldId: id,
|
|
21
|
-
type: type,
|
|
22
|
-
label: label,
|
|
23
|
-
required: required
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
it('should return no error when the components array is null', function () {
|
|
28
|
-
var PAGE = {
|
|
29
|
-
components: null,
|
|
30
|
-
formData: null
|
|
31
|
-
};
|
|
32
|
-
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
33
|
-
});
|
|
34
|
-
it('should return no error when the components array is empty', function () {
|
|
35
|
-
var PAGE = {
|
|
36
|
-
components: [],
|
|
37
|
-
formData: null
|
|
38
|
-
};
|
|
39
|
-
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
40
|
-
});
|
|
41
|
-
describe('when there is no form data', function () {
|
|
42
|
-
it('should return no errors when no components are required', function () {
|
|
43
|
-
var COMPONENTS = [setup('a', _models.ComponentTypes.TEXT, 'Alpha', false), setup('b', _models.ComponentTypes.TEXT, 'Bravo', false)];
|
|
44
|
-
var PAGE = {
|
|
45
|
-
components: COMPONENTS,
|
|
46
|
-
formData: null
|
|
47
|
-
};
|
|
48
|
-
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
49
|
-
});
|
|
50
|
-
it('should return an error for each required component', function () {
|
|
51
|
-
var COMPONENTS = [setup('a', _models.ComponentTypes.TEXT, 'Alpha', true), setup('b', _models.ComponentTypes.TEXT, 'Bravo', true), setup('c', _models.ComponentTypes.TEXT, 'Charlie', false), // The only unrequired one
|
|
52
|
-
setup('d', _models.ComponentTypes.TEXT, 'Delta', true), setup('e', _models.ComponentTypes.TEXT, 'Echo', true)];
|
|
53
|
-
var PAGE = {
|
|
54
|
-
components: COMPONENTS,
|
|
55
|
-
formData: null
|
|
56
|
-
};
|
|
57
|
-
var RESULT = (0, _validatePage.default)(PAGE);
|
|
58
|
-
expect(RESULT.length).toEqual(4);
|
|
59
|
-
expect(RESULT[0]).toEqual({
|
|
60
|
-
id: 'a',
|
|
61
|
-
error: 'Alpha is required'
|
|
62
|
-
});
|
|
63
|
-
expect(RESULT[1]).toEqual({
|
|
64
|
-
id: 'b',
|
|
65
|
-
error: 'Bravo is required'
|
|
66
|
-
});
|
|
67
|
-
expect(RESULT[2]).toEqual({
|
|
68
|
-
id: 'd',
|
|
69
|
-
error: 'Delta is required'
|
|
70
|
-
});
|
|
71
|
-
expect(RESULT[3]).toEqual({
|
|
72
|
-
id: 'e',
|
|
73
|
-
error: 'Echo is required'
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
it('should return an error for each required component with interpolated label', function () {
|
|
77
|
-
var COMPONENTS = [// eslint-disable-next-line no-template-curly-in-string
|
|
78
|
-
setup('a', _models.ComponentTypes.TEXT, 'Alpha ${tiger}', true), // eslint-disable-next-line no-template-curly-in-string
|
|
79
|
-
setup('b', _models.ComponentTypes.EMAIL, 'Bravo ${panther}', true), // eslint-disable-next-line no-template-curly-in-string
|
|
80
|
-
setup('c', _models.ComponentTypes.AUTOCOMPLETE, 'Charlie ${eagle}', true), // eslint-disable-next-line no-template-curly-in-string
|
|
81
|
-
setup('d', _models.ComponentTypes.CHECKBOXES, 'Delta ${lion}', true), // eslint-disable-next-line no-template-curly-in-string
|
|
82
|
-
setup('e', _models.ComponentTypes.FILE, 'Echo ${zoo}', true)];
|
|
83
|
-
var PAGE = {
|
|
84
|
-
components: COMPONENTS,
|
|
85
|
-
formData: {
|
|
86
|
-
tiger: 'Tiger',
|
|
87
|
-
panther: 'Panther',
|
|
88
|
-
eagle: 'Eagle',
|
|
89
|
-
lion: 'Lion',
|
|
90
|
-
zoo: 'Zoo'
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
var RESULT = (0, _validatePage.default)(PAGE);
|
|
94
|
-
expect(RESULT.length).toEqual(5);
|
|
95
|
-
expect(RESULT[0]).toEqual({
|
|
96
|
-
id: 'a',
|
|
97
|
-
error: "Alpha ".concat(PAGE.formData.tiger, " is required")
|
|
98
|
-
});
|
|
99
|
-
expect(RESULT[1]).toEqual({
|
|
100
|
-
id: 'b',
|
|
101
|
-
error: "Bravo ".concat(PAGE.formData.panther, " is required")
|
|
102
|
-
});
|
|
103
|
-
expect(RESULT[2]).toEqual({
|
|
104
|
-
id: 'c',
|
|
105
|
-
error: "Charlie ".concat(PAGE.formData.eagle, " is required")
|
|
106
|
-
});
|
|
107
|
-
expect(RESULT[3]).toEqual({
|
|
108
|
-
id: 'd',
|
|
109
|
-
error: "Delta ".concat(PAGE.formData.lion, " is required")
|
|
110
|
-
});
|
|
111
|
-
expect(RESULT[4]).toEqual({
|
|
112
|
-
id: 'e',
|
|
113
|
-
error: "Echo ".concat(PAGE.formData.zoo, " is required")
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
describe('when the form data is fully valid', function () {
|
|
118
|
-
var DATA = {
|
|
119
|
-
alpha: 'alpha.smith@digital.homeoffice.gov.uk',
|
|
120
|
-
bravo: 'bravo.jones@digital.homeoffice.gov.uk'
|
|
121
|
-
};
|
|
122
|
-
it('should return no errors when none of the components are required or email types', function () {
|
|
123
|
-
var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', false), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', false)];
|
|
124
|
-
var PAGE = {
|
|
125
|
-
components: COMPONENTS,
|
|
126
|
-
formData: DATA
|
|
127
|
-
};
|
|
128
|
-
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
129
|
-
});
|
|
130
|
-
it('should return no errors when all of the components are required but not email types', function () {
|
|
131
|
-
var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', true), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', true)];
|
|
132
|
-
var PAGE = {
|
|
133
|
-
components: COMPONENTS,
|
|
134
|
-
formData: DATA
|
|
135
|
-
};
|
|
136
|
-
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
137
|
-
});
|
|
138
|
-
it('should return no errors when none of the components are required but are all email types', function () {
|
|
139
|
-
var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', false), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', false)];
|
|
140
|
-
var PAGE = {
|
|
141
|
-
components: COMPONENTS,
|
|
142
|
-
formData: DATA
|
|
143
|
-
};
|
|
144
|
-
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
145
|
-
});
|
|
146
|
-
it('should return no errors when all of the components are required and email types', function () {
|
|
147
|
-
var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', true)];
|
|
148
|
-
var PAGE = {
|
|
149
|
-
components: COMPONENTS,
|
|
150
|
-
formData: DATA
|
|
151
|
-
};
|
|
152
|
-
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
describe('when the form data has one field missing and includes an invalid email', function () {
|
|
156
|
-
var DATA = {
|
|
157
|
-
alpha: 'alpha.smith@digital.homeoffice.gov.uk',
|
|
158
|
-
bravo: 'bravo.jones@hotmail.com'
|
|
159
|
-
};
|
|
160
|
-
it('should return no errors when none of the components are required or email types', function () {
|
|
161
|
-
var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', false), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', false), setup('charlie', _models.ComponentTypes.TEXT, 'Charlie', false)];
|
|
162
|
-
var PAGE = {
|
|
163
|
-
components: COMPONENTS,
|
|
164
|
-
formData: null
|
|
165
|
-
};
|
|
166
|
-
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
167
|
-
});
|
|
168
|
-
it('should return an error for the missing field when all are required but not email types', function () {
|
|
169
|
-
var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', true), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', true), setup('charlie', _models.ComponentTypes.TEXT, 'Charlie', true)];
|
|
170
|
-
var PAGE = {
|
|
171
|
-
components: COMPONENTS,
|
|
172
|
-
formData: DATA
|
|
173
|
-
};
|
|
174
|
-
var RESULT = (0, _validatePage.default)(PAGE);
|
|
175
|
-
expect(RESULT.length).toEqual(1);
|
|
176
|
-
expect(RESULT[0]).toEqual({
|
|
177
|
-
id: 'charlie',
|
|
178
|
-
error: 'Charlie is required'
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
it('should return an error for the invalid email field when none are required but all email types', function () {
|
|
182
|
-
var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', false), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', false), setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie', false)];
|
|
183
|
-
var PAGE = {
|
|
184
|
-
components: COMPONENTS,
|
|
185
|
-
formData: DATA
|
|
186
|
-
};
|
|
187
|
-
var RESULT = (0, _validatePage.default)(PAGE);
|
|
188
|
-
expect(RESULT.length).toEqual(1);
|
|
189
|
-
expect(RESULT[0]).toEqual({
|
|
190
|
-
id: 'bravo',
|
|
191
|
-
error: 'Enter bravo in the correct format, like jane.doe@homeoffice.gov.uk'
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
it('should return an error for both invalid fields when all are required and email types', function () {
|
|
195
|
-
var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', true), setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie', true)];
|
|
196
|
-
var PAGE = {
|
|
197
|
-
components: COMPONENTS,
|
|
198
|
-
formData: DATA
|
|
199
|
-
};
|
|
200
|
-
var RESULT = (0, _validatePage.default)(PAGE);
|
|
201
|
-
expect(RESULT.length).toEqual(2);
|
|
202
|
-
expect(RESULT[0]).toEqual({
|
|
203
|
-
id: 'bravo',
|
|
204
|
-
error: 'Enter bravo in the correct format, like jane.doe@homeoffice.gov.uk'
|
|
205
|
-
});
|
|
206
|
-
expect(RESULT[1]).toEqual({
|
|
207
|
-
id: 'charlie',
|
|
208
|
-
error: 'Charlie is required'
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
it('should return an interpolated error for both invalid fields when all are required and email types', function () {
|
|
212
|
-
var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true), // eslint-disable-next-line no-template-curly-in-string
|
|
213
|
-
setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo ${lion}', true), // eslint-disable-next-line no-template-curly-in-string
|
|
214
|
-
setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie ${panther}', true)];
|
|
215
|
-
var PAGE = {
|
|
216
|
-
components: COMPONENTS,
|
|
217
|
-
formData: _objectSpread(_objectSpread({}, DATA), {}, {
|
|
218
|
-
lion: 'Lion',
|
|
219
|
-
panther: 'Panther'
|
|
220
|
-
})
|
|
221
|
-
};
|
|
222
|
-
var RESULT = (0, _validatePage.default)(PAGE);
|
|
223
|
-
expect(RESULT.length).toEqual(2);
|
|
224
|
-
expect(RESULT[0]).toEqual({
|
|
225
|
-
id: 'bravo',
|
|
226
|
-
error: "Enter bravo ".concat(PAGE.formData.lion, " in the correct format, like jane.doe@homeoffice.gov.uk")
|
|
227
|
-
});
|
|
228
|
-
expect(RESULT[1]).toEqual({
|
|
229
|
-
id: 'charlie',
|
|
230
|
-
error: "Charlie ".concat(PAGE.formData.panther, " is required")
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
describe('with CollectionPage', function () {
|
|
236
|
-
var COLLECTION = {
|
|
237
|
-
name: 'pageCollection'
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
var setup = function setup(id, type, label, required) {
|
|
241
|
-
return {
|
|
242
|
-
id: id,
|
|
243
|
-
fieldId: id,
|
|
244
|
-
type: type,
|
|
245
|
-
label: label,
|
|
246
|
-
required: required
|
|
247
|
-
};
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
describe('when the form data is fully valid', function () {
|
|
251
|
-
var _DATA;
|
|
252
|
-
|
|
253
|
-
var DATA = (_DATA = {}, _defineProperty(_DATA, "".concat(COLLECTION.name, "ActiveId"), '01'), _defineProperty(_DATA, COLLECTION.name, [{
|
|
254
|
-
id: '01',
|
|
255
|
-
alpha: 'alpha.smith@digital.homeoffice.gov.uk',
|
|
256
|
-
bravo: 'bravo.jones@digital.homeoffice.gov.uk'
|
|
257
|
-
}]), _DATA);
|
|
258
|
-
it('should return no errors when none of the components are required or email types', function () {
|
|
259
|
-
var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', false), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', false)];
|
|
260
|
-
var PAGE = {
|
|
261
|
-
collection: COLLECTION,
|
|
262
|
-
components: COMPONENTS,
|
|
263
|
-
formData: DATA
|
|
264
|
-
};
|
|
265
|
-
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
266
|
-
});
|
|
267
|
-
it('should return no errors when all of the components are required but not email types', function () {
|
|
268
|
-
var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', true), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', true)];
|
|
269
|
-
var PAGE = {
|
|
270
|
-
collection: COLLECTION,
|
|
271
|
-
components: COMPONENTS,
|
|
272
|
-
formData: DATA
|
|
273
|
-
};
|
|
274
|
-
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
275
|
-
});
|
|
276
|
-
it('should return no errors when none of the components are required but are all email types', function () {
|
|
277
|
-
var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', false), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', false)];
|
|
278
|
-
var PAGE = {
|
|
279
|
-
collection: COLLECTION,
|
|
280
|
-
components: COMPONENTS,
|
|
281
|
-
formData: DATA
|
|
282
|
-
};
|
|
283
|
-
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
284
|
-
});
|
|
285
|
-
it('should return no errors when all of the components are required and email types', function () {
|
|
286
|
-
var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', true)];
|
|
287
|
-
var PAGE = {
|
|
288
|
-
collection: COLLECTION,
|
|
289
|
-
components: COMPONENTS,
|
|
290
|
-
formData: DATA
|
|
291
|
-
};
|
|
292
|
-
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
293
|
-
});
|
|
294
|
-
});
|
|
295
|
-
describe('when the form data has one field missing and includes an invalid email', function () {
|
|
296
|
-
var _DATA2;
|
|
297
|
-
|
|
298
|
-
var DATA = (_DATA2 = {}, _defineProperty(_DATA2, "".concat(COLLECTION.name, "ActiveId"), '01'), _defineProperty(_DATA2, COLLECTION.name, [{
|
|
299
|
-
id: '01',
|
|
300
|
-
alpha: 'alpha.smith@digital.homeoffice.gov.uk',
|
|
301
|
-
bravo: 'bravo.jones@hotmail.com'
|
|
302
|
-
}]), _DATA2);
|
|
303
|
-
it('should return no errors when none of the components are required or email types', function () {
|
|
304
|
-
var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', false), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', false), setup('charlie', _models.ComponentTypes.TEXT, 'Charlie', false)];
|
|
305
|
-
var PAGE = {
|
|
306
|
-
collection: COLLECTION,
|
|
307
|
-
components: COMPONENTS,
|
|
308
|
-
formData: null
|
|
309
|
-
};
|
|
310
|
-
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
311
|
-
});
|
|
312
|
-
it('should return an error for the missing field when all are required but not email types', function () {
|
|
313
|
-
var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', true), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', true), setup('charlie', _models.ComponentTypes.TEXT, 'Charlie', true)];
|
|
314
|
-
var PAGE = {
|
|
315
|
-
collection: COLLECTION,
|
|
316
|
-
components: COMPONENTS,
|
|
317
|
-
formData: DATA
|
|
318
|
-
};
|
|
319
|
-
var RESULT = (0, _validatePage.default)(PAGE);
|
|
320
|
-
expect(RESULT.length).toEqual(1);
|
|
321
|
-
expect(RESULT[0]).toEqual({
|
|
322
|
-
id: 'charlie',
|
|
323
|
-
error: 'Charlie is required'
|
|
324
|
-
});
|
|
325
|
-
});
|
|
326
|
-
it('should return an error for the invalid email field when none are required but all email types', function () {
|
|
327
|
-
var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', false), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', false), setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie', false)];
|
|
328
|
-
var PAGE = {
|
|
329
|
-
collection: COLLECTION,
|
|
330
|
-
components: COMPONENTS,
|
|
331
|
-
formData: DATA
|
|
332
|
-
};
|
|
333
|
-
var RESULT = (0, _validatePage.default)(PAGE);
|
|
334
|
-
expect(RESULT.length).toEqual(1);
|
|
335
|
-
expect(RESULT[0]).toEqual({
|
|
336
|
-
id: 'bravo',
|
|
337
|
-
error: 'Enter bravo in the correct format, like jane.doe@homeoffice.gov.uk'
|
|
338
|
-
});
|
|
339
|
-
});
|
|
340
|
-
it('should return an error for both invalid fields when all are required and email types', function () {
|
|
341
|
-
var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', true), setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie', true)];
|
|
342
|
-
var PAGE = {
|
|
343
|
-
collection: COLLECTION,
|
|
344
|
-
components: COMPONENTS,
|
|
345
|
-
formData: DATA
|
|
346
|
-
};
|
|
347
|
-
var RESULT = (0, _validatePage.default)(PAGE);
|
|
348
|
-
expect(RESULT.length).toEqual(2);
|
|
349
|
-
expect(RESULT[0]).toEqual({
|
|
350
|
-
id: 'bravo',
|
|
351
|
-
error: 'Enter bravo in the correct format, like jane.doe@homeoffice.gov.uk'
|
|
352
|
-
});
|
|
353
|
-
expect(RESULT[1]).toEqual({
|
|
354
|
-
id: 'charlie',
|
|
355
|
-
error: 'Charlie is required'
|
|
356
|
-
});
|
|
357
|
-
});
|
|
358
|
-
it('should return an interpolated error for both invalid fields when all are required and email types', function () {
|
|
359
|
-
var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true), // eslint-disable-next-line no-template-curly-in-string
|
|
360
|
-
setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo ${lion}', true), // eslint-disable-next-line no-template-curly-in-string
|
|
361
|
-
setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie ${panther}', true)];
|
|
362
|
-
var PAGE = {
|
|
363
|
-
collection: COLLECTION,
|
|
364
|
-
components: COMPONENTS,
|
|
365
|
-
formData: _objectSpread(_objectSpread({}, DATA), {}, _defineProperty({}, COLLECTION.name, [_objectSpread(_objectSpread({}, DATA[COLLECTION.name][0]), {}, {
|
|
366
|
-
lion: 'Lion',
|
|
367
|
-
panther: 'Panther'
|
|
368
|
-
})]))
|
|
369
|
-
};
|
|
370
|
-
var RESULT = (0, _validatePage.default)(PAGE);
|
|
371
|
-
expect(RESULT.length).toEqual(2);
|
|
372
|
-
expect(RESULT[0]).toEqual({
|
|
373
|
-
id: 'bravo',
|
|
374
|
-
error: "Enter bravo ".concat(PAGE.formData[COLLECTION.name][0].lion, " in the correct format, like jane.doe@homeoffice.gov.uk")
|
|
375
|
-
});
|
|
376
|
-
expect(RESULT[1]).toEqual({
|
|
377
|
-
id: 'charlie',
|
|
378
|
-
error: "Charlie ".concat(PAGE.formData[COLLECTION.name][0].panther, " is required")
|
|
379
|
-
});
|
|
380
|
-
});
|
|
381
|
-
});
|
|
382
|
-
});
|
|
383
|
-
});
|