fix(web/m7-364): pause on last-track remove + reset drawer in test setup

This commit is contained in:
2026-05-03 20:37:33 -04:00
parent 6f9b5d0059
commit bde017dad3
2 changed files with 39 additions and 2 deletions
+27
View File
@@ -33,6 +33,7 @@ beforeEach(() => {
localStorage.clear();
// Reset state by starting with an empty queue (playQueue([]) leaves queue=[], index=0).
playQueue([]);
closeQueueDrawer();
setVolume(1);
registerAudioEl(null);
// Reset shuffle and repeat to defaults
@@ -460,6 +461,21 @@ describe('queue mutations', () => {
expect(player.index).toBe(0);
});
test('moveQueueItem with from === to is a no-op', () => {
playQueue([track('a'), track('b'), track('c')], 1);
moveQueueItem(1, 1);
expect(player.queue.map((x) => x.id)).toEqual(['a', 'b', 'c']);
expect(player.index).toBe(1);
});
test('moveQueueItem with out-of-range from or to is a no-op', () => {
playQueue([track('a'), track('b'), track('c')], 0);
moveQueueItem(-1, 1);
expect(player.queue.map((x) => x.id)).toEqual(['a', 'b', 'c']);
moveQueueItem(0, 5);
expect(player.queue.map((x) => x.id)).toEqual(['a', 'b', 'c']);
});
test('removeFromQueue with idx < _index decrements _index', () => {
playQueue([track('a'), track('b'), track('c')], 2);
removeFromQueue(0);
@@ -489,6 +505,15 @@ describe('queue mutations', () => {
expect(player.state).toBe('idle');
});
test('removeFromQueue of the currently-playing last track pauses on the previous track', () => {
playQueue([track('a'), track('b'), track('c')], 2);
removeFromQueue(2);
expect(player.queue.map((x) => x.id)).toEqual(['a', 'b']);
expect(player.index).toBe(1);
expect(player.state).toBe('paused');
expect(player.position).toBe(0);
});
test('playFromQueueIndex sets index, resets position, sets state to loading', () => {
playQueue([track('a'), track('b'), track('c')], 0);
playFromQueueIndex(2);
@@ -499,8 +524,10 @@ describe('queue mutations', () => {
test('playFromQueueIndex with out-of-range idx is a no-op', () => {
playQueue([track('a'), track('b')], 0);
const stateBefore = player.state;
playFromQueueIndex(5);
expect(player.index).toBe(0);
expect(player.state).toBe(stateBefore);
});
test('toggleQueueDrawer flips _queueDrawerOpen', () => {