mirror of
https://github.com/kilyabin/psysonic.git
synced 2026-07-22 14:35:41 +00:00
377675ae94
MiniPlayer.test.tsx (4): mounts without throwing, renders the
always-present titlebar controls (Pin + Open main window — Close is
Linux-only and lives on the manual smoke list per pick 4a), click on
Open main window / Close does not throw, clicking the Pin button
flips the alwaysOnTop label between "Unpin" and "Pin on top". Bridge
contract (mini:ready / mini:sync, geometry persistence) deferred to
B-tier phase B5 -- jsdom does not model two webviews.
FullscreenPlayer.test.tsx (9): renders the labelled Fullscreen Player
dialog + Close Fullscreen control. Control wiring: Close calls
onClose, Stop calls stop, Previous calls previous, Next calls next,
Repeat cycles via toggleRepeat.
§4.5 of the v2 plan -- useCachedUrl(coverUrl, coverKey, false)
regression. Mocks the CachedImage module so the call args are
observable. Pins:
- the 500 px cover-art call passes opt=false (no fetchUrl fallback;
prevents double crossfade fetchUrl -> blobUrl);
- the 300 px art-box call passes opt=true (default behaviour).
A refactor that "tidies up" the useCachedUrl call sites would silently
regress the FS player cover; this test makes it loud.
Harness fix: vi.mock for @tauri-apps/api/event now returns an async
emit that resolves -- components chain .catch() on emit which crashed
on the bare vi.fn() return value during first-render useEffect.
Benefits any future component test that mounts something using emit.
Frontend suite: 399 -> 412 tests (+13). F5 (and Phases F0-F6) complete.
92 lines
3.8 KiB
TypeScript
92 lines
3.8 KiB
TypeScript
/**
|
|
* `MiniPlayer` characterization (Phase F5c).
|
|
*
|
|
* Per pick 4a of the v2 plan: renders + click handlers only. The
|
|
* cross-webview bridge contract (`mini:ready` / `mini:sync` emit-listen,
|
|
* geometry persistence) is covered separately in B-tier phase B5; jsdom
|
|
* does not model two webviews, so an in-process test would only fake
|
|
* what we're trying to verify.
|
|
*/
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
vi.mock('@/api/subsonic', () => ({
|
|
savePlayQueue: vi.fn(async () => undefined),
|
|
getPlayQueue: vi.fn(async () => ({ songs: [], current: undefined, position: 0 })),
|
|
buildStreamUrl: vi.fn((id: string) => `https://mock/stream/${id}`),
|
|
buildCoverArtUrl: vi.fn((id: string) => `https://mock/cover/${id}`),
|
|
buildDownloadUrl: vi.fn((id: string) => `https://mock/download/${id}`),
|
|
coverArtCacheKey: vi.fn((id: string, size = 256) => `mock:cover:${id}:${size}`),
|
|
getSong: vi.fn(async () => null),
|
|
getRandomSongs: vi.fn(async () => []),
|
|
getSimilarSongs2: vi.fn(async () => []),
|
|
getTopSongs: vi.fn(async () => []),
|
|
getAlbumInfo2: vi.fn(async () => null),
|
|
reportNowPlaying: vi.fn(async () => undefined),
|
|
scrobbleSong: vi.fn(async () => undefined),
|
|
}));
|
|
|
|
vi.mock('@/api/lastfm', () => ({
|
|
lastfmScrobble: vi.fn(async () => undefined),
|
|
lastfmUpdateNowPlaying: vi.fn(async () => undefined),
|
|
lastfmGetTrackLoved: vi.fn(async () => false),
|
|
lastfmGetAllLovedTracks: vi.fn(async () => []),
|
|
}));
|
|
|
|
import MiniPlayer from './MiniPlayer';
|
|
import { renderWithProviders } from '@/test/helpers/renderWithProviders';
|
|
import { useAuthStore } from '@/store/authStore';
|
|
import { resetAllStores } from '@/test/helpers/storeReset';
|
|
import { onInvoke } from '@/test/mocks/tauri';
|
|
import { fireEvent } from '@testing-library/react';
|
|
|
|
beforeEach(() => {
|
|
resetAllStores();
|
|
const id = useAuthStore.getState().addServer({
|
|
name: 'T', url: 'https://x.test', username: 'u', password: 'p',
|
|
});
|
|
useAuthStore.getState().setActiveServer(id);
|
|
onInvoke('audio_play', () => undefined);
|
|
onInvoke('audio_pause', () => undefined);
|
|
onInvoke('audio_seek', () => undefined);
|
|
onInvoke('audio_stop', () => undefined);
|
|
onInvoke('audio_get_state', () => ({ playing: false }));
|
|
onInvoke('set_window_always_on_top', () => undefined);
|
|
onInvoke('set_linux_webkit_smooth_scrolling', () => undefined);
|
|
onInvoke('discord_update_presence', () => undefined);
|
|
});
|
|
|
|
describe('MiniPlayer — render', () => {
|
|
it('mounts without throwing', () => {
|
|
expect(() => renderWithProviders(<MiniPlayer />)).not.toThrow();
|
|
});
|
|
|
|
it('renders the always-present titlebar controls (Pin + Open main window)', () => {
|
|
// The Close button is Linux-only — gated on `navigator.platform` and
|
|
// therefore not asserted here so the test passes on every jsdom env.
|
|
const { getByLabelText } = renderWithProviders(<MiniPlayer />);
|
|
expect(getByLabelText('Unpin')).toBeInTheDocument(); // initial state: alwaysOnTop=true
|
|
expect(getByLabelText('Open main window')).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
describe('MiniPlayer — click handlers (no bridge)', () => {
|
|
it('clicking Open main window does not throw (bridge emit is a no-op in tests)', () => {
|
|
const { getByLabelText } = renderWithProviders(<MiniPlayer />);
|
|
expect(() => fireEvent.click(getByLabelText('Open main window'))).not.toThrow();
|
|
});
|
|
|
|
// The Close affordance is Linux-only — covered by manual smoke per pick 4a.
|
|
|
|
it('clicking the Pin button toggles the alwaysOnTop label', () => {
|
|
const { getByLabelText, queryByLabelText } = renderWithProviders(<MiniPlayer />);
|
|
// Initial state: alwaysOnTop=true → label is "Unpin".
|
|
expect(getByLabelText('Unpin')).toBeInTheDocument();
|
|
|
|
fireEvent.click(getByLabelText('Unpin'));
|
|
|
|
// Bridge command is mocked away; the local React state still flips,
|
|
// so the label moves to "Pin on top".
|
|
expect(queryByLabelText('Pin on top')).toBeInTheDocument();
|
|
});
|
|
});
|