feat: mini player bar with expandable track list
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { render, screen, waitFor, act } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { PlayerProvider, usePlayer } from '../src/player/PlayerContext.js'
|
||||
import { PlayerProvider, usePlayer, playerReducer, type PlayerState } from '../src/player/PlayerContext.js'
|
||||
import type { Track } from '../src/types.js'
|
||||
|
||||
vi.mock('../src/api.js', async (importOriginal) => {
|
||||
@@ -106,3 +106,30 @@ describe('PlayerProvider', () => {
|
||||
await waitFor(() => expect(screen.getByText('track:Theme de Yoyo')).toBeTruthy())
|
||||
})
|
||||
})
|
||||
|
||||
const twoTracks: Track[] = [
|
||||
{ id: 's1', title: 'Overture', duration: 200, track: 1 },
|
||||
{ id: 's2', title: 'Theme de Yoyo', duration: 300, track: 2 },
|
||||
]
|
||||
|
||||
describe('playerReducer edges', () => {
|
||||
const loaded: PlayerState = playerReducer(
|
||||
{ album: null, tracks: [], index: 0, playing: false, failed: [] },
|
||||
{ type: 'LOAD', album: { id: 'a1', title: 'Motion', artist: 'TCO' }, tracks: twoTracks }
|
||||
)
|
||||
|
||||
it('LOAD with empty tracks does not play', () => {
|
||||
const s = playerReducer(loaded, { type: 'LOAD', album: loaded.album!, tracks: [] })
|
||||
expect(s.playing).toBe(false)
|
||||
})
|
||||
|
||||
it('TRACK_ERROR at last track pauses without advancing, records failure once', () => {
|
||||
const atLast = playerReducer(loaded, { type: 'NEXT' })
|
||||
const err = playerReducer(atLast, { type: 'TRACK_ERROR' })
|
||||
expect(err.index).toBe(1)
|
||||
expect(err.playing).toBe(false)
|
||||
expect(err.failed).toEqual([1])
|
||||
const again = playerReducer(err, { type: 'TRACK_ERROR' })
|
||||
expect(again.failed).toEqual([1])
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user