tobogganSe connecter

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
72 lignes · 4169 octetsBrut · Historique
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 */
8export {}; // a module: the page awaits at its top level
9
10await import("../dist/sequence.js");
11const tick = () => new Promise(resolve => setTimeout(resolve, 0));
12await tick();
13
14const host = document.getElementById("editable")!;
15const form = document.getElementById("campagne") as HTMLFormElement;
16const field = form.elements.namedItem("sequence") as HTMLTextAreaElement;
17const step = (id: string) => host.querySelector(`[data-step="${id}"]`) as HTMLElement;
18const value = () => JSON.parse(field.value);
19const key = (target: Element, k: string) => target.dispatchEvent(new KeyboardEvent("keydown", { key: k, bubbles: true, cancelable: true }));
20
21const hidden = getComputedStyle(field).display === "none";
22const cards = host.querySelectorAll(".card").length;
23const buttons = [...host.querySelectorAll<HTMLElement>("button")].map(b => b.getBoundingClientRect().height);
24const outcomes = [...step("c").querySelectorAll<HTMLElement>(".branches > .branch")].map(b => b.getBoundingClientRect());
25const stacked = outcomes.length === 2 && outcomes[1]!.top >= outcomes[0]!.bottom;
26const wide = [...document.querySelectorAll<HTMLElement>("#wide .branch")].map(b => b.getBoundingClientRect());
27const 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();
31const menu = [...host.querySelectorAll(".menu .kind")].map(b => b.textContent);
32(host.querySelector('.menu .kind[data-kind="wait"]') as HTMLElement).click();
33await tick();
34const days = host.querySelector(".editor input[name=days]") as HTMLInputElement;
35const editorFocused = document.activeElement === days;
36const noOwner = days.form === null;
37days.value = "4";
38// the page's Save pressed mid-edit: FormData carries the open edit, never the editor's own controls
39const midEdit = new FormData(form);
40const postedKeys = [...midEdit.keys()].sort();
41const postedWait = JSON.parse(String(midEdit.get("sequence"))).root.next.next;
42key(days, "Enter");
43await tick();
44const committed = value().root.next.next;
45const summary = step(committed.id)?.querySelector(".summary")?.textContent;
46
47// remove the branching step: asks first, then its "Oui" run takes its place
48const remove = () => step("c").querySelector(".card .remove") as HTMLElement;
49remove().click();
50const asked = remove().textContent;
51remove().click();
52const afterRemove = value().root.next.next.next;
53
54const 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};
72document.getElementById("smoke")!.textContent = `SMOKE:${JSON.stringify(verdict)}`;