@ukhomeoffice/cop-react-form-renderer 5.0.0-alpha → 5.0.1
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 +45 -14
- 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 +251 -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 +76 -23
- 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,763 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _meetsCondition = _interopRequireDefault(require("./meetsCondition"));
|
|
4
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
5
|
+
// Local imports
|
|
6
|
+
|
|
7
|
+
describe('utils.Condition.meetsCondition', function () {
|
|
8
|
+
var getCondition = function getCondition(operator, val) {
|
|
9
|
+
if (['in', 'nin'].includes(operator)) {
|
|
10
|
+
return {
|
|
11
|
+
op: operator,
|
|
12
|
+
values: val
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
op: operator,
|
|
17
|
+
value: val
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
var TEST_VALUES = ['a', 'b', 3, 4, null, undefined, true, false, 0];
|
|
21
|
+
describe('equality operators', function () {
|
|
22
|
+
['eq', '='].forEach(function (op) {
|
|
23
|
+
describe("operator ".concat(op), function () {
|
|
24
|
+
// Should match...
|
|
25
|
+
it('should match two nulls', function () {
|
|
26
|
+
var VALUE = null;
|
|
27
|
+
var CONDITION = getCondition(op, null);
|
|
28
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
29
|
+
});
|
|
30
|
+
it('should match two undefineds', function () {
|
|
31
|
+
var VALUE = undefined;
|
|
32
|
+
var CONDITION = getCondition(op, undefined);
|
|
33
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
34
|
+
});
|
|
35
|
+
it('should match two identical strings', function () {
|
|
36
|
+
var VALUE = 'value';
|
|
37
|
+
var CONDITION = getCondition(op, 'value');
|
|
38
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
39
|
+
});
|
|
40
|
+
it('should match two empty strings', function () {
|
|
41
|
+
var VALUE = '';
|
|
42
|
+
var CONDITION = getCondition(op, '');
|
|
43
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
44
|
+
});
|
|
45
|
+
it('should match two identical numbers', function () {
|
|
46
|
+
var VALUE = 3;
|
|
47
|
+
var CONDITION = getCondition(op, 3);
|
|
48
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
49
|
+
});
|
|
50
|
+
it('should match two zeroes', function () {
|
|
51
|
+
var VALUE = 0;
|
|
52
|
+
var CONDITION = getCondition(op, 0);
|
|
53
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
54
|
+
});
|
|
55
|
+
it('should match two boolean trues', function () {
|
|
56
|
+
var VALUE = true;
|
|
57
|
+
var CONDITION = getCondition(op, true);
|
|
58
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
59
|
+
});
|
|
60
|
+
it('should match two boolean falses', function () {
|
|
61
|
+
var VALUE = false;
|
|
62
|
+
var CONDITION = getCondition(op, false);
|
|
63
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
64
|
+
});
|
|
65
|
+
it('should match environmentContext value with data object', function () {
|
|
66
|
+
var VALUE = 'Bob';
|
|
67
|
+
var DATA = {
|
|
68
|
+
environmentContext: {
|
|
69
|
+
currentUser: 'Bob'
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var CONDITION = getCondition(op, 'field::environmentContext.currentUser');
|
|
73
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE, DATA)).toBeTruthy();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// Should reject...
|
|
77
|
+
it('should reject a null and undefined', function () {
|
|
78
|
+
var VALUE = null;
|
|
79
|
+
var CONDITION = getCondition(op, undefined);
|
|
80
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
81
|
+
});
|
|
82
|
+
it('should reject a null and empty string', function () {
|
|
83
|
+
var VALUE = null;
|
|
84
|
+
var CONDITION = getCondition(op, '');
|
|
85
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
86
|
+
});
|
|
87
|
+
it('should reject an undefined and empty string', function () {
|
|
88
|
+
var VALUE = undefined;
|
|
89
|
+
var CONDITION = getCondition(op, '');
|
|
90
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
91
|
+
});
|
|
92
|
+
it('should reject a string of just whitespace and empty string', function () {
|
|
93
|
+
var VALUE = ' ';
|
|
94
|
+
var CONDITION = getCondition(op, '');
|
|
95
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
96
|
+
});
|
|
97
|
+
it("should reject the string number '3' and the number 3", function () {
|
|
98
|
+
var VALUE = '3';
|
|
99
|
+
var CONDITION = getCondition(op, 3);
|
|
100
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
101
|
+
});
|
|
102
|
+
it('should reject a boolean true and the number 1', function () {
|
|
103
|
+
var VALUE = true;
|
|
104
|
+
var CONDITION = getCondition(op, 1);
|
|
105
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
106
|
+
});
|
|
107
|
+
it('should reject a boolean false and a zero', function () {
|
|
108
|
+
var VALUE = false;
|
|
109
|
+
var CONDITION = getCondition(op, 0);
|
|
110
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
describe('inequality operators', function () {
|
|
116
|
+
['ne', 'neq', '!=', '<>'].forEach(function (op) {
|
|
117
|
+
describe("operator ".concat(op), function () {
|
|
118
|
+
// Should reject...
|
|
119
|
+
it('should reject two nulls', function () {
|
|
120
|
+
var VALUE = null;
|
|
121
|
+
var CONDITION = getCondition(op, null);
|
|
122
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
123
|
+
});
|
|
124
|
+
it('should reject two undefineds', function () {
|
|
125
|
+
var VALUE = undefined;
|
|
126
|
+
var CONDITION = getCondition(op, undefined);
|
|
127
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
128
|
+
});
|
|
129
|
+
it('should reject two identical strings', function () {
|
|
130
|
+
var VALUE = 'value';
|
|
131
|
+
var CONDITION = getCondition(op, 'value');
|
|
132
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
133
|
+
});
|
|
134
|
+
it('should reject two empty strings', function () {
|
|
135
|
+
var VALUE = '';
|
|
136
|
+
var CONDITION = getCondition(op, '');
|
|
137
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
138
|
+
});
|
|
139
|
+
it('should reject two identical numbers', function () {
|
|
140
|
+
var VALUE = 3;
|
|
141
|
+
var CONDITION = getCondition(op, 3);
|
|
142
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
143
|
+
});
|
|
144
|
+
it('should reject two zeroes', function () {
|
|
145
|
+
var VALUE = 0;
|
|
146
|
+
var CONDITION = getCondition(op, 0);
|
|
147
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
148
|
+
});
|
|
149
|
+
it('should reject two boolean trues', function () {
|
|
150
|
+
var VALUE = true;
|
|
151
|
+
var CONDITION = getCondition(op, true);
|
|
152
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
153
|
+
});
|
|
154
|
+
it('should reject two boolean falses', function () {
|
|
155
|
+
var VALUE = false;
|
|
156
|
+
var CONDITION = getCondition(op, false);
|
|
157
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
158
|
+
});
|
|
159
|
+
it('should reject environmentContext value with data object', function () {
|
|
160
|
+
var VALUE = 'Bob';
|
|
161
|
+
var DATA = {
|
|
162
|
+
environmentContext: {
|
|
163
|
+
currentUser: 'Bob'
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
var CONDITION = getCondition(op, 'field::environmentContext.currentUser');
|
|
167
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE, DATA)).toBeFalsy();
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// Should match...
|
|
171
|
+
it('should match a null and undefined', function () {
|
|
172
|
+
var VALUE = null;
|
|
173
|
+
var CONDITION = getCondition(op, undefined);
|
|
174
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
175
|
+
});
|
|
176
|
+
it('should match a null and empty string', function () {
|
|
177
|
+
var VALUE = null;
|
|
178
|
+
var CONDITION = getCondition(op, '');
|
|
179
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
180
|
+
});
|
|
181
|
+
it('should match an undefined and empty string', function () {
|
|
182
|
+
var VALUE = undefined;
|
|
183
|
+
var CONDITION = getCondition(op, '');
|
|
184
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
185
|
+
});
|
|
186
|
+
it('should match a string of just whitespace and empty string', function () {
|
|
187
|
+
var VALUE = ' ';
|
|
188
|
+
var CONDITION = getCondition(op, '');
|
|
189
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
190
|
+
});
|
|
191
|
+
it("should match the string number '3' and the number 3", function () {
|
|
192
|
+
var VALUE = '3';
|
|
193
|
+
var CONDITION = getCondition(op, 3);
|
|
194
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
195
|
+
});
|
|
196
|
+
it('should match a boolean true and the number 1', function () {
|
|
197
|
+
var VALUE = true;
|
|
198
|
+
var CONDITION = getCondition(op, 1);
|
|
199
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
200
|
+
});
|
|
201
|
+
it('should match a boolean false and a zero', function () {
|
|
202
|
+
var VALUE = false;
|
|
203
|
+
var CONDITION = getCondition(op, 0);
|
|
204
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
describe('operator in', function () {
|
|
210
|
+
var op = 'in';
|
|
211
|
+
|
|
212
|
+
// Should match...
|
|
213
|
+
it('should match a string that is in the values array', function () {
|
|
214
|
+
var VALUE = 'alpha';
|
|
215
|
+
var CONDITION = getCondition(op, ['alpha', 'bravo', 'charlie']);
|
|
216
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
217
|
+
});
|
|
218
|
+
it('should match a number that is in the values array', function () {
|
|
219
|
+
var VALUE = 4;
|
|
220
|
+
var CONDITION = getCondition(op, ['alpha', 'bravo', 'charlie', 4]);
|
|
221
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
// Should reject...
|
|
225
|
+
it('should reject a string that is missing from the values array', function () {
|
|
226
|
+
var VALUE = 'delta';
|
|
227
|
+
var CONDITION = getCondition(op, ['alpha', 'bravo', 'charlie']);
|
|
228
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
229
|
+
});
|
|
230
|
+
it('should reject a number that is missing from the values array', function () {
|
|
231
|
+
var VALUE = 4;
|
|
232
|
+
var CONDITION = getCondition(op, ['alpha', 'bravo', 'charlie']);
|
|
233
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
234
|
+
});
|
|
235
|
+
it('should reject everything when the values array is empty', function () {
|
|
236
|
+
var CONDITION = getCondition(op, []);
|
|
237
|
+
['a', 'b', 'c', 'd', 'e', 6, 7, 8, 9, 'ten'].forEach(function (value) {
|
|
238
|
+
expect((0, _meetsCondition.default)(CONDITION, value)).toBeFalsy();
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
it('should reject everything when the values array is null', function () {
|
|
242
|
+
var CONDITION = getCondition(op, null);
|
|
243
|
+
['a', 'b', 'c', 'd', 'e', 6, 7, 8, 9, 'ten'].forEach(function (value) {
|
|
244
|
+
expect((0, _meetsCondition.default)(CONDITION, value)).toBeFalsy();
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
describe('operator nin', function () {
|
|
249
|
+
var op = 'nin';
|
|
250
|
+
|
|
251
|
+
// Should reject...
|
|
252
|
+
it('should reject a string that is in the values array', function () {
|
|
253
|
+
var VALUE = 'alpha';
|
|
254
|
+
var CONDITION = getCondition(op, ['alpha', 'bravo', 'charlie']);
|
|
255
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
256
|
+
});
|
|
257
|
+
it('should reject a number that is in the values array', function () {
|
|
258
|
+
var VALUE = 4;
|
|
259
|
+
var CONDITION = getCondition(op, ['alpha', 'bravo', 'charlie', 4]);
|
|
260
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
// Should match...
|
|
264
|
+
it('should match a string that is missing from the values array', function () {
|
|
265
|
+
var VALUE = 'delta';
|
|
266
|
+
var CONDITION = getCondition(op, ['alpha', 'bravo', 'charlie']);
|
|
267
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
268
|
+
});
|
|
269
|
+
it('should match a number that is missing from the values array', function () {
|
|
270
|
+
var VALUE = 4;
|
|
271
|
+
var CONDITION = getCondition(op, ['alpha', 'bravo', 'charlie']);
|
|
272
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
273
|
+
});
|
|
274
|
+
it('should match anything when the values array is empty', function () {
|
|
275
|
+
var CONDITION = getCondition(op, []);
|
|
276
|
+
TEST_VALUES.forEach(function (value) {
|
|
277
|
+
expect((0, _meetsCondition.default)(CONDITION, value)).toBeTruthy();
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
it('should match anything when the values array is null', function () {
|
|
281
|
+
var CONDITION = getCondition(op, null);
|
|
282
|
+
TEST_VALUES.forEach(function (value) {
|
|
283
|
+
expect((0, _meetsCondition.default)(CONDITION, value)).toBeTruthy();
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
describe('operator contains', function () {
|
|
288
|
+
var op = 'contains';
|
|
289
|
+
|
|
290
|
+
// Should match...
|
|
291
|
+
it('should match a string that is in the field array', function () {
|
|
292
|
+
var FIELD = ['alpha', 'bravo', 'charlie'];
|
|
293
|
+
var VALUE = 'alpha';
|
|
294
|
+
var CONDITION = getCondition(op, VALUE);
|
|
295
|
+
expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeTruthy();
|
|
296
|
+
});
|
|
297
|
+
it('should match a sub-string that is in the field array', function () {
|
|
298
|
+
var FIELD = ['alpha', 'bravo', 'charlie'];
|
|
299
|
+
var VALUE = 'alp';
|
|
300
|
+
var CONDITION = getCondition(op, VALUE);
|
|
301
|
+
expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeTruthy();
|
|
302
|
+
});
|
|
303
|
+
it('should match a number that is in the field array', function () {
|
|
304
|
+
var FIELD = [1, 2, 3];
|
|
305
|
+
var VALUE = 1;
|
|
306
|
+
var CONDITION = getCondition(op, VALUE);
|
|
307
|
+
expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeTruthy();
|
|
308
|
+
});
|
|
309
|
+
it('should match a sub-string that is in the field string', function () {
|
|
310
|
+
var FIELD = 'alphabravocharlie';
|
|
311
|
+
var VALUE = 'alpha';
|
|
312
|
+
var CONDITION = getCondition(op, VALUE);
|
|
313
|
+
expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeTruthy();
|
|
314
|
+
});
|
|
315
|
+
it('should match a string that is in the field array regardless of case', function () {
|
|
316
|
+
var FIELD = ['Alpha', 'bravo', 'charlie'];
|
|
317
|
+
var VALUE = 'alpha';
|
|
318
|
+
var CONDITION = getCondition(op, VALUE);
|
|
319
|
+
expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeTruthy();
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
// Should reject...
|
|
323
|
+
it('should reject a string that is missing from the field array', function () {
|
|
324
|
+
var FIELD = ['alpha', 'bravo', 'charlie'];
|
|
325
|
+
var VALUE = 'delta';
|
|
326
|
+
var CONDITION = getCondition(op, VALUE);
|
|
327
|
+
expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeFalsy();
|
|
328
|
+
});
|
|
329
|
+
it('should reject a number that is missing from the field array', function () {
|
|
330
|
+
var FIELD = [1, 2, 3];
|
|
331
|
+
var VALUE = 4;
|
|
332
|
+
var CONDITION = getCondition(op, VALUE);
|
|
333
|
+
expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeFalsy();
|
|
334
|
+
});
|
|
335
|
+
it('should reject a substring that is missing from the field string', function () {
|
|
336
|
+
var FIELD = 'alphabravocharlie';
|
|
337
|
+
var VALUE = 'delta';
|
|
338
|
+
var CONDITION = getCondition(op, VALUE);
|
|
339
|
+
expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeFalsy();
|
|
340
|
+
});
|
|
341
|
+
it('should reject any value when the field is an empty Array', function () {
|
|
342
|
+
var FIELD = [];
|
|
343
|
+
var VALUE = 'alpha';
|
|
344
|
+
var CONDITION = getCondition(op, VALUE);
|
|
345
|
+
expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeFalsy();
|
|
346
|
+
});
|
|
347
|
+
it('should reject any value when the field is an empty string', function () {
|
|
348
|
+
var FIELD = '';
|
|
349
|
+
var VALUE = 'alpha';
|
|
350
|
+
var CONDITION = getCondition(op, VALUE);
|
|
351
|
+
expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeFalsy();
|
|
352
|
+
});
|
|
353
|
+
it('should reject any field when the value is null', function () {
|
|
354
|
+
var FIELD = ['alpha', 'bravo', 'charlie'];
|
|
355
|
+
var VALUE = null;
|
|
356
|
+
var CONDITION = getCondition(op, VALUE);
|
|
357
|
+
expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeFalsy();
|
|
358
|
+
});
|
|
359
|
+
it('should reject any field when the value is undefined', function () {
|
|
360
|
+
var FIELD = ['alpha', 'bravo', 'charlie'];
|
|
361
|
+
var VALUE = undefined;
|
|
362
|
+
var CONDITION = getCondition(op, VALUE);
|
|
363
|
+
expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeFalsy();
|
|
364
|
+
});
|
|
365
|
+
it('should reject any value when the field is null', function () {
|
|
366
|
+
var FIELD = null;
|
|
367
|
+
var VALUE = 'alpha';
|
|
368
|
+
var CONDITION = getCondition(op, VALUE);
|
|
369
|
+
expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeFalsy();
|
|
370
|
+
});
|
|
371
|
+
it('should reject any value when the field is undefined', function () {
|
|
372
|
+
var FIELD = undefined;
|
|
373
|
+
var VALUE = 'alpha';
|
|
374
|
+
var CONDITION = getCondition(op, VALUE);
|
|
375
|
+
expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeFalsy();
|
|
376
|
+
});
|
|
377
|
+
});
|
|
378
|
+
describe('operator !contains', function () {
|
|
379
|
+
var op = '!contains';
|
|
380
|
+
|
|
381
|
+
// Should match...
|
|
382
|
+
it('should match a string that is not in the field array', function () {
|
|
383
|
+
var FIELD = ['alpha', 'bravo', 'charlie'];
|
|
384
|
+
var VALUE = 'delta';
|
|
385
|
+
var CONDITION = getCondition(op, VALUE);
|
|
386
|
+
expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeTruthy();
|
|
387
|
+
});
|
|
388
|
+
it('should match any value if the field array is empty', function () {
|
|
389
|
+
var FIELD = [];
|
|
390
|
+
var VALUE = 'alpha';
|
|
391
|
+
var CONDITION = getCondition(op, VALUE);
|
|
392
|
+
expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeTruthy();
|
|
393
|
+
});
|
|
394
|
+
it('should match any field when the value is null', function () {
|
|
395
|
+
var FIELD = ['alpha', 'bravo', 'charlie'];
|
|
396
|
+
var VALUE = null;
|
|
397
|
+
var CONDITION = getCondition(op, VALUE);
|
|
398
|
+
expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeTruthy();
|
|
399
|
+
});
|
|
400
|
+
it('should match any field when the value is undefined', function () {
|
|
401
|
+
var FIELD = ['alpha', 'bravo', 'charlie'];
|
|
402
|
+
var VALUE = undefined;
|
|
403
|
+
var CONDITION = getCondition(op, VALUE);
|
|
404
|
+
expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeTruthy();
|
|
405
|
+
});
|
|
406
|
+
it('should match any value when the field is an empty string', function () {
|
|
407
|
+
var FIELD = '';
|
|
408
|
+
var VALUE = 'alpha';
|
|
409
|
+
var CONDITION = getCondition(op, VALUE);
|
|
410
|
+
expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeTruthy();
|
|
411
|
+
});
|
|
412
|
+
it('should match a number that is missing from the field array', function () {
|
|
413
|
+
var FIELD = [1, 2, 3];
|
|
414
|
+
var VALUE = 4;
|
|
415
|
+
var CONDITION = getCondition(op, VALUE);
|
|
416
|
+
expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeTruthy();
|
|
417
|
+
});
|
|
418
|
+
it('should match a substring that is missing from the field string', function () {
|
|
419
|
+
var FIELD = 'alphabravocharlie';
|
|
420
|
+
var VALUE = 'delta';
|
|
421
|
+
var CONDITION = getCondition(op, VALUE);
|
|
422
|
+
expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeTruthy();
|
|
423
|
+
});
|
|
424
|
+
it('should match any value when the field is null', function () {
|
|
425
|
+
var FIELD = null;
|
|
426
|
+
var VALUE = 'alpha';
|
|
427
|
+
var CONDITION = getCondition(op, VALUE);
|
|
428
|
+
expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeTruthy();
|
|
429
|
+
});
|
|
430
|
+
it('should match any value when the field is undefined', function () {
|
|
431
|
+
var FIELD = undefined;
|
|
432
|
+
var VALUE = 'alpha';
|
|
433
|
+
var CONDITION = getCondition(op, VALUE);
|
|
434
|
+
expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeTruthy();
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
// Should reject...
|
|
438
|
+
it('should reject a string that is in the field array', function () {
|
|
439
|
+
var FIELD = ['alpha', 'bravo', 'charlie'];
|
|
440
|
+
var VALUE = 'alpha';
|
|
441
|
+
var CONDITION = getCondition(op, VALUE);
|
|
442
|
+
expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeFalsy();
|
|
443
|
+
});
|
|
444
|
+
it('should reject a sub-string that is in the field array', function () {
|
|
445
|
+
var FIELD = ['alpha', 'bravo', 'charlie'];
|
|
446
|
+
var VALUE = 'alp';
|
|
447
|
+
var CONDITION = getCondition(op, VALUE);
|
|
448
|
+
expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeFalsy();
|
|
449
|
+
});
|
|
450
|
+
it('should reject a number that is in the field array', function () {
|
|
451
|
+
var FIELD = [1, 2, 3];
|
|
452
|
+
var VALUE = 1;
|
|
453
|
+
var CONDITION = getCondition(op, VALUE);
|
|
454
|
+
expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeFalsy();
|
|
455
|
+
});
|
|
456
|
+
it('should reject a sub-string that is in the field string', function () {
|
|
457
|
+
var FIELD = 'alphabravocharlie';
|
|
458
|
+
var VALUE = 'alpha';
|
|
459
|
+
var CONDITION = getCondition(op, VALUE);
|
|
460
|
+
expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeFalsy();
|
|
461
|
+
});
|
|
462
|
+
it('should reject a string that is in the field array regardless of case', function () {
|
|
463
|
+
var FIELD = ['Alpha', 'bravo', 'charlie'];
|
|
464
|
+
var VALUE = 'alpha';
|
|
465
|
+
var CONDITION = getCondition(op, VALUE);
|
|
466
|
+
expect((0, _meetsCondition.default)(CONDITION, FIELD)).toBeFalsy();
|
|
467
|
+
});
|
|
468
|
+
});
|
|
469
|
+
describe('numerical operators', function () {
|
|
470
|
+
it('less than should reject when value is null', function () {
|
|
471
|
+
var CONDITION = {
|
|
472
|
+
op: '<',
|
|
473
|
+
value: '100'
|
|
474
|
+
};
|
|
475
|
+
expect((0, _meetsCondition.default)(CONDITION, null)).toBeFalsy();
|
|
476
|
+
});
|
|
477
|
+
it('less than should reject when condition.value is null', function () {
|
|
478
|
+
var CONDITION = {
|
|
479
|
+
op: '<',
|
|
480
|
+
value: null
|
|
481
|
+
};
|
|
482
|
+
expect((0, _meetsCondition.default)(CONDITION, '100')).toBeFalsy();
|
|
483
|
+
});
|
|
484
|
+
it('less than should reject when condition.value and value are null', function () {
|
|
485
|
+
var CONDITION = {
|
|
486
|
+
op: '<',
|
|
487
|
+
value: null
|
|
488
|
+
};
|
|
489
|
+
expect((0, _meetsCondition.default)(CONDITION, null)).toBeFalsy();
|
|
490
|
+
});
|
|
491
|
+
it('less than should reject when value is greater than condition.value', function () {
|
|
492
|
+
var CONDITION = {
|
|
493
|
+
op: '<',
|
|
494
|
+
value: '100'
|
|
495
|
+
};
|
|
496
|
+
expect((0, _meetsCondition.default)(CONDITION, '101')).toBeFalsy();
|
|
497
|
+
});
|
|
498
|
+
it('less than should accept when value is less than condition.value', function () {
|
|
499
|
+
var CONDITION = {
|
|
500
|
+
op: '<',
|
|
501
|
+
value: '100'
|
|
502
|
+
};
|
|
503
|
+
expect((0, _meetsCondition.default)(CONDITION, '99')).toBeTruthy();
|
|
504
|
+
});
|
|
505
|
+
it('greater than should reject when value is null', function () {
|
|
506
|
+
var CONDITION = {
|
|
507
|
+
op: '>',
|
|
508
|
+
value: '100'
|
|
509
|
+
};
|
|
510
|
+
expect((0, _meetsCondition.default)(CONDITION, null)).toBeFalsy();
|
|
511
|
+
});
|
|
512
|
+
it('greater than should reject when condition.value is null', function () {
|
|
513
|
+
var CONDITION = {
|
|
514
|
+
op: '>',
|
|
515
|
+
value: null
|
|
516
|
+
};
|
|
517
|
+
expect((0, _meetsCondition.default)(CONDITION, '100')).toBeFalsy();
|
|
518
|
+
});
|
|
519
|
+
it('greater than should reject when condition.value and value are null', function () {
|
|
520
|
+
var CONDITION = {
|
|
521
|
+
op: '>',
|
|
522
|
+
value: null
|
|
523
|
+
};
|
|
524
|
+
expect((0, _meetsCondition.default)(CONDITION, null)).toBeFalsy();
|
|
525
|
+
});
|
|
526
|
+
it('greater than should reject when value is less than condition.value', function () {
|
|
527
|
+
var CONDITION = {
|
|
528
|
+
op: '>',
|
|
529
|
+
value: '100'
|
|
530
|
+
};
|
|
531
|
+
expect((0, _meetsCondition.default)(CONDITION, '99')).toBeFalsy();
|
|
532
|
+
});
|
|
533
|
+
it('greater than should accept when value is greater than condition.value', function () {
|
|
534
|
+
var CONDITION = {
|
|
535
|
+
op: '>',
|
|
536
|
+
value: '100'
|
|
537
|
+
};
|
|
538
|
+
expect((0, _meetsCondition.default)(CONDITION, '101')).toBeTruthy();
|
|
539
|
+
});
|
|
540
|
+
});
|
|
541
|
+
describe('operator includes', function () {
|
|
542
|
+
it('should accept a string that exists within the value', function () {
|
|
543
|
+
var VALUE = ['red', 'green', 'blue'];
|
|
544
|
+
var CONDITION = {
|
|
545
|
+
op: 'includes',
|
|
546
|
+
value: 'blue'
|
|
547
|
+
};
|
|
548
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
549
|
+
});
|
|
550
|
+
it('should accept a number that exists within the value', function () {
|
|
551
|
+
var VALUE = [4, 5, 6];
|
|
552
|
+
var CONDITION = {
|
|
553
|
+
op: 'includes',
|
|
554
|
+
value: 6
|
|
555
|
+
};
|
|
556
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
557
|
+
});
|
|
558
|
+
it('should reject a string that doesnt exist within the value', function () {
|
|
559
|
+
var VALUE = ['red', 'green', 'blue'];
|
|
560
|
+
var CONDITION = {
|
|
561
|
+
op: 'includes',
|
|
562
|
+
value: 'purple'
|
|
563
|
+
};
|
|
564
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
565
|
+
});
|
|
566
|
+
it('should reject a number that doesnt exist within the value', function () {
|
|
567
|
+
var VALUE = [4, 5, 6];
|
|
568
|
+
var CONDITION = {
|
|
569
|
+
op: 'includes',
|
|
570
|
+
value: 7
|
|
571
|
+
};
|
|
572
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
573
|
+
});
|
|
574
|
+
it('should reject a value that is not an array', function () {
|
|
575
|
+
var VALUE = 'badValue';
|
|
576
|
+
var CONDITION = {
|
|
577
|
+
op: 'includes',
|
|
578
|
+
value: 7
|
|
579
|
+
};
|
|
580
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
581
|
+
});
|
|
582
|
+
it('should reject an empty array', function () {
|
|
583
|
+
var VALUE = [];
|
|
584
|
+
var CONDITION = {
|
|
585
|
+
op: 'includes',
|
|
586
|
+
value: 7
|
|
587
|
+
};
|
|
588
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
589
|
+
});
|
|
590
|
+
});
|
|
591
|
+
describe('operator !includes', function () {
|
|
592
|
+
it('should reject a string that exists within the value', function () {
|
|
593
|
+
var VALUE = ['red', 'green', 'blue'];
|
|
594
|
+
var CONDITION = {
|
|
595
|
+
op: '!includes',
|
|
596
|
+
value: 'blue'
|
|
597
|
+
};
|
|
598
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
599
|
+
});
|
|
600
|
+
it('should reject a number that exists within the value', function () {
|
|
601
|
+
var VALUE = [4, 5, 6];
|
|
602
|
+
var CONDITION = {
|
|
603
|
+
op: '!includes',
|
|
604
|
+
value: 6
|
|
605
|
+
};
|
|
606
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
607
|
+
});
|
|
608
|
+
it('should accept a string that doesnt exist within the value', function () {
|
|
609
|
+
var VALUE = ['red', 'green', 'blue'];
|
|
610
|
+
var CONDITION = {
|
|
611
|
+
op: '!includes',
|
|
612
|
+
value: 'purple'
|
|
613
|
+
};
|
|
614
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
615
|
+
});
|
|
616
|
+
it('should accept a number that doesnt exist within the value', function () {
|
|
617
|
+
var VALUE = [4, 5, 6];
|
|
618
|
+
var CONDITION = {
|
|
619
|
+
op: '!includes',
|
|
620
|
+
value: 7
|
|
621
|
+
};
|
|
622
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
623
|
+
});
|
|
624
|
+
it('should accept a value that is not an array', function () {
|
|
625
|
+
var VALUE = 'badValue';
|
|
626
|
+
var CONDITION = {
|
|
627
|
+
op: '!includes',
|
|
628
|
+
value: 7
|
|
629
|
+
};
|
|
630
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
631
|
+
});
|
|
632
|
+
it('should accept an empty array', function () {
|
|
633
|
+
var VALUE = [];
|
|
634
|
+
var CONDITION = {
|
|
635
|
+
op: '!includes',
|
|
636
|
+
value: 7
|
|
637
|
+
};
|
|
638
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
639
|
+
});
|
|
640
|
+
});
|
|
641
|
+
describe('operator includesAllOf', function () {
|
|
642
|
+
it('should reject when value is not an array', function () {
|
|
643
|
+
var VALUE = 'Not an array';
|
|
644
|
+
var CONDITION = {
|
|
645
|
+
op: 'includesAllOf',
|
|
646
|
+
values: ['a', 'c']
|
|
647
|
+
};
|
|
648
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
649
|
+
});
|
|
650
|
+
it('should reject when value is an empty array', function () {
|
|
651
|
+
var VALUE = [];
|
|
652
|
+
var CONDITION = {
|
|
653
|
+
op: 'includesAllOf',
|
|
654
|
+
values: ['a', 'c']
|
|
655
|
+
};
|
|
656
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
657
|
+
});
|
|
658
|
+
it('should accept when the list of values is an empty array', function () {
|
|
659
|
+
var VALUE = ['a', 'b', 'c'];
|
|
660
|
+
var CONDITION = {
|
|
661
|
+
op: 'includesAllOf',
|
|
662
|
+
values: []
|
|
663
|
+
};
|
|
664
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
665
|
+
});
|
|
666
|
+
it('should accept a list of values that are all in field', function () {
|
|
667
|
+
var VALUE = ['a', 'b', 'c'];
|
|
668
|
+
var CONDITION = {
|
|
669
|
+
op: 'includesAllOf',
|
|
670
|
+
values: ['a', 'c']
|
|
671
|
+
};
|
|
672
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
673
|
+
});
|
|
674
|
+
it('should reject a list of values if any are missing from field', function () {
|
|
675
|
+
var VALUE = ['a', 'b', 'c'];
|
|
676
|
+
var CONDITION = {
|
|
677
|
+
op: 'includesAllOf',
|
|
678
|
+
values: ['a', 'd']
|
|
679
|
+
};
|
|
680
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
681
|
+
});
|
|
682
|
+
});
|
|
683
|
+
describe('operator !includesAllOf', function () {
|
|
684
|
+
it('should accept when value is not an array', function () {
|
|
685
|
+
var VALUE = 'Not an array';
|
|
686
|
+
var CONDITION = {
|
|
687
|
+
op: '!includesAllOf',
|
|
688
|
+
values: ['a', 'c']
|
|
689
|
+
};
|
|
690
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
691
|
+
});
|
|
692
|
+
it('should accept when value is an empty array', function () {
|
|
693
|
+
var VALUE = [];
|
|
694
|
+
var CONDITION = {
|
|
695
|
+
op: '!includesAllOf',
|
|
696
|
+
values: ['a', 'c']
|
|
697
|
+
};
|
|
698
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
699
|
+
});
|
|
700
|
+
it('should reject when the list of values is an empty array', function () {
|
|
701
|
+
var VALUE = ['a', 'b', 'c'];
|
|
702
|
+
var CONDITION = {
|
|
703
|
+
op: '!includesAllOf',
|
|
704
|
+
values: []
|
|
705
|
+
};
|
|
706
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
707
|
+
});
|
|
708
|
+
it('should reject a list of values that are all in value', function () {
|
|
709
|
+
var VALUE = ['a', 'b', 'c'];
|
|
710
|
+
var CONDITION = {
|
|
711
|
+
op: '!includesAllOf',
|
|
712
|
+
values: ['a', 'c']
|
|
713
|
+
};
|
|
714
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
715
|
+
});
|
|
716
|
+
it('should accept a list of values if any are missing from value', function () {
|
|
717
|
+
var VALUE = ['a', 'b', 'c'];
|
|
718
|
+
var CONDITION = {
|
|
719
|
+
op: '!includesAllOf',
|
|
720
|
+
values: ['a', 'd']
|
|
721
|
+
};
|
|
722
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
723
|
+
});
|
|
724
|
+
});
|
|
725
|
+
describe('unknown operator', function () {
|
|
726
|
+
var op = 'definitely_not_a_real_operator';
|
|
727
|
+
it('should reject anything regardless of the value', function () {
|
|
728
|
+
var CONDITION = getCondition(op, 'a');
|
|
729
|
+
TEST_VALUES.forEach(function (value) {
|
|
730
|
+
expect((0, _meetsCondition.default)(CONDITION, value)).toBeFalsy();
|
|
731
|
+
});
|
|
732
|
+
});
|
|
733
|
+
it('should accept anything even with a null value', function () {
|
|
734
|
+
var CONDITION = getCondition(op, null);
|
|
735
|
+
TEST_VALUES.forEach(function (value) {
|
|
736
|
+
expect((0, _meetsCondition.default)(CONDITION, value)).toBeFalsy();
|
|
737
|
+
});
|
|
738
|
+
});
|
|
739
|
+
it('should accept anything even with a undefined value', function () {
|
|
740
|
+
var CONDITION = getCondition(op, null);
|
|
741
|
+
TEST_VALUES.forEach(function (value) {
|
|
742
|
+
expect((0, _meetsCondition.default)(CONDITION, value)).toBeFalsy();
|
|
743
|
+
});
|
|
744
|
+
});
|
|
745
|
+
});
|
|
746
|
+
describe('invalid condition', function () {
|
|
747
|
+
it('should accept anything when the condition is null', function () {
|
|
748
|
+
TEST_VALUES.forEach(function (value) {
|
|
749
|
+
expect((0, _meetsCondition.default)(null, value)).toBeTruthy();
|
|
750
|
+
});
|
|
751
|
+
});
|
|
752
|
+
it('should accept anything when the condition is undefined', function () {
|
|
753
|
+
TEST_VALUES.forEach(function (value) {
|
|
754
|
+
expect((0, _meetsCondition.default)(undefined, value)).toBeTruthy();
|
|
755
|
+
});
|
|
756
|
+
});
|
|
757
|
+
it('should accept anything when the condition is not an object', function () {
|
|
758
|
+
TEST_VALUES.forEach(function (value) {
|
|
759
|
+
expect((0, _meetsCondition.default)('condition', value)).toBeTruthy();
|
|
760
|
+
});
|
|
761
|
+
});
|
|
762
|
+
});
|
|
763
|
+
});
|