Commit e292025b authored by Aryan Noshirvnai's avatar Aryan Noshirvnai

Redesign FullPlayer to mirror real Spotify (no tabs)

Replaced the Cover/Lyrics/Queue tab switcher with Spotify's actual
pattern: cover art is always the primary now-playing screen, and
Lyrics/Queue are separate screens reached via a lyrics preview bar and
a queue icon respectively, sliding in from the right with their own
back button (push-navigation, not tab-switching). The lyrics preview
bar only appears when the track actually has lyrics, matching Spotify
rather than linking to a dead-end empty screen.

Escape now backs out one level at a time (Lyrics/Queue -> cover ->
close), and picking a track from the Queue screen returns you to the
now-playing screen instead of leaving you on the list.
Co-Authored-By: 's avatarClaude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019i3NAUkLkHNbsPg5vKfzF9
parent 3578ac25
Pipeline #1047 canceled with stage
import { render, screen, waitFor } from '@testing-library/react' import { render, screen, waitFor, within } from '@testing-library/react'
import userEvent from '@testing-library/user-event' import userEvent from '@testing-library/user-event'
import { afterEach, describe, expect, it, vi } from 'vitest' import { afterEach, describe, expect, it, vi } from 'vitest'
import { PlayerProvider, usePlayer, type PlayableSong } from '../context/PlayerContext' import { PlayerProvider, usePlayer, type PlayableSong } from '../context/PlayerContext'
...@@ -6,17 +6,38 @@ import { NowPlayingBar } from './NowPlayingBar' ...@@ -6,17 +6,38 @@ import { NowPlayingBar } from './NowPlayingBar'
import { FullPlayer } from './FullPlayer' import { FullPlayer } from './FullPlayer'
import * as streamApi from '../api/stream' import * as streamApi from '../api/stream'
const SONG: PlayableSong = { const SONG_WITH_LYRICS: PlayableSong = {
id: 1, id: 1,
title: 'Test Song', title: 'Test Song',
artist: 'Test Artist', artist: 'Test Artist',
album: 'Test Album', album: 'Test Album',
lyrics: 'Line one\nLine two', lyrics: 'Line one\nLine two',
} }
const SONG_NO_LYRICS: PlayableSong = {
id: 2,
title: 'Instrumental',
artist: 'Test Artist',
lyrics: null,
}
function Probe() { function Probe() {
const { toggle } = usePlayer() const { toggle } = usePlayer()
return <button onClick={() => toggle(SONG)}>Start Playback</button> return (
<div>
<button onClick={() => toggle(SONG_WITH_LYRICS)}>Start Playback</button>
<button onClick={() => toggle(SONG_WITH_LYRICS, [SONG_WITH_LYRICS, SONG_NO_LYRICS])}>
Start Playback With Queue
</button>
{/* Simulates the current song changing out from under an open FullPlayer via some route
that isn't FullPlayer's own Next button - e.g. auto-advance on track end, or picking
a different song from another page - which is the scenario that actually matters for
"does the Lyrics screen react correctly", independent of whether Next itself is
reachable while that screen is open. */}
<button onClick={() => toggle(SONG_NO_LYRICS, [SONG_WITH_LYRICS, SONG_NO_LYRICS])}>
Switch To No-Lyrics Song
</button>
</div>
)
} }
function renderPlayer() { function renderPlayer() {
...@@ -29,35 +50,77 @@ function renderPlayer() { ...@@ -29,35 +50,77 @@ function renderPlayer() {
) )
} }
async function openFullPlayer() {
const openButton = await screen.findByRole('button', { name: /Open player/ })
await userEvent.click(openButton)
await waitFor(() => expect(screen.getByRole('button', { name: 'Minimize player' })).toHaveFocus())
return openButton
}
// NowPlayingBar is rendered alongside FullPlayer in every test here, and both have their own
// Play/Pause button once a song is loaded - scope queries to the dialog to disambiguate.
function dialog() {
return within(screen.getByRole('dialog'))
}
describe('FullPlayer', () => { describe('FullPlayer', () => {
afterEach(() => { afterEach(() => {
vi.restoreAllMocks() vi.restoreAllMocks()
}) })
it('opens from the mini player, focuses the minimize button, and shows lyrics on the Lyrics tab', async () => { it('opens from the mini player showing the cover art view by default', async () => {
vi.spyOn(streamApi, 'fetchStreamUrl').mockResolvedValue('blob:fake-url') vi.spyOn(streamApi, 'fetchStreamUrl').mockResolvedValue('blob:fake-url')
renderPlayer() renderPlayer()
await userEvent.click(screen.getByText('Start Playback')) await userEvent.click(screen.getByText('Start Playback'))
const openButton = await screen.findByRole('button', { name: /Open player/ }) await openFullPlayer()
await userEvent.click(openButton)
await screen.findByRole('dialog', { name: /Now playing: Test Song by Test Artist/ }) await screen.findByRole('dialog', { name: /Now playing: Test Song by Test Artist/ })
await waitFor(() => expect(screen.getByRole('button', { name: 'Minimize player' })).toHaveFocus()) // No tab switcher any more - cover/transport controls are just there, no navigation needed.
expect(screen.getByRole('tab', { name: /Cover/ })).toHaveAttribute('aria-selected', 'true') expect(dialog().getByRole('button', { name: 'Pause' })).toBeInTheDocument()
expect(dialog().getByRole('button', { name: 'Open queue' })).toBeInTheDocument()
})
it('opens Lyrics via the preview bar, and Back returns to the cover screen with focus restored', async () => {
vi.spyOn(streamApi, 'fetchStreamUrl').mockResolvedValue('blob:fake-url')
renderPlayer()
await userEvent.click(screen.getByText('Start Playback'))
await openFullPlayer()
const lyricsButton = screen.getByRole('button', { name: 'View lyrics' })
await userEvent.click(lyricsButton)
const lyricsRegion = await screen.findByRole('region', { name: 'Lyrics' })
expect(lyricsRegion).toHaveTextContent('Line one')
expect(lyricsRegion).toHaveTextContent('Line two')
await waitFor(() => expect(screen.getByRole('button', { name: 'Back to now playing' })).toHaveFocus())
await userEvent.click(screen.getByRole('button', { name: 'Back to now playing' }))
await waitFor(() => expect(lyricsButton).toHaveFocus())
})
it('falls back to an empty state if the current song changes to one with no lyrics while the Lyrics screen is open', async () => {
vi.spyOn(streamApi, 'fetchStreamUrl').mockResolvedValue('blob:fake-url')
renderPlayer()
await userEvent.click(screen.getByText('Start Playback'))
await openFullPlayer()
await userEvent.click(screen.getByRole('tab', { name: /Lyrics/ })) await userEvent.click(screen.getByRole('button', { name: 'View lyrics' }))
expect(await screen.findByText('Line one')).toBeInTheDocument()
expect(screen.getByRole('tab', { name: /Lyrics/ })).toHaveAttribute('aria-selected', 'true') await userEvent.click(screen.getByText('Switch To No-Lyrics Song'))
expect(screen.getByText(/Line one/)).toBeInTheDocument()
expect(await screen.findByText('No lyrics available for this track.')).toBeInTheDocument()
}) })
it('shows a clear empty state when a track has no lyrics', async () => { it('does not show a lyrics preview bar at all for a track with no lyrics', async () => {
vi.spyOn(streamApi, 'fetchStreamUrl').mockResolvedValue('blob:fake-url') vi.spyOn(streamApi, 'fetchStreamUrl').mockResolvedValue('blob:fake-url')
function ProbeNoLyrics() { function ProbeNoLyrics() {
const { toggle } = usePlayer() const { toggle } = usePlayer()
return <button onClick={() => toggle({ ...SONG, lyrics: null })}>Start Playback</button> return <button onClick={() => toggle(SONG_NO_LYRICS)}>Start Playback</button>
} }
render( render(
...@@ -69,26 +132,42 @@ describe('FullPlayer', () => { ...@@ -69,26 +132,42 @@ describe('FullPlayer', () => {
) )
await userEvent.click(screen.getByText('Start Playback')) await userEvent.click(screen.getByText('Start Playback'))
const openButton = await screen.findByRole('button', { name: /Open player/ }) await openFullPlayer()
await userEvent.click(openButton)
await waitFor(() => expect(screen.getByRole('button', { name: 'Minimize player' })).toHaveFocus()) expect(screen.queryByRole('button', { name: 'View lyrics' })).not.toBeInTheDocument()
})
it('opens the Queue via its icon and can jump straight to a queued track', async () => {
vi.spyOn(streamApi, 'fetchStreamUrl').mockResolvedValue('blob:fake-url')
renderPlayer()
await userEvent.click(screen.getByText('Start Playback With Queue'))
await openFullPlayer()
await userEvent.click(screen.getByRole('button', { name: 'Open queue' }))
expect(await screen.findByText('Instrumental')).toBeInTheDocument()
await userEvent.click(screen.getByRole('tab', { name: /Lyrics/ })) await userEvent.click(screen.getByText('Instrumental'))
expect(screen.getByText('No lyrics available for this track.')).toBeInTheDocument() await screen.findByRole('dialog', { name: /Now playing: Instrumental by Test Artist/ })
}) })
it('closes on Escape and returns focus to the control that opened it', async () => { it('closes on Escape (one level at a time) and returns focus to the control that opened it', async () => {
vi.spyOn(streamApi, 'fetchStreamUrl').mockResolvedValue('blob:fake-url') vi.spyOn(streamApi, 'fetchStreamUrl').mockResolvedValue('blob:fake-url')
renderPlayer() renderPlayer()
await userEvent.click(screen.getByText('Start Playback')) await userEvent.click(screen.getByText('Start Playback'))
const openButton = await screen.findByRole('button', { name: /Open player/ }) const openButton = await openFullPlayer()
await userEvent.click(openButton)
await waitFor(() => expect(screen.getByRole('button', { name: 'Minimize player' })).toHaveFocus())
await userEvent.click(screen.getByRole('button', { name: 'View lyrics' }))
await screen.findByText('Line one')
// First Escape only backs out of the Lyrics screen, not the whole player.
await userEvent.keyboard('{Escape}') await userEvent.keyboard('{Escape}')
await waitFor(() => expect(dialog().getByRole('button', { name: 'Pause' })).toBeInTheDocument())
expect(screen.getByRole('dialog')).toBeInTheDocument()
await userEvent.keyboard('{Escape}')
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument()) await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument())
await waitFor(() => expect(openButton).toHaveFocus()) await waitFor(() => expect(openButton).toHaveFocus())
}) })
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment