forked from mlflow/mlflow
-
Notifications
You must be signed in to change notification settings - Fork 1
/
StringUtils.test.js
58 lines (50 loc) · 2.13 KB
/
StringUtils.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import {
truncateToFirstLineWithMaxLength,
capitalizeFirstChar,
middleTruncateKey,
} from './StringUtils';
describe('truncateToFirstLineWithMaxLength', () => {
test('should truncate to first line if it exists', () => {
const str = 'Test string\nwith a new line';
expect(truncateToFirstLineWithMaxLength(str, 32)).toEqual('Test string');
});
test('if first line longer than maxLength, should truncate and add ellipses', () => {
const str = 'This is 24 characters, so this part should be truncated';
expect(truncateToFirstLineWithMaxLength(str, 24)).toEqual('This is 24 characters...');
});
test('should not add ellipses if length is equal to maxLength', () => {
const str = 'This is 21 characters';
expect(truncateToFirstLineWithMaxLength(str, 21)).toEqual(str);
});
test('should not truncate if only 1 line that is shorter than maxLength', () => {
const str = 'A short line';
expect(truncateToFirstLineWithMaxLength(str, 32)).toEqual(str);
});
});
describe('capitalizeFirstChar', () => {
test('should capitalize first char and lower case all other chars', () => {
const str = 'i WaNt THis tO oNlY cAPItaLize FirSt ChaR.';
expect(capitalizeFirstChar(str)).toEqual('I want this to only capitalize first char.');
});
test('should not work for str with length less than 1', () => {
const str = '';
expect(capitalizeFirstChar(str)).toEqual(str);
});
test('should not work for objects that are not string', () => {
const number = 2;
const array = ['not', 'work'];
const object = { key: 'value' };
expect(capitalizeFirstChar(null)).toEqual(null);
expect(capitalizeFirstChar(number)).toEqual(number);
expect(capitalizeFirstChar(array)).toEqual(array);
expect(capitalizeFirstChar(object)).toEqual(object);
});
});
describe('middleTruncateKey', () => {
test('test middleTruncateKey', () => {
expect(middleTruncateKey('abc', 10)).toEqual('abc');
expect(middleTruncateKey('abcdefghij', 10)).toEqual('abcdefghij');
expect(middleTruncateKey('abcdefghijk', 10)).toEqual('abc...hijk');
expect(middleTruncateKey('abcdefghijkl', 10)).toEqual('abc...ijkl');
});
});