/**
* The page half of the more smoke (see more.html). Stubs two next pages (the
* second without a next link: the end of the feed), measures the link before
* JS takes it, imports the shipped dist bundle and lets a real
* IntersectionObserver load the first page (the list is short, so the link is
* within 600px at once), then activates the new link for the second.
*
* Why not let the observer load both: under --dump-dom's virtual time Chromium
* renders about one frame in total, and IntersectionObserver only delivers on
* a rendering frame, so the new link's first entry never comes. A real browser
* renders every frame; the happy-dom suite proves the new link is observed.
*/
export {}; // a module: the page awaits at its top level
const page = (from: number, next?: string) =>
`
${Array.from({ length: 5 }, (_, i) => `- ${from + i}
`).join("")}
` +
(next ? `Voir plus` : "");
const pages: Record = { "/fil?apres=5": page(6, "/fil?apres=10"), "/fil?apres=10": page(11) };
const asked: string[] = [];
window.fetch = (async (url: RequestInfo | URL, init?: RequestInit) => {
const path = new URL(String(url), location.href);
const key = path.pathname + path.search;
asked.push(`${key} ${(init?.headers as Record)["X-Fragment"]}`);
return new Response(pages[key] ?? "", { status: pages[key] ? 200 : 404, headers: { "content-type": "text/html" } });
}) as typeof fetch;
const link = document.querySelector("pebble-more a") as HTMLAnchorElement;
const linkHeight = link.getBoundingClientRect().height; // no sheet linked yet: the element brings it
const before = location.href;
await import("../dist/more.js");
const enhancedHeight = link.getBoundingClientRect().height;
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
const settle = () => sleep(500);
// the observer's first entry waits for a rendering frame, which virtual time hands out sparingly
for (let waited = 0; waited < 5000 && document.querySelectorAll("#fil > li").length < 10; waited += 100) await sleep(100);
await settle();
const afterObserver = document.querySelectorAll("#fil > li").length;
(document.querySelector("pebble-more a[data-more]") as HTMLAnchorElement | null)?.click();
await settle();
const host = document.querySelector("pebble-more") as HTMLElement;
const status = host.querySelector("[role=status]") as HTMLElement;
const items = [...document.querySelectorAll("#fil > li")].map(li => li.textContent);
const verdict = {
checks: {
registered: customElements.get("pebble-more") !== undefined,
"the link is a 44px target once the sheet applies": enhancedHeight >= 44,
"the observer loaded the first page": afterObserver === 10,
"both next pages loaded, in order, as fragments": asked.join("|") === "/fil?apres=5 1|/fil?apres=10 1",
"the items were appended to the list": items.join(",") === Array.from({ length: 15 }, (_, i) => String(i + 1)).join(","),
"the end of the feed removed the link": host.querySelector("a[data-more]") === null && host.hasAttribute("data-done"),
"the last load was announced": status?.textContent?.trim() === "5 de plus",
"the live region is visually hidden": status.getBoundingClientRect().width <= 1,
"the URL is unchanged": location.href === before,
},
observed: { afterObserver, linkHeight, enhancedHeight, asked, items, status: status?.textContent },
};
document.getElementById("smoke")!.textContent = `SMOKE:${JSON.stringify(verdict)}`;