1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/frontend/src/utils/parseParameter.test.ts
olav 35262e404b refactor: clean up strategy parameter types (#944)
* refactor: fix splash page button background color

* refactor: regenerate OpenAPI client

* refactor: clean up strategy parameter types

* refactor: remove index signature from IConstraint

* refactor: fix never-seen status in features list
2022-05-04 15:16:34 +02:00

37 lines
1.4 KiB
TypeScript

import {
parseParameterNumber,
parseParameterString,
parseParameterStrings,
} from 'utils/parseParameter';
test('parseParameterNumber', () => {
expect(parseParameterNumber(undefined)).toEqual(0);
expect(parseParameterNumber('')).toEqual(0);
expect(parseParameterNumber(0)).toEqual(0);
expect(parseParameterNumber(1)).toEqual(1);
expect(parseParameterNumber('a')).toEqual(0);
expect(parseParameterNumber('0')).toEqual(0);
expect(parseParameterNumber('1')).toEqual(1);
});
test('parseParameterString', () => {
expect(parseParameterString(undefined)).toEqual('');
expect(parseParameterString('')).toEqual('');
expect(parseParameterString(0)).toEqual('0');
expect(parseParameterString(1)).toEqual('1');
expect(parseParameterString('a')).toEqual('a');
expect(parseParameterString('0')).toEqual('0');
expect(parseParameterString('1')).toEqual('1');
expect(parseParameterString(' a, ,a ')).toEqual('a, ,a');
});
test('parseParameterStrings', () => {
expect(parseParameterStrings(undefined)).toEqual([]);
expect(parseParameterStrings('')).toEqual([]);
expect(parseParameterStrings(0)).toEqual(['0']);
expect(parseParameterStrings(1)).toEqual(['1']);
expect(parseParameterStrings('a')).toEqual(['a']);
expect(parseParameterStrings('a,b,c')).toEqual(['a', 'b', 'c']);
expect(parseParameterStrings(' a,, b c ,,, d,')).toEqual(['a', 'b c', 'd']);
});