Commit 95b835fc authored by Aryan Noshirvnai's avatar Aryan Noshirvnai

Rebuild FullPlayer lyrics to match Spotify's actual current pattern

Researched how Spotify actually surfaces lyrics rather than guessing:
the live synced line plays right under the cover art on the main Now
Playing screen at all times, no tap needed, and the full scrollable
view is a step deeper reached by swiping up (with a tap on the line
itself kept as a focusable fallback, since Spotify keeps one too).

Replaces the previous "tap a bar to crossfade cover/lyrics in place"
implementation, which showed a static first line rather than the
actually-playing one and still needed an explicit tap to see anything
at all. Lyrics is now a real slide-up screen (mirroring Queue's own
push-navigation pattern) with its own back control, swipe-down close,
Escape, and system back support.
Co-Authored-By: 's avatarClaude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019i3NAUkLkHNbsPg5vKfzF9
parent 7c321a44
Pipeline #1160 passed with stage
in 5 minutes and 45 seconds
import { render, screen, waitFor, within } from '@testing-library/react'
import { fireEvent, render, screen, waitFor, within } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { PlayerProvider, usePlayer, type PlayableSong } from '../context/PlayerContext'
......@@ -64,6 +64,19 @@ function dialog() {
return within(screen.getByRole('dialog'))
}
// The inline lyric line under the cover art - its accessible name always starts with "Lyrics:"
// (see FullPlayer's aria-label), followed by whatever line is currently showing, so tests that
// don't care about the exact text match on the prefix instead.
function lyricsLineButton() {
return screen.getByRole('button', { name: /^Lyrics:/ })
}
// Fires the pointer sequence FullPlayer's swipe-up/swipe-down handlers listen for.
function verticalSwipe(target: HTMLElement, fromY: number, toY: number) {
fireEvent.pointerDown(target, { clientY: fromY, pointerId: 1 })
fireEvent.pointerUp(target, { clientY: toY, pointerId: 1 })
}
describe('FullPlayer', () => {
beforeEach(() => {
// Default: no synced timing available - matches the plain-text-only fallback path most
......@@ -88,28 +101,77 @@ describe('FullPlayer', () => {
expect(dialog().getByRole('button', { name: 'Open queue' })).toBeInTheDocument()
})
it('toggles lyrics in place (crossfade) rather than navigating to a separate screen', async () => {
it('shows the live lyric line right under the cover art, with no tap needed to see it', async () => {
vi.spyOn(streamApi, 'fetchStreamUrl').mockResolvedValue('blob:fake-url')
renderPlayer()
await userEvent.click(screen.getByText('Start Playback'))
await openFullPlayer()
const toggleButton = screen.getByRole('button', { name: 'Show lyrics' })
await userEvent.click(toggleButton)
// No synced timing in this test (beforeEach's default) - falls back to the first non-empty
// plain line, but it's already visible without any interaction.
expect(screen.getByRole('button', { name: 'Lyrics: Line one' })).toBeInTheDocument()
expect(screen.queryByRole('region', { name: 'Lyrics' })).not.toBeInTheDocument()
})
it('prefers the live synced line over the plain-text fallback once synced timing loads', async () => {
vi.spyOn(streamApi, 'fetchStreamUrl').mockResolvedValue('blob:fake-url')
vi.spyOn(libraryApi, 'getLyrics').mockResolvedValue({
status: 'success',
lyrics: 'First\nSecond',
synced_lyrics: [
[0, 'First'],
[10, 'Second'],
],
})
renderPlayer()
await userEvent.click(screen.getByText('Start Playback'))
await openFullPlayer()
// Playback position starts at 0, and the first synced line's own timestamp is 0 too, so
// it's already the active line - the inline preview shows it directly, not "First" read as
// a plain-text guess but as the genuinely active synced line.
expect(await screen.findByRole('button', { name: 'Lyrics: First' })).toBeInTheDocument()
})
it('opens the full lyrics screen from the live line, as a real deeper screen rather than an in-place crossfade', async () => {
vi.spyOn(streamApi, 'fetchStreamUrl').mockResolvedValue('blob:fake-url')
renderPlayer()
await userEvent.click(screen.getByText('Start Playback'))
await openFullPlayer()
await userEvent.click(lyricsLineButton())
const lyricsRegion = await screen.findByRole('region', { name: 'Lyrics' })
expect(lyricsRegion).toHaveTextContent('Line one')
expect(lyricsRegion).toHaveTextContent('Line two')
// No navigation happened - transport controls are still right there, and there's no
// separate "back" control for lyrics (only Queue has one).
expect(dialog().getByRole('button', { name: 'Pause' })).toBeInTheDocument()
expect(screen.queryByRole('button', { name: 'Back to now playing' })).not.toBeInTheDocument()
// Unlike the old in-place crossfade, this is a real screen with its own back control.
expect(screen.getByRole('button', { name: 'Back to now playing' })).toBeInTheDocument()
await userEvent.click(screen.getByRole('button', { name: 'Back to now playing' }))
await waitFor(() => expect(screen.queryByRole('region', { name: 'Lyrics' })).not.toBeInTheDocument())
// Back on the main screen, with focus returned to the line that opened it.
expect(lyricsLineButton()).toHaveFocus()
})
it('opens the lyrics screen on swipe-up over the cover, and closes it on swipe-down', async () => {
vi.spyOn(streamApi, 'fetchStreamUrl').mockResolvedValue('blob:fake-url')
renderPlayer()
await userEvent.click(screen.getByText('Start Playback'))
await openFullPlayer()
// Same button, toggled the other way.
expect(toggleButton).toHaveAttribute('aria-label', 'Show cover art')
await userEvent.click(toggleButton)
expect(toggleButton).toHaveAttribute('aria-label', 'Show lyrics')
// Test song has no coverart, so this renders the placeholder tile - the swipeable wrapper
// around it (not the tile itself) is what carries the pointer handlers, identified by its
// distinctive layout classes since it has no role/label of its own.
const cover = document.querySelector('.flex-1.items-center.justify-center') as HTMLElement
verticalSwipe(cover, 400, 300)
const lyricsRegion = await screen.findByRole('region', { name: 'Lyrics' })
verticalSwipe(lyricsRegion.parentElement as HTMLElement, 300, 400)
await waitFor(() => expect(screen.queryByRole('region', { name: 'Lyrics' })).not.toBeInTheDocument())
})
it('shows a real-time synced lyrics view when the song has line timing', async () => {
......@@ -126,7 +188,7 @@ describe('FullPlayer', () => {
await userEvent.click(screen.getByText('Start Playback'))
await openFullPlayer()
await userEvent.click(screen.getByRole('button', { name: 'Show lyrics' }))
await userEvent.click(lyricsLineButton())
const lyricsRegion = await screen.findByRole('region', { name: 'Lyrics' })
expect(within(lyricsRegion).getByText('First')).toBeInTheDocument()
......@@ -147,7 +209,7 @@ describe('FullPlayer', () => {
await userEvent.click(screen.getByText('Start Playback'))
await openFullPlayer()
await userEvent.click(screen.getByRole('button', { name: 'Show lyrics' }))
await userEvent.click(lyricsLineButton())
const lyricsRegion = await screen.findByRole('region', { name: 'Lyrics' })
await userEvent.click(within(lyricsRegion).getByText('Second'))
......@@ -165,21 +227,21 @@ describe('FullPlayer', () => {
await userEvent.click(screen.getByText('Start Playback'))
await openFullPlayer()
await userEvent.click(screen.getByRole('button', { name: 'Show lyrics' }))
await userEvent.click(lyricsLineButton())
const lyricsRegion = await screen.findByRole('region', { name: 'Lyrics' })
expect(lyricsRegion).toHaveTextContent('Line one')
expect(lyricsRegion).toHaveTextContent('Line two')
})
it('falls back to an empty state if the current song changes to one with no lyrics while lyrics are showing', async () => {
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('button', { name: 'Show lyrics' }))
await userEvent.click(lyricsLineButton())
expect(await screen.findByRole('region', { name: 'Lyrics' })).toHaveTextContent('Line one')
await userEvent.click(screen.getByText('Switch To No-Lyrics Song'))
......@@ -187,7 +249,7 @@ describe('FullPlayer', () => {
expect(await screen.findByText('No lyrics available for this track.')).toBeInTheDocument()
})
it('does not show a lyrics toggle bar at all for a track with no lyrics', async () => {
it('does not show a lyrics line at all for a track with no lyrics', async () => {
vi.spyOn(streamApi, 'fetchStreamUrl').mockResolvedValue('blob:fake-url')
function ProbeNoLyrics() {
......@@ -206,7 +268,7 @@ describe('FullPlayer', () => {
await userEvent.click(screen.getByText('Start Playback'))
await openFullPlayer()
expect(screen.queryByRole('button', { name: 'Show lyrics' })).not.toBeInTheDocument()
expect(screen.queryByRole('button', { name: /^Lyrics:/ })).not.toBeInTheDocument()
})
it('opens the Queue via its icon and can jump straight to a queued track', async () => {
......@@ -224,17 +286,17 @@ describe('FullPlayer', () => {
await screen.findByRole('dialog', { name: /Now playing: Instrumental by Test Artist/ })
})
it('closes on Escape (backing out of lyrics first, then the player) and returns focus to the control that opened it', async () => {
it('closes on Escape (backing out of the lyrics screen first, then the player) and returns focus to the control that opened it', async () => {
vi.spyOn(streamApi, 'fetchStreamUrl').mockResolvedValue('blob:fake-url')
renderPlayer()
await userEvent.click(screen.getByText('Start Playback'))
const openButton = await openFullPlayer()
await userEvent.click(screen.getByRole('button', { name: 'Show lyrics' }))
await userEvent.click(lyricsLineButton())
await screen.findByRole('region', { name: 'Lyrics' })
// First Escape only reverts the lyrics crossfade, not the whole player.
// First Escape only backs out of the lyrics screen, not the whole player.
await userEvent.keyboard('{Escape}')
await waitFor(() => expect(screen.queryByRole('region', { name: 'Lyrics' })).not.toBeInTheDocument())
expect(screen.getByRole('dialog')).toBeInTheDocument()
......
This diff is collapsed.
......@@ -188,6 +188,7 @@ const FRONTEND_DONE: DoneGroup[] = [
items: [
'Library page with playback',
'Real-time synced lyrics in the full-screen player (2026-08-31): line-by-line highlight follows playback position (last line whose timestamp has passed), auto-scrolls the active line to center, tapping a line seeks there - Spotify\'s actual signature lyrics behavior, not an approximation. Falls back to the existing static full-text view when a song has plain lyrics but no synced timing, and to the empty state when it has neither. Fixed same day: the synced-lyrics lookup was only attempted when the identification candidate itself had no plain lyrics already - but Shazam and Gemini can both independently return a plain snippet, which was silently skipping the sync fetch (and any real timing that existed) whenever that happened. Now always attempted, with synced data winning over the candidate\'s own plain text when found; existing library songs were backfilled',
'Lyrics presentation rebuilt to match Spotify\'s actual current pattern, not the "tap a bar to swap cover for lyrics" one from 08-31 (2026-09-01, researched via web search rather than guessed at): the live synced line now plays right under the cover art on the main Now Playing screen at all times - no tap needed to see it, matching what Spotify itself shipped as its headline update here. The full scrollable lyrics view is a step deeper, reached by swiping up on the cover (Spotify\'s real gesture) or tapping the live line (kept as a focusable fallback for keyboard/screen-reader use, since Spotify itself keeps a tappable entry point alongside the swipe) - a real slide-up screen with its own back control, closed by swipe-down, the back button, Escape, or system back, not the previous in-place crossfade toggle.',
'Universal search box: separate Songs and Albums result sections while searching (an album expands to show/play its tracks) - replaces the plain list rather than filtering it in place',
'Spotify-style default (non-search) view (2026-09-01): an Albums grid of cover-art cards above an always-on All Songs list covering the full library. The (album, artist) grouping is derived client-side from the already-loaded song list (mirroring /library/search\'s own grouping) rather than adding a second backend endpoint that would return the same shape - deletions and new songs update both sections for free since All Songs and the album groups both derive from the same one songs array. Tapping a card expands its tracks below the grid, same interaction as search\'s album rows.',
'Playlists page: list, create, view tracks, playback',
......
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