@ukhomeoffice/cop-react-form-renderer 4.17.0 → 5.0.0-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/CheckYourAnswers/Answer.js +1 -14
- package/dist/components/CheckYourAnswers/CheckYourAnswers.js +19 -57
- package/dist/components/CheckYourAnswers/index.js +0 -3
- package/dist/components/CollectionPage/CollectionPage.js +8 -38
- package/dist/components/CollectionPage/index.js +0 -3
- package/dist/components/FormComponent/Collection.js +13 -54
- package/dist/components/FormComponent/Container.js +6 -30
- package/dist/components/FormComponent/FormComponent.js +14 -57
- package/dist/components/FormComponent/helpers/addLabel.js +4 -7
- package/dist/components/FormComponent/helpers/getComponentDisabled.js +0 -4
- package/dist/components/FormComponent/helpers/getComponentDisabled.test.js +0 -2
- package/dist/components/FormComponent/helpers/getComponentError.js +0 -6
- package/dist/components/FormComponent/helpers/getComponentError.test.js +0 -2
- package/dist/components/FormComponent/helpers/index.js +0 -4
- package/dist/components/FormComponent/index.js +0 -3
- package/dist/components/FormPage/FormPage.js +14 -45
- package/dist/components/FormPage/index.js +0 -3
- package/dist/components/FormRenderer/FormRenderer.js +106 -189
- package/dist/components/FormRenderer/handlers/cyaAction.js +0 -5
- package/dist/components/FormRenderer/handlers/getPageId.js +0 -2
- package/dist/components/FormRenderer/handlers/getPageId.test.js +1 -2
- package/dist/components/FormRenderer/handlers/handlers.test.js +1 -18
- package/dist/components/FormRenderer/handlers/index.js +0 -5
- package/dist/components/FormRenderer/handlers/navigate.js +0 -5
- package/dist/components/FormRenderer/handlers/submissionError.js +0 -2
- package/dist/components/FormRenderer/helpers/canActionProceed.js +0 -3
- package/dist/components/FormRenderer/helpers/canActionProceed.test.js +1 -3
- package/dist/components/FormRenderer/helpers/canCYASubmit.js +0 -2
- package/dist/components/FormRenderer/helpers/canCYASubmit.test.js +1 -5
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.js +0 -5
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.test.js +1 -2
- package/dist/components/FormRenderer/helpers/getCYA.js +0 -6
- package/dist/components/FormRenderer/helpers/getCYA.test.js +1 -3
- package/dist/components/FormRenderer/helpers/getFormState.js +0 -5
- package/dist/components/FormRenderer/helpers/getFormState.test.js +1 -3
- package/dist/components/FormRenderer/helpers/getNextPageId.js +0 -25
- package/dist/components/FormRenderer/helpers/getNextPageId.test.js +1 -4
- package/dist/components/FormRenderer/helpers/getPage.js +0 -5
- package/dist/components/FormRenderer/helpers/getPage.test.js +1 -3
- package/dist/components/FormRenderer/helpers/getRelevantPages.js +0 -6
- package/dist/components/FormRenderer/helpers/getRelevantPages.test.js +1 -3
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +0 -10
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +0 -6
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.js +6 -20
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.test.js +3 -8
- package/dist/components/FormRenderer/helpers/index.js +1 -11
- package/dist/components/FormRenderer/index.js +0 -3
- package/dist/components/PageActions/ActionButton.js +2 -17
- package/dist/components/PageActions/PageActions.js +3 -10
- package/dist/components/PageActions/index.js +0 -3
- package/dist/components/SummaryList/GroupAction.js +3 -24
- package/dist/components/SummaryList/RowAction.js +3 -23
- package/dist/components/SummaryList/SummaryList.js +6 -28
- package/dist/components/SummaryList/SummaryListRow.js +4 -8
- package/dist/components/SummaryList/SummaryListTitleRow.js +2 -7
- package/dist/components/SummaryList/helpers/getGroupActionAttributes.js +0 -3
- package/dist/components/SummaryList/helpers/getGroupActionAttributes.test.js +0 -6
- package/dist/components/SummaryList/helpers/getRowActionAttributes.js +0 -3
- package/dist/components/SummaryList/helpers/getRowActionAttributes.test.js +0 -6
- package/dist/components/SummaryList/helpers/index.js +0 -2
- package/dist/components/SummaryList/index.js +0 -3
- package/dist/components/TaskList/Task.js +7 -29
- package/dist/components/TaskList/TaskList.js +12 -33
- package/dist/components/TaskList/TaskState.js +2 -10
- package/dist/components/TaskList/index.js +0 -3
- package/dist/components/index.js +0 -6
- package/dist/context/HooksContext/HooksContext.js +14 -34
- package/dist/context/HooksContext/index.js +0 -5
- package/dist/context/ValidationContext/ValidationContext.js +8 -34
- package/dist/context/ValidationContext/index.js +0 -5
- package/dist/context/index.js +0 -3
- package/dist/hooks/index.js +0 -9
- package/dist/hooks/useAxios.js +8 -25
- package/dist/hooks/useGetRequest.js +13 -47
- package/dist/hooks/useHooks.js +2 -4
- package/dist/hooks/useRefData.js +8 -37
- package/dist/hooks/useValidation.js +2 -4
- package/dist/index.js +0 -6
- package/dist/models/PageAction.js +0 -3
- package/dist/models/TaskStates.js +0 -3
- package/dist/models/index.js +0 -9
- package/dist/utils/CheckYourAnswers/getCYAAction.js +1 -9
- package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.js +0 -10
- package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.js +0 -8
- package/dist/utils/CheckYourAnswers/getCYARow.js +1 -10
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.js +2 -20
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.js +0 -18
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +0 -20
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.js +0 -13
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +2 -22
- package/dist/utils/CheckYourAnswers/index.js +1 -3
- package/dist/utils/CheckYourAnswers/showComponentCYA.js +2 -11
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.js +0 -11
- package/dist/utils/CollectionPage/getCollectionPageActiveIndex.js +0 -6
- package/dist/utils/CollectionPage/index.js +1 -5
- package/dist/utils/CollectionPage/mergeCollectionPages.js +1 -12
- package/dist/utils/Component/cleanAttributes.js +1 -8
- package/dist/utils/Component/elevateNestedComponents.js +0 -3
- package/dist/utils/Component/getComponent.js +4 -68
- package/dist/utils/Component/getComponentTests/getComponent.autocomplete.test.js +6 -10
- package/dist/utils/Component/getComponentTests/getComponent.calculation.test.js +10 -28
- package/dist/utils/Component/getComponentTests/getComponent.checkboxes.test.js +6 -33
- package/dist/utils/Component/getComponentTests/getComponent.date.test.js +10 -27
- package/dist/utils/Component/getComponentTests/getComponent.details.test.js +4 -10
- package/dist/utils/Component/getComponentTests/getComponent.email.test.js +4 -21
- package/dist/utils/Component/getComponentTests/getComponent.file.test.js +4 -22
- package/dist/utils/Component/getComponentTests/getComponent.heading.test.js +3 -7
- package/dist/utils/Component/getComponentTests/getComponent.html.test.js +4 -10
- package/dist/utils/Component/getComponentTests/getComponent.insetText.test.js +3 -7
- package/dist/utils/Component/getComponentTests/getComponent.nested.test.js +6 -15
- package/dist/utils/Component/getComponentTests/getComponent.phoneNumber.test.js +4 -21
- package/dist/utils/Component/getComponentTests/getComponent.radios.test.js +6 -33
- package/dist/utils/Component/getComponentTests/getComponent.select.test.js +4 -21
- package/dist/utils/Component/getComponentTests/getComponent.text.test.js +4 -21
- package/dist/utils/Component/getComponentTests/getComponent.textarea.test.js +4 -21
- package/dist/utils/Component/getComponentTests/getComponent.time.test.js +10 -29
- package/dist/utils/Component/getComponentTests/getComponent.unknown.test.js +1 -2
- package/dist/utils/Component/getComponentTests/getComponent.warningText.test.js +3 -7
- package/dist/utils/Component/getDefaultValue.js +0 -7
- package/dist/utils/Component/index.js +0 -9
- package/dist/utils/Component/isEditable.js +1 -4
- package/dist/utils/Component/showComponent.js +1 -8
- package/dist/utils/Component/wrapInFormGroup.js +0 -7
- package/dist/utils/Condition/index.js +0 -5
- package/dist/utils/Condition/meetsAllConditions.js +0 -9
- package/dist/utils/Condition/meetsCondition.js +7 -19
- package/dist/utils/Condition/meetsOneCondition.js +1 -9
- package/dist/utils/Condition/setupConditions.js +0 -12
- package/dist/utils/Container/getEditableComponents.js +0 -7
- package/dist/utils/Container/index.js +0 -5
- package/dist/utils/Container/setupNesting.js +0 -11
- package/dist/utils/Container/showContainer.js +9 -18
- package/dist/utils/Data/applyFormula.js +2 -28
- package/dist/utils/Data/getAutocompleteSource.js +1 -4
- package/dist/utils/Data/getDataPath.js +3 -17
- package/dist/utils/Data/getOptions.js +0 -9
- package/dist/utils/Data/getSourceData.js +4 -19
- package/dist/utils/Data/index.js +1 -11
- package/dist/utils/Data/refDataToOptions.js +1 -12
- package/dist/utils/Data/setDataItem.js +0 -5
- package/dist/utils/Data/setupFormData.js +2 -20
- package/dist/utils/Data/setupRefDataUrlForComponent.js +0 -14
- package/dist/utils/FormPage/getFormPage.js +0 -15
- package/dist/utils/FormPage/getFormPages.js +0 -8
- package/dist/utils/FormPage/getPageActions.js +3 -18
- package/dist/utils/FormPage/getParagraphFromText.js +0 -3
- package/dist/utils/FormPage/index.js +0 -6
- package/dist/utils/FormPage/showFormPage.js +9 -18
- package/dist/utils/FormPage/showFormPageCYA.js +0 -5
- package/dist/utils/FormPage/useComponent.js +3 -18
- package/dist/utils/Format/formatData.js +0 -5
- package/dist/utils/Format/formatDataForComponent.js +1 -6
- package/dist/utils/Format/formatDataForForm.js +0 -8
- package/dist/utils/Format/formatDataForPage.js +1 -5
- package/dist/utils/Format/index.js +1 -6
- package/dist/utils/Hub/getFormHub.js +0 -8
- package/dist/utils/Hub/index.js +1 -3
- package/dist/utils/Meta/documents/getDocuments.js +1 -4
- package/dist/utils/Meta/documents/getDocuments.test.js +0 -9
- package/dist/utils/Meta/documents/index.js +1 -5
- package/dist/utils/Meta/documents/setDocumentForField.js +0 -11
- package/dist/utils/Meta/documents/setDocumentForField.test.js +0 -11
- package/dist/utils/Meta/index.js +2 -6
- package/dist/utils/Operate/checkValueIsTruthy.js +1 -7
- package/dist/utils/Operate/getIndexOfMatchingValueIn.js +7 -21
- package/dist/utils/Operate/index.js +0 -3
- package/dist/utils/Operate/persistValueInFormData.js +1 -8
- package/dist/utils/Operate/runPageOperations.js +3 -18
- package/dist/utils/Operate/setValueInFormData.js +2 -7
- package/dist/utils/Operate/shouldRun.js +1 -14
- package/dist/utils/Validate/additional/index.js +1 -18
- package/dist/utils/Validate/additional/index.test.js +0 -6
- package/dist/utils/Validate/additional/mustBeAfter.js +3 -8
- package/dist/utils/Validate/additional/mustBeAfter.test.js +0 -4
- package/dist/utils/Validate/additional/mustBeBefore.js +3 -8
- package/dist/utils/Validate/additional/mustBeBefore.test.js +0 -4
- package/dist/utils/Validate/additional/mustBeEarlierDateTime.js +5 -16
- package/dist/utils/Validate/additional/mustBeEarlierDateTime.test.js +0 -7
- package/dist/utils/Validate/additional/mustBeInTheFuture.js +3 -12
- package/dist/utils/Validate/additional/mustBeInTheFuture.test.js +0 -3
- package/dist/utils/Validate/additional/mustBeInThePast.js +5 -13
- package/dist/utils/Validate/additional/mustBeInThePast.test.js +0 -3
- package/dist/utils/Validate/additional/mustBeLessThan.js +0 -3
- package/dist/utils/Validate/additional/mustBeLessThan.test.js +0 -2
- package/dist/utils/Validate/additional/mustBeLongerThan.js +0 -3
- package/dist/utils/Validate/additional/mustBeLongerThan.test.js +0 -2
- package/dist/utils/Validate/additional/mustBeNumbersOnly.js +0 -4
- package/dist/utils/Validate/additional/mustBeNumbersOnly.test.js +0 -2
- package/dist/utils/Validate/additional/mustBeShorterThan.js +0 -3
- package/dist/utils/Validate/additional/mustBeShorterThan.test.js +0 -2
- package/dist/utils/Validate/additional/mustEnterAtLeastOne.js +0 -5
- package/dist/utils/Validate/additional/mustEnterAtLeastOne.test.js +0 -4
- package/dist/utils/Validate/additional/utils.js +8 -24
- package/dist/utils/Validate/index.js +1 -9
- package/dist/utils/Validate/validateCollection.js +0 -9
- package/dist/utils/Validate/validateComponent.js +2 -35
- package/dist/utils/Validate/validateContainer.js +0 -13
- package/dist/utils/Validate/validateDate.js +4 -36
- package/dist/utils/Validate/validateEmail.js +1 -7
- package/dist/utils/Validate/validatePage.js +0 -15
- package/dist/utils/Validate/validateRegex.js +0 -10
- package/dist/utils/Validate/validateRequired.js +0 -8
- package/dist/utils/Validate/validateTime.js +3 -20
- package/dist/utils/index.js +0 -19
- package/package.json +50 -34
- package/dist/components/CheckYourAnswers/Answer.test.js +0 -95
- package/dist/components/CheckYourAnswers/CheckYourAnswers.stories.mdx +0 -410
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +0 -680
- package/dist/components/CollectionPage/CollectionPage.test.js +0 -428
- package/dist/components/FormComponent/Collection.test.js +0 -381
- package/dist/components/FormComponent/Container.test.js +0 -423
- package/dist/components/FormComponent/FormComponent.stories.mdx +0 -184
- package/dist/components/FormComponent/FormComponent.test.js +0 -264
- package/dist/components/FormPage/FormPage.stories.mdx +0 -131
- package/dist/components/FormPage/FormPage.test.js +0 -368
- package/dist/components/FormRenderer/FormRenderer.stories.mdx +0 -183
- package/dist/components/FormRenderer/FormRenderer.test.js +0 -1006
- package/dist/components/PageActions/ActionButton.test.js +0 -116
- package/dist/components/PageActions/PageActions.stories.mdx +0 -74
- package/dist/components/PageActions/PageActions.test.js +0 -157
- package/dist/components/SummaryList/GroupAction.test.js +0 -94
- package/dist/components/SummaryList/RowAction.test.js +0 -94
- package/dist/components/SummaryList/SummaryList.stories.mdx +0 -90
- package/dist/components/SummaryList/SummaryList.test.js +0 -361
- package/dist/components/TaskList/Task.test.js +0 -194
- package/dist/components/TaskList/TaskList.stories.mdx +0 -164
- package/dist/components/TaskList/TaskList.test.js +0 -334
- package/dist/components/TaskList/TaskState.test.js +0 -104
- package/dist/context/HooksContext/HooksContext.test.js +0 -60
- package/dist/context/ValidationContext/ValidationContext.test.js +0 -98
- package/dist/json/areYouACivilServant.json +0 -7
- package/dist/json/firstForm.json +0 -94
- package/dist/json/grade.json +0 -108
- package/dist/json/group.data.json +0 -21
- package/dist/json/group.json +0 -402
- package/dist/json/groupOfRow.json +0 -137
- package/dist/json/groupOfRowData.json +0 -15
- package/dist/json/port.json +0 -346
- package/dist/json/saveAndContinue.json +0 -98
- package/dist/json/sublocation.json +0 -859
- package/dist/json/taskList.json +0 -265
- package/dist/json/team.json +0 -17351
- package/dist/json/terminal.json +0 -81
- package/dist/json/userProfile.data.json +0 -21
- package/dist/json/userProfile.json +0 -276
- package/dist/setupTests.js +0 -59
- package/dist/utils/CheckYourAnswers/getCYAAction.test.js +0 -139
- package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.test.js +0 -76
- package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.test.js +0 -59
- package/dist/utils/CheckYourAnswers/getCYARow.test.js +0 -256
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.test.js +0 -77
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.test.js +0 -199
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +0 -170
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.test.js +0 -323
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.test.js +0 -281
- package/dist/utils/CheckYourAnswers/showComponentCYA.test.js +0 -64
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.test.js +0 -41
- package/dist/utils/CollectionPage/getCollectionPageActiveIndex.test.js +0 -54
- package/dist/utils/CollectionPage/mergeCollectionPages.test.js +0 -131
- package/dist/utils/Component/cleanAttributes.test.js +0 -69
- package/dist/utils/Component/elevateNestedComponents.test.js +0 -92
- package/dist/utils/Component/getDefaultValue.test.js +0 -53
- package/dist/utils/Component/isEditable.test.js +0 -42
- package/dist/utils/Component/showComponent.test.js +0 -157
- package/dist/utils/Condition/meetsAllConditions.test.js +0 -62
- package/dist/utils/Condition/meetsCondition.test.js +0 -391
- package/dist/utils/Condition/meetsOneCondition.test.js +0 -101
- package/dist/utils/Condition/setupConditions.test.js +0 -35
- package/dist/utils/Container/getEditableComponents.test.js +0 -146
- package/dist/utils/Container/setupNesting.test.js +0 -92
- package/dist/utils/Container/showContainer.test.js +0 -179
- package/dist/utils/Data/applyFormula.test.js +0 -264
- package/dist/utils/Data/getAutocompleteSource.test.js +0 -146
- package/dist/utils/Data/getDataPath.test.js +0 -52
- package/dist/utils/Data/getOptions.test.js +0 -71
- package/dist/utils/Data/getSourceData.test.js +0 -141
- package/dist/utils/Data/refDataToOptions.test.js +0 -197
- package/dist/utils/Data/setDataItem.test.js +0 -112
- package/dist/utils/Data/setupFormData.test.js +0 -276
- package/dist/utils/Data/setupRefDataUrlForComponent.test.js +0 -133
- package/dist/utils/FormPage/getFormPage.test.js +0 -205
- package/dist/utils/FormPage/getFormPages.test.js +0 -98
- package/dist/utils/FormPage/getPageActions.test.js +0 -89
- package/dist/utils/FormPage/getParagraphFromText.test.js +0 -29
- package/dist/utils/FormPage/showFormPage.test.js +0 -182
- package/dist/utils/FormPage/showFormPageCYA.test.js +0 -30
- package/dist/utils/FormPage/useComponent.test.js +0 -169
- package/dist/utils/Format/formatData.test.js +0 -46
- package/dist/utils/Format/formatDataForComponent.test.js +0 -161
- package/dist/utils/Format/formatDataForForm.test.js +0 -78
- package/dist/utils/Format/formatDataForPage.test.js +0 -96
- package/dist/utils/Hub/getFormHub.test.js +0 -107
- package/dist/utils/Operate/checkValueIsTruthy.test.js +0 -44
- package/dist/utils/Operate/getIndexOfMatchingValueIn.test.js +0 -159
- package/dist/utils/Operate/persistValueInFormData.test.js +0 -106
- package/dist/utils/Operate/runPageOperations.test.js +0 -107
- package/dist/utils/Operate/setValueInFormData.test.js +0 -46
- package/dist/utils/Operate/shouldRun.test.js +0 -69
- package/dist/utils/Validate/validateCollection.test.js +0 -74
- package/dist/utils/Validate/validateComponent.test.js +0 -267
- package/dist/utils/Validate/validateContainer.test.js +0 -81
- package/dist/utils/Validate/validateDate.test.js +0 -118
- package/dist/utils/Validate/validateEmail.test.js +0 -57
- package/dist/utils/Validate/validatePage.test.js +0 -383
- package/dist/utils/Validate/validateRegex.test.js +0 -41
- package/dist/utils/Validate/validateRequired.test.js +0 -62
- package/dist/utils/Validate/validateTime.test.js +0 -61
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _models = require("../../models");
|
|
4
|
-
|
|
5
|
-
var _setupNesting = _interopRequireDefault(require("./setupNesting"));
|
|
6
|
-
|
|
7
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
|
-
|
|
9
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
10
|
-
|
|
11
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
12
|
-
|
|
13
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
14
|
-
|
|
15
|
-
describe('utils.Container.setupNesting', function () {
|
|
16
|
-
var getComponent = function getComponent(id, type) {
|
|
17
|
-
return {
|
|
18
|
-
id: id,
|
|
19
|
-
fieldId: id,
|
|
20
|
-
type: type
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
it('should handle an undefined container', function () {
|
|
25
|
-
expect((0, _setupNesting.default)(undefined)).toBeUndefined();
|
|
26
|
-
});
|
|
27
|
-
it('should handle a null container', function () {
|
|
28
|
-
expect((0, _setupNesting.default)(null)).toBeNull();
|
|
29
|
-
});
|
|
30
|
-
it('should handle a single level of nesting', function () {
|
|
31
|
-
var CONTAINER = _objectSpread(_objectSpread({}, getComponent('container', _models.ComponentTypes.CONTAINER)), {}, {
|
|
32
|
-
components: [getComponent('text', _models.ComponentTypes.TEXT), getComponent('email', _models.ComponentTypes.EMAIL)]
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
expect((0, _setupNesting.default)(CONTAINER)).toEqual({
|
|
36
|
-
id: 'container',
|
|
37
|
-
fieldId: 'container',
|
|
38
|
-
type: _models.ComponentTypes.CONTAINER,
|
|
39
|
-
components: [{
|
|
40
|
-
id: 'text',
|
|
41
|
-
fieldId: 'text',
|
|
42
|
-
full_path: 'container.text',
|
|
43
|
-
type: _models.ComponentTypes.TEXT
|
|
44
|
-
}, {
|
|
45
|
-
id: 'email',
|
|
46
|
-
fieldId: 'email',
|
|
47
|
-
full_path: 'container.email',
|
|
48
|
-
type: _models.ComponentTypes.EMAIL
|
|
49
|
-
}]
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
it('should handle multiple levels of nesting', function () {
|
|
53
|
-
var CONTAINER = _objectSpread(_objectSpread({}, getComponent('container', _models.ComponentTypes.CONTAINER)), {}, {
|
|
54
|
-
components: [getComponent('text', _models.ComponentTypes.TEXT), _objectSpread(_objectSpread({}, getComponent('inner', _models.ComponentTypes.CONTAINER)), {}, {
|
|
55
|
-
components: [getComponent('text', _models.ComponentTypes.TEXT), getComponent('email', _models.ComponentTypes.EMAIL)]
|
|
56
|
-
}), getComponent('email', _models.ComponentTypes.EMAIL)]
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
expect((0, _setupNesting.default)(CONTAINER)).toEqual({
|
|
60
|
-
id: 'container',
|
|
61
|
-
fieldId: 'container',
|
|
62
|
-
type: _models.ComponentTypes.CONTAINER,
|
|
63
|
-
components: [{
|
|
64
|
-
id: 'text',
|
|
65
|
-
fieldId: 'text',
|
|
66
|
-
full_path: 'container.text',
|
|
67
|
-
type: _models.ComponentTypes.TEXT
|
|
68
|
-
}, {
|
|
69
|
-
id: 'inner',
|
|
70
|
-
fieldId: 'inner',
|
|
71
|
-
full_path: 'container.inner',
|
|
72
|
-
type: _models.ComponentTypes.CONTAINER,
|
|
73
|
-
components: [{
|
|
74
|
-
id: 'text',
|
|
75
|
-
fieldId: 'text',
|
|
76
|
-
full_path: 'container.inner.text',
|
|
77
|
-
type: _models.ComponentTypes.TEXT
|
|
78
|
-
}, {
|
|
79
|
-
id: 'email',
|
|
80
|
-
fieldId: 'email',
|
|
81
|
-
full_path: 'container.inner.email',
|
|
82
|
-
type: _models.ComponentTypes.EMAIL
|
|
83
|
-
}]
|
|
84
|
-
}, {
|
|
85
|
-
id: 'email',
|
|
86
|
-
fieldId: 'email',
|
|
87
|
-
full_path: 'container.email',
|
|
88
|
-
type: _models.ComponentTypes.EMAIL
|
|
89
|
-
}]
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
});
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _showContainer = _interopRequireDefault(require("./showContainer"));
|
|
4
|
-
|
|
5
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
-
|
|
7
|
-
// Local imports
|
|
8
|
-
describe('utils.Container.showContainer', function () {
|
|
9
|
-
var DATA = {
|
|
10
|
-
alpha: 'Alpha',
|
|
11
|
-
bravo: 'Bravo'
|
|
12
|
-
};
|
|
13
|
-
var HTML = {
|
|
14
|
-
type: 'html',
|
|
15
|
-
tagName: 'p',
|
|
16
|
-
content: 'Alpha'
|
|
17
|
-
};
|
|
18
|
-
var INSET_TEXT = {
|
|
19
|
-
type: 'inset-text',
|
|
20
|
-
content: 'Bravo'
|
|
21
|
-
};
|
|
22
|
-
var HEADING = {
|
|
23
|
-
type: 'heading',
|
|
24
|
-
size: 'm',
|
|
25
|
-
content: 'Charlie'
|
|
26
|
-
};
|
|
27
|
-
it('should NOT be shown when the container is null', function () {
|
|
28
|
-
expect((0, _showContainer.default)(null, DATA)).toBeFalsy();
|
|
29
|
-
});
|
|
30
|
-
it('should NOT be shown when the container has a single show_when condition that is NOT matched', function () {
|
|
31
|
-
var CONTAINER = {
|
|
32
|
-
show_when: {
|
|
33
|
-
field: 'charlie',
|
|
34
|
-
op: '=',
|
|
35
|
-
value: 'Charlie'
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
expect((0, _showContainer.default)(CONTAINER, DATA)).toBeFalsy();
|
|
39
|
-
});
|
|
40
|
-
it('should NOT be shown when the container has multiple show_when conditions and at least one is NOT matched', function () {
|
|
41
|
-
var CONTAINER = {
|
|
42
|
-
show_when: [{
|
|
43
|
-
field: 'alpha',
|
|
44
|
-
op: '=',
|
|
45
|
-
value: 'Alpha'
|
|
46
|
-
}, {
|
|
47
|
-
field: 'charlie',
|
|
48
|
-
op: '=',
|
|
49
|
-
value: 'Charlie'
|
|
50
|
-
}]
|
|
51
|
-
};
|
|
52
|
-
expect((0, _showContainer.default)(CONTAINER, DATA)).toBeFalsy();
|
|
53
|
-
});
|
|
54
|
-
it('SHOULD be shown when the container has a single show_when condition that IS matched', function () {
|
|
55
|
-
var CONTAINER = {
|
|
56
|
-
show_when: {
|
|
57
|
-
field: 'alpha',
|
|
58
|
-
op: '=',
|
|
59
|
-
value: 'Alpha'
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
expect((0, _showContainer.default)(CONTAINER, DATA)).toBeTruthy();
|
|
63
|
-
});
|
|
64
|
-
it('SHOULD be shown when the container has multiple show_when conditions that are ALL matched', function () {
|
|
65
|
-
var CONTAINER = {
|
|
66
|
-
show_when: [{
|
|
67
|
-
field: 'alpha',
|
|
68
|
-
op: '=',
|
|
69
|
-
value: 'Alpha'
|
|
70
|
-
}, {
|
|
71
|
-
field: 'charlie',
|
|
72
|
-
op: '!=',
|
|
73
|
-
value: 'Charlie'
|
|
74
|
-
}]
|
|
75
|
-
};
|
|
76
|
-
expect((0, _showContainer.default)(CONTAINER, DATA)).toBeTruthy();
|
|
77
|
-
});
|
|
78
|
-
it('SHOULD be shown when the container has NO show_when conditions and NO editable components', function () {
|
|
79
|
-
var CONTAINER = {
|
|
80
|
-
components: [HTML, INSET_TEXT, HEADING]
|
|
81
|
-
};
|
|
82
|
-
expect((0, _showContainer.default)(CONTAINER, DATA)).toBeTruthy();
|
|
83
|
-
});
|
|
84
|
-
it('should NOT be shown when the container has NO show_when conditions and NO SHOWN editable components', function () {
|
|
85
|
-
var TEXT = {
|
|
86
|
-
type: 'text',
|
|
87
|
-
show_when: {
|
|
88
|
-
field: 'charlie',
|
|
89
|
-
op: '=',
|
|
90
|
-
value: 'Charlie'
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
var RADIOS = {
|
|
94
|
-
type: 'radios',
|
|
95
|
-
show_when: {
|
|
96
|
-
field: 'charlie',
|
|
97
|
-
op: '=',
|
|
98
|
-
value: 'Charlie'
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
var CONTAINER = {
|
|
102
|
-
components: [TEXT, RADIOS]
|
|
103
|
-
};
|
|
104
|
-
expect((0, _showContainer.default)(CONTAINER, DATA)).toBeFalsy();
|
|
105
|
-
});
|
|
106
|
-
it('SHOULD be shown when the container has NO show_when conditions and AT LEAST ONE SHOWN editable components', function () {
|
|
107
|
-
var TEXT = {
|
|
108
|
-
type: 'text',
|
|
109
|
-
show_when: {
|
|
110
|
-
field: 'alpha',
|
|
111
|
-
op: '=',
|
|
112
|
-
value: 'Alpha'
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
var RADIOS = {
|
|
116
|
-
type: 'radios',
|
|
117
|
-
show_when: {
|
|
118
|
-
field: 'charlie',
|
|
119
|
-
op: '=',
|
|
120
|
-
value: 'Charlie'
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
var CONTAINER = {
|
|
124
|
-
components: [TEXT, RADIOS]
|
|
125
|
-
};
|
|
126
|
-
expect((0, _showContainer.default)(CONTAINER, DATA)).toBeTruthy();
|
|
127
|
-
});
|
|
128
|
-
it('SHOULD be shown when the container has multiple show_when conditions, with type "or" provided and ALL are matched', function () {
|
|
129
|
-
var CONTAINER = {
|
|
130
|
-
show_when: {
|
|
131
|
-
"type": "or",
|
|
132
|
-
"conditions": [{
|
|
133
|
-
field: 'alpha',
|
|
134
|
-
op: '=',
|
|
135
|
-
value: 'Alpha'
|
|
136
|
-
}, {
|
|
137
|
-
field: 'bravo',
|
|
138
|
-
op: '=',
|
|
139
|
-
value: 'Bravo'
|
|
140
|
-
}]
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
expect((0, _showContainer.default)(CONTAINER, DATA)).toBeTruthy();
|
|
144
|
-
});
|
|
145
|
-
it('SHOULD be shown when the container has multiple show_when conditions, with type "or" provided and at least ONE is matched', function () {
|
|
146
|
-
var CONTAINER = {
|
|
147
|
-
show_when: {
|
|
148
|
-
"type": "or",
|
|
149
|
-
"conditions": [{
|
|
150
|
-
field: 'alpha',
|
|
151
|
-
op: '=',
|
|
152
|
-
value: 'Alpha'
|
|
153
|
-
}, {
|
|
154
|
-
field: 'charlie',
|
|
155
|
-
op: '=',
|
|
156
|
-
value: 'Charlie'
|
|
157
|
-
}]
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
expect((0, _showContainer.default)(CONTAINER, DATA)).toBeTruthy();
|
|
161
|
-
});
|
|
162
|
-
it('should NOT be shown when the container has multiple show_when conditions, with type "or" provided and NONE are matched', function () {
|
|
163
|
-
var CONTAINER = {
|
|
164
|
-
show_when: {
|
|
165
|
-
"type": "or",
|
|
166
|
-
"conditions": [{
|
|
167
|
-
field: 'alpha',
|
|
168
|
-
op: '!=',
|
|
169
|
-
value: 'Alpha'
|
|
170
|
-
}, {
|
|
171
|
-
field: 'charlie',
|
|
172
|
-
op: '=',
|
|
173
|
-
value: 'Charlie'
|
|
174
|
-
}]
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
expect((0, _showContainer.default)(CONTAINER, DATA)).toBeFalsy();
|
|
178
|
-
});
|
|
179
|
-
});
|
|
@@ -1,264 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _applyFormula = _interopRequireDefault(require("./applyFormula"));
|
|
4
|
-
|
|
5
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
-
|
|
7
|
-
// Local imports
|
|
8
|
-
describe('utils.Data.applyFormula', function () {
|
|
9
|
-
var error = jest.spyOn(console, 'error').mockImplementation(function () {});
|
|
10
|
-
afterAll(function () {
|
|
11
|
-
error.mockReset();
|
|
12
|
-
});
|
|
13
|
-
afterEach(function () {
|
|
14
|
-
error.mockClear();
|
|
15
|
-
});
|
|
16
|
-
it('should throw and handle exception for a null config', function () {
|
|
17
|
-
(0, _applyFormula.default)(null);
|
|
18
|
-
expect(error).toBeCalledWith("Missing 'formula' definition");
|
|
19
|
-
});
|
|
20
|
-
it("should throw and handle exception for config with missing 'formula'", function () {
|
|
21
|
-
(0, _applyFormula.default)({});
|
|
22
|
-
expect(error).toBeCalledWith("Missing 'formula' definition");
|
|
23
|
-
});
|
|
24
|
-
it("should throw and handle exception for config with 'formula' but missing 'name'", function () {
|
|
25
|
-
(0, _applyFormula.default)({
|
|
26
|
-
formula: {}
|
|
27
|
-
});
|
|
28
|
-
expect(error).toBeCalledWith("Calculation formula 'name' cannot be empty");
|
|
29
|
-
});
|
|
30
|
-
it("should throw and handle exception for config with 'formula' with unsupported operation 'name'", function () {
|
|
31
|
-
(0, _applyFormula.default)({
|
|
32
|
-
formula: {
|
|
33
|
-
name: "something"
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
expect(error).toBeCalledWith("Unsupported operation 'something'");
|
|
37
|
-
});
|
|
38
|
-
it("should throw and handle exception for 'formula' with wrong argument name", function () {
|
|
39
|
-
(0, _applyFormula.default)({
|
|
40
|
-
formula: {
|
|
41
|
-
name: 'plus',
|
|
42
|
-
args: [{
|
|
43
|
-
somthing: 1
|
|
44
|
-
}, {
|
|
45
|
-
somthing: 1
|
|
46
|
-
}]
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
expect(error).toBeCalledWith('Only accept following as argument field: {field, value, or formula}');
|
|
50
|
-
});
|
|
51
|
-
it("should throw and handle exception for 'formula' argument with more than one field", function () {
|
|
52
|
-
(0, _applyFormula.default)({
|
|
53
|
-
formula: {
|
|
54
|
-
name: 'plus',
|
|
55
|
-
args: [{
|
|
56
|
-
value: 1,
|
|
57
|
-
field: 'fieldA'
|
|
58
|
-
}, {
|
|
59
|
-
value: 1
|
|
60
|
-
}]
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
expect(error).toBeCalledWith('Argument cannot have more than one reference');
|
|
64
|
-
});
|
|
65
|
-
it("should throw and handle exception for 'formula' with single argument", function () {
|
|
66
|
-
(0, _applyFormula.default)({
|
|
67
|
-
formula: {
|
|
68
|
-
name: 'plus',
|
|
69
|
-
args: [{
|
|
70
|
-
value: 10
|
|
71
|
-
}]
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
expect(error).toBeCalledWith('Requires more than one argument for calculation');
|
|
75
|
-
});
|
|
76
|
-
var DATA = {
|
|
77
|
-
fieldA: '10',
|
|
78
|
-
fieldB: '20',
|
|
79
|
-
fieldC: 'abc',
|
|
80
|
-
fieldD: '0',
|
|
81
|
-
fieldE: '10'
|
|
82
|
-
};
|
|
83
|
-
[{
|
|
84
|
-
name: 'plus',
|
|
85
|
-
args: [{
|
|
86
|
-
field: 'fieldA'
|
|
87
|
-
}, {
|
|
88
|
-
field: 'fieldB'
|
|
89
|
-
}],
|
|
90
|
-
result: 30
|
|
91
|
-
}, {
|
|
92
|
-
name: 'minus',
|
|
93
|
-
args: [{
|
|
94
|
-
field: 'fieldB'
|
|
95
|
-
}, {
|
|
96
|
-
field: 'fieldA'
|
|
97
|
-
}],
|
|
98
|
-
result: 10
|
|
99
|
-
}, {
|
|
100
|
-
name: 'multiply',
|
|
101
|
-
args: [{
|
|
102
|
-
field: 'fieldA'
|
|
103
|
-
}, {
|
|
104
|
-
field: 'fieldB'
|
|
105
|
-
}],
|
|
106
|
-
result: 200
|
|
107
|
-
}, {
|
|
108
|
-
name: 'divide',
|
|
109
|
-
args: [{
|
|
110
|
-
field: 'fieldA'
|
|
111
|
-
}, {
|
|
112
|
-
field: 'fieldB'
|
|
113
|
-
}],
|
|
114
|
-
result: 0.5
|
|
115
|
-
}, {
|
|
116
|
-
name: 'divide',
|
|
117
|
-
args: [{
|
|
118
|
-
field: 'fieldA'
|
|
119
|
-
}, {
|
|
120
|
-
field: 'fieldD'
|
|
121
|
-
}],
|
|
122
|
-
result: Infinity
|
|
123
|
-
}, {
|
|
124
|
-
name: 'plus',
|
|
125
|
-
args: [{
|
|
126
|
-
field: 'fieldA'
|
|
127
|
-
}, {
|
|
128
|
-
field: 'fieldC'
|
|
129
|
-
}],
|
|
130
|
-
result: ''
|
|
131
|
-
}, {
|
|
132
|
-
name: 'multiply',
|
|
133
|
-
args: [{
|
|
134
|
-
field: 'fieldA'
|
|
135
|
-
}, {
|
|
136
|
-
field: 'fieldB'
|
|
137
|
-
}, {
|
|
138
|
-
field: 'fieldE'
|
|
139
|
-
}],
|
|
140
|
-
result: 2000
|
|
141
|
-
}].forEach(function (test) {
|
|
142
|
-
it("should calculate formula '".concat(test.name, "' correctly for field args to '").concat(test.result, "'"), function () {
|
|
143
|
-
var config = {
|
|
144
|
-
formData: DATA,
|
|
145
|
-
formula: {
|
|
146
|
-
name: test.name,
|
|
147
|
-
args: test.args
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
expect((0, _applyFormula.default)(config)).toEqual(test.result);
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
[{
|
|
154
|
-
fieldA: '1',
|
|
155
|
-
fieldB: '3',
|
|
156
|
-
round: 5,
|
|
157
|
-
result: 0.33333
|
|
158
|
-
}, {
|
|
159
|
-
fieldA: '2',
|
|
160
|
-
fieldB: '3',
|
|
161
|
-
round: 5,
|
|
162
|
-
result: 0.66667
|
|
163
|
-
}, {
|
|
164
|
-
fieldA: '1',
|
|
165
|
-
fieldB: '3',
|
|
166
|
-
round: 4,
|
|
167
|
-
result: 0.3333
|
|
168
|
-
}, {
|
|
169
|
-
fieldA: '2',
|
|
170
|
-
fieldB: '3',
|
|
171
|
-
round: 4,
|
|
172
|
-
result: 0.6667
|
|
173
|
-
}, {
|
|
174
|
-
fieldA: '1',
|
|
175
|
-
fieldB: '3',
|
|
176
|
-
round: 3,
|
|
177
|
-
result: 0.333
|
|
178
|
-
}, {
|
|
179
|
-
fieldA: '2',
|
|
180
|
-
fieldB: '3',
|
|
181
|
-
round: 3,
|
|
182
|
-
result: 0.667
|
|
183
|
-
}, {
|
|
184
|
-
fieldA: '1',
|
|
185
|
-
fieldB: '3',
|
|
186
|
-
round: 2,
|
|
187
|
-
result: 0.33
|
|
188
|
-
}, {
|
|
189
|
-
fieldA: '2',
|
|
190
|
-
fieldB: '3',
|
|
191
|
-
round: 2,
|
|
192
|
-
result: 0.67
|
|
193
|
-
}, {
|
|
194
|
-
fieldA: '1',
|
|
195
|
-
fieldB: '3',
|
|
196
|
-
round: 1,
|
|
197
|
-
result: 0.3
|
|
198
|
-
}, {
|
|
199
|
-
fieldA: '2',
|
|
200
|
-
fieldB: '3',
|
|
201
|
-
round: 1,
|
|
202
|
-
result: 0.7
|
|
203
|
-
}, {
|
|
204
|
-
fieldA: '1',
|
|
205
|
-
fieldB: '3',
|
|
206
|
-
round: 0,
|
|
207
|
-
result: 0
|
|
208
|
-
}, {
|
|
209
|
-
fieldA: '2',
|
|
210
|
-
fieldB: '3',
|
|
211
|
-
round: 0,
|
|
212
|
-
result: 0
|
|
213
|
-
}, {
|
|
214
|
-
fieldA: 'L',
|
|
215
|
-
fieldB: 'G3',
|
|
216
|
-
round: 1,
|
|
217
|
-
result: ''
|
|
218
|
-
}].forEach(function (test) {
|
|
219
|
-
it("should calculdate and round result to precision ".concat(test.round), function () {
|
|
220
|
-
var config = {
|
|
221
|
-
formData: {
|
|
222
|
-
fieldA: test.fieldA,
|
|
223
|
-
fieldB: test.fieldB
|
|
224
|
-
},
|
|
225
|
-
formula: {
|
|
226
|
-
name: 'divide',
|
|
227
|
-
round: test.round,
|
|
228
|
-
args: [{
|
|
229
|
-
field: 'fieldA'
|
|
230
|
-
}, {
|
|
231
|
-
field: 'fieldB'
|
|
232
|
-
}]
|
|
233
|
-
}
|
|
234
|
-
};
|
|
235
|
-
expect((0, _applyFormula.default)(config)).toEqual(test.result);
|
|
236
|
-
});
|
|
237
|
-
});
|
|
238
|
-
it("should calculate nested 'formula'", function () {
|
|
239
|
-
var config = {
|
|
240
|
-
formData: {
|
|
241
|
-
fieldA: '19',
|
|
242
|
-
fieldB: '66'
|
|
243
|
-
},
|
|
244
|
-
formula: {
|
|
245
|
-
name: 'multiply',
|
|
246
|
-
round: 2,
|
|
247
|
-
args: [{
|
|
248
|
-
formula: {
|
|
249
|
-
name: 'divide',
|
|
250
|
-
round: 4,
|
|
251
|
-
args: [{
|
|
252
|
-
field: 'fieldA'
|
|
253
|
-
}, {
|
|
254
|
-
field: 'fieldB'
|
|
255
|
-
}]
|
|
256
|
-
}
|
|
257
|
-
}, {
|
|
258
|
-
value: 100
|
|
259
|
-
}]
|
|
260
|
-
}
|
|
261
|
-
};
|
|
262
|
-
expect((0, _applyFormula.default)(config)).toEqual(28.79);
|
|
263
|
-
});
|
|
264
|
-
});
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _getAutocompleteSource = _interopRequireDefault(require("./getAutocompleteSource"));
|
|
4
|
-
|
|
5
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
-
|
|
7
|
-
// Local imports
|
|
8
|
-
describe('utils', function () {
|
|
9
|
-
describe('Data', function () {
|
|
10
|
-
describe('getAutocompleteSource', function () {
|
|
11
|
-
it('should handle a null config', function () {
|
|
12
|
-
var SOURCE = (0, _getAutocompleteSource.default)(null);
|
|
13
|
-
expect(typeof SOURCE === 'function').toBeTruthy();
|
|
14
|
-
SOURCE('query', function (results) {
|
|
15
|
-
expect(Array.isArray(results)).toBeTruthy();
|
|
16
|
-
expect(results.length).toEqual(0);
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
it('should get any specified options from the config', function () {
|
|
20
|
-
var CONFIG = {
|
|
21
|
-
data: {
|
|
22
|
-
options: [{
|
|
23
|
-
value: 'a',
|
|
24
|
-
label: 'Alpha'
|
|
25
|
-
}, {
|
|
26
|
-
value: 'b',
|
|
27
|
-
label: 'Bravo'
|
|
28
|
-
}]
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
var SOURCE = (0, _getAutocompleteSource.default)(CONFIG);
|
|
32
|
-
expect(typeof SOURCE === 'function').toBeTruthy();
|
|
33
|
-
SOURCE('a', function (results) {
|
|
34
|
-
expect(results.length).toEqual(2);
|
|
35
|
-
expect(results).toEqual([{
|
|
36
|
-
value: 'a',
|
|
37
|
-
label: 'Alpha'
|
|
38
|
-
}, {
|
|
39
|
-
value: 'b',
|
|
40
|
-
label: 'Bravo'
|
|
41
|
-
}]);
|
|
42
|
-
});
|
|
43
|
-
SOURCE('al', function (results) {
|
|
44
|
-
expect(results.length).toEqual(1);
|
|
45
|
-
expect(results).toEqual([{
|
|
46
|
-
value: 'a',
|
|
47
|
-
label: 'Alpha'
|
|
48
|
-
}]);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
it('should handle an empty query', function () {
|
|
52
|
-
var CONFIG = {
|
|
53
|
-
data: {
|
|
54
|
-
options: [{
|
|
55
|
-
value: 'a',
|
|
56
|
-
label: 'Alpha'
|
|
57
|
-
}, {
|
|
58
|
-
value: 'b',
|
|
59
|
-
label: 'Bravo'
|
|
60
|
-
}]
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
var SOURCE = (0, _getAutocompleteSource.default)(CONFIG);
|
|
64
|
-
SOURCE('', function (results) {
|
|
65
|
-
expect(results.length).toEqual(2);
|
|
66
|
-
expect(results).toEqual([{
|
|
67
|
-
value: 'a',
|
|
68
|
-
label: 'Alpha'
|
|
69
|
-
}, {
|
|
70
|
-
value: 'b',
|
|
71
|
-
label: 'Bravo'
|
|
72
|
-
}]);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
it('should handle an undefined query', function () {
|
|
76
|
-
var CONFIG = {
|
|
77
|
-
data: {
|
|
78
|
-
options: [{
|
|
79
|
-
value: 'a',
|
|
80
|
-
label: 'Alpha'
|
|
81
|
-
}, {
|
|
82
|
-
value: 'b',
|
|
83
|
-
label: 'Bravo'
|
|
84
|
-
}]
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
var SOURCE = (0, _getAutocompleteSource.default)(CONFIG);
|
|
88
|
-
SOURCE(undefined, function (results) {
|
|
89
|
-
expect(results.length).toEqual(2);
|
|
90
|
-
expect(results).toEqual([{
|
|
91
|
-
value: 'a',
|
|
92
|
-
label: 'Alpha'
|
|
93
|
-
}, {
|
|
94
|
-
value: 'b',
|
|
95
|
-
label: 'Bravo'
|
|
96
|
-
}]);
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
it('should handle a null query', function () {
|
|
100
|
-
var CONFIG = {
|
|
101
|
-
data: {
|
|
102
|
-
options: [{
|
|
103
|
-
value: 'a',
|
|
104
|
-
label: 'Alpha'
|
|
105
|
-
}, {
|
|
106
|
-
value: 'b',
|
|
107
|
-
label: 'Bravo'
|
|
108
|
-
}]
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
var SOURCE = (0, _getAutocompleteSource.default)(CONFIG);
|
|
112
|
-
SOURCE(null, function (results) {
|
|
113
|
-
expect(results.length).toEqual(2);
|
|
114
|
-
expect(results).toEqual([{
|
|
115
|
-
value: 'a',
|
|
116
|
-
label: 'Alpha'
|
|
117
|
-
}, {
|
|
118
|
-
value: 'b',
|
|
119
|
-
label: 'Bravo'
|
|
120
|
-
}]);
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
it('should handle a missing label on an option', function () {
|
|
124
|
-
var CONFIG = {
|
|
125
|
-
data: {
|
|
126
|
-
options: [{
|
|
127
|
-
value: 'a',
|
|
128
|
-
label: 'Alpha'
|
|
129
|
-
}, {
|
|
130
|
-
value: 'b'
|
|
131
|
-
}]
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
var SOURCE = (0, _getAutocompleteSource.default)(CONFIG);
|
|
135
|
-
expect(typeof SOURCE === 'function').toBeTruthy();
|
|
136
|
-
SOURCE('a', function (results) {
|
|
137
|
-
expect(results.length).toEqual(1);
|
|
138
|
-
expect(results).toEqual([{
|
|
139
|
-
value: 'a',
|
|
140
|
-
label: 'Alpha'
|
|
141
|
-
}]);
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
});
|