@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,152 @@
|
|
|
1
|
+
import OverflowWatcher, { OverFlowWatcherParams, OverflowDirection, OVERFLOWED_CLASS_NAME } from '../../src/utils/OverflowWatcher';
|
|
2
|
+
|
|
3
|
+
describe('OverflowWatcher', () => {
|
|
4
|
+
let mockElement: HTMLElement;
|
|
5
|
+
let mockCallback: jest.Mock;
|
|
6
|
+
let watcherInstance: OverflowWatcher;
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
mockElement = document.createElement('div');
|
|
10
|
+
Object.defineProperty(mockElement, 'clientWidth', { value: 90, configurable: true });
|
|
11
|
+
document.body.appendChild(mockElement);
|
|
12
|
+
mockCallback = jest.fn();
|
|
13
|
+
|
|
14
|
+
const params: OverFlowWatcherParams = {
|
|
15
|
+
element: mockElement,
|
|
16
|
+
callback: mockCallback,
|
|
17
|
+
overFlowDirection: OverflowDirection.HORIZONTAL,
|
|
18
|
+
debounce: 1,
|
|
19
|
+
deltaSize: 1,
|
|
20
|
+
notOverFlow: ['testId'],
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
watcherInstance = new OverflowWatcher(params);
|
|
24
|
+
mockElement.getBoundingClientRect = jest.fn().mockReturnValue(getMockedRectClientValue(200));
|
|
25
|
+
setPrivateField(watcherInstance, '_lastContainerSize', 100);
|
|
26
|
+
setPrivateField(watcherInstance, '_lastContainerInstance', mockElement);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
afterEach(() => {
|
|
30
|
+
watcherInstance.destroy();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('should initialize with provided parameters', () => {
|
|
34
|
+
expect(watcherInstance).toBeDefined();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should disconect ResizeObserver when destroy is called', () => {
|
|
38
|
+
const disconnectSpy = jest.spyOn(ResizeObserver.prototype, 'disconnect');
|
|
39
|
+
watcherInstance.destroy();
|
|
40
|
+
expect(disconnectSpy).toHaveBeenCalled();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('Should call callback on forceUpdate', () => {
|
|
44
|
+
appendMockedChildren(mockElement);
|
|
45
|
+
watcherInstance.forceUpdate();
|
|
46
|
+
expect(mockCallback).toHaveBeenCalled();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('Should call callback on forceUpdate with childSpan', () => {
|
|
50
|
+
appendMockedChildren(mockElement);
|
|
51
|
+
watcherInstance.forceUpdate();
|
|
52
|
+
|
|
53
|
+
const childSpan = mockElement.children[1];
|
|
54
|
+
expect(mockCallback).toHaveBeenCalledWith(expect.arrayContaining([childSpan]));
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('Should call callback on forceUpdate with childSpan when notOverFlow is empty', () => {
|
|
58
|
+
appendMockedChildren(mockElement);
|
|
59
|
+
|
|
60
|
+
const params: OverFlowWatcherParams = {
|
|
61
|
+
element: mockElement,
|
|
62
|
+
callback: mockCallback,
|
|
63
|
+
overFlowDirection: OverflowDirection.HORIZONTAL,
|
|
64
|
+
debounce: 1,
|
|
65
|
+
deltaSize: 1,
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const withNoOverFlow = new OverflowWatcher(params);
|
|
69
|
+
setPrivateField(withNoOverFlow, '_lastContainerSize', 100);
|
|
70
|
+
setPrivateField(withNoOverFlow, '_lastContainerInstance', mockElement);
|
|
71
|
+
|
|
72
|
+
withNoOverFlow.forceUpdate();
|
|
73
|
+
|
|
74
|
+
const childSpan = mockElement.children[1];
|
|
75
|
+
expect(mockCallback).toHaveBeenCalledWith(expect.arrayContaining([childSpan]));
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('Should call callback on forceUpdate with childSpan considering overflowed elements', () => {
|
|
79
|
+
appendMockedChildren(mockElement);
|
|
80
|
+
const childButton = mockElement.children[0];
|
|
81
|
+
const childSpan = mockElement.children[1];
|
|
82
|
+
childSpan.classList.add(OVERFLOWED_CLASS_NAME);
|
|
83
|
+
|
|
84
|
+
const hiddemItemsMock: Map<Element, {size: number, margin: number}> = new Map();
|
|
85
|
+
hiddemItemsMock.set(childSpan, {size: 50, margin: 0});
|
|
86
|
+
hiddemItemsMock.set(childButton, {size: 0, margin: 50});
|
|
87
|
+
setPrivateField(watcherInstance, '_hiddenItemsProps', hiddemItemsMock);
|
|
88
|
+
|
|
89
|
+
watcherInstance.forceUpdate();
|
|
90
|
+
|
|
91
|
+
expect(mockCallback).toHaveBeenCalledWith(expect.arrayContaining([childSpan]));
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('Should call callback on forceUpdate with empty list', () => {
|
|
95
|
+
appendMockedChildren(mockElement);
|
|
96
|
+
setPrivateField(watcherInstance, '_lastContainerSize', 200);
|
|
97
|
+
watcherInstance.forceUpdate();
|
|
98
|
+
const childButton = mockElement.children[0];
|
|
99
|
+
const childSpan = mockElement.children[1];
|
|
100
|
+
|
|
101
|
+
expect(mockCallback).not.toHaveBeenCalledWith(expect.arrayContaining([childButton, childSpan]));
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('should ignore elements that can not overflow', () => {
|
|
105
|
+
appendMockedChildren(mockElement);
|
|
106
|
+
|
|
107
|
+
const notOverflowElement = document.createElement('div');
|
|
108
|
+
notOverflowElement.setAttribute('data-element-id', 'testId') ;
|
|
109
|
+
notOverflowElement.getBoundingClientRect = jest.fn().mockReturnValue(getMockedRectClientValue(50));
|
|
110
|
+
|
|
111
|
+
const notOverflowElement2 = document.createElement('div');
|
|
112
|
+
notOverflowElement2.setAttribute('data-element-id', 'testId2') ;
|
|
113
|
+
notOverflowElement2.getBoundingClientRect = jest.fn().mockReturnValue(getMockedRectClientValue(50));
|
|
114
|
+
|
|
115
|
+
mockElement.appendChild(notOverflowElement);
|
|
116
|
+
mockElement.appendChild(notOverflowElement2);
|
|
117
|
+
|
|
118
|
+
watcherInstance.addNotOverFlowElement('testId');
|
|
119
|
+
watcherInstance.addNotOverFlowElement('testId2');
|
|
120
|
+
|
|
121
|
+
watcherInstance.forceUpdate();
|
|
122
|
+
|
|
123
|
+
expect(mockCallback).not.toHaveBeenCalledWith(expect.arrayContaining([notOverflowElement]));
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('Should not call callback on forceUpdate', () => {
|
|
127
|
+
watcherInstance.forceUpdate();
|
|
128
|
+
expect(mockCallback).not.toHaveBeenCalled();
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
function appendMockedChildren(mockElement: HTMLElement) {
|
|
134
|
+
const chilldButton = document.createElement('button');
|
|
135
|
+
const childSpan = document.createElement('span');
|
|
136
|
+
|
|
137
|
+
chilldButton.getBoundingClientRect = jest.fn().mockReturnValue(getMockedRectClientValue(50));
|
|
138
|
+
childSpan.getBoundingClientRect = jest.fn().mockReturnValue(getMockedRectClientValue(50));
|
|
139
|
+
|
|
140
|
+
mockElement.appendChild(chilldButton);
|
|
141
|
+
mockElement.appendChild(childSpan);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function getMockedRectClientValue(size: number) {
|
|
145
|
+
return {
|
|
146
|
+
x: 0, y: 0, width: size, height: 10, top: 0, right: 0, bottom: 0, left: 0, toJSON: () => {}
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function setPrivateField<T>(instance: T, fieldName: string, value: any): void {
|
|
151
|
+
(instance as any)[fieldName] = value;
|
|
152
|
+
}
|
|
@@ -1,63 +1,287 @@
|
|
|
1
1
|
import { StringUtils } from '../../src/utils/StringUtils';
|
|
2
|
+
import {
|
|
3
|
+
isEmptyCases,
|
|
4
|
+
replaceAccentuatedCharsCases,
|
|
5
|
+
replaceAccentuatedCharsKeepSymbolsCases,
|
|
6
|
+
replaceBlankCharactersCases,
|
|
7
|
+
replaceToSpaceCases,
|
|
8
|
+
replaceAllCases,
|
|
9
|
+
removeSpecialCharactersCases,
|
|
10
|
+
isStringCases,
|
|
11
|
+
decodeHtmlEntitiesCases,
|
|
12
|
+
hashCodeCases,
|
|
13
|
+
getBooleanValueCases,
|
|
14
|
+
padStartCases,
|
|
15
|
+
padEndCases,
|
|
16
|
+
compareCases,
|
|
17
|
+
toCamelCaseCases,
|
|
18
|
+
toPascalCaseCases,
|
|
19
|
+
toSnakeCaseCases,
|
|
20
|
+
toKebabCaseCases,
|
|
21
|
+
formatBytesCases,
|
|
22
|
+
prettyPrecisionCases,
|
|
23
|
+
isCaseableCases,
|
|
24
|
+
isLowerCaseCases,
|
|
25
|
+
getOppositeCaseCases,
|
|
26
|
+
getSpecialCharactersCases,
|
|
27
|
+
getArgumentNumberCases,
|
|
28
|
+
highlightValueCases
|
|
29
|
+
} from '../testCases/StringUtilsTestCases';
|
|
2
30
|
|
|
3
|
-
describe('StringUtils', function
|
|
31
|
+
describe('StringUtils', function() {
|
|
4
32
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
33
|
+
describe('isEmpty', () => {
|
|
34
|
+
isEmptyCases.forEach(e => {
|
|
35
|
+
it(`should return ${e.valueOutput} when value is ${e.valueInput}`, () => {
|
|
36
|
+
expect(StringUtils.isEmpty(e.valueInput)).toBe(e.valueOutput);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
8
39
|
});
|
|
9
40
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
41
|
+
|
|
42
|
+
describe('replaceAccentuatedChars', () => {
|
|
43
|
+
|
|
44
|
+
it('should return the original value when called with an object without a toString method', () => {
|
|
45
|
+
const objWithoutToString = { value: 'someValue' };
|
|
46
|
+
jest.spyOn(StringUtils, 'replaceAccentuatedChars');
|
|
47
|
+
|
|
48
|
+
StringUtils.replaceAccentuatedChars(objWithoutToString as any);
|
|
49
|
+
expect(StringUtils.replaceAccentuatedChars).toHaveBeenCalledWith(objWithoutToString as any);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
it('should return the original value when called with undefined', () => {
|
|
54
|
+
const undefinedArg: any = undefined;
|
|
55
|
+
jest.spyOn(StringUtils, 'replaceAccentuatedChars');
|
|
56
|
+
|
|
57
|
+
StringUtils.replaceAccentuatedChars(undefinedArg);
|
|
58
|
+
expect(StringUtils.replaceAccentuatedChars).toHaveBeenCalledWith(undefinedArg);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
replaceAccentuatedCharsCases.forEach(e => {
|
|
62
|
+
it(`should return ${e.valueOutput} when value is ${e.valueInput}`, () => {
|
|
63
|
+
expect(StringUtils.replaceAccentuatedChars(e.valueInput)).toBe(e.valueOutput);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
describe('replaceAccentuatedCharsKeepSymbols', () => {
|
|
71
|
+
replaceAccentuatedCharsKeepSymbolsCases.forEach(e => {
|
|
72
|
+
it(`should return ${e.valueOutput} when value is ${e.valueInput}`, () => {
|
|
73
|
+
expect(StringUtils.replaceAccentuatedCharsKeepSymbols(e.valueInput)).toBe(e.valueOutput);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
describe('replaceBlankCharacters', () => {
|
|
80
|
+
replaceBlankCharactersCases.forEach(e => {
|
|
81
|
+
it(`should return ${e.valueOutput} when value is ${e.valueInput}`, () => {
|
|
82
|
+
expect(StringUtils.replaceBlankCharacters(e.valueInput)).toBe(e.valueOutput);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
describe('replaceToSpace', () => {
|
|
89
|
+
replaceToSpaceCases.forEach(e => {
|
|
90
|
+
it(`should return "${e.valueOutput}" when value is "${e.valueInput}" and replaceList is ${JSON.stringify(e.replaceList)}`, () => {
|
|
91
|
+
expect(StringUtils.replaceToSpace(e.valueInput, e.replaceList)).toBe(e.valueOutput);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
describe('replaceAll', () => {
|
|
99
|
+
replaceAllCases.forEach(e => {
|
|
100
|
+
it(`should return "${e.valueOutput}" when value is "${e.valueInput}", strFrom is "${e.strFrom}", and strTo is "${e.strTo}"`, () => {
|
|
101
|
+
expect(StringUtils.replaceAll(e.valueInput, e.strFrom, e.strTo)).toBe(e.valueOutput);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
describe('removeSpecialCharacters', () => {
|
|
108
|
+
removeSpecialCharactersCases.forEach(e => {
|
|
109
|
+
it(`should return "${e.valueOutput}" when value is "${e.valueInput}"`, () => {
|
|
110
|
+
expect(StringUtils.removeSpecialCharacters(e.valueInput)).toBe(e.valueOutput);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
describe('isString', () => {
|
|
117
|
+
isStringCases.forEach(e => {
|
|
118
|
+
it(`should return ${e.valueOutput} when value is ${JSON.stringify(e.valueInput)}`, () => {
|
|
119
|
+
expect(StringUtils.isString(e.valueInput as any)).toBe(e.valueOutput);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
describe('decodeHtmlEntities', () => {
|
|
126
|
+
decodeHtmlEntitiesCases.forEach(e => {
|
|
127
|
+
it(`should return "${e.valueOutput}" when value is "${e.valueInput}"`, () => {
|
|
128
|
+
expect(StringUtils.decodeHtmlEntities(e.valueInput as any)).toBe(e.valueOutput);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
13
131
|
});
|
|
14
132
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
133
|
+
|
|
134
|
+
describe('hashCode', () => {
|
|
135
|
+
hashCodeCases.forEach(e => {
|
|
136
|
+
it(`should return "${e.valueOutput}" when value is "${e.valueInput}"`, () => {
|
|
137
|
+
expect(StringUtils.hashCode(e.valueInput)).toBe(e.valueOutput);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
describe('getBooleanValue', () => {
|
|
144
|
+
getBooleanValueCases.forEach(e => {
|
|
145
|
+
it(`should return ${e.valueOutput} when value is "${e.valueInput}" and defaultValue is ${e.defaultValue}`, () => {
|
|
146
|
+
expect(StringUtils.getBooleanValue(e.valueInput as any, e.defaultValue)).toBe(e.valueOutput);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
describe('padStart', () => {
|
|
153
|
+
padStartCases.forEach(e => {
|
|
154
|
+
const { str, len, pad } = e.valueInput;
|
|
155
|
+
it(`should return "${e.valueOutput}" when str="${str}", len=${len}, pad="${pad}"`, () => {
|
|
156
|
+
expect(StringUtils.padStart(str as any, len, pad)).toBe(e.valueOutput);
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
describe('padEnd', () => {
|
|
163
|
+
padEndCases.forEach(e => {
|
|
164
|
+
const { str, len, pad } = e.valueInput;
|
|
165
|
+
it(`should return "${e.valueOutput}" when str="${str}", len=${len}, pad="${pad}"`, () => {
|
|
166
|
+
expect(StringUtils.padEnd(str as any, len, pad)).toBe(e.valueOutput);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
describe('compare', () => {
|
|
173
|
+
compareCases.forEach(e => {
|
|
174
|
+
const { a, b } = e.valueInput;
|
|
175
|
+
it(`should return ${e.valueOutput} when a="${a}" and b="${b}"`, () => {
|
|
176
|
+
expect(StringUtils.compare(a as any, b as any)).toBe(e.valueOutput);
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
describe('toCamelCase', () => {
|
|
183
|
+
toCamelCaseCases.forEach(e => {
|
|
184
|
+
it(`should return "${e.valueOutput}" when value is "${e.valueInput}"`, () => {
|
|
185
|
+
expect(StringUtils.toCamelCase(e.valueInput as any)).toBe(e.valueOutput);
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
describe('toPascalCase', () => {
|
|
192
|
+
toPascalCaseCases.forEach(e => {
|
|
193
|
+
it(`should return "${e.valueOutput}" when value is "${e.valueInput}"`, () => {
|
|
194
|
+
expect(StringUtils.toPascalCase(e.valueInput as any)).toBe(e.valueOutput);
|
|
195
|
+
});
|
|
196
|
+
});
|
|
18
197
|
});
|
|
19
198
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
199
|
+
|
|
200
|
+
describe('toSnakeCase', () => {
|
|
201
|
+
toSnakeCaseCases.forEach(e => {
|
|
202
|
+
it(`should return "${e.valueOutput}" when value is "${e.valueInput}"`, () => {
|
|
203
|
+
expect(StringUtils.toSnakeCase(e.valueInput as any)).toBe(e.valueOutput);
|
|
204
|
+
});
|
|
205
|
+
});
|
|
23
206
|
});
|
|
24
207
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
208
|
+
|
|
209
|
+
describe('toKebabCase', () => {
|
|
210
|
+
toKebabCaseCases.forEach(e => {
|
|
211
|
+
it(`should return "${e.valueOutput}" when value is "${e.valueInput}"`, () => {
|
|
212
|
+
expect(StringUtils.toKebabCase(e.valueInput as any)).toBe(e.valueOutput);
|
|
213
|
+
});
|
|
214
|
+
});
|
|
28
215
|
});
|
|
29
216
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
217
|
+
|
|
218
|
+
describe('formatBytes', () => {
|
|
219
|
+
formatBytesCases.forEach(e => {
|
|
220
|
+
it(`should return "${e.valueOutput}" when value is ${e.valueInput}`, () => {
|
|
221
|
+
expect(StringUtils.formatBytes(e.valueInput as any)).toBe(e.valueOutput);
|
|
222
|
+
});
|
|
223
|
+
});
|
|
33
224
|
});
|
|
34
225
|
|
|
35
|
-
it('substitui vogais com acento por vogais sem acento', function () {
|
|
36
226
|
|
|
37
|
-
|
|
38
|
-
|
|
227
|
+
describe('prettyPrecision', () => {
|
|
228
|
+
prettyPrecisionCases.forEach(e => {
|
|
229
|
+
it(`should return "${e.valueOutput}" when value is "${e.valueInput}"`, () => {
|
|
230
|
+
expect(StringUtils['prettyPrecision'](e.valueInput as any)).toBe(e.valueOutput);
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
describe('isCaseable', () => {
|
|
237
|
+
isCaseableCases.forEach(e => {
|
|
238
|
+
it(`should return ${e.valueOutput} when value is "${e.valueInput}"`, () => {
|
|
239
|
+
expect(StringUtils.isCaseable(e.valueInput as any)).toBe(e.valueOutput);
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
describe('isLowerCase', () => {
|
|
245
|
+
isLowerCaseCases.forEach(e => {
|
|
246
|
+
it(`should return ${e.valueOutput} when value is "${e.valueInput}"`, () => {
|
|
247
|
+
expect(StringUtils.isLowerCase(e.valueInput as any)).toBe(e.valueOutput);
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
describe('getOppositeCase', () => {
|
|
253
|
+
getOppositeCaseCases.forEach(e => {
|
|
254
|
+
it(`should return "${e.valueOutput}" when value is "${e.valueInput}"`, () => {
|
|
255
|
+
expect(StringUtils.getOppositeCase(e.valueInput as any)).toBe(e.valueOutput);
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
});
|
|
39
259
|
|
|
40
|
-
let resultInputMinusculo = StringUtils.replaceAccentuatedChars('áàâãä');
|
|
41
|
-
expect(resultInputMinusculo).toBe('aaaaa');
|
|
42
260
|
|
|
43
|
-
|
|
44
|
-
|
|
261
|
+
describe('getSpecialCharacters', () => {
|
|
262
|
+
getSpecialCharactersCases.forEach(e => {
|
|
263
|
+
it(`should return ${JSON.stringify(e.valueOutput)} when value is "${e.valueInput}"`, () => {
|
|
264
|
+
expect(StringUtils.getSpecialCharacters(e.valueInput as any)).toEqual(e.valueOutput);
|
|
265
|
+
});
|
|
266
|
+
});
|
|
45
267
|
});
|
|
46
268
|
|
|
47
|
-
it('should return the original value when called with an object without a toString method', () => {
|
|
48
|
-
const objWithoutToString = { value: 'someValue' };
|
|
49
|
-
jest.spyOn(StringUtils, 'replaceAccentuatedCharsUpper');
|
|
50
269
|
|
|
51
|
-
|
|
52
|
-
|
|
270
|
+
describe('getArgumentNumber', () => {
|
|
271
|
+
getArgumentNumberCases.forEach(e => {
|
|
272
|
+
it(`should return ${e.valueOutput} when value is "${e.valueInput}"`, () => {
|
|
273
|
+
expect(StringUtils.getArgumentNumber(e.valueInput as any)).toBe(e.valueOutput);
|
|
274
|
+
});
|
|
275
|
+
});
|
|
53
276
|
});
|
|
54
277
|
|
|
55
|
-
it('should return the original value when called with undefined', () => {
|
|
56
|
-
const undefinedArg: any = undefined;
|
|
57
|
-
jest.spyOn(StringUtils, 'replaceAccentuatedCharsUpper');
|
|
58
278
|
|
|
59
|
-
|
|
60
|
-
|
|
279
|
+
describe('highlightValue', () => {
|
|
280
|
+
highlightValueCases.forEach(e => {
|
|
281
|
+
it(`should return "${e.valueOutput}" when value is "${e.valueInput.value}" and argument is "${e.valueInput.argument}"`, () => {
|
|
282
|
+
expect(StringUtils.highlightValue(e.valueInput.argument as any, e.valueInput.matchFields, e.valueInput.value, e.valueInput.fieldMD, e.valueInput.forceMatch)).toBe(e.valueOutput);
|
|
283
|
+
});
|
|
284
|
+
});
|
|
61
285
|
});
|
|
62
286
|
|
|
63
287
|
});
|
|
@@ -1,26 +1,73 @@
|
|
|
1
1
|
import { TimeFormatter } from '../../src/utils/TimeFormatter';
|
|
2
|
+
import { validateTimeTestCases } from '../testCases/TimeFormatterTestUtils';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
|
|
5
|
+
describe('TimeFormatter', () => {
|
|
6
|
+
|
|
7
|
+
describe('prepareValue', () => {
|
|
8
|
+
|
|
9
|
+
test('Case: input string unformated with showSeconds', () => {
|
|
10
|
+
let value = TimeFormatter.prepareValue('1110', false);
|
|
11
|
+
expect(value).toEqual('11:10');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test('Case: input string unformated without showSeconds', () => {
|
|
15
|
+
let value = TimeFormatter.prepareValue('1110', true);
|
|
16
|
+
expect(value).toEqual('00:11:10');
|
|
7
17
|
});
|
|
8
18
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
19
|
+
test('should format valid time without seconds', () => {
|
|
20
|
+
expect(TimeFormatter.prepareValue('1012', false)).toBe('10:12');
|
|
21
|
+
expect(TimeFormatter.prepareValue('12', false)).toBe('00:12');
|
|
22
|
+
expect(TimeFormatter.prepareValue('59', false)).toBe('00:59');
|
|
12
23
|
});
|
|
13
24
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
isValid = TimeFormatter.validateTime("2525", true);
|
|
19
|
-
expect(isValid).toEqual(false);
|
|
20
|
-
isValid = TimeFormatter.validateTime("232920", true);
|
|
21
|
-
expect(isValid).toEqual(true);
|
|
22
|
-
isValid = TimeFormatter.validateTime("232920", false);
|
|
23
|
-
expect(isValid).toEqual(true);
|
|
25
|
+
test('should format valid time with seconds', () => {
|
|
26
|
+
expect(TimeFormatter.prepareValue('101200', true)).toBe('10:12:00');
|
|
27
|
+
expect(TimeFormatter.prepareValue('12', true)).toBe('00:00:12');
|
|
28
|
+
expect(TimeFormatter.prepareValue('1', true)).toBe('00:00:01');
|
|
24
29
|
});
|
|
25
|
-
|
|
30
|
+
|
|
31
|
+
test('should pad input with leading zeros for proper format', () => {
|
|
32
|
+
expect(TimeFormatter.prepareValue('1', false)).toBe('00:01');
|
|
33
|
+
expect(TimeFormatter.prepareValue('123', false)).toBe('01:23');
|
|
34
|
+
expect(TimeFormatter.prepareValue('12345', true)).toBe('01:23:45');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('should return an empty string for invalid input', () => {
|
|
38
|
+
expect(TimeFormatter.prepareValue('', false)).toBe('');
|
|
39
|
+
expect(TimeFormatter.prepareValue(null as any, false)).toBe('');
|
|
40
|
+
expect(TimeFormatter.prepareValue(undefined as any, false)).toBe('');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('should throw error when recieveng string', () => {
|
|
44
|
+
expect(() => {
|
|
45
|
+
TimeFormatter.prepareValue("abcd", false)
|
|
46
|
+
}).toThrow(Error);
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
test('should handle edge cases correctly', () => {
|
|
50
|
+
expect(TimeFormatter.prepareValue('0000', false)).toBe('00:00');
|
|
51
|
+
expect(TimeFormatter.prepareValue('2359', false)).toBe('23:59');
|
|
52
|
+
expect(TimeFormatter.prepareValue('000000', true)).toBe('00:00:00');
|
|
53
|
+
expect(TimeFormatter.prepareValue('235959', true)).toBe('23:59:59');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('should format partially filled times correctly', () => {
|
|
57
|
+
expect(TimeFormatter.prepareValue('1', true)).toBe('00:00:01');
|
|
58
|
+
expect(TimeFormatter.prepareValue('123', true)).toBe('00:01:23');
|
|
59
|
+
expect(TimeFormatter.prepareValue('12', true)).toBe('00:00:12');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
describe('validateTime', () => {
|
|
66
|
+
validateTimeTestCases.forEach(e => {
|
|
67
|
+
it(`should be ${e.expected} when [ value: ${e.value}, showSeconds: ${e.showSeconds}`, () => {
|
|
68
|
+
expect(TimeFormatter.validateTime(e.value, e.showSeconds)).toBe(e.expected);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
26
73
|
});
|