@sankhyalabs/core 5.20.0-dev.8 → 5.20.0-dev.80
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/.docs/classes/Base64Utils.md +39 -0
- package/.docs/classes/Change.md +11 -11
- package/.docs/classes/ColumnFilterManager.md +145 -0
- package/.docs/classes/DataUnit.md +429 -139
- package/.docs/classes/DataUnitInMemoryLoader.md +303 -0
- package/.docs/classes/DataUnitLoaderUtils.md +151 -0
- package/.docs/classes/DateUtils.md +8 -8
- package/.docs/classes/FieldComparator.md +2 -2
- package/.docs/classes/IDBRepository.md +22 -0
- package/.docs/classes/KeyboardManager.md +99 -9
- package/.docs/classes/LockManager.md +249 -0
- package/.docs/classes/MaskFormatter.md +66 -14
- package/.docs/classes/ObjectUtils.md +189 -0
- package/.docs/classes/OverflowWatcher.md +533 -0
- package/.docs/classes/SelectionInfo.md +25 -11
- package/.docs/classes/ServiceCanceledException.md +193 -0
- package/.docs/classes/ServiceUtils.md +67 -0
- package/.docs/classes/SilentException.md +193 -0
- package/.docs/classes/StringUtils.md +33 -9
- package/.docs/classes/UserAgentUtils.md +15 -1
- package/.docs/enumerations/Action.md +41 -21
- package/.docs/enumerations/ChangeOperation.md +4 -4
- package/.docs/enumerations/LockManagerOperation.md +33 -0
- package/.docs/enumerations/OverflowDirection.md +29 -0
- package/.docs/enumerations/RECORD_DATE_FORMAT.md +27 -0
- package/.docs/enumerations/SelectionMode.md +2 -2
- package/.docs/enumerations/StorageType.md +37 -0
- package/.docs/enumerations/UserInterface.md +15 -5
- package/.docs/globals.md +25 -0
- package/.docs/interfaces/DUActionInterceptor.md +1 -1
- package/.docs/interfaces/DataUnitInMemoryLoaderConfig.md +37 -0
- package/.docs/interfaces/IRepository.md +18 -0
- package/.docs/interfaces/LoadDataRequest.md +1 -1
- package/.docs/interfaces/OverFlowWatcherParams.md +67 -0
- package/.docs/interfaces/PageRequest.md +3 -3
- package/.docs/interfaces/PaginationInfo.md +25 -0
- package/.docs/interfaces/PaginationInfoBuilderParams.md +37 -0
- package/.docs/interfaces/QuickFilter.md +3 -3
- package/.docs/interfaces/Record.md +4 -4
- package/.docs/interfaces/SavedRecord.md +5 -5
- package/.docs/interfaces/WaitingChange.md +3 -3
- package/.docs/namespaces/MaskFormatter/type-aliases/MaskCharacter.md +1 -1
- package/.docs/namespaces/MaskFormatter/variables/MaskCharacter.md +1 -1
- package/.docs/type-aliases/DataUnitEventOptions.md +17 -0
- package/.docs/type-aliases/OnOverflowCallBack.md +25 -0
- package/.docs/variables/OVERFLOWED_CLASS_NAME.md +13 -0
- package/.releaserc +1 -0
- package/bun.lockb +0 -0
- package/dist/dataunit/DataUnit.d.ts +92 -13
- package/dist/dataunit/DataUnit.js +227 -71
- package/dist/dataunit/DataUnit.js.map +1 -1
- package/dist/dataunit/DataUnitHelper.js +6 -5
- package/dist/dataunit/DataUnitHelper.js.map +1 -1
- package/dist/dataunit/formatting/PrettyFormatter.js +17 -6
- package/dist/dataunit/formatting/PrettyFormatter.js.map +1 -1
- package/dist/dataunit/loader/DataUnitInMemoryLoaderConfig.d.ts +9 -0
- package/dist/dataunit/loader/DataUnitInMemoryLoaderConfig.js +6 -0
- package/dist/dataunit/loader/DataUnitInMemoryLoaderConfig.js.map +1 -0
- package/dist/dataunit/loader/dataUnitInMemoryLoader.d.ts +25 -0
- package/dist/dataunit/loader/dataUnitInMemoryLoader.js +131 -0
- package/dist/dataunit/loader/dataUnitInMemoryLoader.js.map +1 -0
- package/dist/dataunit/loader/utils/dataUnitLoaderUtils.d.ts +20 -0
- package/dist/dataunit/loader/utils/dataUnitLoaderUtils.js +62 -0
- package/dist/dataunit/loader/utils/dataUnitLoaderUtils.js.map +1 -0
- package/dist/dataunit/loading/LoadDataRequest.d.ts +1 -1
- package/dist/dataunit/loading/PaginationInfo.d.ts +8 -0
- package/dist/dataunit/metadata/DataType.js +7 -1
- package/dist/dataunit/metadata/DataType.js.map +1 -1
- package/dist/dataunit/metadata/UnitMetadata.d.ts +1 -0
- package/dist/dataunit/metadata/UnitMetadata.js +1 -0
- package/dist/dataunit/metadata/UnitMetadata.js.map +1 -1
- package/dist/dataunit/sorting/FieldComparator.d.ts +2 -2
- package/dist/dataunit/sorting/FieldComparator.js +4 -9
- package/dist/dataunit/sorting/FieldComparator.js.map +1 -1
- package/dist/dataunit/state/action/DataUnitAction.d.ts +2 -0
- package/dist/dataunit/state/action/DataUnitAction.js +2 -0
- package/dist/dataunit/state/action/DataUnitAction.js.map +1 -1
- package/dist/dataunit/state/slice/LoadingControlSlice.js +16 -0
- package/dist/dataunit/state/slice/LoadingControlSlice.js.map +1 -1
- package/dist/dataunit/state/slice/RecordsSlice.js +1 -1
- package/dist/dataunit/state/slice/RecordsSlice.js.map +1 -1
- package/dist/dataunit/state/slice/SelectionSlice.js +4 -4
- package/dist/dataunit/state/slice/SelectionSlice.js.map +1 -1
- package/dist/exceptions/ServiceCanceledException.d.ts +14 -0
- package/dist/exceptions/ServiceCanceledException.js +13 -0
- package/dist/exceptions/ServiceCanceledException.js.map +1 -0
- package/dist/exceptions/SilentException.d.ts +14 -0
- package/dist/exceptions/SilentException.js +13 -0
- package/dist/exceptions/SilentException.js.map +1 -0
- package/dist/index.d.ts +13 -2
- package/dist/index.js +12 -1
- package/dist/index.js.map +1 -1
- package/dist/repository/IRepository.d.ts +6 -0
- package/dist/repository/indexeddb/IDBRepository.d.ts +1 -0
- package/dist/repository/indexeddb/IDBRepository.js +3 -0
- package/dist/repository/indexeddb/IDBRepository.js.map +1 -1
- package/dist/utils/Base64Utils.d.ts +7 -0
- package/dist/utils/Base64Utils.js +13 -0
- package/dist/utils/Base64Utils.js.map +1 -0
- package/dist/utils/CacheManager/index.d.ts +52 -0
- package/dist/utils/CacheManager/index.js +101 -0
- package/dist/utils/CacheManager/index.js.map +1 -0
- package/dist/utils/CacheManager/interfaces/index.d.ts +5 -0
- package/dist/utils/CacheManager/interfaces/index.js +7 -0
- package/dist/utils/CacheManager/interfaces/index.js.map +1 -0
- package/dist/utils/ColumnFilterManager.d.ts +19 -0
- package/dist/utils/ColumnFilterManager.js +73 -0
- package/dist/utils/ColumnFilterManager.js.map +1 -0
- package/dist/utils/DateUtils.js +3 -0
- package/dist/utils/DateUtils.js.map +1 -1
- package/dist/utils/ElementUtils.d.ts +2 -0
- package/dist/utils/ElementUtils.js +9 -0
- package/dist/utils/ElementUtils.js.map +1 -0
- package/dist/utils/KeyboardManager/index.d.ts +9 -0
- package/dist/utils/KeyboardManager/index.js +45 -1
- package/dist/utils/KeyboardManager/index.js.map +1 -1
- package/dist/utils/KeyboardManager/interface.d.ts +1 -0
- package/dist/utils/LockManager.d.ts +58 -0
- package/dist/utils/LockManager.js +188 -0
- package/dist/utils/LockManager.js.map +1 -0
- package/dist/utils/MaskFormatter.d.ts +16 -1
- package/dist/utils/MaskFormatter.js +82 -2
- package/dist/utils/MaskFormatter.js.map +1 -1
- package/dist/utils/ObjectUtils.d.ts +52 -0
- package/dist/utils/ObjectUtils.js +71 -0
- package/dist/utils/ObjectUtils.js.map +1 -1
- package/dist/utils/OnboardingUtils.js +1 -1
- package/dist/utils/OnboardingUtils.js.map +1 -1
- package/dist/utils/OverflowWatcher/index.d.ts +59 -0
- package/dist/utils/OverflowWatcher/index.js +188 -0
- package/dist/utils/OverflowWatcher/index.js.map +1 -0
- package/dist/utils/OverflowWatcher/types/overflow-callback.d.ts +6 -0
- package/dist/utils/OverflowWatcher/types/overflow-callback.js +2 -0
- package/dist/utils/OverflowWatcher/types/overflow-callback.js.map +1 -0
- package/dist/utils/OverflowWatcher/types/overflow-direction.d.ts +7 -0
- package/dist/utils/OverflowWatcher/types/overflow-direction.js +9 -0
- package/dist/utils/OverflowWatcher/types/overflow-direction.js.map +1 -0
- package/dist/utils/ServiceUtils.d.ts +24 -0
- package/dist/utils/ServiceUtils.js +40 -0
- package/dist/utils/ServiceUtils.js.map +1 -0
- package/dist/utils/SortingUtils.d.ts +9 -0
- package/dist/utils/SortingUtils.js +24 -0
- package/dist/utils/SortingUtils.js.map +1 -0
- package/dist/utils/StringUtils.d.ts +6 -0
- package/dist/utils/StringUtils.js +23 -6
- package/dist/utils/StringUtils.js.map +1 -1
- package/dist/utils/UserAgentUtils/index.d.ts +1 -0
- package/dist/utils/UserAgentUtils/index.js +5 -0
- package/dist/utils/UserAgentUtils/index.js.map +1 -1
- package/jest.config.ts +2 -0
- package/package.json +2 -1
- package/reports/test-report.xml +760 -0
- package/setupTests.js +7 -0
- package/sonar-project.properties +6 -3
- package/src/dataunit/DataUnit.ts +278 -86
- package/src/dataunit/DataUnitHelper.ts +6 -5
- package/src/dataunit/formatting/PrettyFormatter.ts +19 -6
- package/src/dataunit/loader/DataUnitInMemoryLoaderConfig.ts +10 -0
- package/src/dataunit/loader/dataUnitInMemoryLoader.ts +176 -0
- package/src/dataunit/loader/utils/dataUnitLoaderUtils.ts +86 -0
- package/src/dataunit/loading/LoadDataRequest.ts +1 -1
- package/src/dataunit/loading/PaginationInfo.ts +10 -0
- package/src/dataunit/metadata/DataType.ts +8 -1
- package/src/dataunit/metadata/UnitMetadata.ts +1 -0
- package/src/dataunit/sorting/FieldComparator.ts +18 -32
- package/src/dataunit/state/action/DataUnitAction.ts +2 -0
- package/src/dataunit/state/slice/LoadingControlSlice.ts +42 -0
- package/src/dataunit/state/slice/RecordsSlice.ts +1 -1
- package/src/dataunit/state/slice/SelectionSlice.ts +4 -4
- package/src/dataunit/state/slice/test/RecordsSlice.spec.ts +45 -0
- package/src/dataunit/test/DataUnit.spec.ts +44 -0
- package/src/exceptions/ServiceCanceledException.ts +25 -0
- package/src/exceptions/SilentException.ts +25 -0
- package/src/index.ts +32 -1
- package/src/repository/IRepository.ts +7 -0
- package/src/repository/indexeddb/IDBRepository.ts +4 -0
- package/src/utils/Base64Utils.ts +13 -0
- package/src/utils/CacheManager/index.ts +103 -0
- package/src/utils/CacheManager/interfaces/index.ts +5 -0
- package/src/utils/ColumnFilterManager.ts +104 -0
- package/src/utils/DateUtils.ts +3 -0
- package/src/utils/ElementUtils.ts +10 -0
- package/src/utils/KeyboardManager/index.ts +57 -0
- package/src/utils/KeyboardManager/interface.ts +1 -0
- package/src/utils/LockManager.ts +207 -0
- package/src/utils/MaskFormatter.ts +93 -2
- package/src/utils/ObjectUtils.ts +77 -0
- package/src/utils/OnboardingUtils.ts +1 -1
- package/src/utils/OverflowWatcher/index.ts +243 -0
- package/src/utils/OverflowWatcher/types/overflow-callback.ts +6 -0
- package/src/utils/OverflowWatcher/types/overflow-direction.ts +7 -0
- package/src/utils/ServiceUtils.ts +36 -0
- package/src/utils/SortingUtils.ts +30 -0
- package/src/utils/StringUtils.ts +23 -6
- package/src/utils/UserAgentUtils/index.ts +6 -1
- package/test/dataunit/formatting/PrettyFormatter.spec.ts +177 -0
- package/test/dataunit/loader/dataUnitInMemoryLoader.spec.ts +221 -0
- package/test/dataunit/loader/utils/dataUnitLoaderUtils.spec.ts +158 -0
- package/test/testCases/NumberUtilsTestCases.ts +190 -0
- package/test/testCases/StringUtilsTestCases.ts +435 -0
- package/test/testCases/TimeFormatterTestUtils.ts +43 -0
- package/test/util/ColumnFilterManager.spec.ts +133 -0
- package/test/util/ElementUtils.spec.ts +34 -0
- package/test/util/NumberUtils.spec.ts +72 -150
- package/test/util/ObjectUtils.spec.ts +572 -0
- package/test/util/OverflowWatcher.spec.ts +152 -0
- package/test/util/StringUtils.spec.ts +260 -36
- 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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
56
|
-
// ----------------------------------------------------------------------------------------
|
|
15
|
+
describe('NumberUtils', function() {
|
|
57
16
|
|
|
17
|
+
describe('stringToNumber', () => {
|
|
58
18
|
|
|
59
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
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
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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
|
});
|