diff options
Diffstat (limited to 'tests/search-utils.test.ts')
| -rw-r--r-- | tests/search-utils.test.ts | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/search-utils.test.ts b/tests/search-utils.test.ts new file mode 100644 index 0000000..18d3b45 --- /dev/null +++ b/tests/search-utils.test.ts @@ -0,0 +1,24 @@ +import { expect, test } from 'bun:test'; +import { findSourceByFormattedName, formatSourceName } from '../src/lib/search/utils'; + +test('formatSourceName converts to lowercase and replaces spaces with dots', () => { + expect(formatSourceName('Example Source')).toBe('example.source'); + expect(formatSourceName('Multiple Spaces')).toBe('multiple.spaces'); + expect(formatSourceName('ALREADY LOWERCASE')).toBe('already.lowercase'); + expect(formatSourceName('Mixed Case')).toBe('mixed.case'); +}); + +test('findSourceByFormattedName returns "all" for "all"', () => { + expect(findSourceByFormattedName('all', ['Source A', 'Source B'])).toBe('all'); +}); + +test('findSourceByFormattedName finds matching source', () => { + const sources = ['Example Source', 'Another Source', 'Test']; + expect(findSourceByFormattedName('example.source', sources)).toBe('Example Source'); + expect(findSourceByFormattedName('another.source', sources)).toBe('Another Source'); +}); + +test('findSourceByFormattedName returns "all" when no match found', () => { + const sources = ['Example Source', 'Another Source']; + expect(findSourceByFormattedName('non.existent', sources)).toBe('all'); +}); |
