| index 28dd0cf..9b91c3a 100644 |
| --- a/internal/browsertest/cards_test.go |
| +++ b/internal/browsertest/cards_test.go |
| @@ -304,6 +304,7 @@ func jobViewJS(id, status, side string) string { |
| if (!d.open) p.push("the details are closed"); |
| if (s.getAttribute("aria-expanded") !== "true") p.push("aria-expanded " + s.getAttribute("aria-expanded")); |
| if (!v.checkVisibility({ visibilityProperty: true })) return p.concat("the view is not drawn").join("; "); |
| + v.getAnimations().forEach((a) => a.finish()); // measured where it rests, not mid-rise |
| const r = v.getBoundingClientRect(), pill = j.querySelector(".pill").getBoundingClientRect(); |
| const chat = document.querySelector("#ask-panel").getBoundingClientRect(), head = document.querySelector("#ask-panel .ask-head").getBoundingClientRect(); |
| if (r.left < chat.left + 15.5 || r.right > chat.right - 15.5 || r.top < head.bottom || r.bottom > chat.bottom) p.push("outside the chat: " + JSON.stringify(r) + " in " + JSON.stringify(chat)); |
| @@ -436,9 +437,19 @@ func TestAskJobViewOpens(t *testing.T) { |
| settle() |
| drive(t, rig, chromedp.Click(chromedp.CSS(`#ask-panel .ask-head h2`))) |
| settle() |
| + // A tap on the chat's own words (nothing to focus there) gives focus |
| + // back to the pill. |
| + if got := pending(closedViewJS(id)); got != "" { |
| + t.Errorf("after a tap outside on the chat's header: %s", got) |
| + } |
| + // A tap on something that takes focus, the composer, keeps it there. |
| + drive(t, rig, chromedp.Click(chromedp.CSS(summary))) |
| + settle() |
| + drive(t, rig, chromedp.Click(chromedp.CSS(`#ask-panel textarea`))) |
| + settle() |
| if got := pending(`(() => { const j = document.querySelector(` + strconv.Quote(job) + `); |
| - return j.querySelector("details").open + " " + j.querySelector(".jobview").checkVisibility() + " " + j.querySelector("summary").getAttribute("aria-expanded"); })()`); got != "false false false" { |
| - t.Errorf("after a tap outside: open, shown, expanded: %s", got) |
| + return j.querySelector("details").open + " " + j.querySelector(".jobview").checkVisibility() + " " + j.querySelector("summary").getAttribute("aria-expanded") + " " + document.activeElement.tagName; })()`); got != "false false false TEXTAREA" { |
| + t.Errorf("after a tap outside on the composer: open, shown, expanded, focus: %s", got) |
| } |
| |
| // A new revision while it is open: still open, the new status, focus |
| @@ -494,3 +505,54 @@ func TestAskJobViewOpens(t *testing.T) { |
| t.Errorf("after the redraws: %s", got) |
| } |
| } |
| + |
| +// The job view goes with the chat: closing the docked chat from the |
| +// keyboard (its X, with Enter), or a narrowing screen that puts the chat |
| +// away, closes the view too. Escape afterwards is the page's own again, |
| +// and focus stays where closing the chat put it. |
| +func TestAskJobViewClosesWithTheChat(t *testing.T) { |
| + rig, f := askBase(t) |
| + openPanel(t, rig) |
| + id := f.AskJob("Building your website") |
| + job := `#ask-panel li.job[data-job="` + id + `"]` |
| + drive(t, rig, chromedp.WaitVisible(chromedp.CSS(job+" summary")), |
| + chromedp.Evaluate[chromedp.Void](`window.__esc = []; document.addEventListener("keydown", (e) => { if (e.key === "Escape") window.__esc.push(e.defaultPrevented); })`)) |
| + gone := `(() => { const j = document.querySelector(` + strconv.Quote(job) + `), p = []; |
| + if (j.querySelector("details").open || j.querySelector("summary").getAttribute("aria-expanded") !== "false") p.push("still open"); |
| + if (j.querySelector(".jobview").matches(":popover-open")) p.push("the popover shows"); |
| + if (document.querySelector("#ask-panel .scrim")?.checkVisibility()) p.push("the scrim shows"); |
| + return p.join("; "); })()` |
| + escape := func(when, focus string) { |
| + t.Helper() |
| + drive(t, rig, chromedp.Evaluate[chromedp.Void](`window.__esc = []`), chromedp.KeyEvent(kb.Escape), chromedp.Sleep(200*time.Millisecond)) |
| + if got := harness.Evaluate[string](rig, `JSON.stringify(window.__esc) + " " + document.activeElement.className`); got != "[false] "+focus { |
| + t.Errorf("%s, Escape (taken, focus): %s, want [false] %s", when, got, focus) |
| + } |
| + } |
| + |
| + // Closed from the keyboard: the chat's X, with Enter. |
| + drive(t, rig, chromedp.Click(chromedp.CSS(job+" summary")), chromedp.Sleep(250*time.Millisecond), |
| + chromedp.Focus(chromedp.CSS(`#ask-panel [data-ask-close]`)), chromedp.KeyEvent(kb.Enter), chromedp.Sleep(600*time.Millisecond)) |
| + if got := harness.Evaluate[string](rig, gone); got != "" { |
| + t.Errorf("the chat closed from its X: %s", got) |
| + } |
| + escape("the chat closed from its X", "base-btn") |
| + |
| + // Put away by a narrowing screen: a wide screen's open chat is not a |
| + // phone's, which opens from the springboard. |
| + drive(t, rig, chromedp.Click(chromedp.CSS(".base-btn")), chromedp.Poll[chromedp.Void](settledJS, chromedp.WithPollingTimeout(3*time.Second)), |
| + chromedp.WaitVisible(chromedp.CSS(job+" summary")), chromedp.Click(chromedp.CSS(job+" summary")), chromedp.Sleep(250*time.Millisecond)) |
| + if !harness.Evaluate[bool](rig, `document.querySelector(`+strconv.Quote(job+" .jobview")+`).matches(":popover-open")`) { |
| + t.Fatalf("the view did not open again") |
| + } |
| + drive(t, rig, chromedp.EmulateViewport(390, 844), chromedp.Sleep(600*time.Millisecond)) |
| + if got := harness.Evaluate[string](rig, gone); got != "" { |
| + t.Errorf("narrowed to a phone: %s", got) |
| + } |
| + drive(t, rig, chromedp.Evaluate[chromedp.Void](`document.body.focus()`)) |
| + escape("narrowed to a phone", "") |
| + drive(t, rig, chromedp.EmulateViewport(1280, 800), chromedp.Sleep(600*time.Millisecond)) |
| + if got := harness.Evaluate[string](rig, gone); got != "" { |
| + t.Errorf("widened again: %s", got) |
| + } |
| +} |