@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
|
@@ -23,7 +23,7 @@ var meetsOneCondition = function meetsOneCondition(options, data) {
|
|
|
23
23
|
var arr = Array.isArray(conditions) ? conditions : [conditions];
|
|
24
24
|
return arr.some(function (condition) {
|
|
25
25
|
var sourceDataValue = _Data.default.getSource(data, condition.field);
|
|
26
|
-
return (0, _meetsCondition.default)(condition, sourceDataValue);
|
|
26
|
+
return (0, _meetsCondition.default)(condition, sourceDataValue, data);
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
29
|
return true;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _meetsOneCondition = _interopRequireDefault(require("./meetsOneCondition"));
|
|
4
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
5
|
+
// Local imports
|
|
6
|
+
|
|
7
|
+
describe('utils.Condition.meetsOneCondition', function () {
|
|
8
|
+
var DATA = {
|
|
9
|
+
alpha: 'bravo',
|
|
10
|
+
charlie: 'delta'
|
|
11
|
+
};
|
|
12
|
+
it('should evaluate to true when conditions are null', function () {
|
|
13
|
+
expect((0, _meetsOneCondition.default)(null, DATA)).toBeTruthy();
|
|
14
|
+
});
|
|
15
|
+
it('should evaluate to true when conditions are undefined', function () {
|
|
16
|
+
expect((0, _meetsOneCondition.default)(undefined, DATA)).toBeTruthy();
|
|
17
|
+
});
|
|
18
|
+
it('should evaluate to true when conditions is an empty array', function () {
|
|
19
|
+
var CONDITION = {
|
|
20
|
+
"type": "or",
|
|
21
|
+
"conditions": []
|
|
22
|
+
};
|
|
23
|
+
expect((0, _meetsOneCondition.default)(CONDITION, DATA)).toBeTruthy();
|
|
24
|
+
});
|
|
25
|
+
it('should evaluate to true when one condition is provided and one condition is met', function () {
|
|
26
|
+
var CONDITION = {
|
|
27
|
+
"type": "or",
|
|
28
|
+
"conditions": [{
|
|
29
|
+
field: 'alpha',
|
|
30
|
+
op: 'eq',
|
|
31
|
+
value: 'bravo'
|
|
32
|
+
}]
|
|
33
|
+
};
|
|
34
|
+
expect((0, _meetsOneCondition.default)(CONDITION, DATA)).toBeTruthy();
|
|
35
|
+
});
|
|
36
|
+
it('should evaluate to true when two conditions are provided and one condition is met', function () {
|
|
37
|
+
var CONDITION = {
|
|
38
|
+
"type": "or",
|
|
39
|
+
"conditions": [{
|
|
40
|
+
field: 'alpha',
|
|
41
|
+
op: 'eq',
|
|
42
|
+
value: 'bravo'
|
|
43
|
+
}, {
|
|
44
|
+
field: 'alpha',
|
|
45
|
+
op: 'eq',
|
|
46
|
+
value: "charlie"
|
|
47
|
+
}]
|
|
48
|
+
};
|
|
49
|
+
expect((0, _meetsOneCondition.default)(CONDITION, DATA)).toBeTruthy();
|
|
50
|
+
});
|
|
51
|
+
it('should evaluate to true when three conditions are provided and two conditions are met', function () {
|
|
52
|
+
var CONDITION = {
|
|
53
|
+
"type": "or",
|
|
54
|
+
"conditions": [{
|
|
55
|
+
field: 'alpha',
|
|
56
|
+
op: 'eq',
|
|
57
|
+
value: 'bravo'
|
|
58
|
+
}, {
|
|
59
|
+
field: 'charlie',
|
|
60
|
+
op: 'eq',
|
|
61
|
+
value: 'delta'
|
|
62
|
+
}, {
|
|
63
|
+
field: 'alpha',
|
|
64
|
+
op: 'eq',
|
|
65
|
+
value: "charlie"
|
|
66
|
+
}]
|
|
67
|
+
};
|
|
68
|
+
expect((0, _meetsOneCondition.default)(CONDITION, DATA)).toBeTruthy();
|
|
69
|
+
});
|
|
70
|
+
it('should evaluate to true when all conditions are met', function () {
|
|
71
|
+
var CONDITION = {
|
|
72
|
+
"type": "or",
|
|
73
|
+
"conditions": [{
|
|
74
|
+
field: 'alpha',
|
|
75
|
+
op: 'eq',
|
|
76
|
+
value: 'bravo'
|
|
77
|
+
}, {
|
|
78
|
+
field: 'charlie',
|
|
79
|
+
op: 'eq',
|
|
80
|
+
value: 'delta'
|
|
81
|
+
}]
|
|
82
|
+
};
|
|
83
|
+
expect((0, _meetsOneCondition.default)(CONDITION, DATA)).toBeTruthy();
|
|
84
|
+
});
|
|
85
|
+
it('should evaluate to false when no conditions are met', function () {
|
|
86
|
+
var CONDITION = {
|
|
87
|
+
"type": "or",
|
|
88
|
+
"conditions": [{
|
|
89
|
+
field: 'alpha',
|
|
90
|
+
op: 'eq',
|
|
91
|
+
value: 'delta'
|
|
92
|
+
}, {
|
|
93
|
+
field: 'charlie',
|
|
94
|
+
op: 'eq',
|
|
95
|
+
value: 'bravo'
|
|
96
|
+
}]
|
|
97
|
+
};
|
|
98
|
+
expect((0, _meetsOneCondition.default)(CONDITION, DATA)).toBeTruthy();
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -6,16 +6,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _Data = _interopRequireDefault(require("../Data"));
|
|
8
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
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 makeComponentFieldsAbsolute = function makeComponentFieldsAbsolute(component) {
|
|
13
16
|
if (component.show_when) {
|
|
14
17
|
var conditions = component.show_when.type ? component.show_when.conditions : component.show_when;
|
|
15
|
-
var
|
|
18
|
+
var fullPath = component.full_path;
|
|
16
19
|
conditions = Array.isArray(conditions) ? conditions : [conditions];
|
|
17
20
|
return conditions.map(function (condition) {
|
|
18
|
-
var field = _Data.default.getDataPath(condition.field,
|
|
21
|
+
var field = _Data.default.getDataPath(condition.field, fullPath);
|
|
19
22
|
return _objectSpread(_objectSpread({}, condition), {}, {
|
|
20
23
|
field: field
|
|
21
24
|
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _setupConditions = _interopRequireDefault(require("./setupConditions"));
|
|
4
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
5
|
+
describe('utils.Condition.setupConditions', function () {
|
|
6
|
+
it('should return an array of conditions directly', function () {
|
|
7
|
+
var OPTIONS = [{
|
|
8
|
+
field: 'alpha',
|
|
9
|
+
op: '=',
|
|
10
|
+
value: 'ALPHA'
|
|
11
|
+
}];
|
|
12
|
+
expect((0, _setupConditions.default)(OPTIONS)).toEqual(OPTIONS);
|
|
13
|
+
});
|
|
14
|
+
it('should return a condition directly', function () {
|
|
15
|
+
var OPTIONS = {
|
|
16
|
+
field: 'alpha',
|
|
17
|
+
op: '=',
|
|
18
|
+
value: 'ALPHA'
|
|
19
|
+
};
|
|
20
|
+
expect((0, _setupConditions.default)(OPTIONS)).toEqual(OPTIONS);
|
|
21
|
+
});
|
|
22
|
+
it('should return the options on a component with untouched absolute path fields', function () {
|
|
23
|
+
var OPTIONS = {
|
|
24
|
+
id: 'field',
|
|
25
|
+
show_when: {
|
|
26
|
+
field: 'alpha',
|
|
27
|
+
op: '=',
|
|
28
|
+
value: 'ALPHA'
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
expect((0, _setupConditions.default)(OPTIONS)).toEqual([OPTIONS.show_when]);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _models = require("../../models");
|
|
4
|
+
var _isEditable = require("../Component/isEditable");
|
|
5
|
+
var _getEditableComponents = _interopRequireDefault(require("./getEditableComponents"));
|
|
6
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
7
|
+
// Local imports
|
|
8
|
+
|
|
9
|
+
describe('utils.Container.getEditableComponents', function () {
|
|
10
|
+
var HTML = {
|
|
11
|
+
type: 'html',
|
|
12
|
+
tagName: 'p',
|
|
13
|
+
content: 'Alpha'
|
|
14
|
+
};
|
|
15
|
+
var INSET_TEXT = {
|
|
16
|
+
type: 'inset-text',
|
|
17
|
+
content: 'Bravo'
|
|
18
|
+
};
|
|
19
|
+
var HEADING = {
|
|
20
|
+
type: 'heading',
|
|
21
|
+
size: 'm',
|
|
22
|
+
content: 'Charlie'
|
|
23
|
+
};
|
|
24
|
+
it('should return an empty array for a null container', function () {
|
|
25
|
+
expect((0, _getEditableComponents.default)(null)).toEqual([]);
|
|
26
|
+
});
|
|
27
|
+
it('should return an empty array for a container with no components', function () {
|
|
28
|
+
expect((0, _getEditableComponents.default)({
|
|
29
|
+
components: []
|
|
30
|
+
})).toEqual([]);
|
|
31
|
+
});
|
|
32
|
+
it('should return an empty array for a container with only non-editable components', function () {
|
|
33
|
+
var COMPONENTS = [HTML, INSET_TEXT, HEADING];
|
|
34
|
+
expect((0, _getEditableComponents.default)({
|
|
35
|
+
components: COMPONENTS
|
|
36
|
+
})).toEqual([]);
|
|
37
|
+
});
|
|
38
|
+
it('should return an empty array for a container that contains a container with only non-editable components', function () {
|
|
39
|
+
var COMPONENTS = [HTML, INSET_TEXT, HEADING];
|
|
40
|
+
var INNER_CONTAINER = {
|
|
41
|
+
type: _models.ComponentTypes.CONTAINER,
|
|
42
|
+
components: COMPONENTS
|
|
43
|
+
};
|
|
44
|
+
expect((0, _getEditableComponents.default)({
|
|
45
|
+
components: [INNER_CONTAINER]
|
|
46
|
+
})).toEqual([]);
|
|
47
|
+
});
|
|
48
|
+
_isEditable.EDITABLE_TYPES.forEach(function (type) {
|
|
49
|
+
it("should return just the \"".concat(type, "\" component if it exists in the components, but no non-editable ones"), function () {
|
|
50
|
+
var EDITABLE = {
|
|
51
|
+
type: type
|
|
52
|
+
};
|
|
53
|
+
var COMPONENTS = [HTML, EDITABLE, INSET_TEXT, HEADING];
|
|
54
|
+
expect((0, _getEditableComponents.default)({
|
|
55
|
+
components: COMPONENTS
|
|
56
|
+
})).toEqual([EDITABLE]);
|
|
57
|
+
});
|
|
58
|
+
it("should return just the \"".concat(type, "\" component if it exists inside an inner container's components, but no non-editable ones"), function () {
|
|
59
|
+
var EDITABLE = {
|
|
60
|
+
type: type
|
|
61
|
+
};
|
|
62
|
+
var COMPONENTS = [HTML, EDITABLE, INSET_TEXT, HEADING];
|
|
63
|
+
var INNER_CONTAINER = {
|
|
64
|
+
type: _models.ComponentTypes.CONTAINER,
|
|
65
|
+
components: COMPONENTS
|
|
66
|
+
};
|
|
67
|
+
expect((0, _getEditableComponents.default)({
|
|
68
|
+
components: [INNER_CONTAINER]
|
|
69
|
+
})).toEqual([EDITABLE]);
|
|
70
|
+
});
|
|
71
|
+
it("should return just all \"".concat(type, "\" components that exists at any nested level within the container, but no non-editable ones"), function () {
|
|
72
|
+
var EDITABLE = {
|
|
73
|
+
type: type
|
|
74
|
+
};
|
|
75
|
+
var COMPONENTS = [HTML, EDITABLE, INSET_TEXT, HEADING];
|
|
76
|
+
var INNER_INNER_CONTAINER = {
|
|
77
|
+
type: _models.ComponentTypes.CONTAINER,
|
|
78
|
+
components: COMPONENTS
|
|
79
|
+
};
|
|
80
|
+
var INNER_CONTAINER = {
|
|
81
|
+
type: _models.ComponentTypes.CONTAINER,
|
|
82
|
+
components: [].concat(COMPONENTS, [INNER_INNER_CONTAINER])
|
|
83
|
+
};
|
|
84
|
+
expect((0, _getEditableComponents.default)({
|
|
85
|
+
components: [EDITABLE, INNER_CONTAINER]
|
|
86
|
+
})).toEqual([EDITABLE, EDITABLE, EDITABLE]);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
it('should return all editable components and no non-editable ones', function () {
|
|
90
|
+
var COMPONENTS = [HTML, INSET_TEXT, HEADING];
|
|
91
|
+
_isEditable.EDITABLE_TYPES.forEach(function (type) {
|
|
92
|
+
COMPONENTS.push({
|
|
93
|
+
type: type
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
var RESULT = (0, _getEditableComponents.default)({
|
|
97
|
+
components: COMPONENTS
|
|
98
|
+
});
|
|
99
|
+
expect(RESULT.length).toEqual(_isEditable.EDITABLE_TYPES.length);
|
|
100
|
+
_isEditable.EDITABLE_TYPES.forEach(function (type) {
|
|
101
|
+
expect(RESULT).toContainEqual({
|
|
102
|
+
type: type
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
it('should return all editable components and no non-editable ones, regardless of nesting level', function () {
|
|
107
|
+
var EDITABLE_COMPONENTS = _isEditable.EDITABLE_TYPES.map(function (type) {
|
|
108
|
+
return {
|
|
109
|
+
type: type
|
|
110
|
+
};
|
|
111
|
+
});
|
|
112
|
+
var NON_EDITABLE_COMPONENTS = [HTML, INSET_TEXT, HEADING];
|
|
113
|
+
var COMPONENTS = [].concat(EDITABLE_COMPONENTS, NON_EDITABLE_COMPONENTS, [{
|
|
114
|
+
type: _models.ComponentTypes.CONTAINER,
|
|
115
|
+
id: 'inner',
|
|
116
|
+
components: [].concat(EDITABLE_COMPONENTS, NON_EDITABLE_COMPONENTS, [{
|
|
117
|
+
type: _models.ComponentTypes.CONTAINER,
|
|
118
|
+
id: 'inner-inner',
|
|
119
|
+
components: [].concat(NON_EDITABLE_COMPONENTS, EDITABLE_COMPONENTS)
|
|
120
|
+
}])
|
|
121
|
+
}]);
|
|
122
|
+
var RESULT = (0, _getEditableComponents.default)({
|
|
123
|
+
components: COMPONENTS
|
|
124
|
+
});
|
|
125
|
+
expect(RESULT.length).toEqual(_isEditable.EDITABLE_TYPES.length * 3); // 1 each at top, inner, and inner-inner levels.
|
|
126
|
+
_isEditable.EDITABLE_TYPES.forEach(function (type) {
|
|
127
|
+
expect(RESULT).toContainEqual({
|
|
128
|
+
type: type
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
expect(RESULT).not.toContainEqual(HTML);
|
|
132
|
+
expect(RESULT).not.toContainEqual(INSET_TEXT);
|
|
133
|
+
expect(RESULT).not.toContainEqual(HEADING);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
@@ -5,18 +5,37 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _models = require("../../models");
|
|
8
|
+
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
9
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
9
10
|
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) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11
|
+
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; }
|
|
12
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
13
|
+
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); }
|
|
11
14
|
var nestComponents = function nestComponents(container) {
|
|
12
15
|
var containerPath = container.full_path || container.fieldId;
|
|
13
16
|
return container.components.map(function (component) {
|
|
17
|
+
// eslint-disable-next-line camelcase
|
|
14
18
|
var full_path = containerPath ? "".concat(containerPath, ".").concat(component.fieldId) : component.fieldId;
|
|
15
19
|
var ret = _objectSpread(_objectSpread({}, component), {}, {
|
|
16
20
|
full_path: full_path
|
|
17
21
|
});
|
|
18
22
|
if (component.type === _models.ComponentTypes.CONTAINER) {
|
|
19
|
-
return
|
|
23
|
+
return (
|
|
24
|
+
// eslint-disable-next-line no-use-before-define
|
|
25
|
+
setupNesting(ret)
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
if (component.type === _models.ComponentTypes.RADIOS) {
|
|
29
|
+
var _ret$data, _ret$data$options;
|
|
30
|
+
(_ret$data = ret.data) === null || _ret$data === void 0 ? void 0 : (_ret$data$options = _ret$data.options) === null || _ret$data$options === void 0 ? void 0 : _ret$data$options.forEach(function (option, optionIndex) {
|
|
31
|
+
var _option$nested;
|
|
32
|
+
(_option$nested = option.nested) === null || _option$nested === void 0 ? void 0 : _option$nested.forEach(function (nest, nestIndex) {
|
|
33
|
+
if (nest.type === _models.ComponentTypes.CONTAINER) {
|
|
34
|
+
// eslint-disable-next-line no-use-before-define
|
|
35
|
+
ret.data.options[optionIndex].nested[nestIndex] = setupNesting(nest);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
20
39
|
}
|
|
21
40
|
return ret;
|
|
22
41
|
});
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _models = require("../../models");
|
|
4
|
+
var _setupNesting = _interopRequireDefault(require("./setupNesting"));
|
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
+
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); }
|
|
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
|
+
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; }
|
|
9
|
+
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; }
|
|
10
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
11
|
+
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
|
+
describe('utils.Container.setupNesting', function () {
|
|
13
|
+
var getComponent = function getComponent(id, type) {
|
|
14
|
+
return {
|
|
15
|
+
id: id,
|
|
16
|
+
fieldId: id,
|
|
17
|
+
type: type
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
it('should handle an undefined container', function () {
|
|
21
|
+
expect((0, _setupNesting.default)(undefined)).toBeUndefined();
|
|
22
|
+
});
|
|
23
|
+
it('should handle a null container', function () {
|
|
24
|
+
expect((0, _setupNesting.default)(null)).toBeNull();
|
|
25
|
+
});
|
|
26
|
+
it('should handle a single level of nesting', function () {
|
|
27
|
+
var CONTAINER = _objectSpread(_objectSpread({}, getComponent('container', _models.ComponentTypes.CONTAINER)), {}, {
|
|
28
|
+
components: [getComponent('text', _models.ComponentTypes.TEXT), getComponent('email', _models.ComponentTypes.EMAIL)]
|
|
29
|
+
});
|
|
30
|
+
expect((0, _setupNesting.default)(CONTAINER)).toEqual({
|
|
31
|
+
id: 'container',
|
|
32
|
+
fieldId: 'container',
|
|
33
|
+
type: _models.ComponentTypes.CONTAINER,
|
|
34
|
+
components: [{
|
|
35
|
+
id: 'text',
|
|
36
|
+
fieldId: 'text',
|
|
37
|
+
full_path: 'container.text',
|
|
38
|
+
type: _models.ComponentTypes.TEXT
|
|
39
|
+
}, {
|
|
40
|
+
id: 'email',
|
|
41
|
+
fieldId: 'email',
|
|
42
|
+
full_path: 'container.email',
|
|
43
|
+
type: _models.ComponentTypes.EMAIL
|
|
44
|
+
}]
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
it('should handle multiple levels of nesting', function () {
|
|
48
|
+
var CONTAINER = _objectSpread(_objectSpread({}, getComponent('container', _models.ComponentTypes.CONTAINER)), {}, {
|
|
49
|
+
components: [getComponent('text', _models.ComponentTypes.TEXT), _objectSpread(_objectSpread({}, getComponent('inner', _models.ComponentTypes.CONTAINER)), {}, {
|
|
50
|
+
components: [getComponent('text', _models.ComponentTypes.TEXT), getComponent('email', _models.ComponentTypes.EMAIL)]
|
|
51
|
+
}), getComponent('email', _models.ComponentTypes.EMAIL)]
|
|
52
|
+
});
|
|
53
|
+
expect((0, _setupNesting.default)(CONTAINER)).toEqual({
|
|
54
|
+
id: 'container',
|
|
55
|
+
fieldId: 'container',
|
|
56
|
+
type: _models.ComponentTypes.CONTAINER,
|
|
57
|
+
components: [{
|
|
58
|
+
id: 'text',
|
|
59
|
+
fieldId: 'text',
|
|
60
|
+
full_path: 'container.text',
|
|
61
|
+
type: _models.ComponentTypes.TEXT
|
|
62
|
+
}, {
|
|
63
|
+
id: 'inner',
|
|
64
|
+
fieldId: 'inner',
|
|
65
|
+
full_path: 'container.inner',
|
|
66
|
+
type: _models.ComponentTypes.CONTAINER,
|
|
67
|
+
components: [{
|
|
68
|
+
id: 'text',
|
|
69
|
+
fieldId: 'text',
|
|
70
|
+
full_path: 'container.inner.text',
|
|
71
|
+
type: _models.ComponentTypes.TEXT
|
|
72
|
+
}, {
|
|
73
|
+
id: 'email',
|
|
74
|
+
fieldId: 'email',
|
|
75
|
+
full_path: 'container.inner.email',
|
|
76
|
+
type: _models.ComponentTypes.EMAIL
|
|
77
|
+
}]
|
|
78
|
+
}, {
|
|
79
|
+
id: 'email',
|
|
80
|
+
fieldId: 'email',
|
|
81
|
+
full_path: 'container.email',
|
|
82
|
+
type: _models.ComponentTypes.EMAIL
|
|
83
|
+
}]
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
it('should handle a container under a radio button', function () {
|
|
87
|
+
var CONTAINER = _objectSpread(_objectSpread({}, getComponent('container', _models.ComponentTypes.CONTAINER)), {}, {
|
|
88
|
+
components: [getComponent('text', _models.ComponentTypes.TEXT), getComponent('email', _models.ComponentTypes.EMAIL)]
|
|
89
|
+
});
|
|
90
|
+
var RADIO = {
|
|
91
|
+
id: 'radio',
|
|
92
|
+
fieldId: 'radio',
|
|
93
|
+
type: 'radios',
|
|
94
|
+
data: {
|
|
95
|
+
options: [{
|
|
96
|
+
value: 'yes',
|
|
97
|
+
label: 'Yes'
|
|
98
|
+
}, {
|
|
99
|
+
value: 'no',
|
|
100
|
+
label: 'No',
|
|
101
|
+
nested: [CONTAINER]
|
|
102
|
+
}]
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
var TOP_CONTAINER = _objectSpread(_objectSpread({}, getComponent('topContainer', _models.ComponentTypes.CONTAINER)), {}, {
|
|
106
|
+
components: [RADIO]
|
|
107
|
+
});
|
|
108
|
+
expect((0, _setupNesting.default)(TOP_CONTAINER)).toEqual({
|
|
109
|
+
id: 'topContainer',
|
|
110
|
+
fieldId: 'topContainer',
|
|
111
|
+
type: _models.ComponentTypes.CONTAINER,
|
|
112
|
+
components: [{
|
|
113
|
+
id: 'radio',
|
|
114
|
+
fieldId: 'radio',
|
|
115
|
+
type: 'radios',
|
|
116
|
+
full_path: 'topContainer.radio',
|
|
117
|
+
data: {
|
|
118
|
+
options: [{
|
|
119
|
+
value: 'yes',
|
|
120
|
+
label: 'Yes'
|
|
121
|
+
}, {
|
|
122
|
+
value: 'no',
|
|
123
|
+
label: 'No',
|
|
124
|
+
nested: [{
|
|
125
|
+
id: 'container',
|
|
126
|
+
fieldId: 'container',
|
|
127
|
+
type: 'container',
|
|
128
|
+
components: [{
|
|
129
|
+
id: 'text',
|
|
130
|
+
fieldId: 'text',
|
|
131
|
+
full_path: 'container.text',
|
|
132
|
+
type: _models.ComponentTypes.TEXT
|
|
133
|
+
}, {
|
|
134
|
+
id: 'email',
|
|
135
|
+
fieldId: 'email',
|
|
136
|
+
full_path: 'container.email',
|
|
137
|
+
type: _models.ComponentTypes.EMAIL
|
|
138
|
+
}]
|
|
139
|
+
}]
|
|
140
|
+
}]
|
|
141
|
+
}
|
|
142
|
+
}]
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
});
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _showContainer = _interopRequireDefault(require("./showContainer"));
|
|
4
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
5
|
+
// Local imports
|
|
6
|
+
|
|
7
|
+
describe('utils.Container.showContainer', function () {
|
|
8
|
+
var DATA = {
|
|
9
|
+
alpha: 'Alpha',
|
|
10
|
+
bravo: 'Bravo'
|
|
11
|
+
};
|
|
12
|
+
var HTML = {
|
|
13
|
+
type: 'html',
|
|
14
|
+
tagName: 'p',
|
|
15
|
+
content: 'Alpha'
|
|
16
|
+
};
|
|
17
|
+
var INSET_TEXT = {
|
|
18
|
+
type: 'inset-text',
|
|
19
|
+
content: 'Bravo'
|
|
20
|
+
};
|
|
21
|
+
var HEADING = {
|
|
22
|
+
type: 'heading',
|
|
23
|
+
size: 'm',
|
|
24
|
+
content: 'Charlie'
|
|
25
|
+
};
|
|
26
|
+
it('should NOT be shown when the container is null', function () {
|
|
27
|
+
expect((0, _showContainer.default)(null, DATA)).toBeFalsy();
|
|
28
|
+
});
|
|
29
|
+
it('should NOT be shown when the container has a single show_when condition that is NOT matched', function () {
|
|
30
|
+
var CONTAINER = {
|
|
31
|
+
show_when: {
|
|
32
|
+
field: 'charlie',
|
|
33
|
+
op: '=',
|
|
34
|
+
value: 'Charlie'
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
expect((0, _showContainer.default)(CONTAINER, DATA)).toBeFalsy();
|
|
38
|
+
});
|
|
39
|
+
it('should NOT be shown when the container has multiple show_when conditions and at least one is NOT matched', function () {
|
|
40
|
+
var CONTAINER = {
|
|
41
|
+
show_when: [{
|
|
42
|
+
field: 'alpha',
|
|
43
|
+
op: '=',
|
|
44
|
+
value: 'Alpha'
|
|
45
|
+
}, {
|
|
46
|
+
field: 'charlie',
|
|
47
|
+
op: '=',
|
|
48
|
+
value: 'Charlie'
|
|
49
|
+
}]
|
|
50
|
+
};
|
|
51
|
+
expect((0, _showContainer.default)(CONTAINER, DATA)).toBeFalsy();
|
|
52
|
+
});
|
|
53
|
+
it('SHOULD be shown when the container has a single show_when condition that IS matched', function () {
|
|
54
|
+
var CONTAINER = {
|
|
55
|
+
show_when: {
|
|
56
|
+
field: 'alpha',
|
|
57
|
+
op: '=',
|
|
58
|
+
value: 'Alpha'
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
expect((0, _showContainer.default)(CONTAINER, DATA)).toBeTruthy();
|
|
62
|
+
});
|
|
63
|
+
it('SHOULD be shown when the container has multiple show_when conditions that are ALL matched', function () {
|
|
64
|
+
var CONTAINER = {
|
|
65
|
+
show_when: [{
|
|
66
|
+
field: 'alpha',
|
|
67
|
+
op: '=',
|
|
68
|
+
value: 'Alpha'
|
|
69
|
+
}, {
|
|
70
|
+
field: 'charlie',
|
|
71
|
+
op: '!=',
|
|
72
|
+
value: 'Charlie'
|
|
73
|
+
}]
|
|
74
|
+
};
|
|
75
|
+
expect((0, _showContainer.default)(CONTAINER, DATA)).toBeTruthy();
|
|
76
|
+
});
|
|
77
|
+
it('SHOULD be shown when the container has NO show_when conditions and NO editable components', function () {
|
|
78
|
+
var CONTAINER = {
|
|
79
|
+
components: [HTML, INSET_TEXT, HEADING]
|
|
80
|
+
};
|
|
81
|
+
expect((0, _showContainer.default)(CONTAINER, DATA)).toBeTruthy();
|
|
82
|
+
});
|
|
83
|
+
it('should NOT be shown when the container has NO show_when conditions and NO SHOWN editable components', function () {
|
|
84
|
+
var TEXT = {
|
|
85
|
+
type: 'text',
|
|
86
|
+
show_when: {
|
|
87
|
+
field: 'charlie',
|
|
88
|
+
op: '=',
|
|
89
|
+
value: 'Charlie'
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
var RADIOS = {
|
|
93
|
+
type: 'radios',
|
|
94
|
+
show_when: {
|
|
95
|
+
field: 'charlie',
|
|
96
|
+
op: '=',
|
|
97
|
+
value: 'Charlie'
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
var CONTAINER = {
|
|
101
|
+
components: [TEXT, RADIOS]
|
|
102
|
+
};
|
|
103
|
+
expect((0, _showContainer.default)(CONTAINER, DATA)).toBeFalsy();
|
|
104
|
+
});
|
|
105
|
+
it('SHOULD be shown when the container has NO show_when conditions and AT LEAST ONE SHOWN editable components', function () {
|
|
106
|
+
var TEXT = {
|
|
107
|
+
type: 'text',
|
|
108
|
+
show_when: {
|
|
109
|
+
field: 'alpha',
|
|
110
|
+
op: '=',
|
|
111
|
+
value: 'Alpha'
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
var RADIOS = {
|
|
115
|
+
type: 'radios',
|
|
116
|
+
show_when: {
|
|
117
|
+
field: 'charlie',
|
|
118
|
+
op: '=',
|
|
119
|
+
value: 'Charlie'
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
var CONTAINER = {
|
|
123
|
+
components: [TEXT, RADIOS]
|
|
124
|
+
};
|
|
125
|
+
expect((0, _showContainer.default)(CONTAINER, DATA)).toBeTruthy();
|
|
126
|
+
});
|
|
127
|
+
it('SHOULD be shown when the container has multiple show_when conditions, with type "or" provided and ALL are matched', function () {
|
|
128
|
+
var CONTAINER = {
|
|
129
|
+
show_when: {
|
|
130
|
+
"type": "or",
|
|
131
|
+
"conditions": [{
|
|
132
|
+
field: 'alpha',
|
|
133
|
+
op: '=',
|
|
134
|
+
value: 'Alpha'
|
|
135
|
+
}, {
|
|
136
|
+
field: 'bravo',
|
|
137
|
+
op: '=',
|
|
138
|
+
value: 'Bravo'
|
|
139
|
+
}]
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
expect((0, _showContainer.default)(CONTAINER, DATA)).toBeTruthy();
|
|
143
|
+
});
|
|
144
|
+
it('SHOULD be shown when the container has multiple show_when conditions, with type "or" provided and at least ONE is matched', function () {
|
|
145
|
+
var CONTAINER = {
|
|
146
|
+
show_when: {
|
|
147
|
+
"type": "or",
|
|
148
|
+
"conditions": [{
|
|
149
|
+
field: 'alpha',
|
|
150
|
+
op: '=',
|
|
151
|
+
value: 'Alpha'
|
|
152
|
+
}, {
|
|
153
|
+
field: 'charlie',
|
|
154
|
+
op: '=',
|
|
155
|
+
value: 'Charlie'
|
|
156
|
+
}]
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
expect((0, _showContainer.default)(CONTAINER, DATA)).toBeTruthy();
|
|
160
|
+
});
|
|
161
|
+
it('should NOT be shown when the container has multiple show_when conditions, with type "or" provided and NONE are matched', function () {
|
|
162
|
+
var CONTAINER = {
|
|
163
|
+
show_when: {
|
|
164
|
+
"type": "or",
|
|
165
|
+
"conditions": [{
|
|
166
|
+
field: 'alpha',
|
|
167
|
+
op: '!=',
|
|
168
|
+
value: 'Alpha'
|
|
169
|
+
}, {
|
|
170
|
+
field: 'charlie',
|
|
171
|
+
op: '=',
|
|
172
|
+
value: 'Charlie'
|
|
173
|
+
}]
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
expect((0, _showContainer.default)(CONTAINER, DATA)).toBeFalsy();
|
|
177
|
+
});
|
|
178
|
+
});
|