summaryrefslogtreecommitdiffstats
path: root/tests/search-utils.test.ts
diff options
context:
space:
mode:
authorGravatar amrkmn 2025-12-26 22:39:23 +0800
committerGravatar amrkmn 2025-12-26 22:39:23 +0800
commit32ca410f4edbff578d71781d943c41573912f476 (patch)
tree49f7e1e5602657d23945082fe273fc4802959a40 /tests/search-utils.test.ts
Initial commitmain
Diffstat (limited to 'tests/search-utils.test.ts')
-rw-r--r--tests/search-utils.test.ts24
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');
+});