Show Ask's Send and Stop as icons inside the field
The composer now follows the familiar pattern Paul asked for: no Send until something other than spaces is typed, then a round up-arrow inside the field's right end (primary-button colours in both themes) that pops in, without motion under reduced motion. While a turn runs, a square Stop sits in the same spot and posts the turn's cancel form; the separate Stop button under the status line is gone. Enter still sends, Shift+Enter is still a new line. Send and Stop carry the approved words as aria-label and title; no new visible copy. With scripts off the arrow always shows, so the form still sends, and Stop shows beside it while a turn runs. Tests: a browser test for hidden-when-empty, appear on typing, send on click and on Enter, and Stop in place that cancels; a webtest for the scripts-off composer's Send and Stop. Existing tests follow the new selectors.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
8 files changed,
+226
−18
internal/browsertest/ask_test.go+91 −0internal/browsertest/cards_test.go+1 −1internal/browsertest/mobile_test.go+10 −3internal/browsertest/scroll_test.go+3 −3internal/look/static/app.css+18 −2internal/look/static/ask.js+22 −7internal/web/templates/partials/chat.html+2 −2internal/webtest/ask_test.go+79 −0
diff --git a/internal/browsertest/ask_test.go b/internal/browsertest/ask_test.go| index 5a1bdaf..4e84818 100644 |
| --- a/internal/browsertest/ask_test.go |
| +++ b/internal/browsertest/ask_test.go |
| @@ -275,3 +275,94 @@ func TestAskPanel(t *testing.T) { |
| return [r.left, r.top, r.width, r.height].map(Math.round).join(" ") === "0 0 390 844" })()` |
| drive(t, rig, chromedp.Poll[chromedp.Void](whole, chromedp.WithPollingTimeout(3*time.Second))) |
| } |
| + |
| +// The composer is the familiar one: no Send until something is typed, then |
| +// a round arrow inside the field's end that sends on a click or on Enter; |
| +// while Equipo answers, a square Stop takes its place and cancels the turn. |
| +func TestAskComposerSendAndStop(t *testing.T) { |
| + rig, f := askBase(t) |
| + openPanel(t, rig) |
| + const send, stop = `#ask-panel form.composer button.send`, `#ask-panel form.composer button.stop` |
| + shown := func(sel string) string { |
| + return `(() => { const b = document.querySelector(` + strconv.Quote(sel) + `); |
| + return !!b && b.checkVisibility({ visibilityProperty: true }) && b.getBoundingClientRect().width > 0 })()` |
| + } |
| + buttons := func() string { |
| + return harness.Evaluate[string](rig, `"send " + `+shown(send)+` + ", stop " + `+shown(stop)) |
| + } |
| + wait := func(js string) { |
| + t.Helper() |
| + drive(t, rig, chromedp.Poll[chromedp.Void](js, chromedp.WithPollingTimeout(10*time.Second))) |
| + } |
| + // Once the panel has finished opening. |
| + wait(`(() => { const s = getComputedStyle(document.querySelector("#ask-panel")); return s.opacity === "1" && s.transform === "none" })()`) |
| + if got := buttons(); got != "send false, stop false" { |
| + t.Fatalf("empty field: %s", got) |
| + } |
| + drive(t, rig, chromedp.SendKeys(chromedp.CSS(`#ask-text`), " "), chromedp.Sleep(200*time.Millisecond)) |
| + if got := buttons(); got != "send false, stop false" { |
| + t.Fatalf("only spaces typed: %s", got) |
| + } |
| + drive(t, rig, chromedp.SendKeys(chromedp.CSS(`#ask-text`), "What can I do")) |
| + wait(shown(send)) |
| + // The arrow sits inside the field's right end, named Send. |
| + if got := harness.Evaluate[string](rig, `(() => { |
| + const b = document.querySelector(`+strconv.Quote(send)+`), f = document.querySelector("#ask-text"); |
| + for (const a of b.getAnimations()) a.finish(); // measured once it has grown in |
| + const r = b.getBoundingClientRect(), x = f.getBoundingClientRect(), p = []; |
| + if (b.getAttribute("aria-label") !== "Send" || b.title !== "Send") p.push("named " + b.getAttribute("aria-label") + "/" + b.title); |
| + if (b.textContent.trim() !== "") p.push("has text " + b.textContent.trim()); |
| + if (!b.querySelector("svg")) p.push("no icon"); |
| + if (r.left < x.left || r.right > x.right + 0.5 || r.top < x.top - 0.5 || r.bottom > x.bottom + 0.5) p.push("outside the field"); |
| + if (x.right - r.right > 8) p.push(Math.round(x.right - r.right) + "px from the field's end"); |
| + return p.join("; "); |
| + })()`); got != "" { |
| + t.Errorf("the Send button: %s", got) |
| + } |
| + |
| + // Sent by a click; while Equipo answers, Stop is where Send was, the |
| + // status line above the field, and no other Stop shows. |
| + f.Hold = true |
| + drive(t, rig, chromedp.Click(chromedp.CSS(send))) |
| + wait(`document.querySelectorAll("#ask-panel .msg.person").length === 1 && ` + shown(stop)) |
| + if got := harness.Evaluate[string](rig, `(() => { |
| + const b = document.querySelector(`+strconv.Quote(stop)+`), p = []; |
| + if (b.getAttribute("aria-label") !== "Stop" || b.title !== "Stop") p.push("named " + b.getAttribute("aria-label") + "/" + b.title); |
| + if (!b.querySelector("svg")) p.push("no icon"); |
| + if (`+shown(send)+`) p.push("Send shows too"); |
| + if (document.querySelector("#ask-text").value !== "") p.push("the field still holds text"); |
| + const others = [...document.querySelectorAll("#ask-panel button")].filter(x => x !== b && /Stop/.test(x.textContent) && x.checkVisibility()); |
| + if (others.length) p.push(others.length + " other Stop buttons"); |
| + const st = document.querySelector("#ask-panel .ask-status"); |
| + if (st.textContent !== "Equipo is answering…") p.push("status " + st.textContent); |
| + if (st.getBoundingClientRect().bottom > document.querySelector("#ask-text").getBoundingClientRect().top + 0.5) p.push("status not above the field"); |
| + return p.join("; "); |
| + })()`); got != "" { |
| + t.Errorf("while answering: %s", got) |
| + } |
| + action := harness.Evaluate[string](rig, `document.querySelector("#ask-panel form.cancel").getAttribute("action")`) |
| + m := regexp.MustCompile(`^/ask/turns/([^/]+)/cancel$`).FindStringSubmatch(action) |
| + if m == nil { |
| + t.Fatalf("cancel form posts to %q", action) |
| + } |
| + rig.Screen("#ask-panel", "the panel while Equipo answers, with Stop in the field") |
| + drive(t, rig, chromedp.Click(chromedp.CSS(stop))) |
| + wait(`!` + shown(stop) + ` && document.querySelector("#ask-panel .ask-status").textContent === ""`) |
| + for i := 0; f.Turn(m[1]) != "cancelled"; i++ { |
| + if i > 100 { |
| + t.Fatalf("Stop left the turn %q", f.Turn(m[1])) |
| + } |
| + time.Sleep(20 * time.Millisecond) |
| + } |
| + if got := buttons(); got != "send false, stop false" { |
| + t.Errorf("after Stop, the field empty: %s", got) |
| + } |
| + f.Hold = false |
| + |
| + // Enter sends too. |
| + drive(t, rig, chromedp.SendKeys(chromedp.CSS(`#ask-text`), "And what else?\r")) |
| + wait(`document.querySelectorAll("#ask-panel .msg.person").length === 2`) |
| + if n := len(f.Calls("/api/v1/assistant/messages")); n != 2 { |
| + t.Errorf("messages sent: %d, want 2", n) |
| + } |
| +} |
diff --git a/internal/browsertest/cards_test.go b/internal/browsertest/cards_test.go| index 0a1b1ed..c4844e8 100644 |
| --- a/internal/browsertest/cards_test.go |
| +++ b/internal/browsertest/cards_test.go |
| @@ -52,7 +52,7 @@ func TestAskCardsInPanel(t *testing.T) { |
| wait(`document.querySelector(` + strconv.Quote(card+` .card-state`) + `)?.textContent === "Go ahead"`) |
| drive(t, rig, chromedp.Sleep(300*time.Millisecond)) |
| if got := harness.Evaluate[string](rig, `[...document.querySelectorAll("#ask-panel .msg.person")].map(m => "[" + m.textContent + "]").join("") + "|" + |
| - document.querySelector("#ask-panel .ask-status").textContent + "|" + document.querySelector("#ask-panel form.stop").hidden`); got != "||true" { |
| + document.querySelector("#ask-panel .ask-status").textContent + "|" + document.querySelector("#ask-panel form.composer button.stop").hidden`); got != "||true" { |
| t.Errorf("after answering an outcome card: bubbles, status and Stop hidden %q", got) |
| } |
| if c := f.Calls("/api/v1/assistant/cards/" + open + "/answer"); len(c) != 1 || strings.TrimSpace(c[0].Body) != `{"choice":"go","revision":1}` { |
diff --git a/internal/browsertest/mobile_test.go b/internal/browsertest/mobile_test.go| index fb3402e..04670e6 100644 |
| --- a/internal/browsertest/mobile_test.go |
| +++ b/internal/browsertest/mobile_test.go |
| @@ -154,12 +154,19 @@ func TestMobile(t *testing.T) { |
| const link = document.querySelector("#ask-panel .ask-head a[target=_blank]"); |
| if (link && link.checkVisibility()) problems.push("Open Equipo shows in the header"); |
| if (head.height > 64) problems.push("header is " + head.height + "px tall"); |
| - for (const el of document.querySelectorAll("#ask-panel .ask-head summary, #ask-panel .ask-head .close, #ask-panel form.composer .btn, #ask-panel textarea")) { |
| + // 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 summary, #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.textContent.trim() + " is " + r.width + "x" + r.height); |
| + 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 .btn").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 = "Equipo is answering…"; |
diff --git a/internal/browsertest/scroll_test.go b/internal/browsertest/scroll_test.go| index 462d835..412cd71 100644 |
| --- a/internal/browsertest/scroll_test.go |
| +++ b/internal/browsertest/scroll_test.go |
| @@ -78,7 +78,7 @@ func TestAskScrollFollowsNewest(t *testing.T) { |
| } |
| f.Hold = true |
| send("Can we fix a bug in Tito?") |
| - if _, err := chromedp.Run(rig.Context(), chromedp.Poll[chromedp.Void](`!document.querySelector("#ask-panel form.stop").hidden && document.querySelector("#ask-panel .ask-status").textContent !== ""`, chromedp.WithPollingTimeout(10*time.Second))); err != nil { |
| + if _, err := chromedp.Run(rig.Context(), chromedp.Poll[chromedp.Void](`!document.querySelector("#ask-panel form.composer button.stop").hidden && document.querySelector("#ask-panel .ask-status").textContent !== ""`, chromedp.WithPollingTimeout(10*time.Second))); err != nil { |
| t.Fatalf("no answering status: %v; person bubbles %d, status %q, field %q", err, |
| harness.Evaluate[int](rig, `document.querySelectorAll("#ask-panel .msg.person").length`), |
| harness.Evaluate[string](rig, `document.querySelector("#ask-panel .ask-status").textContent`), |
| @@ -88,8 +88,8 @@ func TestAskScrollFollowsNewest(t *testing.T) { |
| if got := harness.Evaluate[string](rig, lastVisible); got != "" { |
| t.Errorf("sent, waiting for an answer: %s", got) |
| } |
| - drive(t, rig, chromedp.Click(chromedp.CSS(`#ask-panel form.stop button`))) |
| - wait(`document.querySelector("#ask-panel form.stop").hidden`) |
| + drive(t, rig, chromedp.Click(chromedp.CSS(`#ask-panel form.composer button.stop`))) |
| + wait(`document.querySelector("#ask-panel form.composer button.stop").hidden`) |
| f.Hold = false |
| // Send: the log goes to the bottom, and stays there as the reply |
diff --git a/internal/look/static/app.css b/internal/look/static/app.css| index 52601f1..5f74336 100644 |
| --- a/internal/look/static/app.css |
| +++ b/internal/look/static/app.css |
| @@ -469,7 +469,7 @@ dialog.ask-panel::backdrop { background: transparent; } |
| .ask-note { padding: 22px 20px; display: flex; flex-direction: column; gap: 14px; align-items: flex-start; } |
| .ask-note p { margin: 0; color: var(--haze); } |
| .ask-chat { flex: 1; min-height: 0; display: flex; flex-direction: column; } |
| -/* The log scrolls; the status row (with Stop) and the composer are the |
| +/* The log scrolls; the status row and the composer are the |
| footer below it, never over it. Jump to latest floats at the log's foot |
| when the person has scrolled up and something new arrives. */ |
| .log { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; } |
| @@ -496,7 +496,22 @@ dialog.ask-panel::backdrop { background: transparent; } |
| .ask-status { flex: 1; margin: 0; min-height: 1.5em; color: var(--haze); font-size: 14px; } |
| .ask-status:empty { min-height: 0; } |
| .composer { display: flex; gap: 8px; align-items: flex-end; padding: 10px 16px 16px; } |
| +.composer .field { flex: 1; min-width: 0; position: relative; display: flex; } |
| .composer textarea.input { flex: 1; height: auto; min-height: 44px; max-height: 160px; padding: 11px 14px; resize: none; font: inherit; line-height: 20px; field-sizing: content; } |
| +/* Send (an arrow) and Stop (a square) sit in the field's end, round and |
| + filled like a primary button: a 32px circle in a 44px target. The field |
| + keeps its text clear of whichever shows; with none it is all field. Each |
| + fades and grows in as it appears. */ |
| +.composer .actions { position: absolute; right: 0; bottom: 0; display: flex; } |
| +.composer .field:has(.actions > :not([hidden])) textarea.input { padding-right: 46px; } |
| +.composer .field:has(.actions > :not([hidden]) ~ :not([hidden])) textarea.input { padding-right: 90px; } |
| +.composer .actions button { flex: none; width: 44px; height: 44px; padding: 6px; border: 0; border-radius: 50%; display: grid; place-items: center; cursor: pointer; |
| + background: var(--btn); background-clip: content-box; color: var(--btn-ink); animation: pop .16s cubic-bezier(.2,.7,0,1); } |
| +.composer .actions button:focus-visible { outline-offset: -3px; } |
| +.composer .actions svg { width: 18px; height: 18px; } |
| +.composer .send svg { fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; } |
| +.composer .stop svg { fill: currentColor; } |
| +@keyframes pop { from { opacity: 0; transform: scale(.6); } } |
| .ask-page { display: flex; flex-direction: column; padding: 22px 0 0; } |
| .ask-page .crumb { padding: 0 24px; } |
| .ask-page .ask-head { padding-left: 24px; } |
| @@ -557,11 +572,12 @@ main { min-height: 100dvh; } |
| } |
| /* With reduced motion the chat just shows: no slide, no scale, and Home |
| - does not step back, blur or dim behind it. */ |
| + does not step back, blur or dim behind it. Send and Stop just appear. */ |
| @media (prefers-reduced-motion: reduce) { |
| dialog.ask-panel, dialog.ask-panel[open], main.home { transition: none; transform: none; animation: none; } |
| @starting-style { dialog.ask-panel[open] { transform: none; opacity: 1; } } |
| body:has(dialog.ask-panel[open]) main.home { transform: none; filter: none; opacity: 1; } |
| + .composer .actions button { animation: none; } |
| } |
| @keyframes sheet-up { from { transform: translateY(100%); } } |
diff --git a/internal/look/static/ask.js b/internal/look/static/ask.js| index fb10bd4..a1896c1 100644 |
| --- a/internal/look/static/ask.js |
| +++ b/internal/look/static/ask.js |
| @@ -16,9 +16,11 @@ function start(root) { |
| const thread = root.querySelector(".thread"); |
| const empty = root.querySelector("[data-empty]"); |
| const status = root.querySelector(".ask-status"); |
| - const stop = root.querySelector("form.stop"); |
| + const cancel = root.querySelector("form.cancel"); |
| const composer = root.querySelector("form.composer"); |
| const field = composer.querySelector("textarea"); |
| + const send = composer.querySelector("button.send"); |
| + const stop = composer.querySelector("button.stop"); |
| let source = null; |
| let turn = null; |
| let retry = 0; |
| @@ -44,7 +46,7 @@ function start(root) { |
| // The log follows its newest line while the person is at (or within |
| // 80px of) its bottom. Anything that changes its height (a new line, a |
| - // card, a streamed word, or the status row and Stop appearing below it) |
| + // card, a streamed word, or the status row appearing below it) |
| // keeps it there; if they have scrolled up to read, it stays put and |
| // Jump to latest appears. Scrolling is always instant. |
| const jump = root.querySelector("button.jump"); |
| @@ -213,12 +215,24 @@ function start(root) { |
| const ended = (s) => s === "replied" || s === "failed" || s === "cancelled"; |
| + // The field's end holds Stop while a turn runs, else Send once something |
| + // is typed, else nothing. A button that goes while it has focus hands it |
| + // to the field. |
| + function paint() { |
| + const had = document.activeElement; |
| + stop.hidden = !turn; |
| + send.hidden = !!turn || !field.value.trim(); |
| + if ((had === send && send.hidden) || (had === stop && stop.hidden)) field.focus(); |
| + } |
| + field.addEventListener("input", paint); |
| + paint(); |
| + |
| function setTurn(t, line) { |
| if (t && !t.id) return; |
| if (t && !ended(t.state)) { |
| turn = t; |
| - stop.action = `/ask/turns/${encodeURIComponent(t.id)}/cancel`; |
| - stop.hidden = false; |
| + cancel.action = `/ask/turns/${encodeURIComponent(t.id)}/cancel`; |
| + paint(); |
| status.textContent = line || (t.state === "waiting" |
| ? "Equipo can't answer right now. It will as soon as it can." |
| : "Equipo is answering…"); |
| @@ -226,7 +240,7 @@ function start(root) { |
| } |
| if (t && turn && t.id !== turn.id) return; |
| turn = null; |
| - stop.hidden = true; |
| + paint(); |
| status.textContent = t && t.state === "failed" ? "That didn't get an answer. Try again." : ""; |
| for (const d of thread.querySelectorAll("[data-draft]")) { |
| if (!t || d.dataset.draft === t.id) { |
| @@ -349,6 +363,7 @@ function start(root) { |
| const sent = await post(composer); |
| if (!sent) return; |
| field.value = ""; |
| + paint(); |
| // Sending always goes to the bottom, wherever the person had scrolled. |
| pinned = true; |
| addMessage(sent.message); |
| @@ -361,9 +376,9 @@ function start(root) { |
| composer.requestSubmit(); |
| } |
| }); |
| - stop.addEventListener("submit", (e) => { |
| + cancel.addEventListener("submit", (e) => { |
| e.preventDefault(); |
| - post(stop); |
| + post(cancel); |
| }); |
| thread.addEventListener("submit", async (e) => { |
| e.preventDefault(); |
diff --git a/internal/web/templates/partials/chat.html b/internal/web/templates/partials/chat.html| index 08debe4..8cb7a37 100644 |
| --- a/internal/web/templates/partials/chat.html |
| +++ b/internal/web/templates/partials/chat.html |
| @@ -37,7 +37,7 @@ |
| <p class="ask-problem ask-runner" data-when="oldrunner"{{if not (.Shows "oldrunner")}} hidden{{end}} role="alert">Your runner needs an update for this. <a href="{{.Equipo}}" target="_blank" rel="noopener">Update it in Equipo</a>, then try again.</p> |
| <div class="ask-foot"> |
| <p class="ask-status" role="status">{{.Status}}</p> |
| -<form class="stop" method="post" action="{{with .Turn}}/ask/turns/{{.ID}}/cancel{{else}}/ask{{end}}"{{if not .Turn}} hidden{{end}}><input type="hidden" name="key" value="{{newKey}}"><button class="btn ghost" type="submit">Stop</button></form> |
| </div> |
| -<form class="composer" method="post" action="/ask/messages"><input type="hidden" name="key" value="{{.Key}}"><label class="sr-only" for="ask-text">Message</label><textarea class="input" id="ask-text" name="text" rows="1" required maxlength="16000" placeholder="Ask Base anything">{{.Text}}</textarea><button class="btn" type="submit">Send</button></form> |
| +{{/* The composer: Send (an arrow) and, while a turn runs, Stop (a square) sit inside the field's end. Stop posts the cancel form beside it. Without scripts Send always shows; the panel's script hides it while the field is empty, and while a turn runs. */}}<form class="cancel" id="ask-cancel" method="post" action="{{with .Turn}}/ask/turns/{{.ID}}/cancel{{else}}/ask{{end}}"><input type="hidden" name="key" value="{{newKey}}"></form> |
| +<form class="composer" method="post" action="/ask/messages"><input type="hidden" name="key" value="{{.Key}}"><label class="sr-only" for="ask-text">Message</label><div class="field"><textarea class="input" id="ask-text" name="text" rows="1" required maxlength="16000" placeholder="Ask Base anything">{{.Text}}</textarea><div class="actions"><button class="send" type="submit" aria-label="Send" title="Send"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 19V5M6 11l6-6 6 6"/></svg></button><button class="stop" type="submit" form="ask-cancel" aria-label="Stop" title="Stop"{{if not .Turn}} hidden{{end}}><svg viewBox="0 0 24 24" aria-hidden="true"><rect x="6.5" y="6.5" width="11" height="11" rx="2"/></svg></button></div></div></form> |
| </div>{{end}} |
diff --git a/internal/webtest/ask_test.go b/internal/webtest/ask_test.go| index 03774ea..5bfccd9 100644 |
| --- a/internal/webtest/ask_test.go |
| +++ b/internal/webtest/ask_test.go |
| @@ -422,6 +422,85 @@ func TestAskScriptsOffCardAndCancel(t *testing.T) { |
| } |
| } |
| +// buttonRE is a <button>'s opening tag; buttonAttrRE one of its |
| +// attributes, valued or bare (hidden). |
| +var ( |
| + buttonRE = regexp.MustCompile(`<button([^>]*)>`) |
| + buttonAttrRE = regexp.MustCompile(`([\w-]+)(?:="([^"]*)")?`) |
| +) |
| + |
| +// buttons are the attributes of each <button> in markup. |
| +func buttons(markup string) []map[string]string { |
| + var out []map[string]string |
| + for _, b := range buttonRE.FindAllStringSubmatch(markup, -1) { |
| + attrs := map[string]string{} |
| + for _, kv := range buttonAttrRE.FindAllStringSubmatch(b[1], -1) { |
| + attrs[kv[1]] = html.UnescapeString(kv[2]) |
| + } |
| + out = append(out, attrs) |
| + } |
| + return out |
| +} |
| + |
| +// With scripts off the composer is still a form that sends: its Send is an |
| +// icon button labelled "Send", drawn (not hidden) whatever the field holds; |
| +// while a turn runs, a Stop icon button posts the turn's cancel form, and |
| +// Send stays, so a person can still write. |
| +func TestAskScriptsOffComposer(t *testing.T) { |
| + a, f := newAskApp(t) |
| + a.connectEquipo(f) |
| + composer := func(page string) string { |
| + m := regexp.MustCompile(`(?s)<form class="composer"[^>]*action="/ask/messages"[^>]*>(.*?)</form>`).FindStringSubmatch(page) |
| + if m == nil { |
| + t.Fatalf("no composer posting to /ask/messages in:\n%s", page) |
| + } |
| + return m[1] |
| + } |
| + find := func(markup, label string) map[string]string { |
| + for _, b := range buttons(markup) { |
| + if b["aria-label"] == label { |
| + return b |
| + } |
| + } |
| + return nil |
| + } |
| + send := find(composer(a.get("/ask").Body), "Send") |
| + if send == nil || send["type"] != "submit" || send["title"] != "Send" { |
| + t.Fatalf("the composer's Send button: %v", send) |
| + } |
| + if _, hidden := send["hidden"]; hidden { |
| + t.Fatal("Send is hidden with scripts off") |
| + } |
| + if stop := find(composer(a.get("/ask").Body), "Stop"); stop != nil { |
| + if _, hidden := stop["hidden"]; !hidden { |
| + t.Fatal("a Stop button shows with no turn running") |
| + } |
| + } |
| + |
| + f.Hold = true |
| + a.post("/ask/messages", url.Values{"text": {"Can we fix a bug in Tito?"}}) |
| + page := a.get("/ask").Body |
| + stop := find(composer(page), "Stop") |
| + if stop == nil || stop["type"] != "submit" || stop["title"] != "Stop" || stop["form"] == "" { |
| + t.Fatalf("the composer's Stop button while answering: %v", stop) |
| + } |
| + if _, hidden := stop["hidden"]; hidden { |
| + t.Fatal("Stop is hidden while a turn runs") |
| + } |
| + if send := find(composer(page), "Send"); send == nil { |
| + t.Fatal("no Send while answering, scripts off") |
| + } else if _, hidden := send["hidden"]; hidden { |
| + t.Fatal("Send is hidden while answering, scripts off") |
| + } |
| + m := regexp.MustCompile(`<form[^>]*id="` + regexp.QuoteMeta(stop["form"]) + `"[^>]*action="(/ask/turns/([^/"]+)/cancel)"`).FindStringSubmatch(page) |
| + if m == nil { |
| + t.Fatalf("Stop's form %q is not a cancel form:\n%s", stop["form"], page) |
| + } |
| + if r := a.post(m[1], formFields(t, page, m[1])); r.Code != 303 || f.Turn(m[2]) != "cancelled" { |
| + t.Fatalf("cancel: %d, turn %q", r.Code, f.Turn(m[2])) |
| + } |
| +} |
| + |
| func TestAskNeedsReconnectAfter401(t *testing.T) { |
| a, f := newAskApp(t) |
| a.connectEquipo(f) |