@zohodesk/library-platform 1.1.9-exp.1 → 1.1.10
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/es/bc/field-validation/Constants.js +4 -0
- package/es/bc/field-validation/EventHandlers.js +1 -0
- package/es/bc/field-validation/Events.js +106 -0
- package/es/bc/field-validation/FieldTypes.js +20 -0
- package/es/bc/field-validation/Properties.js +11 -0
- package/es/bc/field-validation/index.js +5 -0
- package/es/cc/ephi-tag/Properties.js +1 -0
- package/es/cc/ephi-tag/index.js +1 -0
- package/es/cc/info-icon/Properties.js +10 -0
- package/es/cc/info-icon/index.js +1 -0
- package/es/{platform/app-context-behaviour → library/behaviours/field-validation}/adapters/controllers/AbstractController.js +4 -2
- package/es/library/behaviours/field-validation/adapters/controllers/ValidateFieldController.js +32 -0
- package/es/library/behaviours/field-validation/adapters/controllers/ValidateFieldsController.js +31 -0
- package/es/library/behaviours/field-validation/adapters/gateway/Repository.js +23 -0
- package/es/library/behaviours/field-validation/adapters/gateway/Service.js +18 -0
- package/es/library/behaviours/field-validation/applications/interfaces/input/FieldData.js +17 -0
- package/es/library/behaviours/field-validation/applications/usecases/AbstractUseCase.js +15 -0
- package/es/library/behaviours/field-validation/applications/usecases/ValidateField.js +29 -0
- package/es/library/behaviours/field-validation/applications/usecases/ValidateFields.js +28 -0
- package/es/library/behaviours/field-validation/domain/FieldValidation.js +94 -0
- package/es/library/behaviours/field-validation/domain/field-vise-validations/BooleanValidation.js +28 -0
- package/es/library/behaviours/field-validation/domain/field-vise-validations/CurrencyValidation.js +49 -0
- package/es/library/behaviours/field-validation/domain/field-vise-validations/DateTimeValidation.js +24 -0
- package/es/library/behaviours/field-validation/domain/field-vise-validations/DateValidation.js +24 -0
- package/es/library/behaviours/field-validation/domain/field-vise-validations/DecimalValidation.js +49 -0
- package/es/library/behaviours/field-validation/domain/field-vise-validations/EmailValidation.js +28 -0
- package/es/library/behaviours/field-validation/domain/field-vise-validations/IntegerValidation.js +39 -0
- package/es/library/behaviours/field-validation/domain/field-vise-validations/LookUpValidation.js +24 -0
- package/es/library/behaviours/field-validation/domain/field-vise-validations/MultiSelectValidation.js +26 -0
- package/es/library/behaviours/field-validation/domain/field-vise-validations/PercentValidation.js +28 -0
- package/es/library/behaviours/field-validation/domain/field-vise-validations/PhoneValidation.js +39 -0
- package/es/library/behaviours/field-validation/domain/field-vise-validations/PicklistValidation.js +24 -0
- package/es/library/behaviours/field-validation/domain/field-vise-validations/TextAreaValidation.js +39 -0
- package/es/library/behaviours/field-validation/domain/field-vise-validations/TextBoxValidation.js +39 -0
- package/es/library/behaviours/field-validation/domain/field-vise-validations/URLValidation.js +28 -0
- package/es/library/behaviours/field-validation/domain/interfaces/FieldTypes.js +20 -0
- package/es/library/behaviours/field-validation/domain/interfaces/ValidationsEnum.js +22 -0
- package/es/library/behaviours/field-validation/domain/interfaces/ValidationsMap.js +1 -0
- package/es/library/behaviours/field-validation/domain/interfaces/fields/IDateField.js +0 -0
- package/es/library/behaviours/field-validation/domain/interfaces/fields/IDateTimeField.js +0 -0
- package/es/library/behaviours/field-validation/domain/interfaces/fields/IDecimalField.js +0 -0
- package/es/library/behaviours/field-validation/domain/interfaces/fields/IEmailField.js +0 -0
- package/es/library/behaviours/field-validation/domain/interfaces/fields/IIntegerField.js +0 -0
- package/es/library/behaviours/field-validation/domain/interfaces/fields/ILookUpField.js +0 -0
- package/es/library/behaviours/field-validation/domain/interfaces/fields/IMultiSelectField.js +0 -0
- package/es/library/behaviours/field-validation/domain/interfaces/fields/IPercentField.js +0 -0
- package/es/library/behaviours/field-validation/domain/interfaces/fields/IPhoneField.js +0 -0
- package/es/library/behaviours/field-validation/domain/interfaces/fields/IPicklistField.js +0 -0
- package/es/library/behaviours/field-validation/domain/interfaces/fields/ITextAreaField.js +0 -0
- package/es/library/behaviours/field-validation/domain/interfaces/fields/ITextBoxField.js +0 -0
- package/es/library/behaviours/field-validation/domain/interfaces/fields/IURLField.js +0 -0
- package/es/library/behaviours/field-validation/frameworks/ui/EventHandlerFactory.js +23 -0
- package/es/library/behaviours/field-validation/frameworks/ui/FieldValidationBehaviourFactory.js +27 -0
- package/es/library/behaviours/field-validation/frameworks/ui/__tests__/BooleanFieldValidation.test.js +137 -0
- package/es/library/behaviours/field-validation/frameworks/ui/__tests__/CurrencyFieldValidation.test.js +228 -0
- package/es/library/behaviours/field-validation/frameworks/ui/__tests__/DateFieldValidation.test.js +108 -0
- package/es/library/behaviours/field-validation/frameworks/ui/__tests__/DateTimeFieldValidation.test.js +108 -0
- package/es/library/behaviours/field-validation/frameworks/ui/__tests__/DecimalFieldValidation.test.js +257 -0
- package/es/library/behaviours/field-validation/frameworks/ui/__tests__/EmailFieldValidation.test.js +139 -0
- package/es/library/behaviours/field-validation/frameworks/ui/__tests__/FieldValidationBehaviour.test.js +171 -0
- package/es/library/behaviours/field-validation/frameworks/ui/__tests__/IntegerFieldValidation.test.js +168 -0
- package/es/library/behaviours/field-validation/frameworks/ui/__tests__/LookUpFieldValidation.test.js +108 -0
- package/es/library/behaviours/field-validation/frameworks/ui/__tests__/MultiSelectFieldValidation.test.js +79 -0
- package/es/library/behaviours/field-validation/frameworks/ui/__tests__/PercentFieldValidation.test.js +108 -0
- package/es/library/behaviours/field-validation/frameworks/ui/__tests__/PhoneFieldValidation.test.js +168 -0
- package/es/library/behaviours/field-validation/frameworks/ui/__tests__/PicklistFieldValidation.test.js +79 -0
- package/es/library/behaviours/field-validation/frameworks/ui/__tests__/TextAreaFieldValidation.test.js +170 -0
- package/es/library/behaviours/field-validation/frameworks/ui/__tests__/TextBoxFieldValidation.test.js +170 -0
- package/es/library/behaviours/field-validation/frameworks/ui/__tests__/URLFieldValidation.test.js +108 -0
- package/es/library/behaviours/field-validation/frameworks/utils/FormBasicValidationAdaptor.js +228 -0
- package/es/library/behaviours/field-validation/frameworks/utils/__tests__/formValidate.test.js +284 -0
- package/es/library/behaviours/field-validation/frameworks/utils/formValidate.js +334 -0
- package/es/library/dot/components/form-fields/checkbox/adapters/presenter/TransformState.js +22 -0
- package/es/library/dot/components/form-fields/currency/adapters/presenter/TransformState.js +81 -0
- package/es/library/dot/components/form-fields/date/adapters/presenter/TransformState.js +22 -0
- package/es/library/dot/components/form-fields/datetime/adapters/presenter/TransformState.js +22 -0
- package/es/library/dot/components/form-fields/decimal/adapters/presenter/TransformState.js +31 -0
- package/es/library/dot/components/form-fields/email/adapters/presenter/TransformState.js +23 -0
- package/es/library/dot/components/form-fields/ephi-tag/frameworks/ui/EPHITag.js +10 -0
- package/es/library/dot/components/form-fields/ephi-tag/frameworks/ui/EPHITagView.js +21 -0
- package/es/library/dot/components/form-fields/ephi-tag/frameworks/ui/css/EPHITag.module.css +3 -0
- package/es/library/dot/components/form-fields/info-icon/frameworks/ui/InfoIcon.js +10 -0
- package/es/library/dot/components/form-fields/info-icon/frameworks/ui/InfoIconView.js +21 -0
- package/es/library/dot/components/form-fields/info-icon/frameworks/ui/css/InfoIcon.module.css +3 -0
- package/es/library/dot/components/form-fields/multi-select/adapters/presenter/TransformState.js +31 -0
- package/es/library/dot/components/form-fields/number/adapters/presenter/TransformState.js +31 -0
- package/es/library/dot/components/form-fields/percentage/adapters/presenter/TransformState.js +31 -0
- package/es/library/dot/components/form-fields/phone/adapters/presenter/TransformState.js +31 -0
- package/es/library/dot/components/form-fields/pick-list/adapters/presenter/TransformState.js +23 -0
- package/es/library/dot/components/form-fields/textarea/adapters/presenter/TransformState.js +23 -0
- package/es/library/dot/components/form-fields/textbox/adapters/presenter/TransformState.js +32 -0
- package/es/library/dot/components/form-fields/url/adapters/presenter/TransformState.js +31 -0
- package/es/library/dot/components/section/adapters/presenter/TransFormState.js +26 -0
- package/es/library/dot/legacy-to-new-arch/label/frameworks/ui/sub-components/ui/LabelAction.js +9 -0
- package/es/library/dot/legacy-to-new-arch/label/frameworks/ui/sub-components/ui/LabelActionView.js +38 -0
- package/es/library/dot/legacy-to-new-arch/label/frameworks/ui/sub-components/ui/css/LabelAction.module.css +4 -0
- package/es/platform/components/form-connected/adapters/resources/SmartFormResources.js +18 -0
- package/es/platform/components/form-connected/frameworks/FormSdkFactory.js +4 -2
- package/es/platform/zdata-source/domain/entities/APITemplate.js +2 -1
- package/es/platform/zform/adapters/controllers/ValidateErrorMessageController.js +22 -0
- package/es/platform/zform/applications/interfaces/input/GetIsFieldValueChangedUseCaseInput.js +1 -0
- package/es/platform/zform/applications/interfaces/input/ValidateErrorMessageInputModel.js +1 -0
- package/es/platform/zform/applications/usecases/GetIsFieldValueChanged.js +35 -0
- package/es/platform/zform/applications/usecases/ValidateErrorMessageUseCase.js +33 -0
- package/es/platform/zform/applications/usecases/ValidateFieldRequestUseCase.js +56 -0
- package/es/platform/zform/domain/ZField.js +4 -0
- package/package.json +1 -1
- package/es/bc/app-context/Event.js +0 -1
- package/es/bc/app-context/Properties.js +0 -58
- package/es/cc/component/ErrorStructure.js +0 -9
- package/es/cc/error-state/ErrorTypes.js +0 -11
- package/es/cc/error-state/Properties.js +0 -31
- package/es/cc/error-state/index.js +0 -2
- package/es/library/custom-component/domain/entities/ComponentProperties.js +0 -121
- package/es/library/custom-component/domain/entities/Logger.js +0 -63
- package/es/library/dot/legacy-to-new-arch/error-state/frameworks/ui/ErrorState.js +0 -10
- package/es/library/dot/legacy-to-new-arch/error-state/frameworks/ui/ErrorStateView.js +0 -68
- package/es/platform/app-context-behaviour/adapters/controllers/InitializeController.js +0 -19
- package/es/platform/app-context-behaviour/adapters/gateways/Service.js +0 -7
- package/es/platform/app-context-behaviour/adapters/presenters/Presenter.js +0 -18
- package/es/platform/app-context-behaviour/adapters/resources/AppResource.js +0 -25
- package/es/platform/app-context-behaviour/applications/AbstractUseCase.js +0 -6
- package/es/platform/app-context-behaviour/applications/usecases/InitializeUseCase.js +0 -15
- package/es/platform/app-context-behaviour/frameworks/AppContextBehaviourFactory.js +0 -31
- package/es/platform/app-context-behaviour/frameworks/EventHandlerFactory.js +0 -25
- package/es/platform/components/form-connected/frameworks/FallbackView.js +0 -23
- package/es/platform/data-source/http-template/getDependencyMappings.js +0 -18
- package/es/platform/data-source/http-template/getLayoutRules.js +0 -29
- package/es/platform/data-source/http-template/getMyForm.js +0 -19
- package/es/platform/data-source/http-template/getMyLayout.js +0 -43
- package/es/platform/data-source/http-template/getValidationRules.js +0 -30
- package/es/platform/zform/adapters/controllers/ApiFailureController.js +0 -31
- package/es/platform/zform/applications/usecases/ApiFailureUseCase.js +0 -30
- /package/es/{platform/app-context-behaviour/applications/interfaces/UsecaseDependencies.js → library/behaviours/field-validation/applications/interfaces/UseCaseDependencies.js} +0 -0
- /package/es/{platform/app-context-behaviour/applications/interfaces/gateways/IService.js → library/behaviours/field-validation/applications/interfaces/gateways/IRepository.js} +0 -0
- /package/es/{platform/app-context-behaviour/applications/interfaces/input/InitializeUseCaseInputModel.js → library/behaviours/field-validation/applications/interfaces/gateways/IService.js} +0 -0
- /package/es/{platform/app-context-behaviour/applications/interfaces/output/BehaviourState.js → library/behaviours/field-validation/applications/interfaces/input/FieldValidationInputModel.js} +0 -0
- /package/es/{platform/app-context-behaviour/applications/interfaces/output/IPresenter.js → library/behaviours/field-validation/applications/interfaces/input/ValidateFieldsInputModel.js} +0 -0
- /package/es/{bc/app-context/Constants.js → library/behaviours/field-validation/domain/interfaces/IField.js} +0 -0
- /package/es/{platform/app-context-behaviour/applications/interfaces/resources/ApiHeaderContract.js → library/behaviours/field-validation/domain/interfaces/IFieldValidation.js} +0 -0
- /package/es/{platform/app-context-behaviour/applications/interfaces/resources/ContextContract.js → library/behaviours/field-validation/domain/interfaces/IFieldViseValidation.js} +0 -0
- /package/es/{platform/app-context-behaviour/applications/interfaces/resources/IAppResource.js → library/behaviours/field-validation/domain/interfaces/ValidationResult.js} +0 -0
- /package/es/{platform/zform/applications/interfaces/input/ApiFailureInputModel.js → library/behaviours/field-validation/domain/interfaces/ValidationsArray.js} +0 -0
- /package/es/{bc/app-context/EventHandlers.js → library/behaviours/field-validation/domain/interfaces/fields/IBooleanField.js} +0 -0
- /package/es/library/{custom-component/domain/entities/interfaces/IComponentProperties.js → behaviours/field-validation/domain/interfaces/fields/ICurrencyField.js} +0 -0
package/es/library/behaviours/field-validation/frameworks/ui/__tests__/URLFieldValidation.test.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { VALIDATE_FIELD, FIELD_VALIDATION_RESULT } from "../../../../../../bc/field-validation/Constants";
|
|
2
|
+
import FieldValidationBehaviourFactory from "../FieldValidationBehaviourFactory";
|
|
3
|
+
import { validations } from "../../utils/FormBasicValidationAdaptor";
|
|
4
|
+
import FieldTypes from "../../../../../../bc/field-validation/FieldTypes";
|
|
5
|
+
describe('URL FieldValidationBehaviour', () => {
|
|
6
|
+
let behaviour;
|
|
7
|
+
let state;
|
|
8
|
+
let updateState;
|
|
9
|
+
let dispatch;
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
behaviour = FieldValidationBehaviourFactory.create();
|
|
12
|
+
state = {
|
|
13
|
+
properties: {
|
|
14
|
+
validations
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
updateState = jest.fn();
|
|
18
|
+
dispatch = jest.fn();
|
|
19
|
+
});
|
|
20
|
+
it('should validate URL mandatory field and return error', () => {
|
|
21
|
+
const field = {
|
|
22
|
+
id: 'url',
|
|
23
|
+
type: FieldTypes.URL,
|
|
24
|
+
required: true
|
|
25
|
+
};
|
|
26
|
+
const event = {
|
|
27
|
+
state,
|
|
28
|
+
updateState,
|
|
29
|
+
action: {
|
|
30
|
+
type: VALIDATE_FIELD,
|
|
31
|
+
payload: {
|
|
32
|
+
field,
|
|
33
|
+
value: ''
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
dispatch
|
|
37
|
+
};
|
|
38
|
+
behaviour.eventHandlers[VALIDATE_FIELD](event);
|
|
39
|
+
expect(dispatch).toHaveBeenCalledWith({
|
|
40
|
+
type: FIELD_VALIDATION_RESULT,
|
|
41
|
+
payload: {
|
|
42
|
+
validationResult: {
|
|
43
|
+
isValid: false,
|
|
44
|
+
message: 'This field is required.'
|
|
45
|
+
},
|
|
46
|
+
field
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
it('should validate valid URL and return true', () => {
|
|
51
|
+
const field = {
|
|
52
|
+
id: 'url',
|
|
53
|
+
type: FieldTypes.URL
|
|
54
|
+
};
|
|
55
|
+
const event = {
|
|
56
|
+
state,
|
|
57
|
+
updateState,
|
|
58
|
+
action: {
|
|
59
|
+
type: VALIDATE_FIELD,
|
|
60
|
+
payload: {
|
|
61
|
+
field,
|
|
62
|
+
value: 'http://example.com'
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
dispatch
|
|
66
|
+
};
|
|
67
|
+
behaviour.eventHandlers[VALIDATE_FIELD](event);
|
|
68
|
+
expect(dispatch).toHaveBeenCalledWith({
|
|
69
|
+
type: FIELD_VALIDATION_RESULT,
|
|
70
|
+
payload: {
|
|
71
|
+
validationResult: {
|
|
72
|
+
isValid: true,
|
|
73
|
+
message: ''
|
|
74
|
+
},
|
|
75
|
+
field
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
xit('should validate invalid URL and return false', () => {
|
|
80
|
+
const field = {
|
|
81
|
+
id: 'url',
|
|
82
|
+
type: FieldTypes.URL
|
|
83
|
+
};
|
|
84
|
+
const event = {
|
|
85
|
+
state,
|
|
86
|
+
updateState,
|
|
87
|
+
action: {
|
|
88
|
+
type: VALIDATE_FIELD,
|
|
89
|
+
payload: {
|
|
90
|
+
field,
|
|
91
|
+
value: 'invalid-url'
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
dispatch
|
|
95
|
+
};
|
|
96
|
+
behaviour.eventHandlers[VALIDATE_FIELD](event);
|
|
97
|
+
expect(dispatch).toHaveBeenCalledWith({
|
|
98
|
+
type: FIELD_VALIDATION_RESULT,
|
|
99
|
+
payload: {
|
|
100
|
+
validationResult: {
|
|
101
|
+
isValid: false,
|
|
102
|
+
message: 'Invalid URL format'
|
|
103
|
+
},
|
|
104
|
+
field
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
});
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import { fieldValidate } from "./formValidate";
|
|
3
|
+
import ValidationsEnum from "../../domain/interfaces/ValidationsEnum";
|
|
4
|
+
export const validations = {
|
|
5
|
+
// NOTE: special validations
|
|
6
|
+
[ValidationsEnum.mandatory]: mandatory,
|
|
7
|
+
[ValidationsEnum.maxLength]: maxLength,
|
|
8
|
+
[ValidationsEnum.decimalPlaces]: decimalPlaces,
|
|
9
|
+
// NOTE: type based validations
|
|
10
|
+
[ValidationsEnum.text]: text,
|
|
11
|
+
[ValidationsEnum.textArea]: textArea,
|
|
12
|
+
[ValidationsEnum.email]: email,
|
|
13
|
+
[ValidationsEnum.phone]: phone,
|
|
14
|
+
[ValidationsEnum.integer]: integer,
|
|
15
|
+
[ValidationsEnum.decimal]: decimal,
|
|
16
|
+
[ValidationsEnum.date]: date,
|
|
17
|
+
[ValidationsEnum.dateTime]: dateTime,
|
|
18
|
+
[ValidationsEnum.boolean]: boolean,
|
|
19
|
+
[ValidationsEnum.multiSelect]: multiSelect,
|
|
20
|
+
[ValidationsEnum.picklist]: picklist,
|
|
21
|
+
[ValidationsEnum.percent]: percent,
|
|
22
|
+
[ValidationsEnum.currency]: currency,
|
|
23
|
+
[ValidationsEnum.url]: url
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
function mandatory(value, _ref) {
|
|
27
|
+
let {
|
|
28
|
+
type
|
|
29
|
+
} = _ref;
|
|
30
|
+
const fieldDetails = {
|
|
31
|
+
type,
|
|
32
|
+
isMandatory: true
|
|
33
|
+
};
|
|
34
|
+
const result = fieldValidate(value, fieldDetails);
|
|
35
|
+
return {
|
|
36
|
+
isValid: !result.isError,
|
|
37
|
+
message: 'This field is required.'
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function maxLength(value, _ref2) {
|
|
42
|
+
let {
|
|
43
|
+
maxLength
|
|
44
|
+
} = _ref2;
|
|
45
|
+
const fieldDetails = {
|
|
46
|
+
type: 'Text',
|
|
47
|
+
maxLength
|
|
48
|
+
};
|
|
49
|
+
const result = fieldValidate(value, fieldDetails);
|
|
50
|
+
return {
|
|
51
|
+
isValid: !result.isError,
|
|
52
|
+
message: 'Field exceeds max length'
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function decimalPlaces(value, _ref3) {
|
|
57
|
+
let {
|
|
58
|
+
decimalPlaces
|
|
59
|
+
} = _ref3;
|
|
60
|
+
const fieldDetails = {
|
|
61
|
+
type: 'Decimal',
|
|
62
|
+
decimalPlaces
|
|
63
|
+
};
|
|
64
|
+
const result = fieldValidate(value, fieldDetails);
|
|
65
|
+
return {
|
|
66
|
+
isValid: !result.isError,
|
|
67
|
+
message: 'Invalid decimal places'
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function text(value) {
|
|
72
|
+
const fieldDetails = {
|
|
73
|
+
type: 'Text'
|
|
74
|
+
};
|
|
75
|
+
const result = fieldValidate(value, fieldDetails);
|
|
76
|
+
return {
|
|
77
|
+
isValid: !result.isError,
|
|
78
|
+
message: result.message
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function textArea(value) {
|
|
83
|
+
const fieldDetails = {
|
|
84
|
+
type: 'Textarea'
|
|
85
|
+
};
|
|
86
|
+
const result = fieldValidate(value, fieldDetails);
|
|
87
|
+
return {
|
|
88
|
+
isValid: !result.isError,
|
|
89
|
+
message: result.message
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function email(value) {
|
|
94
|
+
const fieldDetails = {
|
|
95
|
+
type: 'Email'
|
|
96
|
+
};
|
|
97
|
+
const result = fieldValidate(value, fieldDetails);
|
|
98
|
+
return {
|
|
99
|
+
isValid: !result.isError,
|
|
100
|
+
message: 'Invalid email format'
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function phone(value) {
|
|
105
|
+
const fieldDetails = {
|
|
106
|
+
type: 'Phone'
|
|
107
|
+
};
|
|
108
|
+
const result = fieldValidate(value, fieldDetails);
|
|
109
|
+
return {
|
|
110
|
+
isValid: !result.isError,
|
|
111
|
+
message: 'Invalid phone number format'
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function integer(value) {
|
|
116
|
+
const fieldDetails = {
|
|
117
|
+
type: 'Number'
|
|
118
|
+
};
|
|
119
|
+
const result = fieldValidate(value, fieldDetails);
|
|
120
|
+
return {
|
|
121
|
+
isValid: !result.isError,
|
|
122
|
+
message: 'Invalid integer format'
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function decimal(value) {
|
|
127
|
+
// NOTE: for Decimal, decimalPlaces is must in fieldValidate. So we handled in adaptor side
|
|
128
|
+
const fieldDetails = {
|
|
129
|
+
type: 'Decimal',
|
|
130
|
+
decimalPlaces: 1000
|
|
131
|
+
};
|
|
132
|
+
const result = fieldValidate(value, fieldDetails);
|
|
133
|
+
return {
|
|
134
|
+
isValid: !result.isError,
|
|
135
|
+
message: 'Invalid decimal format'
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function date(value) {
|
|
140
|
+
const fieldDetails = {
|
|
141
|
+
type: 'Date'
|
|
142
|
+
};
|
|
143
|
+
const result = fieldValidate(value, fieldDetails); // NOTE: data field returns true even for invalid date format
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
isValid: !result.isError,
|
|
147
|
+
message: 'Invalid date format'
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function dateTime(value) {
|
|
152
|
+
const fieldDetails = {
|
|
153
|
+
type: 'DateTime'
|
|
154
|
+
};
|
|
155
|
+
const result = fieldValidate(value, fieldDetails); // NOTE: data field returns true even for invalid date time format
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
isValid: !result.isError,
|
|
159
|
+
message: 'Invalid datetime format'
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function boolean(value) {
|
|
164
|
+
const fieldDetails = {
|
|
165
|
+
type: 'Boolean'
|
|
166
|
+
};
|
|
167
|
+
const result = fieldValidate(value, fieldDetails); // NOTE: need to fix invalid value
|
|
168
|
+
|
|
169
|
+
return {
|
|
170
|
+
isValid: !result.isError,
|
|
171
|
+
message: 'Invalid boolean format'
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function multiSelect(value) {
|
|
176
|
+
const fieldDetails = {
|
|
177
|
+
type: 'Multiselect'
|
|
178
|
+
};
|
|
179
|
+
const result = fieldValidate(value, fieldDetails);
|
|
180
|
+
return {
|
|
181
|
+
isValid: !result.isError,
|
|
182
|
+
message: result.message
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function picklist(value) {
|
|
187
|
+
const fieldDetails = {
|
|
188
|
+
type: 'Picklist'
|
|
189
|
+
};
|
|
190
|
+
const result = fieldValidate(value, fieldDetails);
|
|
191
|
+
return {
|
|
192
|
+
isValid: !result.isError,
|
|
193
|
+
message: result.message
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function percent(value) {
|
|
198
|
+
const fieldDetails = {
|
|
199
|
+
type: 'Percent'
|
|
200
|
+
};
|
|
201
|
+
const result = fieldValidate(value, fieldDetails);
|
|
202
|
+
return {
|
|
203
|
+
isValid: !result.isError,
|
|
204
|
+
message: "Invalid percent value"
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function currency(value) {
|
|
209
|
+
const fieldDetails = {
|
|
210
|
+
type: 'Currency'
|
|
211
|
+
};
|
|
212
|
+
const result = fieldValidate(value, fieldDetails);
|
|
213
|
+
return {
|
|
214
|
+
isValid: !result.isError,
|
|
215
|
+
message: result.message
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function url(value) {
|
|
220
|
+
const fieldDetails = {
|
|
221
|
+
type: 'URL'
|
|
222
|
+
};
|
|
223
|
+
const result = fieldValidate(value, fieldDetails);
|
|
224
|
+
return {
|
|
225
|
+
isValid: !result.isError,
|
|
226
|
+
message: result.message
|
|
227
|
+
};
|
|
228
|
+
}
|
package/es/library/behaviours/field-validation/frameworks/utils/__tests__/formValidate.test.js
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
// import { fieldValidate, validator } from '../../utils/fieldValidate';
|
|
2
|
+
import { fieldValidate } from "../formValidate";
|
|
3
|
+
describe('fieldValidate', () => {
|
|
4
|
+
test('Validate empty string', () => {
|
|
5
|
+
const fieldDetails = {
|
|
6
|
+
type: 'Text',
|
|
7
|
+
isMandatory: true
|
|
8
|
+
};
|
|
9
|
+
const result = fieldValidate('', fieldDetails);
|
|
10
|
+
expect(result.isError).toBe(true);
|
|
11
|
+
expect(result.message).toBe('crm.field.empty.check');
|
|
12
|
+
});
|
|
13
|
+
test('Validate non-empty string', () => {
|
|
14
|
+
const fieldDetails = {
|
|
15
|
+
type: 'Text',
|
|
16
|
+
isMandatory: true
|
|
17
|
+
};
|
|
18
|
+
const result = fieldValidate('test', fieldDetails);
|
|
19
|
+
expect(result.isError).toBe(false);
|
|
20
|
+
});
|
|
21
|
+
test('Validate empty array', () => {
|
|
22
|
+
const fieldDetails = {
|
|
23
|
+
type: 'Multiselect',
|
|
24
|
+
isMandatory: true
|
|
25
|
+
};
|
|
26
|
+
const result = fieldValidate([], fieldDetails);
|
|
27
|
+
expect(result.isError).toBe(true);
|
|
28
|
+
expect(result.message).toBe('crm.field.empty.check');
|
|
29
|
+
});
|
|
30
|
+
test('Validate non-empty array', () => {
|
|
31
|
+
const fieldDetails = {
|
|
32
|
+
type: 'Multiselect',
|
|
33
|
+
isMandatory: true
|
|
34
|
+
};
|
|
35
|
+
const result = fieldValidate(['item'], fieldDetails);
|
|
36
|
+
expect(result.isError).toBe(false);
|
|
37
|
+
});
|
|
38
|
+
test('Validate empty object', () => {
|
|
39
|
+
const fieldDetails = {
|
|
40
|
+
type: 'Object',
|
|
41
|
+
isMandatory: true
|
|
42
|
+
};
|
|
43
|
+
const result = fieldValidate({}, fieldDetails);
|
|
44
|
+
expect(result.isError).toBe(true);
|
|
45
|
+
expect(result.message).toBe('crm.field.empty.check');
|
|
46
|
+
});
|
|
47
|
+
test('Validate non-empty object', () => {
|
|
48
|
+
const fieldDetails = {
|
|
49
|
+
type: 'Object',
|
|
50
|
+
isMandatory: true
|
|
51
|
+
};
|
|
52
|
+
const result = fieldValidate({
|
|
53
|
+
key: 'value'
|
|
54
|
+
}, fieldDetails);
|
|
55
|
+
expect(result.isError).toBe(false);
|
|
56
|
+
});
|
|
57
|
+
test('Validate valid email', () => {
|
|
58
|
+
const fieldDetails = {
|
|
59
|
+
type: 'Email'
|
|
60
|
+
};
|
|
61
|
+
const result = fieldValidate('test@example.com', fieldDetails);
|
|
62
|
+
expect(result.isError).toBe(false);
|
|
63
|
+
});
|
|
64
|
+
test('Validate invalid email', () => {
|
|
65
|
+
const fieldDetails = {
|
|
66
|
+
type: 'Email'
|
|
67
|
+
};
|
|
68
|
+
const result = fieldValidate('invalid-email', fieldDetails);
|
|
69
|
+
expect(result.isError).toBe(true);
|
|
70
|
+
expect(result.message).toBe('crm.field.valid.check');
|
|
71
|
+
});
|
|
72
|
+
test('Validate valid phone number', () => {
|
|
73
|
+
const fieldDetails = {
|
|
74
|
+
type: 'Phone'
|
|
75
|
+
};
|
|
76
|
+
const result = fieldValidate('+1234567890', fieldDetails);
|
|
77
|
+
expect(result.isError).toBe(false);
|
|
78
|
+
});
|
|
79
|
+
test('Validate invalid phone number', () => {
|
|
80
|
+
const fieldDetails = {
|
|
81
|
+
type: 'Phone'
|
|
82
|
+
};
|
|
83
|
+
const result = fieldValidate('***-***-****', fieldDetails);
|
|
84
|
+
expect(result.isError).toBe(true);
|
|
85
|
+
expect(result.message).toBe('crm.field.valid.check');
|
|
86
|
+
});
|
|
87
|
+
test('Validate valid integer', () => {
|
|
88
|
+
const fieldDetails = {
|
|
89
|
+
type: 'Number'
|
|
90
|
+
};
|
|
91
|
+
const result = fieldValidate(123, fieldDetails);
|
|
92
|
+
expect(result.isError).toBe(false);
|
|
93
|
+
});
|
|
94
|
+
test('Validate invalid integer', () => {
|
|
95
|
+
const fieldDetails = {
|
|
96
|
+
type: 'Number'
|
|
97
|
+
};
|
|
98
|
+
const result = fieldValidate('123.45', fieldDetails);
|
|
99
|
+
expect(result.isError).toBe(true);
|
|
100
|
+
expect(result.message).toBe('crm.field.valid.check');
|
|
101
|
+
});
|
|
102
|
+
test('Validate valid decimal', () => {
|
|
103
|
+
const fieldDetails = {
|
|
104
|
+
type: 'Decimal',
|
|
105
|
+
decimalPlaces: 2
|
|
106
|
+
}; // NOTE: as per formValidate.js, the decimalPlaces is must for Decimal Field
|
|
107
|
+
|
|
108
|
+
const result = fieldValidate(123.45, fieldDetails);
|
|
109
|
+
expect(result.isError).toBe(false);
|
|
110
|
+
});
|
|
111
|
+
test('Validate invalid decimal', () => {
|
|
112
|
+
const fieldDetails = {
|
|
113
|
+
type: 'Decimal'
|
|
114
|
+
};
|
|
115
|
+
const result = fieldValidate('invalid-decimal', fieldDetails);
|
|
116
|
+
expect(result.isError).toBe(true);
|
|
117
|
+
expect(result.message).toBe('crm.field.valid.check');
|
|
118
|
+
});
|
|
119
|
+
test('Validate valid date', () => {
|
|
120
|
+
const fieldDetails = {
|
|
121
|
+
type: 'Date'
|
|
122
|
+
};
|
|
123
|
+
const result = fieldValidate('2025-02-11T00:00:00Z', fieldDetails);
|
|
124
|
+
expect(result.isError).toBe(false);
|
|
125
|
+
});
|
|
126
|
+
test.skip('Validate invalid date', () => {
|
|
127
|
+
const fieldDetails = {
|
|
128
|
+
type: 'Date'
|
|
129
|
+
};
|
|
130
|
+
const result = fieldValidate('invalid-date', fieldDetails);
|
|
131
|
+
expect(result.isError).toBe(true);
|
|
132
|
+
expect(result.message).toBe('crm.field.valid.check');
|
|
133
|
+
});
|
|
134
|
+
test('Validate mandatory field', () => {
|
|
135
|
+
const fieldDetails = {
|
|
136
|
+
type: 'Text',
|
|
137
|
+
isMandatory: true
|
|
138
|
+
};
|
|
139
|
+
const result = fieldValidate('', fieldDetails);
|
|
140
|
+
expect(result.isError).toBe(true);
|
|
141
|
+
expect(result.message).toBe('crm.field.empty.check');
|
|
142
|
+
});
|
|
143
|
+
test('Validate field with max length', () => {
|
|
144
|
+
const fieldDetails = {
|
|
145
|
+
type: 'Text',
|
|
146
|
+
maxLength: 3
|
|
147
|
+
};
|
|
148
|
+
const result = fieldValidate('test', fieldDetails);
|
|
149
|
+
expect(result.isError).toBe(true);
|
|
150
|
+
expect(result.message).toBe('support.form.more.than.max.length');
|
|
151
|
+
});
|
|
152
|
+
test('Validate field with valid length', () => {
|
|
153
|
+
const fieldDetails = {
|
|
154
|
+
type: 'Text',
|
|
155
|
+
maxLength: 5
|
|
156
|
+
};
|
|
157
|
+
const result = fieldValidate('test', fieldDetails);
|
|
158
|
+
expect(result.isError).toBe(false);
|
|
159
|
+
});
|
|
160
|
+
test('Validate valid decimal places', () => {
|
|
161
|
+
const fieldDetails = {
|
|
162
|
+
type: 'Decimal',
|
|
163
|
+
decimalPlaces: 2
|
|
164
|
+
};
|
|
165
|
+
const result = fieldValidate(123.45, fieldDetails);
|
|
166
|
+
expect(result.isError).toBe(false);
|
|
167
|
+
});
|
|
168
|
+
test('Validate invalid decimal places', () => {
|
|
169
|
+
const fieldDetails = {
|
|
170
|
+
type: 'Decimal',
|
|
171
|
+
decimalPlaces: 2
|
|
172
|
+
};
|
|
173
|
+
const result = fieldValidate(123.456, fieldDetails);
|
|
174
|
+
expect(result.isError).toBe(true);
|
|
175
|
+
expect(result.message).toBe('support.form.decimal.places.length.error.message');
|
|
176
|
+
});
|
|
177
|
+
test('Validate empty multi-select', () => {
|
|
178
|
+
const fieldDetails = {
|
|
179
|
+
type: 'Multiselect',
|
|
180
|
+
isMandatory: true
|
|
181
|
+
};
|
|
182
|
+
const result = fieldValidate([], fieldDetails);
|
|
183
|
+
expect(result.isError).toBe(true);
|
|
184
|
+
expect(result.message).toBe('crm.field.empty.check');
|
|
185
|
+
});
|
|
186
|
+
test('Validate non-empty multi-select', () => {
|
|
187
|
+
const fieldDetails = {
|
|
188
|
+
type: 'Multiselect',
|
|
189
|
+
isMandatory: true
|
|
190
|
+
};
|
|
191
|
+
const result = fieldValidate(['item'], fieldDetails);
|
|
192
|
+
expect(result.isError).toBe(false);
|
|
193
|
+
});
|
|
194
|
+
test('Validate empty multi-select with -None- value', () => {
|
|
195
|
+
const fieldDetails = {
|
|
196
|
+
type: 'Multiselect',
|
|
197
|
+
isMandatory: true
|
|
198
|
+
};
|
|
199
|
+
const result = fieldValidate(['-None-'], fieldDetails);
|
|
200
|
+
expect(result.isError).toBe(true);
|
|
201
|
+
expect(result.message).toBe('crm.field.empty.check');
|
|
202
|
+
});
|
|
203
|
+
test('Validate non-empty multi-select with -None- value', () => {
|
|
204
|
+
const fieldDetails = {
|
|
205
|
+
type: 'Multiselect',
|
|
206
|
+
isMandatory: true
|
|
207
|
+
};
|
|
208
|
+
const result = fieldValidate(['item', '-None-'], fieldDetails);
|
|
209
|
+
expect(result.isError).toBe(false);
|
|
210
|
+
});
|
|
211
|
+
test('Validate empty picklist', () => {
|
|
212
|
+
const fieldDetails = {
|
|
213
|
+
type: 'Picklist',
|
|
214
|
+
isMandatory: true
|
|
215
|
+
};
|
|
216
|
+
const result = fieldValidate('', fieldDetails);
|
|
217
|
+
expect(result.isError).toBe(true);
|
|
218
|
+
expect(result.message).toBe('crm.field.empty.check');
|
|
219
|
+
});
|
|
220
|
+
test('Validate non-empty picklist', () => {
|
|
221
|
+
const fieldDetails = {
|
|
222
|
+
type: 'Picklist',
|
|
223
|
+
isMandatory: true
|
|
224
|
+
};
|
|
225
|
+
const result = fieldValidate('item', fieldDetails);
|
|
226
|
+
expect(result.isError).toBe(false);
|
|
227
|
+
});
|
|
228
|
+
test('Validate empty picklist with -None- value', () => {
|
|
229
|
+
const fieldDetails = {
|
|
230
|
+
type: 'Picklist',
|
|
231
|
+
isMandatory: true
|
|
232
|
+
};
|
|
233
|
+
const result = fieldValidate('-None-', fieldDetails);
|
|
234
|
+
expect(result.isError).toBe(true);
|
|
235
|
+
expect(result.message).toBe('crm.field.empty.check');
|
|
236
|
+
});
|
|
237
|
+
test('Validate non-empty picklist with -None- value', () => {
|
|
238
|
+
const fieldDetails = {
|
|
239
|
+
type: 'Picklist',
|
|
240
|
+
isMandatory: true
|
|
241
|
+
};
|
|
242
|
+
const result = fieldValidate('item', fieldDetails);
|
|
243
|
+
expect(result.isError).toBe(false);
|
|
244
|
+
});
|
|
245
|
+
test('Validate empty boolean field', () => {
|
|
246
|
+
const fieldDetails = {
|
|
247
|
+
type: 'Boolean',
|
|
248
|
+
isMandatory: true
|
|
249
|
+
};
|
|
250
|
+
const result = fieldValidate(false, fieldDetails);
|
|
251
|
+
expect(result.isError).toBe(true);
|
|
252
|
+
expect(result.message).toBe('crm.field.empty.check');
|
|
253
|
+
});
|
|
254
|
+
test('Validate valid website', () => {
|
|
255
|
+
const fieldDetails = {
|
|
256
|
+
type: 'URL'
|
|
257
|
+
};
|
|
258
|
+
const result = fieldValidate('htt' + 'p://example.com', fieldDetails);
|
|
259
|
+
expect(result.isError).toBe(false);
|
|
260
|
+
});
|
|
261
|
+
test.skip('Validate invalid website', () => {
|
|
262
|
+
const fieldDetails = {
|
|
263
|
+
type: 'URL'
|
|
264
|
+
};
|
|
265
|
+
const result = fieldValidate('invalid-url', fieldDetails);
|
|
266
|
+
expect(result.isError).toBe(true);
|
|
267
|
+
expect(result.message).toBe('crm.field.valid.check');
|
|
268
|
+
});
|
|
269
|
+
test('Validate valid URL', () => {
|
|
270
|
+
const fieldDetails = {
|
|
271
|
+
type: 'URL'
|
|
272
|
+
};
|
|
273
|
+
const result = fieldValidate('htt' + 'p://example.com', fieldDetails);
|
|
274
|
+
expect(result.isError).toBe(false);
|
|
275
|
+
});
|
|
276
|
+
test.skip('Validate invalid URL', () => {
|
|
277
|
+
const fieldDetails = {
|
|
278
|
+
type: 'URL'
|
|
279
|
+
};
|
|
280
|
+
const result = fieldValidate('invalid-url', fieldDetails);
|
|
281
|
+
expect(result.isError).toBe(true);
|
|
282
|
+
expect(result.message).toBe('crm.field.valid.check');
|
|
283
|
+
});
|
|
284
|
+
});
|