Files
siftlode/frontend/src/lib/nextPage.wiring.contract.test.ts
T
peter 63a0fecc8b refactor(frontend): the flat components/ folder moves into shell/, modules/<page>/ and features/<name>/
A pure move (git mv, history kept): 333 files leave components/, which now holds only the platform
layer (ui/) and the legal pages. The shell is the frame (App, header, nav rail, palette, boot); each
page lives in modules/<page>/ with its rail, store and tests; what several pages share sits in
features/<name>/; the shared-link page is watch/. Domain-free helpers went straight to ui/
(ViewSwitcher, FilterRail, the confirm dialog, the language switcher, the copy rows).

Every relative specifier was rewritten (imports, dynamic imports, vi.mock, new URL), and the
contract tests that scan sources now scan the whole app source, not only components/ — each glob
was counted before and after so none went green over fewer files. The locale-format rule matched
`/src/components/` only, so the move would have taken ~300 files out from under its i18n-singleton
check; it now covers every folder that holds components, with a test per folder.
2026-10-22 23:12:45 +02:00

60 lines
2.8 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { readSources } from "./rawSources.testkit";
// Every infinite list's read-ahead waits while the list fetches ANYTHING and runs again when the fetch
// settles. A read-ahead that only checks `isFetchingNextPage` calls during a background
// refetch, joins it through NEXT_PAGE and loads no page: the grid stalls at its loaded end until the
// reader scrolls the range. The jsdom virtualizer measures nothing, so the wiring is pinned in source.
const files = readSources(__dirname, ["../**/*.tsx", "!../**/*.test.tsx", "!../design-lab/**"]);
const source = (name: string) => {
const hit = Object.entries(files).find(([path]) => path.endsWith(`/${name}`));
if (!hit) throw new Error(`no ${name}`);
return hit[1] as string;
};
describe("an infinite list's read-ahead", () => {
it.each(["ui/VirtualGrid.tsx", "PlexBrowse.tsx"])(
"%s gates on mayReadAhead and re-runs on isFetching",
(file) => {
const src = source(file);
expect(src).toMatch(/mayReadAhead\(hasNextPage, isFetching\)/);
expect(src).toMatch(/\[[^\]]*\bisFetching\b[^\]]*fetchNextPage\]\);/);
expect(src).not.toMatch(/hasNextPage && !isFetchingNextPage/);
},
);
it("the feed hands the grid the query's isFetching", () => {
expect(source("Feed.tsx")).toMatch(/isFetching=\{query\.isFetching\}/);
});
// Retry is off, so a failed page settles at once; a read-ahead that re-runs on the settle would
// request it again once a round-trip while the end is in view.
it("stands down at a failed next page", () => {
expect(source("Feed.tsx")).toMatch(
/hasNextPage=\{!!hasNextPage && !query\.isFetchNextPageError\}/,
);
expect(source("PlexBrowse.tsx")).toMatch(
/const hasNextPage = browseQ\.hasNextPage && !isFetchNextPageError;/,
);
});
});
// A click joins an in-flight next page but cancels a background refetch (nextPageOnClick): through
// NEXT_PAGE it would join the refetch and load nothing. NEXT_PAGE is only for the read-aheads, so a
// click site that goes back to it fails here (the YouTube "Load more" was once missed).
describe("a click that loads the next page", () => {
const READ_AHEADS = new Set(["components/ui/VirtualGrid.tsx", "modules/plex/PlexBrowse.tsx"]);
it("uses nextPageOnClick; NEXT_PAGE only in the read-aheads", () => {
const users = Object.entries(files)
.filter(([, src]) => /fetchNextPage\(NEXT_PAGE\)/.test(src as string))
.map(([path]) => path.replace(/^\.\.\//, ""));
expect(users.sort()).toEqual([...READ_AHEADS].sort());
for (const [file, sites] of [
["AdminLogs.tsx", 2],
["Feed.tsx", 2],
["PlexBrowse.tsx", 1],
] as const)
expect(source(file).match(/fetchNextPage\(nextPageOnClick\(/g)?.length, file).toBe(sites);
});
});