//go:build browser package gallery import ( "context" "net/http" "strings" "testing" "time" "github.com/chromedp/cdproto/emulation" "github.com/chromedp/chromedp" "amadan.net/rastrillo/fiesta" "amadan.net/rastrillo/fiesta/internal/harness" ) // TestEveryPageKindFitsAPhoneAt320: WCAG 2.2 AA 1.4.10 Reflow on one // page of every kind in the shell, in English and Arabic: the index, // Tokens, Icons, a family page and an example page at a 320 CSS-pixel // viewport must not need horizontal scrolling. Fiesta's own drive // over every example page in a11y_browser_test.go stays beside this // one; this reads the shell's other pages, in the other direction too. func TestEveryPageKindFitsAPhoneAt320(t *testing.T) { rig := harness.New(t, func(string) http.Handler { return treeHandler(t) }) ctx, cancel := context.WithTimeout(rig.Context(), 3*time.Minute) defer cancel() theme := fiesta.ThemeNames()[0] measured := 0 for _, locale := range []string{"en", "ar"} { for _, file := range []string{"index.html", "tokens.html", "icons.html", "form.html", "button.html"} { where := theme + "/" + locale + "/" + file mustRun(t, ctx, chromedp.ActionFunc(func(c context.Context) error { return emulation.SetDeviceMetricsOverride(320, 640, 1, false).Do(c) }), chromedp.Navigate(rig.Origin+pageAt(theme, locale, file)), chromedp.WaitReady("body"), ) present(t, ctx, where, "[rst-shell-sidebar]") var got struct { Doc, Client, Body int Over []string } at(t, ctx, measureJS, &got) if got.Doc > got.Client || got.Body > got.Client { t.Errorf("%s scrolls sideways at 320px (WCAG 1.4.10): document %dpx, body %dpx in a %dpx page\n widest: %s", where, got.Doc, got.Body, got.Client, strings.Join(got.Over, "\n ")) } measured++ } } t.Logf("%d pages measured", measured) }