mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 23:35:44 +00:00
refactor(search): co-locate search feature into features/search
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import { describe, expect, it, beforeEach } from 'vitest';
|
||||
import { useLiveSearchScopeStore } from '@/store/liveSearchScopeStore';
|
||||
import { syncLiveSearchRouteScope } from '@/features/search/hooks/useLiveSearchRouteScope';
|
||||
|
||||
describe('syncLiveSearchRouteScope', () => {
|
||||
beforeEach(() => {
|
||||
useLiveSearchScopeStore.setState({ query: '', scope: null, undoStack: [] });
|
||||
});
|
||||
|
||||
it('activates scope on supported browse routes', () => {
|
||||
syncLiveSearchRouteScope('/albums');
|
||||
expect(useLiveSearchScopeStore.getState().scope).toBe('albums');
|
||||
|
||||
syncLiveSearchRouteScope('/tracks');
|
||||
expect(useLiveSearchScopeStore.getState().scope).toBe('tracks');
|
||||
|
||||
syncLiveSearchRouteScope('/composers');
|
||||
expect(useLiveSearchScopeStore.getState().scope).toBe('composers');
|
||||
});
|
||||
|
||||
it('clears scope and query when leaving browse routes', () => {
|
||||
useLiveSearchScopeStore.setState({ query: 'beatles', scope: 'albums' });
|
||||
|
||||
syncLiveSearchRouteScope('/album/abc123');
|
||||
|
||||
expect(useLiveSearchScopeStore.getState().scope).toBeNull();
|
||||
expect(useLiveSearchScopeStore.getState().query).toBe('');
|
||||
});
|
||||
|
||||
it('clears query when leaving browse with scope already cleared (ghost mode)', () => {
|
||||
useLiveSearchScopeStore.setState({ query: 'beatles', scope: null });
|
||||
|
||||
syncLiveSearchRouteScope('/album/abc123');
|
||||
|
||||
expect(useLiveSearchScopeStore.getState().scope).toBeNull();
|
||||
expect(useLiveSearchScopeStore.getState().query).toBe('');
|
||||
});
|
||||
|
||||
it('preserves query when switching between browse routes', () => {
|
||||
useLiveSearchScopeStore.setState({ query: 'jazz', scope: 'albums' });
|
||||
|
||||
syncLiveSearchRouteScope('/artists');
|
||||
|
||||
expect(useLiveSearchScopeStore.getState().scope).toBe('artists');
|
||||
expect(useLiveSearchScopeStore.getState().query).toBe('jazz');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user