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.
110 lines
3.7 KiB
TypeScript
110 lines
3.7 KiB
TypeScript
// @vitest-environment jsdom
|
|
//
|
|
// The owner's call: a freshly opened channel page shows what is still unwatched, and a watch state the
|
|
// viewer picks there sticks — a reload (a fresh mount, seeded from the stored preference) keeps it.
|
|
import type { ReactNode } from "react";
|
|
import { describe, it, expect, vi, beforeAll, afterEach } from "vitest";
|
|
import { render, cleanup, act } from "@testing-library/react";
|
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
import type { FeedFilters } from "../lib/api";
|
|
|
|
vi.mock("react-i18next", async (importOriginal) => ({
|
|
...(await importOriginal<typeof import("react-i18next")>()),
|
|
useTranslation: () => ({ t: (key: string) => key, i18n: { language: "en" } }),
|
|
}));
|
|
vi.mock("./navigationContext", () => ({
|
|
useNavigationActions: () => ({ closeChannel: vi.fn(), openChannel: vi.fn() }),
|
|
}));
|
|
vi.mock("./confirmContext", () => ({ useConfirm: () => async () => true }));
|
|
vi.mock("./feedFiltersContext", () => ({
|
|
useFeedFilters: () => ({ includeNormal: true, includeShorts: false, includeLive: false }),
|
|
}));
|
|
const feed = vi.hoisted(() => ({
|
|
last: null as null | { filters: FeedFilters; setFilters: (f: FeedFilters) => void },
|
|
}));
|
|
vi.mock("./Feed", () => ({
|
|
default: (p: { filters: FeedFilters; setFilters: (f: FeedFilters) => void }) => {
|
|
feed.last = p;
|
|
return null;
|
|
},
|
|
}));
|
|
vi.mock("./ChannelAbout", () => ({ default: () => null }));
|
|
vi.mock("./ui/PageShell", async (importOriginal) => ({
|
|
...(await importOriginal<typeof import("./ui/PageShell")>()),
|
|
PageToolbar: ({ children }: { children?: ReactNode }) => <>{children}</>,
|
|
}));
|
|
|
|
import ChannelPage from "./ChannelPage";
|
|
import { api, type ChannelDetail, type Me } from "../lib/api";
|
|
import { qk } from "../lib/queryKeys";
|
|
|
|
beforeAll(() => {
|
|
class Stub {
|
|
observe() {}
|
|
unobserve() {}
|
|
disconnect() {}
|
|
takeRecords() {
|
|
return [];
|
|
}
|
|
}
|
|
globalThis.ResizeObserver ??= Stub as unknown as typeof ResizeObserver;
|
|
globalThis.IntersectionObserver ??= Stub as unknown as typeof IntersectionObserver;
|
|
});
|
|
afterEach(() => {
|
|
cleanup();
|
|
vi.restoreAllMocks();
|
|
feed.last = null;
|
|
});
|
|
|
|
const CH = "UCqoAEDirJPjEUFcF2FklnBA";
|
|
|
|
function mount(preferences: Record<string, unknown> = {}) {
|
|
vi.spyOn(api, "channelDetail").mockResolvedValue({
|
|
id: CH,
|
|
title: "StarTalk",
|
|
subscribed: true,
|
|
stored_videos: 10,
|
|
} as unknown as ChannelDetail);
|
|
vi.spyOn(api, "tags").mockResolvedValue([] as never);
|
|
const save = vi.spyOn(api, "savePrefs").mockResolvedValue({} as never);
|
|
const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } });
|
|
qc.setQueryData(qk.me(), { id: 1, preferences } as unknown as Me);
|
|
render(
|
|
<QueryClientProvider client={qc}>
|
|
<ChannelPage
|
|
channelId={CH}
|
|
initialName="StarTalk"
|
|
me={{ id: 1, can_write: true, can_read: true } as unknown as Me}
|
|
view="cards"
|
|
setView={() => {}}
|
|
onShowInFeed={() => {}}
|
|
/>
|
|
</QueryClientProvider>,
|
|
);
|
|
return save;
|
|
}
|
|
|
|
describe("ChannelPage — the watch state", () => {
|
|
it("shows only the unwatched videos on a freshly opened page", () => {
|
|
mount();
|
|
expect(feed.last?.filters.show).toBe("unwatched");
|
|
});
|
|
|
|
it("stores a picked watch state", () => {
|
|
const save = mount();
|
|
act(() => feed.last!.setFilters({ ...feed.last!.filters, show: "all" }));
|
|
expect(feed.last?.filters.show).toBe("all");
|
|
expect(save).toHaveBeenCalledWith({ channelShow: "all" });
|
|
});
|
|
|
|
it("keeps the stored watch state after a reload", () => {
|
|
mount({ channelShow: "watched" });
|
|
expect(feed.last?.filters.show).toBe("watched");
|
|
});
|
|
|
|
it("falls back to unwatched for a stored value it does not know", () => {
|
|
mount({ channelShow: "bogus" });
|
|
expect(feed.last?.filters.show).toBe("unwatched");
|
|
});
|
|
});
|