mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 07:15:47 +00:00
feat(genre): play, shuffle and queue buttons on the genre view (#926)
* feat(genre): add paginated songs-by-genre API Wraps the Subsonic getSongsByGenre endpoint plus a fetchAllSongsByGenre helper that paginates until exhausted, capped to keep the queue and the burst of requests bounded for very large genres. * refactor(playback): extract shared bulk play/shuffle/enqueue helper A single fetchTracks-driven core (loading flag, empty guard, canonical shuffleArray) so async detail-page play buttons stop growing divergent copies. Artist detail now reuses it, dropping its weaker sort-random shuffle. * feat(genre): play, shuffle and queue buttons on the genre view Header buttons load the genre's songs and start ordered or shuffled playback, or append them to the queue. The slice is bounded to stay within the queue resolver's cache budget so every row resolves instead of rendering as a placeholder. Strings added across all nine locales. * docs(changelog): genre play/shuffle buttons (#926)
This commit is contained in:
committed by
GitHub
parent
6c74cae0b7
commit
e734a8fc43
@@ -0,0 +1,61 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import type { Track } from '../../store/playerStoreTypes';
|
||||
import { runBulkEnqueue, runBulkPlayAll, runBulkShuffle } from './runBulkPlay';
|
||||
|
||||
function track(id: string): Track {
|
||||
return { id, title: id } as Track;
|
||||
}
|
||||
|
||||
describe('runBulkPlayAll', () => {
|
||||
it('plays the first track with the full list as queue and toggles loading', async () => {
|
||||
const tracks = [track('a'), track('b'), track('c')];
|
||||
const setLoading = vi.fn();
|
||||
const playTrack = vi.fn();
|
||||
await runBulkPlayAll({ fetchTracks: async () => tracks, setLoading, playTrack });
|
||||
expect(playTrack).toHaveBeenCalledWith(tracks[0], tracks);
|
||||
expect(setLoading.mock.calls).toEqual([[true], [false]]);
|
||||
});
|
||||
|
||||
it('does not start playback for an empty genre but still clears loading', async () => {
|
||||
const setLoading = vi.fn();
|
||||
const playTrack = vi.fn();
|
||||
await runBulkPlayAll({ fetchTracks: async () => [], setLoading, playTrack });
|
||||
expect(playTrack).not.toHaveBeenCalled();
|
||||
expect(setLoading).toHaveBeenLastCalledWith(false);
|
||||
});
|
||||
|
||||
it('clears loading even when fetching throws', async () => {
|
||||
const setLoading = vi.fn();
|
||||
await expect(
|
||||
runBulkPlayAll({ fetchTracks: async () => { throw new Error('boom'); }, setLoading, playTrack: vi.fn() }),
|
||||
).rejects.toThrow('boom');
|
||||
expect(setLoading).toHaveBeenLastCalledWith(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('runBulkShuffle', () => {
|
||||
it('plays a permutation of the same tracks, head consistent with the queue', async () => {
|
||||
const tracks = Array.from({ length: 25 }, (_, i) => track(String(i)));
|
||||
const playTrack = vi.fn();
|
||||
await runBulkShuffle({ fetchTracks: async () => tracks, setLoading: vi.fn(), playTrack });
|
||||
const [head, queue] = playTrack.mock.calls[0];
|
||||
expect(queue).toHaveLength(tracks.length);
|
||||
expect(queue[0]).toBe(head);
|
||||
expect([...queue].map(t => t.id).sort()).toEqual([...tracks].map(t => t.id).sort());
|
||||
});
|
||||
});
|
||||
|
||||
describe('runBulkEnqueue', () => {
|
||||
it('enqueues all fetched tracks', async () => {
|
||||
const tracks = [track('a'), track('b')];
|
||||
const enqueue = vi.fn();
|
||||
await runBulkEnqueue({ fetchTracks: async () => tracks, setLoading: vi.fn(), enqueue });
|
||||
expect(enqueue).toHaveBeenCalledWith(tracks);
|
||||
});
|
||||
|
||||
it('skips enqueue when there are no tracks', async () => {
|
||||
const enqueue = vi.fn();
|
||||
await runBulkEnqueue({ fetchTracks: async () => [], setLoading: vi.fn(), enqueue });
|
||||
expect(enqueue).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user