fix(plex): a Surprise draw stays put until its reshuffle
The rail's query was always stale, so Back from a card's player or page remounted it into a new draw, as did a return to the window: the card just looked at was gone. It now stands until the reshuffle (or another scope, language or filter) asks for a new one.
This commit is contained in:
@@ -7,7 +7,7 @@
|
|||||||
// synchronously. The rails scroll inside a Carousel (useHScroll → ResizeObserver), stubbed for jsdom.
|
// synchronously. The rails scroll inside a Carousel (useHScroll → ResizeObserver), stubbed for jsdom.
|
||||||
import { describe, it, expect, afterEach, beforeAll, vi } from "vitest";
|
import { describe, it, expect, afterEach, beforeAll, vi } from "vitest";
|
||||||
import { act, render, screen, fireEvent, cleanup, waitFor } from "@testing-library/react";
|
import { act, render, screen, fireEvent, cleanup, waitFor } from "@testing-library/react";
|
||||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
import { focusManager, QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
class Stub {
|
class Stub {
|
||||||
@@ -223,6 +223,37 @@ describe("PlexDiscover", () => {
|
|||||||
expect(plexSurprise.mock.calls[1]?.[4]).toEqual(["sp1"]);
|
expect(plexSurprise.mock.calls[1]?.[4]).toEqual(["sp1"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Back from a card's player or page remounts the surface: the draw it left must still be there.
|
||||||
|
it("keeps its draw across a remount and a return to the window; only ↻ redraws", async () => {
|
||||||
|
plexDiscover.mockResolvedValue(fullPayload);
|
||||||
|
plexSurprise.mockResolvedValue({ scope: "both", items: [card("sp1", "Random Pick")] });
|
||||||
|
const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } });
|
||||||
|
const ui = (
|
||||||
|
<QueryClientProvider client={qc}>
|
||||||
|
<PlexDiscover
|
||||||
|
scope="both"
|
||||||
|
onOpenCard={noop}
|
||||||
|
onRestartCard={() => {}}
|
||||||
|
onInfoCard={noop}
|
||||||
|
onGenre={noop}
|
||||||
|
onSeeAllRecent={noop}
|
||||||
|
/>
|
||||||
|
</QueryClientProvider>
|
||||||
|
);
|
||||||
|
const first = render(ui);
|
||||||
|
await screen.findByText("Random Pick");
|
||||||
|
first.unmount();
|
||||||
|
render(ui);
|
||||||
|
await screen.findByText("Random Pick");
|
||||||
|
act(() => {
|
||||||
|
focusManager.setFocused(false);
|
||||||
|
focusManager.setFocused(true);
|
||||||
|
});
|
||||||
|
await new Promise((r) => setTimeout(r, 20));
|
||||||
|
expect(plexSurprise).toHaveBeenCalledTimes(1);
|
||||||
|
focusManager.setFocused(undefined);
|
||||||
|
});
|
||||||
|
|
||||||
it("shows the empty message when every rail is empty", async () => {
|
it("shows the empty message when every rail is empty", async () => {
|
||||||
plexDiscover.mockResolvedValue({
|
plexDiscover.mockResolvedValue({
|
||||||
scope: "both",
|
scope: "both",
|
||||||
|
|||||||
@@ -134,7 +134,10 @@ export default function PlexDiscover({
|
|||||||
shown.map((c) => c.id),
|
shown.map((c) => c.id),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
staleTime: 0,
|
// A draw stands until ↻ (or another scope, language or filter) asks for a new one. A stale one was
|
||||||
|
// redrawn on every remount — Back from the player or a show page — and on a return to the window,
|
||||||
|
// so the card just looked at was gone from the rail it came from.
|
||||||
|
staleTime: Infinity,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Watched toggle over BOTH this surface's cache (so a rail card flips instantly) and the surprise
|
// Watched toggle over BOTH this surface's cache (so a rail card flips instantly) and the surprise
|
||||||
|
|||||||
Reference in New Issue
Block a user