Files
siftlode/frontend/src/lib/plexImage.test.ts
T
peter fb2e3d8490 perf(plex): a card fetches its picture at a card's size, not the detail page's
Cards fetched the full cuts: a 400x600 poster (~38 KB) for a ~144px picture and the 1280x720
backdrop (~162 KB) for a ~212px shelf picture. The image proxy now also cuts thumb_sm (240x360)
and art_sm (480x270), cached apart; card pictures (grid, shelves, collection tiles, Up next) carry
both in srcset with sizes=auto, so the browser picks by laid-out width and DPR. Localdev:
17 KB a poster, 56 KB a backdrop. The detail page keeps the full cuts.
2026-10-02 21:27:13 +02:00

27 lines
859 B
TypeScript

import { describe, expect, it } from "vitest";
import { cardImage } from "./plexImage";
describe("cardImage", () => {
it("offers a poster's small cut beside the full one", () => {
expect(cardImage("/api/plex/image/123")).toEqual({
src: "/api/plex/image/123",
srcSet: "/api/plex/image/123?variant=thumb_sm 240w, /api/plex/image/123 400w",
sizes: "auto, 200px",
});
});
it("offers a backdrop's small cut beside the full one", () => {
expect(cardImage("/api/plex/image/123?variant=art").srcSet).toBe(
"/api/plex/image/123?variant=art_sm 480w, /api/plex/image/123?variant=art 1280w",
);
});
it("leaves any other picture alone", () => {
expect(cardImage("https://image.tmdb.org/x.jpg")).toEqual({
src: "https://image.tmdb.org/x.jpg",
});
expect(cardImage("")).toEqual({ src: "" });
});
});