| index 8da4e381..134ef64a 100644 |
| --- a/internal/equipo/team_taste_browser_test.go |
| +++ b/internal/equipo/team_taste_browser_test.go |
| @@ -134,3 +134,81 @@ func TestBrowserTasteDrafts(t *testing.T) { |
| t.Errorf("script errors: %s", got) |
| } |
| } |
| + |
| +// TestBrowserNeedsDrafts (Task 8 review, fix round 2): the Needs you page |
| +// renders several decisions in one live region, each with a More options |
| +// form keyed "more" and a field named note. A refresh keeps each |
| +// decision's note in its own form: the key is scoped by the decision's |
| +// task, so one note never overwrites or joins another task's. |
| +func TestBrowserNeedsDrafts(t *testing.T) { |
| + var lines []taskLine |
| + for _, id := range []string{"tk1", "tk2"} { |
| + c := feedbackTask(feedbackRounds()) |
| + c.task.ID, c.card.ID, c.card.TaskID = id, "c"+id, id |
| + line := taskLine{Task: c.task, Card: c.card} |
| + line.Decision = decisionOf(c.task, line) |
| + if line.Decision == nil || !line.Decision.More { |
| + t.Fatalf("%s: no decision with More options", id) |
| + } |
| + lines = append(lines, line) |
| + } |
| + var content bytes.Buffer |
| + if err := pages["work_needs"].ExecuteTemplate(&content, "content", pageData{Thin: workView{Decisions: lines}}); err != nil { |
| + t.Fatal(err) |
| + } |
| + head := fmt.Sprintf(`<!doctype html><html lang="en"><head><meta charset="utf-8"><link rel="stylesheet" href="%s"><link rel="stylesheet" href="%s"><link rel="stylesheet" href="%s">`+ |
| + `<script>window.errors = []; addEventListener("error", e => errors.push(String(e.message)));</script><script defer src="%s"></script></head><body>`, |
| + assets.Path("static/tokens.css"), assets.Path("static/theme.css"), assets.Path("static/equipo.css"), assets.Path("static/work-stream.js")) |
| + mux := http.NewServeMux() |
| + mux.Handle("GET /static/", assets.Handler()) |
| + mux.HandleFunc("GET /needs-you", func(w http.ResponseWriter, r *http.Request) { |
| + w.Header().Set("Content-Type", "text/html; charset=utf-8") |
| + fmt.Fprint(w, head+content.String()+`</body></html>`) |
| + }) |
| + mux.HandleFunc("GET /tasks/{task}/files/{id}", func(w http.ResponseWriter, r *http.Request) { http.NotFound(w, r) }) |
| + server := httptest.NewServer(mux) // 127.0.0.1 |
| + defer server.Close() |
| + |
| + opts := append(chromedp.DefaultExecAllocatorOptions[:], chromedp.ExecPath(harness.ChromePath(t)), chromedp.NoSandbox, chromedp.UserDataDir(t.TempDir())) |
| + alloc, stop := chromedp.NewExecAllocator(context.Background(), opts...) |
| + defer stop() |
| + ctx, cancel := chromedp.NewContext(alloc) |
| + defer cancel() |
| + ctx, timeout := context.WithTimeout(ctx, 60*time.Second) |
| + defer timeout() |
| + run := func(a chromedp.Action[chromedp.Void]) { |
| + t.Helper() |
| + if _, err := chromedp.Run(ctx, a); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + eval := func(js string) string { |
| + t.Helper() |
| + out, err := chromedp.Run(ctx, chromedp.Evaluate[string](js, chromedp.EvalAwaitPromise)) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return out |
| + } |
| + note := func(task string) string { |
| + return `document.querySelector('[data-decision="` + task + `"] form[data-draft-key="more"] [name=note]')` |
| + } |
| + run(chromedp.Navigate(server.URL + "/needs-you")) |
| + if got := eval(`new Promise(r => setTimeout(() => r(document.querySelectorAll('form[data-draft-key="more"] [name=note]').length + " " + errors.join(";")), 300))`); got != "2 " { |
| + t.Fatalf("More options notes on the page: %s", got) |
| + } |
| + // A swap waits while a form has the focus: type each, then move on. |
| + for task, text := range map[string]string{"tk1": "fewer colours", "tk2": "bigger type"} { |
| + eval(`(` + note(task) + `.focus(), "")`) |
| + run(chromedp.KeyEvent(text)) |
| + } |
| + eval(`(document.activeElement.blur(), document.querySelector("#work-needs").dataset.old = "1", document.dispatchEvent(new Event("equipo:work")), "")`) |
| + if got := eval(`new Promise(r => { const t0 = Date.now(); (function wait() { const s = document.querySelector("#work-needs"); if (s && !s.dataset.old) return r("ok"); if (Date.now() - t0 > 5000) return r("no refresh " + errors.join(";")); setTimeout(wait, 50); })(); })`); got != "ok" { |
| + t.Fatal(got) |
| + } |
| + for task, want := range map[string]string{"tk1": "fewer colours", "tk2": "bigger type"} { |
| + if got := eval(note(task) + `.value`); got != want { |
| + t.Errorf("after the refresh %s's More options note holds %q, want %q", task, got, want) |
| + } |
| + } |
| +} |