@sankhyalabs/core 5.20.0-dev.8 → 5.20.0-dev.81

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 (208) hide show
  1. package/.docs/classes/Base64Utils.md +39 -0
  2. package/.docs/classes/Change.md +11 -11
  3. package/.docs/classes/ColumnFilterManager.md +145 -0
  4. package/.docs/classes/DataUnit.md +429 -139
  5. package/.docs/classes/DataUnitInMemoryLoader.md +303 -0
  6. package/.docs/classes/DataUnitLoaderUtils.md +151 -0
  7. package/.docs/classes/DateUtils.md +8 -8
  8. package/.docs/classes/FieldComparator.md +2 -2
  9. package/.docs/classes/IDBRepository.md +22 -0
  10. package/.docs/classes/KeyboardManager.md +99 -9
  11. package/.docs/classes/LockManager.md +249 -0
  12. package/.docs/classes/MaskFormatter.md +66 -14
  13. package/.docs/classes/ObjectUtils.md +189 -0
  14. package/.docs/classes/OverflowWatcher.md +533 -0
  15. package/.docs/classes/SelectionInfo.md +25 -11
  16. package/.docs/classes/ServiceCanceledException.md +193 -0
  17. package/.docs/classes/ServiceUtils.md +67 -0
  18. package/.docs/classes/SilentException.md +193 -0
  19. package/.docs/classes/StringUtils.md +33 -9
  20. package/.docs/classes/UserAgentUtils.md +15 -1
  21. package/.docs/enumerations/Action.md +41 -21
  22. package/.docs/enumerations/ChangeOperation.md +4 -4
  23. package/.docs/enumerations/LockManagerOperation.md +33 -0
  24. package/.docs/enumerations/OverflowDirection.md +29 -0
  25. package/.docs/enumerations/RECORD_DATE_FORMAT.md +27 -0
  26. package/.docs/enumerations/SelectionMode.md +2 -2
  27. package/.docs/enumerations/StorageType.md +37 -0
  28. package/.docs/enumerations/UserInterface.md +15 -5
  29. package/.docs/globals.md +25 -0
  30. package/.docs/interfaces/DUActionInterceptor.md +1 -1
  31. package/.docs/interfaces/DataUnitInMemoryLoaderConfig.md +37 -0
  32. package/.docs/interfaces/IRepository.md +18 -0
  33. package/.docs/interfaces/LoadDataRequest.md +1 -1
  34. package/.docs/interfaces/OverFlowWatcherParams.md +67 -0
  35. package/.docs/interfaces/PageRequest.md +3 -3
  36. package/.docs/interfaces/PaginationInfo.md +25 -0
  37. package/.docs/interfaces/PaginationInfoBuilderParams.md +37 -0
  38. package/.docs/interfaces/QuickFilter.md +3 -3
  39. package/.docs/interfaces/Record.md +4 -4
  40. package/.docs/interfaces/SavedRecord.md +5 -5
  41. package/.docs/interfaces/WaitingChange.md +3 -3
  42. package/.docs/namespaces/MaskFormatter/type-aliases/MaskCharacter.md +1 -1
  43. package/.docs/namespaces/MaskFormatter/variables/MaskCharacter.md +1 -1
  44. package/.docs/type-aliases/DataUnitEventOptions.md +17 -0
  45. package/.docs/type-aliases/OnOverflowCallBack.md +25 -0
  46. package/.docs/variables/OVERFLOWED_CLASS_NAME.md +13 -0
  47. package/.releaserc +1 -0
  48. package/bun.lockb +0 -0
  49. package/dist/dataunit/DataUnit.d.ts +92 -13
  50. package/dist/dataunit/DataUnit.js +227 -71
  51. package/dist/dataunit/DataUnit.js.map +1 -1
  52. package/dist/dataunit/DataUnitHelper.js +6 -5
  53. package/dist/dataunit/DataUnitHelper.js.map +1 -1
  54. package/dist/dataunit/formatting/PrettyFormatter.js +17 -6
  55. package/dist/dataunit/formatting/PrettyFormatter.js.map +1 -1
  56. package/dist/dataunit/loader/DataUnitInMemoryLoaderConfig.d.ts +9 -0
  57. package/dist/dataunit/loader/DataUnitInMemoryLoaderConfig.js +6 -0
  58. package/dist/dataunit/loader/DataUnitInMemoryLoaderConfig.js.map +1 -0
  59. package/dist/dataunit/loader/dataUnitInMemoryLoader.d.ts +25 -0
  60. package/dist/dataunit/loader/dataUnitInMemoryLoader.js +131 -0
  61. package/dist/dataunit/loader/dataUnitInMemoryLoader.js.map +1 -0
  62. package/dist/dataunit/loader/utils/dataUnitLoaderUtils.d.ts +20 -0
  63. package/dist/dataunit/loader/utils/dataUnitLoaderUtils.js +62 -0
  64. package/dist/dataunit/loader/utils/dataUnitLoaderUtils.js.map +1 -0
  65. package/dist/dataunit/loading/LoadDataRequest.d.ts +1 -1
  66. package/dist/dataunit/loading/PaginationInfo.d.ts +8 -0
  67. package/dist/dataunit/metadata/DataType.js +7 -1
  68. package/dist/dataunit/metadata/DataType.js.map +1 -1
  69. package/dist/dataunit/metadata/UnitMetadata.d.ts +1 -0
  70. package/dist/dataunit/metadata/UnitMetadata.js +1 -0
  71. package/dist/dataunit/metadata/UnitMetadata.js.map +1 -1
  72. package/dist/dataunit/sorting/FieldComparator.d.ts +2 -2
  73. package/dist/dataunit/sorting/FieldComparator.js +4 -9
  74. package/dist/dataunit/sorting/FieldComparator.js.map +1 -1
  75. package/dist/dataunit/state/action/DataUnitAction.d.ts +2 -0
  76. package/dist/dataunit/state/action/DataUnitAction.js +2 -0
  77. package/dist/dataunit/state/action/DataUnitAction.js.map +1 -1
  78. package/dist/dataunit/state/slice/LoadingControlSlice.js +16 -0
  79. package/dist/dataunit/state/slice/LoadingControlSlice.js.map +1 -1
  80. package/dist/dataunit/state/slice/RecordsSlice.js +1 -1
  81. package/dist/dataunit/state/slice/RecordsSlice.js.map +1 -1
  82. package/dist/dataunit/state/slice/SelectionSlice.js +4 -4
  83. package/dist/dataunit/state/slice/SelectionSlice.js.map +1 -1
  84. package/dist/exceptions/ServiceCanceledException.d.ts +14 -0
  85. package/dist/exceptions/ServiceCanceledException.js +13 -0
  86. package/dist/exceptions/ServiceCanceledException.js.map +1 -0
  87. package/dist/exceptions/SilentException.d.ts +14 -0
  88. package/dist/exceptions/SilentException.js +13 -0
  89. package/dist/exceptions/SilentException.js.map +1 -0
  90. package/dist/index.d.ts +13 -2
  91. package/dist/index.js +12 -1
  92. package/dist/index.js.map +1 -1
  93. package/dist/repository/IRepository.d.ts +6 -0
  94. package/dist/repository/indexeddb/IDBRepository.d.ts +1 -0
  95. package/dist/repository/indexeddb/IDBRepository.js +3 -0
  96. package/dist/repository/indexeddb/IDBRepository.js.map +1 -1
  97. package/dist/utils/Base64Utils.d.ts +7 -0
  98. package/dist/utils/Base64Utils.js +13 -0
  99. package/dist/utils/Base64Utils.js.map +1 -0
  100. package/dist/utils/CacheManager/index.d.ts +52 -0
  101. package/dist/utils/CacheManager/index.js +101 -0
  102. package/dist/utils/CacheManager/index.js.map +1 -0
  103. package/dist/utils/CacheManager/interfaces/index.d.ts +5 -0
  104. package/dist/utils/CacheManager/interfaces/index.js +7 -0
  105. package/dist/utils/CacheManager/interfaces/index.js.map +1 -0
  106. package/dist/utils/ColumnFilterManager.d.ts +19 -0
  107. package/dist/utils/ColumnFilterManager.js +73 -0
  108. package/dist/utils/ColumnFilterManager.js.map +1 -0
  109. package/dist/utils/DateUtils.js +3 -0
  110. package/dist/utils/DateUtils.js.map +1 -1
  111. package/dist/utils/ElementUtils.d.ts +2 -0
  112. package/dist/utils/ElementUtils.js +9 -0
  113. package/dist/utils/ElementUtils.js.map +1 -0
  114. package/dist/utils/KeyboardManager/index.d.ts +9 -0
  115. package/dist/utils/KeyboardManager/index.js +45 -1
  116. package/dist/utils/KeyboardManager/index.js.map +1 -1
  117. package/dist/utils/KeyboardManager/interface.d.ts +1 -0
  118. package/dist/utils/LockManager.d.ts +58 -0
  119. package/dist/utils/LockManager.js +188 -0
  120. package/dist/utils/LockManager.js.map +1 -0
  121. package/dist/utils/MaskFormatter.d.ts +16 -1
  122. package/dist/utils/MaskFormatter.js +82 -2
  123. package/dist/utils/MaskFormatter.js.map +1 -1
  124. package/dist/utils/ObjectUtils.d.ts +52 -0
  125. package/dist/utils/ObjectUtils.js +71 -0
  126. package/dist/utils/ObjectUtils.js.map +1 -1
  127. package/dist/utils/OnboardingUtils.js +1 -1
  128. package/dist/utils/OnboardingUtils.js.map +1 -1
  129. package/dist/utils/OverflowWatcher/index.d.ts +59 -0
  130. package/dist/utils/OverflowWatcher/index.js +188 -0
  131. package/dist/utils/OverflowWatcher/index.js.map +1 -0
  132. package/dist/utils/OverflowWatcher/types/overflow-callback.d.ts +6 -0
  133. package/dist/utils/OverflowWatcher/types/overflow-callback.js +2 -0
  134. package/dist/utils/OverflowWatcher/types/overflow-callback.js.map +1 -0
  135. package/dist/utils/OverflowWatcher/types/overflow-direction.d.ts +7 -0
  136. package/dist/utils/OverflowWatcher/types/overflow-direction.js +9 -0
  137. package/dist/utils/OverflowWatcher/types/overflow-direction.js.map +1 -0
  138. package/dist/utils/ServiceUtils.d.ts +24 -0
  139. package/dist/utils/ServiceUtils.js +40 -0
  140. package/dist/utils/ServiceUtils.js.map +1 -0
  141. package/dist/utils/SortingUtils.d.ts +9 -0
  142. package/dist/utils/SortingUtils.js +24 -0
  143. package/dist/utils/SortingUtils.js.map +1 -0
  144. package/dist/utils/StringUtils.d.ts +6 -0
  145. package/dist/utils/StringUtils.js +23 -6
  146. package/dist/utils/StringUtils.js.map +1 -1
  147. package/dist/utils/UserAgentUtils/index.d.ts +1 -0
  148. package/dist/utils/UserAgentUtils/index.js +5 -0
  149. package/dist/utils/UserAgentUtils/index.js.map +1 -1
  150. package/jest.config.ts +2 -0
  151. package/package.json +2 -1
  152. package/reports/test-report.xml +760 -0
  153. package/setupTests.js +7 -0
  154. package/sonar-project.properties +6 -3
  155. package/src/dataunit/DataUnit.ts +278 -86
  156. package/src/dataunit/DataUnitHelper.ts +6 -5
  157. package/src/dataunit/formatting/PrettyFormatter.ts +19 -6
  158. package/src/dataunit/loader/DataUnitInMemoryLoaderConfig.ts +10 -0
  159. package/src/dataunit/loader/dataUnitInMemoryLoader.ts +176 -0
  160. package/src/dataunit/loader/utils/dataUnitLoaderUtils.ts +86 -0
  161. package/src/dataunit/loading/LoadDataRequest.ts +1 -1
  162. package/src/dataunit/loading/PaginationInfo.ts +10 -0
  163. package/src/dataunit/metadata/DataType.ts +8 -1
  164. package/src/dataunit/metadata/UnitMetadata.ts +1 -0
  165. package/src/dataunit/sorting/FieldComparator.ts +18 -32
  166. package/src/dataunit/state/action/DataUnitAction.ts +2 -0
  167. package/src/dataunit/state/slice/LoadingControlSlice.ts +42 -0
  168. package/src/dataunit/state/slice/RecordsSlice.ts +1 -1
  169. package/src/dataunit/state/slice/SelectionSlice.ts +4 -4
  170. package/src/dataunit/state/slice/test/RecordsSlice.spec.ts +45 -0
  171. package/src/dataunit/test/DataUnit.spec.ts +44 -0
  172. package/src/exceptions/ServiceCanceledException.ts +25 -0
  173. package/src/exceptions/SilentException.ts +25 -0
  174. package/src/index.ts +32 -1
  175. package/src/repository/IRepository.ts +7 -0
  176. package/src/repository/indexeddb/IDBRepository.ts +4 -0
  177. package/src/utils/Base64Utils.ts +13 -0
  178. package/src/utils/CacheManager/index.ts +103 -0
  179. package/src/utils/CacheManager/interfaces/index.ts +5 -0
  180. package/src/utils/ColumnFilterManager.ts +104 -0
  181. package/src/utils/DateUtils.ts +3 -0
  182. package/src/utils/ElementUtils.ts +10 -0
  183. package/src/utils/KeyboardManager/index.ts +57 -0
  184. package/src/utils/KeyboardManager/interface.ts +1 -0
  185. package/src/utils/LockManager.ts +207 -0
  186. package/src/utils/MaskFormatter.ts +93 -2
  187. package/src/utils/ObjectUtils.ts +77 -0
  188. package/src/utils/OnboardingUtils.ts +1 -1
  189. package/src/utils/OverflowWatcher/index.ts +243 -0
  190. package/src/utils/OverflowWatcher/types/overflow-callback.ts +6 -0
  191. package/src/utils/OverflowWatcher/types/overflow-direction.ts +7 -0
  192. package/src/utils/ServiceUtils.ts +36 -0
  193. package/src/utils/SortingUtils.ts +30 -0
  194. package/src/utils/StringUtils.ts +23 -6
  195. package/src/utils/UserAgentUtils/index.ts +6 -1
  196. package/test/dataunit/formatting/PrettyFormatter.spec.ts +177 -0
  197. package/test/dataunit/loader/dataUnitInMemoryLoader.spec.ts +221 -0
  198. package/test/dataunit/loader/utils/dataUnitLoaderUtils.spec.ts +158 -0
  199. package/test/testCases/NumberUtilsTestCases.ts +190 -0
  200. package/test/testCases/StringUtilsTestCases.ts +435 -0
  201. package/test/testCases/TimeFormatterTestUtils.ts +43 -0
  202. package/test/util/ColumnFilterManager.spec.ts +133 -0
  203. package/test/util/ElementUtils.spec.ts +34 -0
  204. package/test/util/NumberUtils.spec.ts +72 -150
  205. package/test/util/ObjectUtils.spec.ts +572 -0
  206. package/test/util/OverflowWatcher.spec.ts +152 -0
  207. package/test/util/StringUtils.spec.ts +260 -36
  208. package/test/util/TimeFormatter.spec.ts +65 -18
@@ -0,0 +1,34 @@
1
+ import { calcMarginSize } from '../../src/utils/ElementUtils';
2
+ import { OverflowDirection } from '../../src';
3
+
4
+ describe('calcMarginSize', () => {
5
+ it('should calculate correctly the size of horizontal margin', () => {
6
+ const element = document.createElement('div');
7
+ element.style.marginLeft = '10px';
8
+ element.style.marginRight = '15px';
9
+ document.body.appendChild(element);
10
+
11
+ const size = calcMarginSize(element, OverflowDirection.HORIZONTAL);
12
+ expect(size).toBe(25);
13
+ });
14
+
15
+ it('should calculate correctly the size of vertical margin', () => {
16
+ const element = document.createElement('div');
17
+ element.style.marginTop = '5px';
18
+ element.style.marginBottom = '20px';
19
+ document.body.appendChild(element);
20
+
21
+ const size = calcMarginSize(element, OverflowDirection.VERTICAL);
22
+ expect(size).toBe(25);
23
+ });
24
+
25
+ it('should threat values defined as zero', () => {
26
+ const element = document.createElement('div');
27
+ document.body.appendChild(element);
28
+
29
+ const horizontalSize = calcMarginSize(element, OverflowDirection.HORIZONTAL);
30
+ const verticalSize = calcMarginSize(element, OverflowDirection.VERTICAL);
31
+ expect(horizontalSize).toBe(0);
32
+ expect(verticalSize).toBe(0);
33
+ });
34
+ });
@@ -1,182 +1,104 @@
1
1
  import { NumberUtils } from '../../src/utils/NumberUtils';
2
-
3
- describe('StringUtils', function () {
4
-
5
-
6
- // => STRING_TO_NUMBER
7
- // ----------------------------------------------------------------------------------------
8
-
9
- const arrayDataTest = [
10
- { valueInput: '100', valueOutput: 100 },
11
- { valueInput: '100,12', valueOutput: 100.12 },
12
- { valueInput: '11500,12', valueOutput: 11500.12 },
13
- { valueInput: '11500', valueOutput: 11500 },
14
- { valueInput: '1.000', valueOutput: 1 },
15
- { valueInput: '11.500,003', valueOutput: 11500.003 },
16
- { valueInput: '-100', valueOutput: -100 },
17
- { valueInput: '-100,12', valueOutput: -100.12 },
18
- { valueInput: '-11500,1', valueOutput: -11500.1 },
19
- { valueInput: '-11500', valueOutput: -11500 },
20
- { valueInput: '-11.500,003', valueOutput: -11500.003 },
21
- { valueInput: 'R$100', valueOutput: 100 },
22
- { valueInput: 'R$100,12', valueOutput: 100.12 },
23
- { valueInput: 'R$11500,12', valueOutput: 11500.12 },
24
- { valueInput: 'R$11500', valueOutput: 11500 },
25
- { valueInput: 'R$11.500,003', valueOutput: 11500.003 },
26
- { valueInput: '-R$100', valueOutput: -100 },
27
- { valueInput: '-R$100,12', valueOutput: -100.12 },
28
- { valueInput: '-R$11500,12', valueOutput: -11500.12 },
29
- { valueInput: '-R$11500', valueOutput: -11500 },
30
- { valueInput: '-R$11.500,003', valueOutput: -11500.003 },
31
- { valueInput: '', valueOutput: NaN },
32
- { valueInput: 'OrdinaryString', valueOutput: NaN },
33
- { valueInput: '100.167.80', valueOutput: NaN },
34
- { valueInput: 'uahsuhas,auhsuhasu', valueOutput: NaN },
35
- { valueInput: '100,100,100', valueOutput: NaN },
36
- { valueInput: 'OrdinaryString,.OrdinaryString', valueOutput: NaN },
37
- { valueInput: 'OrdinaryString.,OrdinaryString', valueOutput: NaN },
38
- { valueInput: '.121212', valueOutput: 0.121212 },
39
- { valueInput: ',121212', valueOutput: 0.121212 },
40
- { valueInput: '1,232,333.345', valueOutput: NaN },
41
- { valueInput: '1232333,345', valueOutput: 1232333.345 },
42
- ]
43
-
44
- it('stringToNumber', function () {
45
- let result: number;
46
- arrayDataTest.forEach(e => {
47
- result = NumberUtils.stringToNumber(e.valueInput);
48
- expect(result).toBe(e.valueOutput);
49
- })
50
- });
51
-
52
-
2
+ import {
3
+ changeFormatCases,
4
+ formatCases,
5
+ safeFormatCases,
6
+ keepOnlyDecimalSeparatorCases,
7
+ roundTestCases,
8
+ stringToNumberCases,
9
+ getValueOrDefaultCases,
10
+ getValueOrZeroCases,
11
+ compareCases,
12
+ } from '../testCases/NumberUtilsTestCases';
53
13
 
54
14
 
55
- // FORMAT
56
- // ----------------------------------------------------------------------------------------
15
+ describe('NumberUtils', function() {
57
16
 
17
+ describe('stringToNumber', () => {
58
18
 
59
- const casesStrValue = [
19
+ stringToNumberCases.forEach(e => {
20
+ it(`should return ${e.valueOutput} when value is ${e.valueInput}`, () => {
21
+ expect(NumberUtils.stringToNumber(e.valueInput)).toBe(e.valueOutput);
22
+ });
23
+ });
60
24
 
61
- { precision: 4, prettyprecision: 2, strvalue: '1.200.999,3333', strvalueOutPut: '1.200.999,3333' },
62
- { precision: 2, prettyprecision: 1, strvalue: '1.000', strvalueOutPut: '1,0' },
63
- { precision: 2, prettyprecision: 1, strvalue: '1200999,99', strvalueOutPut: '1.200.999,99' },
64
- { precision: 4, prettyprecision: 2, strvalue: '1,232,333.345', strvalueOutPut: 'NaN' },
65
- { precision: 2, prettyprecision: 1, strvalue: '1,23', strvalueOutPut: '1,23' },
66
- { precision: 4, prettyprecision: 2, strvalue: '1.200.999', strvalueOutPut: 'NaN' },
67
- { precision: 4, prettyprecision: 0, strvalue: '1200.00001', strvalueOutPut: '1.200' },
68
- { precision: 4, prettyprecision: 0, strvalue: 'String', strvalueOutPut: 'NaN' },
69
- { precision: 4, prettyprecision: 0, strvalue: '', strvalueOutPut: 'NaN' },
70
-
71
- { precision: 4, prettyprecision: undefined, strvalue: '1.200.999,3333', strvalueOutPut: '1.200.999,3333' },
72
- { precision: 2, prettyprecision: undefined, strvalue: '1.000', strvalueOutPut: '1,00' },
73
- { precision: 2, prettyprecision: undefined, strvalue: '1200999,99', strvalueOutPut: '1.200.999,99' },
74
- { precision: 4, prettyprecision: undefined, strvalue: '1,232,333.345', strvalueOutPut: 'NaN' },
75
- { precision: 2, prettyprecision: undefined, strvalue: '1,23', strvalueOutPut: '1,23' },
76
- { precision: 4, prettyprecision: undefined, strvalue: '1.200.999', strvalueOutPut: 'NaN' },
77
- { precision: 4, prettyprecision: undefined, strvalue: 'NaN', strvalueOutPut: 'NaN' },
78
-
79
-
80
- { precision: 1, prettyprecision: -1, strvalue: '111,199', strvalueOutPut: '111,2' },
81
- { precision: 1, prettyprecision: -1, strvalue: '111,1000', strvalueOutPut: '111,1' },
82
- { precision: 1, prettyprecision: 1.3, strvalue: '111,100', strvalueOutPut: '111,1' },
83
- { precision: -1, prettyprecision: 1, strvalue: '111,1009', strvalueOutPut: '111,1009' },
84
- { precision: -1, prettyprecision: 1, strvalue: '111,1000', strvalueOutPut: '111,1' },
85
- { precision: 1.2, prettyprecision: 1, strvalue: '111,1009', strvalueOutPut: '111,1009' },
25
+ });
86
26
 
87
27
 
88
- { precision: 2, prettyprecision: -1, strvalue: '111,199', strvalueOutPut: '111,20' },
89
- { precision: 2, prettyprecision: -1, strvalue: '111,1000', strvalueOutPut: '111,10' },
90
- { precision: -2, prettyprecision: 1, strvalue: '111,1009', strvalueOutPut: '111,1009' },
91
- { precision: -2, prettyprecision: 1, strvalue: '111,1000', strvalueOutPut: '111,1' },
28
+ describe('format', () => {
92
29
 
30
+ formatCases.forEach(e => {
31
+ it(`should return ${e.strvalueOutPut} when: [ value: ${e.strvalue}, precision: ${e.precision}, prettyPrecision: ${e.prettyprecision} ]`, () => {
32
+ expect(NumberUtils.format(e.strvalue, e.precision, e.prettyprecision)).toBe(e.strvalueOutPut);
33
+ });
34
+ });
93
35
 
94
- ];
36
+ });
95
37
 
96
38
 
97
- it('format', function () {
98
- let result: string = '';
99
- casesStrValue.forEach(e => {
100
- result = NumberUtils.format(e.strvalue, e.precision, e.prettyprecision);
101
- expect(result).toBe(e.strvalueOutPut);
102
- })
39
+ describe('changeFormat', () => {
40
+ changeFormatCases.forEach(e => {
41
+ it(`should return ${e.outPutValue} when value is ${e.inputValue}`, () => {
42
+ expect(NumberUtils.changeFormat(e.inputValue)).toBe(e.outPutValue);
43
+ });
44
+ });
103
45
 
104
46
  });
105
47
 
106
48
 
49
+ describe('keepOnlyDecimalSeparator', () => {
107
50
 
51
+ keepOnlyDecimalSeparatorCases.forEach(e => {
52
+ it(`should return ${e.outPutValue} when: [ value: ${e.inputValue}, formatNumber: ${e.formatnumber} ]`, () => {
53
+ expect(NumberUtils.keepOnlyDecimalSeparator(e.inputValue, e.formatnumber)).toBe(e.outPutValue);
54
+ });
55
+ });
108
56
 
109
- // keepOnlyDecimalSeparator
110
- // ----------------------------------------------------------------------------------------
111
- const testCasesTo_changeFormat = [
112
-
113
- { inputValue: '1.200.999', outPutValue: '1,200,999' },
114
- { inputValue: '1.000,99', outPutValue: '1,000.99' },
115
- { inputValue: '1200999,99', outPutValue: '1200999.99' },
116
- { inputValue: 'R$ 1,232,333.345', outPutValue: 'R$ 1.232.333,345' },
117
- { inputValue: 'R$ 1.232.333,345', outPutValue: 'R$ 1,232,333.345' },
118
-
119
- ]
57
+ });
120
58
 
121
- it('format without formatnumber parameter', function () {
122
- let result: string = '';
123
- testCasesTo_changeFormat.forEach(e => {
124
- result = NumberUtils.changeFormat(e.inputValue);
125
- expect(result).toBe(e.outPutValue);
126
- })
127
59
 
60
+ describe('round', () => {
61
+ roundTestCases.forEach(e => {
62
+ it(`should return ${e.outPutValue} when: [ value: ${e.inputValue}, decimal: ${e.decimal} ]`, () => {
63
+ expect(NumberUtils.round(e.inputValue, e.decimal)).toBe(e.outPutValue);
64
+ });
65
+ });
128
66
  });
129
67
 
130
68
 
131
- // keepOnlyDecimalSeparator
132
- // ----------------------------------------------------------------------------------------
133
- const testCasesTo_keepOnlyDecimalSeparator = [
69
+ describe('safeFormat', () => {
70
+ safeFormatCases.forEach(e => {
71
+ it(`should return ${e.strvalueOutPut} when: [ value: ${e.strvalue}, precision: ${e.precision}, prettyPrecision: ${e.prettyprecision} ]`, () => {
72
+ expect(NumberUtils.safeFormat(e.strvalue, e.precision, e.prettyprecision)).toBe(e.strvalueOutPut);
73
+ });
74
+ });
75
+ });
134
76
 
135
- { formatnumber: 'pt-BR', inputValue: '1.200.999', outPutValue: '1200999' },
136
- { formatnumber: 'pt-BR', inputValue: '1000,99', outPutValue: '1000,99' },
137
- { formatnumber: 'pt-BR', inputValue: '1200999,99', outPutValue: '1200999,99' },
138
- { formatnumber: 'pt-BR', inputValue: 'R$ 1.232.333,345', outPutValue: 'R$ 1232333,345' },
139
77
 
140
- { formatnumber: 'en-US', inputValue: '1,200,999', outPutValue: '1200999' },
141
- { formatnumber: 'en-US', inputValue: '1,000.99', outPutValue: '1000.99' },
142
- { formatnumber: 'en-US', inputValue: '1200999.99', outPutValue: '1200999.99' },
143
- { formatnumber: 'en-US', inputValue: 'EUR 1,232,333.345', outPutValue: 'EUR 1232333.345' },
78
+ describe('getValueOrDefault', () => {
79
+ getValueOrDefaultCases.forEach(e => {
80
+ it(`should return ${e.expected} when value is ${e.value}`, () => {
81
+ expect(NumberUtils.getValueOrDefault(e.value, e.defaultValue)).toBe(e.expected);
82
+ });
83
+ });
84
+ });
144
85
 
145
86
 
146
- ]
87
+ describe('getValueOrZero', () => {
88
+ getValueOrZeroCases.forEach(e => {
89
+ it(`should return ${e.expected} when value is ${e.value}`, () => {
90
+ expect(NumberUtils.getValueOrZero(e.value)).toBe(e.expected);
91
+ });
92
+ });
93
+ });
147
94
 
148
- it('format without formatnumber parameter', function () {
149
- let result: string = '';
150
- testCasesTo_keepOnlyDecimalSeparator.forEach(e => {
151
- result = NumberUtils.keepOnlyDecimalSeparator(e.inputValue, e.formatnumber);
152
- expect(result).toBe(e.outPutValue);
153
- })
154
95
 
155
- });
156
-
157
-
158
- const testCasesTo_round = [
159
- { decimal: undefined, inputValue: 100.12, outPutValue: 100.12 },
160
- { decimal: 1, inputValue: 100.12, outPutValue: 100.1 },
161
- { decimal: 2, inputValue: 100.12, outPutValue: 100.12 },
162
- { decimal: 3, inputValue: 100.12, outPutValue: 100.12 },
163
- { decimal: 1, inputValue: 100.15, outPutValue: 100.2 },
164
- { decimal: 2, inputValue: 100.15, outPutValue: 100.15 },
165
- { decimal: 3, inputValue: 100.15, outPutValue: 100.15 },
166
- { decimal: 1, inputValue: 100.16, outPutValue: 100.2 },
167
- { decimal: 2, inputValue: 100.16, outPutValue: 100.16 },
168
- { decimal: 3, inputValue: 100.16, outPutValue: 100.16 },
169
- { decimal: 12, inputValue: 2118000000000.0002, outPutValue: 2118000000000.0002 },
170
- { decimal: 5, inputValue: 123.45, outPutValue: 123.45 },
171
- { decimal: 0, inputValue: 123.45, outPutValue: 123 },
172
- ]
173
-
174
- it('format round number', function () {
175
- let result: number;
176
- testCasesTo_round.forEach(e => {
177
- result = NumberUtils.round(e.inputValue, e.decimal);
178
- expect(result).toBe(e.outPutValue);
179
- })
96
+ describe('compare', () => {
97
+ compareCases.forEach(({ a, b, expected }) => {
98
+ it(`should return ${expected} when comparing ${a} and ${b}`, () => {
99
+ expect(NumberUtils.compare(a, b)).toBe(expected);
100
+ });
101
+ });
180
102
  });
181
103
 
182
104
  });