/** * The page half of the sequence smoke (see sequence.html). Imports the * shipped dist bundle and checks on a real engine what happy-dom cannot: * the editor's controls have no form owner and are never posted, the form's * serialization mid-edit carries the open edit ("formdata"), focus moves, * 44px targets, outcomes stacked on a phone and side by side in a wide box. */ export {}; // a module: the page awaits at its top level await import("../dist/sequence.js"); const tick = () => new Promise(resolve => setTimeout(resolve, 0)); await tick(); const host = document.getElementById("editable")!; const form = document.getElementById("campagne") as HTMLFormElement; const field = form.elements.namedItem("sequence") as HTMLTextAreaElement; const step = (id: string) => host.querySelector(`[data-step="${id}"]`) as HTMLElement; const value = () => JSON.parse(field.value); const key = (target: Element, k: string) => target.dispatchEvent(new KeyboardEvent("keydown", { key: k, bubbles: true, cancelable: true })); const hidden = getComputedStyle(field).display === "none"; const cards = host.querySelectorAll(".card").length; const buttons = [...host.querySelectorAll("button")].map(b => b.getBoundingClientRect().height); const outcomes = [...step("c").querySelectorAll(".branches > .branch")].map(b => b.getBoundingClientRect()); const stacked = outcomes.length === 2 && outcomes[1]!.top >= outcomes[0]!.bottom; const wide = [...document.querySelectorAll("#wide .branch")].map(b => b.getBoundingClientRect()); const sideBySide = wide.length === 2 && Math.abs(wide[0]!.top - wide[1]!.top) < 1 && wide[1]!.left > wide[0]!.right; // add a wait after "invite": the menu, the editor, focus, Enter commits (host.querySelector('button.add[data-slot="b/next"]') as HTMLElement).click(); const menu = [...host.querySelectorAll(".menu .kind")].map(b => b.textContent); (host.querySelector('.menu .kind[data-kind="wait"]') as HTMLElement).click(); await tick(); const days = host.querySelector(".editor input[name=days]") as HTMLInputElement; const editorFocused = document.activeElement === days; const noOwner = days.form === null; days.value = "4"; // the page's Save pressed mid-edit: FormData carries the open edit, never the editor's own controls const midEdit = new FormData(form); const postedKeys = [...midEdit.keys()].sort(); const postedWait = JSON.parse(String(midEdit.get("sequence"))).root.next.next; key(days, "Enter"); await tick(); const committed = value().root.next.next; const summary = step(committed.id)?.querySelector(".summary")?.textContent; // remove the branching step: asks first, then its "Oui" run takes its place const remove = () => step("c").querySelector(".card .remove") as HTMLElement; remove().click(); const asked = remove().textContent; remove().click(); const afterRemove = value().root.next.next.next; const verdict = { checks: { registered: customElements.get("pebble-sequence") !== undefined, "the textarea is hidden, the tree drawn": hidden && cards === 5, "every button is a 44px target": buttons.length > 0 && buttons.every(h => h >= 44), "outcomes stack on a phone": stacked, "outcomes sit side by side in a wide box": sideBySide, "the menu lists the page's kinds": menu.join("|") === "Visiter le profil|Inviter|Attendre|Envoyer un message|A accepté ?", "the new step's editor takes focus": editorFocused, "the editor's controls have no form owner": noOwner, "only the page's fields are posted": postedKeys.join("|") === "sequence|titre", "a mid-edit post carries the open edit": postedWait?.kind === "wait" && postedWait?.fields?.days === 4, "Enter commits into the textarea": committed.kind === "wait" && committed.fields.days === 4 && committed.next.id === "c", "the card summarizes with the page's words": summary === "4 jours", "removing a branching step asks, then its first outcome takes its place": asked === "Retirer avec la suite" && afterRemove?.id === "m", }, observed: { buttons, menu, postedKeys, summary, asked }, }; document.getElementById("smoke")!.textContent = `SMOKE:${JSON.stringify(verdict)}`;