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 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 | */ |
| 8 | export {}; // a module: the page awaits at its top level |
| 9 | |
| 10 | const poster = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='2' height='3'/%3E"; |
| 11 | const asked: string[] = []; |
| 12 | window.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 | |
| 23 | await import("../dist/combobox.js"); |
| 24 | const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms)); |
| 25 | const input = document.querySelector("#q") as HTMLInputElement; |
| 26 | const popup = document.querySelector("pebble-combobox .popup") as HTMLElement; |
| 27 | const key = (k: string) => input.dispatchEvent(new KeyboardEvent("keydown", { key: k, bubbles: true, cancelable: true })); |
| 28 | |
| 29 | input.focus(); |
| 30 | for (const value of ["m", "ma", "mam"]) { |
| 31 | input.value = value; |
| 32 | input.dispatchEvent(new Event("input", { bubbles: true })); |
| 33 | await sleep(50); |
| 34 | } |
| 35 | await sleep(500); |
| 36 | const shown = getComputedStyle(popup).display !== "none"; |
| 37 | const below = popup.getBoundingClientRect().top >= input.getBoundingClientRect().bottom; |
| 38 | const rows = [...popup.querySelectorAll("li")].map(li => li.getBoundingClientRect().height); |
| 39 | key("ArrowDown"); |
| 40 | key("ArrowDown"); |
| 41 | const second = popup.querySelectorAll("li")[1]!; |
| 42 | const activeId = input.getAttribute("aria-activedescendant"); |
| 43 | const selected = second.getAttribute("aria-selected"); |
| 44 | const activeBg = getComputedStyle(second).backgroundColor; |
| 45 | key("Escape"); |
| 46 | const closedByEscape = getComputedStyle(popup).display === "none" && input.getAttribute("aria-expanded") === "false"; |
| 47 | key("ArrowDown"); |
| 48 | const reopened = getComputedStyle(popup).display !== "none"; |
| 49 | document.getElementById("dehors")!.dispatchEvent(new PointerEvent("pointerdown", { bubbles: true })); |
| 50 | const closedOutside = getComputedStyle(popup).display === "none"; |
| 51 | |
| 52 | const 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 | }; |
| 67 | document.getElementById("smoke")!.textContent = `SMOKE:${JSON.stringify(verdict)}`; |