@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,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _models = require("../../models");
|
|
4
|
+
var _getPageActions = _interopRequireDefault(require("./getPageActions"));
|
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
+
// Local imports
|
|
7
|
+
|
|
8
|
+
describe('utils', function () {
|
|
9
|
+
describe('FormPage', function () {
|
|
10
|
+
describe('getPageActions', function () {
|
|
11
|
+
it('should handle a null or undefined page', function () {
|
|
12
|
+
expect((0, _getPageActions.default)(null)).toBeUndefined();
|
|
13
|
+
expect((0, _getPageActions.default)(undefined)).toBeUndefined();
|
|
14
|
+
});
|
|
15
|
+
it('should handle a null or undefined actions array', function () {
|
|
16
|
+
expect((0, _getPageActions.default)({
|
|
17
|
+
actions: null
|
|
18
|
+
})).toBeUndefined();
|
|
19
|
+
expect((0, _getPageActions.default)({
|
|
20
|
+
actions: undefined
|
|
21
|
+
})).toBeUndefined();
|
|
22
|
+
});
|
|
23
|
+
it('should handle an array of strings', function () {
|
|
24
|
+
var actions = [_models.PageAction.TYPES.SAVE_AND_CONTINUE, _models.PageAction.TYPES.SAVE_AND_RETURN];
|
|
25
|
+
expect((0, _getPageActions.default)({
|
|
26
|
+
actions: actions
|
|
27
|
+
})).toEqual([_models.PageAction.DEFAULTS.saveAndContinue, _models.PageAction.DEFAULTS.saveAndReturn]);
|
|
28
|
+
});
|
|
29
|
+
it('should handle a null entry in the array', function () {
|
|
30
|
+
var actions = [_models.PageAction.TYPES.SAVE_AND_CONTINUE, _models.PageAction.TYPES.SAVE_AND_RETURN, null];
|
|
31
|
+
expect((0, _getPageActions.default)({
|
|
32
|
+
actions: actions
|
|
33
|
+
})).toEqual([_models.PageAction.DEFAULTS.saveAndContinue, _models.PageAction.DEFAULTS.saveAndReturn]);
|
|
34
|
+
});
|
|
35
|
+
it('should handle an undefined entry in the array', function () {
|
|
36
|
+
var actions = [undefined, _models.PageAction.TYPES.SAVE_AND_CONTINUE, undefined, _models.PageAction.TYPES.SAVE_AND_RETURN];
|
|
37
|
+
expect((0, _getPageActions.default)({
|
|
38
|
+
actions: actions
|
|
39
|
+
})).toEqual([_models.PageAction.DEFAULTS.saveAndContinue, _models.PageAction.DEFAULTS.saveAndReturn]);
|
|
40
|
+
});
|
|
41
|
+
it('should handle an object entry in the array', function () {
|
|
42
|
+
var actions = [{
|
|
43
|
+
type: 'navigate',
|
|
44
|
+
page: 'alpha'
|
|
45
|
+
}];
|
|
46
|
+
expect((0, _getPageActions.default)({
|
|
47
|
+
actions: actions
|
|
48
|
+
})).toEqual(actions);
|
|
49
|
+
});
|
|
50
|
+
it('should convert an href to a page', function () {
|
|
51
|
+
var actions = [{
|
|
52
|
+
type: 'navigate',
|
|
53
|
+
href: '/alpha/bravo'
|
|
54
|
+
}];
|
|
55
|
+
expect((0, _getPageActions.default)({
|
|
56
|
+
actions: actions
|
|
57
|
+
})).toEqual([{
|
|
58
|
+
type: 'navigate',
|
|
59
|
+
page: 'bravo',
|
|
60
|
+
href: '/alpha/bravo'
|
|
61
|
+
}]);
|
|
62
|
+
});
|
|
63
|
+
it('should convert a url to a page', function () {
|
|
64
|
+
var actions = [{
|
|
65
|
+
type: 'navigate',
|
|
66
|
+
url: '/alpha/bravo'
|
|
67
|
+
}];
|
|
68
|
+
expect((0, _getPageActions.default)({
|
|
69
|
+
actions: actions
|
|
70
|
+
})).toEqual([{
|
|
71
|
+
type: 'navigate',
|
|
72
|
+
page: 'bravo',
|
|
73
|
+
url: '/alpha/bravo'
|
|
74
|
+
}]);
|
|
75
|
+
});
|
|
76
|
+
it('should handle an action without a page, href, or url', function () {
|
|
77
|
+
var actions = [{
|
|
78
|
+
type: 'submit',
|
|
79
|
+
label: 'Charlie'
|
|
80
|
+
}];
|
|
81
|
+
expect((0, _getPageActions.default)({
|
|
82
|
+
actions: actions
|
|
83
|
+
})).toEqual(actions);
|
|
84
|
+
});
|
|
85
|
+
it('should add a default validation prop if none are present', function () {
|
|
86
|
+
var actions = [{
|
|
87
|
+
type: 'saveAndContinue',
|
|
88
|
+
label: 'Charlie'
|
|
89
|
+
}];
|
|
90
|
+
expect((0, _getPageActions.default)({
|
|
91
|
+
actions: actions
|
|
92
|
+
})).toEqual([{
|
|
93
|
+
type: 'saveAndContinue',
|
|
94
|
+
label: 'Charlie',
|
|
95
|
+
validate: true
|
|
96
|
+
}]);
|
|
97
|
+
});
|
|
98
|
+
it('should not overwrite a validation prop when one exists', function () {
|
|
99
|
+
var actions = [{
|
|
100
|
+
type: 'submit',
|
|
101
|
+
label: 'Charlie',
|
|
102
|
+
validate: false
|
|
103
|
+
}];
|
|
104
|
+
expect((0, _getPageActions.default)({
|
|
105
|
+
actions: actions
|
|
106
|
+
})).toEqual([{
|
|
107
|
+
type: 'submit',
|
|
108
|
+
label: 'Charlie',
|
|
109
|
+
validate: false
|
|
110
|
+
}]);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _models = require("../../models");
|
|
4
|
+
var _getParagraphFromText = _interopRequireDefault(require("./getParagraphFromText"));
|
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
+
// Local imports
|
|
7
|
+
|
|
8
|
+
describe('utils', function () {
|
|
9
|
+
describe('FormPage', function () {
|
|
10
|
+
describe('getParagraphFromText', function () {
|
|
11
|
+
it('should handle text content', function () {
|
|
12
|
+
var CONTENT = 'Appropriate text content';
|
|
13
|
+
expect((0, _getParagraphFromText.default)(CONTENT)).toEqual({
|
|
14
|
+
type: _models.ComponentTypes.HTML,
|
|
15
|
+
tagName: 'p',
|
|
16
|
+
content: CONTENT
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
it('should handle undefined content', function () {
|
|
20
|
+
expect((0, _getParagraphFromText.default)(undefined)).toEqual({
|
|
21
|
+
type: _models.ComponentTypes.HTML,
|
|
22
|
+
tagName: 'p'
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -4,12 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
var _applyConditionalProperties = _interopRequireDefault(require("./applyConditionalProperties"));
|
|
7
8
|
var _getFormPage = _interopRequireDefault(require("./getFormPage"));
|
|
8
9
|
var _getFormPages = _interopRequireDefault(require("./getFormPages"));
|
|
9
10
|
var _showFormPage = _interopRequireDefault(require("./showFormPage"));
|
|
10
11
|
var _showFormPageCYA = _interopRequireDefault(require("./showFormPageCYA"));
|
|
11
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
13
|
var FormPage = {
|
|
14
|
+
applyConditionalProperties: _applyConditionalProperties.default,
|
|
13
15
|
get: _getFormPage.default,
|
|
14
16
|
getAll: _getFormPages.default,
|
|
15
17
|
show: _showFormPage.default,
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var
|
|
7
|
+
var _showComponent = _interopRequireDefault(require("../Component/showComponent"));
|
|
8
8
|
var _Condition = _interopRequireDefault(require("../Condition"));
|
|
9
9
|
var _Container = _interopRequireDefault(require("../Container"));
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -18,7 +18,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
18
18
|
*/
|
|
19
19
|
var showEditableComponent = function showEditableComponent(editableComponents, data) {
|
|
20
20
|
return editableComponents.some(function (component) {
|
|
21
|
-
return
|
|
21
|
+
return (0, _showComponent.default)(component, data);
|
|
22
22
|
});
|
|
23
23
|
};
|
|
24
24
|
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _showFormPage = _interopRequireDefault(require("./showFormPage"));
|
|
4
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
5
|
+
describe('utils', function () {
|
|
6
|
+
describe('FormPage', function () {
|
|
7
|
+
describe('showFormPage', 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 page is null', function () {
|
|
27
|
+
expect((0, _showFormPage.default)(null, DATA)).toBeFalsy();
|
|
28
|
+
});
|
|
29
|
+
it('should NOT be shown when the page has a single show_when condition that is NOT matched', function () {
|
|
30
|
+
var PAGE = {
|
|
31
|
+
show_when: {
|
|
32
|
+
field: 'charlie',
|
|
33
|
+
op: '=',
|
|
34
|
+
value: 'Charlie'
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
expect((0, _showFormPage.default)(PAGE, DATA)).toBeFalsy();
|
|
38
|
+
});
|
|
39
|
+
it('should NOT be shown when the page has a multiple show_when conditions and at least one is NOT matched', function () {
|
|
40
|
+
var PAGE = {
|
|
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, _showFormPage.default)(PAGE, DATA)).toBeFalsy();
|
|
52
|
+
});
|
|
53
|
+
it('SHOULD be shown when the page has a single show_when condition that IS matched', function () {
|
|
54
|
+
var PAGE = {
|
|
55
|
+
show_when: {
|
|
56
|
+
field: 'alpha',
|
|
57
|
+
op: '=',
|
|
58
|
+
value: 'Alpha'
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
expect((0, _showFormPage.default)(PAGE, DATA)).toBeTruthy();
|
|
62
|
+
});
|
|
63
|
+
it('SHOULD be shown when the page has a multiple show_when conditions that are ALL matched', function () {
|
|
64
|
+
var PAGE = {
|
|
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, _showFormPage.default)(PAGE, DATA)).toBeTruthy();
|
|
76
|
+
});
|
|
77
|
+
it('SHOULD be shown when the page has NO show_when conditions and NO editable components', function () {
|
|
78
|
+
var PAGE = {
|
|
79
|
+
components: [HTML, INSET_TEXT, HEADING]
|
|
80
|
+
};
|
|
81
|
+
expect((0, _showFormPage.default)(PAGE, DATA)).toBeTruthy();
|
|
82
|
+
});
|
|
83
|
+
it('should NOT be shown when the page 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 PAGE = {
|
|
101
|
+
components: [TEXT, RADIOS]
|
|
102
|
+
};
|
|
103
|
+
expect((0, _showFormPage.default)(PAGE, DATA)).toBeFalsy();
|
|
104
|
+
});
|
|
105
|
+
it('SHOULD be shown when the page 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 PAGE = {
|
|
123
|
+
components: [TEXT, RADIOS]
|
|
124
|
+
};
|
|
125
|
+
expect((0, _showFormPage.default)(PAGE, DATA)).toBeTruthy();
|
|
126
|
+
});
|
|
127
|
+
it('SHOULD be shown when the page has multiple show_when conditions, with type "or" provided and ALL are matched', function () {
|
|
128
|
+
var PAGE = {
|
|
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, _showFormPage.default)(PAGE, DATA)).toBeTruthy();
|
|
143
|
+
});
|
|
144
|
+
it('SHOULD be shown when the page has multiple show_when conditions, with type "or" provided and at least ONE is matched', function () {
|
|
145
|
+
var PAGE = {
|
|
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, _showFormPage.default)(PAGE, DATA)).toBeTruthy();
|
|
160
|
+
});
|
|
161
|
+
it('should NOT be shown when the page has multiple show_when conditions, with type "or" provided and NONE are matched', function () {
|
|
162
|
+
var PAGE = {
|
|
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, _showFormPage.default)(PAGE, DATA)).toBeFalsy();
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
});
|
|
@@ -13,6 +13,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
13
13
|
* @returns Boolean true if the page should be shown; false if not.
|
|
14
14
|
*/
|
|
15
15
|
var showFormPageCYA = function showFormPageCYA(page, data) {
|
|
16
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
16
17
|
if (page !== null && page !== void 0 && page.hasOwnProperty('show_on_cya') && !page.show_on_cya) {
|
|
17
18
|
return false;
|
|
18
19
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _showFormPageCYA = _interopRequireDefault(require("./showFormPageCYA"));
|
|
4
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
5
|
+
describe('utils.FormPage.showFormPageCYA', function () {
|
|
6
|
+
var DATA = {
|
|
7
|
+
alpha: 'Alpha',
|
|
8
|
+
bravo: 'Bravo'
|
|
9
|
+
};
|
|
10
|
+
it('should NOT be shown when the page is null', function () {
|
|
11
|
+
expect((0, _showFormPageCYA.default)(null, DATA)).toEqual(false);
|
|
12
|
+
});
|
|
13
|
+
it('should NOT be shown if the show_on_cya flag is false', function () {
|
|
14
|
+
var PAGE = {
|
|
15
|
+
show_on_cya: false
|
|
16
|
+
};
|
|
17
|
+
expect((0, _showFormPageCYA.default)(PAGE, DATA)).toEqual(false);
|
|
18
|
+
});
|
|
19
|
+
it('SHOULD be shown if the show_on_cya flag is true', function () {
|
|
20
|
+
var PAGE = {
|
|
21
|
+
show_on_cya: true
|
|
22
|
+
};
|
|
23
|
+
expect((0, _showFormPageCYA.default)(PAGE, DATA)).toEqual(true);
|
|
24
|
+
});
|
|
25
|
+
it('SHOULD be shown if the show_on_cya flag is missing', function () {
|
|
26
|
+
expect((0, _showFormPageCYA.default)({}, DATA)).toEqual(true);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -4,42 +4,61 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
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); }
|
|
7
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; }
|
|
8
9
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
9
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
10
|
+
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); }
|
|
10
13
|
var getComponentToUse = function getComponentToUse(toUse, formComponents) {
|
|
11
14
|
var path = toUse.use.split('.');
|
|
12
15
|
var firstId = path.shift();
|
|
13
|
-
var wrapper = _objectSpread({}, formComponents.find(function (fc) {
|
|
16
|
+
var wrapper = JSON.parse(JSON.stringify(_objectSpread({}, formComponents.find(function (fc) {
|
|
14
17
|
return fc.id === firstId;
|
|
15
|
-
}));
|
|
18
|
+
}))));
|
|
19
|
+
var component = wrapper;
|
|
16
20
|
var parent = wrapper;
|
|
17
21
|
var _loop = function _loop() {
|
|
18
22
|
var id = path.shift();
|
|
19
|
-
if (Array.isArray(
|
|
23
|
+
if (Array.isArray(component.components)) {
|
|
20
24
|
// Filter the parent components down to just the one referenced
|
|
21
25
|
// by the current id.
|
|
26
|
+
parent = component;
|
|
22
27
|
parent.components = parent.components.filter(function (c) {
|
|
23
28
|
return c.id === id;
|
|
24
29
|
});
|
|
25
30
|
if (parent.components.length > 0) {
|
|
26
31
|
// Make the found child the parent so we can iterate.
|
|
27
|
-
|
|
32
|
+
// eslint-disable-next-line prefer-destructuring
|
|
33
|
+
component = parent.components[0];
|
|
28
34
|
} else {
|
|
29
35
|
// If no child was found, there can be no parent.
|
|
30
|
-
|
|
36
|
+
component = undefined;
|
|
31
37
|
}
|
|
32
38
|
} else {
|
|
33
39
|
// We cannot find the child with this id if there are no child
|
|
34
40
|
// components on this parent.
|
|
35
|
-
|
|
41
|
+
component = undefined;
|
|
36
42
|
}
|
|
37
43
|
};
|
|
38
|
-
while (
|
|
44
|
+
while (component && path.length > 0) {
|
|
39
45
|
_loop();
|
|
40
46
|
}
|
|
47
|
+
if (component) {
|
|
48
|
+
component = _objectSpread(_objectSpread(_objectSpread({}, component), toUse), {}, {
|
|
49
|
+
cya_label: component.label || component.cya_label,
|
|
50
|
+
fieldId: toUse.fieldId || component.fieldId
|
|
51
|
+
});
|
|
52
|
+
if (parent && parent.id !== component.id) {
|
|
53
|
+
parent.components[0] = component;
|
|
54
|
+
} else {
|
|
55
|
+
wrapper = component;
|
|
56
|
+
}
|
|
57
|
+
return wrapper;
|
|
58
|
+
}
|
|
59
|
+
|
|
41
60
|
// If we missed a nested reference along the way, don't return the wrapper.
|
|
42
|
-
return
|
|
61
|
+
return undefined;
|
|
43
62
|
};
|
|
44
63
|
|
|
45
64
|
/**
|
|
@@ -53,11 +72,7 @@ var useComponent = function useComponent(toUse, formComponents) {
|
|
|
53
72
|
if (toUse) {
|
|
54
73
|
var component = getComponentToUse(toUse, formComponents);
|
|
55
74
|
if (component) {
|
|
56
|
-
|
|
57
|
-
return _objectSpread(_objectSpread(_objectSpread({}, component), toUse), {}, {
|
|
58
|
-
cya_label: component.label || component.cya_label,
|
|
59
|
-
fieldId: fieldId
|
|
60
|
-
});
|
|
75
|
+
return component;
|
|
61
76
|
}
|
|
62
77
|
}
|
|
63
78
|
return _objectSpread({}, toUse);
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _models = require("../../models");
|
|
4
|
+
var _useComponent = _interopRequireDefault(require("./useComponent"));
|
|
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', function () {
|
|
13
|
+
describe('FormPage', function () {
|
|
14
|
+
describe('useComponent', function () {
|
|
15
|
+
var ZULU = {
|
|
16
|
+
id: 'z',
|
|
17
|
+
fieldId: 'z',
|
|
18
|
+
label: 'Zulu',
|
|
19
|
+
type: _models.ComponentTypes.TEXT
|
|
20
|
+
};
|
|
21
|
+
var CONTAINER = {
|
|
22
|
+
id: 'container',
|
|
23
|
+
fieldId: 'container',
|
|
24
|
+
label: 'Container',
|
|
25
|
+
type: _models.ComponentTypes.CONTAINER,
|
|
26
|
+
components: [{
|
|
27
|
+
id: 'f',
|
|
28
|
+
fieldId: 'f',
|
|
29
|
+
label: 'Foxtrot',
|
|
30
|
+
type: _models.ComponentTypes.TEXT
|
|
31
|
+
}, ZULU]
|
|
32
|
+
};
|
|
33
|
+
var FORM_COMPONENTS = [{
|
|
34
|
+
id: 'a',
|
|
35
|
+
fieldId: 'a',
|
|
36
|
+
label: 'Alpha',
|
|
37
|
+
type: _models.ComponentTypes.TEXT
|
|
38
|
+
}, {
|
|
39
|
+
id: 'b',
|
|
40
|
+
fieldId: 'b',
|
|
41
|
+
label: 'Bravo',
|
|
42
|
+
type: _models.ComponentTypes.TEXT
|
|
43
|
+
}, {
|
|
44
|
+
id: 'c',
|
|
45
|
+
fieldId: 'c',
|
|
46
|
+
label: 'Charlie',
|
|
47
|
+
type: _models.ComponentTypes.TEXT
|
|
48
|
+
}, {
|
|
49
|
+
id: 'd',
|
|
50
|
+
fieldId: 'd',
|
|
51
|
+
cya_label: 'Delta',
|
|
52
|
+
type: _models.ComponentTypes.TEXT
|
|
53
|
+
}, CONTAINER];
|
|
54
|
+
it('should handle a null toUse configuration', function () {
|
|
55
|
+
var TO_USE = null;
|
|
56
|
+
expect((0, _useComponent.default)(TO_USE, FORM_COMPONENTS)).toEqual({});
|
|
57
|
+
});
|
|
58
|
+
it('should handle an unrecognised component reference', function () {
|
|
59
|
+
var TO_USE = {
|
|
60
|
+
use: 'e',
|
|
61
|
+
label: 'Echo'
|
|
62
|
+
};
|
|
63
|
+
expect((0, _useComponent.default)(TO_USE, FORM_COMPONENTS)).toEqual(TO_USE);
|
|
64
|
+
});
|
|
65
|
+
it('should use the appropriate component', function () {
|
|
66
|
+
var TO_USE = {
|
|
67
|
+
use: 'a'
|
|
68
|
+
};
|
|
69
|
+
var A = FORM_COMPONENTS[0];
|
|
70
|
+
expect((0, _useComponent.default)(TO_USE, FORM_COMPONENTS)).toEqual(_objectSpread(_objectSpread({
|
|
71
|
+
use: 'a'
|
|
72
|
+
}, A), {}, {
|
|
73
|
+
cya_label: A.label
|
|
74
|
+
}));
|
|
75
|
+
});
|
|
76
|
+
it('should allow the fieldId to be overridden', function () {
|
|
77
|
+
var TO_USE = {
|
|
78
|
+
use: 'a',
|
|
79
|
+
fieldId: 'alpha'
|
|
80
|
+
};
|
|
81
|
+
var A = FORM_COMPONENTS[0];
|
|
82
|
+
expect((0, _useComponent.default)(TO_USE, FORM_COMPONENTS)).toEqual(_objectSpread(_objectSpread({
|
|
83
|
+
use: 'a'
|
|
84
|
+
}, A), {}, {
|
|
85
|
+
cya_label: A.label,
|
|
86
|
+
fieldId: TO_USE.fieldId
|
|
87
|
+
}));
|
|
88
|
+
});
|
|
89
|
+
it('should allow the label to be overridden but keep the cya_label unaffected', function () {
|
|
90
|
+
var TO_USE = {
|
|
91
|
+
use: 'a',
|
|
92
|
+
label: 'Alpha foxtrot'
|
|
93
|
+
};
|
|
94
|
+
var A = FORM_COMPONENTS[0];
|
|
95
|
+
expect((0, _useComponent.default)(TO_USE, FORM_COMPONENTS)).toEqual(_objectSpread(_objectSpread({
|
|
96
|
+
use: 'a'
|
|
97
|
+
}, A), {}, {
|
|
98
|
+
cya_label: A.label,
|
|
99
|
+
label: TO_USE.label
|
|
100
|
+
}));
|
|
101
|
+
});
|
|
102
|
+
it('should allow the form component cya_label, if label is empty', function () {
|
|
103
|
+
var TO_USE = {
|
|
104
|
+
use: 'd',
|
|
105
|
+
label: ''
|
|
106
|
+
};
|
|
107
|
+
var A = FORM_COMPONENTS[3];
|
|
108
|
+
expect((0, _useComponent.default)(TO_USE, FORM_COMPONENTS)).toEqual(_objectSpread(_objectSpread({
|
|
109
|
+
use: 'd'
|
|
110
|
+
}, A), {}, {
|
|
111
|
+
cya_label: A.cya_label,
|
|
112
|
+
label: TO_USE.label
|
|
113
|
+
}));
|
|
114
|
+
});
|
|
115
|
+
it('should allow the form component cya_label, if label is not given', function () {
|
|
116
|
+
var TO_USE = {
|
|
117
|
+
use: 'd'
|
|
118
|
+
};
|
|
119
|
+
var A = FORM_COMPONENTS[3];
|
|
120
|
+
expect((0, _useComponent.default)(TO_USE, FORM_COMPONENTS)).toEqual(_objectSpread(_objectSpread({
|
|
121
|
+
use: 'd'
|
|
122
|
+
}, A), {}, {
|
|
123
|
+
cya_label: A.cya_label,
|
|
124
|
+
label: TO_USE.label
|
|
125
|
+
}));
|
|
126
|
+
});
|
|
127
|
+
it('should handle a container', function () {
|
|
128
|
+
var TO_USE = {
|
|
129
|
+
use: CONTAINER.id
|
|
130
|
+
};
|
|
131
|
+
expect((0, _useComponent.default)(TO_USE, FORM_COMPONENTS)).toEqual(_objectSpread(_objectSpread({
|
|
132
|
+
use: CONTAINER.id
|
|
133
|
+
}, CONTAINER), {}, {
|
|
134
|
+
cya_label: CONTAINER.label
|
|
135
|
+
}));
|
|
136
|
+
});
|
|
137
|
+
it('should handle a component nested inside a container', function () {
|
|
138
|
+
var ID = "".concat(CONTAINER.id, ".").concat(ZULU.id);
|
|
139
|
+
var TO_USE = {
|
|
140
|
+
use: ID
|
|
141
|
+
};
|
|
142
|
+
expect((0, _useComponent.default)(TO_USE, FORM_COMPONENTS)).toEqual(_objectSpread(_objectSpread({}, CONTAINER), {}, {
|
|
143
|
+
components: [_objectSpread(_objectSpread({
|
|
144
|
+
use: ID
|
|
145
|
+
}, ZULU), {}, {
|
|
146
|
+
cya_label: ZULU.label
|
|
147
|
+
}) // Foxtrot is not included
|
|
148
|
+
]
|
|
149
|
+
}));
|
|
150
|
+
});
|
|
151
|
+
it('should handle an unrecognised container reference', function () {
|
|
152
|
+
var ID = "unrecognised.".concat(ZULU.id);
|
|
153
|
+
var TO_USE = {
|
|
154
|
+
use: ID
|
|
155
|
+
};
|
|
156
|
+
expect((0, _useComponent.default)(TO_USE, FORM_COMPONENTS)).toEqual(TO_USE);
|
|
157
|
+
});
|
|
158
|
+
it('should handle an unrecognised component within a container', function () {
|
|
159
|
+
var ID = "".concat(CONTAINER.id, ".unrecognised");
|
|
160
|
+
var TO_USE = {
|
|
161
|
+
use: ID
|
|
162
|
+
};
|
|
163
|
+
expect((0, _useComponent.default)(TO_USE, FORM_COMPONENTS)).toEqual(TO_USE);
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
});
|