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 vote smoke (see vote.html). Stubs the server's vote |
| 3 | * endpoint, imports the shipped dist bundle (the import IS the registration), |
| 4 | * presses Cadeau, then Charbon, and checks on a real engine what happy-dom |
| 5 | * cannot: the press never navigates, the sheet applies (44px targets, the |
| 6 | * pressed side's colour, the bounce animation), and the server's tally wins. |
| 7 | */ |
| 8 | export {}; // a module: the page awaits at its top level |
| 9 | |
| 10 | const answers = [ |
| 11 | { up: 13, down: 3, mine: 1 }, |
| 12 | { up: 12, down: 4, mine: -1 }, |
| 13 | ]; |
| 14 | const posted: string[] = []; |
| 15 | window.fetch = (async (_url: RequestInfo | URL, init?: RequestInit) => { |
| 16 | posted.push(String((init?.body as FormData).get("valeur"))); |
| 17 | return new Response(JSON.stringify(answers.shift()), { headers: { "content-type": "application/json" } }); |
| 18 | }) as typeof fetch; |
| 19 | |
| 20 | await import("../dist/vote.js"); |
| 21 | const settle = (ms = 100) => new Promise(resolve => setTimeout(resolve, ms)); |
| 22 | const [up, down] = [...document.querySelectorAll("pebble-vote button")] as HTMLButtonElement[]; |
| 23 | const before = location.href; |
| 24 | |
| 25 | up!.click(); |
| 26 | const optimistic = up!.getAttribute("aria-pressed") === "true" && up!.dataset.count === "13"; |
| 27 | const bouncing = up!.classList.contains("bounce") && getComputedStyle(up!).animationName === "pebble-vote-bounce"; |
| 28 | await settle(); |
| 29 | const pressedColour = getComputedStyle(up!).borderTopColor; |
| 30 | down!.click(); |
| 31 | await settle(500); |
| 32 | |
| 33 | const verdict = { |
| 34 | checks: { |
| 35 | registered: customElements.get("pebble-vote") !== undefined, |
| 36 | "the buttons are 44px targets": up!.getBoundingClientRect().height >= 44 && up!.getBoundingClientRect().width >= 44, |
| 37 | "a press is painted before the answer": optimistic, |
| 38 | "the pressed button bounces": bouncing, |
| 39 | "the pressed side takes its colour": pressedColour === "rgb(201, 42, 42)", |
| 40 | "the server's tally wins": up!.dataset.count === "12" && down!.dataset.count === "4" && down!.getAttribute("aria-pressed") === "true", |
| 41 | "aria-label follows": down!.getAttribute("aria-label") === "Charbon (4)", |
| 42 | "the bounce ends": !up!.classList.contains("bounce") && !down!.classList.contains("bounce"), |
| 43 | "each press posted its side": posted.join(",") === "1,-1", |
| 44 | "no navigation": location.href === before, |
| 45 | }, |
| 46 | observed: { pressedColour, posted }, |
| 47 | }; |
| 48 | document.getElementById("smoke")!.textContent = `SMOKE:${JSON.stringify(verdict)}`; |