diff --git a/changelog.d/changed-waiting-on-chip-icons.md b/changelog.d/changed-waiting-on-chip-icons.md new file mode 100644 index 0000000000..68c5d5f351 --- /dev/null +++ b/changelog.d/changed-waiting-on-chip-icons.md @@ -0,0 +1 @@ +- The Activity Monitor's "waiting on" chip now draws who a row waits on instead of spelling it out: a human owner reads `waiting on [person] @login` with the stage chevrons' person glyph and no "(human · no clanker)" qualifier; a contributor's hive reads `waiting on [robot ●] @login` with the clanker's robot head and the online / offline / unknown dot beside it. The hover title says the rest — `Waiting on @zoe (human) — waiting for a human reply` / `Waiting on @hanthor's hive (clanker · offline 26h) — hive will adopt at …` ([#15227](https://github.com/hivecommons/hive/issues/15227)). diff --git a/src/pkg/dashboard/stage_tracker_presence.test.js b/src/pkg/dashboard/stage_tracker_presence.test.js index e82d64ff77..17d35aefc3 100644 --- a/src/pkg/dashboard/stage_tracker_presence.test.js +++ b/src/pkg/dashboard/stage_tracker_presence.test.js @@ -1,7 +1,9 @@ // The presence indicator on the Activity Monitor's waiting-on pill -// (hivecommons/hive#15051): a row waiting on a person says whether their -// clanker is online (dot), offline (square) or not registered (hollow ring), -// and what the hive does next (wait / adopt at …). The helpers are lifted +// (hivecommons/hive#15051): a row waiting on a person draws who it waits on — +// the chevrons' person glyph for a human, the robot head for a contributor's +// hive with a state dot beside it: online (dot), offline (square) or not +// registered (hollow ring) — and the title says what the hive does next +// (wait / adopt at …). The helpers are lifted // out of index.html so this runs against the shipped source; the fixtures // are the live /api/stage-tracker shape with the new `presence` field. const test = require('node:test'); @@ -23,6 +25,8 @@ const src = [ pick(/function stageTrackerAdoptOffered\(item\) \{[\s\S]*?\n \}\n/, 'stageTrackerAdoptOffered'), pick(/function stageTrackerAdoptionChipText\(item\) \{[\s\S]*?\n \}\n/, 'stageTrackerAdoptionChipText'), pick(/function stageTrackerAdoptionChipHtml\(item\) \{[\s\S]*?\n \}\n/, 'stageTrackerAdoptionChipHtml'), + pick(/const STAGE_TRACKER_ICONS = \{[\s\S]*?\n \};\n/, 'STAGE_TRACKER_ICONS'), + pick(/function stageTrackerIcon\(key, cls, label\) \{[\s\S]*?\n \}\n/, 'stageTrackerIcon'), pick(/const STAGE_TRACKER_PRESENCE_STATES = \[[^\n]*\];/, 'STAGE_TRACKER_PRESENCE_STATES'), pick(/const STAGE_TRACKER_PRESENCE_WORDS = \{[^\n]*\};/, 'STAGE_TRACKER_PRESENCE_WORDS'), pick(/function stageTrackerPresenceOf\(item\) \{[\s\S]*?\n \}\n/, 'stageTrackerPresenceOf'), @@ -46,7 +50,9 @@ const stubs = ` Date.now = () => ${NOW}; `; const api = new Function(stubs + src + `; return { of: stageTrackerPresenceOf, tip: stageTrackerPresenceTip, aria: stageTrackerPresenceAria, dot: stageTrackerPresenceDotHtml, - inPill: stageTrackerPresenceInPillHtml, chipText: stageTrackerPresenceChipText, chip: stageTrackerPresenceChipHtml, adoptionChip: stageTrackerAdoptionChipHtml };`)(); + inPill: stageTrackerPresenceInPillHtml, chipText: stageTrackerPresenceChipText, chip: stageTrackerPresenceChipHtml, adoptionChip: stageTrackerAdoptionChipHtml, icons: STAGE_TRACKER_ICONS };`)(); +// Collapse an inline SVG's body so the surrounding markup can be matched exactly. +const flat = (h) => h.replace(/]*)>[\s\S]*?<\/svg>/g, ''); const iso = ms => new Date(ms).toISOString(); const MIN = 60000, HOUR = 60 * MIN; @@ -62,57 +68,64 @@ const offline14524 = { repo: 'hivecommons/hive', number: 14524, kind: 'pr', stag const human = { repo: 'hivecommons/hive', number: 15000, kind: 'pr', stage: 71, author: 'zoe', author_kind: 'human', presence: { login: 'zoe', state: 'unknown', kind: 'human', since: iso(NOW - 40 * MIN), next: 'wait' } }; -test('online clanker: filled dot, "hive is waiting for them", last seen in words', () => { - assert.strictEqual(api.tip(online14989, NOW), "@Danathar's clanker: online, last seen 2 min ago — hive is waiting for them"); +test('online clanker: robot head + filled dot, "hive is waiting for them", last seen in words', () => { + assert.strictEqual(api.tip(online14989, NOW), "Waiting on @Danathar's hive (clanker · online, last seen 2 min ago) — hive is waiting for them"); const dot = api.dot(online14989, NOW); - assert.match(dot, /class="ham-presence ham-presence-online"/); + assert.match(dot, /class="ham-presence ham-presence-online ham-presence-clanker"/); + assert.ok(dot.includes(api.icons.clanker), 'draws the robot head'); + assert.match(flat(dot), /]*aria-hidden="true"><\/svg><\/i><\/span>$/); assert.match(dot, /role="img"/); assert.match(dot, /aria-label="@Danathar: clanker online — hive is waiting for them"/); assert.match(dot, /data-ham-presence="online"/); // The online grace still projects an adopt-at: the tooltip says so after the wait. const graced = Object.assign({}, online14989, { presence: Object.assign({}, online14989.presence, { adopt_at: iso(NOW + 2 * HOUR) }) }); - assert.strictEqual(api.tip(graced, NOW), "@Danathar's clanker: online, last seen 2 min ago — hive is waiting for them; adopts at 16:32 UTC (in 2h) if nothing moves"); + assert.strictEqual(api.tip(graced, NOW), "Waiting on @Danathar's hive (clanker · online, last seen 2 min ago) — hive is waiting for them; adopts at 16:32 UTC (in 2h) if nothing moves"); }); test('offline clanker: filled square, offline span, adopt-at clock with countdown', () => { - assert.strictEqual(api.tip(offline14524, NOW), "@hanthor's clanker: offline 26h — hive will adopt at 15:10 UTC (in 38m)"); + assert.strictEqual(api.tip(offline14524, NOW), "Waiting on @hanthor's hive (clanker · offline 26h) — hive will adopt at 15:10 UTC (in 38m)"); assert.match(api.dot(offline14524, NOW), /ham-presence-offline/); assert.match(api.dot(offline14524, NOW), /aria-label="@hanthor: clanker offline — hive will adopt at 15:10 UTC \(in 38m\)"/); // Past due. const due = Object.assign({}, offline14524, { presence: Object.assign({}, offline14524.presence, { adopt_at: iso(NOW - MIN) }) }); - assert.strictEqual(api.tip(due, NOW), "@hanthor's clanker: offline 26h — hive will adopt due now"); + assert.strictEqual(api.tip(due, NOW), "Waiting on @hanthor's hive (clanker · offline 26h) — hive will adopt due now"); // Held (maintainer_policy ask): no adopt_at, next=wait — the dot does not promise an adoption the text denies. const held = Object.assign({}, offline14524, { presence: Object.assign({}, offline14524.presence, { next: 'wait', adopt_at: '' }) }); - assert.strictEqual(api.tip(held, NOW), "@hanthor's clanker: offline 26h — hive is waiting for them"); + assert.strictEqual(api.tip(held, NOW), "Waiting on @hanthor's hive (clanker · offline 26h) — hive is waiting for them"); // Long absences read in days. const days = Object.assign({}, offline14524, { presence: Object.assign({}, offline14524.presence, { since: iso(NOW - 80 * HOUR), last_seen: iso(NOW - 80 * HOUR) }) }); - assert.match(api.tip(days, NOW), /offline 3d — /); + assert.match(api.tip(days, NOW), /offline 3d\) — /); }); -test('human without a clanker: hollow ring, "waiting for a human reply", pill says human · no clanker', () => { - assert.strictEqual(api.tip(human, NOW), '@zoe: no clanker registered — waiting for a human reply'); +test('human: the person glyph and the handle only — no dot, no "(human · no clanker)" qualifier', () => { + assert.strictEqual(api.tip(human, NOW), 'Waiting on @zoe (human) — waiting for a human reply'); const dot = api.dot(human, NOW); - assert.match(dot, /ham-presence-unknown/); - assert.match(dot, /aria-label="@zoe: human, no clanker — waiting for a human reply"/); - assert.strictEqual(api.chipText(human), 'waiting on @zoe (human · no clanker)'); + assert.match(dot, /class="ham-presence ham-presence-unknown ham-presence-human"/); + assert.ok(dot.includes(api.icons.human), 'draws the chevrons\' person glyph'); + assert.ok(!dot.includes(api.icons.clanker), 'never the robot head'); + assert.ok(!dot.includes('ham-presence-dot'), 'a human carries no state dot'); + assert.match(dot, /aria-label="@zoe: human — waiting for a human reply"/); + assert.strictEqual(api.chipText(human), 'waiting on @zoe'); const chip = api.chip(human); - assert.match(chip, /^/); - assert.match(chip, /waiting on ]*><\/span>@zoe \(human · no clanker\)<\/span>$/); - // An unregistered clanker (another hive's PR) is unknown too, but adoption's clock runs. + assert.match(chip, /^/); + assert.match(flat(chip), /waiting on ]*>]*><\/svg><\/span>@zoe<\/span>$/); + assert.ok(!chip.includes('no clanker')); + // An unregistered clanker (another hive's PR) is unknown too — robot head + hollow ring — and adoption's clock runs. const foreign = { presence: { login: 'bot-x', state: 'unknown', kind: 'clanker', since: iso(NOW - 10 * MIN), next: 'adopt', adopt_at: iso(NOW + 5 * MIN) } }; - assert.strictEqual(api.tip(foreign, NOW), '@bot-x: no clanker registered here — hive will adopt at 14:37 UTC (in 5m)'); + assert.strictEqual(api.tip(foreign, NOW), "Waiting on @bot-x's hive (clanker · not registered here) — hive will adopt at 14:37 UTC (in 5m)"); + assert.match(flat(api.dot(foreign, NOW)), /class="ham-presence ham-presence-unknown ham-presence-clanker"[^>]*>]*><\/svg><\/i><\/span>$/); }); test('the indicator sits inside the adoption pill just before the @login and its line joins the tooltip', () => { const chip = api.adoptionChip(offline14524); - assert.match(chip, /^]*><\/span>@hanthor<\/span>$/); + assert.match(chip, /^]*>]*><\/svg><\/i><\/span>@hanthor<\/span>$/); // A 071 row has no adoption line: the muted waiting pill carries the dot instead, never both. assert.strictEqual(api.chip(offline14524), '', 'no second pill beside the adoption one'); - assert.match(api.chip(online14989), /^]*>waiting on ]*><\/span>@Danathar<\/span>$/); + assert.match(flat(api.chip(online14989)), /^]*>waiting on ]*>]*><\/svg><\/i><\/span>@Danathar<\/span>$/); // Text naming nobody gets the indicator in front. - assert.match(api.inPill(online14989, 'adopt?'), /^]*><\/span>adopt\?$/); + assert.match(flat(api.inPill(online14989, 'adopt?')), /^]*>]*><\/svg><\/i><\/span>adopt\?$/); }); test('rows without presence, or with a malformed one, render as before', () => { @@ -136,6 +149,6 @@ test('style ratchet: the indicator uses classes and tokens, no inline styles; re assert.ok(!/ham-presence[^\n]*style="/.test(html), 'no inline style on the indicator'); assert.match(html, /\.ham-presence-online \{[^\n]*var\(--cue-decision\)/); assert.match(html, /\.ham-presence-offline \{[^\n]*var\(--status-error\)/); - assert.match(html, /\.ham-presence-unknown \{[^\n]*border: var\(--line-width\) solid var\(--text-faint\)[^\n]*background: transparent/); - assert.match(html, /@media \(prefers-reduced-motion: reduce\) \{ \.ham-presence-online \{ animation: none; \} \}/); + assert.match(html, /\.ham-presence-unknown \.ham-presence-dot \{[^\n]*border: var\(--line-width\) solid var\(--text-faint\)[^\n]*background: transparent/); + assert.match(html, /@media \(prefers-reduced-motion: reduce\) \{ \.ham-presence-online \.ham-presence-dot \{ animation: none; \} \}/); }); diff --git a/src/pkg/dashboard/stage_tracker_presence_test.go b/src/pkg/dashboard/stage_tracker_presence_test.go index 28fc5933e7..08641782e0 100644 --- a/src/pkg/dashboard/stage_tracker_presence_test.go +++ b/src/pkg/dashboard/stage_tracker_presence_test.go @@ -222,6 +222,8 @@ func stageTrackerPresenceJS(t *testing.T, html string) string { return strings.Join([]string{ jsFunc(t, html, "agentNowAgo"), jsFunc(t, html, "agentNowClockTime"), + jsConstBlock(t, html, "STAGE_TRACKER_ICONS"), + jsFunc(t, html, "stageTrackerIcon"), jsConstLine(t, html, "STAGE_TRACKER_PRESENCE_STATES"), jsConstLine(t, html, "STAGE_TRACKER_PRESENCE_WORDS"), jsFunc(t, html, "stageTrackerPresenceOf"), @@ -236,8 +238,8 @@ func stageTrackerPresenceJS(t *testing.T, html string) string { }, "\n") } -// The SPA, fed the live payload shape: the indicator's shape class and -// aria-label per state, the plain-words tooltip, its place inside the +// The SPA, fed the live payload shape: the indicator's kind glyph (person / +// robot head), its state class and aria-label, the plain-words tooltip, its place inside the // adoption pill, the muted waiting pill where there is no adoption line, // and the popover's presence line. Node runs the lifted helpers on stdin. func TestStageTrackerPresenceJS(t *testing.T) { @@ -269,35 +271,41 @@ const ask = { kind: 'pr', repo: 'hivecommons/hive', number: 14524, stage: 72, au decision_needed: { question: '@hanthor maintains this repository and has been offline for 26h; adopt the PR?', asked_by: 'the hive', since: iso(NOW - 26 * HOUR), blocker: 'maintainer_policy is ask', options: [{ action: 'decide:adopt', label: 'Adopt (hive takes over)', enabled: true }] }, presence: { login: 'hanthor', state: 'offline', kind: 'clanker', since: iso(NOW - 26 * HOUR), last_seen: iso(NOW - 26 * HOUR), next: 'wait' } }; -assert.strictEqual(stageTrackerPresenceTip(online, NOW), "@Danathar's clanker: online, last seen 2 min ago — hive is waiting for them"); -assert.match(stageTrackerPresenceTip(offline, NOW), /^@hanthor's clanker: offline 26h — hive will adopt at \S+ .*\(in 38m\)$/); -assert.strictEqual(stageTrackerPresenceTip(human, NOW), '@zoe: no clanker registered — waiting for a human reply'); -assert.strictEqual(stageTrackerPresenceTip(ask, NOW), "@hanthor's clanker: offline 26h — hive is waiting for them", 'held adoption promises no adopt-at'); +assert.strictEqual(stageTrackerPresenceTip(online, NOW), "Waiting on @Danathar's hive (clanker · online, last seen 2 min ago) — hive is waiting for them"); +assert.match(stageTrackerPresenceTip(offline, NOW), /^Waiting on @hanthor's hive \(clanker · offline 26h\) — hive will adopt at \S+ .*\(in 38m\)$/); +assert.strictEqual(stageTrackerPresenceTip(human, NOW), 'Waiting on @zoe (human) — waiting for a human reply'); +assert.strictEqual(stageTrackerPresenceTip(ask, NOW), "Waiting on @hanthor's hive (clanker · offline 26h) — hive is waiting for them", 'held adoption promises no adopt-at'); -// Shape class + aria per state; role=img so the shape reads out. -for (const [item, state, word] of [[online, 'online', 'clanker online'], [offline, 'offline', 'clanker offline'], [human, 'unknown', 'human, no clanker']]) { +// Kind glyph + state class + aria per state; role=img so it reads out. +for (const [item, state, kind, word] of [[online, 'online', 'clanker', 'clanker online'], [offline, 'offline', 'clanker', 'clanker offline'], [human, 'unknown', 'human', 'human']]) { const dot = stageTrackerPresenceDotHtml(item, NOW); - assert.ok(dot.includes('class="ham-presence ham-presence-' + state + '"'), dot); + assert.ok(dot.includes('class="ham-presence ham-presence-' + state + ' ham-presence-' + kind + '"'), dot); assert.ok(dot.includes('role="img"'), dot); assert.ok(dot.includes('aria-label="@' + item.presence.login + ': ' + word + ' — '), dot); + assert.ok(dot.includes('waiting on ]*><\/span>@hanthor<\/span>$/.test(chip), chip); -assert.ok(chip.includes("title=\"waiting on @hanthor (offline 26h, 2 nudges) · @hanthor's clanker: offline 26h"), chip); -assert.ok(chip.includes("aria-label=\"Adoption — waiting on @hanthor (offline 26h, 2 nudges) · @hanthor's clanker"), chip); +assert.ok(/>waiting on ]*>]*><\/svg><\/i><\/span>@hanthor<\/span>$/.test(chip.replace(/]*)>[\s\S]*?<\/svg>/, '')), chip); +assert.ok(chip.includes("title=\"waiting on @hanthor (offline 26h, 2 nudges) · Waiting on @hanthor's hive (clanker · offline 26h)"), chip); +assert.ok(chip.includes("aria-label=\"Adoption — waiting on @hanthor (offline 26h, 2 nudges) · Waiting on @hanthor's hive (clanker"), chip); assert.strictEqual(stageTrackerPresenceChipHtml(offline), '', 'one pill, not two'); // The "adopt?" trigger carries the dot in front of its word. const trig = stageTrackerAdoptionChipHtml(ask); -assert.ok(/]*><\/span>adopt\?<\/button>$/.test(trig), trig); +assert.ok(/