Eight verified findings from the sprint deep-review: - Transcode cap: _enforce_cap now counts only transcode sessions, so a live remux (stream-copy) stream can no longer be LRU-evicted mid-play — matching the config comment + the HU/EN Config hint that promise remux is uncapped. - Player Back: the browser/mouse Back interceptor (BackClose) now also mounts for the stats overlay and up-next card, so Back closes them first instead of ejecting the whole player (keyboard/Esc already did). - Honest cold-start: loadSession clears sessionIsTranscode up front, so a transcode->direct/remux switch no longer flashes a stale "Preparing stream..." during the session request. - Stats overlay a11y: the close (X) buttons in the stats, help and info overlays now read as "Close"/"Bezaras" (new plex.player.close key), not "Back"; dropped aria-live from the per-second stat grid so a screen reader is not flooded with telemetry. Tests: route-level transcode routing (transcode item -> HLS re-encode session, remux stays copy, direct opens none); start_session threading the preset/crf/max_height knobs + hw/preexec into the ffmpeg argv; UpNextCard countdown auto-advance, Play-now, Cancel and the S?-E? heading fallback. Also brings UpNextCard.tsx / plexStats.ts / plexStats.test.ts to prettier.
94 lines
3.4 KiB
TypeScript
94 lines
3.4 KiB
TypeScript
// @vitest-environment jsdom
|
|
//
|
|
// The up-next end-card's core behaviour (E6 S4): the countdown that auto-advances at ~10s (the whole
|
|
// point — it REPLACED the old instant jump, so a regression that fires early or never is exactly the
|
|
// bug to guard), the "Play now"/Cancel controls, and the episode heading's null season/episode
|
|
// fallback. i18n is key-passthrough; `../lib/api` is mocked so no network runs; the countdown uses
|
|
// performance.now, which vitest's fake timers advance alongside setInterval.
|
|
import { describe, it, expect, afterEach, vi } from "vitest";
|
|
import { render, screen, fireEvent, cleanup, act } from "@testing-library/react";
|
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
|
|
vi.mock("react-i18next", async (importOriginal) => {
|
|
const actual = await importOriginal<typeof import("react-i18next")>();
|
|
return { ...actual, useTranslation: () => ({ t: (key: string) => key }) };
|
|
});
|
|
|
|
vi.mock("../lib/api", () => ({
|
|
api: { plexItem: vi.fn(), plexImageUrl: () => "/img" },
|
|
}));
|
|
|
|
import { UpNextCard } from "./UpNextCard";
|
|
import { api } from "../lib/api";
|
|
|
|
afterEach(() => {
|
|
cleanup();
|
|
vi.useRealTimers();
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
function renderCard(opts: { onAdvance?: () => void; onCancel?: () => void } = {}) {
|
|
const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } });
|
|
return render(
|
|
<QueryClientProvider client={qc}>
|
|
<UpNextCard
|
|
nextId="e7"
|
|
onAdvance={opts.onAdvance ?? vi.fn()}
|
|
onCancel={opts.onCancel ?? vi.fn()}
|
|
/>
|
|
</QueryClientProvider>,
|
|
);
|
|
}
|
|
|
|
describe("UpNextCard", () => {
|
|
it("auto-advances after the ~10s countdown, and NOT before", () => {
|
|
vi.useFakeTimers();
|
|
// A never-resolving detail query: the heading is irrelevant here and this avoids async state
|
|
// updates racing the fake clock.
|
|
(api.plexItem as ReturnType<typeof vi.fn>).mockReturnValue(new Promise(() => {}));
|
|
const onAdvance = vi.fn();
|
|
renderCard({ onAdvance });
|
|
|
|
act(() => {
|
|
vi.advanceTimersByTime(9000);
|
|
});
|
|
expect(onAdvance).not.toHaveBeenCalled(); // still counting down
|
|
|
|
act(() => {
|
|
vi.advanceTimersByTime(1200);
|
|
});
|
|
expect(onAdvance).toHaveBeenCalledTimes(1); // crossed zero → advanced exactly once
|
|
});
|
|
|
|
it("'Play now' advances immediately, without waiting for the countdown", () => {
|
|
(api.plexItem as ReturnType<typeof vi.fn>).mockReturnValue(new Promise(() => {}));
|
|
const onAdvance = vi.fn();
|
|
renderCard({ onAdvance });
|
|
fireEvent.click(screen.getByRole("button", { name: /playNow/ }));
|
|
expect(onAdvance).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("Cancel dismisses via onCancel and does not advance", () => {
|
|
(api.plexItem as ReturnType<typeof vi.fn>).mockReturnValue(new Promise(() => {}));
|
|
const onAdvance = vi.fn();
|
|
const onCancel = vi.fn();
|
|
renderCard({ onAdvance, onCancel });
|
|
fireEvent.click(screen.getByText("plex.player.upNext.cancel"));
|
|
expect(onCancel).toHaveBeenCalledTimes(1);
|
|
expect(onAdvance).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("an episode heading falls back to S?·E? when season/episode are null", async () => {
|
|
(api.plexItem as ReturnType<typeof vi.fn>).mockResolvedValue({
|
|
id: "e7",
|
|
kind: "episode",
|
|
show_title: "Westworld",
|
|
title: "The Adversary",
|
|
season_number: null,
|
|
episode_number: null,
|
|
});
|
|
renderCard();
|
|
expect(await screen.findByText("Westworld · S?·E?")).toBeTruthy();
|
|
});
|
|
});
|