| index 006db00..ff99958 100644 |
| --- a/internal/browsertest/thinking_test.go |
| +++ b/internal/browsertest/thinking_test.go |
| @@ -431,9 +431,9 @@ func TestAskGlance(t *testing.T) { |
| th.wait(`(() => { const l = document.querySelector(` + strconv.Quote(thinkingSel+" .think-line") + `); |
| return l && l.getAnimations({ subtree: true }).some(a => a.playState === "running" && a.effect.target.textContent === ` + strconv.Quote(glance) + ` && |
| Number(a.effect.getKeyframes()[0].opacity) === 0); })()`) |
| - th.wait(`!window.__b.querySelector(".dots")`) // faded out under the glance |
| + th.wait(`!window.__b.querySelector(":scope > .think-line > .dots")`) // faded out under the glance |
| if got := th.eval(`(() => { const b = window.__b, p = []; |
| - if (b.querySelector(".dots")) p.push("the dots still show"); |
| + if (b.querySelector(":scope > .think-line > .dots")) p.push("the wordless dots still show"); |
| if (!b.matches(".thinking") || !b.querySelector("canvas")) p.push("no longer thinking, with its spark"); |
| if (document.querySelectorAll("#ask-panel .thinking").length !== 1) p.push(document.querySelectorAll("#ask-panel .thinking").length + " bubbles"); |
| if (document.querySelector("#ask-panel .ask-status").textContent) p.push("the status line says " + document.querySelector("#ask-panel .ask-status").textContent); |
| @@ -529,6 +529,77 @@ func TestAskGlance(t *testing.T) { |
| th.wait(`[...document.querySelectorAll("#ask-panel .msg.coordinator")].some(m => m.dataset.id && m.textContent === "All done.") && !document.querySelector("#ask-panel .thinking")`) |
| } |
| |
| +// glanceJS reports how the watched bubble's glance (window.__b) does not |
| +// read as a status: secondary ink (want), italic, one line, the three dots |
| +// after its words, hidden from assistive tech, shimmering or (still) not. |
| +func glanceJS(want string, still bool) string { |
| + return `(() => { const b = window.__b, say = b.querySelector(":scope > .think-line > .say"), p = []; |
| + if (!say) return "no status words"; |
| + const w = say.querySelector(":scope > .words"), d = [...say.querySelectorAll(":scope > .dots > i")], s = getComputedStyle(say); |
| + if (s.fontStyle !== "italic" || getComputedStyle(w).fontStyle !== "italic") p.push("upright"); |
| + if (s.color !== ` + strconv.Quote(want) + `) p.push("ink " + s.color); |
| + if (getComputedStyle(w).whiteSpace !== "nowrap") p.push("wraps"); |
| + if (d.length !== 3) p.push(d.length + " dots after the words"); |
| + if (say.querySelector(".dots")?.getAttribute("aria-hidden") !== "true") p.push("the dots are read out"); |
| + if (d.length && d[0].getBoundingClientRect().left < w.getBoundingClientRect().right - 0.5) p.push("the dots are not after the words"); |
| + for (const i of d) { |
| + const c = getComputedStyle(i), moving = c.animationName === "think-dot, think-hue"; |
| + if (moving === ` + strconv.FormatBool(still) + `) p.push("a dot: " + c.animationName); |
| + if (i.getBoundingClientRect().width < 4 || !(Number(c.opacity) > 0.3)) p.push("a dot hardly shows"); |
| + } |
| + return p.join("; "); })()` |
| +} |
| + |
| +// A glance (or an activity line) is a status, not a reply: secondary ink, |
| +// italic, AA on the bubble in dark and light, and the soft dots after it, |
| +// still shimmering, so the Assistant is plainly still working (holding |
| +// still with reduced motion). The reply that takes its place is upright, |
| +// in full ink, with no dots. |
| +func TestAskGlanceReadsAsStatus(t *testing.T) { |
| + rig, f := askBase(t) |
| + th := thinking{t, rig, f} |
| + const glance, reply = "Yo, Paul.", "Here is what I found." |
| + for _, c := range []struct { |
| + scheme string |
| + still bool |
| + haze, frost string |
| + }{ |
| + {"dark", false, "rgb(221, 227, 240)", "rgb(238, 242, 248)"}, |
| + {"light", false, "rgb(74, 82, 117)", "rgb(30, 36, 64)"}, |
| + {"dark", true, "rgb(221, 227, 240)", "rgb(238, 242, 248)"}, |
| + } { |
| + when := c.scheme + map[bool]string{false: "", true: ", reduced motion"}[c.still] |
| + drive(t, rig, chromedp.EmulateViewport(1280, 800), reducedMotion(c.scheme, c.still)) |
| + openPanel(t, rig) |
| + id := th.send("Anything new?") |
| + drive(t, rig, chromedp.Evaluate[chromedp.Void](watchJS(glance))) |
| + f.Glance(id, glance) |
| + th.wait(`window.__g > 0 && !window.__b.querySelector(":scope > .think-line > .dots") && !window.__b.getAnimations({ subtree: true }).some(a => !(a instanceof CSSAnimation))`) |
| + if got := th.eval(glanceJS(c.haze, c.still)); got != "" { |
| + t.Errorf("%s, the glance: %s", when, got) |
| + } |
| + if !c.still { |
| + worst, need, where := textContrast(t, rig, thinkingSel+" .say") |
| + t.Logf("%s: the glance's contrast %.2f (%q)", when, worst, where) |
| + if worst < need { |
| + t.Errorf("%s: the glance %q has contrast %.2f, needs %.1f", when, where, worst, need) |
| + } |
| + rig.Screen("#ask-panel", "the glance as a status, "+when) |
| + } |
| + f.Answer(id, reply, false) |
| + th.wait(`window.__b.dataset.id && window.__b.textContent === ` + strconv.Quote(reply) + ` && !document.querySelector("#ask-panel .think-line") && !window.__b.getAnimations({ subtree: true }).length`) |
| + if got := th.eval(`(() => { const b = window.__b, p = []; |
| + for (const e of [b, ...b.querySelectorAll("*")]) { const s = getComputedStyle(e); |
| + if (s.fontStyle !== "normal") p.push(e.tagName + " " + s.fontStyle); |
| + if (s.color !== ` + strconv.Quote(c.frost) + `) p.push(e.tagName + " ink " + s.color); } |
| + if (b.querySelector(".dots, .say")) p.push("status left in it: " + b.innerHTML); |
| + return p.join("; "); })()`); got != "" { |
| + t.Errorf("%s, the reply: %s", when, got) |
| + } |
| + } |
| + drive(t, rig, reducedMotion("dark", false)) |
| +} |
| + |
| // steadyJS watches the thinking bubble frame by frame from now on, until |
| // window.__stop: in window.__steady, every frame's problem (no words or |
| // dots in view, the line's text empty once words have come, the bubble's |
| @@ -579,9 +650,11 @@ func TestAskThinkingHoldsSteady(t *testing.T) { |
| } |
| th.wait(`document.querySelector(` + strconv.Quote(thinkingSel+" .think-line") + `).textContent === ` + strconv.Quote(line)) |
| if line == long { |
| - if got := th.eval(`(() => { const l = document.querySelector(` + strconv.Quote(thinkingSel+" .think-line") + `), c = l.lastElementChild, s = getComputedStyle(c); |
| - return [c.getClientRects().length, Math.round(c.getBoundingClientRect().height) <= Math.ceil(parseFloat(s.lineHeight)), c.scrollWidth > c.clientWidth, s.textOverflow].join(" "); })()`); got != "1 true true ellipsis" { |
| - t.Errorf("the 120-character line: boxes, one line high, clipped, overflow %s; want 1 true true ellipsis", got) |
| + if got := th.eval(`(() => { const l = document.querySelector(` + strconv.Quote(thinkingSel+" .think-line") + `), c = l.lastElementChild.querySelector(".words"), s = getComputedStyle(c); |
| + const d = l.lastElementChild.querySelector(".dots").getBoundingClientRect(), b = l.parentElement.getBoundingClientRect(); |
| + return [c.getClientRects().length, Math.round(c.getBoundingClientRect().height) <= Math.ceil(parseFloat(s.lineHeight)), c.scrollWidth > c.clientWidth, s.textOverflow, |
| + d.width > 0 && d.left >= c.getBoundingClientRect().right - 0.5 && d.right <= b.right].join(" "); })()`); got != "1 true true ellipsis true" { |
| + t.Errorf("the 120-character line: boxes, one line high, clipped, overflow, dots in view after it %s; want 1 true true ellipsis true", got) |
| } |
| } |
| drive(t, rig, chromedp.Sleep(400*time.Millisecond)) |