1
0

fix: clear re-match selection when searching again

This commit is contained in:
2026-08-29 23:27:54 +02:00
parent e912d9e485
commit 71423c7ab7
2 changed files with 21 additions and 1 deletions

View File

@@ -25,7 +25,10 @@ export default function ItemPage() {
function searchAlbums() {
void api
.searchAlbums(albumQuery)
.then((res) => setAlbums(res.albums))
.then((res) => {
setAlbums(res.albums)
setPickedAlbum(null)
})
.catch(() => setAlbums([]))
}

View File

@@ -110,4 +110,21 @@ describe('ItemPage', () => {
await waitFor(() => expect(api.deleteItem).toHaveBeenCalledWith(1))
await waitFor(() => expect(screen.getByText('library')).toBeTruthy())
})
it('re-match clears the picked album when searching again', async () => {
vi.mocked(api.searchAlbums)
.mockResolvedValueOnce({
albums: [{ id: 77, subsonicId: 'a1', title: 'Motion (Remaster)', artist: 'The Cinematic Orchestra' }],
} as never)
.mockResolvedValueOnce({
albums: [{ id: 88, subsonicId: 'a2', title: 'Something Else', artist: 'Other Artist' }],
} as never)
renderItem()
await userEvent.click(await screen.findByRole('button', { name: /re-match/i }))
await userEvent.click(screen.getByRole('button', { name: /^search$/i }))
await userEvent.click(await screen.findByRole('radio', { name: /motion \(remaster\)/i }))
await userEvent.click(screen.getByRole('button', { name: /^search$/i }))
const linkBtn = await screen.findByRole('button', { name: /^link$/i })
expect(linkBtn).toHaveProperty('disabled', true)
})
})