Files
psysonic/src/components/settings/settingsSearch.test.ts
T
Psychotoxical 7c724a642f chore(eslint): add ESLint toolchain and clean src to strict 0/0 (#1165)
* chore(eslint): add eslint toolchain and configs

* fix(eslint): resolve gradual-config errors (rules-of-hooks, no-empty, prefer-const, …)

* chore(eslint): clear unused vars in config, contexts, app and test

* chore(eslint): clear unused vars in api and music-network

* chore(eslint): clear unused vars in utils

* chore(eslint): clear unused vars in store

* chore(eslint): clear unused vars in cover and hooks

* chore(eslint): clear unused vars in components

* chore(eslint): clear unused vars in pages

* chore(eslint): remove explicit any in src

* chore(eslint): align react-hooks exhaustive-deps

* chore(eslint): zero gradual config on src

* chore(eslint): strict hook rules in store and utils

* chore(eslint): strict hook rules in hooks and cover

* chore(eslint): strict hook rules in components

* chore(eslint): strict hook rules in pages and contexts

* chore(eslint): document scripts ignore in eslint config

* chore(eslint): add lint script and zero strict findings

* chore(eslint): address review round 1 (gradual 0/0, per-site disable reasons)

* chore(eslint): tighten two set-state disable comments (review round 2 LOW)

* chore(nix): sync npmDepsHash with package-lock.json

* docs(changelog): add Under the Hood entry for ESLint setup (PR #1165)

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-06-24 01:33:34 +02:00

49 lines
1.7 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest';
import type { TFunction } from 'i18next';
import { matchScore } from './settingsTabs';
import { searchSettings } from './settingsSearch';
const t = vi.fn((key: string) => {
const labels: Record<string, string> = {
'settings.audiomuseTitle': 'AudioMuse-AI (Navidrome)',
'settings.servers': 'Servers',
'settings.inputKeybindingsTitle': 'In-app shortcuts',
'settings.globalShortcutsTitle': 'Global shortcuts',
'settings.shortcutVolumeUp': 'Volume up',
'settings.shortcutVolumeDown': 'Volume down',
'settings.playbackTitle': 'Playback',
};
return labels[key] ?? key;
});
describe('matchScore', () => {
it('prefers earlier substring matches', () => {
expect(matchScore('volume up global shortcuts', 'volume')).toBeGreaterThan(0);
});
it('rejects repeated-character junk queries via fuzzy matching', () => {
expect(matchScore('database backup analytics strategy', 'aaaaaaa')).toBe(0);
});
it('still fuzzy-matches compact typos', () => {
expect(matchScore('equalizer eq bass treble', 'equl')).toBeGreaterThan(0);
});
});
describe('searchSettings', () => {
it('finds AudioMuse by product name', () => {
const hits = searchSettings('AudioMuse', 'library', t as unknown as TFunction);
expect(hits.some(h => h.title.includes('AudioMuse'))).toBe(true);
});
it('finds global volume shortcuts', () => {
const hits = searchSettings('Volume', 'library', t as unknown as TFunction);
expect(hits.some(h => h.title === 'Volume up')).toBe(true);
expect(hits.some(h => h.title === 'Volume down')).toBe(true);
});
it('returns nothing for nonsense queries', () => {
expect(searchSettings('aaaaaaa', 'library', t as unknown as TFunction)).toEqual([]);
});
});