Skip to content

Commit

Permalink
feat(checkboxGroup): correctly parsing values with spaces (#1034)
Browse files Browse the repository at this point in the history
  • Loading branch information
vtsvetkov-splunk authored Jan 31, 2024
1 parent 6472e81 commit 73358ee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions ui/src/components/CheckboxGroup/checkboxGroup.utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ describe('parseValue', () => {
expect(resultMap.get('collect_file')?.inputValue).toBe(1);
expect(resultMap.get('collect_task')?.inputValue).toBe(1);
});

it('should correctly parse a collection string with spaces into a Map', () => {
const collection = 'ec2_volumes/3600, ec2_instances/1800, ec2_reserved_instances/900';
const resultMap = parseValue(collection);

expect(resultMap.size).toBe(3);
expect(resultMap.get('ec2_volumes')?.inputValue).toBe(3600);
expect(resultMap.get('ec2_instances')?.inputValue).toBe(1800);
expect(resultMap.get('ec2_reserved_instances')?.inputValue).toBe(900);
});

it('should return an empty Map for undefined collection', () => {
const resultMap = parseValue();
expect(resultMap.size).toBe(0);
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/CheckboxGroup/checkboxGroup.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function parseValue(collection?: string): ValueByField {

const splitValues = collection.split(',');
splitValues.forEach((rawValue) => {
const [field, inputValue] = rawValue.split('/');
const [field, inputValue] = rawValue.trim().split('/');
const parsedInputValue = inputValue === '' ? undefined : Number(inputValue);
if (!field || Number.isNaN(parsedInputValue)) {
throw new Error(`Value is not parsable: ${collection}`);
Expand Down

0 comments on commit 73358ee

Please sign in to comment.