+
@@ -102,8 +108,8 @@ export default function NowPlaying() {
player.jumpTo(player.index + 1 + k)}
+ index={index + 1 + k}
+ onPlay={() => jumpTo(index + 1 + k)}
/>
))}
diff --git a/web/src/components/layout/Player.test.tsx b/web/src/components/layout/Player.test.tsx
index 141ff21..2adfc89 100644
--- a/web/src/components/layout/Player.test.tsx
+++ b/web/src/components/layout/Player.test.tsx
@@ -1,3 +1,4 @@
+import { Profiler } from 'react'
import { act, fireEvent, render, screen, within } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { MemoryRouter } from 'react-router-dom'
@@ -11,6 +12,7 @@ import { usePlayer } from '@/player/store'
import { useNowPlayingUi } from '@/player/ui'
import { fakeFullscreen } from '@/test/fullscreen'
import PlayerBar from './PlayerBar'
+import PlayerControls from './PlayerControls'
function track(n: number, over: Partial
-
- {formatTime(track ? player.positionMs : 0)}
-
-
-
- {formatTime(track?.duration_ms ?? 0)}
-
+
diff --git a/web/src/components/layout/PlayerControls.tsx b/web/src/components/layout/PlayerControls.tsx
index 9ece9b1..3105a3c 100644
--- a/web/src/components/layout/PlayerControls.tsx
+++ b/web/src/components/layout/PlayerControls.tsx
@@ -7,45 +7,52 @@ import { currentTrack, usePlayer } from '@/player/store'
/** Shuffle, previous, play/pause, next and repeat. Used by the player bar and the full-screen player. */
export default function PlayerControls({ large = false }: { large?: boolean }) {
const { t } = useTranslation()
- const player = usePlayer()
- const none = currentTrack(player) === null
+ const none = usePlayer((s) => currentTrack(s) === null)
+ const playing = usePlayer((s) => s.playing)
+ const shuffle = usePlayer((s) => s.shuffle)
+ const repeat = usePlayer((s) => s.repeat)
+ const toggleShuffle = usePlayer((s) => s.toggleShuffle)
+ const prev = usePlayer((s) => s.prev)
+ const togglePlay = usePlayer((s) => s.togglePlay)
+ const next = usePlayer((s) => s.next)
+ const cycleRepeat = usePlayer((s) => s.cycleRepeat)
const small = large ? 'size-12' : 'size-11'
- const repeatLabel = { off: 'player.repeatOff', all: 'player.repeatAll', one: 'player.repeatOne' }[player.repeat]
+ const repeatLabel = { off: 'player.repeatOff', all: 'player.repeatAll', one: 'player.repeatOne' }[repeat]
return (
-
)
diff --git a/web/src/components/layout/Shell.test.tsx b/web/src/components/layout/Shell.test.tsx
index 75c95f6..21192ba 100644
--- a/web/src/components/layout/Shell.test.tsx
+++ b/web/src/components/layout/Shell.test.tsx
@@ -1,5 +1,6 @@
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
-import { render, screen, within } from '@testing-library/react'
+import { render, screen, waitFor, within } from '@testing-library/react'
+import userEvent from '@testing-library/user-event'
import { createMemoryRouter, RouterProvider } from 'react-router-dom'
import { beforeEach, expect, test, vi } from 'vitest'
import { sessionStore } from '@/auth/session'
@@ -12,21 +13,24 @@ beforeEach(async () => {
await initI18n()
})
-function renderAt(path: string) {
+async function renderAt(path: string) {
const router = createMemoryRouter(routes, { initialEntries: [path] })
render(
,
)
+ // The pages are fetched when first opened: wait until the one asked for is in.
+ await waitFor(() => expect(router.state.initialized).toBe(true))
+ await screen.findByRole('main')
}
function mainNav() {
return screen.getByRole('navigation', { name: 'Main' })
}
-test('at /artists the Artists link is the current page and the others are not', () => {
- renderAt('/artists')
+test('at /artists the Artists link is the current page and the others are not', async () => {
+ await renderAt('/artists')
const nav = within(mainNav())
expect(nav.getByRole('link', { name: 'Artists' })).toHaveAttribute('aria-current', 'page')
for (const name of ['Home', 'Search', 'Discover', 'Albums', 'Songs', 'Settings']) {
@@ -39,16 +43,16 @@ const adminRoutes = {
'GET /api/v1/library/scan': () => ({ running: false }),
}
-test('an admin has an Admin link, and a user who is not one has none', () => {
+test('an admin has an Admin link, and a user who is not one has none', async () => {
sessionStore.setState({ status: 'authenticated', user: { id: 1, email: 'tom@example.org', is_admin: false } })
- renderAt('/artists')
+ await renderAt('/artists')
expect(within(mainNav()).queryByRole('link', { name: 'Admin' })).not.toBeInTheDocument()
})
test('the Admin link opens the libraries and stays current inside the admin area', async () => {
sessionStore.setState({ status: 'authenticated', user: { id: 1, email: 'tom@example.org', is_admin: true } })
mockFetch(adminRoutes)
- renderAt('/admin')
+ await renderAt('/admin')
expect(await screen.findByRole('region', { name: 'Libraries' })).toBeInTheDocument()
expect(within(mainNav()).getByRole('link', { name: 'Admin' })).toHaveAttribute('aria-current', 'page')
})
@@ -56,7 +60,7 @@ test('the Admin link opens the libraries and stays current inside the admin area
test('the admin area has a Users section next to Libraries', async () => {
sessionStore.setState({ status: 'authenticated', user: { id: 1, email: 'tom@example.org', is_admin: true } })
mockFetch({ ...adminRoutes, 'GET /api/v1/users': () => ({ users: [{ id: 1, email: 'tom@example.org', is_admin: true }] }) })
- renderAt('/admin/users')
+ await renderAt('/admin/users')
expect(await screen.findByRole('region', { name: 'Users' })).toBeInTheDocument()
const sections = within(screen.getByRole('navigation', { name: 'Admin sections' }))
expect(sections.getByRole('link', { name: 'Users' })).toHaveAttribute('aria-current', 'page')
@@ -66,7 +70,7 @@ test('the admin area has a Users section next to Libraries', async () => {
test('the admin area has a Providers section too', async () => {
sessionStore.setState({ status: 'authenticated', user: { id: 1, email: 'tom@example.org', is_admin: true } })
mockFetch({ ...adminRoutes, 'GET /api/v1/providers': () => ({ providers: [] }) })
- renderAt('/admin/providers')
+ await renderAt('/admin/providers')
expect(await screen.findByRole('region', { name: 'Providers' })).toBeInTheDocument()
expect(within(screen.getByRole('navigation', { name: 'Admin sections' })).getByRole('link', { name: 'Providers' })).toHaveAttribute('aria-current', 'page')
})
@@ -80,7 +84,7 @@ test('the admin area has a Jobs section too', async () => {
'GET /api/v1/library/artist-images': () => ({ running: false }),
'GET /api/v1/library/descriptions': () => ({ running: false }),
})
- renderAt('/admin/jobs')
+ await renderAt('/admin/jobs')
expect(await screen.findByRole('region', { name: 'Jobs' })).toBeInTheDocument()
expect(within(screen.getByRole('navigation', { name: 'Admin sections' })).getByRole('link', { name: 'Jobs' })).toHaveAttribute('aria-current', 'page')
})
@@ -88,8 +92,8 @@ test('the admin area has a Jobs section too', async () => {
test('someone who is not an admin who opens the jobs address gets a notice and no request', async () => {
sessionStore.setState({ status: 'authenticated', user: { id: 2, email: 'ann@example.org', is_admin: false } })
const { calls } = mockFetch({ 'GET /api/v1/library/covers': () => ({ running: false }) })
- renderAt('/admin/jobs')
- expect(screen.getByText('Only admins can see this page.')).toBeInTheDocument()
+ await renderAt('/admin/jobs')
+ expect(await screen.findByText('Only admins can see this page.')).toBeInTheDocument()
await new Promise((r) => setTimeout(r, 30))
expect(calls).toHaveLength(0)
})
@@ -97,8 +101,8 @@ test('someone who is not an admin who opens the jobs address gets a notice and n
test('someone who is not an admin who opens the providers address gets a notice and no request', async () => {
sessionStore.setState({ status: 'authenticated', user: { id: 2, email: 'ann@example.org', is_admin: false } })
const { calls } = mockFetch({ 'GET /api/v1/providers': () => ({ providers: [] }) })
- renderAt('/admin/providers')
- expect(screen.getByText('Only admins can see this page.')).toBeInTheDocument()
+ await renderAt('/admin/providers')
+ expect(await screen.findByText('Only admins can see this page.')).toBeInTheDocument()
await new Promise((r) => setTimeout(r, 30))
expect(calls).toHaveLength(0)
})
@@ -106,8 +110,8 @@ test('someone who is not an admin who opens the providers address gets a notice
test('someone who is not an admin who opens the users address gets a notice and no request', async () => {
sessionStore.setState({ status: 'authenticated', user: { id: 2, email: 'ann@example.org', is_admin: false } })
const { calls } = mockFetch({ 'GET /api/v1/users': () => ({ users: [] }) })
- renderAt('/admin/users')
- expect(screen.getByText('Only admins can see this page.')).toBeInTheDocument()
+ await renderAt('/admin/users')
+ expect(await screen.findByText('Only admins can see this page.')).toBeInTheDocument()
await new Promise((r) => setTimeout(r, 30))
expect(calls).toHaveLength(0)
})
@@ -115,30 +119,30 @@ test('someone who is not an admin who opens the users address gets a notice and
test('someone who is not an admin who opens the admin address gets a notice and no request', async () => {
sessionStore.setState({ status: 'authenticated', user: { id: 2, email: 'ann@example.org', is_admin: false } })
const { calls } = mockFetch(adminRoutes)
- renderAt('/admin/libraries')
- expect(screen.getByText('Only admins can see this page.')).toBeInTheDocument()
+ await renderAt('/admin/libraries')
+ expect(await screen.findByText('Only admins can see this page.')).toBeInTheDocument()
await new Promise((r) => setTimeout(r, 30))
expect(calls.filter((c) => c.url.pathname.includes('librar'))).toHaveLength(0)
})
-test('Home is the current page only on /', () => {
- renderAt('/')
+test('Home is the current page only on /', async () => {
+ await renderAt('/')
expect(within(mainNav()).getByRole('link', { name: 'Home' })).toHaveAttribute('aria-current', 'page')
})
-test('an artist page keeps the Artists link current', () => {
- renderAt('/artists/5')
+test('an artist page keeps the Artists link current', async () => {
+ await renderAt('/artists/5')
expect(within(mainNav()).getByRole('link', { name: 'Artists' })).toHaveAttribute('aria-current', 'page')
})
-test('the page has one main landmark and says what the server does with data', () => {
- renderAt('/songs')
+test('the page has one main landmark and says what the server does with data', async () => {
+ await renderAt('/songs')
expect(screen.getAllByRole('main')).toHaveLength(1)
expect(screen.getByText('Nothing leaves this server unless an admin turns a provider on.')).toBeInTheDocument()
})
-test('the home page opens with a greeting as its heading', () => {
- renderAt('/')
+test('the home page opens with a greeting as its heading', async () => {
+ await renderAt('/')
expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent(/^Good (morning|afternoon|evening)$/)
})
@@ -149,19 +153,29 @@ test.each([
['/songs', 'Songs'],
['/discover', 'Discover'],
['/settings', 'Settings'],
-])('the route %s opens a page headed %s', (path, heading) => {
- renderAt(path)
+])('the route %s opens a page headed %s', async (path, heading) => {
+ await renderAt(path)
expect(screen.getByRole('heading', { level: 1, name: heading })).toBeInTheDocument()
})
-test.each(['/artists/5', '/albums/5'])('the detail route %s opens inside the shell and starts loading', (path) => {
+test.each(['/artists/5', '/albums/5'])('the detail route %s opens inside the shell and starts loading', async (path) => {
mockFetch({})
- renderAt(path)
+ await renderAt(path)
expect(within(screen.getByRole('main')).getByRole('status')).toHaveTextContent('Loading')
})
-test('an unknown path shows the not-found page with a way back', () => {
- renderAt('/no/such/page')
+test('an unknown path shows the not-found page with a way back', async () => {
+ await renderAt('/no/such/page')
expect(screen.getByRole('heading', { name: 'This page does not exist' })).toBeInTheDocument()
expect(screen.getByRole('link', { name: 'Back to Home' })).toHaveAttribute('href', '/')
})
+
+test('a skip link comes first and moves the focus to the page', async () => {
+ const user = userEvent.setup()
+ await renderAt('/artists')
+ await user.tab()
+ const skip = screen.getByRole('link', { name: 'Skip to content' })
+ expect(skip).toHaveFocus()
+ await user.keyboard('{Enter}')
+ expect(screen.getByRole('main')).toHaveFocus()
+})
diff --git a/web/src/components/layout/Shell.tsx b/web/src/components/layout/Shell.tsx
index df9b2c1..691424f 100644
--- a/web/src/components/layout/Shell.tsx
+++ b/web/src/components/layout/Shell.tsx
@@ -1,3 +1,5 @@
+import { useRef } from 'react'
+import { useTranslation } from 'react-i18next'
import { Outlet } from 'react-router-dom'
import { usePlayerEngine } from '@/player/usePlayer'
import UpdateNotice from '@/pwa/UpdateNotice'
@@ -6,12 +8,30 @@ import Sidebar from './Sidebar'
/** The frame of the app: the sidebar, the page, and the player bar. */
export default function Shell() {
+ const { t } = useTranslation()
+ const main = useRef(null)
usePlayerEngine()
return (