//go:build browser package browsertest import ( "context" "fmt" "net/http" "os" "path/filepath" "regexp" "strconv" "testing" "time" "github.com/chromedp/chromedp" "amadan.net/rastrillo/rastrillo/harness" "amadan.net/oficina/base/internal/equipo" "amadan.net/oficina/base/internal/equipo/equipotest" ) // noOverflow fails if the page is wider than the screen. func noOverflow(t *testing.T, rig *harness.Rig, page string) { t.Helper() if got := harness.Evaluate[string](rig, `(() => { const w = document.documentElement.clientWidth, s = document.documentElement.scrollWidth; if (s <= w) return ""; const wide = [...document.querySelectorAll("body *")].filter(e => e.getBoundingClientRect().right > w + 0.5) .slice(0, 5).map(e => e.tagName.toLowerCase() + "." + e.className + " " + Math.round(e.getBoundingClientRect().right)); return s + " > " + w + ": " + wide.join(", "); })()`); got != "" { t.Errorf("%s overflows the screen: %s", page, got) } } // mobileShot saves a full-page PNG when BASE_BROWSER_ARTIFACTS is set. func mobileShot(t *testing.T, rig *harness.Rig, name string) { t.Helper() dir := os.Getenv("BASE_BROWSER_ARTIFACTS") if dir == "" { return } drive(t, rig, chromedp.Func(func(ctx context.Context, target *chromedp.Target) error { _, err := chromedp.Evaluate[bool](`document.fonts.ready.then(() => true)`, chromedp.EvalAwaitPromise)(ctx, target) return err })) var png []byte drive(t, rig, chromedp.Func(func(ctx context.Context, target *chromedp.Target) error { var err error png, err = chromedp.FullScreenshot(100)(ctx, target) return err })) if err := os.MkdirAll(dir, 0o755); err != nil { t.Fatal(err) } if err := os.WriteFile(filepath.Join(dir, name+".png"), png, 0o644); err != nil { t.Fatal(err) } } // Base on an iPhone-sized screen: every page fits 390px, Home's top bar // stays on one line, and the chat is a full-screen sheet whose composer // stays on screen. func TestMobile(t *testing.T) { f := equipotest.New(t) f.Reply = func(string) string { return "You can ask me to plan work, check on a project, or start a task. What would you like to do?" } apps := teamApps(t) var b *baseApp rig := newRig(t, func(origin string) http.Handler { cfg := baseConfig(origin) cfg.EquipoOrigin = f.URL cfg.OficinaApps = apps b = newBase(t, cfg) return b.handler }) drive(t, rig, chromedp.EmulateViewport(390, 844, chromedp.EmulateMobile, chromedp.EmulateScale(3)), reducedMotion("dark", false)) drive(t, rig, chromedp.Navigate(rig.Origin+"/signin"), chromedp.WaitVisible(chromedp.CSS(`input[name="address"]`))) noOverflow(t, rig, "sign-in") installAll(t, b) signInByEmail(t, rig, rig.Origin, b.mail) // Home: on a phone the Base button sits on one line with the wordmark // and the avatar, and the Ask field is under the greeting. noOverflow(t, rig, "Home") if got := harness.Evaluate[string](rig, `(() => { const bar = document.querySelector(".topbar"), icon = document.querySelector("a.base-btn"), field = document.querySelector("a.ask-field"); const shown = [...bar.querySelectorAll(":scope > *, :scope > form > *")].filter(e => e.checkVisibility()); const mids = shown.map(e => Math.round(e.getBoundingClientRect().top + e.getBoundingClientRect().height / 2)); const problems = []; if (Math.max(...mids) - Math.min(...mids) > 2) problems.push("top bar wraps: " + mids.join(",")); if (!field.checkVisibility({ visibilityProperty: true })) problems.push("no Ask field under the greeting"); if (!icon || !icon.checkVisibility({ visibilityProperty: true })) return problems.concat("no Base button").join("; "); const r = icon.getBoundingClientRect(), me = document.querySelector(".me").getBoundingClientRect(); if (Math.round(r.width) !== 44 || Math.round(r.height) !== 44) problems.push("Base button is " + r.width + "x" + r.height); if (Math.round(me.width) !== 44) problems.push("avatar is " + me.width); if (icon.getAttribute("aria-label") !== "Ask Base") problems.push("Base button labelled " + icon.getAttribute("aria-label")); const used = shown.reduce((w, e) => w + e.getBoundingClientRect().width, 0); if (bar.clientWidth - used < 60) problems.push("no room to spare: " + (bar.clientWidth - used)); return problems.join("; "); })()`); got != "" { t.Errorf("Home's top bar on a phone: %s", got) } mobileShot(t, rig, "1-home") // Home on a phone is a springboard: every app, Store, People and // Settings among them, in four columns inside the glass panel. if got := harness.Evaluate[string](rig, springboardJS+`(`+gridNames(apps)+`)`); got != "" { t.Errorf("the springboard: %s", got) } checkContrast(t, rig, "Home on a phone, dark", ".lede", ".app-grid .label") viewportShot(t, rig, "home-phone") layoutShot(t, rig, "phone-home-dark") // The chat before connecting. drive(t, rig, chromedp.Click(chromedp.CSS(`a.base-btn`)), chromedp.WaitVisible(chromedp.CSS(`#ask-panel [data-when="connect"] button`)), // The sheet slides up; click once it has arrived. chromedp.Poll[chromedp.Void](`document.querySelector("#ask-panel").getBoundingClientRect().top === 0`, chromedp.WithPollingTimeout(3*time.Second))) mobileShot(t, rig, "2-panel-connect") // Connect from the panel: the code page, then back to the open panel. drive(t, rig, chromedp.Click(chromedp.CSS(`#ask-panel [data-when="connect"] button`)), chromedp.WaitVisible(chromedp.CSS(`p.code`))) noOverflow(t, rig, "the connect page") mobileShot(t, rig, "3-connect-code") if err := f.Approve(harness.Evaluate[string](rig, `document.querySelector("p.code").textContent`)); err != nil { t.Fatal(err) } if _, err := b.db.Exec(`UPDATE equipo_links SET polled_at = ?`, time.Now().Add(-time.Minute).UTC()); err != nil { t.Fatal(err) } drive(t, rig, chromedp.Click(chromedp.CSS(`form[action="/ask/connect/check"] button`)), chromedp.WaitVisible(chromedp.CSS(`#ask-panel textarea`)), chromedp.Poll[chromedp.Void](`document.querySelector("#ask-panel").getBoundingClientRect().top === 0`, chromedp.WithPollingTimeout(3*time.Second))) // Mid-conversation: the sheet fills the screen, the header is at the // top, the composer on screen at the bottom, targets 44px. drive(t, rig, chromedp.SendKeys(chromedp.CSS(`#ask-text`), "What can I do"), chromedp.Click(chromedp.CSS(`#ask-panel form.composer button.send`)), chromedp.Poll[chromedp.Void](`!document.querySelector("#ask-panel .thinking, #ask-panel .draft, #ask-panel .think-line") && [...document.querySelectorAll("#ask-panel .msg.coordinator")].some(m => m.dataset.id)`, chromedp.WithPollingTimeout(10*time.Second)), chromedp.Poll[chromedp.Void](`(() => { const r = document.querySelector("#ask-panel").getBoundingClientRect(); return r.left === 0 && r.top === 0 })()`, chromedp.WithPollingTimeout(3*time.Second))) if got := harness.Evaluate[string](rig, `(() => { const vh = window.visualViewport.height, vw = window.visualViewport.width, problems = []; const p = document.querySelector("#ask-panel").getBoundingClientRect(); if (Math.round(p.width) !== Math.round(vw) || Math.round(p.height) !== Math.round(vh)) problems.push("sheet " + p.width + "x" + p.height); const head = document.querySelector("#ask-panel .ask-head").getBoundingClientRect(); if (head.top < 0 || head.top > 1) problems.push("header at " + head.top); const c = document.querySelector("#ask-panel form.composer").getBoundingClientRect(); if (c.top < 0 || c.bottom > vh + 0.5 || c.height === 0) problems.push("composer at " + c.top + "-" + c.bottom + " of " + vh); if (document.querySelector("#ask-panel .ask-head summary, #ask-panel .ask-head a")) problems.push("the header has a menu or a link"); if (head.height > 64) problems.push("header is " + head.height + "px tall"); // Send shows once something is typed. const ta = document.querySelector("#ask-text"); ta.value = "x"; ta.dispatchEvent(new Event("input")); for (const a of document.querySelector("#ask-panel form.composer button.send").getAnimations()) a.finish(); // measured once it has grown in for (const el of document.querySelectorAll("#ask-panel .ask-head .close, #ask-panel form.composer button.send, #ask-panel textarea")) { const r = el.getBoundingClientRect(); if (r.height < 44 || r.width < 44) problems.push((el.getAttribute("aria-label") || el.textContent.trim()) + " is " + r.width + "x" + r.height); } const field = document.querySelector("#ask-panel textarea").getBoundingClientRect(); const send = document.querySelector("#ask-panel form.composer button.send").getBoundingClientRect(); ta.value = ""; ta.dispatchEvent(new Event("input")); if (field.left > 12 || vw - send.right > 12) problems.push("composer gaps " + field.left + " and " + (vw - send.right)); const st = document.querySelector("#ask-panel .ask-status"); st.textContent = "Thinking…"; if (Math.abs(st.getBoundingClientRect().left - field.left) > 1) problems.push("status at " + st.getBoundingClientRect().left + ", composer at " + field.left); st.textContent = ""; const m = document.querySelector("#ask-panel .msg.coordinator").getBoundingClientRect(); if (m.right > vw) problems.push("a message overflows"); return problems.join("; "); })()`); got != "" { t.Errorf("the chat on a phone: %s", got) } mobileShot(t, rig, "4-panel-conversation") layoutShot(t, rig, "phone-chat-dark") // Home behind the sheet is pushed back: smaller, dimmed and blurred. if got := harness.Evaluate[string](rig, `(() => { const s = getComputedStyle(document.querySelector("main.home")); return s.transform + " | " + s.filter; })()`); !regexp.MustCompile(`^matrix\(0\.94, 0, 0, 0\.94, [^)]*\) \| .*blur\(`).MatchString(got) { t.Errorf("Home behind the open sheet: %s, want scaled to 0.94 and blurred", got) } mobileShot(t, rig, "4c-panel-tight") drive(t, rig, chromedp.KeyEvent("\u001b"), chromedp.Poll[chromedp.Void](phoneClosedJS, chromedp.WithPollingTimeout(3*time.Second))) // Focus goes back to the Base button, which opened it. drive(t, rig, chromedp.Poll[chromedp.Void](`document.activeElement.className === "base-btn"`, chromedp.WithPollingTimeout(3*time.Second))) // Reopened from the Base button, mid-conversation: the sheet slides up. drive(t, rig, chromedp.Click(chromedp.CSS(`a.base-btn`)), chromedp.Sleep(90*time.Millisecond)) if top := harness.Evaluate[float64](rig, `document.querySelector("#ask-panel").getBoundingClientRect().top`); top <= 1 { t.Errorf("the sheet did not slide up: at %v moments after opening", top) } opening := harness.Read(rig, chromedp.CaptureScreenshot()) if dir := os.Getenv("BASE_LAYOUT_ARTIFACTS"); dir != "" { if err := os.WriteFile(filepath.Join(dir, "phone-chat-opening.png"), opening, 0o644); err != nil { t.Fatal(err) } } drive(t, rig, chromedp.WaitVisible(chromedp.CSS(`#ask-panel .msg.coordinator`)), chromedp.Poll[chromedp.Void](`document.querySelector("#ask-panel").getBoundingClientRect().top === 0`, chromedp.WithPollingTimeout(3*time.Second))) mobileShot(t, rig, "4b-home-panel-open") drive(t, rig, chromedp.KeyEvent("\u001b")) // With reduced motion there is no slide and no push-back: it just shows. drive(t, rig, reducedMotion("dark", true), chromedp.Poll[chromedp.Void](phoneClosedJS, chromedp.WithPollingTimeout(3*time.Second)), chromedp.Click(chromedp.CSS(`a.base-btn`)), chromedp.Sleep(30*time.Millisecond)) if got := harness.Evaluate[string](rig, `(() => { const d = document.querySelector("#ask-panel").getBoundingClientRect(); const h = getComputedStyle(document.querySelector("main.home")); return d.top + " " + h.transform + " " + h.filter + " " + h.opacity; })()`); got != "0 none none 1" { t.Errorf("with reduced motion the sheet and Home are %q (want 0 none none 1: no slide, no scale, no blur or dimming)", got) } drive(t, rig, chromedp.KeyEvent("\u001b"), reducedMotion("dark", false)) // Every inner page has an X at its top right, 44px, that goes Home. for _, p := range []struct{ path, wait, name string }{ {"/store", ".sheet", "5-store"}, {"/people", ".sheet", "6-people"}, {"/settings", ".sheet", "7-settings"}, {"/ask", ".ask-page .composer", "8-ask"}, } { drive(t, rig, chromedp.Navigate(rig.Origin+p.path), chromedp.WaitVisible(chromedp.CSS(p.wait))) noOverflow(t, rig, p.path) if got := harness.Evaluate[string](rig, closeJS); got != "" { t.Errorf("%s's close: %s", p.path, got) } mobileShot(t, rig, p.name) drive(t, rig, chromedp.Click(chromedp.CSS(`.crumb a.close`)), chromedp.WaitVisible(chromedp.CSS(`.hello`))) if here := harness.Read(rig, chromedp.Location()); here != rig.Origin+"/" { t.Errorf("%s's close went to %s, want Home", p.path, here) } } } // closeJS describes what is wrong with an inner page's close, "" if // nothing: one X at the top right of the sheet, 44px, named Close, a link // to Home. const closeJS = `(() => { const all = document.querySelectorAll(".crumb a.close"), problems = []; if (all.length !== 1) return all.length + " close links"; const x = all[0], r = x.getBoundingClientRect(), sheet = x.closest(".sheet").getBoundingClientRect(); if (x.getAttribute("href") !== "/") problems.push("goes to " + x.getAttribute("href")); if (x.getAttribute("aria-label") !== "Close") problems.push("named " + x.getAttribute("aria-label")); if (!x.checkVisibility({ visibilityProperty: true })) problems.push("not shown"); if (Math.round(r.width) !== 44 || Math.round(r.height) !== 44) problems.push("is " + r.width + "x" + r.height); if (sheet.right - r.right > 36 || r.top - sheet.top > 36 || r.top < sheet.top) problems.push("not at the top right: " + Math.round(sheet.right - r.right) + " from the right, " + Math.round(r.top - sheet.top) + " from the top"); const w = document.querySelector(".crumb .wordmark").getBoundingClientRect(); if (Math.abs((w.top + w.bottom) / 2 - (r.top + r.bottom) / 2) > 1) problems.push("not level with the wordmark"); if (getComputedStyle(x).borderRadius !== "50%") problems.push("not round: " + getComputedStyle(x).borderRadius); return problems.join("; "); })()` // On a phone a double tap is two taps, never a zoom: the page and what is // tapped on it are touch-action: manipulation. Pinching still zooms: the // viewport sets no maximum scale and doesn't stop the person scaling it. func TestMobileNoDoubleTapZoom(t *testing.T) { rig, _, b := askBaseOn(t, nil, chromedp.EmulateViewport(390, 844, chromedp.EmulateMobile, chromedp.EmulateScale(3))) installAll(t, b) for _, p := range []struct{ path, wait string }{ {"/", ".hello"}, {"/settings", "form.segmented"}, {"/store", ".listing"}, {"/people", ".people"}, {"/ask", ".ask-page .composer"}, } { drive(t, rig, chromedp.Navigate(rig.Origin+p.path), chromedp.WaitVisible(chromedp.CSS(p.wait))) if got := harness.Evaluate[string](rig, `(() => { const problems = [], meta = document.querySelector('meta[name="viewport"]').content; if (/maximum-scale|user-scalable/i.test(meta)) problems.push("the viewport stops zooming: " + meta); for (const el of [document.documentElement, document.body, ...document.querySelectorAll("a, button, input, textarea, summary, label, li, p, .sheet, .glass")]) { const ta = getComputedStyle(el).touchAction; if (ta !== "manipulation") problems.push(el.tagName.toLowerCase() + (el.className ? "." + el.className : "") + " is touch-action: " + ta); } return [...new Set(problems)].slice(0, 6).join("; "); })()`); got != "" { t.Errorf("%s: %s", p.path, got) } } } // phoneClosedJS is true once the chat on a phone has gone: no phone-open, // out of sight. const phoneClosedJS = `!document.documentElement.classList.contains("phone-open") && !document.querySelector("#ask-panel").checkVisibility({ visibilityProperty: true })` // On a phone Home opens on the springboard with Ask Base out of sight, // whatever the member chose on a wide screen; the field brings it up full // screen over Home, which is out of reach behind it, and X or Escape closes // it. Neither is remembered. func TestAskPhoneUnchanged(t *testing.T) { rig, _, b := askBaseOn(t, nil, chromedp.EmulateViewport(390, 844, chromedp.EmulateMobile, chromedp.EmulateScale(3))) whole := `(() => { const r = document.querySelector("#ask-panel").getBoundingClientRect(); return [r.left, r.top, r.width, r.height].map(Math.round).join(" ") === "0 0 390 844" })()` for _, closed := range []bool{false, true} { if _, err := b.db.Exec(`UPDATE members SET ask_closed = ?`, closed); err != nil { t.Fatal(err) } when := fmt.Sprintf("ask_closed %v", closed) drive(t, rig, chromedp.Navigate(rig.Origin+"/"), chromedp.WaitVisible(chromedp.CSS("a.ask-field"))) if got := harness.Evaluate[string](rig, `(() => { const problems = []; if (document.querySelector("#ask-panel").checkVisibility({ visibilityProperty: true })) problems.push("the chat shows"); if (!document.querySelector("#ask-panel").inert) problems.push("the chat is in reach"); if (document.querySelector("main.home").inert) problems.push("Home is out of reach"); const apps = document.querySelector("nav.apps").getBoundingClientRect(); if (apps.top > innerHeight || apps.width < 300) problems.push("no springboard: the apps at " + apps.top + ", " + apps.width + " wide"); return problems.join("; "); })()`); got != "" { t.Errorf("%s, Home: %s", when, got) } drive(t, rig, chromedp.Click(chromedp.CSS("a.ask-field")), chromedp.Poll[chromedp.Void](whole, chromedp.WithPollingTimeout(3*time.Second))) // Only transform moves Home and the header back; the blur just applies. if got := harness.Evaluate[string](rig, `getComputedStyle(document.querySelector("main.home")).transitionProperty + " " + getComputedStyle(document.querySelector(".topbar")).transitionProperty`); got != "transform transform" { t.Errorf("%s: Home and the header transition %q, want transform alone", when, got) } if got := harness.Evaluate[string](rig, `[document.documentElement.classList.contains("phone-open"), document.activeElement.id, document.querySelector("main.home").inert, document.querySelector(".topbar").inert].join(" ")`); got != "true ask-text true true" { t.Errorf("%s, opened by the field: %q, want phone-open, focus in the composer, Home and the header out of reach", when, got) } if closed { mobileShot(t, rig, "9-chat-open-closed-on-desktop") } else { drive(t, rig, reducedMotion("light", false)) layoutShot(t, rig, "phone-chat-light") drive(t, rig, reducedMotion("dark", false)) } drive(t, rig, chromedp.Click(chromedp.CSS(`#ask-panel .ask-head button.close`)), chromedp.Poll[chromedp.Void](phoneClosedJS, chromedp.WithPollingTimeout(3*time.Second))) if got := harness.Evaluate[string](rig, `document.activeElement.className + " " + document.querySelector("main.home").inert`); got != "ask-field false" { t.Errorf("%s, after X: %q, want focus on the field and Home in reach", when, got) } drive(t, rig, chromedp.Click(chromedp.CSS("a.ask-field")), chromedp.Poll[chromedp.Void](whole, chromedp.WithPollingTimeout(3*time.Second)), chromedp.KeyEvent("\u001b"), chromedp.Poll[chromedp.Void](phoneClosedJS, chromedp.WithPollingTimeout(3*time.Second))) var got bool if err := b.db.QueryRow(`SELECT ask_closed FROM members`).Scan(&got); err != nil || got != closed { t.Errorf("%s: a phone's open and close were kept: ask_closed %v %v", when, got, err) } } // Without scripts the field and the Base button go to /ask, and keep // no wide-screen choice. drive(t, rig, scriptsDisabled(true)) defer drive(t, rig, scriptsDisabled(false)) for _, opener := range []string{"a.ask-field", "a.base-btn"} { drive(t, rig, chromedp.Navigate(rig.Origin+"/"), chromedp.WaitVisible(chromedp.CSS(opener)), chromedp.Click(chromedp.CSS(opener)), chromedp.WaitVisible(chromedp.CSS(".ask-page .composer"))) if here := harness.Read(rig, chromedp.Location()); here != rig.Origin+"/ask" { t.Errorf("scripts off, %s led to %s, want /ask", opener, here) } var got bool if err := b.db.QueryRow(`SELECT ask_closed FROM members`).Scan(&got); err != nil || !got { t.Errorf("scripts off, %s changed the wide-screen choice: ask_closed %v %v", opener, got, err) } } } // The job view on a phone (plan decision D13): a sheet from the foot of // the screen, over the dimmed chat (a scrim), the title's arrow always // showing. A tap on the scrim closes it, and focus goes back to the pill. // Without scripts the pill's
opens in place, under the pill. func TestAskJobViewIsASheetOnPhones(t *testing.T) { rig, f, _ := askBaseOn(t, nil, chromedp.EmulateViewport(390, 844, chromedp.EmulateMobile, chromedp.EmulateScale(3))) drive(t, rig, chromedp.Navigate(rig.Origin+"/"), chromedp.WaitVisible(chromedp.CSS("a.ask-field")), chromedp.Click(chromedp.CSS("a.ask-field")), chromedp.WaitVisible(chromedp.CSS(`#ask-panel textarea`)), chromedp.Poll[chromedp.Void](readJS, chromedp.WithPollingTimeout(5*time.Second)), chromedp.Poll[chromedp.Void](`document.querySelector("#ask-panel").getBoundingClientRect().top === 0`, chromedp.WithPollingTimeout(3*time.Second))) f.Say("On it.") id := f.AskJob("Building your website") job := `#ask-panel li.job[data-job="` + id + `"]` drive(t, rig, chromedp.WaitVisible(chromedp.CSS(job+" summary")), chromedp.Click(chromedp.CSS(job+" summary")), chromedp.Sleep(400*time.Millisecond)) sheet := `(() => { const j = document.querySelector(` + strconv.Quote(job) + `), v = j.querySelector(".jobview"), s = j.querySelector("summary"), p = []; if (!j.querySelector("details").open || s.getAttribute("aria-expanded") !== "true") p.push("not open"); if (!v.checkVisibility()) return p.concat("the view is not drawn").join("; "); const r = v.getBoundingClientRect(); if (Math.abs(r.bottom - innerHeight) > 0.5 || Math.abs(r.left) > 0.5 || Math.abs(r.right - innerWidth) > 0.5) p.push("not a sheet at the foot: " + JSON.stringify(r) + " in " + innerWidth + "x" + innerHeight); const mid = document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2); if (!v.contains(mid)) p.push("covered at its middle by " + (mid && mid.className)); const scrim = document.querySelector("#ask-panel .scrim"); if (!scrim || !scrim.checkVisibility()) p.push("no scrim"); else if (document.elementFromPoint(innerWidth / 2, 120) !== scrim) p.push("the chat is not behind the scrim: " + document.elementFromPoint(innerWidth / 2, 120)?.className); if (document.activeElement !== v.querySelector("[data-job-close]")) p.push("focus on " + document.activeElement.className); if (getComputedStyle(v.querySelector(".jv-title svg")).opacity !== "1") p.push("the title's arrow hides"); return p.join("; "); })()` if got := harness.Evaluate[string](rig, sheet); got != "" { t.Errorf("the job view on a phone: %s", got) } for _, scheme := range []string{"dark", "light"} { drive(t, rig, prefersScheme(scheme), chromedp.Sleep(300*time.Millisecond)) // Measured before the full-page shot, which leaves a phone's // screenshots cut short for a moment. checkContrast(t, rig, "the job view on a phone, "+scheme, job+" .jobview h3", job+" .jv-stage", job+" .jv-detail") mobileShot(t, rig, "jobview-working-phone-"+scheme) } drive(t, rig, prefersScheme("dark")) // A new revision keeps the sheet up. f.SetJob(id, "ready", "Ready to try", "Have a look.", equipo.Link{Label: "Try it", URL: "https://preview.example.test/"}) drive(t, rig, chromedp.Poll[chromedp.Void](`document.querySelector(`+strconv.Quote(job+" .jv-stage")+`).textContent === "Ready to try"`, chromedp.WithPollingTimeout(10*time.Second)), chromedp.Sleep(300*time.Millisecond)) if got := harness.Evaluate[string](rig, sheet); got != "" { t.Errorf("the job view on a phone, redrawn: %s", got) } for _, scheme := range []string{"dark", "light"} { drive(t, rig, prefersScheme(scheme), chromedp.Sleep(300*time.Millisecond)) mobileShot(t, rig, "jobview-ready-phone-"+scheme) } drive(t, rig, prefersScheme("dark")) // A tap on the scrim, above the sheet, closes it. drive(t, rig, chromedp.MouseClickXY(195, 120), chromedp.Sleep(300*time.Millisecond)) if got := harness.Evaluate[string](rig, `(() => { const j = document.querySelector(`+strconv.Quote(job)+`), s = j.querySelector("summary"), p = []; if (j.querySelector("details").open || s.getAttribute("aria-expanded") !== "false") p.push("still open"); if (j.querySelector(".jobview").checkVisibility()) p.push("the view shows"); if (document.querySelector("#ask-panel .scrim")?.checkVisibility()) p.push("the scrim shows"); if (document.activeElement !== s) p.push("focus on " + document.activeElement.className); if (!document.documentElement.classList.contains("phone-open")) p.push("the chat closed"); return p.join("; "); })()`); got != "" { t.Errorf("after a tap on the scrim: %s", got) } mobileShot(t, rig, "job-ready-phone-closed") // Without scripts: /ask, and the pill opens its view in place, just // under its row, with no Close and no scrim. drive(t, rig, scriptsDisabled(true)) defer drive(t, rig, scriptsDisabled(false)) page := `.ask-page li.job[data-job="` + id + `"]` drive(t, rig, chromedp.Navigate(rig.Origin+"/ask"), chromedp.WaitVisible(chromedp.CSS(page+" summary")), chromedp.Click(chromedp.CSS(page+" summary")), chromedp.Sleep(200*time.Millisecond)) if got := harness.Evaluate[string](rig, `(() => { const j = document.querySelector(`+strconv.Quote(page)+`), v = j.querySelector(".jobview"), p = []; if (!j.querySelector("details").open) p.push("closed"); if (!v.checkVisibility()) return p.concat("the view is not drawn").join("; "); const r = v.getBoundingClientRect(), pill = j.querySelector("summary").getBoundingClientRect(); if (r.top < pill.bottom || r.top - pill.bottom > 12 || r.left < pill.left - 0.5) p.push("not under the pill: " + JSON.stringify(r) + " pill " + JSON.stringify(pill)); if (v.querySelector("[data-job-close]").checkVisibility()) p.push("Close shows"); if (document.querySelector(".scrim")) p.push("a scrim"); if (v.querySelector(".jv-stage").textContent !== "Ready to try" || v.querySelector(".jv-go")?.textContent !== "Try it") p.push("its words: " + v.innerText); return p.join("; "); })()`); got != "" { t.Errorf("scripts off, the job view: %s", got) } mobileShot(t, rig, "jobview-ready-phone-noscript") }