/** * The page half of the combobox smoke (see combobox.html). Stubs the * suggestions endpoint, imports the shipped dist bundle, types a query and * checks on a real engine: one request after the pause, the popup under the * form with 44px rows, the arrow keys and aria-activedescendant, Escape and a * press outside closing it. */ export {}; // a module: the page awaits at its top level const poster = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='2' height='3'/%3E"; const asked: string[] = []; window.fetch = (async (url: RequestInfo | URL) => { asked.push(new URL(String(url), location.href).search); return new Response( ``, { headers: { "content-type": "text/html" } }, ); }) as typeof fetch; await import("../dist/combobox.js"); const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms)); const input = document.querySelector("#q") as HTMLInputElement; const popup = document.querySelector("pebble-combobox .popup") as HTMLElement; const key = (k: string) => input.dispatchEvent(new KeyboardEvent("keydown", { key: k, bubbles: true, cancelable: true })); input.focus(); for (const value of ["m", "ma", "mam"]) { input.value = value; input.dispatchEvent(new Event("input", { bubbles: true })); await sleep(50); } await sleep(500); const shown = getComputedStyle(popup).display !== "none"; const below = popup.getBoundingClientRect().top >= input.getBoundingClientRect().bottom; const rows = [...popup.querySelectorAll("li")].map(li => li.getBoundingClientRect().height); key("ArrowDown"); key("ArrowDown"); const second = popup.querySelectorAll("li")[1]!; const activeId = input.getAttribute("aria-activedescendant"); const selected = second.getAttribute("aria-selected"); const activeBg = getComputedStyle(second).backgroundColor; key("Escape"); const closedByEscape = getComputedStyle(popup).display === "none" && input.getAttribute("aria-expanded") === "false"; key("ArrowDown"); const reopened = getComputedStyle(popup).display !== "none"; document.getElementById("dehors")!.dispatchEvent(new PointerEvent("pointerdown", { bubbles: true })); const closedOutside = getComputedStyle(popup).display === "none"; const verdict = { checks: { registered: customElements.get("pebble-combobox") !== undefined, "the field is a 44px combobox": input.getAttribute("role") === "combobox" && input.getBoundingClientRect().height >= 44, "one request, for the last query, after the pause": asked.join("|") === "?q=mam", "the popup shows under the form": shown && below, "each option is a 44px row": rows.length === 3 && rows.every(h => h >= 44), "the arrows activate an option": activeId === second.id && selected === "true", "the active option is highlighted": activeBg !== "rgba(0, 0, 0, 0)", "Escape closes": closedByEscape, "ArrowDown opens again": reopened, "a press outside closes": closedOutside, }, observed: { asked, rows, activeId, activeBg }, }; document.getElementById("smoke")!.textContent = `SMOKE:${JSON.stringify(verdict)}`;