mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 15:25:46 +00:00
* test(cover): smoke-test CoverArtImage hook-guard split (#1165) * test(search): smoke-test MobileSearchOverlay recent-search (#1165)
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { describe, expect, it, vi, beforeEach } from 'vitest';
|
||||
import { screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { renderWithProviders } from '../test/helpers/renderWithProviders';
|
||||
import MobileSearchOverlay from './MobileSearchOverlay';
|
||||
import { useLiveSearchScopeStore } from '../store/liveSearchScopeStore';
|
||||
|
||||
// The overlay's only behaviour-bearing change in PR #1165 was renaming the
|
||||
// recent-search handler `useRecent` → `applyRecentSearch` (it was a plain
|
||||
// function mis-flagged as a hook). Smoke-test that the recent-search path still
|
||||
// applies the term to the live-search store. Heavy collaborators are stubbed.
|
||||
vi.mock('../hooks/useShareSearch', () => ({ useShareSearch: () => ({ shareMatch: null }) }));
|
||||
vi.mock('../api/subsonicSearch', () => ({
|
||||
search: vi.fn(() => Promise.resolve({ artists: [], albums: [], songs: [] })),
|
||||
}));
|
||||
vi.mock('../cover/AlbumCoverArtImage', () => ({ AlbumCoverArtImage: () => null }));
|
||||
vi.mock('../cover/ArtistCoverArtImage', () => ({ ArtistCoverArtImage: () => null }));
|
||||
vi.mock('../cover/CoverArtImage', () => ({ CoverArtImage: () => null }));
|
||||
|
||||
const RECENT_KEY = 'psysonic_recent_searches';
|
||||
|
||||
describe('MobileSearchOverlay — recent search (applyRecentSearch, PR #1165)', () => {
|
||||
beforeEach(() => {
|
||||
useLiveSearchScopeStore.setState({ query: '', scope: null, undoStack: [] });
|
||||
localStorage.setItem(RECENT_KEY, JSON.stringify(['first query', 'second query']));
|
||||
});
|
||||
|
||||
it('lists stored recent searches in the empty state', () => {
|
||||
renderWithProviders(<MobileSearchOverlay onClose={vi.fn()} />);
|
||||
expect(screen.getByText('first query')).toBeInTheDocument();
|
||||
expect(screen.getByText('second query')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('applies a recent search term to the live-search store on click', async () => {
|
||||
const user = userEvent.setup();
|
||||
renderWithProviders(<MobileSearchOverlay onClose={vi.fn()} />);
|
||||
|
||||
await user.click(screen.getByText('first query'));
|
||||
|
||||
expect(useLiveSearchScopeStore.getState().query).toBe('first query');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user