A dedicated Plex "Discover" landing — a stack of horizontal Carousel rails served from ONE consolidated read (serve-from-DB, no live Plex/TMDB call): - GET /api/plex/discover → continue_watching (in-progress movies + shows, most recently progressed) · recently_added · genres (top-N tiles) · because_you_watched (recs of the most-recent watched, TMDB-enriched movie, resolved to library rows by guid via serve_block's resolver). - GET /api/plex/surprise → a fresh random, scope-bounded sample for the ↻ rail. Frontend: PlexDiscover.tsx (rails reuse the S1 Carousel + S3 PlexPosterCard; colored genre tiles → tap to filter the grid; ↻ reshuffles the surprise rail alone). Discover is now the root sub-view; the flat grid becomes the bookmarkable "Browse all" secondary view (?v=browse) reached by a header search/filter (a browse-intent flip) or the new Discover⟷Browse toggle. resolve_recs is promoted from _resolve_recs (now cross-module). Tests: test_plex_discover.py (rail shape/order, continue-watching, because-you-watched + null, surprise bounds, scope) and PlexDiscover.dom.test.tsx; plexSubUrl round-trip updated for discover-root/grid-browse. Backend lane 393, vitest 332.
72 lines
2.9 KiB
TypeScript
72 lines
2.9 KiB
TypeScript
// PLEX_SUB_URL encode/decode round-trip + guards. Extracted from PlexBrowse for this test (E4
|
|
// deep-review deferred gap). Pure — no DOM, no history.
|
|
import { describe, it, expect } from "vitest";
|
|
import { PLEX_SUB_URL as U, type Sub } from "./plexSubUrl";
|
|
|
|
describe("PLEX_SUB_URL encode", () => {
|
|
it("mirrors each bookmarkable sub-view to ?v=<kind>:<args>", () => {
|
|
expect(U.encode({ kind: "grid" })).toBe("browse"); // the flat "Browse all" grid (E5 S4)
|
|
expect(U.encode({ kind: "show", id: "s1" })).toBe("show:s1");
|
|
expect(U.encode({ kind: "season", showId: "s1", seasonId: "se2" })).toBe("season:s1:se2");
|
|
expect(U.encode({ kind: "info", id: "m9" })).toBe("info:m9");
|
|
expect(U.encode({ kind: "person", name: "Jane Doe" })).toBe("person:Jane Doe");
|
|
expect(U.encode({ kind: "playlist", id: 12 })).toBe("playlist:12");
|
|
});
|
|
|
|
it("does NOT mirror the root Discover landing or the ephemeral player (encode → null)", () => {
|
|
expect(U.encode({ kind: "discover" })).toBeNull();
|
|
expect(U.encode({ kind: "player", id: "m9" })).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("PLEX_SUB_URL round-trip", () => {
|
|
const cases: Sub[] = [
|
|
{ kind: "grid" },
|
|
{ kind: "show", id: "s1" },
|
|
{ kind: "season", showId: "s1", seasonId: "se2" },
|
|
{ kind: "info", id: "m9" },
|
|
{ kind: "person", name: "Jane Doe" },
|
|
{ kind: "playlist", id: 12 },
|
|
];
|
|
it.each(cases)("encode→decode is identity for %o", (view) => {
|
|
const raw = U.encode(view);
|
|
expect(raw).not.toBeNull();
|
|
expect(U.decode(raw as string)).toEqual(view);
|
|
});
|
|
|
|
it("a person name containing ':' round-trips (tail after the first colon)", () => {
|
|
const view: Sub = { kind: "person", name: "Dr: Strange: Origins" };
|
|
expect(U.decode(U.encode(view) as string)).toEqual(view);
|
|
});
|
|
});
|
|
|
|
describe("PLEX_SUB_URL decode guards", () => {
|
|
it("rejects a playlist id that is not a positive integer", () => {
|
|
expect(U.decode("playlist:")).toBeNull(); // Number("")===0, not >0
|
|
expect(U.decode("playlist:0")).toBeNull();
|
|
expect(U.decode("playlist:-1")).toBeNull();
|
|
expect(U.decode("playlist:1.5")).toBeNull();
|
|
expect(U.decode("playlist:abc")).toBeNull();
|
|
expect(U.decode("playlist:12")).toEqual({ kind: "playlist", id: 12 });
|
|
});
|
|
|
|
it("requires both ids for a season", () => {
|
|
expect(U.decode("season:s1")).toBeNull();
|
|
expect(U.decode("season:")).toBeNull();
|
|
expect(U.decode("season:s1:se2")).toEqual({ kind: "season", showId: "s1", seasonId: "se2" });
|
|
});
|
|
|
|
it("requires a non-empty arg for show / info / person", () => {
|
|
expect(U.decode("show:")).toBeNull();
|
|
expect(U.decode("info:")).toBeNull();
|
|
expect(U.decode("person:")).toBeNull();
|
|
});
|
|
|
|
it("rejects an unknown kind or garbage", () => {
|
|
expect(U.decode("grid")).toBeNull();
|
|
expect(U.decode("player:m9")).toBeNull(); // player is not URL-restorable
|
|
expect(U.decode("bogus")).toBeNull();
|
|
expect(U.decode("")).toBeNull();
|
|
});
|
|
});
|