feat(web/m7-364): queue mutations + drawer state on player store

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-03 20:29:48 -04:00
parent 8053704afa
commit 6f9b5d0059
2 changed files with 161 additions and 2 deletions
+94 -1
View File
@@ -280,7 +280,17 @@ describe('player store — shuffle + repeat + audio reports', () => {
});
});
import { enqueueTrack, enqueueTracks, playNext, playRadio } from './store.svelte';
import {
enqueueTrack,
enqueueTracks,
playNext,
playRadio,
moveQueueItem,
removeFromQueue,
playFromQueueIndex,
toggleQueueDrawer,
closeQueueDrawer
} from './store.svelte';
import * as client from '$lib/api/client';
describe('player store — enqueue + playRadio', () => {
@@ -427,3 +437,86 @@ describe('M4c radio auto-refresh at 80%', () => {
apiGet.mockRestore();
});
});
describe('queue mutations', () => {
test('moveQueueItem reorders correctly when the playing track stays put', () => {
playQueue([track('a'), track('b'), track('c')], 0);
moveQueueItem(1, 2);
expect(player.queue.map((x) => x.id)).toEqual(['a', 'c', 'b']);
expect(player.index).toBe(0);
});
test('moveQueueItem keeps _index pointing at the playing track when its row moves', () => {
playQueue([track('a'), track('b'), track('c')], 1);
moveQueueItem(1, 0);
expect(player.queue.map((x) => x.id)).toEqual(['b', 'a', 'c']);
expect(player.index).toBe(0);
});
test('moveQueueItem preserves _index logical pointer when other rows reorder around it', () => {
playQueue([track('a'), track('b'), track('c'), track('d')], 1);
moveQueueItem(0, 3);
expect(player.queue.map((x) => x.id)).toEqual(['b', 'c', 'd', 'a']);
expect(player.index).toBe(0);
});
test('removeFromQueue with idx < _index decrements _index', () => {
playQueue([track('a'), track('b'), track('c')], 2);
removeFromQueue(0);
expect(player.queue.map((x) => x.id)).toEqual(['b', 'c']);
expect(player.index).toBe(1);
});
test('removeFromQueue with idx > _index leaves _index unchanged', () => {
playQueue([track('a'), track('b'), track('c')], 0);
removeFromQueue(2);
expect(player.queue.map((x) => x.id)).toEqual(['a', 'b']);
expect(player.index).toBe(0);
});
test('removeFromQueue with idx === _index advances to next, sets state to loading', () => {
playQueue([track('a'), track('b'), track('c')], 1);
removeFromQueue(1);
expect(player.queue.map((x) => x.id)).toEqual(['a', 'c']);
expect(player.index).toBe(1);
expect(player.state).toBe('loading');
});
test('removeFromQueue emptying the queue sets state to idle', () => {
playQueue([track('a')], 0);
removeFromQueue(0);
expect(player.queue).toEqual([]);
expect(player.state).toBe('idle');
});
test('playFromQueueIndex sets index, resets position, sets state to loading', () => {
playQueue([track('a'), track('b'), track('c')], 0);
playFromQueueIndex(2);
expect(player.index).toBe(2);
expect(player.position).toBe(0);
expect(player.state).toBe('loading');
});
test('playFromQueueIndex with out-of-range idx is a no-op', () => {
playQueue([track('a'), track('b')], 0);
playFromQueueIndex(5);
expect(player.index).toBe(0);
});
test('toggleQueueDrawer flips _queueDrawerOpen', () => {
expect(player.queueDrawerOpen).toBe(false);
toggleQueueDrawer();
expect(player.queueDrawerOpen).toBe(true);
toggleQueueDrawer();
expect(player.queueDrawerOpen).toBe(false);
});
test('closeQueueDrawer is idempotent', () => {
closeQueueDrawer();
expect(player.queueDrawerOpen).toBe(false);
toggleQueueDrawer();
expect(player.queueDrawerOpen).toBe(true);
closeQueueDrawer();
expect(player.queueDrawerOpen).toBe(false);
});
});