//go:build browser // No page scrolls sideways at a phone's width, in a real Chromium. Run // with `make browser`. // // The UI pass (2026-10-26) stopped values and dates from wrapping, and // review found three pages that then ran wider than the screen: a long // boxed value at 390px, the documents table at 417px, and the // ?explain=facts table at 320px. Measured, not reasoned about: a nowrap // rule is correct for a phone number and wrong for an address, and only // the page can say which won. // // MUTATION-TESTED 2026-10-26, each reverted: the documents table's // column-hiding breakpoint put back at 26rem → "/ at 417px is 434px // wide"; the explanation table's scroll wrapper emptied → "…explain=facts // at 320px is 484px wide"; every fact value made nowrap → "/?q=accounts+ // email at 320px is 536px wide". package memoriatest import ( "bytes" "context" "io" "log/slog" "mime/multipart" "net/http" "net/url" "path/filepath" "testing" "time" "amadan.net/rastrillo/rastrillo/db" "amadan.net/rastrillo/rastrillo/harness" "github.com/chromedp/cdproto/emulation" "github.com/chromedp/chromedp" memoria "amadan.net/oficina/memoria/internal/memoria" ) func TestNoSidewaysScrollAtPhoneWidths(t *testing.T) { rig := harness.New(t, func(origin string) http.Handler { logger := slog.New(slog.NewTextHandler(io.Discard, nil)) d, err := db.Open(filepath.Join(t.TempDir(), "app.db"), logger) if err != nil { t.Fatalf("db.Open: %v", err) } t.Cleanup(func() { d.Close() }) mux, _, err := memoria.AppForTest(d, origin, testDEK(t), logger) if err != nil { t.Fatalf("AppForTest: %v", err) } return mux }) for _, doc := range [][2]string{ {"Leadership Team — Doc Parsons, Co-founder & Chief Operating Officer", "## Doc Parsons\n\n- +353 86 222 0820"}, {"Office", "## Office Address\n\n- The office phone number is: +353 (0)1 547 7854\n" + "- We also have the following unused phone numbers: +353 (0)1 598 1234\n" + " - +353 (0)1 598 1235\n - +353 (0)1 598 1236\n\nOffice VAT: IE3384527RH"}, {"Accounts", "## Contact\n\nAccounts email: accounts-payable-and-receivable-team@tito-example.ie"}, // Astra, 2026-10-26: these two widened the page at 320px. {"Front desk", "## Desk\n\nDesk phone: +353 (0)1 547 7854 ext. 12"}, {"Billing", "## Billing\n\nBilling email: accounts-payable-and-receivable-team@tito-example.ie\n\n" + "Sales email: sales@tito-example.ie\n\nSupport email: support@tito-example.ie\n\nLegal email: legal@tito-example.ie"}, } { var buf bytes.Buffer mw := multipart.NewWriter(&buf) _ = mw.WriteField("title", doc[0]) _ = mw.WriteField("body", doc[1]) mw.Close() req, _ := http.NewRequest(http.MethodPost, rig.Origin+"/documents", &buf) req.Header.Set("Content-Type", mw.FormDataContentType()) req.Header.Set("Origin", rig.Origin) res, err := http.DefaultClient.Do(req) if err != nil { t.Fatalf("store %q: %v", doc[0], err) } res.Body.Close() } paths := []string{ "/", "/?q=" + url.QueryEscape("what is the office phone number?") + "&explain=facts", "/?q=" + url.QueryEscape("office phone and vat"), "/?q=" + url.QueryEscape("accounts email"), // §8.10: the large card, the correction page, and reports. "/?q=" + url.QueryEscape("office phone number"), "/facts/correct?q=" + url.QueryEscape("office phone number"), "/reports", "/?q=" + url.QueryEscape("desk phone"), "/facts/correct?q=" + url.QueryEscape("billing email"), } for _, width := range []int64{320, 390, 417, 640} { for _, path := range paths { var wide int64 ctx, cancel := context.WithTimeout(rig.Context(), 20*time.Second) err := chromedp.Do(ctx, cdpStep(emulation.SetDeviceMetricsOverride, emulation.SetDeviceMetricsOverrideParams{Width: width, Height: 800, DeviceScaleFactor: 1, Mobile: true}), chromedp.Navigate(rig.Origin+path), chromedp.WaitReady(chromedp.CSS("body")), evalInto(&wide, `document.documentElement.scrollWidth`), ) cancel() if err != nil { t.Fatalf("%s at %dpx: %v", path, width, err) } if wide > width { t.Errorf("%s at %dpx is %dpx wide: the page scrolls sideways", path, width, wide) } } } }