tobogganSe connecter

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
67 lignes · 3318 octetsBrut · Historique
1/**
2 * The page half of the combobox smoke (see combobox.html). Stubs the
3 * suggestions endpoint, imports the shipped dist bundle, types a query and
4 * checks on a real engine: one request after the pause, the popup under the
5 * form with 44px rows, the arrow keys and aria-activedescendant, Escape and a
6 * press outside closing it.
7 */
8export {}; // a module: the page awaits at its top level
9
10const poster = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='2' height='3'/%3E";
11const asked: string[] = [];
12window.fetch = (async (url: RequestInfo | URL) => {
13 asked.push(new URL(String(url), location.href).search);
14 return new Response(
15 `<ul>${["Maman, j’ai raté l’avion|1990", "Elfe|2003", "Le Grincheux|2000"]
16 .map(t => t.split("|"))
17 .map(([title, year], i) => `<li><a href="/titres/${i}"><img src="${poster}" alt=""> ${title} <small>${year}</small></a></li>`)
18 .join("")}</ul>`,
19 { headers: { "content-type": "text/html" } },
20 );
21}) as typeof fetch;
22
23await import("../dist/combobox.js");
24const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
25const input = document.querySelector("#q") as HTMLInputElement;
26const popup = document.querySelector("pebble-combobox .popup") as HTMLElement;
27const key = (k: string) => input.dispatchEvent(new KeyboardEvent("keydown", { key: k, bubbles: true, cancelable: true }));
28
29input.focus();
30for (const value of ["m", "ma", "mam"]) {
31 input.value = value;
32 input.dispatchEvent(new Event("input", { bubbles: true }));
33 await sleep(50);
34}
35await sleep(500);
36const shown = getComputedStyle(popup).display !== "none";
37const below = popup.getBoundingClientRect().top >= input.getBoundingClientRect().bottom;
38const rows = [...popup.querySelectorAll("li")].map(li => li.getBoundingClientRect().height);
39key("ArrowDown");
40key("ArrowDown");
41const second = popup.querySelectorAll("li")[1]!;
42const activeId = input.getAttribute("aria-activedescendant");
43const selected = second.getAttribute("aria-selected");
44const activeBg = getComputedStyle(second).backgroundColor;
45key("Escape");
46const closedByEscape = getComputedStyle(popup).display === "none" && input.getAttribute("aria-expanded") === "false";
47key("ArrowDown");
48const reopened = getComputedStyle(popup).display !== "none";
49document.getElementById("dehors")!.dispatchEvent(new PointerEvent("pointerdown", { bubbles: true }));
50const closedOutside = getComputedStyle(popup).display === "none";
51
52const verdict = {
53 checks: {
54 registered: customElements.get("pebble-combobox") !== undefined,
55 "the field is a 44px combobox": input.getAttribute("role") === "combobox" && input.getBoundingClientRect().height >= 44,
56 "one request, for the last query, after the pause": asked.join("|") === "?q=mam",
57 "the popup shows under the form": shown && below,
58 "each option is a 44px row": rows.length === 3 && rows.every(h => h >= 44),
59 "the arrows activate an option": activeId === second.id && selected === "true",
60 "the active option is highlighted": activeBg !== "rgba(0, 0, 0, 0)",
61 "Escape closes": closedByEscape,
62 "ArrowDown opens again": reopened,
63 "a press outside closes": closedOutside,
64 },
65 observed: { asked, rows, activeId, activeBg },
66};
67document.getElementById("smoke")!.textContent = `SMOKE:${JSON.stringify(verdict)}`;