feat(web): the Lidarr button on the artist page and on Discover cards
The artist page reads what Lidarr has first, so it also works for an artist the library has nothing of. A card does not ask Lidarr anything until an admin sends the artist.
This commit is contained in:
parent
67205ec2e1
commit
0527a12c87
4 changed files with 41 additions and 0 deletions
|
|
@ -5,6 +5,7 @@ import { useAlbumList, useArtist, useTrackList } from '@/api/catalog'
|
|||
import { ApiError } from '@/api/client'
|
||||
import ArtistPhoto from '@/components/ArtistPhoto'
|
||||
import { AlbumCard, CARD_GRID } from '@/components/cards'
|
||||
import LidarrButton from '@/components/LidarrButton'
|
||||
import LoadMore from '@/components/LoadMore'
|
||||
import { EmptyMessage, ErrorMessage, Loading } from '@/components/Status'
|
||||
import TrackList from '@/components/TrackList'
|
||||
|
|
@ -58,6 +59,7 @@ function ArtistView({ id }: { id: number }) {
|
|||
</Button>
|
||||
</div>
|
||||
)}
|
||||
<LidarrButton artist={{ id: a.id, name: a.name }} check />
|
||||
</div>
|
||||
</header>
|
||||
|
||||
|
|
|
|||
|
|
@ -61,6 +61,20 @@ test('an artist you have shows its photo', () => {
|
|||
expect(screen.getByRole('img', { name: 'Portishead' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
test('an admin can request the artist on Lidarr from the card, and the card asks Lidarr nothing before that', async () => {
|
||||
sessionStore.setState({ user: { id: 1, username: 'tom', is_admin: true } })
|
||||
const { calls } = mockFetch({})
|
||||
renderCard(make())
|
||||
expect(screen.getByRole('button', { name: 'Request on Lidarr' })).toBeInTheDocument()
|
||||
await new Promise((r) => setTimeout(r, 30))
|
||||
expect(calls).toHaveLength(0)
|
||||
})
|
||||
|
||||
test('someone who is not an admin has no Lidarr button on the card', () => {
|
||||
renderCard(make())
|
||||
expect(screen.queryByRole('button', { name: 'Request on Lidarr' })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
test('an artist with no reason to give says nothing about one', () => {
|
||||
renderCard(make({ because: [] }))
|
||||
expect(screen.queryByText(/Because of/)).not.toBeInTheDocument()
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { Link } from 'react-router-dom'
|
|||
import { ApiError } from '@/api/client'
|
||||
import { useArtistMarks, type Suggestion } from '@/api/discover'
|
||||
import ArtistPhoto from '@/components/ArtistPhoto'
|
||||
import LidarrButton from '@/components/LidarrButton'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { errorMessageKey } from '@/i18n'
|
||||
|
||||
|
|
@ -57,6 +58,8 @@ export default function SuggestionCard({ suggestion }: { suggestion: Suggestion
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<LidarrButton artist={artist} />
|
||||
|
||||
<details className="text-sm">
|
||||
<summary className="cursor-pointer font-semibold text-primary">{t('discover.why')}</summary>
|
||||
<ul aria-label={t('discover.parts.label')} className="mt-2 flex max-w-sm flex-col gap-1">
|
||||
|
|
|
|||
|
|
@ -371,6 +371,28 @@ test('an artist a provider named, with nothing to play, still has a page', async
|
|||
expect(await screen.findByText('Nothing of this artist is in your library.')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
test('an admin gets the Lidarr button on the page of an artist they have nothing of', async () => {
|
||||
sessionStore.setState({ user: { id: 1, username: 'tom', is_admin: true } })
|
||||
mockFetch(
|
||||
artistRoutes({
|
||||
'GET /api/v1/artists/5': () => ({ ...artist, album_count: 0, track_count: 0 }),
|
||||
'GET /api/v1/albums': () => page([]),
|
||||
'GET /api/v1/tracks': () => page([]),
|
||||
'GET /api/v1/artists/5/lidarr': () => ({ provider_status: 'ok', in_lidarr: false, monitored: false }),
|
||||
}),
|
||||
)
|
||||
renderPage(<ArtistPage />, '/artists/5', '/artists/:id')
|
||||
expect(await screen.findByRole('button', { name: 'Request on Lidarr' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
test('anyone else gets no Lidarr button and the page never asks Lidarr', async () => {
|
||||
const { calls } = mockFetch(artistRoutes())
|
||||
renderPage(<ArtistPage />, '/artists/5', '/artists/:id')
|
||||
await screen.findByRole('heading', { level: 1, name: 'Radiohead' })
|
||||
expect(screen.queryByRole('button', { name: 'Request on Lidarr' })).not.toBeInTheDocument()
|
||||
expect(calls.map((c) => c.key)).not.toContain('GET /api/v1/artists/5/lidarr')
|
||||
})
|
||||
|
||||
test('an artist the server does not know says so', async () => {
|
||||
mockFetch(artistRoutes({ 'GET /api/v1/artists/5': () => apiError(404, 'artist_not_found') }))
|
||||
renderPage(<ArtistPage />, '/artists/5', '/artists/:id')
|
||||
|
|
|
|||
Loading…
Reference in a new issue