@sankhyalabs/core 6.0.1 → 6.1.0-dev.2
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/Change.md +11 -11
- package/.docs/classes/DataUnit.md +230 -122
- package/.docs/classes/FieldComparator.md +6 -2
- package/.docs/classes/KeyboardManager.md +99 -9
- package/.docs/classes/LockManager.md +4 -4
- package/.docs/classes/ObjectUtils.md +50 -2
- package/.docs/classes/SelectionInfo.md +12 -12
- package/.docs/classes/StringUtils.md +10 -10
- package/.docs/enumerations/Action.md +41 -31
- package/.docs/enumerations/ChangeOperation.md +4 -4
- package/.docs/enumerations/SelectionMode.md +2 -2
- package/.docs/enumerations/UserInterface.md +15 -5
- package/.docs/interfaces/DUActionInterceptor.md +1 -1
- package/.docs/interfaces/PageRequest.md +3 -3
- 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/type-aliases/DataUnitEventOptions.md +1 -1
- package/dist/dataunit/DataUnit.d.ts +19 -0
- package/dist/dataunit/DataUnit.js +43 -3
- package/dist/dataunit/DataUnit.js.map +1 -1
- package/dist/dataunit/formatting/PrettyFormatter.js +8 -3
- package/dist/dataunit/formatting/PrettyFormatter.js.map +1 -1
- package/dist/dataunit/metadata/DataType.d.ts +1 -1
- package/dist/dataunit/metadata/DataType.js +7 -4
- 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 -4
- package/dist/dataunit/sorting/FieldComparator.js.map +1 -1
- package/dist/dataunit/state/action/DataUnitAction.d.ts +1 -0
- package/dist/dataunit/state/action/DataUnitAction.js +1 -0
- package/dist/dataunit/state/action/DataUnitAction.js.map +1 -1
- 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.js.map +1 -1
- package/dist/utils/ObjectUtils.d.ts +14 -0
- package/dist/utils/ObjectUtils.js +20 -0
- package/dist/utils/ObjectUtils.js.map +1 -1
- package/dist/utils/SortingUtils.js +9 -1
- package/dist/utils/SortingUtils.js.map +1 -1
- package/dist/utils/StringUtils.js +12 -6
- package/dist/utils/StringUtils.js.map +1 -1
- package/package.json +1 -1
- package/reports/test-report.xml +669 -124
- package/src/dataunit/DataUnit.ts +51 -3
- package/src/dataunit/formatting/PrettyFormatter.ts +8 -5
- package/src/dataunit/metadata/DataType.ts +8 -4
- package/src/dataunit/metadata/UnitMetadata.ts +1 -0
- package/src/dataunit/sorting/FieldComparator.ts +4 -4
- package/src/dataunit/state/action/DataUnitAction.ts +2 -0
- package/src/utils/KeyboardManager/index.ts +57 -0
- package/src/utils/KeyboardManager/interface.ts +1 -0
- package/src/utils/LockManager.ts +0 -1
- package/src/utils/ObjectUtils.ts +21 -0
- package/src/utils/SortingUtils.ts +10 -1
- package/src/utils/StringUtils.ts +10 -6
- package/test/dataunit/formatting/PrettyFormatter.spec.ts +1 -1
- package/test/testCases/NumberUtilsTestCases.ts +190 -0
- package/test/testCases/StringUtilsTestCases.ts +435 -0
- package/test/testCases/TimeFormatterTestUtils.ts +43 -0
- package/test/util/NumberUtils.spec.ts +72 -150
- package/test/util/ObjectUtils.spec.ts +572 -0
- package/test/util/StringUtils.spec.ts +260 -36
- package/test/util/TimeFormatter.spec.ts +65 -18
- package/src/utils/test/objectUtils.spec.ts +0 -109
|
@@ -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
|
});
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import ObjectUtils from '../ObjectUtils'
|
|
2
|
-
|
|
3
|
-
describe("ObjectUtils", () => {
|
|
4
|
-
describe('hasEquivalentValues', () => {
|
|
5
|
-
it('should return true if both objects have the same property value', () => {
|
|
6
|
-
const obj1 = { value: 10 };
|
|
7
|
-
const obj2 = { value: 10 };
|
|
8
|
-
expect(ObjectUtils.hasEquivalentProps(obj1, obj2)).toBe(true);
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it('should return false if both objects have different property values', () => {
|
|
12
|
-
const obj1 = { value: 10 };
|
|
13
|
-
const obj2 = { value: 20 };
|
|
14
|
-
expect(ObjectUtils.hasEquivalentProps(obj1, obj2)).toBe(false);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('should return true if both objects are equivalent with custom property to compare', () => {
|
|
18
|
-
const obj1 = { customProp: 'hello' };
|
|
19
|
-
const obj2 = { customProp: 'hello' };
|
|
20
|
-
expect(ObjectUtils.hasEquivalentProps(obj1, obj2, 'customProp')).toBe(true);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('should return false if both objects are not equivalent with custom property to compare', () => {
|
|
24
|
-
const obj1 = { customProp: 'hello' };
|
|
25
|
-
const obj2 = { customProp: 'world' };
|
|
26
|
-
expect(ObjectUtils.hasEquivalentProps(obj1, obj2, 'customProp')).toBe(false);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('should return false if one object does not have the property', () => {
|
|
30
|
-
const obj1 = { value: 10 };
|
|
31
|
-
const obj2 = { anotherProp: 10 };
|
|
32
|
-
expect(ObjectUtils.hasEquivalentProps(obj1, obj2)).toBe(false);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('should return true if comparing primitive values directly', () => {
|
|
36
|
-
const obj1 = 5;
|
|
37
|
-
const obj2 = 5;
|
|
38
|
-
expect(ObjectUtils.hasEquivalentProps(obj1, obj2)).toBe(true);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('should return false if comparing different primitive values', () => {
|
|
42
|
-
const obj1 = 5;
|
|
43
|
-
const obj2 = 10;
|
|
44
|
-
expect(ObjectUtils.hasEquivalentProps(obj1, obj2)).toBe(false);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('should return true when comparing object with a null value', () => {
|
|
48
|
-
const obj1 = null;
|
|
49
|
-
const obj2 = null;
|
|
50
|
-
expect(ObjectUtils.hasEquivalentProps(obj1, obj2)).toBe(true);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('should return false when comparing object with null and non-null value', () => {
|
|
54
|
-
const obj1 = null;
|
|
55
|
-
const obj2 = { value: 5 };
|
|
56
|
-
expect(ObjectUtils.hasEquivalentProps(obj1, obj2)).toBe(false);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('should return true when comparing non-object values that are equal', () => {
|
|
60
|
-
const obj1 = 'same';
|
|
61
|
-
const obj2 = 'same';
|
|
62
|
-
expect(ObjectUtils.hasEquivalentProps(obj1, obj2)).toBe(true);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
it("should get an object value based on its path", async () => {
|
|
69
|
-
const obj = {
|
|
70
|
-
food: {
|
|
71
|
-
fruits: {
|
|
72
|
-
apple: 1,
|
|
73
|
-
banana: 2
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const value = ObjectUtils.getProp(obj, "food.fruits.banana");
|
|
79
|
-
expect(value).toBe(2);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it("should get an object value based on its path", async () => {
|
|
83
|
-
const food = {
|
|
84
|
-
fruits: {
|
|
85
|
-
apple: 1,
|
|
86
|
-
banana: 2
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const obj = { food };
|
|
91
|
-
|
|
92
|
-
const value = ObjectUtils.getProp(obj, "food");
|
|
93
|
-
expect(JSON.stringify(value)).toBe(JSON.stringify(food));
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it("should return undefined if the path doesn't exist in the object", async () => {
|
|
97
|
-
const obj = {
|
|
98
|
-
food: {
|
|
99
|
-
fruits: {
|
|
100
|
-
apple: 1,
|
|
101
|
-
banana: 2
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
const value = ObjectUtils.getProp(obj, "vegetables");
|
|
107
|
-
expect(value).toBe(undefined);
|
|
108
|
-
});
|
|
109
|
-
});
|