| index a9a6ec2..b4f4aa0 100644 |
| --- a/internal/browsertest/ask_test.go |
| +++ b/internal/browsertest/ask_test.go |
| @@ -695,3 +695,59 @@ func TestAskMarkdownMatchesServer(t *testing.T) { |
| } |
| rig.Screen("#ask-panel", "the Assistant's simple Markdown") |
| } |
| + |
| +const focusedJS = `document.activeElement && document.activeElement.id` |
| + |
| +// The composer has focus when the page opens on a wide screen with the |
| +// chat open and ready, and only then. |
| +func TestAskFocusesFieldOnLoad(t *testing.T) { |
| + load := func(t *testing.T, rig *harness.Rig, path string) string { |
| + t.Helper() |
| + drive(t, rig, chromedp.Navigate(rig.Origin+path), chromedp.WaitVisible(chromedp.CSS(`body`)), chromedp.Sleep(500*time.Millisecond)) |
| + return harness.Evaluate[string](rig, focusedJS) |
| + } |
| + t.Run("desktop open", func(t *testing.T) { |
| + rig, _ := askBase(t) |
| + if got := load(t, rig, "/"); got != "ask-text" { |
| + t.Errorf("focus is %q, want the composer", got) |
| + } |
| + if y := harness.Evaluate[float64](rig, `scrollY`); y != 0 { |
| + t.Errorf("the page scrolled to %v", y) |
| + } |
| + if got := load(t, rig, "/ask"); got != "ask-text" { |
| + t.Errorf("/ask focus is %q, want the composer", got) |
| + } |
| + }) |
| + t.Run("desktop closed", func(t *testing.T) { |
| + rig, _, b := askBaseWith(t, nil) |
| + openPanel(t, rig) |
| + drive(t, rig, chromedp.Click(chromedp.CSS(`#ask-panel .ask-head button.close`))) |
| + askClosed(t, b, true) |
| + if got := load(t, rig, "/"); got == "ask-text" { |
| + t.Error("the closed chat's composer took focus") |
| + } |
| + }) |
| + t.Run("phone", func(t *testing.T) { |
| + rig, _, _ := askBaseOn(t, nil, chromedp.EmulateViewport(390, 844, chromedp.EmulateMobile, chromedp.EmulateScale(3))) |
| + if got := load(t, rig, "/"); got == "ask-text" { |
| + t.Error("the composer took focus on a phone") |
| + } |
| + if got := load(t, rig, "/ask"); got == "ask-text" { |
| + t.Error("/ask's composer took focus on a phone") |
| + } |
| + }) |
| + t.Run("not connected", func(t *testing.T) { |
| + var b *baseApp |
| + rig := newRig(t, func(origin string) http.Handler { |
| + b = newBase(t, baseConfig(origin)) |
| + return b.handler |
| + }) |
| + signInByEmail(t, rig, rig.Origin, b.mail) |
| + drive(t, rig, chromedp.EmulateViewport(1280, 800)) |
| + for _, path := range []string{"/", "/ask"} { |
| + if got := load(t, rig, path); got == "ask-text" { |
| + t.Errorf("%s: the composer took focus without a connection", path) |
| + } |
| + } |
| + }) |
| +} |