library
Prebuilt pebble components: drop-in custom elements, no compiler needed
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runAucun
0Étoiles
0Forks
2Issues
| 1 | /** |
| 2 | * The page half of the more smoke (see more.html). Stubs two next pages (the |
| 3 | * second without a next link: the end of the feed), measures the link before |
| 4 | * JS takes it, imports the shipped dist bundle and lets a real |
| 5 | * IntersectionObserver load the first page (the list is short, so the link is |
| 6 | * within 600px at once), then activates the new link for the second. |
| 7 | * |
| 8 | * Why not let the observer load both: under --dump-dom's virtual time Chromium |
| 9 | * renders about one frame in total, and IntersectionObserver only delivers on |
| 10 | * a rendering frame, so the new link's first entry never comes. A real browser |
| 11 | * renders every frame; the happy-dom suite proves the new link is observed. |
| 12 | */ |
| 13 | export {}; // a module: the page awaits at its top level |
| 14 | |
| 15 | const page = (from: number, next?: string) => |
| 16 | `<!doctype html><ol data-feed-items>${Array.from({ length: 5 }, (_, i) => `<li>${from + i}</li>`).join("")}</ol>` + |
| 17 | (next ? `<pebble-more><a href="${next}" data-more>Voir plus</a></pebble-more>` : ""); |
| 18 | const pages: Record<string, string> = { "/fil?apres=5": page(6, "/fil?apres=10"), "/fil?apres=10": page(11) }; |
| 19 | const asked: string[] = []; |
| 20 | window.fetch = (async (url: RequestInfo | URL, init?: RequestInit) => { |
| 21 | const path = new URL(String(url), location.href); |
| 22 | const key = path.pathname + path.search; |
| 23 | asked.push(`${key} ${(init?.headers as Record<string, string>)["X-Fragment"]}`); |
| 24 | return new Response(pages[key] ?? "", { status: pages[key] ? 200 : 404, headers: { "content-type": "text/html" } }); |
| 25 | }) as typeof fetch; |
| 26 | |
| 27 | const link = document.querySelector("pebble-more a") as HTMLAnchorElement; |
| 28 | const linkHeight = link.getBoundingClientRect().height; // no sheet linked yet: the element brings it |
| 29 | const before = location.href; |
| 30 | await import("../dist/more.js"); |
| 31 | const enhancedHeight = link.getBoundingClientRect().height; |
| 32 | const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms)); |
| 33 | const settle = () => sleep(500); |
| 34 | // the observer's first entry waits for a rendering frame, which virtual time hands out sparingly |
| 35 | for (let waited = 0; waited < 5000 && document.querySelectorAll("#fil > li").length < 10; waited += 100) await sleep(100); |
| 36 | await settle(); |
| 37 | const afterObserver = document.querySelectorAll("#fil > li").length; |
| 38 | (document.querySelector("pebble-more a[data-more]") as HTMLAnchorElement | null)?.click(); |
| 39 | await settle(); |
| 40 | |
| 41 | const host = document.querySelector("pebble-more") as HTMLElement; |
| 42 | const status = host.querySelector("[role=status]") as HTMLElement; |
| 43 | const items = [...document.querySelectorAll("#fil > li")].map(li => li.textContent); |
| 44 | const verdict = { |
| 45 | checks: { |
| 46 | registered: customElements.get("pebble-more") !== undefined, |
| 47 | "the link is a 44px target once the sheet applies": enhancedHeight >= 44, |
| 48 | "the observer loaded the first page": afterObserver === 10, |
| 49 | "both next pages loaded, in order, as fragments": asked.join("|") === "/fil?apres=5 1|/fil?apres=10 1", |
| 50 | "the items were appended to the list": items.join(",") === Array.from({ length: 15 }, (_, i) => String(i + 1)).join(","), |
| 51 | "the end of the feed removed the link": host.querySelector("a[data-more]") === null && host.hasAttribute("data-done"), |
| 52 | "the last load was announced": status?.textContent?.trim() === "5 de plus", |
| 53 | "the live region is visually hidden": status.getBoundingClientRect().width <= 1, |
| 54 | "the URL is unchanged": location.href === before, |
| 55 | }, |
| 56 | observed: { afterObserver, linkHeight, enhancedHeight, asked, items, status: status?.textContent }, |
| 57 | }; |
| 58 | document.getElementById("smoke")!.textContent = `SMOKE:${JSON.stringify(verdict)}`; |