1
0

fix: refetch item detail after re-match so the play button stays honest

This commit is contained in:
2026-09-03 22:54:09 +02:00
parent ece18d125b
commit 47858b1788
2 changed files with 22 additions and 4 deletions

View File

@@ -60,10 +60,7 @@ export default function ItemPage() {
if (!item) return
void api
.setMatch(item.id, albumId)
.then((updated) => {
applyUpdated(updated)
setMutationError(null)
})
.then(() => refetch())
.catch(() => setMutationError("That didn't work — check your connection and try again."))
}

View File

@@ -119,6 +119,27 @@ describe('ItemPage', () => {
await waitFor(() => expect(api.setMatch).toHaveBeenCalledWith(1, 77))
})
it('re-match refreshes the play button state', async () => {
vi.mocked(api.getItem)
.mockResolvedValueOnce({ ...rippedItem, matchedAlbum: null } as never)
.mockResolvedValue({ ...rippedItem } as never)
vi.mocked(api.searchAlbums).mockResolvedValue({
albums: [{ id: 77, subsonicId: 'a1', title: 'Motion (Remaster)', artist: 'The Cinematic Orchestra' }],
} as never)
vi.mocked(api.setMatch).mockResolvedValue({ ...item } as never)
renderItem()
await waitFor(() => expect(screen.getByRole('heading', { name: 'Motion' })).toBeTruthy())
expect(screen.queryByRole('button', { name: /play album/i })).toBeNull()
await userEvent.click(screen.getByRole('button', { name: /re-match/i }))
await userEvent.click(screen.getByRole('button', { name: /^search$/i }))
const albumRadio = await screen.findByRole('radio', { name: /motion \(remaster\)/i })
await userEvent.click(albumRadio)
await userEvent.click(screen.getByRole('button', { name: /^link$/i }))
await waitFor(() => expect(screen.getByRole('button', { name: /play album/i })).toBeTruthy())
})
it('unlink clears the match', async () => {
vi.mocked(api.setMatch).mockResolvedValue(item as never)
renderItem()