mosaic-headless 1.35.0 → 1.36.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,421 @@
1
+ #!/usr/bin/env python3
2
+ """Build every way Mosaic can make a site menu on one page, then drive each one.
3
+
4
+ python tools/verify_menus.py --config c.json --post <ID of menu-lab> --slug menu-lab \
5
+ --csv data/menu-verification.csv
6
+
7
+ Mosaic has no off-canvas node. A desktop menu is a `dropdown` / `dropdown-wide`; a
8
+ phone menu is one of three assemblies, and they differ on exactly what a visitor
9
+ notices - whether Esc closes it, where focus goes, whether a sticky header can sit
10
+ on top of its close button:
11
+
12
+ DESKTOP a sticky header (z-index 1000) with a `dropdown` (openOn hover, its toggle
13
+ carrying a url), a `dropdown-wide` mega panel and a plain `menu-link`.
14
+ Asserted with a mouse, with the keyboard, and on a touch tablet: open and
15
+ close timing, aria-expanded, Esc, what a tap on a linked toggle does, and
16
+ whether the panel links are in the HTML before any script runs.
17
+ DRAWER (b) a Pro `modal` as a right-hand drawer: overlay + window, opened by a
18
+ hamburger's modalOpen, closed by a modalClose button inside, Esc and the
19
+ overlay. Asserted at 390px on a touch phone.
20
+ NAVBAR (a) `navbar` > `navbar-toggle` + `navigation`, collapsing below `_t`.
21
+ PANEL (c) Mosaic's off-canvas tutorial: a fixed div opened by click odd/even
22
+ interactions - z-index 50, under the sticky header, on purpose.
23
+ """
24
+ from __future__ import annotations
25
+
26
+ import mosaic_config
27
+ import argparse
28
+ import csv
29
+ import os
30
+ import re
31
+ import sys
32
+ import time
33
+ import urllib.request
34
+ import uuid
35
+
36
+ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
37
+ import interactions as ix # noqa: E402
38
+ from build_page import Surface # noqa: E402
39
+ from build_site import bind_page, build_page_document, build_shell # noqa: E402
40
+ from sweep_node_types import Client # noqa: E402
41
+
42
+ NS = uuid.UUID("6d6f7361-6963-4865-6164-6c657373ff0c")
43
+ INK, PAPER = "rgb(22, 24, 28)", "rgb(250, 250, 247)"
44
+
45
+
46
+ def det(name):
47
+ return str(uuid.uuid5(NS, name))
48
+
49
+
50
+ def link(attr, label, url, **style):
51
+ st = {"paddingTop": "10px", "paddingBottom": "10px", "paddingLeft": "14px",
52
+ "paddingRight": "14px", "color": INK, "fontSize": "15px"}
53
+ st.update(style)
54
+ return {"type": "menu-link", "data": {"attrID": attr, "url": url},
55
+ "style": {"&": {"_": st}, "focus-visible": {"_": {
56
+ "customDeclarations": "outline:2px solid rgb(9,99,199);outline-offset:2px;"}}},
57
+ "children": [{"type": "wysiwyg-text", "data": {"text": label}}]}
58
+
59
+
60
+ def button(attr, label, actions, **style):
61
+ st = {"paddingTop": "10px", "paddingBottom": "10px", "paddingLeft": "14px",
62
+ "paddingRight": "14px", "backgroundColor": INK, "color": PAPER,
63
+ "cursor": "pointer"}
64
+ st.update(style)
65
+ return {"type": "button", "data": {"attrID": attr, "interactions": [ix.on("click", actions)]},
66
+ "style": {"&": {"_": st}},
67
+ "children": [{"type": "wysiwyg-text", "data": {"text": label}}]}
68
+
69
+
70
+ def act(kind, node_id):
71
+ return {"type": kind, "uuid": str(uuid.uuid4()),
72
+ "settings": {"target": {"type": "element", "uuid": node_id}}}
73
+
74
+
75
+ PANEL = {"backgroundColor": PAPER, "paddingTop": "8px", "paddingBottom": "8px",
76
+ "minWidth": "220px",
77
+ "customDeclarations": "border:1px solid rgb(22,24,28);box-shadow:0 18px 40px rgba(22,24,28,.16);"}
78
+
79
+
80
+ def tree():
81
+ drawer, panel = det("drawer"), det("panel")
82
+ desktop = {"type": "div", "data": {"attrID": "ml-desk"},
83
+ "style": {"&": {"_": {"display": "flex", "alignItems": "center", "columnGap": "8px"},
84
+ "_t": {"display": "none"}}},
85
+ "children": [
86
+ {"type": "dropdown", "data": {"attrID": "ml-dd", "openOn": "hover", "animation": "fadeDown"},
87
+ "style": {"&": {"_": {"position": "relative"}}},
88
+ "children": [
89
+ {"type": "dropdown-toggle", "data": {"attrID": "ml-dd-toggle", "url": "/components/"},
90
+ "style": {"&": {"_": {"paddingTop": "10px", "paddingBottom": "10px",
91
+ "paddingLeft": "14px", "paddingRight": "14px",
92
+ "color": INK, "cursor": "pointer"}}},
93
+ "children": [{"type": "wysiwyg-text", "data": {"text": "服務"}}]},
94
+ {"type": "dropdown-wrapper", "data": {"attrID": "ml-dd-menu"},
95
+ "style": {"&": {"_": dict(PANEL, flexDirection="column")}},
96
+ "children": [link("ml-dd-l%d" % i, t, u) for i, (t, u) in enumerate(
97
+ [("服務總覽", "/components/"), ("表單", "/forms/"), ("輪播", "/sliders/")], 1)]}]},
98
+ {"type": "dropdown-wide", "data": {"attrID": "ml-mega", "openOn": "hover", "animation": "fadeDown"},
99
+ "children": [
100
+ {"type": "dropdown-toggle", "data": {"attrID": "ml-mega-toggle"},
101
+ "style": {"&": {"_": {"paddingTop": "10px", "paddingBottom": "10px",
102
+ "paddingLeft": "14px", "paddingRight": "14px",
103
+ "color": INK, "cursor": "pointer"}}},
104
+ "children": [{"type": "wysiwyg-text", "data": {"text": "全部功能"}}]},
105
+ {"type": "dropdown-wrapper-wide", "data": {"attrID": "ml-mega-menu"},
106
+ "style": {"&": {"_": dict(PANEL, display="grid", gridCols="repeat(3, 1fr)",
107
+ paddingLeft="24px", paddingRight="24px")}},
108
+ "children": [link("ml-mega-l%d" % i, t, u) for i, (t, u) in enumerate(
109
+ [("元件牆", "/components/"), ("表單", "/forms/"), ("內容", "/content/"),
110
+ ("輪播", "/sliders/"), ("彈出層", "/popovers/"), ("對話框", "/dialogs/")], 1)]}]},
111
+ link("ml-contact", "聯絡", "/forms/")]}
112
+
113
+ header = {"type": "div", "data": {"attrID": "ml-header"},
114
+ "style": {"&": {"_": {"position": "sticky", "top": "0px", "zIndex": "1000",
115
+ "height": "64px", "display": "flex", "alignItems": "center",
116
+ "justifyContent": "space-between",
117
+ "paddingLeft": "20px", "paddingRight": "20px",
118
+ "backgroundColor": PAPER,
119
+ "customDeclarations": "border-bottom:1px solid rgb(22,24,28);"}}},
120
+ "children": [
121
+ {"type": "text", "data": {"attrID": "ml-logo", "tagName": "p"}, "text": "MENU LAB"},
122
+ desktop,
123
+ {"type": "div", "data": {"attrID": "ml-mob"},
124
+ "style": {"&": {"_": {"display": "none"}, "_t": {"display": "flex", "columnGap": "8px"}}},
125
+ "children": [
126
+ button("ml-burger", "選單", [act("modalOpen", drawer)]),
127
+ {"type": "div", "data": {"attrID": "ml-oc-btn", "interactions": [_panel_toggle(panel)]},
128
+ "style": {"&": {"_": {"paddingTop": "10px", "paddingBottom": "10px",
129
+ "paddingLeft": "14px", "paddingRight": "14px",
130
+ "cursor": "pointer",
131
+ "customDeclarations": "border:1px solid rgb(22,24,28);"}}},
132
+ "text": "面板"}]}]}
133
+
134
+ modal = {"type": "modal", "nodeID": drawer,
135
+ "data": {"attrID": "ml-drawer", "closedby": "everything", "accessibleLabel": "主選單"},
136
+ "style": {"&": {"_": {"paddingTop": "0px", "paddingBottom": "0px",
137
+ "paddingLeft": "0px", "paddingRight": "0px"}}},
138
+ "children": [
139
+ {"type": "modal-overlay", "data": {"attrID": "ml-drawer-ov"},
140
+ "style": {"&": {"_": {"backgroundColor": "rgba(22, 24, 28, 0.5)"}}}},
141
+ {"type": "modal-window", "data": {"attrID": "ml-drawer-win"},
142
+ "style": {"&": {"_": {"position": "absolute", "top": "0px", "right": "0px",
143
+ "height": "100dvh", "width": "86%", "maxWidth": "360px",
144
+ "backgroundColor": PAPER, "overflow": "auto",
145
+ "display": "flex", "flexDirection": "column",
146
+ "paddingTop": "16px", "paddingLeft": "16px",
147
+ "paddingRight": "16px", "paddingBottom": "24px"}}},
148
+ "children": [
149
+ button("ml-close", "關閉", [act("modalClose", drawer)], alignSelf="flex-end"),
150
+ link("ml-d1", "服務總覽", "/components/"), link("ml-d2", "表單", "/forms/"),
151
+ link("ml-d3", "輪播", "/sliders/"), link("ml-d4", "聯絡", "/forms/")]}]}
152
+
153
+ navbar = {"type": "navbar", "data": {"attrID": "ml-nb", "buttonBreakpoint": "_t",
154
+ "animation": "fadeDown", "disableScroll": "1"},
155
+ "style": {"&": {"_": {"display": "flex", "alignItems": "center",
156
+ "justifyContent": "space-between", "paddingTop": "12px",
157
+ "paddingBottom": "12px", "paddingLeft": "20px", "paddingRight": "20px",
158
+ "customDeclarations": "border-bottom:1px solid rgb(22,24,28);"}}},
159
+ "children": [
160
+ {"type": "navbar-toggle", "data": {"attrID": "ml-nb-toggle"},
161
+ "style": {"&": {"_": {"paddingTop": "10px", "paddingBottom": "10px",
162
+ "paddingLeft": "14px", "paddingRight": "14px", "cursor": "pointer",
163
+ "customDeclarations": "border:1px solid rgb(22,24,28);"}}},
164
+ "children": [{"type": "wysiwyg-text", "data": {"text": "NAVBAR"}}]},
165
+ {"type": "navigation", "data": {"attrID": "ml-nb-nav"},
166
+ "style": {"&": {"_": {"display": "flex", "columnGap": "8px"}}},
167
+ "children": [link("ml-nb-l1", "服務", "/components/"), link("ml-nb-l2", "表單", "/forms/"),
168
+ link("ml-nb-l3", "聯絡", "/forms/")]}]}
169
+
170
+ oc_panel = {"type": "div", "nodeID": panel, "data": {"attrID": "ml-oc-panel"},
171
+ "style": {"&": {"_": {"display": "none", "position": "fixed", "zIndex": "50",
172
+ "top": "0px", "right": "0px", "bottom": "0px", "width": "300px",
173
+ "flexDirection": "column", "paddingTop": "16px",
174
+ "paddingLeft": "16px", "paddingRight": "16px",
175
+ "backgroundColor": "rgb(240, 240, 235)"}}},
176
+ "children": [
177
+ {"type": "div", "data": {"attrID": "ml-oc-close", "interactions": [_panel_toggle(panel)]},
178
+ "style": {"&": {"_": {"paddingTop": "10px", "paddingBottom": "10px", "cursor": "pointer"}}},
179
+ "text": "關閉面板"},
180
+ link("ml-oc-l1", "服務總覽", "/components/"), link("ml-oc-l2", "表單", "/forms/")]}
181
+
182
+ return {"type": "div", "data": {"attrID": "ml-root"},
183
+ "children": [header, modal, navbar, oc_panel,
184
+ {"type": "div", "data": {"attrID": "ml-body"},
185
+ "style": {"&": {"_": {"height": "2400px", "paddingTop": "40px",
186
+ "paddingLeft": "20px", "paddingRight": "20px"}}},
187
+ "children": [{"type": "text", "data": {"attrID": "ml-copy", "tagName": "p"},
188
+ "text": "選單實驗頁:桌機 hover 下拉、mega 下拉、modal 抽屜、navbar 收合、互動面板。"},
189
+ # which spelling of a notch inset survives the style validator
190
+ {"type": "div", "data": {"attrID": "ml-safe-native"},
191
+ "style": {"&": {"_": {"paddingTop": "max(16px, env(safe-area-inset-top))"}}}},
192
+ {"type": "div", "data": {"attrID": "ml-safe-custom"},
193
+ "style": {"&": {"_": {"customDeclarations":
194
+ "padding-top:max(16px, env(safe-area-inset-top));"}}}},
195
+ {"type": "div", "data": {"attrID": "ml-safe-calc"},
196
+ "style": {"&": {"_": {"paddingTop": "calc(16px + env(safe-area-inset-top))"}}}}]}]}
197
+
198
+
199
+ def _panel_toggle(panel):
200
+ t = ix.on("click", [ix.display(start="flex", target=ix.element(panel)),
201
+ ix.tween([("translateX", "100%", "0%")], 300, target=ix.element(panel))],
202
+ slot="odd")
203
+ return ix.add_slot(t, "even", [ix.tween([("translateX", "0%", "100%")], 300, target=ix.element(panel)),
204
+ ix.display(end="none", duration=300, target=ix.element(panel))])
205
+
206
+
207
+ def build(client, cfg, post, slug):
208
+ surface = Surface()
209
+ master, _h, _f = build_shell(client, cfg, {"pages": [], "shell": {}}, surface)
210
+ template = bind_page(client, cfg, master, slug, post)
211
+ build_page_document(client, cfg, master, template, tree(), surface)
212
+ return master
213
+
214
+
215
+ # ---------------------------------------------------------------- the drive
216
+
217
+ INFO = """id => { const e = document.getElementById(id); if (!e) return null;
218
+ const r = e.getBoundingClientRect(), s = getComputedStyle(e);
219
+ return {shown: r.width > 2 && r.height > 2 && s.display !== 'none' && s.visibility !== 'hidden'
220
+ && parseFloat(s.opacity) > 0.05,
221
+ x: r.x, y: r.y, w: r.width, h: r.height, tag: e.tagName.toLowerCase(),
222
+ expanded: e.getAttribute('aria-expanded')}; }"""
223
+ ON_TOP = """id => { const e = document.getElementById(id); const r = e.getBoundingClientRect();
224
+ const t = document.elementFromPoint(r.x + r.width / 2, r.y + Math.min(r.height / 2, 12));
225
+ return t ? (e.contains(t) ? 'self' : (t.id || t.className || t.tagName)) : 'nothing'; }"""
226
+ ACTIVE = """() => { let a = document.activeElement; while (a && !a.id) a = a.parentElement;
227
+ return a ? a.id : null; }"""
228
+ IN_DRAWER = """() => !!document.activeElement && !!document.activeElement.closest('#ml-drawer')"""
229
+
230
+
231
+ def drive(url, rows):
232
+ from playwright.sync_api import sync_playwright
233
+
234
+ def row(group, check, ok, evidence):
235
+ rows.append([group, check, "PASS" if ok else ("INFO" if ok is None else "FAIL"), evidence])
236
+ print(" %-8s %-46s %-4s %s" % (group, check, rows[-1][2], evidence))
237
+
238
+ bust = lambda: "%s?_v=%d" % (url, time.time() * 1000) # noqa: E731
239
+
240
+ # the HTML before any script: are the panel links crawlable?
241
+ raw = urllib.request.urlopen(urllib.request.Request(bust(), headers={"User-Agent": "Mozilla/5.0"})).read().decode("utf-8")
242
+ hrefs = re.findall(r'id="(ml-(?:dd|mega|d|nb|oc)-?l?\d+)"[^>]*href="([^"]*)"|href="([^"]*)"[^>]*id="(ml-(?:dd|mega|d|nb|oc)-?l?\d+)"', raw)
243
+ ids = sorted({a or d for a, _b, _c, d in hrefs})
244
+ row("SEO", "panel links are <a href> in the server HTML", len(ids) >= 15,
245
+ "%d links: %s" % (len(ids), ", ".join(ids)))
246
+ dt = re.search(r'<[a-z-]+[^>]*id="ml-dd-toggle"[^>]*>', raw)
247
+ row("SEO", "a dropdown-toggle with a url renders as", None, dt.group(0)[:160] if dt else "absent")
248
+
249
+ with sync_playwright() as pw:
250
+ b = pw.chromium.launch()
251
+
252
+ # ---------------- desktop, mouse
253
+ p = b.new_page(viewport={"width": 1280, "height": 800})
254
+ p.goto(bust(), wait_until="networkidle")
255
+ info = lambda i: p.evaluate(INFO, i) # noqa: E731
256
+ row("DESKTOP", "panels closed at rest", not info("ml-dd-menu")["shown"] and not info("ml-mega-menu")["shown"],
257
+ "dd %s, mega %s" % (info("ml-dd-menu")["shown"], info("ml-mega-menu")["shown"]))
258
+ t = info("ml-dd-toggle")
259
+ p.mouse.move(t["x"] + t["w"] / 2, t["y"] + t["h"] / 2)
260
+ t0 = time.time(); opened_at = None
261
+ while time.time() - t0 < 2:
262
+ if info("ml-dd-menu")["shown"]:
263
+ opened_at = time.time() - t0; break
264
+ p.wait_for_timeout(20)
265
+ row("DESKTOP", "hover opens the dropdown", opened_at is not None,
266
+ "visible after %s ms, aria-expanded=%s" % (int(opened_at * 1000) if opened_at else "-",
267
+ info("ml-dd-toggle")["expanded"]))
268
+ m = info("ml-dd-menu")
269
+ p.mouse.move(m["x"] + 30, m["y"] + m["h"] / 2, steps=8)
270
+ p.wait_for_timeout(500)
271
+ row("DESKTOP", "moving down into the panel keeps it open", info("ml-dd-menu")["shown"],
272
+ "still shown 500 ms after entering the panel")
273
+ p.mouse.move(700, 600)
274
+ t0 = time.time(); closed_at = None
275
+ while time.time() - t0 < 3:
276
+ if not info("ml-dd-menu")["shown"]:
277
+ closed_at = time.time() - t0; break
278
+ p.wait_for_timeout(20)
279
+ row("DESKTOP", "leaving closes it", closed_at is not None,
280
+ "hidden after %s ms" % (int(closed_at * 1000) if closed_at else "-"))
281
+ g = info("ml-mega-toggle")
282
+ p.mouse.move(g["x"] + g["w"] / 2, g["y"] + g["h"] / 2)
283
+ p.wait_for_timeout(600)
284
+ mg = info("ml-mega-menu")
285
+ row("DESKTOP", "mega panel opens on hover", mg["shown"],
286
+ "x=%d w=%d (viewport 1280)" % (mg["x"], mg["w"]))
287
+ p.mouse.move(700, 700); p.wait_for_timeout(800)
288
+
289
+ # keyboard
290
+ p.goto(bust(), wait_until="networkidle")
291
+ p.focus("#ml-dd-toggle")
292
+ p.keyboard.press("Enter")
293
+ p.wait_for_timeout(1200)
294
+ p.wait_for_load_state("domcontentloaded")
295
+ row("KEYS", "Enter on a toggle that has a url", None,
296
+ "navigated to %s" % p.url if "menu-lab" not in p.url
297
+ else "opened=%s" % info("ml-dd-menu")["shown"])
298
+ if "menu-lab" not in p.url:
299
+ p.goto(bust(), wait_until="networkidle")
300
+ p.focus("#ml-dd-toggle")
301
+ p.keyboard.press("ArrowDown"); p.wait_for_timeout(500)
302
+ row("KEYS", "ArrowDown opens it", info("ml-dd-menu")["shown"],
303
+ "shown=%s, focus on %s" % (info("ml-dd-menu")["shown"], p.evaluate(ACTIVE)))
304
+ p.keyboard.press("ArrowDown"); p.wait_for_timeout(150)
305
+ row("KEYS", "ArrowDown moves into the links", None, "focus on %s" % p.evaluate(ACTIVE))
306
+ p.keyboard.press("Escape"); p.wait_for_timeout(500)
307
+ row("KEYS", "Escape closes it and returns focus", not info("ml-dd-menu")["shown"],
308
+ "shown=%s, focus on %s" % (info("ml-dd-menu")["shown"], p.evaluate(ACTIVE)))
309
+ p.focus("#ml-mega-toggle"); p.keyboard.press("Space"); p.wait_for_timeout(500)
310
+ row("KEYS", "Space opens the mega panel (toggle without url)", info("ml-mega-menu")["shown"],
311
+ "shown=%s aria-expanded=%s" % (info("ml-mega-menu")["shown"], info("ml-mega-toggle")["expanded"]))
312
+ p.keyboard.press("Tab"); p.wait_for_timeout(150)
313
+ row("KEYS", "Tab from the open toggle goes to", None, p.evaluate(ACTIVE))
314
+ p.close()
315
+
316
+ # ---------------- touch tablet at desktop width
317
+ ctx = b.new_context(viewport={"width": 1366, "height": 1024}, has_touch=True, is_mobile=True)
318
+ p = ctx.new_page(); p.goto(bust(), wait_until="networkidle")
319
+ info = lambda i: p.evaluate(INFO, i) # noqa: E731
320
+ p.tap("#ml-dd-toggle"); p.wait_for_timeout(600)
321
+ row("TOUCH", "first tap on a linked toggle", "menu-lab" in p.url and info("ml-dd-menu")["shown"],
322
+ "url stays=%s, panel shown=%s" % ("menu-lab" in p.url, info("ml-dd-menu")["shown"] if "menu-lab" in p.url else "-"))
323
+ if "menu-lab" in p.url:
324
+ p.tap("#ml-dd-toggle"); p.wait_for_timeout(900)
325
+ row("TOUCH", "second tap on the same toggle", None,
326
+ "navigated to %s" % p.url if "menu-lab" not in p.url else "stayed; shown=%s" % info("ml-dd-menu")["shown"])
327
+ p.goto(bust(), wait_until="networkidle")
328
+ p.tap("#ml-mega-toggle"); p.wait_for_timeout(600)
329
+ row("TOUCH", "tap opens the mega panel", info("ml-mega-menu")["shown"], "")
330
+ p.tap("#ml-copy"); p.wait_for_timeout(600)
331
+ row("TOUCH", "tap outside closes it", not info("ml-mega-menu")["shown"], "")
332
+ ctx.close()
333
+
334
+ # ---------------- phone
335
+ ctx = b.new_context(viewport={"width": 390, "height": 844}, has_touch=True, is_mobile=True)
336
+ p = ctx.new_page(); p.goto(bust(), wait_until="networkidle")
337
+ info = lambda i: p.evaluate(INFO, i) # noqa: E731
338
+ row("PHONE", "desktop menu hidden, burger shown", not info("ml-desk")["shown"] and info("ml-burger")["shown"], "")
339
+ p.tap("#ml-burger"); p.wait_for_timeout(700)
340
+ d = p.evaluate("""() => { const m = document.getElementById('ml-drawer');
341
+ return {open: m.matches(':popover-open') || m.open, role: m.getAttribute('role'),
342
+ label: m.getAttribute('aria-label'), modal: m.getAttribute('aria-modal'),
343
+ tag: m.tagName.toLowerCase(), scroll: getComputedStyle(document.documentElement).overflow
344
+ + '/' + getComputedStyle(document.body).overflow}; }""")
345
+ row("DRAWER", "burger opens the modal drawer", d["open"], str(d))
346
+ row("DRAWER", "focus moves into the drawer", p.evaluate(IN_DRAWER), "focus on %s" % p.evaluate(ACTIVE))
347
+ c = info("ml-close")
348
+ row("DRAWER", "close button inside the viewport", c["shown"] and c["y"] >= 0 and c["x"] + c["w"] <= 390,
349
+ "x=%d y=%d w=%d h=%d" % (c["x"], c["y"], c["w"], c["h"]))
350
+ row("DRAWER", "close button not covered by the z-1000 sticky header", p.evaluate(ON_TOP, "ml-close") == "self",
351
+ "element at its centre: %s" % p.evaluate(ON_TOP, "ml-close"))
352
+ seen = set()
353
+ for _ in range(8):
354
+ p.keyboard.press("Tab"); seen.add(p.evaluate(ACTIVE))
355
+ row("DRAWER", "Tab stays inside the drawer", all((s or "").startswith(("ml-d", "ml-close")) for s in seen),
356
+ "focus visited %s" % sorted(s or "-" for s in seen))
357
+ p.keyboard.press("Escape"); p.wait_for_timeout(600)
358
+ closed = not p.evaluate("() => document.getElementById('ml-drawer').matches(':popover-open')")
359
+ row("DRAWER", "Escape closes it", closed, "")
360
+ row("DRAWER", "focus returns to the burger", p.evaluate(ACTIVE) == "ml-burger", "focus on %s" % p.evaluate(ACTIVE))
361
+ p.tap("#ml-burger"); p.wait_for_timeout(700)
362
+ p.tap("#ml-close"); p.wait_for_timeout(700)
363
+ row("DRAWER", "the close button closes it",
364
+ not p.evaluate("() => document.getElementById('ml-drawer').matches(':popover-open')"), "")
365
+ p.tap("#ml-burger"); p.wait_for_timeout(700)
366
+ p.mouse.click(20, 400); p.wait_for_timeout(700)
367
+ row("DRAWER", "a tap on the overlay closes it",
368
+ not p.evaluate("() => document.getElementById('ml-drawer').matches(':popover-open')"), "")
369
+
370
+ # navbar
371
+ p.goto(bust(), wait_until="networkidle")
372
+ nb = p.evaluate("""() => { const t = document.getElementById('ml-nb-toggle');
373
+ return {mode: document.getElementById('ml-nb').className.includes('dropdown-mode'),
374
+ tag: t.tagName.toLowerCase(), expanded: t.getAttribute('aria-expanded'),
375
+ controls: t.getAttribute('aria-controls')}; }""")
376
+ row("NAVBAR", "collapsed below _t", nb["mode"] and not info("ml-nb-nav")["shown"], str(nb))
377
+ p.tap("#ml-nb-toggle"); p.wait_for_timeout(700)
378
+ row("NAVBAR", "toggle opens the links", info("ml-nb-nav")["shown"],
379
+ "aria-expanded=%s, focus on %s" % (info("ml-nb-toggle")["expanded"], p.evaluate(ACTIVE)))
380
+ p.keyboard.press("Escape"); p.wait_for_timeout(600)
381
+ row("NAVBAR", "Escape closes it", not info("ml-nb-nav")["shown"], "shown=%s" % info("ml-nb-nav")["shown"])
382
+
383
+ # interaction panel
384
+ p.goto(bust(), wait_until="networkidle")
385
+ p.tap("#ml-oc-btn"); p.wait_for_timeout(700)
386
+ row("PANEL", "click interaction opens the panel", info("ml-oc-panel")["shown"], "")
387
+ row("PANEL", "its close control is covered by the sticky header", None,
388
+ "element at its centre: %s" % p.evaluate(ON_TOP, "ml-oc-close"))
389
+ p.keyboard.press("Escape"); p.wait_for_timeout(600)
390
+ row("PANEL", "Escape closes it", not info("ml-oc-panel")["shown"], "shown=%s" % info("ml-oc-panel")["shown"])
391
+ row("PANEL", "focus moved into it", p.evaluate("() => !!document.activeElement.closest('#ml-oc-panel')"),
392
+ "focus on %s" % p.evaluate(ACTIVE))
393
+ ctx.close()
394
+ b.close()
395
+
396
+
397
+ def main():
398
+ ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
399
+ ap.add_argument("--config")
400
+ ap.add_argument("--post", required=True, type=int)
401
+ ap.add_argument("--slug", default="menu-lab")
402
+ ap.add_argument("--csv")
403
+ ap.add_argument("--no-build", action="store_true")
404
+ a = ap.parse_args()
405
+ cfg = mosaic_config.load(a.config)
406
+ if not a.no_build:
407
+ master = build(Client(cfg), cfg, a.post, a.slug)
408
+ print("built on master %s" % master[:8])
409
+ rows = []
410
+ drive("%s/%s/" % (cfg["base"].rstrip("/"), a.slug), rows)
411
+ if a.csv:
412
+ with open(a.csv, "w", newline="", encoding="utf-8") as fh:
413
+ w = csv.writer(fh)
414
+ w.writerow(["group", "check", "result", "evidence"])
415
+ w.writerows(rows)
416
+ fails = sum(1 for r in rows if r[2] == "FAIL")
417
+ print("\n%d checks, %d FAIL" % (len(rows), fails))
418
+
419
+
420
+ if __name__ == "__main__":
421
+ main()