import { describe, it, expect } from 'vitest' import { playerReducer } from './playerReducer' import { PLAYER_REFRESH_QUEUE } from '../actions' describe('playerReducer', () => { describe('PLAYER_REFRESH_QUEUE', () => { it('clamps negative savedPlayIndex to 0', () => { const state = { queue: [ { trackId: 'song-1', musicSrc: 'old-url', uuid: 'a' }, { trackId: 'song-2', musicSrc: 'old-url', uuid: 'b' }, ], savedPlayIndex: -1, current: {}, clear: false, volume: 1, } const action = { type: PLAYER_REFRESH_QUEUE, data: {} } const result = playerReducer(state, action) expect(result.playIndex).toBe(0) }) it('preserves valid savedPlayIndex', () => { const state = { queue: [ { trackId: 'song-1', musicSrc: 'old-url', uuid: 'a' }, { trackId: 'song-2', musicSrc: 'old-url', uuid: 'b' }, ], savedPlayIndex: 1, current: {}, clear: false, volume: 1, } const action = { type: PLAYER_REFRESH_QUEUE, data: {} } const result = playerReducer(state, action) expect(result.playIndex).toBe(1) }) it('uses savedPlayIndex of 0 correctly', () => { const state = { queue: [{ trackId: 'song-1', musicSrc: 'old-url', uuid: 'a' }], savedPlayIndex: 0, current: {}, clear: false, volume: 1, } const action = { type: PLAYER_REFRESH_QUEUE, data: {} } const result = playerReducer(state, action) expect(result.playIndex).toBe(0) }) }) })