The code cited its plan instead of saying why: `E28 review J4`, `(R6 S3b)`, `S1 justified…`,
`deep-review round 5`. That plan lives in the private ops repo, so for every reader of this one the
citation was noise, and a sentence whose subject was the plan step ("round 2 showed…") hid its
lesson behind an id. Each one is gone and the "why" kept: a bare citation is deleted, a sentence
carrying a lesson is reworded around it ("a later attempt showed…").
Measured (`scripts/audit_metrics.py`, product code): 652 lines in 270 files carried an epic code by
the definition the next commit holds (507 / 241 by the old, two-digit-only one) -> 0. Across all
code, tests, scripts and configs: ~1100 epic-code lines plus ~320 sprint/round ids.
Behaviour unchanged, checked mechanically: every changed .py file has the same AST once docstrings
are blanked; css/sh/toml/yml/json files are identical once comments are stripped; the only
non-comment changes in TS/JS are test titles, one description string in a contract table, and five
ESLint messages, whose text is all the gates snapshot diff holds. Not touched: Markdown (docs and
the changelog keep their history), Alembic migrations, TV episode notation (`S2 · E5`), DESIGN.md
ids (`C1`, `B4`, `S3h`), tracker ids (`SEC-16`, `DX-17`).
One stale claim fixed on the way: test_hls_reaper's docstring said the player checkpoints "every
10 s whether or not it is playing", which plex/stream.py calls wrong; it now says what the code does.
97 lines
3.4 KiB
TypeScript
97 lines
3.4 KiB
TypeScript
// @vitest-environment jsdom
|
|
//
|
|
// The up-next end-card's core behaviour: 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: () => ({ i18n: { language: "en" }, 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();
|
|
});
|
|
});
|