@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,106 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _persistValueInFormData = _interopRequireDefault(require("./persistValueInFormData"));
|
|
4
|
-
|
|
5
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
-
|
|
7
|
-
describe('Utils.Operate.persistValueInFormData', function () {
|
|
8
|
-
var DATA = {
|
|
9
|
-
alpha: 'abc',
|
|
10
|
-
beta: 'charlie',
|
|
11
|
-
charlie: '123'
|
|
12
|
-
};
|
|
13
|
-
var ON_CHANGE_COUNT = 0;
|
|
14
|
-
|
|
15
|
-
var ON_CHANGE = function ON_CHANGE(_ref) {
|
|
16
|
-
var target = _ref.target;
|
|
17
|
-
DATA[target.name] = target.value;
|
|
18
|
-
ON_CHANGE_COUNT++;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
beforeEach(function () {
|
|
22
|
-
DATA = {
|
|
23
|
-
alpha: 'abc',
|
|
24
|
-
beta: 'charlie',
|
|
25
|
-
charlie: '123'
|
|
26
|
-
};
|
|
27
|
-
ON_CHANGE_COUNT = 0;
|
|
28
|
-
});
|
|
29
|
-
it('Should trigger a change correctly', function () {
|
|
30
|
-
var CONFIG = {
|
|
31
|
-
name: 'alpha',
|
|
32
|
-
value: 'bcd'
|
|
33
|
-
};
|
|
34
|
-
(0, _persistValueInFormData.default)(CONFIG, DATA, ON_CHANGE);
|
|
35
|
-
expect(DATA).toEqual({
|
|
36
|
-
alpha: 'bcd',
|
|
37
|
-
beta: 'charlie',
|
|
38
|
-
charlie: '123'
|
|
39
|
-
});
|
|
40
|
-
expect(ON_CHANGE_COUNT).toEqual(1);
|
|
41
|
-
});
|
|
42
|
-
it('Should not call onChange when value is unchanged', function () {
|
|
43
|
-
var CONFIG = {
|
|
44
|
-
name: 'alpha',
|
|
45
|
-
value: 'abc'
|
|
46
|
-
};
|
|
47
|
-
(0, _persistValueInFormData.default)(CONFIG, DATA, ON_CHANGE);
|
|
48
|
-
expect(DATA).toEqual({
|
|
49
|
-
alpha: 'abc',
|
|
50
|
-
beta: 'charlie',
|
|
51
|
-
charlie: '123'
|
|
52
|
-
});
|
|
53
|
-
expect(ON_CHANGE_COUNT).toEqual(0);
|
|
54
|
-
});
|
|
55
|
-
it('Should not call onChange if no value or field is given', function () {
|
|
56
|
-
var CONFIG = {
|
|
57
|
-
name: 'alpha'
|
|
58
|
-
};
|
|
59
|
-
(0, _persistValueInFormData.default)(CONFIG, DATA, ON_CHANGE);
|
|
60
|
-
expect(DATA).toEqual({
|
|
61
|
-
alpha: 'abc',
|
|
62
|
-
beta: 'charlie',
|
|
63
|
-
charlie: '123'
|
|
64
|
-
});
|
|
65
|
-
expect(ON_CHANGE_COUNT).toEqual(0);
|
|
66
|
-
});
|
|
67
|
-
it('Should not call onChange if no name is given', function () {
|
|
68
|
-
var CONFIG = {
|
|
69
|
-
field: 'charlie'
|
|
70
|
-
};
|
|
71
|
-
(0, _persistValueInFormData.default)(CONFIG, DATA, ON_CHANGE);
|
|
72
|
-
expect(DATA).toEqual({
|
|
73
|
-
alpha: 'abc',
|
|
74
|
-
beta: 'charlie',
|
|
75
|
-
charlie: '123'
|
|
76
|
-
});
|
|
77
|
-
expect(ON_CHANGE_COUNT).toEqual(0);
|
|
78
|
-
});
|
|
79
|
-
it('Should not call onChange if field cannot be found', function () {
|
|
80
|
-
var CONFIG = {
|
|
81
|
-
name: 'alpha',
|
|
82
|
-
field: 'delta'
|
|
83
|
-
};
|
|
84
|
-
(0, _persistValueInFormData.default)(CONFIG, DATA, ON_CHANGE);
|
|
85
|
-
expect(DATA).toEqual({
|
|
86
|
-
alpha: 'abc',
|
|
87
|
-
beta: 'charlie',
|
|
88
|
-
charlie: '123'
|
|
89
|
-
});
|
|
90
|
-
expect(ON_CHANGE_COUNT).toEqual(0);
|
|
91
|
-
});
|
|
92
|
-
it('Should correctly interpolate a field value', function () {
|
|
93
|
-
// eslint-disable-next-line no-template-curly-in-string
|
|
94
|
-
var CONFIG = {
|
|
95
|
-
name: 'alpha',
|
|
96
|
-
field: '${beta}'
|
|
97
|
-
};
|
|
98
|
-
(0, _persistValueInFormData.default)(CONFIG, DATA, ON_CHANGE);
|
|
99
|
-
expect(DATA).toEqual({
|
|
100
|
-
alpha: '123',
|
|
101
|
-
beta: 'charlie',
|
|
102
|
-
charlie: '123'
|
|
103
|
-
});
|
|
104
|
-
expect(ON_CHANGE_COUNT).toEqual(1);
|
|
105
|
-
});
|
|
106
|
-
});
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _runPageOperations = _interopRequireDefault(require("./runPageOperations"));
|
|
4
|
-
|
|
5
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
-
|
|
7
|
-
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; }
|
|
8
|
-
|
|
9
|
-
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; }
|
|
10
|
-
|
|
11
|
-
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; }
|
|
12
|
-
|
|
13
|
-
describe('Utils.Operate.runPageOperations', function () {
|
|
14
|
-
var DATA = {
|
|
15
|
-
alpha: 'abc',
|
|
16
|
-
bravo: ['bcd', 'cde', 'charlie'],
|
|
17
|
-
charlie: 'def',
|
|
18
|
-
delta: 'root',
|
|
19
|
-
array: ['123', '234', '456']
|
|
20
|
-
};
|
|
21
|
-
it('Should return an empty object when no operations are specified', function () {
|
|
22
|
-
var PAGE = {};
|
|
23
|
-
var result = (0, _runPageOperations.default)(PAGE, DATA);
|
|
24
|
-
expect(result).toEqual(DATA);
|
|
25
|
-
});
|
|
26
|
-
it('Should handle a single operation correctly', function () {
|
|
27
|
-
var PAGE = {
|
|
28
|
-
operations: [{
|
|
29
|
-
output: 'firstOpResult',
|
|
30
|
-
function: 'setValueInFormData',
|
|
31
|
-
field: 'alpha'
|
|
32
|
-
}]
|
|
33
|
-
};
|
|
34
|
-
var result = (0, _runPageOperations.default)(PAGE, DATA);
|
|
35
|
-
expect(result).toEqual(_objectSpread(_objectSpread({}, DATA), {}, {
|
|
36
|
-
firstOpResult: 'abc'
|
|
37
|
-
}));
|
|
38
|
-
});
|
|
39
|
-
it('Should handle a multiple operations correctly', function () {
|
|
40
|
-
var PAGE = {
|
|
41
|
-
operations: [{
|
|
42
|
-
output: 'firstOpResult',
|
|
43
|
-
function: 'setValueInFormData',
|
|
44
|
-
field: 'alpha'
|
|
45
|
-
}, {
|
|
46
|
-
output: 'secondOpResult',
|
|
47
|
-
function: 'setValueInFormData',
|
|
48
|
-
field: 'bravo[1]'
|
|
49
|
-
}]
|
|
50
|
-
};
|
|
51
|
-
var result = (0, _runPageOperations.default)(PAGE, DATA);
|
|
52
|
-
expect(result).toEqual(_objectSpread(_objectSpread({}, DATA), {}, {
|
|
53
|
-
firstOpResult: 'abc',
|
|
54
|
-
secondOpResult: 'cde'
|
|
55
|
-
}));
|
|
56
|
-
});
|
|
57
|
-
it('Should handle chained operations correctly', function () {
|
|
58
|
-
var PAGE = {
|
|
59
|
-
operations: [{
|
|
60
|
-
output: 'firstOpResult',
|
|
61
|
-
function: 'setValueInFormData',
|
|
62
|
-
field: 'bravo[2]'
|
|
63
|
-
}, {
|
|
64
|
-
output: 'secondOpResult',
|
|
65
|
-
function: 'setValueInFormData',
|
|
66
|
-
// eslint-disable-next-line no-template-curly-in-string
|
|
67
|
-
field: '${firstOpResult}'
|
|
68
|
-
}]
|
|
69
|
-
};
|
|
70
|
-
var result = (0, _runPageOperations.default)(PAGE, DATA);
|
|
71
|
-
expect(result).toEqual(_objectSpread(_objectSpread({}, DATA), {}, {
|
|
72
|
-
firstOpResult: 'charlie',
|
|
73
|
-
secondOpResult: 'def'
|
|
74
|
-
}));
|
|
75
|
-
});
|
|
76
|
-
it('Should handle an interpolated output string correctly', function () {
|
|
77
|
-
var PAGE = {
|
|
78
|
-
operations: [{
|
|
79
|
-
function: 'setValueInFormData',
|
|
80
|
-
value: 'leaf',
|
|
81
|
-
// eslint-disable-next-line no-template-curly-in-string
|
|
82
|
-
output: '${delta}.trunk.branch'
|
|
83
|
-
}]
|
|
84
|
-
};
|
|
85
|
-
var result = (0, _runPageOperations.default)(PAGE, DATA);
|
|
86
|
-
expect(result).toEqual(_objectSpread(_objectSpread({}, DATA), {}, {
|
|
87
|
-
root: {
|
|
88
|
-
trunk: {
|
|
89
|
-
branch: 'leaf'
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}));
|
|
93
|
-
});
|
|
94
|
-
it('Should handle an output string with array indeces in', function () {
|
|
95
|
-
var PAGE = {
|
|
96
|
-
operations: [{
|
|
97
|
-
function: 'setValueInFormData',
|
|
98
|
-
value: '000',
|
|
99
|
-
output: 'array[1]'
|
|
100
|
-
}]
|
|
101
|
-
};
|
|
102
|
-
var result = (0, _runPageOperations.default)(PAGE, DATA);
|
|
103
|
-
expect(result).toEqual(_objectSpread(_objectSpread({}, DATA), {}, {
|
|
104
|
-
array: ['123', '000', '456']
|
|
105
|
-
}));
|
|
106
|
-
});
|
|
107
|
-
});
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _setValueInFormData = _interopRequireDefault(require("./setValueInFormData"));
|
|
4
|
-
|
|
5
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
-
|
|
7
|
-
describe('Utils.Operate.addToFormData', function () {
|
|
8
|
-
var DATA = {
|
|
9
|
-
a: '1',
|
|
10
|
-
b: ['2', '3'],
|
|
11
|
-
indexOfThree: 1
|
|
12
|
-
};
|
|
13
|
-
it('Should return the value provided in config if no field is specified', function () {
|
|
14
|
-
var CONFIG = {
|
|
15
|
-
value: '2'
|
|
16
|
-
};
|
|
17
|
-
var result = (0, _setValueInFormData.default)(CONFIG, DATA);
|
|
18
|
-
expect(result).toEqual(CONFIG.value);
|
|
19
|
-
});
|
|
20
|
-
it('Should return the value of the field given in config, if it exists', function () {
|
|
21
|
-
var CONFIG = {
|
|
22
|
-
field: 'a'
|
|
23
|
-
};
|
|
24
|
-
var result = (0, _setValueInFormData.default)(CONFIG, DATA);
|
|
25
|
-
expect(result).toEqual(DATA.a);
|
|
26
|
-
});
|
|
27
|
-
it('Should handle interpolated field strings', function () {
|
|
28
|
-
// eslint-disable-next-line no-template-curly-in-string
|
|
29
|
-
var CONFIG = {
|
|
30
|
-
field: 'b[${indexOfThree}]'
|
|
31
|
-
};
|
|
32
|
-
var result = (0, _setValueInFormData.default)(CONFIG, DATA);
|
|
33
|
-
expect(result).toEqual(DATA.b[1]);
|
|
34
|
-
});
|
|
35
|
-
it('Should return null when an invalid config is used', function () {
|
|
36
|
-
var result = (0, _setValueInFormData.default)(null, DATA);
|
|
37
|
-
expect(result).toEqual(null);
|
|
38
|
-
});
|
|
39
|
-
it('Should return null when invalid data is used', function () {
|
|
40
|
-
var CONFIG = {
|
|
41
|
-
field: 'a'
|
|
42
|
-
};
|
|
43
|
-
var result = (0, _setValueInFormData.default)(CONFIG, null);
|
|
44
|
-
expect(result).toEqual(null);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _shouldRun = _interopRequireDefault(require("./shouldRun"));
|
|
4
|
-
|
|
5
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
-
|
|
7
|
-
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; }
|
|
8
|
-
|
|
9
|
-
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; }
|
|
10
|
-
|
|
11
|
-
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; }
|
|
12
|
-
|
|
13
|
-
describe('Utils.Operate.shouldRun', function () {
|
|
14
|
-
var DATA = {
|
|
15
|
-
alpha: 'abc',
|
|
16
|
-
bravo: ''
|
|
17
|
-
};
|
|
18
|
-
it('Should return true if the run_when config is invalid', function () {
|
|
19
|
-
expect((0, _shouldRun.default)(null, DATA)).toEqual(true);
|
|
20
|
-
});
|
|
21
|
-
it('Should return true when the condition is \'changes\' and target value has changed', function () {
|
|
22
|
-
var CONFIG = {
|
|
23
|
-
condition: 'changes',
|
|
24
|
-
field: 'alpha'
|
|
25
|
-
};
|
|
26
|
-
var result = (0, _shouldRun.default)(CONFIG, DATA);
|
|
27
|
-
expect(result).toEqual(false); // Expect false as this is the first render.
|
|
28
|
-
|
|
29
|
-
result = (0, _shouldRun.default)(CONFIG, DATA);
|
|
30
|
-
expect(result).toEqual(false); // Expect false as the field hasn't changed.
|
|
31
|
-
|
|
32
|
-
result = (0, _shouldRun.default)(CONFIG, _objectSpread(_objectSpread({}, DATA), {}, {
|
|
33
|
-
alpha: 'bcd'
|
|
34
|
-
}));
|
|
35
|
-
expect(result).toEqual(true); // Expect true as the field's value has been updated.
|
|
36
|
-
});
|
|
37
|
-
it('Should return true when the condition is \'isTruthy\' and target value is truthy', function () {
|
|
38
|
-
var CONFIG = {
|
|
39
|
-
condition: 'isTruthy',
|
|
40
|
-
field: 'alpha'
|
|
41
|
-
};
|
|
42
|
-
var result = (0, _shouldRun.default)(CONFIG, DATA);
|
|
43
|
-
expect(result).toEqual(true);
|
|
44
|
-
});
|
|
45
|
-
it('Should return false when the condition is \'isTruthy\' and target value is falsy', function () {
|
|
46
|
-
var CONFIG = {
|
|
47
|
-
condition: 'isTruthy',
|
|
48
|
-
field: 'bravo'
|
|
49
|
-
};
|
|
50
|
-
var result = (0, _shouldRun.default)(CONFIG, DATA);
|
|
51
|
-
expect(result).toEqual(false);
|
|
52
|
-
});
|
|
53
|
-
it('Should return true when the condition is \'isFalsy\' and target value is falsy', function () {
|
|
54
|
-
var CONFIG = {
|
|
55
|
-
condition: 'isFalsy',
|
|
56
|
-
field: 'bravo'
|
|
57
|
-
};
|
|
58
|
-
var result = (0, _shouldRun.default)(CONFIG, DATA);
|
|
59
|
-
expect(result).toEqual(true);
|
|
60
|
-
});
|
|
61
|
-
it('Should return false when the condition is \'isFalsy\' and target value is truthy', function () {
|
|
62
|
-
var CONFIG = {
|
|
63
|
-
condition: 'isFalsy',
|
|
64
|
-
field: 'alpha'
|
|
65
|
-
};
|
|
66
|
-
var result = (0, _shouldRun.default)(CONFIG, DATA);
|
|
67
|
-
expect(result).toEqual(false);
|
|
68
|
-
});
|
|
69
|
-
});
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _models = require("../../models");
|
|
4
|
-
|
|
5
|
-
var _validateCollection = _interopRequireDefault(require("./validateCollection"));
|
|
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.Collection', function () {
|
|
12
|
-
var setup = function setup(id, type, label, required, item) {
|
|
13
|
-
return {
|
|
14
|
-
id: id,
|
|
15
|
-
fieldId: id,
|
|
16
|
-
type: type,
|
|
17
|
-
label: label,
|
|
18
|
-
required: required,
|
|
19
|
-
item: item
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
it('should return an empty array when the component is null', function () {
|
|
24
|
-
expect((0, _validateCollection.default)(null, [])).toEqual([]);
|
|
25
|
-
});
|
|
26
|
-
it('should return an empty array when the collection has an undefined item array', function () {
|
|
27
|
-
var ID = 'collection';
|
|
28
|
-
var LABEL = 'field';
|
|
29
|
-
var COLLECTION = setup(ID, _models.ComponentTypes.COLLECTION, LABEL, false, undefined);
|
|
30
|
-
expect((0, _validateCollection.default)(COLLECTION, [])).toEqual([]);
|
|
31
|
-
});
|
|
32
|
-
it('should return an empty array when the collection has an empty item array', function () {
|
|
33
|
-
var ID = 'collection';
|
|
34
|
-
var LABEL = 'field';
|
|
35
|
-
var COLLECTION = setup(ID, _models.ComponentTypes.COLLECTION, LABEL, false, []);
|
|
36
|
-
expect((0, _validateCollection.default)(COLLECTION, [])).toEqual([]);
|
|
37
|
-
});
|
|
38
|
-
it('should return an empty array when the collection has only valid items', function () {
|
|
39
|
-
var EMAIL_ID = 'email';
|
|
40
|
-
var EMAIL_LABEL = 'Email';
|
|
41
|
-
var EMAIL = setup(EMAIL_ID, _models.ComponentTypes.EMAIL, EMAIL_LABEL, false);
|
|
42
|
-
var ID = 'collection';
|
|
43
|
-
var LABEL = 'field';
|
|
44
|
-
var COLLECTION = setup(ID, _models.ComponentTypes.COLLECTION, LABEL, false, [EMAIL]);
|
|
45
|
-
var ITEMS = [_defineProperty({}, EMAIL_ID, 'alpha.bravo@homeoffice.gov.uk'), _defineProperty({}, EMAIL_ID, 'charlie.delta@homeoffice.gov.uk')];
|
|
46
|
-
expect((0, _validateCollection.default)(COLLECTION, ITEMS)).toEqual([]);
|
|
47
|
-
});
|
|
48
|
-
it('should return an array containing an error when the collection has an invalid first item', function () {
|
|
49
|
-
var EMAIL_ID = 'email';
|
|
50
|
-
var EMAIL_LABEL = 'Email';
|
|
51
|
-
var EMAIL = setup(EMAIL_ID, _models.ComponentTypes.EMAIL, EMAIL_LABEL, false);
|
|
52
|
-
var ID = 'container';
|
|
53
|
-
var LABEL = 'field';
|
|
54
|
-
var COLLECTION = setup(ID, _models.ComponentTypes.CONTAINER, LABEL, false, [EMAIL]);
|
|
55
|
-
var ITEMS = [_defineProperty({}, EMAIL_ID, 'alpha.bravo@digital.homeoffice.com'), _defineProperty({}, EMAIL_ID, 'alpha.bravo@digital.homeoffice.gov.uk')];
|
|
56
|
-
expect((0, _validateCollection.default)(COLLECTION, ITEMS)).toEqual([{
|
|
57
|
-
id: "".concat(ID, "[0].").concat(EMAIL_ID),
|
|
58
|
-
error: "Enter ".concat(EMAIL_LABEL.toLowerCase(), " in the correct format, like jane.doe@homeoffice.gov.uk")
|
|
59
|
-
}]);
|
|
60
|
-
});
|
|
61
|
-
it('should return an array containing an error when the collection has an invalid second item', function () {
|
|
62
|
-
var EMAIL_ID = 'email';
|
|
63
|
-
var EMAIL_LABEL = 'Email';
|
|
64
|
-
var EMAIL = setup(EMAIL_ID, _models.ComponentTypes.EMAIL, EMAIL_LABEL, false);
|
|
65
|
-
var ID = 'container';
|
|
66
|
-
var LABEL = 'field';
|
|
67
|
-
var COLLECTION = setup(ID, _models.ComponentTypes.CONTAINER, LABEL, false, [EMAIL]);
|
|
68
|
-
var ITEMS = [_defineProperty({}, EMAIL_ID, 'alpha.bravo@digital.homeoffice.gov.uk'), _defineProperty({}, EMAIL_ID, 'alpha.bravo@digital.homeoffice.com')];
|
|
69
|
-
expect((0, _validateCollection.default)(COLLECTION, ITEMS)).toEqual([{
|
|
70
|
-
id: "".concat(ID, "[1].").concat(EMAIL_ID),
|
|
71
|
-
error: "Enter ".concat(EMAIL_LABEL.toLowerCase(), " in the correct format, like jane.doe@homeoffice.gov.uk")
|
|
72
|
-
}]);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _models = require("../../models");
|
|
4
|
-
|
|
5
|
-
var _validateComponent = _interopRequireDefault(require("./validateComponent"));
|
|
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.Component', 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 no error when the component is null', function () {
|
|
24
|
-
expect((0, _validateComponent.default)(null, {})).toBeUndefined();
|
|
25
|
-
});
|
|
26
|
-
describe('when there is no form data', function () {
|
|
27
|
-
it('should return no error when the component is not required and not an email type', function () {
|
|
28
|
-
var ID = 'field';
|
|
29
|
-
var LABEL = 'Field';
|
|
30
|
-
var COMPONENT = setup(ID, _models.ComponentTypes.TEXT, LABEL, false);
|
|
31
|
-
expect((0, _validateComponent.default)(COMPONENT, null)).toBeUndefined();
|
|
32
|
-
});
|
|
33
|
-
it('should return a required error when the component is required and not an email type', function () {
|
|
34
|
-
var ID = 'field';
|
|
35
|
-
var LABEL = 'Field';
|
|
36
|
-
var COMPONENT = setup(ID, _models.ComponentTypes.TEXT, LABEL, true);
|
|
37
|
-
expect((0, _validateComponent.default)(COMPONENT, null)).toEqual({
|
|
38
|
-
id: ID,
|
|
39
|
-
error: "".concat(LABEL, " is required")
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
it('should return a required error when the component is required and of type email', function () {
|
|
43
|
-
var ID = 'field';
|
|
44
|
-
var LABEL = 'Field';
|
|
45
|
-
var COMPONENT = setup(ID, _models.ComponentTypes.EMAIL, LABEL, true);
|
|
46
|
-
expect((0, _validateComponent.default)(COMPONENT, null)).toEqual({
|
|
47
|
-
id: ID,
|
|
48
|
-
error: "".concat(LABEL, " is required")
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
it('should return no error when the component is of type email but not required', function () {
|
|
52
|
-
var ID = 'field';
|
|
53
|
-
var LABEL = 'Field';
|
|
54
|
-
var COMPONENT = setup(ID, _models.ComponentTypes.EMAIL, LABEL, false);
|
|
55
|
-
expect((0, _validateComponent.default)(COMPONENT, null)).toBeUndefined();
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
describe('when the value is fully valid', function () {
|
|
59
|
-
var ID = 'field';
|
|
60
|
-
|
|
61
|
-
var DATA = _defineProperty({}, ID, 'alpha.bravo@digital.homeoffice.gov.uk');
|
|
62
|
-
|
|
63
|
-
it('should return no error when the component is not required and not an email type', function () {
|
|
64
|
-
var LABEL = 'Field';
|
|
65
|
-
var COMPONENT = setup(ID, _models.ComponentTypes.TEXT, LABEL, false);
|
|
66
|
-
expect((0, _validateComponent.default)(COMPONENT, DATA)).toBeUndefined();
|
|
67
|
-
});
|
|
68
|
-
it('should return no error when the component is required and not an email type', function () {
|
|
69
|
-
var LABEL = 'Field';
|
|
70
|
-
var COMPONENT = setup(ID, _models.ComponentTypes.TEXT, LABEL, true);
|
|
71
|
-
expect((0, _validateComponent.default)(COMPONENT, DATA)).toBeUndefined();
|
|
72
|
-
});
|
|
73
|
-
it('should return no error when the component is required and of type email', function () {
|
|
74
|
-
var LABEL = 'Field';
|
|
75
|
-
var COMPONENT = setup(ID, _models.ComponentTypes.EMAIL, LABEL, true);
|
|
76
|
-
expect((0, _validateComponent.default)(COMPONENT, DATA)).toBeUndefined();
|
|
77
|
-
});
|
|
78
|
-
it('should return no error when the component is of type email but not required', function () {
|
|
79
|
-
var LABEL = 'Field';
|
|
80
|
-
var COMPONENT = setup(ID, _models.ComponentTypes.EMAIL, LABEL, false);
|
|
81
|
-
expect((0, _validateComponent.default)(COMPONENT, DATA)).toBeUndefined();
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
describe('when the value is an invalid email', function () {
|
|
85
|
-
var ID = 'field';
|
|
86
|
-
|
|
87
|
-
var DATA = _defineProperty({}, ID, 'alpha.bravo@hotmail.com');
|
|
88
|
-
|
|
89
|
-
it('should return no error when the component is not required and not an email type', function () {
|
|
90
|
-
var LABEL = 'Field';
|
|
91
|
-
var COMPONENT = setup(ID, _models.ComponentTypes.TEXT, LABEL, false);
|
|
92
|
-
expect((0, _validateComponent.default)(COMPONENT, DATA)).toBeUndefined();
|
|
93
|
-
});
|
|
94
|
-
it('should return no error when the component is required and not an email type', function () {
|
|
95
|
-
var LABEL = 'Field';
|
|
96
|
-
var COMPONENT = setup(ID, _models.ComponentTypes.TEXT, LABEL, true);
|
|
97
|
-
expect((0, _validateComponent.default)(COMPONENT, DATA)).toBeUndefined();
|
|
98
|
-
});
|
|
99
|
-
it('should return no error when the component is required and of type email', function () {
|
|
100
|
-
var LABEL = 'Field';
|
|
101
|
-
var COMPONENT = setup(ID, _models.ComponentTypes.EMAIL, LABEL, true);
|
|
102
|
-
expect((0, _validateComponent.default)(COMPONENT, DATA)).toEqual({
|
|
103
|
-
id: ID,
|
|
104
|
-
error: "Enter ".concat(LABEL.toLowerCase(), " in the correct format, like jane.doe@homeoffice.gov.uk")
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
it('should return no error when the component is of type email but not required', function () {
|
|
108
|
-
var LABEL = 'Field';
|
|
109
|
-
var COMPONENT = setup(ID, _models.ComponentTypes.EMAIL, LABEL, false);
|
|
110
|
-
expect((0, _validateComponent.default)(COMPONENT, DATA)).toEqual({
|
|
111
|
-
id: ID,
|
|
112
|
-
error: "Enter ".concat(LABEL.toLowerCase(), " in the correct format, like jane.doe@homeoffice.gov.uk")
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
describe('when the component is a Date Input', function () {
|
|
117
|
-
var ID = 'field';
|
|
118
|
-
it('should always reject invalid dates', function () {
|
|
119
|
-
var LABEL = 'Field';
|
|
120
|
-
var COMPONENT = setup(ID, _models.ComponentTypes.DATE, LABEL, false);
|
|
121
|
-
|
|
122
|
-
var DATA = _defineProperty({}, ID, '25-45-2033');
|
|
123
|
-
|
|
124
|
-
expect((0, _validateComponent.default)(COMPONENT, DATA)).toEqual({
|
|
125
|
-
error: 'Month must be between 1 and 12',
|
|
126
|
-
id: ID,
|
|
127
|
-
properties: {
|
|
128
|
-
month: true
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
it('should apply optional validators when specified', function () {
|
|
133
|
-
var LABEL = 'Field';
|
|
134
|
-
|
|
135
|
-
var DATA = _defineProperty({}, ID, '25-3-3033');
|
|
136
|
-
|
|
137
|
-
var ADDITIONAL_VALIDATION = [{
|
|
138
|
-
function: 'mustBeBefore',
|
|
139
|
-
value: 3,
|
|
140
|
-
unit: 'day',
|
|
141
|
-
message: 'Date must be less than 3 days in the future'
|
|
142
|
-
}];
|
|
143
|
-
var COMPONENT = setup(ID, _models.ComponentTypes.DATE, LABEL, false, ADDITIONAL_VALIDATION);
|
|
144
|
-
expect((0, _validateComponent.default)(COMPONENT, DATA)).toEqual({
|
|
145
|
-
error: 'Date must be less than 3 days in the future',
|
|
146
|
-
id: ID,
|
|
147
|
-
properties: {
|
|
148
|
-
day: true,
|
|
149
|
-
month: true,
|
|
150
|
-
year: true
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
describe('when the component is a Time Input', function () {
|
|
156
|
-
var ID = 'field';
|
|
157
|
-
it('should always reject invalid time', function () {
|
|
158
|
-
var LABEL = 'Field';
|
|
159
|
-
var COMPONENT = setup(ID, _models.ComponentTypes.TIME, LABEL, false);
|
|
160
|
-
|
|
161
|
-
var DATA = _defineProperty({}, ID, '25:45');
|
|
162
|
-
|
|
163
|
-
expect((0, _validateComponent.default)(COMPONENT, DATA)).toEqual({
|
|
164
|
-
error: 'Hour must be between 0 and 23',
|
|
165
|
-
id: ID,
|
|
166
|
-
properties: {
|
|
167
|
-
hour: true
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
describe('when the component is a container', function () {
|
|
173
|
-
it('should return an empty array when the container has only valid components', function () {
|
|
174
|
-
var EMAIL_ID = 'email';
|
|
175
|
-
var EMAIL_LABEL = 'Email';
|
|
176
|
-
var EMAIL = setup(EMAIL_ID, _models.ComponentTypes.EMAIL, EMAIL_LABEL, false);
|
|
177
|
-
var ID = 'container';
|
|
178
|
-
var LABEL = 'field';
|
|
179
|
-
var CONTAINER = setup(ID, _models.ComponentTypes.CONTAINER, LABEL, false);
|
|
180
|
-
CONTAINER.components = [EMAIL];
|
|
181
|
-
|
|
182
|
-
var DATA = _defineProperty({}, ID, _defineProperty({}, EMAIL_ID, 'alpha.bravo@digital.homeoffice.gov.uk'));
|
|
183
|
-
|
|
184
|
-
expect((0, _validateComponent.default)(CONTAINER, DATA)).toEqual([]);
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
describe('when the component is a collection', function () {
|
|
188
|
-
it('should return an empty array when the collection has only valid items', function () {
|
|
189
|
-
var EMAIL_ID = 'email';
|
|
190
|
-
var EMAIL_LABEL = 'Email';
|
|
191
|
-
var EMAIL = setup(EMAIL_ID, _models.ComponentTypes.EMAIL, EMAIL_LABEL, false);
|
|
192
|
-
var ID = 'collection';
|
|
193
|
-
var LABEL = 'field';
|
|
194
|
-
var COLLECTION = setup(ID, _models.ComponentTypes.COLLECTION, LABEL, false);
|
|
195
|
-
COLLECTION.item = [EMAIL];
|
|
196
|
-
|
|
197
|
-
var DATA = _defineProperty({}, ID, [_defineProperty({}, EMAIL_ID, 'alpha.bravo@homeoffice.gov.uk'), _defineProperty({}, EMAIL_ID, 'charlie.delta@homeoffice.gov.uk')]);
|
|
198
|
-
|
|
199
|
-
expect((0, _validateComponent.default)(COLLECTION, DATA)).toEqual([]);
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
describe('when the component has a nested component', function () {
|
|
203
|
-
it('should return no error when the radio component contains nested components without errors', function () {
|
|
204
|
-
var NESTED_ID = 'nestedId';
|
|
205
|
-
var NESTED_VALUE = 'nestedValue';
|
|
206
|
-
|
|
207
|
-
var FORMDATA = _defineProperty({}, NESTED_ID, NESTED_VALUE);
|
|
208
|
-
|
|
209
|
-
var COMPONENT = {
|
|
210
|
-
type: 'radios',
|
|
211
|
-
id: 'a',
|
|
212
|
-
data: {
|
|
213
|
-
options: [{
|
|
214
|
-
nested: [{
|
|
215
|
-
type: 'text',
|
|
216
|
-
fieldId: NESTED_ID,
|
|
217
|
-
id: NESTED_ID,
|
|
218
|
-
required: true
|
|
219
|
-
}]
|
|
220
|
-
}]
|
|
221
|
-
}
|
|
222
|
-
};
|
|
223
|
-
expect((0, _validateComponent.default)(COMPONENT, undefined, FORMDATA)).toBeUndefined();
|
|
224
|
-
});
|
|
225
|
-
it('should return an error when the radio component contains nested components with errors', function () {
|
|
226
|
-
var NESTED_ID = 'nestedId';
|
|
227
|
-
var FORMDATA = {};
|
|
228
|
-
var COMPONENT = {
|
|
229
|
-
type: 'radios',
|
|
230
|
-
id: 'a',
|
|
231
|
-
data: {
|
|
232
|
-
options: [{
|
|
233
|
-
nested: [{
|
|
234
|
-
type: 'text',
|
|
235
|
-
fieldId: NESTED_ID,
|
|
236
|
-
id: NESTED_ID,
|
|
237
|
-
required: true
|
|
238
|
-
}]
|
|
239
|
-
}]
|
|
240
|
-
}
|
|
241
|
-
};
|
|
242
|
-
expect((0, _validateComponent.default)(COMPONENT, undefined, FORMDATA)).toEqual([{
|
|
243
|
-
id: "undefined.nestedId",
|
|
244
|
-
error: "Field is required"
|
|
245
|
-
}]);
|
|
246
|
-
});
|
|
247
|
-
it('should return no error when a non selected radio component contains nested components with errors', function () {
|
|
248
|
-
var NESTED_ID = 'nestedId';
|
|
249
|
-
var COMPONENT = {
|
|
250
|
-
type: 'radios',
|
|
251
|
-
id: 'a',
|
|
252
|
-
data: {
|
|
253
|
-
options: [{
|
|
254
|
-
value: 'optionValue',
|
|
255
|
-
nested: [{
|
|
256
|
-
type: 'text',
|
|
257
|
-
fieldId: NESTED_ID,
|
|
258
|
-
id: NESTED_ID,
|
|
259
|
-
required: true
|
|
260
|
-
}]
|
|
261
|
-
}]
|
|
262
|
-
}
|
|
263
|
-
};
|
|
264
|
-
expect((0, _validateComponent.default)(COMPONENT, undefined, {})).toBeUndefined();
|
|
265
|
-
});
|
|
266
|
-
});
|
|
267
|
-
});
|