/** * The page half of the vote smoke (see vote.html). Stubs the server's vote * endpoint, imports the shipped dist bundle (the import IS the registration), * presses Cadeau, then Charbon, and checks on a real engine what happy-dom * cannot: the press never navigates, the sheet applies (44px targets, the * pressed side's colour, the bounce animation), and the server's tally wins. */ export {}; // a module: the page awaits at its top level const answers = [ { up: 13, down: 3, mine: 1 }, { up: 12, down: 4, mine: -1 }, ]; const posted: string[] = []; window.fetch = (async (_url: RequestInfo | URL, init?: RequestInit) => { posted.push(String((init?.body as FormData).get("valeur"))); return new Response(JSON.stringify(answers.shift()), { headers: { "content-type": "application/json" } }); }) as typeof fetch; await import("../dist/vote.js"); const settle = (ms = 100) => new Promise(resolve => setTimeout(resolve, ms)); const [up, down] = [...document.querySelectorAll("pebble-vote button")] as HTMLButtonElement[]; const before = location.href; up!.click(); const optimistic = up!.getAttribute("aria-pressed") === "true" && up!.dataset.count === "13"; const bouncing = up!.classList.contains("bounce") && getComputedStyle(up!).animationName === "pebble-vote-bounce"; await settle(); const pressedColour = getComputedStyle(up!).borderTopColor; down!.click(); await settle(500); const verdict = { checks: { registered: customElements.get("pebble-vote") !== undefined, "the buttons are 44px targets": up!.getBoundingClientRect().height >= 44 && up!.getBoundingClientRect().width >= 44, "a press is painted before the answer": optimistic, "the pressed button bounces": bouncing, "the pressed side takes its colour": pressedColour === "rgb(201, 42, 42)", "the server's tally wins": up!.dataset.count === "12" && down!.dataset.count === "4" && down!.getAttribute("aria-pressed") === "true", "aria-label follows": down!.getAttribute("aria-label") === "Charbon (4)", "the bounce ends": !up!.classList.contains("bounce") && !down!.classList.contains("bounce"), "each press posted its side": posted.join(",") === "1,-1", "no navigation": location.href === before, }, observed: { pressedColour, posted }, }; document.getElementById("smoke")!.textContent = `SMOKE:${JSON.stringify(verdict)}`;