|
1 | 1 | import { describe, expect, it } from 'vitest'; |
2 | 2 |
|
3 | | -import { getValuesByDotKeys } from '../../src/utils/generic.js'; |
| 3 | +import { getValuesByDotKeys, parseCommaSeparatedList } from '../../src/utils/generic.js'; |
4 | 4 |
|
5 | 5 | describe('getValuesByDotKeys', () => { |
6 | 6 | it('should get value for a key without dot', () => { |
@@ -50,3 +50,35 @@ describe('getValuesByDotKeys', () => { |
50 | 50 | expect(result).toEqual({ nested: { a: 1, b: 2 } }); |
51 | 51 | }); |
52 | 52 | }); |
| 53 | + |
| 54 | +describe('parseCommaSeparatedList', () => { |
| 55 | + it('should parse comma-separated list with trimming', () => { |
| 56 | + const result = parseCommaSeparatedList('field1, field2,field3 '); |
| 57 | + expect(result).toEqual(['field1', 'field2', 'field3']); |
| 58 | + }); |
| 59 | + |
| 60 | + it('should handle empty input', () => { |
| 61 | + const result = parseCommaSeparatedList(); |
| 62 | + expect(result).toEqual([]); |
| 63 | + }); |
| 64 | + |
| 65 | + it('should handle empty string', () => { |
| 66 | + const result = parseCommaSeparatedList(''); |
| 67 | + expect(result).toEqual([]); |
| 68 | + }); |
| 69 | + |
| 70 | + it('should filter empty strings', () => { |
| 71 | + const result = parseCommaSeparatedList(' field1, , field2,,field3 '); |
| 72 | + expect(result).toEqual(['field1', 'field2', 'field3']); |
| 73 | + }); |
| 74 | + |
| 75 | + it('should handle only commas and spaces', () => { |
| 76 | + const result = parseCommaSeparatedList(' , , '); |
| 77 | + expect(result).toEqual([]); |
| 78 | + }); |
| 79 | + |
| 80 | + it('should handle single item', () => { |
| 81 | + const result = parseCommaSeparatedList(' single '); |
| 82 | + expect(result).toEqual(['single']); |
| 83 | + }); |
| 84 | +}); |
0 commit comments