2022-12-29 01:00:55 +03:00
|
|
|
import {
|
|
|
|
nonEmptyValueOrNull,
|
|
|
|
parseBooleanToString,
|
|
|
|
parseOptionalBooleanToString,
|
|
|
|
rangeOf,
|
|
|
|
} from '../../src/utils/utils';
|
2019-01-08 23:19:38 +03:00
|
|
|
|
|
|
|
describe('utils', () => {
|
2019-03-09 14:19:33 +03:00
|
|
|
describe('rangeOf', () => {
|
2020-11-14 01:06:03 +03:00
|
|
|
const func = (i: number) => `result_${i}`;
|
2019-03-09 14:19:33 +03:00
|
|
|
const size = 5;
|
|
|
|
|
|
|
|
it('builds a range of specified size invike provided function', () => {
|
|
|
|
expect(rangeOf(size, func)).toEqual([
|
|
|
|
'result_1',
|
|
|
|
'result_2',
|
|
|
|
'result_3',
|
|
|
|
'result_4',
|
|
|
|
'result_5',
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('builds a range starting at provided pos', () => {
|
|
|
|
const startAt = 3;
|
|
|
|
|
|
|
|
expect(rangeOf(size, func, startAt)).toEqual([
|
|
|
|
'result_3',
|
|
|
|
'result_4',
|
|
|
|
'result_5',
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
2021-08-21 18:53:06 +03:00
|
|
|
|
|
|
|
describe('nonEmptyValueOrNull', () => {
|
|
|
|
it.each([
|
2022-03-26 14:17:42 +03:00
|
|
|
['', null],
|
|
|
|
['Hello', 'Hello'],
|
|
|
|
[[], null],
|
|
|
|
[[1, 2, 3], [1, 2, 3]],
|
|
|
|
[{}, null],
|
2021-08-21 18:53:06 +03:00
|
|
|
[{ foo: 'bar' }, { foo: 'bar' }],
|
|
|
|
])('returns expected value based on input', (value, expected) => {
|
|
|
|
expect(nonEmptyValueOrNull(value)).toEqual(expected);
|
|
|
|
});
|
|
|
|
});
|
2021-09-25 09:20:56 +03:00
|
|
|
|
2022-12-23 22:03:27 +03:00
|
|
|
describe('parseBooleanToString', () => {
|
|
|
|
it.each([
|
|
|
|
[true, 'true'],
|
|
|
|
[false, 'false'],
|
|
|
|
])('parses value as expected', (value, expectedResult) => {
|
|
|
|
expect(parseBooleanToString(value)).toEqual(expectedResult);
|
|
|
|
});
|
|
|
|
});
|
2022-12-29 01:00:55 +03:00
|
|
|
|
|
|
|
describe('parseOptionalBooleanToString', () => {
|
|
|
|
it.each([
|
|
|
|
[undefined, undefined],
|
|
|
|
[true, 'true'],
|
|
|
|
[false, 'false'],
|
|
|
|
])('parses value as expected', (value, expectedResult) => {
|
|
|
|
expect(parseOptionalBooleanToString(value)).toEqual(expectedResult);
|
|
|
|
});
|
|
|
|
});
|
2019-01-08 23:19:38 +03:00
|
|
|
});
|