| index 9b91c3a..6baeebd 100644 |
| --- a/internal/browsertest/cards_test.go |
| +++ b/internal/browsertest/cards_test.go |
| @@ -556,3 +556,77 @@ func TestAskJobViewClosesWithTheChat(t *testing.T) { |
| t.Errorf("widened again: %s", got) |
| } |
| } |
| + |
| +// A job redrawn (a new revision) keeps focus where it was: on a decision |
| +// under its pill, which moves to the new pill; on the pill or its link to |
| +// the work; and with its view open, on the view's title, its link to the |
| +// work, or Close. A decision drawn before its job keeps focus as the job |
| +// arrives and the decision moves under it. |
| +func TestAskJobRedrawKeepsFocus(t *testing.T) { |
| + rig, f := askBase(t) |
| + // Wide enough for a ready pill's link beside its status. |
| + drive(t, rig, chromedp.EmulateViewport(1500, 900)) |
| + openPanel(t, rig) |
| + wait := func(js string) { |
| + t.Helper() |
| + drive(t, rig, chromedp.Poll[chromedp.Void](js, chromedp.WithPollingTimeout(10*time.Second))) |
| + } |
| + options := []equipo.Option{{Value: "go", Label: "Go ahead"}, {Value: "later", Label: "Not yet"}} |
| + try := equipo.Link{Label: "Try it", URL: "https://preview.example.test/"} |
| + id := f.AskJob("Building your website") |
| + f.SetJob(id, "ready", "Ready to try", "Have a look.", try) |
| + goAhead := f.AskOutcomeFor(id, "This is ready. Go ahead?", options, nil) |
| + job := `#ask-panel li.job[data-job="` + id + `"]` |
| + wait(jobJS(id) + ` === ` + strconv.Quote("1 ready Ready to try [Try it] "+goAhead)) |
| + focusedJS := func(sel string) string { |
| + return `(() => { const a = document.activeElement, want = document.querySelector(` + strconv.Quote(sel) + `); |
| + if (!want) return "no " + ` + strconv.Quote(sel) + `; |
| + return a === want ? "" : "focus on " + a.tagName + "." + a.className + " " + (a.textContent || "").trim().slice(0, 30); })()` |
| + } |
| + rev := 2 |
| + redraw := func(where, sel string) { |
| + t.Helper() |
| + drive(t, rig, chromedp.Focus(chromedp.CSS(sel))) |
| + if got := harness.Evaluate[string](rig, focusedJS(sel)); got != "" { |
| + t.Fatalf("focusing %s: %s", where, got) |
| + } |
| + rev++ |
| + f.SetJob(id, "ready", "Ready to try", fmt.Sprintf("Revision %d.", rev), try) |
| + wait(`document.querySelector(` + strconv.Quote(job) + `)?.dataset.revision === "` + strconv.Itoa(rev) + `"`) |
| + drive(t, rig, chromedp.Sleep(150*time.Millisecond)) |
| + if got := harness.Evaluate[string](rig, focusedJS(sel)); got != "" { |
| + t.Errorf("focused on %s, redrawn: %s", where, got) |
| + } |
| + } |
| + redraw("the go-ahead's button", job+` ol.job-cards [data-card="`+goAhead+`"] button[value="go"]`) |
| + redraw("the pill", job+` summary`) |
| + redraw("the pill's link", job+` .pill-link`) |
| + drive(t, rig, chromedp.Click(chromedp.CSS(job+` summary`)), chromedp.Sleep(250*time.Millisecond)) |
| + redraw("the job view's title", job+` .jobview a.jv-title`) |
| + redraw("the job view's link", job+` .jobview a.jv-go`) |
| + redraw("the job view's Close", job+` .jobview [data-job-close]`) |
| + if got := harness.Evaluate[string](rig, `(() => { const j = document.querySelector(`+strconv.Quote(job)+`); |
| + return j.querySelector("details").open + " " + j.querySelector(".jobview").matches(":popover-open"); })()`); got != "true true" { |
| + t.Errorf("after the redraws the view (open, shown): %s", got) |
| + } |
| + drive(t, rig, chromedp.KeyEvent(kb.Escape), chromedp.Sleep(200*time.Millisecond)) |
| + |
| + // A decision of a job not yet drawn, focused, as the job arrives. (The |
| + // fake numbers its cards in turn: the job is the card after it.) |
| + n, err := strconv.Atoi(strings.TrimPrefix(goAhead, "c_")) |
| + if err != nil { |
| + t.Fatalf("card id %q", goAhead) |
| + } |
| + early := f.AskOutcomeFor(fmt.Sprintf("c_%04d", n+2), "And this one?", options, nil) |
| + button := `#ask-panel [data-card="` + early + `"] button[value="go"]` |
| + wait(`!!document.querySelector('#ask-panel .thread > [data-card="` + early + `"]')`) |
| + drive(t, rig, chromedp.Focus(chromedp.CSS(button))) |
| + if other := f.AskJob("Fixing the login"); other != fmt.Sprintf("c_%04d", n+2) { |
| + t.Fatalf("the next job is %s", other) |
| + } |
| + wait(`!!document.querySelector('#ask-panel li.job ol.job-cards > [data-card="` + early + `"]')`) |
| + drive(t, rig, chromedp.Sleep(150*time.Millisecond)) |
| + if got := harness.Evaluate[string](rig, focusedJS(button)); got != "" { |
| + t.Errorf("focused on a decision as its job arrived: %s", got) |
| + } |
| +} |