fix: refetch item detail after re-match so the play button stays honest
This commit is contained in:
@@ -60,10 +60,7 @@ export default function ItemPage() {
|
|||||||
if (!item) return
|
if (!item) return
|
||||||
void api
|
void api
|
||||||
.setMatch(item.id, albumId)
|
.setMatch(item.id, albumId)
|
||||||
.then((updated) => {
|
.then(() => refetch())
|
||||||
applyUpdated(updated)
|
|
||||||
setMutationError(null)
|
|
||||||
})
|
|
||||||
.catch(() => setMutationError("That didn't work — check your connection and try again."))
|
.catch(() => setMutationError("That didn't work — check your connection and try again."))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -119,6 +119,27 @@ describe('ItemPage', () => {
|
|||||||
await waitFor(() => expect(api.setMatch).toHaveBeenCalledWith(1, 77))
|
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 () => {
|
it('unlink clears the match', async () => {
|
||||||
vi.mocked(api.setMatch).mockResolvedValue(item as never)
|
vi.mocked(api.setMatch).mockResolvedValue(item as never)
|
||||||
renderItem()
|
renderItem()
|
||||||
|
|||||||
Reference in New Issue
Block a user