fix(plex): a Surprise card whose watched toggle failed is put back

Deep-review round 3 of bug hunt 2026-09 — the sibling of the collection page's fix (d349bc90).
Discover's toggle flips the Surprise draw too, but its resync refetches only the rails (refetching the
draw would reshuffle it under the viewer), so a refused toggle stayed flipped there. toggleWatchState
takes an optional `revert`, called on a failure only; the queryKeys comment that claimed the watched
toggle invalidates the Surprise key now says what the code does.
This commit is contained in:
2026-09-11 18:05:30 +02:00
parent 76b5f7c93e
commit 785080f3da
4 changed files with 47 additions and 7 deletions
@@ -235,4 +235,31 @@ describe("PlexDiscover", () => {
);
await screen.findByText("plex.discover.empty");
});
it("puts a Surprise card back when its watched toggle fails", async () => {
// The resync refetches the rails but not the Surprise draw (that would reshuffle it), so a
// refused toggle stayed flipped there — the sibling of the collection page's fix.
plexDiscover.mockResolvedValue({
...fullPayload,
continue_watching: [],
recently_watched: [],
recently_added: [],
because_you_watched: null,
});
plexSurprise.mockResolvedValue({ scope: "both", items: [card("sp1", "Random Pick")] });
plexSetState.mockRejectedValueOnce(new Error("refused"));
wrap(
<PlexDiscover
scope="both"
onOpenCard={noop}
onInfoCard={noop}
onGenre={noop}
onSeeAllRecent={noop}
/>,
);
fireEvent.click(await screen.findByLabelText("plex.markWatched"));
await waitFor(() => expect(plexSetState).toHaveBeenCalledWith("sp1", "watched"));
await waitFor(() => expect(screen.getByLabelText("plex.markWatched")).toBeTruthy());
expect(screen.queryByLabelText("plex.markUnwatched")).toBeNull();
});
});