| 1 | //go:build browser |
| 2 | |
| 3 | // No page scrolls sideways at a phone's width, in a real Chromium. Run |
| 4 | // with `make browser`. |
| 5 | // |
| 6 | // The UI pass (2026-10-26) stopped values and dates from wrapping, and |
| 7 | // review found three pages that then ran wider than the screen: a long |
| 8 | // boxed value at 390px, the documents table at 417px, and the |
| 9 | // ?explain=facts table at 320px. Measured, not reasoned about: a nowrap |
| 10 | // rule is correct for a phone number and wrong for an address, and only |
| 11 | // the page can say which won. |
| 12 | // |
| 13 | // MUTATION-TESTED 2026-10-26, each reverted: the documents table's |
| 14 | // column-hiding breakpoint put back at 26rem → "/ at 417px is 434px |
| 15 | // wide"; the explanation table's scroll wrapper emptied → "…explain=facts |
| 16 | // at 320px is 484px wide"; every fact value made nowrap → "/?q=accounts+ |
| 17 | // email at 320px is 536px wide". |
| 18 | package memoriatest |
| 19 | |
| 20 | import ( |
| 21 | "bytes" |
| 22 | "context" |
| 23 | "io" |
| 24 | "log/slog" |
| 25 | "mime/multipart" |
| 26 | "net/http" |
| 27 | "net/url" |
| 28 | "path/filepath" |
| 29 | "testing" |
| 30 | "time" |
| 31 | |
| 32 | "amadan.net/rastrillo/rastrillo/db" |
| 33 | "amadan.net/rastrillo/rastrillo/harness" |
| 34 | "github.com/chromedp/cdproto/emulation" |
| 35 | "github.com/chromedp/chromedp" |
| 36 | |
| 37 | memoria "amadan.net/oficina/memoria/internal/memoria" |
| 38 | ) |
| 39 | |
| 40 | func TestNoSidewaysScrollAtPhoneWidths(t *testing.T) { |
| 41 | rig := harness.New(t, func(origin string) http.Handler { |
| 42 | logger := slog.New(slog.NewTextHandler(io.Discard, nil)) |
| 43 | d, err := db.Open(filepath.Join(t.TempDir(), "app.db"), logger) |
| 44 | if err != nil { |
| 45 | t.Fatalf("db.Open: %v", err) |
| 46 | } |
| 47 | t.Cleanup(func() { d.Close() }) |
| 48 | mux, _, err := memoria.AppForTest(d, origin, testDEK(t), logger) |
| 49 | if err != nil { |
| 50 | t.Fatalf("AppForTest: %v", err) |
| 51 | } |
| 52 | return mux |
| 53 | }) |
| 54 | for _, doc := range [][2]string{ |
| 55 | {"Leadership Team — Doc Parsons, Co-founder & Chief Operating Officer", "## Doc Parsons\n\n- +353 86 222 0820"}, |
| 56 | {"Office", "## Office Address\n\n- The office phone number is: +353 (0)1 547 7854\n" + |
| 57 | "- We also have the following unused phone numbers: +353 (0)1 598 1234\n" + |
| 58 | " - +353 (0)1 598 1235\n - +353 (0)1 598 1236\n\nOffice VAT: IE3384527RH"}, |
| 59 | {"Accounts", "## Contact\n\nAccounts email: accounts-payable-and-receivable-team@tito-example.ie"}, |
| 60 | // Astra, 2026-10-26: these two widened the page at 320px. |
| 61 | {"Front desk", "## Desk\n\nDesk phone: +353 (0)1 547 7854 ext. 12"}, |
| 62 | {"Billing", "## Billing\n\nBilling email: accounts-payable-and-receivable-team@tito-example.ie\n\n" + |
| 63 | "Sales email: sales@tito-example.ie\n\nSupport email: support@tito-example.ie\n\nLegal email: legal@tito-example.ie"}, |
| 64 | } { |
| 65 | var buf bytes.Buffer |
| 66 | mw := multipart.NewWriter(&buf) |
| 67 | _ = mw.WriteField("title", doc[0]) |
| 68 | _ = mw.WriteField("body", doc[1]) |
| 69 | mw.Close() |
| 70 | req, _ := http.NewRequest(http.MethodPost, rig.Origin+"/documents", &buf) |
| 71 | req.Header.Set("Content-Type", mw.FormDataContentType()) |
| 72 | req.Header.Set("Origin", rig.Origin) |
| 73 | res, err := http.DefaultClient.Do(req) |
| 74 | if err != nil { |
| 75 | t.Fatalf("store %q: %v", doc[0], err) |
| 76 | } |
| 77 | res.Body.Close() |
| 78 | } |
| 79 | |
| 80 | paths := []string{ |
| 81 | "/", |
| 82 | "/?q=" + url.QueryEscape("what is the office phone number?") + "&explain=facts", |
| 83 | "/?q=" + url.QueryEscape("office phone and vat"), |
| 84 | "/?q=" + url.QueryEscape("accounts email"), |
| 85 | // §8.10: the large card, the correction page, and reports. |
| 86 | "/?q=" + url.QueryEscape("office phone number"), |
| 87 | "/facts/correct?q=" + url.QueryEscape("office phone number"), |
| 88 | "/reports", |
| 89 | "/?q=" + url.QueryEscape("desk phone"), |
| 90 | "/facts/correct?q=" + url.QueryEscape("billing email"), |
| 91 | } |
| 92 | for _, width := range []int64{320, 390, 417, 640} { |
| 93 | for _, path := range paths { |
| 94 | var wide int64 |
| 95 | ctx, cancel := context.WithTimeout(rig.Context(), 20*time.Second) |
| 96 | err := chromedp.Do(ctx, |
| 97 | cdpStep(emulation.SetDeviceMetricsOverride, emulation.SetDeviceMetricsOverrideParams{Width: width, Height: 800, DeviceScaleFactor: 1, Mobile: true}), |
| 98 | chromedp.Navigate(rig.Origin+path), |
| 99 | chromedp.WaitReady(chromedp.CSS("body")), |
| 100 | evalInto(&wide, `document.documentElement.scrollWidth`), |
| 101 | ) |
| 102 | cancel() |
| 103 | if err != nil { |
| 104 | t.Fatalf("%s at %dpx: %v", path, width, err) |
| 105 | } |
| 106 | if wide > width { |
| 107 | t.Errorf("%s at %dpx is %dpx wide: the page scrolls sideways", path, width, wide) |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | |