{t('discover.seeds.max', { count: MAX_SEEDS })}
} + + {!full && q !== '' && found.isSuccess && offered.length === 0 &&{t('discover.seeds.privacy')}
} +{t(errorMessageKey(failure instanceof ApiError ? failure.code : 'unknown'))}
- )} + ) : null} ) } diff --git a/web/src/pages/discover/SuggestionsTab.test.tsx b/web/src/pages/discover/SuggestionsTab.test.tsx new file mode 100644 index 0000000..4cd85fc --- /dev/null +++ b/web/src/pages/discover/SuggestionsTab.test.tsx @@ -0,0 +1,198 @@ +import { QueryClient, QueryClientProvider } from '@tanstack/react-query' +import { render, screen, waitFor, within } from '@testing-library/react' +import userEvent from '@testing-library/user-event' +import { MemoryRouter } from 'react-router-dom' +import { beforeEach, expect, test, vi } from 'vitest' +import { sessionStore } from '@/auth/session' +import { initI18n } from '@/i18n' +import { apiError, mockFetch, type MockRoutes, type RecordedCall } from '@/test/mockFetch' +import SuggestionsTab from './SuggestionsTab' + +const none = () => new Response(null, { status: 204 }) + +const suggestion = (id: number, name: string, wishlisted = false) => ({ + artist: { id, name }, + in_library: false, + wishlisted, + score: 0.7, + components: { a: 0.6, g: null, p: 0.5, d: 1 }, + because: [{ artist: { id: 1, name: 'Björk' }, match: 0.9 }], +}) + +const answer = (over: object = {}) => ({ + provider_status: 'ok', + attribution: 'Similar artists from Last.fm', + from_listening: false, + seeds: [], + items: [suggestion(7, 'Portishead'), suggestion(8, 'Massive Attack')], + ...over, +}) + +function routes(listening: boolean, over: MockRoutes = {}): MockRoutes { + return { + 'GET /api/v1/me/settings': () => ({ discover_from_listening: listening }), + 'GET /api/v1/me/taste': () => ({ artists: [], tags: [] }), + 'GET /api/v1/discover': () => answer(), + 'GET /api/v1/artists': () => ({ items: [{ id: 1, name: 'Björk', album_count: 1, track_count: 3 }], total: 1, limit: 6, offset: 0 }), + ...over, + } +} + +function renderTab() { + const client = new QueryClient({ defaultOptions: { queries: { retry: false }, mutations: { retry: false } } }) + return render( +{t('discover.busy')}
+ +{t('discover.waiting')}
++ {t('discover.fromListening', { names: data.seeds.map((s) => s.name).join(', ') })} +
+ )} + {data.items.length === 0 ? ( ++ {t('discover.taste.artists', { names: artists.map((a) => a.name).join(', ') })} +
+ )} +