Files
openchamber/packages/ui/src/lib/worktrees/branchSearch.test.ts
T
Bohdan Triapitsyn b8716fe808 refactor(search): unify dropdown filtering on the shared ranked matcher
Branch, project, agent, model, provider, stash, SSH-host, skill-catalog
and archive filters each had their own toLowerCase().includes (or no
ordering at all); the git branch and gitmoji pickers also let cmdk
re-filter and reorder on top of the manual filter, silently dropping
rows. All of them now go through rankByQuery/matchesRankQuery: results
are relevance-ordered, multi-word queries match in any order, matching
ignores punctuation, and cmdk filtering is disabled where the ranked
list is already final. rankBranchesForQuery keeps relevance order
instead of re-sorting matches alphabetically; the model picker now also
matches model ids.
2026-08-24 15:00:52 +03:00

34 lines
1.3 KiB
TypeScript

import { describe, expect, test } from 'bun:test';
import { rankBranchesForQuery } from './branchSearch';
describe('rankBranchesForQuery', () => {
test('empty query keeps everything in the other groups', () => {
const result = rankBranchesForQuery({ localBranches: ['main'], remoteBranches: ['origin/dev'], query: ' ' });
expect(result.matching).toEqual([]);
expect(result.otherLocal).toEqual(['main']);
expect(result.otherRemote).toEqual(['origin/dev']);
});
test('orders matches by relevance, not alphabetically', () => {
const result = rankBranchesForQuery({
localBranches: ['aaa-fix-scroll', 'fix/scroll', 'main'],
remoteBranches: ['origin/fix/scroll-old'],
query: 'fix',
});
expect(result.matching[0]).toEqual({ label: 'fix/scroll', value: 'fix/scroll', source: 'local' });
expect(result.matching.map((entry) => entry.label)).toEqual([
'fix/scroll',
'aaa-fix-scroll',
'origin/fix/scroll-old',
]);
expect(result.otherLocal).toEqual(['main']);
expect(result.otherRemote).toEqual([]);
});
test('remote matches carry the remotes/ checkout value', () => {
const result = rankBranchesForQuery({ localBranches: [], remoteBranches: ['origin/feat/x'], query: 'feat' });
expect(result.matching[0].value).toBe('remotes/origin/feat/x');
});
});