A heart on every song, album and artist, in the player bar and the full-screen player, and a Favourites page with the songs, albums and artists, newest first. The heart changes at once and goes back if the server refuses. Hearts are only for music of this server: a friend's song has none. - FavoriteButton, useIsFavorite and useSetFavorite - /favorites page, a Favourites item in the Library group of the menu, on the Library page and in the phone Library tab
59 lines
2.3 KiB
TypeScript
59 lines
2.3 KiB
TypeScript
import { render, screen, within } from '@testing-library/react'
|
|
import { MemoryRouter } from 'react-router-dom'
|
|
import { beforeEach, expect, test, vi } from 'vitest'
|
|
import { sessionStore } from '@/auth/session'
|
|
import { initI18n } from '@/i18n'
|
|
import LibraryPage from './LibraryPage'
|
|
import MorePage from './MorePage'
|
|
|
|
beforeEach(async () => {
|
|
vi.spyOn(navigator, 'language', 'get').mockReturnValue('en-US')
|
|
await initI18n()
|
|
})
|
|
|
|
test('Library is a list of the places of the music, each a row that leads there', () => {
|
|
render(
|
|
<MemoryRouter>
|
|
<LibraryPage />
|
|
</MemoryRouter>,
|
|
)
|
|
expect(screen.getByRole('heading', { level: 1, name: 'Library' })).toBeInTheDocument()
|
|
const links = screen.getAllByRole('link').map((a) => [a.textContent, a.getAttribute('href')])
|
|
// The same order as the menu of a wide screen: the music, then what you listened to. Discover is on Home.
|
|
expect(links).toEqual([
|
|
['Artists', '/artists'],
|
|
['Albums', '/albums'],
|
|
['Songs', '/songs'],
|
|
['Favourites', '/favorites'],
|
|
['Playlists', '/playlists'],
|
|
['Smart playlists', '/smart-playlists'],
|
|
['Mixes', '/mixes'],
|
|
['History', '/history'],
|
|
['Statistics', '/stats'],
|
|
['Import', '/import'],
|
|
])
|
|
expect(within(screen.getByRole('region', { name: 'Your listening' })).getAllByRole('link')).toHaveLength(3)
|
|
expect(screen.queryByRole('link', { name: 'Discover' })).not.toBeInTheDocument()
|
|
})
|
|
|
|
test('More has Settings, and Admin only for an admin', () => {
|
|
sessionStore.setState({ status: 'authenticated', user: { id: 1, email: 'ann@example.org', is_admin: false } })
|
|
const { unmount } = render(
|
|
<MemoryRouter>
|
|
<MorePage />
|
|
</MemoryRouter>,
|
|
)
|
|
expect(screen.getByRole('heading', { level: 1, name: 'More' })).toBeInTheDocument()
|
|
expect(screen.queryByRole('link', { name: 'Import' })).not.toBeInTheDocument()
|
|
expect(screen.getByRole('link', { name: 'Settings' })).toHaveAttribute('href', '/settings')
|
|
expect(screen.queryByRole('link', { name: 'Admin' })).not.toBeInTheDocument()
|
|
unmount()
|
|
|
|
sessionStore.setState({ status: 'authenticated', user: { id: 2, email: 'tom@example.org', is_admin: true } })
|
|
render(
|
|
<MemoryRouter>
|
|
<MorePage />
|
|
</MemoryRouter>,
|
|
)
|
|
expect(screen.getByRole('link', { name: 'Admin' })).toHaveAttribute('href', '/admin')
|
|
})
|