| 1 | //go:build browser |
| 2 | |
| 3 | package mapatest |
| 4 | |
| 5 | import ( |
| 6 | "strings" |
| 7 | "testing" |
| 8 | |
| 9 | "github.com/chromedp/chromedp" |
| 10 | ) |
| 11 | |
| 12 | // The week strip's key, order and empty texts in a real browser (level-up |
| 13 | // build note 82), with scripts off and on, then axe. |
| 14 | |
| 15 | func TestTheWeekKeyShowsWithScriptsOffAndOn(t *testing.T) { |
| 16 | rig, _ := browserRig(t, 0) |
| 17 | for _, on := range []bool{false, true} { |
| 18 | drive(t, rig, scripts(on), chromedp.EmulateViewport(1440, 900), |
| 19 | chromedp.Navigate(rig.Origin+"/d/2026-11-20"), |
| 20 | chromedp.WaitVisible(`aside[mapa-links] p[mapa-week-key]`)) |
| 21 | key := text(t, rig, `aside[mapa-links] p[mapa-week-key]`) |
| 22 | for _, want := range []string{"Day shown", "Today", |
| 23 | "A note you wrote"} { |
| 24 | if !strings.Contains(key, want) { |
| 25 | t.Fatalf("scripts %v: the key reads %q", on, key) |
| 26 | } |
| 27 | } |
| 28 | order := read(t, rig, chromedp.Evaluate[string]( |
| 29 | `Array.prototype.map.call(document.querySelectorAll( |
| 30 | "#mapa-links-body > section > h2"), function (heading) { |
| 31 | return heading.firstChild.textContent.trim(); |
| 32 | }).join(" | ")`)) |
| 33 | if order != "This week | Linked from | Links out" { |
| 34 | t.Fatalf("scripts %v: the panel reads %q", on, order) |
| 35 | } |
| 36 | said := text(t, rig, `#mapa-links-body`) |
| 37 | if !strings.Contains(said, "Nothing links to this day yet.") || |
| 38 | !strings.Contains(said, "No links out yet.") { |
| 39 | t.Fatalf("scripts %v: the empty lists read %q", on, said) |
| 40 | } |
| 41 | } |
| 42 | if found := axeSerious(t, rig); found != "" { |
| 43 | t.Fatalf("axe, a day with the key:\n%s", found) |
| 44 | } |
| 45 | } |
| 46 | |