//go:build browser
package browsertest
import (
"fmt"
"strconv"
"strings"
"testing"
"time"
"github.com/chromedp/chromedp"
"github.com/chromedp/chromedp/kb"
"amadan.net/rastrillo/rastrillo/harness"
"amadan.net/oficina/base/internal/config"
"amadan.net/oficina/base/internal/equipo"
)
// The Assistant's cards in the panel, drawn from their fields alone: an
// open outcome card with its buttons and link keeps the conversation at
// its newest line; answering it posts the option's value and brings no
// bubble and no turn; a card that has ended shows its result and link;
// a card of a kind Base does not draw never shows.
func TestAskCardsInPanel(t *testing.T) {
rig, f := askBase(t)
openPanel(t, rig)
wait := func(js string) {
t.Helper()
drive(t, rig, chromedp.Poll[chromedp.Void](js, chromedp.WithPollingTimeout(10*time.Second)))
}
for i := 1; i <= 20; i++ {
f.Say("Earlier line " + strconv.Itoa(i) + " of a long conversation.")
}
wait(`document.querySelectorAll("#ask-panel .thread > li").length >= 20`)
options := []equipo.Option{{Value: "go", Label: "Go ahead"}, {Value: "later", Label: "Not yet"}}
preview := []equipo.Link{{Label: "See it", URL: "https://preview.example.test/"}}
open := f.AskOutcome("This is ready. Go ahead?", options, preview)
card := `#ask-panel [data-card="` + open + `"]`
wait(`(() => { const c = document.querySelector(` + strconv.Quote(card) + `);
return c && c.textContent.includes("This is ready. Go ahead?") &&
[...c.querySelectorAll("button")].map(b => b.textContent + "=" + b.value).join("|") === "Go ahead=go|Not yet=later" &&
!!c.querySelector('a.card-link[href="https://preview.example.test/"][target="_blank"][rel="noopener"]') })()`)
drive(t, rig, chromedp.Sleep(200*time.Millisecond))
if got := harness.Evaluate[string](rig, lastVisible); got != "" {
t.Errorf("with an open card: %s", got)
}
mobileShot(t, rig, "1-outcome-open")
// Answering posts the value; Equipo starts no turn for it, so there is
// no bubble, no status and no Stop.
drive(t, rig, chromedp.Click(chromedp.CSS(card+` button[value="go"]`)))
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.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}` {
t.Fatalf("answers: %+v", c)
}
// An ended card says how it ended, with its link, and has no buttons.
site := f.AskOutcome("Your site is ready. Publish it?", nil, []equipo.Link{{Label: "Open it", URL: "https://site.example.test/"}})
f.SetCard(site, "resolved", "Published")
scard := `#ask-panel [data-card="` + site + `"]`
wait(`(() => { const c = document.querySelector(` + strconv.Quote(scard) + `);
return c && c.querySelector(".card-state")?.textContent === "Published" && !c.querySelector("form") &&
!!c.querySelector('a.card-link[href="https://site.example.test/"][rel="noopener"]') })()`)
mobileShot(t, rig, "2-outcome-result")
task := f.AskKind("task", "Merge tk0001?", options, nil)
f.Say("Try [this](javascript:alert(1)), [that](/tasks/tk1) or
.")
wait(`[...document.querySelectorAll("#ask-panel .msg.coordinator")].some(m => m.textContent.includes("
{ const all = document.querySelectorAll("#ask-panel li.job"), j = document.querySelector('#ask-panel li.job[data-job="` + id + `"]');
if (!j) return all.length + " none";
const link = j.querySelector(".pill-link");
return all.length + " " + j.dataset.state + " " + j.querySelector(".pill-stage").textContent + " [" + (link ? link.textContent : "") + "] " +
[...j.querySelectorAll("ol.job-cards > li")].map(c => c.dataset.card).join(","); })()`
}
// A job is one pill, updated in place as it moves: one li.job throughout,
// its state, status and name following each revision. A team_update turn
// is quiet: its activity sets no status line and it shows no Stop.
func TestAskJobPillInPanel(t *testing.T) {
rig, f := askBase(t)
openPanel(t, rig)
wait := func(js string) {
t.Helper()
drive(t, rig, chromedp.Poll[chromedp.Void](js, chromedp.WithPollingTimeout(10*time.Second)))
}
f.Say("On it.")
id := f.AskJob("Building your website")
is := func(want string) {
t.Helper()
wait(jobJS(id) + ` === ` + strconv.Quote(want))
}
is("1 working Getting started [] ")
if got := harness.Evaluate[string](rig, `(() => { const j = document.querySelector("#ask-panel li.job"), p = [];
if (j.querySelector(".card, .card-link")) p.push("drawn as a card");
if (j.querySelector(".pill-title").textContent !== "Building your website") p.push("title " + j.querySelector(".pill-title").textContent);
if (j.querySelector("summary.pill-main").getAttribute("aria-label") !== "Building your website, Getting started") p.push("name " + j.querySelector("summary").getAttribute("aria-label"));
if (j.querySelector(".state-mark svg")) p.push("working has an icon");
if (!getComputedStyle(j.querySelector(".state-mark"), "::after").animationName.includes("turn")) p.push("working mark still");
if (/equipo/i.test(document.querySelector("#ask-panel").innerText)) p.push("names Equipo");
const pages = document.querySelectorAll('#ask-panel a[href*="/jobs/"]');
if (pages.length !== 1 || !pages[0].matches(".jobview > header > h3 > a.jv-title")) p.push("links the job's page outside the job view's title");
return p.join("; "); })()`); got != "" {
t.Errorf("the working pill: %s", got)
}
rig.Screen("#ask-panel", "a job's pill, working")
// With reduced motion the working mark holds still.
drive(t, rig, reducedMotion("dark", true))
if got := harness.Evaluate[string](rig, `(() => { const m = document.querySelector("#ask-panel li.job .state-mark");
return getComputedStyle(m, "::after").animationName + " " + getComputedStyle(m, "::before").animationName; })()`); got != "none none" {
t.Errorf("the working mark with reduced motion: %s", got)
}
drive(t, rig, reducedMotion("dark", false))
f.SetJob(id, "working", "Building it", "Writing the pages.")
is("1 working Building it [] ")
// A link shows only once there is something to see.
try := equipo.Link{Label: "Try it", URL: "https://preview.example.test/"}
f.SetJob(id, "asking", "One question for you", "Waiting for your answer.", try)
is("1 asking One question for you [] ")
f.SetJob(id, "ready", "Ready to try", "Have a look.", try)
is("1 ready Ready to try [Try it] ")
if got := harness.Evaluate[string](rig, `(() => { const j = document.querySelector("#ask-panel li.job"), a = j.querySelector(".pill-link");
return j.dataset.revision + " " + j.querySelector("summary").getAttribute("aria-label") + " " + a.href + " " + a.target + " " + a.rel + " " + !!j.querySelector(".state-mark svg"); })()`); got != "4 Building your website, Ready to try https://preview.example.test/ _blank noopener true" {
t.Errorf("the ready pill: %s", got)
}
rig.Screen("#ask-panel", "a job's pill, ready")
// A quiet turn: running, with an activity line, and neither shows.
turn := f.EmitTurn("team_update", "running")
f.Emit("activity", map[string]string{"turn_id": turn, "label": "Looking at the job"})
f.Say("Have a look.")
wait(`[...document.querySelectorAll("#ask-panel .msg.coordinator")].some(m => m.textContent === "Have a look.")`)
drive(t, rig, chromedp.Sleep(200*time.Millisecond))
if got := harness.Evaluate[string](rig, `JSON.stringify(document.querySelector("#ask-panel .ask-status").textContent) + " " +
document.querySelector("#ask-panel form.composer button.stop").hidden + " " + document.querySelector("#ask-panel form.cancel").getAttribute("action")`); got != `"" true /ask` {
t.Errorf("with a team_update turn running: status, Stop hidden, cancel %s", got)
}
}
// Ruling P6j: the go-ahead under a ready pill stays under it as the job is
// redrawn, still ready and then working again; answering it posts its
// value and moves it into the job view; a Publish card that arrives after
// the redraw lands under the same pill. A card that comes before its job
// is drawn joins it when it is.
func TestAskJobKeepsItsCards(t *testing.T) {
rig, f := askBase(t)
// The docked chat at its widest, where a ready pill has room for its
// status beside its link.
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)
wait(jobJS(id) + ` === ` + strconv.Quote("1 ready Ready to try [Try it] "+goAhead))
rig.Screen("#ask-panel", "a ready pill with its go-ahead")
// Legible in the dark and in the light.
for _, scheme := range []string{"dark", "light"} {
drive(t, rig, prefersScheme(scheme), chromedp.Sleep(300*time.Millisecond))
mobileShot(t, rig, "job-ready-"+scheme)
checkContrast(t, rig, "a ready pill, "+scheme, "#ask-panel .pill-title", "#ask-panel .pill-stage", "#ask-panel .pill-link")
}
drive(t, rig, prefersScheme("dark"))
f.SetJob(id, "ready", "Ready to try", "Still ready.", try)
wait(`document.querySelector('#ask-panel li.job').dataset.revision === "3" && ` + jobJS(id) + ` === ` + strconv.Quote("1 ready Ready to try [Try it] "+goAhead))
f.SetJob(id, "working", "Almost ready", "Putting the finishing touches on it.")
wait(jobJS(id) + ` === ` + strconv.Quote("1 working Almost ready [] "+goAhead))
if n := harness.Evaluate[int](rig, `document.querySelectorAll('#ask-panel [data-card="`+goAhead+`"]').length`); n != 1 {
t.Fatalf("the go-ahead is drawn %d times", n)
}
card := `#ask-panel li.job ol.job-cards [data-card="` + goAhead + `"]`
drive(t, rig, chromedp.Click(chromedp.CSS(card+` button[value="go"]`)))
// Answered, it leaves the pill for the job view.
wait(jobJS(id) + ` === ` + strconv.Quote("1 working Almost ready [] ") + ` && ` + endedJS(id) + ` === "This is ready. Go ahead?|Go ahead"`)
if c := f.Calls("/api/v1/assistant/cards/" + goAhead + "/answer"); len(c) != 1 || strings.TrimSpace(c[0].Body) != `{"choice":"go","revision":1}` {
t.Fatalf("answers: %+v", c)
}
f.SetJob(id, "ready", "Ready to publish", "Publish it when you're happy.", try)
publish := f.AskOutcomeFor(id, "Your site is ready. Publish it?", options, nil)
wait(jobJS(id) + ` === ` + strconv.Quote("1 ready Ready to publish [Try it] "+publish) + ` && ` + endedJS(id) + ` === "This is ready. Go ahead?|Go ahead"`)
// A card of a job not yet drawn is loose, and moves under it when the
// job arrives. (The fake numbers its cards in turn: the next job is
// the card after this one.)
early := f.AskOutcomeFor("", "Go ahead with the other one?", options, nil)
n, err := strconv.Atoi(strings.TrimPrefix(early, "c_"))
if err != nil {
t.Fatalf("card id %q", early)
}
later := f.AskOutcomeFor(fmt.Sprintf("c_%04d", n+2), "And this one?", options, nil)
wait(`!!document.querySelector('#ask-panel .thread > [data-card="` + later + `"]')`)
other := f.AskJob("Fixing the login")
if other != fmt.Sprintf("c_%04d", n+2) {
t.Fatalf("the next job is %s", other)
}
wait(jobJS(other) + ` === ` + strconv.Quote("2 working Getting started [] "+later))
rig.Screen("#ask-panel", "two pills with their cards")
if got := harness.Evaluate[string](rig, `[...document.querySelectorAll("#ask-panel .thread > li")].map(l => l.dataset.job ? "job" : l.dataset.card ? "card" : "msg").join(",")`); got != "job,card,job" {
t.Errorf("the thread: %s", got)
}
}
// endedJS lists the cards in job id's view, each as its question and
// its result line ("question|result"), comma-separated; "none" without
// the job.
func endedJS(id string) string {
return `(() => { const j = document.querySelector('#ask-panel li.job[data-job="` + id + `"]');
if (!j) return "none";
return [...j.querySelectorAll(".jobview ol.jv-cards > li")].map(c => [...c.children].map(p => p.textContent).join("|")).join(","); })()`
}
// Paul's live check (2026-11-16): only a card that needs an answer hangs
// under its job's pill. A question answered and a go-ahead given move
// into the job view, under its detail, each as its question and how it
// ended, with nothing to press; an open go-ahead still shows under the
// pill, and moves into the view once answered. The view keeps them as
// the job is redrawn, and an ended card of a job not yet drawn joins its
// view when it is. A card of no job stays in the conversation.
func TestAskJobSettledCardsInView(t *testing.T) {
rig, f := askBase(t)
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"}}
id := f.AskLegacyJob("Can you make me a website?")
question := f.AskKindFor("question", id, "Which website?", []equipo.Option{{Value: "new", Label: "A new one"}}, nil)
goAhead := f.AskOutcomeFor(id, "This is ready. Go ahead?", options, nil)
f.SetCard(question, "answered", "A new one")
f.SetCard(goAhead, "answered", "Go ahead")
f.SetJob(id, "stopped", "Stopped", "It can't go on until something is sorted out.")
both := "Which website?|A new one,This is ready. Go ahead?|Go ahead"
wait(jobJS(id) + ` === "1 stopped Stopped [] " && ` + endedJS(id) + ` === ` + strconv.Quote(both))
job := `#ask-panel li.job[data-job="` + id + `"]`
if got := harness.Evaluate[string](rig, `(() => { const j = document.querySelector(`+strconv.Quote(job)+`), p = [];
if (document.querySelectorAll('#ask-panel .thread > [data-card]').length) p.push("a card loose in the conversation");
const list = j.querySelector(".jobview ol.jv-cards");
if (list.previousElementSibling !== j.querySelector(".jobview .jv-detail")) p.push("not under the detail");
if (list.querySelector("form, button, a")) p.push("something to press");
return p.join("; "); })()`); got != "" {
t.Errorf("the ended cards: %s", got)
}
drive(t, rig, chromedp.Click(chromedp.CSS(job+` summary`)), chromedp.Sleep(250*time.Millisecond))
if n := harness.Evaluate[int](rig, `[...document.querySelectorAll(`+strconv.Quote(job+` .jobview ol.jv-cards > li`)+`)].filter(c => c.checkVisibility()).length`); n != 2 {
t.Errorf("%d ended cards show in the open view", n)
}
rig.Screen("#ask-panel", "a stopped job's view with its ended cards")
for _, scheme := range []string{"dark", "light"} {
drive(t, rig, prefersScheme(scheme), chromedp.Sleep(300*time.Millisecond))
mobileShot(t, rig, "jobview-settled-"+scheme)
checkContrast(t, rig, "the ended cards, "+scheme, job+" .jv-cards .jv-q", job+" .jv-cards .jv-result")
}
drive(t, rig, prefersScheme("dark"), chromedp.KeyEvent(kb.Escape), chromedp.Sleep(200*time.Millisecond))
// An open go-ahead hangs under the pill; answered, it joins the view.
f.SetJob(id, "ready", "Ready to try", "Have a look.")
again := f.AskOutcomeFor(id, "Try it again?", options, nil)
wait(jobJS(id) + ` === ` + strconv.Quote("1 ready Ready to try [] "+again) + ` && ` + endedJS(id) + ` === ` + strconv.Quote(both))
drive(t, rig, chromedp.Click(chromedp.CSS(job+` ol.job-cards [data-card="`+again+`"] button[value="go"]`)))
wait(jobJS(id) + ` === "1 ready Ready to try [] " && ` + endedJS(id) + ` === ` + strconv.Quote(both+",Try it again?|Go ahead"))
// Redrawn, the job keeps them in its view.
f.SetJob(id, "working", "Almost ready", "Putting the finishing touches on it.")
wait(jobJS(id) + ` === "1 working Almost ready [] " && ` + endedJS(id) + ` === ` + strconv.Quote(both+",Try it again?|Go ahead"))
// An ended card of a job not yet drawn joins its view when it is; a
// card of no job stays where it is. (The fake numbers its cards in
// turn: the next job is the card after the next.)
loose := f.AskOutcome("Something else?", options, nil)
n, err := strconv.Atoi(strings.TrimPrefix(loose, "c_"))
if err != nil {
t.Fatalf("card id %q", loose)
}
early := f.AskOutcomeFor(fmt.Sprintf("c_%04d", n+2), "And this one?", options, nil)
f.SetCard(early, "resolved", "Not needed any more")
f.SetCard(loose, "answered", "Go ahead")
wait(`!!document.querySelector('#ask-panel .thread > [data-card="` + early + `"]')`)
if other := f.AskJob("Fixing the login"); other != fmt.Sprintf("c_%04d", n+2) {
t.Fatalf("the next job is %s", other)
}
wait(jobJS(fmt.Sprintf("c_%04d", n+2)) + ` === ` + `"2 working Getting started [] "` + ` && ` + endedJS(fmt.Sprintf("c_%04d", n+2)) + ` === "And this one?|Not needed any more"`)
if got := harness.Evaluate[string](rig, `[...document.querySelectorAll("#ask-panel .thread > li")].map(l => l.dataset.job ? "job" : l.dataset.card ? "card" : "msg").join(",")`); got != "job,card,job" {
t.Errorf("the thread: %s", got)
}
// Read afresh, the same.
drive(t, rig, chromedp.Reload(), chromedp.Sleep(300*time.Millisecond))
openPanel(t, rig)
wait(jobJS(id) + ` === "2 working Almost ready [] " && ` + endedJS(id) + ` === ` + strconv.Quote(both+",Try it again?|Go ahead"))
}
// statusShownJS checks the pill of job id: its status is drawn (a box with
// width, neither display:none nor visibility:hidden) and its title is cut
// short with an ellipsis before the status is; "" when both hold.
func statusShownJS(id string) string {
return `(() => { const j = document.querySelector('#ask-panel li.job[data-job="` + id + `"]');
if (!j) return "no job";
const s = j.querySelector(".pill-stage"), t = j.querySelector(".pill-title"), cs = getComputedStyle(s), p = [];
if (cs.display === "none" || cs.visibility === "hidden" || s.getBoundingClientRect().width < 1 || !s.checkVisibility({ visibilityProperty: true })) p.push("the status is not drawn");
if (t.scrollWidth <= t.clientWidth) p.push("the title is not cut short");
// The status is cut short only once the title is down to its least
// (measured to the fraction of a pixel: a sliver less already draws
// an ellipsis). Its whole width is a copy's, set beside it with no
// cap and no shrinking.
const drawn = s.getBoundingClientRect().width, copy = s.cloneNode(true);
copy.style.cssText = "position: absolute; visibility: hidden; flex: none; max-width: none; min-width: 0; width: max-content";
s.parentElement.append(copy);
const whole = copy.getBoundingClientRect().width;
copy.remove();
const title = t.getBoundingClientRect().width, least = parseFloat(getComputedStyle(t).minWidth);
if (whole - drawn > 0.01 && title > least + 0.5) p.push("the status is cut short (" + drawn + "px of " + whole + ") while the title is " + title + "px, more than its least " + least);
if (!j.querySelector(".pill-link")) p.push("no link");
const pill = j.querySelector(".pill").getBoundingClientRect(), log = document.querySelector("#ask-panel .thread").getBoundingClientRect();
if (pill.right > log.right + 0.5) p.push("the pill overflows the chat");
return p.join("; "); })()`
}
// Ruling R26: a ready or done pill keeps its status in sight at every
// width, beside its link: on the default desktop's docked chat and on a
// phone, a long title is cut short first.
func TestAskJobStatusStaysVisible(t *testing.T) {
const title = "Building a website about disability benefits in Ireland now"
for _, view := range []struct {
name string
act chromedp.Action[chromedp.Void]
}{
{"desktop", nil},
{"phone", chromedp.EmulateViewport(390, 844, chromedp.EmulateMobile, chromedp.EmulateScale(3))},
} {
t.Run(view.name, func(t *testing.T) {
rig, f, _ := askBaseOn(t, nil, view.act)
if view.act == nil {
openPanel(t, rig)
} else {
// On a phone the chat opens full screen from the field on Home.
drive(t, rig, chromedp.Navigate(rig.Origin+"/"), chromedp.WaitVisible(chromedp.CSS("a.ask-field")),
chromedp.Click(chromedp.CSS("a.ask-field")), chromedp.WaitVisible(chromedp.CSS(`#ask-panel textarea`)),
chromedp.Poll[chromedp.Void](readJS, chromedp.WithPollingTimeout(5*time.Second)))
}
id := f.AskJob(title)
for _, st := range []struct{ state, result, label string }{
{"ready", "Ready to try", "Try it"},
{"done", "Done", "Open your site"},
{"ready", "Ready to try on a phone, a tablet and a computer", "Try it"},
{"done", "Done, and live for everyone who visits", "Open your site"},
} {
f.SetJob(id, st.state, st.result, "One sentence more.", equipo.Link{Label: st.label, URL: "https://site.example.test/"})
drive(t, rig, chromedp.Poll[chromedp.Void](`document.querySelector('#ask-panel li.job .pill-stage')?.textContent === `+strconv.Quote(st.result),
chromedp.WithPollingTimeout(10*time.Second)))
// Measured in the page's own font, once it has loaded.
drive(t, rig, chromedp.Poll[chromedp.Void](`document.fonts.status === "loaded"`, chromedp.WithPollingTimeout(10*time.Second)),
chromedp.Sleep(100*time.Millisecond))
if got := harness.Evaluate[string](rig, statusShownJS(id)); got != "" {
t.Errorf("%s, %s: %s", view.name, st.state, got)
}
mobileShot(t, rig, "job-"+st.state+"-"+strconv.Itoa(len(st.result))+"-"+view.name)
}
})
}
}
// jobViewJS checks the open view of job id, docked on a wide screen: its
// is open and the summary says so; it is drawn whole and on top
// (nothing covers its middle), inside the chat below its header, beside
// the pill (side: above it when there is room, else below), with no
// scrim; focus is on its Close; its title is the one link to the job's
// page, in a new tab; its status says status. "" when all hold.
func jobViewJS(id, status, side string) string {
return `(() => { const j = document.querySelector('#ask-panel li.job[data-job="` + id + `"]');
if (!j) return "no job";
const d = j.querySelector("details"), s = j.querySelector("summary"), v = j.querySelector(".jobview"), p = [];
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));
const room = pill.top - head.bottom - 8 >= r.height + 8;
if (` + strconv.Quote(side) + ` === "above" && (!room || r.bottom > pill.top - 4 || pill.top - r.bottom > 12)) p.push("not just above the pill: view bottom " + r.bottom + ", pill top " + pill.top + ", room " + room);
if (` + strconv.Quote(side) + ` === "below" && (room || r.top < pill.bottom + 4 || r.top - pill.bottom > 12)) p.push("not just below the pill: view top " + r.top + ", pill bottom " + pill.bottom + ", room above " + room);
const mid = document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2);
if (!v.contains(mid)) p.push("covered at its middle by " + (mid && mid.className));
const close = v.querySelector("[data-job-close]");
if (close.hidden || !close.checkVisibility()) p.push("no Close");
if (document.activeElement !== close) p.push("focus on " + document.activeElement.tagName + "." + document.activeElement.className);
if (document.querySelector("#ask-panel .scrim")?.checkVisibility()) p.push("a scrim on a wide screen");
const pages = document.querySelectorAll('#ask-panel a[href*="/jobs/"]'), a = v.querySelector("h3 > a.jv-title");
if (!a || [...pages].some(l => !l.matches(".jobview > header > h3 > a.jv-title"))) p.push("the job's page is linked outside a job view's title");
else if (a.target !== "_blank" || a.rel !== "noopener" || a.title !== "Open in Equipo" || a.textContent !== j.querySelector(".pill-title").textContent) p.push("the title link: " + a.outerHTML);
if (v.querySelector(".jv-stage").textContent !== ` + strconv.Quote(status) + `) p.push("status " + v.querySelector(".jv-stage").textContent);
return p.join("; "); })()`
}
// closedViewJS is "" once job id's view is closed: the details shut, the
// summary saying so, the view and any scrim gone, and focus back on the
// pill's summary.
func closedViewJS(id string) string {
return `(() => { const j = document.querySelector('#ask-panel li.job[data-job="` + id + `"]'), p = [];
if (!j) return "no job";
const s = j.querySelector("summary");
if (j.querySelector("details").open) p.push("the details are open");
if (s.getAttribute("aria-expanded") !== "false") p.push("aria-expanded " + s.getAttribute("aria-expanded"));
if (j.querySelector(".jobview").checkVisibility()) p.push("the view shows");
if (document.querySelector("#ask-panel .scrim")?.checkVisibility()) p.push("the scrim shows");
if (document.activeElement !== s) p.push("focus on " + document.activeElement.tagName + "." + document.activeElement.className);
return p.join("; "); })()`
}
// The job view on a wide screen (plan decision D13): tapping the pill opens
// it as a popover beside the pill, inside the docked chat, with focus on
// its Close; Escape closes it (and only it: the chat stays open), and
// focus goes back to the pill. Close, a tap on the pill and a tap outside
// close it too. A new revision while it is open keeps it open, with the
// new status, and focus where it was. When it started moves on in words
// as the server says it, the day in Base's time zone.
func TestAskJobViewOpens(t *testing.T) {
auckland, err := time.LoadLocation("Pacific/Auckland")
if err != nil {
t.Fatal(err)
}
rig, f, _ := askBaseWith(t, func(c *config.Config) { c.Timezone = auckland })
openPanel(t, rig)
wait := func(js string) {
t.Helper()
drive(t, rig, chromedp.Poll[chromedp.Void](js, chromedp.WithPollingTimeout(10*time.Second)))
}
pending := func(js string) string { return harness.Evaluate[string](rig, js) }
settle := func() { drive(t, rig, chromedp.Sleep(250*time.Millisecond)) }
// A job at the top of the conversation, with no room above it: its
// view opens below it.
first := f.AskJob("Fixing the login")
for _, line := range []string{"On it.", "Got it.", "I'll let you know.", "Anything else?", "Sure.", "On it."} {
f.Say(line)
}
id := f.AskJob("Building your website")
job := `#ask-panel li.job[data-job="` + id + `"]`
summary, view := job+` summary`, job+` .jobview`
wait(`!!document.querySelector(` + strconv.Quote(summary) + `) && document.querySelectorAll("#ask-panel .msg.coordinator").length === 6`)
drive(t, rig, chromedp.Click(chromedp.CSS(`#ask-panel li.job[data-job="`+first+`"] summary`)))
settle()
if got := pending(jobViewJS(first, "Getting started", "below")); got != "" {
t.Errorf("the first job, tapped open: %s", got)
}
// Tapping another pill closes the first view and opens its own.
drive(t, rig, chromedp.Click(chromedp.CSS(summary)))
settle()
if got := pending(jobViewJS(id, "Getting started", "above")); got != "" {
t.Errorf("tapped open: %s", got)
}
if n := harness.Evaluate[int](rig, `[...document.querySelectorAll("#ask-panel .jobview")].filter(v => v.checkVisibility()).length`); n != 1 {
t.Errorf("%d job views show", n)
}
if got := pending(`(() => { const v = document.querySelector(` + strconv.Quote(view) + `);
return [v.querySelector(".jv-detail")?.textContent, v.querySelector(".jv-started")?.textContent].join("|"); })()`); got != "Working out what's needed.|Started just now" {
t.Errorf("the view's detail and when it started: %s", got)
}
// The title's arrow: hidden at rest where there is a pointer that
// hovers; always there on a touch screen (headless Chromium may say
// it is one).
arrow := `getComputedStyle(document.querySelector(` + strconv.Quote(view+` .jv-title svg`) + `)).opacity`
if got := pending(`matchMedia("(hover: none)").matches + " " + ` + arrow); got != "true 1" && got != "false 0" {
t.Errorf("the title's arrow at rest (touch screen, opacity): %s", got)
}
rig.Screen("#ask-panel", "a working job's view, open beside its pill")
for _, scheme := range []string{"dark", "light"} {
drive(t, rig, prefersScheme(scheme), chromedp.Sleep(300*time.Millisecond))
mobileShot(t, rig, "jobview-working-desktop-"+scheme)
checkContrast(t, rig, "the job view, "+scheme, view+" h3", view+" .jv-stage", view+" .jv-detail", view+" .jv-started")
}
// The title's arrow shows on keyboard focus (Shift+Tab from Close).
drive(t, rig, chromedp.KeyEvent(kb.Tab, chromedp.KeyModifiers(chromedp.ModifierShift)))
settle()
if got := pending(`document.activeElement.className + " " + ` + arrow); got != "jv-title 1" {
t.Errorf("the title focused: %s", got)
}
drive(t, rig, prefersScheme("dark"))
// Escape closes the view, and the chat stays open.
drive(t, rig, chromedp.KeyEvent(kb.Escape))
settle()
if got := pending(closedViewJS(id)); got != "" {
t.Errorf("after Escape: %s", got)
}
if !harness.Evaluate[bool](rig, settledJS) {
t.Errorf("Escape on the job view closed the chat")
}
// Close, a second tap on the pill, and a tap outside it close it too.
drive(t, rig, chromedp.Click(chromedp.CSS(summary)))
settle()
drive(t, rig, chromedp.Click(chromedp.CSS(view+` [data-job-close]`)))
settle()
if got := pending(closedViewJS(id)); got != "" {
t.Errorf("after Close: %s", got)
}
drive(t, rig, chromedp.Click(chromedp.CSS(summary)))
settle()
drive(t, rig, chromedp.Click(chromedp.CSS(summary)))
settle()
if got := pending(closedViewJS(id)); got != "" {
t.Errorf("after a second tap on the pill: %s", got)
}
drive(t, rig, chromedp.Click(chromedp.CSS(summary)))
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") + " " + 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
// on Close.
drive(t, rig, chromedp.Click(chromedp.CSS(summary)))
settle()
f.SetJob(id, "working", "Building it", "Writing the pages.")
wait(`document.querySelector(` + strconv.Quote(job) + `).dataset.revision === "2"`)
settle()
if got := pending(jobViewJS(id, "Building it", "above")); got != "" {
t.Errorf("redrawn while open: %s", got)
}
try := equipo.Link{Label: "Try it", URL: "https://preview.example.test/"}
f.SetJob(id, "ready", "Ready to try", "Have a look.", try)
wait(`document.querySelector(` + strconv.Quote(job) + `).dataset.revision === "3"`)
settle()
if got := pending(jobViewJS(id, "Ready to try", "above")); got != "" {
t.Errorf("ready, open: %s", got)
}
if got := pending(`(() => { const a = document.querySelector(` + strconv.Quote(view+` a.jv-go`) + `); return a ? a.textContent + " " + a.href + " " + a.target : "none"; })()`); got != "Try it https://preview.example.test/ _blank" {
t.Errorf("a ready view's link: %s", got)
}
for _, scheme := range []string{"dark", "light"} {
drive(t, rig, prefersScheme(scheme), chromedp.Sleep(300*time.Millisecond))
mobileShot(t, rig, "jobview-ready-desktop-"+scheme)
checkContrast(t, rig, "a ready job's view, "+scheme, view+" h3", view+" .jv-stage", view+" .jv-go")
}
drive(t, rig, prefersScheme("dark"))
for _, st := range []struct{ state, result string }{{"asking", "One question for you"}, {"done", "Done"}, {"stopped", "Stopped"}} {
f.SetJob(id, st.state, st.result, "One sentence more.", try)
wait(`document.querySelector(` + strconv.Quote(view+` .jv-stage`) + `).textContent === ` + strconv.Quote(st.result))
for _, scheme := range []string{"dark", "light"} {
drive(t, rig, prefersScheme(scheme), chromedp.Sleep(300*time.Millisecond))
mobileShot(t, rig, "jobview-"+st.state+"-desktop-"+scheme)
}
drive(t, rig, prefersScheme("dark"))
}
// When it started, as the server words it: hours, then the day in
// Base's time zone (Auckland's, a day ahead of UTC's evening).
started := func(at time.Time, want string) {
t.Helper()
f.SetJobStarted(id, at)
wait(`document.querySelector(` + strconv.Quote(view+` .jv-started`) + `)?.textContent === ` + strconv.Quote(want))
}
started(time.Now().Add(-3*time.Hour-time.Minute), "Started 3 hours ago")
old := time.Date(2026, 3, 4, 20, 0, 0, 0, time.UTC)
started(old, "Started on "+old.In(auckland).Format("2 January"))
if old.In(auckland).Day() == old.Day() {
t.Fatalf("the day is the same in both zones")
}
if got := pending(jobViewJS(id, "Stopped", "above")); got != "" {
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)
}
}
// 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)
}
}
// Without scripts the job view opens in place, in the conversation's flow
// (plan decision D13): opened, it pushes what follows down, the decision
// under its pill and the next job, rather than covering them.
func TestAskJobViewScriptsOffInPlace(t *testing.T) {
rig, f := askBase(t)
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)
next := f.AskJob("Fixing the login")
drive(t, rig, scriptsDisabled(true))
defer drive(t, rig, scriptsDisabled(false))
for _, view := range []chromedp.Action[chromedp.Void]{chromedp.EmulateViewport(1280, 800), chromedp.EmulateViewport(390, 844, chromedp.EmulateMobile, chromedp.EmulateScale(3))} {
page := `.ask-page li.job[data-job="` + id + `"]`
drive(t, rig, view, chromedp.Navigate(rig.Origin+"/ask"), chromedp.WaitVisible(chromedp.CSS(page+" summary")),
chromedp.Click(chromedp.CSS(page+" summary")), chromedp.Sleep(200*time.Millisecond))
if got := harness.Evaluate[string](rig, `(() => { const j = document.querySelector(`+strconv.Quote(page)+`), v = j.querySelector(".jobview"), p = [];
if (!j.querySelector("details").open) p.push("closed");
if (!v.checkVisibility()) return p.concat("the view is not drawn").join("; ");
const r = v.getBoundingClientRect(), s = j.querySelector("summary").getBoundingClientRect();
if (r.top < s.bottom || r.top - s.bottom > 12 || r.left < s.left - 0.5) p.push("not under the pill: " + JSON.stringify(r) + " pill " + JSON.stringify(s));
if (getComputedStyle(v).position !== "static") p.push("out of the flow: " + getComputedStyle(v).position);
const clear = (sel, what) => {
const el = document.querySelector(sel);
if (!el) return p.push("no " + what);
el.scrollIntoView({ block: "center" });
const o = el.getBoundingClientRect(), v2 = v.getBoundingClientRect();
if (o.top < v2.bottom && o.bottom > v2.top && o.left < v2.right && o.right > v2.left) p.push("covers " + what + ": " + JSON.stringify(o) + " view " + JSON.stringify(v2));
const at = document.elementFromPoint(o.left + o.width / 2, o.top + Math.min(o.height / 2, 20));
if (!el.contains(at)) p.push(what + " covered by " + (at && at.className));
};
clear(`+strconv.Quote(page+` ol.job-cards [data-card="`+goAhead+`"]`)+`, "the go-ahead");
clear(`+strconv.Quote(`.ask-page li.job[data-job="`+next+`"] .pill`)+`, "the next job");
if (document.documentElement.scrollWidth > document.documentElement.clientWidth) p.push("the page overflows");
return p.join("; "); })()`); got != "" {
t.Errorf("scripts off, the job view opened: %s", got)
}
rig.Screen(".ask-page", "the job view opened in place, scripts off")
}
}
// A paused job (clearer paused work, 2026-11-24): the pill's clock mark on
// the calm indigo, its status as Equipo wrote it, and in its view the
// sentence and "Carry on now" with the line under it, readable in both
// themes. Carry on now posts once, the card's revision and a key (the
// body's idempotency_key and the Idempotency-Key header), and the job
// redraws in place, working, with no button. Stopped's mark is a square.
func TestAskJobPausedCarriesOn(t *testing.T) {
rig, f := askBase(t)
openPanel(t, rig)
wait := func(js string) {
t.Helper()
drive(t, rig, chromedp.Poll[chromedp.Void](js, chromedp.WithPollingTimeout(10*time.Second)))
}
settle := func() { drive(t, rig, chromedp.Sleep(250*time.Millisecond)) }
stopped := f.AskJob("Invoice reminders")
f.SetJob(stopped, "stopped", "Stopped: needs you", "It needs you.")
id := f.AskJob("Bakery website")
f.PauseJob(id, "Paused until 21:00", "It has reached the limit on its plan for now. It will carry on by itself at 21:00 (in 9 hours).", true)
job := `#ask-panel li.job[data-job="` + id + `"]`
wait(`document.querySelector(` + strconv.Quote(job) + `)?.dataset.state === "paused" && document.querySelector(` + strconv.Quote(job+` .jv-act`) + `) !== null`)
drive(t, rig, prefersScheme("dark"), chromedp.Sleep(300*time.Millisecond))
if got := harness.Evaluate[string](rig, `[document.querySelector(`+strconv.Quote(job+` .pill-stage`)+`).textContent,
document.querySelector(`+strconv.Quote(job+` .pill-main .state-mark path`)+`).getAttribute("d"),
getComputedStyle(document.querySelector(`+strconv.Quote(job+` .pill-main .state-mark`)+`)).backgroundColor,
document.querySelector('#ask-panel li.job[data-job="`+stopped+`"] .pill-main .state-mark path').getAttribute("d")].join("|")`); got !=
"Paused until 21:00|M19.2 12a7.2 7.2 0 1 1-14.4 0a7.2 7.2 0 1 1 14.4 0zM12 8.6V12l2.4 1.6|rgb(174, 184, 255)|M9 7.5h6a1.5 1.5 0 0 1 1.5 1.5v6a1.5 1.5 0 0 1-1.5 1.5H9a1.5 1.5 0 0 1-1.5-1.5V9A1.5 1.5 0 0 1 9 7.5z" {
t.Errorf("paused pill (status|mark|colour|stopped's mark): %s", got)
}
drive(t, rig, chromedp.Click(chromedp.CSS(job+` summary`)))
settle()
view := job + ` .jobview`
if got := harness.Evaluate[string](rig, `(() => { const v = document.querySelector(`+strconv.Quote(view)+`);
return [v.checkVisibility(), v.querySelector(".jv-stage").textContent, v.querySelector(".jv-detail").textContent,
v.querySelector(".jv-act button").textContent, v.querySelector(".jv-act small").textContent].join("|"); })()`); got !=
"true|Paused until 21:00|It has reached the limit on its plan for now. It will carry on by itself at 21:00 (in 9 hours).|Carry on now|Uses your other plan, at no extra cost." {
t.Errorf("the paused job's view: %s", got)
}
for _, scheme := range []string{"dark", "light"} {
drive(t, rig, prefersScheme(scheme), chromedp.Sleep(300*time.Millisecond))
mobileShot(t, rig, "jobview-paused-"+scheme)
checkContrast(t, rig, "the paused job's view, "+scheme, view+" .jv-stage", view+" .jv-detail", view+" .jv-act button", view+" .jv-act small")
iconContrast(t, rig, "the paused mark, "+scheme, job+" .pill-main .state-mark svg")
}
if got := harness.Evaluate[string](rig, `getComputedStyle(document.querySelector(`+strconv.Quote(job+` .pill-main .state-mark`)+`)).backgroundColor`); got != "rgb(75, 85, 201)" {
t.Errorf("paused's colour in light: %s", got)
}
drive(t, rig, prefersScheme("dark"))
rig.Screen("#ask-panel", "a paused job's view, with Carry on now")
// Equipo not answering: the view says so under the button (Fable's
// review S3: on a phone the sheet hides the status line), and the
// button comes back. Pressing again sends the same key.
f.FailCarryOn(503)
drive(t, rig, chromedp.Click(chromedp.CSS(view+` .jv-act button`)))
wait(`document.querySelector(` + strconv.Quote(view+` .jv-act .jv-error[role="status"]`) + `)?.textContent === "That didn't send. Try again." &&
!document.querySelector(` + strconv.Quote(view+` .jv-act button`) + `).disabled`)
// Said once (Fable's re-review R4): in the view's live region only, not
// on the status line too.
if got := harness.Evaluate[string](rig, `[...document.querySelectorAll("#ask-panel [role=status], #ask-panel [role=alert], #ask-panel [aria-live]")]
.filter(el => el.textContent.includes("That didn't send")).map(el => el.className).join("|")`); got != "jv-error" {
t.Errorf("the failure is said in %q, want once, in the view (jv-error)", got)
}
f.FailCarryOn(0)
drive(t, rig, chromedp.Click(chromedp.CSS(view+` .jv-act button`)))
wait(`document.querySelector(` + strconv.Quote(job) + `)?.dataset.state === "working"`)
settle()
if n := harness.Evaluate[int](rig, `document.querySelectorAll(`+strconv.Quote(job+` .jv-act`)+`).length`); n != 0 {
t.Errorf("Carry on now still shows on a working job")
}
calls := f.Calls("/api/v1/assistant/cards/" + id + "/carry_on")
if len(calls) != 2 {
t.Fatalf("Carry on now went %d times, want the failure and its retry", len(calls))
}
key := calls[0].Header.Get("Idempotency-Key")
if want := `{"idempotency_key":"` + key + `","revision":3}`; key == "" || strings.TrimSpace(calls[0].Body) != want || calls[1].Body != calls[0].Body {
t.Errorf("sent %s then %s with key %q, want %s twice", calls[0].Body, calls[1].Body, key, want)
}
}