diff --git a/web/src/components/ListeningSwitch.tsx b/web/src/components/ListeningSwitch.tsx index 6b37dc4..b493bc7 100644 --- a/web/src/components/ListeningSwitch.tsx +++ b/web/src/components/ListeningSwitch.tsx @@ -41,8 +41,8 @@ export default function ListeningSwitch() { diff --git a/web/src/pages/discover/SeedPicker.test.tsx b/web/src/pages/discover/SeedPicker.test.tsx index 8f3c7f7..ffa031e 100644 --- a/web/src/pages/discover/SeedPicker.test.tsx +++ b/web/src/pages/discover/SeedPicker.test.tsx @@ -54,9 +54,32 @@ test('typing finds artists, and choosing one makes it a chip', async () => { await userEvent.click(await screen.findByRole('button', { name: 'Add Björk' })) expect(calls.at(-1)?.url.searchParams.get('q')).toBe('bj') expect(screen.getByRole('list', { name: 'Starting artists' })).toHaveTextContent('Björk') - // A chosen artist is not offered again. - await waitFor(() => expect(screen.queryByRole('button', { name: 'Add Björk' })).not.toBeInTheDocument()) - expect(screen.getByRole('button', { name: 'Add Bjørn' })).toBeInTheDocument() + // Choosing is done: the box is empty for the next one and offers nothing. + expect(box()).toHaveValue('') + expect(screen.queryByRole('button', { name: 'Add Bjørn' })).not.toBeInTheDocument() + expect(screen.queryByText(/Nothing matches/)).not.toBeInTheDocument() + + // Looking again, a chosen artist is not offered a second time. + await userEvent.type(box(), 'bj') + expect(await screen.findByRole('button', { name: 'Add Bjørn' })).toBeInTheDocument() + expect(screen.queryByRole('button', { name: 'Add Björk' })).not.toBeInTheDocument() + expect(screen.queryByText(/Nothing matches/)).not.toBeInTheDocument() +}) + +test('when the only match is already chosen it does not claim there is no match', async () => { + mockFetch({ 'GET /api/v1/artists': () => ({ items: [artist(1, 'Björk')], total: 1, limit: 6, offset: 0 }) }) + renderPicker([{ id: 1, name: 'Björk' }]) + await userEvent.type(box(), 'bj') + await waitFor(() => expect(box()).toHaveValue('bj')) + await new Promise((r) => setTimeout(r, 400)) + expect(screen.queryByText(/Nothing matches/)).not.toBeInTheDocument() +}) + +test('a search that finds nothing says so', async () => { + mockFetch({ 'GET /api/v1/artists': () => ({ items: [], total: 0, limit: 6, offset: 0 }) }) + renderPicker() + await userEvent.type(box(), 'zzz') + expect(await screen.findByText('Nothing matches “zzz”.')).toBeInTheDocument() }) test('a chip can be taken away', async () => { diff --git a/web/src/pages/discover/SeedPicker.tsx b/web/src/pages/discover/SeedPicker.tsx index da7041b..239ffc3 100644 --- a/web/src/pages/discover/SeedPicker.tsx +++ b/web/src/pages/discover/SeedPicker.tsx @@ -41,7 +41,15 @@ export default function SeedPicker({ const q = Array.from(typed.trim()).slice(0, MAX_QUERY_LENGTH).join('') const found = useArtistList(q, { pageSize: SHOWN, enabled: q !== '' && !full }) const chosen = new Set(seeds.map((s) => s.id)) - const offered = (found.data?.items ?? []).filter((a) => !chosen.has(a.id)) + const matches = found.data?.items ?? [] + const offered = matches.filter((a) => !chosen.has(a.id)) + + function choose(seed: Seed) { + onAdd(seed) + // Done with this one: the box is ready for the next. + setText('') + setTyped('') + } return (
{t('discover.seeds.max', { count: MAX_SEEDS })}
} - {!full && q !== '' && found.isSuccess && offered.length === 0 &&+
{t('discover.because', { names: suggestion.because.map((b) => b.artist.name).join(', ') })}
)}