//go:build browser package mapatest import ( "context" _ "embed" "strings" "testing" "amadan.net/rastrillo/rastrillo/harness" "github.com/chromedp/chromedp" "github.com/chromedp/chromedp/kb" ) // L10, accessibility (level-up spec §6.12, §7), for the page editor: // axe-core finds nothing serious; the editor is a named multi-line // textbox; task boxes are named buttons; the keyboard reaches [[, /, // the toolbar and Make team page, and focus comes back each time; the // page reflows at 320px. ⌘K, the calendar, History and Restore have // their own keyboard walks (palette_browser_test.go, // browser_history_test.go). // axe is axe-core, vendored (testdata/axe/README): the gate fetches // nothing. // //go:embed testdata/axe/axe.min.js var axe string // axeSerious runs axe over the page and lists what is serious or // critical, by rule and the first element it names. func axeSerious(t *testing.T, rig *harness.Rig) string { t.Helper() drive(t, rig, chromedp.Evaluate[chromedp.Void](axe)) return read(t, rig, chromedp.Evaluate[string](`axe.run(document, { resultTypes: ["violations"] }).then(function (result) { return result.violations.filter(function (rule) { return rule.impact === "serious" || rule.impact === "critical"; }).map(function (rule) { return rule.id + " " + rule.nodes.map(function (node) { return node.target.join(" "); }).slice(0, 3).join(", "); }).join("\n"); })`, chromedp.EvalAwaitPromise)) } const accessBody = "# Plan\n\nMet [[Access Target]] and [[Not yet]] " + "on [[2026-11-12]]. ^intro\n\n- [ ] Send Tom the summary\n- [x] Book" + "\n\n> Quoted\n\n```\ncode\n```\n\n---\n\nEnd." func TestL10TheEditorPassesAxe(t *testing.T) { rig, store := browserRig(t, 0) if _, err := store.CreateTeamPage(context.Background(), Bo, "Access Target", "Here."); err != nil { t.Fatal(err) } teamPage(t, rig, store, accessBody) if found := axeSerious(t, rig); found != "" { t.Fatalf("axe, the page in the editor:\n%s", found) } role := read(t, rig, chromedp.Evaluate[string](`(function (dom) { return [dom.getAttribute("role"), dom.getAttribute("aria-multiline"), dom.getAttribute("aria-label")].join("|"); })(mapaEditor.view.dom)`)) if !strings.HasPrefix(role, "textbox|true|Page text, Plan") { t.Fatalf("the editor is %q", role) } boxes := read(t, rig, chromedp.Evaluate[string](`Array.prototype.map.call( document.querySelectorAll("button[mapa-task-box]"), function (box) { return box.getAttribute("aria-label") + "=" + box.getAttribute("aria-pressed"); }).join("|")`)) if boxes != "Not done: Send Tom the summary=false|Done: Book=true" { t.Fatalf("the task boxes are %q", boxes) } drive(t, rig, chromedp.Click(`button[mapa-task-box]`)) if got := typed(t, rig); !strings.Contains(got, "- [x] Send Tom the summary") { t.Fatalf("the box did not toggle: %q", got) } drive(t, rig, caretAt(0), chromedp.KeyEvent(" [[Acc")) listShows(t, rig, "Access Target") if found := axeSerious(t, rig); found != "" { t.Fatalf("axe, with the [[ list open:\n%s", found) } } // focusInEditor is whether focus is in the page's text. const focusInEditor = `mapaEditor.view.dom.contains(document.activeElement)` func TestL10TheKeyboardWalkReturnsFocus(t *testing.T) { rig, _ := browserRig(t, 0) emptyDay(t, rig, "2026-11-08") drive(t, rig, chromedp.KeyEvent("Keep. [[No")) listShows(t, rig, "Link “No”") drive(t, rig, chromedp.KeyEvent(kb.Escape)) if options(t, rig) != "" || !read(t, rig, chromedp.Evaluate[bool](focusInEditor)) { t.Fatal("Esc did not close [[ in place") } drive(t, rig, enter(), chromedp.KeyEvent("/quo")) listShows(t, rig, "Quote") drive(t, rig, chromedp.KeyEvent(kb.Escape), chromedp.KeyEvent(kb.Backspace+kb.Backspace+kb.Backspace+ kb.Backspace), chromedp.KeyEvent("Share me."), chromedp.KeyEvent(kb.Home, chromedp.KeyModifiers( chromedp.ModifierShift)), chromedp.KeyEvent(kb.ArrowUp, chromedp.KeyModifiers( chromedp.ModifierShift)), chromedp.WaitVisible(`[mapa-bubble]`), chromedp.KeyEvent(kb.F10, chromedp.KeyModifiers( chromedp.ModifierAlt))) active := read(t, rig, chromedp.Evaluate[string]( `document.activeElement.getAttribute("aria-label")`)) if active != "Bold" { t.Fatalf("⌥F10 went to %q", active) } drive(t, rig, chromedp.KeyEvent(kb.ArrowLeft), enter(), chromedp.WaitVisible(`dialog[mapa-make-team] input`), chromedp.KeyEvent(kb.Escape)) eventually(t, "focus back from Make team page", func() bool { return read(t, rig, chromedp.Evaluate[bool](focusInEditor)) }) drive(t, rig, chromedp.KeyEvent("k", mod()), chromedp.WaitVisible(`dialog[mapa-palette] input`), chromedp.KeyEvent(kb.Escape)) eventually(t, "focus back from ⌘K", func() bool { return read(t, rig, chromedp.Evaluate[bool](focusInEditor)) }) } func TestL10ThePageReflowsAt320(t *testing.T) { rig, store := browserRig(t, 0) teamPage(t, rig, store, accessBody+"\n\n"+strings.Repeat( "Averyveryverylongwordwithoutanybreaks", 4)) drive(t, rig, chromedp.EmulateViewport(320, 640), chromedp.WaitVisible(mounted)) wide := read(t, rig, chromedp.Evaluate[int]( `document.documentElement.scrollWidth`)) if wide > 320 { t.Fatalf("at 320px the page is %dpx wide", wide) } } // §6.11 on a phone (a coarse pointer, 390px): the text is 16px, so iOS // does not zoom on focus; the accessory row is over the keyboard while // writing, and its [[ opens the list; the bubble sits below the // selection, clear of iOS's callout. func TestThePhoneWritesWithTheAccessoryRow(t *testing.T) { rig, _ := browserRig(t, 0, harness.WithCoarsePointer()) drive(t, rig, scripts(true), chromedp.EmulateViewport(390, 844), chromedp.Navigate(rig.Origin+"/d/2026-11-09"), chromedp.WaitVisible(mounted), caretAt(0), chromedp.WaitVisible(`[mapa-accessory]`)) size := read(t, rig, chromedp.Evaluate[float64]( `parseFloat(getComputedStyle(mapaEditor.view.dom`+ `.querySelector("p")).fontSize)`)) if size < 16 { t.Fatalf("the page's text is %vpx on a phone", size) } drive(t, rig, chromedp.Click(`[mapa-accessory] [aria-label="Bold"]`), chromedp.KeyEvent("strong"), chromedp.Click(`[mapa-accessory] [aria-label="Bold"]`), chromedp.KeyEvent(" and "), chromedp.Click(`[mapa-accessory] [aria-label="Link to a page"]`), chromedp.KeyEvent("Zeb")) listShows(t, rig, "Link “Zeb”") drive(t, rig, enter()) if got := typed(t, rig); got != "**strong** and [[Zeb]]" { t.Fatalf("the row wrote %q", got) } drive(t, rig, chromedp.KeyEvent(kb.ArrowLeft, chromedp.KeyModifiers( chromedp.ModifierShift|chromedp.ModifierAlt)), chromedp.WaitVisible(`[mapa-bubble]`)) below := read(t, rig, chromedp.Evaluate[bool](`(function () { var bubble = document.querySelector("[mapa-bubble]").getBoundingClientRect(); var range = getSelection().getRangeAt(0).getBoundingClientRect(); return bubble.top >= range.bottom; })()`)) if !below { t.Fatal("on a coarse pointer the bubble is not below the selection") } }