//go:build browser package fichastest import ( "encoding/json" "fmt" "slices" "testing" "amadan.net/rastrillo/rastrillo/harness" "github.com/chromedp/chromedp" ) // File is the first menu, as in Docs, Slides and Mapa (level-up build // note 24; Paul, 2026-11-22: "Why is there no 'File' menu?"). It keeps // Card's rows, and has no Import until the Notion databases phase gives // Fichas an importer. Below 800px the menus are the bar's own second // row (estilo's Menu sheet carries the types and actions, not the // menus), so a phone reaches File's very rows; with scripts off File is // a
of links. // fileMenu is File's rows as drawn, a divider as "—", the first menu's // title and whether it is shown, and any import link on the page. const fileMenu = `(function () { var first = document.querySelector("[estilo-menubar] [estilo-menubar-title]"); var file = document.getElementById("fichas-menu-file"); var rows = Array.prototype.map.call( file.querySelectorAll("[estilo-menu] > hr, [estilo-menu-label]"), function (row) { return row.tagName === "HR" ? "—" : row.textContent; }); return JSON.stringify({first: first.textContent, shown: first.checkVisibility(), rows: rows, imports: document.querySelectorAll('a[href*="import"]').length}); })()` // rowsOffScreen names File's rows that are hidden or cross the // viewport's sides. const rowsOffScreen = `Array.prototype.filter.call( document.querySelectorAll("#fichas-menu-file [estilo-menu-item]"), function (row) { var box = row.getBoundingClientRect(); return !row.checkVisibility() || box.left < 0 || box.right > document.documentElement.clientWidth; }).map(function (row) { return row.textContent; }).join(", ")` type fileState struct { First string Shown bool Rows []string Imports int } func TestFileIsTheFirstMenu(t *testing.T) { s := seedCards(t, 2) card := cardPath(s.ids[0]) want := map[string][]string{ "/t/t_customer": {"New customer"}, card: {"New customer", "Open full page", "History", "—", "Delete…"}, } for _, live := range []bool{false, true} { for path, rows := range want { for _, width := range []int64{1440, 390} { name := fmt.Sprintf("%s at %dpx, scripts %v", path, width, live) var raw string s.rig.Run(scriptsOn(live), viewport(width), chromedp.Navigate(s.rig.Origin+path), chromedp.WaitReady(`[estilo-bar]`), harness.Into(&raw, chromedp.Evaluate[string](fileMenu))) var got fileState if err := json.Unmarshal([]byte(raw), &got); err != nil { t.Fatalf("%s: %v", name, err) } if got.First != "File" || !got.Shown { t.Errorf("%s: the first menu is %q, shown %v", name, got.First, got.Shown) } if !slices.Equal(got.Rows, rows) { t.Errorf("%s: File is %q, want %q", name, got.Rows, rows) } // The phone reaches File's very rows: open, each is shown // and inside the viewport's width. var off string s.rig.Run(chromedp.Click(`#fichas-menu-file > summary`), harness.Into(&off, chromedp.Evaluate[string](rowsOffScreen))) if off != "" { t.Errorf("%s: File's rows not on screen: %s", name, off) } if got.Imports != 0 { t.Errorf("%s: %d import links, before Fichas has an importer", name, got.Imports) } } } // File → New customer opens the form, by pointer, on a phone // and wide. for _, width := range []int64{1440, 390} { s.rig.Run(scriptsOn(live), viewport(width), chromedp.Navigate(s.rig.Origin+card), chromedp.Click(`#fichas-menu-file > summary`), chromedp.Click(`#fichas-menu-file a[href^="/cards/new"]`), chromedp.WaitReady(`form[action="/cards"]`)) } } s.rig.Run(scriptsOn(true)) for _, width := range []int64{1440, 390} { axeCheckWith(t, s.rig, card, width, chromedp.Click(`#fichas-menu-file > summary`), chromedp.WaitVisible(`#fichas-menu-file a[href$="/history"]`)) } }