@ukhomeoffice/cop-react-form-renderer 5.0.0-alpha → 5.0.0
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 +18 -7
- package/dist/components/CheckYourAnswers/Answer.test.js +137 -0
- package/dist/components/CheckYourAnswers/CheckYourAnswers.js +70 -46
- package/dist/components/CheckYourAnswers/CheckYourAnswers.stories.mdx +410 -0
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +551 -0
- package/dist/components/CollectionPage/CollectionPage.js +15 -10
- package/dist/components/CollectionPage/CollectionPage.test.js +382 -0
- package/dist/components/FormComponent/Collection.js +91 -48
- package/dist/components/FormComponent/Collection.scss +2 -1
- package/dist/components/FormComponent/Collection.test.js +807 -0
- package/dist/components/FormComponent/Container.js +35 -16
- package/dist/components/FormComponent/Container.test.js +370 -0
- package/dist/components/FormComponent/FormComponent.js +39 -13
- package/dist/components/FormComponent/FormComponent.stories.mdx +184 -0
- package/dist/components/FormComponent/FormComponent.test.js +226 -0
- package/dist/components/FormComponent/helpers/addLabel.js +5 -4
- package/dist/components/FormComponent/helpers/getComponentFieldSet.js +16 -0
- package/dist/components/FormComponent/helpers/getComponentFieldSet.test.js +29 -0
- package/dist/components/FormComponent/helpers/index.js +8 -1
- package/dist/components/FormPage/FormPage.js +69 -30
- package/dist/components/FormPage/FormPage.stories.mdx +155 -0
- package/dist/components/FormPage/FormPage.test.js +330 -0
- package/dist/components/FormRenderer/FormRenderer.js +142 -228
- package/dist/components/FormRenderer/FormRenderer.stories.mdx +183 -0
- package/dist/components/FormRenderer/FormRenderer.test.js +968 -0
- package/dist/components/FormRenderer/handlers/index.js +1 -2
- package/dist/components/FormRenderer/handlers/navigate.js +3 -1
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.js +35 -14
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.test.js +88 -5
- package/dist/components/FormRenderer/helpers/getCYA.js +11 -2
- package/dist/components/FormRenderer/helpers/getNextPageId.js +13 -7
- package/dist/components/FormRenderer/helpers/getRelevantPages.js +10 -2
- package/dist/components/FormRenderer/helpers/getRelevantPages.test.js +1 -1
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +2 -2
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +6 -2
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.js +171 -51
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.test.js +307 -24
- package/dist/components/FormRenderer/helpers/index.js +1 -2
- package/dist/components/FormRenderer/onCYAAction.js +108 -0
- package/dist/components/FormRenderer/onCYAAction.test.js +583 -0
- package/dist/components/FormRenderer/onPageAction.js +145 -0
- package/dist/components/FormRenderer/onPageAction.test.js +678 -0
- package/dist/components/FormRenderer/onTaskAction.js +48 -0
- package/dist/components/FormRenderer/onTaskAction.test.js +217 -0
- package/dist/components/PageActions/ActionButton.js +0 -3
- package/dist/components/PageActions/ActionButton.test.js +93 -0
- package/dist/components/PageActions/PageActions.js +2 -2
- package/dist/components/PageActions/PageActions.stories.mdx +74 -0
- package/dist/components/PageActions/PageActions.test.js +132 -0
- package/dist/components/SummaryList/GroupAction.js +2 -2
- package/dist/components/SummaryList/GroupAction.test.js +80 -0
- package/dist/components/SummaryList/RowAction.js +2 -2
- package/dist/components/SummaryList/RowAction.test.js +80 -0
- package/dist/components/SummaryList/SummaryList.js +29 -12
- package/dist/components/SummaryList/SummaryList.scss +19 -0
- package/dist/components/SummaryList/SummaryList.stories.mdx +90 -0
- package/dist/components/SummaryList/SummaryList.test.js +400 -0
- package/dist/components/SummaryList/SummaryListHeadingRow.js +30 -0
- package/dist/components/SummaryList/SummaryListRow.js +5 -2
- package/dist/components/SummaryList/helpers/getGroupActionAttributes.js +2 -1
- package/dist/components/SummaryList/helpers/getRowActionAttributes.js +2 -1
- package/dist/components/TaskList/Task.js +3 -3
- package/dist/components/TaskList/Task.test.js +167 -0
- package/dist/components/TaskList/TaskList.js +73 -22
- package/dist/components/TaskList/TaskList.stories.mdx +164 -0
- package/dist/components/TaskList/TaskList.test.js +389 -0
- package/dist/components/TaskList/TaskState.js +2 -2
- package/dist/components/TaskList/TaskState.test.js +86 -0
- package/dist/components/index.js +14 -0
- package/dist/context/HooksContext/HooksContext.js +72 -8
- package/dist/context/HooksContext/HooksContext.test.js +44 -0
- package/dist/context/ValidationContext/ValidationContext.js +38 -28
- package/dist/context/ValidationContext/ValidationContext.test.js +84 -0
- package/dist/hooks/useAxios.js +10 -12
- package/dist/hooks/useGetRequest.js +48 -49
- package/dist/hooks/useRefData.js +7 -4
- package/dist/index.js +34 -1
- package/dist/json/addressDetails.json +149 -0
- package/dist/json/areYouACivilServant.json +7 -0
- package/dist/json/firstForm.json +94 -0
- package/dist/json/grade.json +108 -0
- package/dist/json/group.data.json +21 -0
- package/dist/json/group.json +402 -0
- package/dist/json/groupOfRow.json +137 -0
- package/dist/json/groupOfRowData.json +15 -0
- package/dist/json/port.json +346 -0
- package/dist/json/saveAndContinue.json +98 -0
- package/dist/json/sublocation.json +859 -0
- package/dist/json/taskList.json +265 -0
- package/dist/json/team.json +17351 -0
- package/dist/json/terminal.json +81 -0
- package/dist/json/userProfile.data.json +21 -0
- package/dist/json/userProfile.json +276 -0
- package/dist/models/ComponentTypes.js +8 -0
- package/dist/models/PageAction.js +4 -1
- package/dist/models/TaskStates.js +10 -2
- package/dist/models/index.js +16 -1
- package/dist/setupTests.js +46 -0
- package/dist/utils/CheckYourAnswers/getCYAAction.js +5 -5
- package/dist/utils/CheckYourAnswers/getCYAAction.test.js +121 -0
- package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.js +6 -2
- package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.test.js +71 -0
- package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.js +6 -2
- package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.test.js +55 -0
- package/dist/utils/CheckYourAnswers/getCYARow.js +14 -11
- package/dist/utils/CheckYourAnswers/getCYARow.test.js +291 -0
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.js +4 -1
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.test.js +70 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.js +15 -10
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.test.js +288 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +94 -36
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +414 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.js +21 -7
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.test.js +486 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +11 -3
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.test.js +346 -0
- package/dist/utils/CheckYourAnswers/showComponentCYA.js +19 -3
- package/dist/utils/CheckYourAnswers/showComponentCYA.test.js +143 -0
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.js +5 -1
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.test.js +40 -0
- package/dist/utils/CollectionPage/getCollectionPageActiveIndex.test.js +53 -0
- package/dist/utils/CollectionPage/mergeCollectionPages.js +25 -17
- package/dist/utils/CollectionPage/mergeCollectionPages.test.js +130 -0
- package/dist/utils/Component/addShowWhen.js +44 -0
- package/dist/utils/Component/addShowWhen.test.js +216 -0
- package/dist/utils/Component/applyToComponentTree.js +71 -0
- package/dist/utils/Component/applyToComponentTree.test.js +127 -0
- package/dist/utils/Component/cleanAttributes.js +8 -2
- package/dist/utils/Component/cleanAttributes.test.js +68 -0
- package/dist/utils/Component/elevateNestedComponents.js +4 -1
- package/dist/utils/Component/elevateNestedComponents.test.js +122 -0
- package/dist/utils/Component/getComponent.js +80 -11
- package/dist/utils/Component/getComponentTests/getComponent.autocomplete.test.js +4 -4
- package/dist/utils/Component/getComponentTests/getComponent.calculation.test.js +25 -24
- package/dist/utils/Component/getComponentTests/getComponent.checkboxes.test.js +66 -5
- package/dist/utils/Component/getComponentTests/getComponent.date.test.js +2 -2
- package/dist/utils/Component/getComponentTests/getComponent.details.test.js +9 -7
- package/dist/utils/Component/getComponentTests/getComponent.email.test.js +3 -3
- package/dist/utils/Component/getComponentTests/getComponent.file.test.js +3 -3
- package/dist/utils/Component/getComponentTests/getComponent.list.test.js +44 -0
- package/dist/utils/Component/getComponentTests/{getComponent.textarea.test.js → getComponent.multifile.test.js} +29 -21
- package/dist/utils/Component/getComponentTests/getComponent.nested.test.js +159 -83
- package/dist/utils/Component/getComponentTests/getComponent.paragraph.test.js +43 -0
- package/dist/utils/Component/getComponentTests/getComponent.phoneNumber.test.js +3 -3
- package/dist/utils/Component/getComponentTests/getComponent.radios.test.js +55 -5
- package/dist/utils/Component/getComponentTests/getComponent.select.test.js +3 -9
- package/dist/utils/Component/getComponentTests/getComponent.text.test.js +3 -3
- package/dist/utils/Component/getComponentTests/getComponent.textArea.test.js +109 -0
- package/dist/utils/Component/getComponentTests/getComponent.time.test.js +7 -7
- package/dist/utils/Component/getDefaultValue.js +4 -1
- package/dist/utils/Component/getDefaultValue.test.js +50 -0
- package/dist/utils/Component/index.js +2 -0
- package/dist/utils/Component/isEditable.js +2 -2
- package/dist/utils/Component/isEditable.test.js +43 -0
- package/dist/utils/Component/optionIsSelected.js +22 -0
- package/dist/utils/Component/optionIsSelected.test.js +42 -0
- package/dist/utils/Component/setupContainerComponentsPath.js +40 -0
- package/dist/utils/Component/setupContainerComponentsPath.test.js +78 -0
- package/dist/utils/Component/showComponent.test.js +156 -0
- package/dist/utils/Component/wrapInFormGroup.js +1 -1
- package/dist/utils/Condition/meetsAllConditions.js +1 -1
- package/dist/utils/Condition/meetsAllConditions.test.js +61 -0
- package/dist/utils/Condition/meetsCondition.js +74 -4
- package/dist/utils/Condition/meetsCondition.test.js +763 -0
- package/dist/utils/Condition/meetsOneCondition.js +1 -1
- package/dist/utils/Condition/meetsOneCondition.test.js +100 -0
- package/dist/utils/Condition/setupConditions.js +6 -3
- package/dist/utils/Condition/setupConditions.test.js +33 -0
- package/dist/utils/Container/getEditableComponents.test.js +135 -0
- package/dist/utils/Container/setupNesting.js +21 -2
- package/dist/utils/Container/setupNesting.test.js +145 -0
- package/dist/utils/Container/showContainer.test.js +178 -0
- package/dist/utils/Data/applyFormula.js +20 -11
- package/dist/utils/Data/applyFormula.test.js +263 -0
- package/dist/utils/Data/getAutocompleteSource.js +6 -2
- package/dist/utils/Data/getAutocompleteSource.test.js +352 -0
- package/dist/utils/Data/getDataPath.test.js +48 -0
- package/dist/utils/Data/getOptions.js +17 -3
- package/dist/utils/Data/getOptions.test.js +140 -0
- package/dist/utils/Data/getSourceData.js +2 -2
- package/dist/utils/Data/getSourceData.test.js +153 -0
- package/dist/utils/Data/refDataToOptions.js +4 -1
- package/dist/utils/Data/refDataToOptions.test.js +196 -0
- package/dist/utils/Data/setDataItem.test.js +110 -0
- package/dist/utils/Data/setupFormData.js +39 -16
- package/dist/utils/Data/setupFormData.test.js +410 -0
- package/dist/utils/Data/setupRefDataUrlForComponent.js +4 -1
- package/dist/utils/Data/setupRefDataUrlForComponent.test.js +131 -0
- package/dist/utils/FormPage/applyConditionalProperties.js +35 -0
- package/dist/utils/FormPage/applyConditionalProperties.test.js +61 -0
- package/dist/utils/FormPage/getFormPage.js +5 -2
- package/dist/utils/FormPage/getFormPage.test.js +206 -0
- package/dist/utils/FormPage/getFormPages.js +4 -1
- package/dist/utils/FormPage/getFormPages.test.js +97 -0
- package/dist/utils/FormPage/getPageActions.js +8 -4
- package/dist/utils/FormPage/getPageActions.test.js +114 -0
- package/dist/utils/FormPage/getParagraphFromText.test.js +27 -0
- package/dist/utils/FormPage/index.js +2 -0
- package/dist/utils/FormPage/showFormPage.js +2 -2
- package/dist/utils/FormPage/showFormPage.test.js +180 -0
- package/dist/utils/FormPage/showFormPageCYA.js +1 -0
- package/dist/utils/FormPage/showFormPageCYA.test.js +28 -0
- package/dist/utils/FormPage/useComponent.js +29 -14
- package/dist/utils/FormPage/useComponent.test.js +167 -0
- package/dist/utils/Format/formatData.test.js +45 -0
- package/dist/utils/Format/formatDataForComponent.js +2 -1
- package/dist/utils/Format/formatDataForComponent.test.js +142 -0
- package/dist/utils/Format/formatDataForForm.js +4 -1
- package/dist/utils/Format/formatDataForForm.test.js +81 -0
- package/dist/utils/Format/formatDataForPage.test.js +99 -0
- package/dist/utils/Hub/getFormHub.test.js +105 -0
- package/dist/utils/Meta/documents/getDocuments.test.js +4 -1
- package/dist/utils/Meta/documents/index.js +2 -2
- package/dist/utils/Meta/documents/setDocumentsForField.js +31 -0
- package/dist/utils/Meta/documents/setDocumentsForField.test.js +59 -0
- package/dist/utils/Operate/checkValueIsTruthy.test.js +42 -0
- package/dist/utils/Operate/getFirstOf.js +31 -0
- package/dist/utils/Operate/getFirstOf.test.js +86 -0
- package/dist/utils/Operate/getIndexOfMatchingValueIn.test.js +163 -0
- package/dist/utils/Operate/persistValueInFormData.js +2 -1
- package/dist/utils/Operate/persistValueInFormData.test.js +115 -0
- package/dist/utils/Operate/runPageOperations.js +3 -1
- package/dist/utils/Operate/runPageOperations.test.js +105 -0
- package/dist/utils/Operate/setValueInFormData.test.js +44 -0
- package/dist/utils/Operate/shouldRun.js +16 -13
- package/dist/utils/Operate/shouldRun.test.js +66 -0
- package/dist/utils/Validate/additional/conditionallyRequired.js +24 -0
- package/dist/utils/Validate/additional/conditionallyRequired.test.js +73 -0
- package/dist/utils/Validate/additional/index.js +13 -4
- package/dist/utils/Validate/additional/mustBeAfter.js +8 -6
- package/dist/utils/Validate/additional/mustBeAfter.test.js +15 -1
- package/dist/utils/Validate/additional/mustBeBefore.js +9 -5
- package/dist/utils/Validate/additional/mustBeBefore.test.js +14 -0
- package/dist/utils/Validate/additional/mustBeEarlierDateTime.js +1 -1
- package/dist/utils/Validate/additional/mustBeEarlierDateTime.test.js +6 -3
- package/dist/utils/Validate/additional/mustBeGreaterThan.js +22 -0
- package/dist/utils/Validate/additional/mustBeGreaterThan.test.js +56 -0
- package/dist/utils/Validate/additional/mustBeInTheFuture.js +1 -1
- package/dist/utils/Validate/additional/mustBeInThePast.js +5 -5
- package/dist/utils/Validate/additional/mustBeLessThan.js +7 -6
- package/dist/utils/Validate/additional/mustBeLessThan.test.js +11 -1
- package/dist/utils/Validate/additional/mustBeNumbersOnly.js +9 -5
- package/dist/utils/Validate/additional/mustBeNumbersOnly.test.js +10 -2
- package/dist/utils/Validate/additional/mustEnterAtLeastOne.js +1 -0
- package/dist/utils/Validate/additional/mustEnterAtLeastOne.test.js +4 -1
- package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.js +19 -0
- package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.test.js +36 -0
- package/dist/utils/Validate/additional/mustSelectOnlyOne.js +29 -0
- package/dist/utils/Validate/additional/mustSelectOnlyOne.test.js +52 -0
- package/dist/utils/Validate/additional/utils.js +18 -18
- package/dist/utils/Validate/index.js +6 -0
- package/dist/utils/Validate/validateCollection.js +20 -5
- package/dist/utils/Validate/validateCollection.test.js +125 -0
- package/dist/utils/Validate/validateComponent.js +36 -20
- package/dist/utils/Validate/validateComponent.test.js +365 -0
- package/dist/utils/Validate/validateContainer.js +9 -3
- package/dist/utils/Validate/validateContainer.test.js +75 -0
- package/dist/utils/Validate/validateDate.js +4 -3
- package/dist/utils/Validate/validateDate.test.js +114 -0
- package/dist/utils/Validate/validateEmail.js +14 -1
- package/dist/utils/Validate/validateEmail.test.js +74 -0
- package/dist/utils/Validate/validateMultifile.js +32 -0
- package/dist/utils/Validate/validateMultifile.test.js +47 -0
- package/dist/utils/Validate/validatePage.js +12 -6
- package/dist/utils/Validate/validatePage.test.js +472 -0
- package/dist/utils/Validate/validateRegex.js +2 -5
- package/dist/utils/Validate/validateRegex.test.js +42 -0
- package/dist/utils/Validate/validateRequired.js +2 -4
- package/dist/utils/Validate/validateRequired.test.js +63 -0
- package/dist/utils/Validate/validateTextArea.js +37 -0
- package/dist/utils/Validate/validateTextArea.test.js +42 -0
- package/dist/utils/Validate/validateTime.js +2 -2
- package/dist/utils/Validate/validateTime.test.js +59 -0
- package/dist/utils/index.js +4 -1
- package/package.json +35 -50
- package/dist/utils/Meta/documents/setDocumentForField.js +0 -29
- package/dist/utils/Meta/documents/setDocumentForField.test.js +0 -49
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _setDataItem = _interopRequireDefault(require("./setDataItem"));
|
|
4
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
5
|
+
describe('utils.Data.setDataItem', function () {
|
|
6
|
+
it('should handle a null data object', function () {
|
|
7
|
+
var DATA = null;
|
|
8
|
+
var FIELD_ID = 'alpha.bravo.charlie';
|
|
9
|
+
var VALUE = 'delta';
|
|
10
|
+
expect((0, _setDataItem.default)(DATA, FIELD_ID, VALUE)).toBeNull();
|
|
11
|
+
expect(DATA).toBeNull();
|
|
12
|
+
});
|
|
13
|
+
it('should handle an undefined data object', function () {
|
|
14
|
+
var DATA = undefined;
|
|
15
|
+
var FIELD_ID = 'alpha.bravo.charlie';
|
|
16
|
+
var VALUE = 'delta';
|
|
17
|
+
expect((0, _setDataItem.default)(DATA, FIELD_ID, VALUE)).toBeUndefined();
|
|
18
|
+
expect(DATA).toBeUndefined();
|
|
19
|
+
});
|
|
20
|
+
it('should handle a null fieldId', function () {
|
|
21
|
+
var DATA = {};
|
|
22
|
+
var FIELD_ID = null;
|
|
23
|
+
var VALUE = 'delta';
|
|
24
|
+
expect((0, _setDataItem.default)(DATA, FIELD_ID, VALUE)).toMatchObject({});
|
|
25
|
+
expect(DATA).toMatchObject({});
|
|
26
|
+
});
|
|
27
|
+
it('should handle an undefined fieldId', function () {
|
|
28
|
+
var DATA = {};
|
|
29
|
+
var FIELD_ID = undefined;
|
|
30
|
+
var VALUE = 'delta';
|
|
31
|
+
expect((0, _setDataItem.default)(DATA, FIELD_ID, VALUE)).toMatchObject({});
|
|
32
|
+
expect(DATA).toMatchObject({});
|
|
33
|
+
});
|
|
34
|
+
it('should handle an empty fieldId', function () {
|
|
35
|
+
var DATA = {};
|
|
36
|
+
var FIELD_ID = '';
|
|
37
|
+
var VALUE = 'delta';
|
|
38
|
+
expect((0, _setDataItem.default)(DATA, FIELD_ID, VALUE)).toMatchObject({});
|
|
39
|
+
expect(DATA).toMatchObject({});
|
|
40
|
+
});
|
|
41
|
+
it('should appropriately set a nested value', function () {
|
|
42
|
+
var DATA = {
|
|
43
|
+
alpha: {}
|
|
44
|
+
};
|
|
45
|
+
var FIELD_ID = 'alpha.bravo.charlie';
|
|
46
|
+
var VALUE = 'delta';
|
|
47
|
+
expect((0, _setDataItem.default)(DATA, FIELD_ID, VALUE)).toMatchObject({
|
|
48
|
+
alpha: {
|
|
49
|
+
bravo: {
|
|
50
|
+
charlie: VALUE
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
expect(DATA).toMatchObject({
|
|
55
|
+
alpha: {
|
|
56
|
+
bravo: {
|
|
57
|
+
charlie: VALUE
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
it('should appropriately change a nested value', function () {
|
|
63
|
+
var DATA = {
|
|
64
|
+
alpha: {
|
|
65
|
+
bravo: {
|
|
66
|
+
charlie: 'echo'
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
var FIELD_ID = 'alpha.bravo.charlie';
|
|
71
|
+
var VALUE = 'delta';
|
|
72
|
+
expect((0, _setDataItem.default)(DATA, FIELD_ID, VALUE)).toMatchObject({
|
|
73
|
+
alpha: {
|
|
74
|
+
bravo: {
|
|
75
|
+
charlie: VALUE
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
expect(DATA).toMatchObject({
|
|
80
|
+
alpha: {
|
|
81
|
+
bravo: {
|
|
82
|
+
charlie: VALUE
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
it('should handle a parent node that is not an object and convert it appropriately', function () {
|
|
88
|
+
var DATA = {
|
|
89
|
+
alpha: {
|
|
90
|
+
bravo: 'echo'
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
var FIELD_ID = 'alpha.bravo.charlie';
|
|
94
|
+
var VALUE = 'delta';
|
|
95
|
+
expect((0, _setDataItem.default)(DATA, FIELD_ID, VALUE)).toMatchObject({
|
|
96
|
+
alpha: {
|
|
97
|
+
bravo: {
|
|
98
|
+
charlie: VALUE
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
expect(DATA).toMatchObject({
|
|
103
|
+
alpha: {
|
|
104
|
+
bravo: {
|
|
105
|
+
charlie: VALUE
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
});
|
|
@@ -6,30 +6,52 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
8
8
|
var _getSourceData = _interopRequireDefault(require("./getSourceData"));
|
|
9
|
+
var _setDataItem = _interopRequireDefault(require("./setDataItem"));
|
|
9
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
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); }
|
|
10
12
|
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; }
|
|
11
13
|
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
|
-
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; }
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
14
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
15
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
16
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
17
|
+
var setDefaultDateValue = function setDefaultDateValue(date, data, fullPath) {
|
|
18
|
+
var val = date.defaultValue === 'today' ? (0, _dayjs.default)().format('DD-MM-YYYY') : date.defaultValue;
|
|
19
|
+
(0, _setDataItem.default)(data, "".concat(fullPath).concat(date.fieldId), val);
|
|
19
20
|
};
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
|
-
* This currently will not work for collections
|
|
23
|
+
* This currently will not work for collections.
|
|
23
24
|
* If support is required it will need to be added.
|
|
24
25
|
*/
|
|
25
|
-
var setupDefaultValue = function setupDefaultValue(component, data) {
|
|
26
|
-
|
|
26
|
+
var setupDefaultValue = function setupDefaultValue(component, data, fullPath) {
|
|
27
|
+
var thisComponent = component;
|
|
28
|
+
var componentFullPath = "".concat(fullPath).concat(component.fieldId);
|
|
29
|
+
if (component.type === 'container') {
|
|
30
|
+
var _component$components;
|
|
31
|
+
(_component$components = component.components) === null || _component$components === void 0 ? void 0 : _component$components.forEach(function (comp) {
|
|
32
|
+
setupDefaultValue(comp, data, "".concat(componentFullPath, "."));
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
if ((component.defaultValue || component.defaultObjectValue) && !(0, _getSourceData.default)(data, componentFullPath)) {
|
|
27
36
|
switch (component.type) {
|
|
28
37
|
case 'date':
|
|
29
|
-
setDefaultDateValue(component, data);
|
|
38
|
+
setDefaultDateValue(component, data, fullPath);
|
|
30
39
|
break;
|
|
31
40
|
default:
|
|
32
|
-
|
|
41
|
+
// defaultValue is expected to be a string, default object value is an object. Keeping defaultValue
|
|
42
|
+
// as a string is required for consuming apps using FormIO, this restriction could be removed in the future.
|
|
43
|
+
{
|
|
44
|
+
if (component.defaultObjectValue) {
|
|
45
|
+
Object.keys(component.defaultObjectValue).forEach(function (value) {
|
|
46
|
+
if (typeof component.defaultObjectValue[value] === 'string' && (0, _getSourceData.default)(data, component.defaultObjectValue[value]) !== undefined) {
|
|
47
|
+
thisComponent.defaultObjectValue[value] = (0, _getSourceData.default)(data, component.defaultObjectValue[value]);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
var defaultToUse = component.defaultObjectValue ? component.defaultObjectValue : component.defaultValue;
|
|
52
|
+
(0, _setDataItem.default)(data, componentFullPath, defaultToUse);
|
|
53
|
+
delete thisComponent.defaultObjectValue;
|
|
54
|
+
}
|
|
33
55
|
}
|
|
34
56
|
}
|
|
35
57
|
if (component.defaultValue) {
|
|
@@ -37,12 +59,12 @@ var setupDefaultValue = function setupDefaultValue(component, data) {
|
|
|
37
59
|
// both a 'value' and 'defaultValue' prop set.
|
|
38
60
|
// defaultValue is safe to delete once we've tried
|
|
39
61
|
// to use it.
|
|
40
|
-
delete
|
|
62
|
+
delete thisComponent.defaultValue;
|
|
41
63
|
}
|
|
42
64
|
};
|
|
43
65
|
var setupDefaultValuesForComponents = function setupDefaultValuesForComponents(components, data) {
|
|
44
66
|
components.forEach(function (component) {
|
|
45
|
-
return setupDefaultValue(component, data);
|
|
67
|
+
return setupDefaultValue(component, data, '');
|
|
46
68
|
});
|
|
47
69
|
};
|
|
48
70
|
var setupPageDefaultValues = function setupPageDefaultValues(pages, data) {
|
|
@@ -50,13 +72,14 @@ var setupPageDefaultValues = function setupPageDefaultValues(pages, data) {
|
|
|
50
72
|
page.components.filter(function (c) {
|
|
51
73
|
return !c.use;
|
|
52
74
|
}).forEach(function (component) {
|
|
53
|
-
return setupDefaultValue(component, data);
|
|
75
|
+
return setupDefaultValue(component, data, '');
|
|
54
76
|
});
|
|
55
77
|
});
|
|
56
78
|
};
|
|
57
79
|
var setupComponentSourceData = function setupComponentSourceData(component, data) {
|
|
80
|
+
var componentSourceData = data;
|
|
58
81
|
if (component.source) {
|
|
59
|
-
|
|
82
|
+
componentSourceData[component.fieldId] = (0, _getSourceData.default)(componentSourceData, component.source.field);
|
|
60
83
|
}
|
|
61
84
|
};
|
|
62
85
|
var setupSourceDataForComponents = function setupSourceDataForComponents(components, data) {
|
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _setupFormData = _interopRequireDefault(require("./setupFormData"));
|
|
4
|
+
var _userProfile = _interopRequireDefault(require("../../json/userProfile.json"));
|
|
5
|
+
var _userProfileData = _interopRequireDefault(require("../../json/userProfile.data.json"));
|
|
6
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
7
|
+
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); }
|
|
8
|
+
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; }
|
|
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
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
12
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
13
|
+
describe('utils', function () {
|
|
14
|
+
describe('Data', function () {
|
|
15
|
+
describe('setupFormData', function () {
|
|
16
|
+
it('should populate a simple form', function () {
|
|
17
|
+
var PAGES = [];
|
|
18
|
+
var COMPONENTS = [{
|
|
19
|
+
fieldId: 'testField',
|
|
20
|
+
source: {
|
|
21
|
+
field: 'sourceField'
|
|
22
|
+
}
|
|
23
|
+
}];
|
|
24
|
+
var DATA = {
|
|
25
|
+
sourceField: 'VALUE'
|
|
26
|
+
};
|
|
27
|
+
var RESULT = (0, _setupFormData.default)(PAGES, COMPONENTS, DATA);
|
|
28
|
+
expect(RESULT).toEqual({
|
|
29
|
+
sourceField: 'VALUE',
|
|
30
|
+
testField: 'VALUE'
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
it('should handle a missing source field', function () {
|
|
34
|
+
var PAGES = [];
|
|
35
|
+
var COMPONENTS = [{
|
|
36
|
+
fieldId: 'testField',
|
|
37
|
+
source: {
|
|
38
|
+
field: 'otherSourceField'
|
|
39
|
+
}
|
|
40
|
+
}];
|
|
41
|
+
var DATA = {
|
|
42
|
+
sourceField: 'VALUE'
|
|
43
|
+
};
|
|
44
|
+
var RESULT = (0, _setupFormData.default)(PAGES, COMPONENTS, DATA);
|
|
45
|
+
expect(RESULT).toEqual({
|
|
46
|
+
sourceField: 'VALUE',
|
|
47
|
+
testField: undefined
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
it('should handle a nested source field', function () {
|
|
51
|
+
var PAGES = [];
|
|
52
|
+
var COMPONENTS = [{
|
|
53
|
+
fieldId: 'testField',
|
|
54
|
+
source: {
|
|
55
|
+
field: 'nested.sourceField'
|
|
56
|
+
}
|
|
57
|
+
}];
|
|
58
|
+
var DATA = {
|
|
59
|
+
nested: {
|
|
60
|
+
sourceField: 'VALUE'
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
var RESULT = (0, _setupFormData.default)(PAGES, COMPONENTS, DATA);
|
|
64
|
+
expect(RESULT).toEqual({
|
|
65
|
+
nested: {
|
|
66
|
+
sourceField: 'VALUE'
|
|
67
|
+
},
|
|
68
|
+
testField: 'VALUE'
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
it('should handle a missing nested source field', function () {
|
|
72
|
+
var PAGES = [];
|
|
73
|
+
var COMPONENTS = [{
|
|
74
|
+
fieldId: 'testField',
|
|
75
|
+
source: {
|
|
76
|
+
field: 'nested.otherSourceField'
|
|
77
|
+
}
|
|
78
|
+
}];
|
|
79
|
+
var DATA = {
|
|
80
|
+
nested: {
|
|
81
|
+
sourceField: 'VALUE'
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
var RESULT = (0, _setupFormData.default)(PAGES, COMPONENTS, DATA);
|
|
85
|
+
expect(RESULT).toEqual({
|
|
86
|
+
nested: {
|
|
87
|
+
sourceField: 'VALUE'
|
|
88
|
+
},
|
|
89
|
+
testField: undefined
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
it('should handle an entirely missing nested source field', function () {
|
|
93
|
+
var PAGES = [];
|
|
94
|
+
var COMPONENTS = [{
|
|
95
|
+
fieldId: 'testField',
|
|
96
|
+
source: {
|
|
97
|
+
field: 'otherNested.sourceField'
|
|
98
|
+
}
|
|
99
|
+
}];
|
|
100
|
+
var DATA = {
|
|
101
|
+
nested: {
|
|
102
|
+
sourceField: 'VALUE'
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
var RESULT = (0, _setupFormData.default)(PAGES, COMPONENTS, DATA);
|
|
106
|
+
expect(RESULT).toEqual({
|
|
107
|
+
nested: {
|
|
108
|
+
sourceField: 'VALUE'
|
|
109
|
+
},
|
|
110
|
+
testField: undefined
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
it('should handle sources within pages', function () {
|
|
114
|
+
var PAGES = [{
|
|
115
|
+
components: [{
|
|
116
|
+
fieldId: 'pageField',
|
|
117
|
+
source: {
|
|
118
|
+
field: 'pageSourceField'
|
|
119
|
+
}
|
|
120
|
+
}]
|
|
121
|
+
}, {
|
|
122
|
+
components: [{
|
|
123
|
+
fieldId: 'secondPageField',
|
|
124
|
+
source: {
|
|
125
|
+
field: 'secondPageSourceField'
|
|
126
|
+
}
|
|
127
|
+
}]
|
|
128
|
+
}];
|
|
129
|
+
var COMPONENTS = [{
|
|
130
|
+
fieldId: 'testField',
|
|
131
|
+
source: {
|
|
132
|
+
field: 'nested.sourceField'
|
|
133
|
+
}
|
|
134
|
+
}];
|
|
135
|
+
var DATA = {
|
|
136
|
+
nested: {
|
|
137
|
+
sourceField: 'VALUE'
|
|
138
|
+
},
|
|
139
|
+
pageSourceField: 'PAGE 1',
|
|
140
|
+
secondPageSourceField: 'Bob'
|
|
141
|
+
};
|
|
142
|
+
var RESULT = (0, _setupFormData.default)(PAGES, COMPONENTS, DATA);
|
|
143
|
+
expect(RESULT).toEqual({
|
|
144
|
+
nested: {
|
|
145
|
+
sourceField: 'VALUE'
|
|
146
|
+
},
|
|
147
|
+
pageSourceField: 'PAGE 1',
|
|
148
|
+
secondPageSourceField: 'Bob',
|
|
149
|
+
testField: 'VALUE',
|
|
150
|
+
pageField: 'PAGE 1',
|
|
151
|
+
secondPageField: 'Bob'
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
it('should ignore sources within pages that reference a top-level component', function () {
|
|
155
|
+
var PAGES = [{
|
|
156
|
+
components: [{
|
|
157
|
+
fieldId: 'pageField',
|
|
158
|
+
use: 'testField',
|
|
159
|
+
source: {
|
|
160
|
+
field: 'pageSourceField'
|
|
161
|
+
}
|
|
162
|
+
}]
|
|
163
|
+
}, {
|
|
164
|
+
components: [{
|
|
165
|
+
fieldId: 'secondPageField',
|
|
166
|
+
source: {
|
|
167
|
+
field: 'secondPageSourceField'
|
|
168
|
+
}
|
|
169
|
+
}]
|
|
170
|
+
}];
|
|
171
|
+
var COMPONENTS = [{
|
|
172
|
+
fieldId: 'testField',
|
|
173
|
+
source: {
|
|
174
|
+
field: 'nested.sourceField'
|
|
175
|
+
}
|
|
176
|
+
}];
|
|
177
|
+
var DATA = {
|
|
178
|
+
nested: {
|
|
179
|
+
sourceField: 'VALUE'
|
|
180
|
+
},
|
|
181
|
+
pageSourceField: 'PAGE 1',
|
|
182
|
+
secondPageSourceField: 'Bob'
|
|
183
|
+
};
|
|
184
|
+
var RESULT = (0, _setupFormData.default)(PAGES, COMPONENTS, DATA);
|
|
185
|
+
expect(RESULT).toEqual({
|
|
186
|
+
nested: {
|
|
187
|
+
sourceField: 'VALUE'
|
|
188
|
+
},
|
|
189
|
+
pageSourceField: 'PAGE 1',
|
|
190
|
+
secondPageSourceField: 'Bob',
|
|
191
|
+
testField: 'VALUE',
|
|
192
|
+
secondPageField: 'Bob'
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
it('should populate data for the user profile configuration and source', function () {
|
|
196
|
+
var pages = _userProfile.default.pages,
|
|
197
|
+
components = _userProfile.default.components;
|
|
198
|
+
var RESULT = (0, _setupFormData.default)(pages, components, _userProfileData.default);
|
|
199
|
+
|
|
200
|
+
// It should produce an aggregation of the original source data (USER_PROFILE_DATA)
|
|
201
|
+
// and data calculated for the fields, based on that source data.
|
|
202
|
+
expect(RESULT).toEqual(_objectSpread(_objectSpread({}, _userProfileData.default), {}, {
|
|
203
|
+
firstName: _userProfileData.default.currentUser.givenName,
|
|
204
|
+
surname: _userProfileData.default.currentUser.familyName,
|
|
205
|
+
team: _userProfileData.default.userDetails.defaultteam,
|
|
206
|
+
staffGradeId: _userProfileData.default.userDetails.gradeid,
|
|
207
|
+
linemanagerEmail: _userProfileData.default.userDetails.linemanagerEmail,
|
|
208
|
+
delegateEmails: _userProfileData.default.userDetails.delegateEmails
|
|
209
|
+
}));
|
|
210
|
+
});
|
|
211
|
+
it('should handle a default value field', function () {
|
|
212
|
+
var PAGES = [];
|
|
213
|
+
var COMPONENTS = [{
|
|
214
|
+
fieldId: 'testField',
|
|
215
|
+
type: 'text',
|
|
216
|
+
defaultValue: 'VALUE'
|
|
217
|
+
}];
|
|
218
|
+
var DATA = {};
|
|
219
|
+
var RESULT = (0, _setupFormData.default)(PAGES, COMPONENTS, DATA);
|
|
220
|
+
expect(RESULT).toEqual({
|
|
221
|
+
testField: 'VALUE'
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
it('should handle a default value field with defaultObjectValue', function () {
|
|
225
|
+
var PAGES = [];
|
|
226
|
+
var COMPONENTS = [{
|
|
227
|
+
fieldId: 'testField',
|
|
228
|
+
type: 'autocomplete',
|
|
229
|
+
defaultObjectValue: {
|
|
230
|
+
id: 4,
|
|
231
|
+
name: 'Algeria',
|
|
232
|
+
value: '4',
|
|
233
|
+
label: 'Algeria'
|
|
234
|
+
}
|
|
235
|
+
}];
|
|
236
|
+
var DATA = {};
|
|
237
|
+
var RESULT = (0, _setupFormData.default)(PAGES, COMPONENTS, DATA);
|
|
238
|
+
expect(RESULT.testField).toMatchObject({
|
|
239
|
+
id: 4,
|
|
240
|
+
name: 'Algeria',
|
|
241
|
+
value: '4',
|
|
242
|
+
label: 'Algeria'
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
it('should handle a default value field with defaultObjectValue if dot-separated field identifier exists within the data', function () {
|
|
246
|
+
var PAGES = [];
|
|
247
|
+
var COMPONENTS = [{
|
|
248
|
+
fieldId: 'testField',
|
|
249
|
+
type: 'autocomplete',
|
|
250
|
+
defaultObjectValue: {
|
|
251
|
+
id: 'country.id',
|
|
252
|
+
name: 'country.name',
|
|
253
|
+
value: 'country.value',
|
|
254
|
+
label: 'country.name'
|
|
255
|
+
}
|
|
256
|
+
}];
|
|
257
|
+
var DATA = {
|
|
258
|
+
'country': {
|
|
259
|
+
'id': 4,
|
|
260
|
+
'name': 'Algeria',
|
|
261
|
+
'value': '4'
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
var RESULT = (0, _setupFormData.default)(PAGES, COMPONENTS, DATA);
|
|
265
|
+
expect(RESULT.testField).toMatchObject({
|
|
266
|
+
id: 4,
|
|
267
|
+
name: 'Algeria',
|
|
268
|
+
value: '4',
|
|
269
|
+
label: 'Algeria'
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
it('should ignore the default value field with defaultObjectValue if dot-separated field identifier doesn\'t exists within the data', function () {
|
|
273
|
+
var PAGES = [];
|
|
274
|
+
var COMPONENTS = [{
|
|
275
|
+
fieldId: 'testField',
|
|
276
|
+
type: 'autocomplete',
|
|
277
|
+
defaultObjectValue: {
|
|
278
|
+
id: 'country.id',
|
|
279
|
+
name: 'country.name',
|
|
280
|
+
value: 'country.value',
|
|
281
|
+
label: 'country.name'
|
|
282
|
+
}
|
|
283
|
+
}];
|
|
284
|
+
var DATA = {};
|
|
285
|
+
var RESULT = (0, _setupFormData.default)(PAGES, COMPONENTS, DATA);
|
|
286
|
+
expect(RESULT.testField).toMatchObject({
|
|
287
|
+
id: 'country.id',
|
|
288
|
+
name: 'country.name',
|
|
289
|
+
value: 'country.value',
|
|
290
|
+
label: 'country.name'
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
it('should ignore a default value when a value already exists in data', function () {
|
|
294
|
+
var PAGES = [];
|
|
295
|
+
var COMPONENTS = [{
|
|
296
|
+
fieldId: 'testField',
|
|
297
|
+
type: 'text',
|
|
298
|
+
defaultValue: 'VALUE'
|
|
299
|
+
}];
|
|
300
|
+
var DATA = {
|
|
301
|
+
testField: 'EXISTING_VALUE'
|
|
302
|
+
};
|
|
303
|
+
var RESULT = (0, _setupFormData.default)(PAGES, COMPONENTS, DATA);
|
|
304
|
+
expect(RESULT).toEqual({
|
|
305
|
+
testField: 'EXISTING_VALUE'
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
it('should handle default values within pages', function () {
|
|
309
|
+
var PAGES = [{
|
|
310
|
+
components: [{
|
|
311
|
+
fieldId: 'pageField',
|
|
312
|
+
type: 'text',
|
|
313
|
+
defaultValue: 'VALUE'
|
|
314
|
+
}]
|
|
315
|
+
}];
|
|
316
|
+
var COMPONENTS = [];
|
|
317
|
+
var DATA = {};
|
|
318
|
+
var RESULT = (0, _setupFormData.default)(PAGES, COMPONENTS, DATA);
|
|
319
|
+
expect(RESULT).toEqual({
|
|
320
|
+
pageField: 'VALUE'
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
it('should ignore default values within pages when a value already exists in data', function () {
|
|
324
|
+
var PAGES = [{
|
|
325
|
+
components: [{
|
|
326
|
+
fieldId: 'pageField',
|
|
327
|
+
type: 'text',
|
|
328
|
+
defaultValue: 'VALUE'
|
|
329
|
+
}]
|
|
330
|
+
}];
|
|
331
|
+
var COMPONENTS = [];
|
|
332
|
+
var DATA = {
|
|
333
|
+
pageField: 'EXISTING_VALUE'
|
|
334
|
+
};
|
|
335
|
+
var RESULT = (0, _setupFormData.default)(PAGES, COMPONENTS, DATA);
|
|
336
|
+
expect(RESULT).toEqual({
|
|
337
|
+
pageField: 'EXISTING_VALUE'
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
it('should handle default values of components within containers', function () {
|
|
341
|
+
var PAGES = [{
|
|
342
|
+
components: [{
|
|
343
|
+
fieldId: 'firstContainer',
|
|
344
|
+
type: 'container',
|
|
345
|
+
components: [{
|
|
346
|
+
fieldId: 'firstDate',
|
|
347
|
+
type: 'date',
|
|
348
|
+
defaultValue: '01-01-1999'
|
|
349
|
+
}, {
|
|
350
|
+
fieldId: 'secondContainer',
|
|
351
|
+
type: 'container',
|
|
352
|
+
components: [{
|
|
353
|
+
fieldId: 'secondDate',
|
|
354
|
+
type: 'date',
|
|
355
|
+
defaultValue: '01-01-2000'
|
|
356
|
+
}]
|
|
357
|
+
}]
|
|
358
|
+
}]
|
|
359
|
+
}];
|
|
360
|
+
var RESULT = (0, _setupFormData.default)(PAGES, [], {});
|
|
361
|
+
expect(RESULT).toEqual({
|
|
362
|
+
firstContainer: {
|
|
363
|
+
firstDate: '01-01-1999',
|
|
364
|
+
secondContainer: {
|
|
365
|
+
secondDate: '01-01-2000'
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
it('should ignore default values of components within containers when they already have a value in data', function () {
|
|
371
|
+
var PAGES = [{
|
|
372
|
+
components: [{
|
|
373
|
+
fieldId: 'firstContainer',
|
|
374
|
+
type: 'container',
|
|
375
|
+
components: [{
|
|
376
|
+
fieldId: 'firstDate',
|
|
377
|
+
type: 'date',
|
|
378
|
+
defaultValue: '01-01-1999'
|
|
379
|
+
}, {
|
|
380
|
+
fieldId: 'secondContainer',
|
|
381
|
+
type: 'container',
|
|
382
|
+
components: [{
|
|
383
|
+
fieldId: 'secondDate',
|
|
384
|
+
type: 'date',
|
|
385
|
+
defaultValue: '01-01-2000'
|
|
386
|
+
}]
|
|
387
|
+
}]
|
|
388
|
+
}]
|
|
389
|
+
}];
|
|
390
|
+
var DATA = {
|
|
391
|
+
firstContainer: {
|
|
392
|
+
firstDate: '01-01-1000',
|
|
393
|
+
secondContainer: {
|
|
394
|
+
secondDate: '01-01-1000'
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
var RESULT = (0, _setupFormData.default)(PAGES, [], DATA);
|
|
399
|
+
expect(RESULT).toEqual({
|
|
400
|
+
firstContainer: {
|
|
401
|
+
firstDate: '01-01-1000',
|
|
402
|
+
secondContainer: {
|
|
403
|
+
secondDate: '01-01-1000'
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
});
|
|
408
|
+
});
|
|
409
|
+
});
|
|
410
|
+
});
|
|
@@ -6,9 +6,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
8
8
|
var _models = require("../../models");
|
|
9
|
+
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); }
|
|
9
10
|
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; }
|
|
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
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
13
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
14
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
12
15
|
var setupRefDataForContainer = function setupRefDataForContainer(container, data) {
|
|
13
16
|
return _objectSpread(_objectSpread({}, container), {}, {
|
|
14
17
|
components: setupRefDataUrlForComponents(container.components, data)
|