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 sequence smoke (see sequence.html). Imports the |
| 3 | * shipped dist bundle and checks on a real engine what happy-dom cannot: |
| 4 | * the editor's controls have no form owner and are never posted, the form's |
| 5 | * serialization mid-edit carries the open edit ("formdata"), focus moves, |
| 6 | * 44px targets, outcomes stacked on a phone and side by side in a wide box. |
| 7 | */ |
| 8 | export {}; // a module: the page awaits at its top level |
| 9 | |
| 10 | await import("../dist/sequence.js"); |
| 11 | const tick = () => new Promise(resolve => setTimeout(resolve, 0)); |
| 12 | await tick(); |
| 13 | |
| 14 | const host = document.getElementById("editable")!; |
| 15 | const form = document.getElementById("campagne") as HTMLFormElement; |
| 16 | const field = form.elements.namedItem("sequence") as HTMLTextAreaElement; |
| 17 | const step = (id: string) => host.querySelector(`[data-step="${id}"]`) as HTMLElement; |
| 18 | const value = () => JSON.parse(field.value); |
| 19 | const key = (target: Element, k: string) => target.dispatchEvent(new KeyboardEvent("keydown", { key: k, bubbles: true, cancelable: true })); |
| 20 | |
| 21 | const hidden = getComputedStyle(field).display === "none"; |
| 22 | const cards = host.querySelectorAll(".card").length; |
| 23 | const buttons = [...host.querySelectorAll<HTMLElement>("button")].map(b => b.getBoundingClientRect().height); |
| 24 | const outcomes = [...step("c").querySelectorAll<HTMLElement>(".branches > .branch")].map(b => b.getBoundingClientRect()); |
| 25 | const stacked = outcomes.length === 2 && outcomes[1]!.top >= outcomes[0]!.bottom; |
| 26 | const wide = [...document.querySelectorAll<HTMLElement>("#wide .branch")].map(b => b.getBoundingClientRect()); |
| 27 | const sideBySide = wide.length === 2 && Math.abs(wide[0]!.top - wide[1]!.top) < 1 && wide[1]!.left > wide[0]!.right; |
| 28 | |
| 29 | // add a wait after "invite": the menu, the editor, focus, Enter commits |
| 30 | (host.querySelector('button.add[data-slot="b/next"]') as HTMLElement).click(); |
| 31 | const menu = [...host.querySelectorAll(".menu .kind")].map(b => b.textContent); |
| 32 | (host.querySelector('.menu .kind[data-kind="wait"]') as HTMLElement).click(); |
| 33 | await tick(); |
| 34 | const days = host.querySelector(".editor input[name=days]") as HTMLInputElement; |
| 35 | const editorFocused = document.activeElement === days; |
| 36 | const noOwner = days.form === null; |
| 37 | days.value = "4"; |
| 38 | // the page's Save pressed mid-edit: FormData carries the open edit, never the editor's own controls |
| 39 | const midEdit = new FormData(form); |
| 40 | const postedKeys = [...midEdit.keys()].sort(); |
| 41 | const postedWait = JSON.parse(String(midEdit.get("sequence"))).root.next.next; |
| 42 | key(days, "Enter"); |
| 43 | await tick(); |
| 44 | const committed = value().root.next.next; |
| 45 | const summary = step(committed.id)?.querySelector(".summary")?.textContent; |
| 46 | |
| 47 | // remove the branching step: asks first, then its "Oui" run takes its place |
| 48 | const remove = () => step("c").querySelector(".card .remove") as HTMLElement; |
| 49 | remove().click(); |
| 50 | const asked = remove().textContent; |
| 51 | remove().click(); |
| 52 | const afterRemove = value().root.next.next.next; |
| 53 | |
| 54 | const verdict = { |
| 55 | checks: { |
| 56 | registered: customElements.get("pebble-sequence") !== undefined, |
| 57 | "the textarea is hidden, the tree drawn": hidden && cards === 5, |
| 58 | "every button is a 44px target": buttons.length > 0 && buttons.every(h => h >= 44), |
| 59 | "outcomes stack on a phone": stacked, |
| 60 | "outcomes sit side by side in a wide box": sideBySide, |
| 61 | "the menu lists the page's kinds": menu.join("|") === "Visiter le profil|Inviter|Attendre|Envoyer un message|A accepté ?", |
| 62 | "the new step's editor takes focus": editorFocused, |
| 63 | "the editor's controls have no form owner": noOwner, |
| 64 | "only the page's fields are posted": postedKeys.join("|") === "sequence|titre", |
| 65 | "a mid-edit post carries the open edit": postedWait?.kind === "wait" && postedWait?.fields?.days === 4, |
| 66 | "Enter commits into the textarea": committed.kind === "wait" && committed.fields.days === 4 && committed.next.id === "c", |
| 67 | "the card summarizes with the page's words": summary === "4 jours", |
| 68 | "removing a branching step asks, then its first outcome takes its place": asked === "Retirer avec la suite" && afterRemove?.id === "m", |
| 69 | }, |
| 70 | observed: { buttons, menu, postedKeys, summary, asked }, |
| 71 | }; |
| 72 | document.getElementById("smoke")!.textContent = `SMOKE:${JSON.stringify(verdict)}`; |