From 0527a12c8700ff5d1d6148411c27bbd22d706bc0 Mon Sep 17 00:00:00 2001 From: tgiachi Date: Thu, 12 Nov 2026 14:30:29 +0100 Subject: [PATCH] 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. --- web/src/pages/ArtistPage.tsx | 2 ++ .../pages/discover/SuggestionCard.test.tsx | 14 ++++++++++++ web/src/pages/discover/SuggestionCard.tsx | 3 +++ web/src/pages/pages.test.tsx | 22 +++++++++++++++++++ 4 files changed, 41 insertions(+) diff --git a/web/src/pages/ArtistPage.tsx b/web/src/pages/ArtistPage.tsx index 278a1d3..d1ef35d 100644 --- a/web/src/pages/ArtistPage.tsx +++ b/web/src/pages/ArtistPage.tsx @@ -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 }) { )} + diff --git a/web/src/pages/discover/SuggestionCard.test.tsx b/web/src/pages/discover/SuggestionCard.test.tsx index 45b67af..eed7494 100644 --- a/web/src/pages/discover/SuggestionCard.test.tsx +++ b/web/src/pages/discover/SuggestionCard.test.tsx @@ -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() diff --git a/web/src/pages/discover/SuggestionCard.tsx b/web/src/pages/discover/SuggestionCard.tsx index b550fba..db6936e 100644 --- a/web/src/pages/discover/SuggestionCard.tsx +++ b/web/src/pages/discover/SuggestionCard.tsx @@ -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 + +
{t('discover.why')}
    diff --git a/web/src/pages/pages.test.tsx b/web/src/pages/pages.test.tsx index 6f987d2..5db3fb4 100644 --- a/web/src/pages/pages.test.tsx +++ b/web/src/pages/pages.test.tsx @@ -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(, '/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(, '/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(, '/artists/5', '/artists/:id')