@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.
Files changed (145) hide show
  1. package/es/bc/field-validation/Constants.js +4 -0
  2. package/es/bc/field-validation/EventHandlers.js +1 -0
  3. package/es/bc/field-validation/Events.js +106 -0
  4. package/es/bc/field-validation/FieldTypes.js +20 -0
  5. package/es/bc/field-validation/Properties.js +11 -0
  6. package/es/bc/field-validation/index.js +5 -0
  7. package/es/cc/ephi-tag/Properties.js +1 -0
  8. package/es/cc/ephi-tag/index.js +1 -0
  9. package/es/cc/info-icon/Properties.js +10 -0
  10. package/es/cc/info-icon/index.js +1 -0
  11. package/es/{platform/app-context-behaviour → library/behaviours/field-validation}/adapters/controllers/AbstractController.js +4 -2
  12. package/es/library/behaviours/field-validation/adapters/controllers/ValidateFieldController.js +32 -0
  13. package/es/library/behaviours/field-validation/adapters/controllers/ValidateFieldsController.js +31 -0
  14. package/es/library/behaviours/field-validation/adapters/gateway/Repository.js +23 -0
  15. package/es/library/behaviours/field-validation/adapters/gateway/Service.js +18 -0
  16. package/es/library/behaviours/field-validation/applications/interfaces/input/FieldData.js +17 -0
  17. package/es/library/behaviours/field-validation/applications/usecases/AbstractUseCase.js +15 -0
  18. package/es/library/behaviours/field-validation/applications/usecases/ValidateField.js +29 -0
  19. package/es/library/behaviours/field-validation/applications/usecases/ValidateFields.js +28 -0
  20. package/es/library/behaviours/field-validation/domain/FieldValidation.js +94 -0
  21. package/es/library/behaviours/field-validation/domain/field-vise-validations/BooleanValidation.js +28 -0
  22. package/es/library/behaviours/field-validation/domain/field-vise-validations/CurrencyValidation.js +49 -0
  23. package/es/library/behaviours/field-validation/domain/field-vise-validations/DateTimeValidation.js +24 -0
  24. package/es/library/behaviours/field-validation/domain/field-vise-validations/DateValidation.js +24 -0
  25. package/es/library/behaviours/field-validation/domain/field-vise-validations/DecimalValidation.js +49 -0
  26. package/es/library/behaviours/field-validation/domain/field-vise-validations/EmailValidation.js +28 -0
  27. package/es/library/behaviours/field-validation/domain/field-vise-validations/IntegerValidation.js +39 -0
  28. package/es/library/behaviours/field-validation/domain/field-vise-validations/LookUpValidation.js +24 -0
  29. package/es/library/behaviours/field-validation/domain/field-vise-validations/MultiSelectValidation.js +26 -0
  30. package/es/library/behaviours/field-validation/domain/field-vise-validations/PercentValidation.js +28 -0
  31. package/es/library/behaviours/field-validation/domain/field-vise-validations/PhoneValidation.js +39 -0
  32. package/es/library/behaviours/field-validation/domain/field-vise-validations/PicklistValidation.js +24 -0
  33. package/es/library/behaviours/field-validation/domain/field-vise-validations/TextAreaValidation.js +39 -0
  34. package/es/library/behaviours/field-validation/domain/field-vise-validations/TextBoxValidation.js +39 -0
  35. package/es/library/behaviours/field-validation/domain/field-vise-validations/URLValidation.js +28 -0
  36. package/es/library/behaviours/field-validation/domain/interfaces/FieldTypes.js +20 -0
  37. package/es/library/behaviours/field-validation/domain/interfaces/ValidationsEnum.js +22 -0
  38. package/es/library/behaviours/field-validation/domain/interfaces/ValidationsMap.js +1 -0
  39. package/es/library/behaviours/field-validation/domain/interfaces/fields/IDateField.js +0 -0
  40. package/es/library/behaviours/field-validation/domain/interfaces/fields/IDateTimeField.js +0 -0
  41. package/es/library/behaviours/field-validation/domain/interfaces/fields/IDecimalField.js +0 -0
  42. package/es/library/behaviours/field-validation/domain/interfaces/fields/IEmailField.js +0 -0
  43. package/es/library/behaviours/field-validation/domain/interfaces/fields/IIntegerField.js +0 -0
  44. package/es/library/behaviours/field-validation/domain/interfaces/fields/ILookUpField.js +0 -0
  45. package/es/library/behaviours/field-validation/domain/interfaces/fields/IMultiSelectField.js +0 -0
  46. package/es/library/behaviours/field-validation/domain/interfaces/fields/IPercentField.js +0 -0
  47. package/es/library/behaviours/field-validation/domain/interfaces/fields/IPhoneField.js +0 -0
  48. package/es/library/behaviours/field-validation/domain/interfaces/fields/IPicklistField.js +0 -0
  49. package/es/library/behaviours/field-validation/domain/interfaces/fields/ITextAreaField.js +0 -0
  50. package/es/library/behaviours/field-validation/domain/interfaces/fields/ITextBoxField.js +0 -0
  51. package/es/library/behaviours/field-validation/domain/interfaces/fields/IURLField.js +0 -0
  52. package/es/library/behaviours/field-validation/frameworks/ui/EventHandlerFactory.js +23 -0
  53. package/es/library/behaviours/field-validation/frameworks/ui/FieldValidationBehaviourFactory.js +27 -0
  54. package/es/library/behaviours/field-validation/frameworks/ui/__tests__/BooleanFieldValidation.test.js +137 -0
  55. package/es/library/behaviours/field-validation/frameworks/ui/__tests__/CurrencyFieldValidation.test.js +228 -0
  56. package/es/library/behaviours/field-validation/frameworks/ui/__tests__/DateFieldValidation.test.js +108 -0
  57. package/es/library/behaviours/field-validation/frameworks/ui/__tests__/DateTimeFieldValidation.test.js +108 -0
  58. package/es/library/behaviours/field-validation/frameworks/ui/__tests__/DecimalFieldValidation.test.js +257 -0
  59. package/es/library/behaviours/field-validation/frameworks/ui/__tests__/EmailFieldValidation.test.js +139 -0
  60. package/es/library/behaviours/field-validation/frameworks/ui/__tests__/FieldValidationBehaviour.test.js +171 -0
  61. package/es/library/behaviours/field-validation/frameworks/ui/__tests__/IntegerFieldValidation.test.js +168 -0
  62. package/es/library/behaviours/field-validation/frameworks/ui/__tests__/LookUpFieldValidation.test.js +108 -0
  63. package/es/library/behaviours/field-validation/frameworks/ui/__tests__/MultiSelectFieldValidation.test.js +79 -0
  64. package/es/library/behaviours/field-validation/frameworks/ui/__tests__/PercentFieldValidation.test.js +108 -0
  65. package/es/library/behaviours/field-validation/frameworks/ui/__tests__/PhoneFieldValidation.test.js +168 -0
  66. package/es/library/behaviours/field-validation/frameworks/ui/__tests__/PicklistFieldValidation.test.js +79 -0
  67. package/es/library/behaviours/field-validation/frameworks/ui/__tests__/TextAreaFieldValidation.test.js +170 -0
  68. package/es/library/behaviours/field-validation/frameworks/ui/__tests__/TextBoxFieldValidation.test.js +170 -0
  69. package/es/library/behaviours/field-validation/frameworks/ui/__tests__/URLFieldValidation.test.js +108 -0
  70. package/es/library/behaviours/field-validation/frameworks/utils/FormBasicValidationAdaptor.js +228 -0
  71. package/es/library/behaviours/field-validation/frameworks/utils/__tests__/formValidate.test.js +284 -0
  72. package/es/library/behaviours/field-validation/frameworks/utils/formValidate.js +334 -0
  73. package/es/library/dot/components/form-fields/checkbox/adapters/presenter/TransformState.js +22 -0
  74. package/es/library/dot/components/form-fields/currency/adapters/presenter/TransformState.js +81 -0
  75. package/es/library/dot/components/form-fields/date/adapters/presenter/TransformState.js +22 -0
  76. package/es/library/dot/components/form-fields/datetime/adapters/presenter/TransformState.js +22 -0
  77. package/es/library/dot/components/form-fields/decimal/adapters/presenter/TransformState.js +31 -0
  78. package/es/library/dot/components/form-fields/email/adapters/presenter/TransformState.js +23 -0
  79. package/es/library/dot/components/form-fields/ephi-tag/frameworks/ui/EPHITag.js +10 -0
  80. package/es/library/dot/components/form-fields/ephi-tag/frameworks/ui/EPHITagView.js +21 -0
  81. package/es/library/dot/components/form-fields/ephi-tag/frameworks/ui/css/EPHITag.module.css +3 -0
  82. package/es/library/dot/components/form-fields/info-icon/frameworks/ui/InfoIcon.js +10 -0
  83. package/es/library/dot/components/form-fields/info-icon/frameworks/ui/InfoIconView.js +21 -0
  84. package/es/library/dot/components/form-fields/info-icon/frameworks/ui/css/InfoIcon.module.css +3 -0
  85. package/es/library/dot/components/form-fields/multi-select/adapters/presenter/TransformState.js +31 -0
  86. package/es/library/dot/components/form-fields/number/adapters/presenter/TransformState.js +31 -0
  87. package/es/library/dot/components/form-fields/percentage/adapters/presenter/TransformState.js +31 -0
  88. package/es/library/dot/components/form-fields/phone/adapters/presenter/TransformState.js +31 -0
  89. package/es/library/dot/components/form-fields/pick-list/adapters/presenter/TransformState.js +23 -0
  90. package/es/library/dot/components/form-fields/textarea/adapters/presenter/TransformState.js +23 -0
  91. package/es/library/dot/components/form-fields/textbox/adapters/presenter/TransformState.js +32 -0
  92. package/es/library/dot/components/form-fields/url/adapters/presenter/TransformState.js +31 -0
  93. package/es/library/dot/components/section/adapters/presenter/TransFormState.js +26 -0
  94. package/es/library/dot/legacy-to-new-arch/label/frameworks/ui/sub-components/ui/LabelAction.js +9 -0
  95. package/es/library/dot/legacy-to-new-arch/label/frameworks/ui/sub-components/ui/LabelActionView.js +38 -0
  96. package/es/library/dot/legacy-to-new-arch/label/frameworks/ui/sub-components/ui/css/LabelAction.module.css +4 -0
  97. package/es/platform/components/form-connected/adapters/resources/SmartFormResources.js +18 -0
  98. package/es/platform/components/form-connected/frameworks/FormSdkFactory.js +4 -2
  99. package/es/platform/zdata-source/domain/entities/APITemplate.js +2 -1
  100. package/es/platform/zform/adapters/controllers/ValidateErrorMessageController.js +22 -0
  101. package/es/platform/zform/applications/interfaces/input/GetIsFieldValueChangedUseCaseInput.js +1 -0
  102. package/es/platform/zform/applications/interfaces/input/ValidateErrorMessageInputModel.js +1 -0
  103. package/es/platform/zform/applications/usecases/GetIsFieldValueChanged.js +35 -0
  104. package/es/platform/zform/applications/usecases/ValidateErrorMessageUseCase.js +33 -0
  105. package/es/platform/zform/applications/usecases/ValidateFieldRequestUseCase.js +56 -0
  106. package/es/platform/zform/domain/ZField.js +4 -0
  107. package/package.json +1 -1
  108. package/es/bc/app-context/Event.js +0 -1
  109. package/es/bc/app-context/Properties.js +0 -58
  110. package/es/cc/component/ErrorStructure.js +0 -9
  111. package/es/cc/error-state/ErrorTypes.js +0 -11
  112. package/es/cc/error-state/Properties.js +0 -31
  113. package/es/cc/error-state/index.js +0 -2
  114. package/es/library/custom-component/domain/entities/ComponentProperties.js +0 -121
  115. package/es/library/custom-component/domain/entities/Logger.js +0 -63
  116. package/es/library/dot/legacy-to-new-arch/error-state/frameworks/ui/ErrorState.js +0 -10
  117. package/es/library/dot/legacy-to-new-arch/error-state/frameworks/ui/ErrorStateView.js +0 -68
  118. package/es/platform/app-context-behaviour/adapters/controllers/InitializeController.js +0 -19
  119. package/es/platform/app-context-behaviour/adapters/gateways/Service.js +0 -7
  120. package/es/platform/app-context-behaviour/adapters/presenters/Presenter.js +0 -18
  121. package/es/platform/app-context-behaviour/adapters/resources/AppResource.js +0 -25
  122. package/es/platform/app-context-behaviour/applications/AbstractUseCase.js +0 -6
  123. package/es/platform/app-context-behaviour/applications/usecases/InitializeUseCase.js +0 -15
  124. package/es/platform/app-context-behaviour/frameworks/AppContextBehaviourFactory.js +0 -31
  125. package/es/platform/app-context-behaviour/frameworks/EventHandlerFactory.js +0 -25
  126. package/es/platform/components/form-connected/frameworks/FallbackView.js +0 -23
  127. package/es/platform/data-source/http-template/getDependencyMappings.js +0 -18
  128. package/es/platform/data-source/http-template/getLayoutRules.js +0 -29
  129. package/es/platform/data-source/http-template/getMyForm.js +0 -19
  130. package/es/platform/data-source/http-template/getMyLayout.js +0 -43
  131. package/es/platform/data-source/http-template/getValidationRules.js +0 -30
  132. package/es/platform/zform/adapters/controllers/ApiFailureController.js +0 -31
  133. package/es/platform/zform/applications/usecases/ApiFailureUseCase.js +0 -30
  134. /package/es/{platform/app-context-behaviour/applications/interfaces/UsecaseDependencies.js → library/behaviours/field-validation/applications/interfaces/UseCaseDependencies.js} +0 -0
  135. /package/es/{platform/app-context-behaviour/applications/interfaces/gateways/IService.js → library/behaviours/field-validation/applications/interfaces/gateways/IRepository.js} +0 -0
  136. /package/es/{platform/app-context-behaviour/applications/interfaces/input/InitializeUseCaseInputModel.js → library/behaviours/field-validation/applications/interfaces/gateways/IService.js} +0 -0
  137. /package/es/{platform/app-context-behaviour/applications/interfaces/output/BehaviourState.js → library/behaviours/field-validation/applications/interfaces/input/FieldValidationInputModel.js} +0 -0
  138. /package/es/{platform/app-context-behaviour/applications/interfaces/output/IPresenter.js → library/behaviours/field-validation/applications/interfaces/input/ValidateFieldsInputModel.js} +0 -0
  139. /package/es/{bc/app-context/Constants.js → library/behaviours/field-validation/domain/interfaces/IField.js} +0 -0
  140. /package/es/{platform/app-context-behaviour/applications/interfaces/resources/ApiHeaderContract.js → library/behaviours/field-validation/domain/interfaces/IFieldValidation.js} +0 -0
  141. /package/es/{platform/app-context-behaviour/applications/interfaces/resources/ContextContract.js → library/behaviours/field-validation/domain/interfaces/IFieldViseValidation.js} +0 -0
  142. /package/es/{platform/app-context-behaviour/applications/interfaces/resources/IAppResource.js → library/behaviours/field-validation/domain/interfaces/ValidationResult.js} +0 -0
  143. /package/es/{platform/zform/applications/interfaces/input/ApiFailureInputModel.js → library/behaviours/field-validation/domain/interfaces/ValidationsArray.js} +0 -0
  144. /package/es/{bc/app-context/EventHandlers.js → library/behaviours/field-validation/domain/interfaces/fields/IBooleanField.js} +0 -0
  145. /package/es/library/{custom-component/domain/entities/interfaces/IComponentProperties.js → behaviours/field-validation/domain/interfaces/fields/ICurrencyField.js} +0 -0
@@ -0,0 +1,139 @@
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('Email 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 Email mandatory field and return error', () => {
21
+ const field = {
22
+ id: 'text',
23
+ type: FieldTypes.Email,
24
+ // type: "Text",
25
+ // mandatory: true
26
+ required: true
27
+ };
28
+ const event = {
29
+ state,
30
+ updateState,
31
+ action: {
32
+ type: VALIDATE_FIELD,
33
+ payload: {
34
+ field,
35
+ value: ''
36
+ }
37
+ },
38
+ dispatch
39
+ };
40
+ behaviour.eventHandlers[VALIDATE_FIELD](event);
41
+ expect(dispatch).toHaveBeenCalledWith({
42
+ type: FIELD_VALIDATION_RESULT,
43
+ payload: {
44
+ validationResult: {
45
+ isValid: false,
46
+ message: 'This field is required.'
47
+ },
48
+ field
49
+ }
50
+ });
51
+ });
52
+ it('should validate Email empty string and return true', () => {
53
+ const field = {
54
+ id: 'text',
55
+ type: FieldTypes.Email
56
+ };
57
+ const event = {
58
+ state,
59
+ updateState,
60
+ action: {
61
+ type: VALIDATE_FIELD,
62
+ payload: {
63
+ field,
64
+ value: ''
65
+ }
66
+ },
67
+ dispatch
68
+ };
69
+ behaviour.eventHandlers[VALIDATE_FIELD](event);
70
+ expect(dispatch).toHaveBeenCalledWith({
71
+ type: FIELD_VALIDATION_RESULT,
72
+ payload: {
73
+ validationResult: {
74
+ isValid: true,
75
+ message: ''
76
+ },
77
+ field
78
+ }
79
+ });
80
+ });
81
+ it('should validate valid email and return true', () => {
82
+ const field = {
83
+ id: 'email',
84
+ type: FieldTypes.Email
85
+ };
86
+ const event = {
87
+ state,
88
+ updateState,
89
+ action: {
90
+ type: VALIDATE_FIELD,
91
+ payload: {
92
+ field,
93
+ value: 'test@example.com'
94
+ }
95
+ },
96
+ dispatch
97
+ };
98
+ behaviour.eventHandlers[VALIDATE_FIELD](event);
99
+ expect(dispatch).toHaveBeenCalledWith({
100
+ type: FIELD_VALIDATION_RESULT,
101
+ payload: {
102
+ validationResult: {
103
+ isValid: true,
104
+ message: ''
105
+ },
106
+ field
107
+ }
108
+ });
109
+ });
110
+ it('should validate invalid email and return false', () => {
111
+ const field = {
112
+ id: 'email',
113
+ type: FieldTypes.Email
114
+ };
115
+ const event = {
116
+ state,
117
+ updateState,
118
+ action: {
119
+ type: VALIDATE_FIELD,
120
+ payload: {
121
+ field,
122
+ value: 'invalid-email'
123
+ }
124
+ },
125
+ dispatch
126
+ };
127
+ behaviour.eventHandlers[VALIDATE_FIELD](event);
128
+ expect(dispatch).toHaveBeenCalledWith({
129
+ type: FIELD_VALIDATION_RESULT,
130
+ payload: {
131
+ validationResult: {
132
+ isValid: false,
133
+ message: 'Invalid email format'
134
+ },
135
+ field
136
+ }
137
+ });
138
+ });
139
+ });
@@ -0,0 +1,171 @@
1
+ import FieldValidationBehaviourFactory from "../FieldValidationBehaviourFactory";
2
+ import ValidationsEnum from "../../../domain/interfaces/ValidationsEnum";
3
+ import { VALIDATE_FIELD, FIELD_VALIDATION_RESULT } from "../../../../../../bc/field-validation/Constants";
4
+ import FieldTypes from "../../../../../../bc/field-validation/FieldTypes";
5
+ describe('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
+ [ValidationsEnum.mandatory]: value => {
16
+ if (!value) {
17
+ return {
18
+ isValid: false,
19
+ message: 'This field is required'
20
+ };
21
+ }
22
+
23
+ return {
24
+ isValid: true,
25
+ message: ''
26
+ };
27
+ },
28
+ [ValidationsEnum.email]: value => {
29
+ if (!value.includes('@')) {
30
+ return {
31
+ isValid: false,
32
+ message: 'Invalid email format'
33
+ };
34
+ }
35
+
36
+ return {
37
+ isValid: true,
38
+ message: ''
39
+ };
40
+ }
41
+ }
42
+ }
43
+ };
44
+ updateState = jest.fn();
45
+ dispatch = jest.fn();
46
+ });
47
+ it('should validate field and dispatch result with errors for invalid input', () => {
48
+ const field = {
49
+ id: 'email',
50
+ type: FieldTypes.Email
51
+ };
52
+ const event = {
53
+ state,
54
+ updateState,
55
+ action: {
56
+ type: VALIDATE_FIELD,
57
+ payload: {
58
+ field,
59
+ value: 'invalid-email'
60
+ }
61
+ },
62
+ dispatch
63
+ };
64
+ behaviour.eventHandlers[VALIDATE_FIELD](event);
65
+ expect(dispatch).toHaveBeenCalledWith({
66
+ type: FIELD_VALIDATION_RESULT,
67
+ payload: {
68
+ validationResult: {
69
+ isValid: false,
70
+ message: 'Invalid email format'
71
+ },
72
+ field
73
+ }
74
+ });
75
+ });
76
+ it('should validate field and dispatch result with no errors for valid input', () => {
77
+ const field = {
78
+ id: 'email',
79
+ type: FieldTypes.Email
80
+ };
81
+ const event = {
82
+ state,
83
+ updateState,
84
+ action: {
85
+ type: VALIDATE_FIELD,
86
+ payload: {
87
+ field,
88
+ value: 'test@email.com'
89
+ }
90
+ },
91
+ dispatch
92
+ };
93
+ behaviour.eventHandlers[VALIDATE_FIELD](event);
94
+ expect(dispatch).toHaveBeenCalledWith({
95
+ type: FIELD_VALIDATION_RESULT,
96
+ payload: {
97
+ validationResult: {
98
+ isValid: true,
99
+ message: ''
100
+ },
101
+ field
102
+ }
103
+ });
104
+ });
105
+ it('should return same reference metadata dispatch with result when errors for invalid input', () => {
106
+ const metadata = {};
107
+ const field = {
108
+ id: 'email',
109
+ type: FieldTypes.Email
110
+ };
111
+ const event = {
112
+ state,
113
+ updateState,
114
+ action: {
115
+ type: VALIDATE_FIELD,
116
+ payload: {
117
+ field,
118
+ value: 'invalid-email'
119
+ },
120
+ metadata
121
+ },
122
+ dispatch
123
+ };
124
+ behaviour.eventHandlers[VALIDATE_FIELD](event);
125
+ expect(dispatch).toHaveBeenCalledWith({
126
+ type: FIELD_VALIDATION_RESULT,
127
+ payload: {
128
+ validationResult: {
129
+ isValid: false,
130
+ message: 'Invalid email format'
131
+ },
132
+ field
133
+ },
134
+ metadata
135
+ });
136
+ expect(dispatch.mock.calls[0][0].metadata).toBe(metadata);
137
+ });
138
+ it('should return same reference metadata dispatch with result when no errors for valid input', () => {
139
+ const metadata = {};
140
+ const field = {
141
+ id: 'email',
142
+ type: FieldTypes.Email
143
+ };
144
+ const event = {
145
+ state,
146
+ updateState,
147
+ action: {
148
+ type: VALIDATE_FIELD,
149
+ payload: {
150
+ field,
151
+ value: 'test@email.com'
152
+ },
153
+ metadata
154
+ },
155
+ dispatch
156
+ };
157
+ behaviour.eventHandlers[VALIDATE_FIELD](event);
158
+ expect(dispatch).toHaveBeenCalledWith({
159
+ type: FIELD_VALIDATION_RESULT,
160
+ payload: {
161
+ validationResult: {
162
+ isValid: true,
163
+ message: ''
164
+ },
165
+ field
166
+ },
167
+ metadata
168
+ });
169
+ expect(dispatch.mock.calls[0][0].metadata).toBe(metadata);
170
+ });
171
+ });
@@ -0,0 +1,168 @@
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('Integer 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 Integer mandatory field and return error', () => {
21
+ const field = {
22
+ id: 'integer',
23
+ type: FieldTypes.Integer,
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 integer and return true', () => {
51
+ const field = {
52
+ id: 'integer',
53
+ type: FieldTypes.Integer
54
+ };
55
+ const event = {
56
+ state,
57
+ updateState,
58
+ action: {
59
+ type: VALIDATE_FIELD,
60
+ payload: {
61
+ field,
62
+ value: '123'
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
+ it('should validate invalid integer and return false', () => {
80
+ const field = {
81
+ id: 'integer',
82
+ type: FieldTypes.Integer
83
+ };
84
+ const event = {
85
+ state,
86
+ updateState,
87
+ action: {
88
+ type: VALIDATE_FIELD,
89
+ payload: {
90
+ field,
91
+ value: '123.45'
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 integer format'
103
+ },
104
+ field
105
+ }
106
+ });
107
+ });
108
+ it('should validate Integer field with valid max length and return no error', () => {
109
+ const field = {
110
+ id: 'integer',
111
+ type: FieldTypes.Integer,
112
+ maxLength: 10
113
+ };
114
+ const event = {
115
+ state,
116
+ updateState,
117
+ action: {
118
+ type: VALIDATE_FIELD,
119
+ payload: {
120
+ field,
121
+ value: '100234'
122
+ }
123
+ },
124
+ dispatch
125
+ };
126
+ behaviour.eventHandlers[VALIDATE_FIELD](event);
127
+ expect(dispatch).toHaveBeenCalledWith({
128
+ type: FIELD_VALIDATION_RESULT,
129
+ payload: {
130
+ validationResult: {
131
+ isValid: true,
132
+ message: ''
133
+ },
134
+ field
135
+ }
136
+ });
137
+ });
138
+ it('should validate Integer field with invalid max length and return error', () => {
139
+ const field = {
140
+ id: 'integer',
141
+ type: FieldTypes.Integer,
142
+ maxLength: 10
143
+ };
144
+ const event = {
145
+ state,
146
+ updateState,
147
+ action: {
148
+ type: VALIDATE_FIELD,
149
+ payload: {
150
+ field,
151
+ value: '192929292978'
152
+ }
153
+ },
154
+ dispatch
155
+ };
156
+ behaviour.eventHandlers[VALIDATE_FIELD](event);
157
+ expect(dispatch).toHaveBeenCalledWith({
158
+ type: FIELD_VALIDATION_RESULT,
159
+ payload: {
160
+ validationResult: {
161
+ isValid: false,
162
+ message: 'Field exceeds max length'
163
+ },
164
+ field
165
+ }
166
+ });
167
+ });
168
+ });
@@ -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('LookUp 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 LookUp mandatory field and return error', () => {
21
+ const field = {
22
+ id: 'lookup',
23
+ type: FieldTypes.LookUp,
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 be valid LookUp when value is selected and return true', () => {
51
+ const field = {
52
+ id: 'lookup',
53
+ type: FieldTypes.LookUp
54
+ };
55
+ const event = {
56
+ state,
57
+ updateState,
58
+ action: {
59
+ type: VALIDATE_FIELD,
60
+ payload: {
61
+ field,
62
+ value: 'selectedValue'
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 LookUp and return false', () => {
80
+ const field = {
81
+ id: 'lookup',
82
+ type: FieldTypes.LookUp
83
+ };
84
+ const event = {
85
+ state,
86
+ updateState,
87
+ action: {
88
+ type: VALIDATE_FIELD,
89
+ payload: {
90
+ field,
91
+ value: 'invalid'
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 LookUp format'
103
+ },
104
+ field
105
+ }
106
+ });
107
+ });
108
+ });
@@ -0,0 +1,79 @@
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('MultiSelect 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 MultiSelect mandatory field and return error', () => {
21
+ const field = {
22
+ id: 'multiSelect',
23
+ type: FieldTypes.MultiSelect,
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 MultiSelect and return true', () => {
51
+ const field = {
52
+ id: 'multiSelect',
53
+ type: FieldTypes.MultiSelect
54
+ };
55
+ const event = {
56
+ state,
57
+ updateState,
58
+ action: {
59
+ type: VALIDATE_FIELD,
60
+ payload: {
61
+ field,
62
+ value: ['option1', 'option2']
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
+ });