Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/changed-waiting-on-chip-icons.md
Original file line number Diff line number Diff line change
@@ -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)).
69 changes: 41 additions & 28 deletions src/pkg/dashboard/stage_tracker_presence.test.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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'),
Expand All @@ -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(/<svg ([^>]*)>[\s\S]*?<\/svg>/g, '<svg $1></svg>');

const iso = ms => new Date(ms).toISOString();
const MIN = 60000, HOUR = 60 * MIN;
Expand All @@ -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), /<svg class="ham-ico ham-presence-ico"[^>]*aria-hidden="true"><\/svg><i class="ham-presence-dot"><\/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, /^<span class="ham-badge ham-badge-waiting" title="@zoe: no clanker registered — waiting for a human reply" aria-label="Waiting on — @zoe: no clanker registered — waiting for a human reply">/);
assert.match(chip, /waiting on <span class="ham-presence ham-presence-unknown"[^>]*><\/span>@zoe \(human · no clanker\)<\/span>$/);
// An unregistered clanker (another hive's PR) is unknown too, but adoption's clock runs.
assert.match(chip, /^<span class="ham-badge ham-badge-waiting" title="Waiting on @zoe \(human\) — waiting for a human reply" aria-label="Waiting on @zoe \(human\) — waiting for a human reply">/);
assert.match(flat(chip), /waiting on <span class="ham-presence ham-presence-unknown ham-presence-human"[^>]*><svg [^>]*><\/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 [^>]*><\/svg><i class="ham-presence-dot"><\/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 class="ham-badge ham-badge-adoption" title="waiting on @hanthor \(offline 26h, 2 nudges\) · @hanthor's clanker: offline 26h — hive will adopt at 15:10 UTC \(in 38m\)"/);
assert.match(chip, /aria-label="Adoption — waiting on @hanthor \(offline 26h, 2 nudges\) · @hanthor's clanker: offline 26h/);
assert.match(chip, />waiting on <span class="ham-presence ham-presence-offline"[^>]*><\/span>@hanthor<\/span>$/);
assert.match(chip, /^<span class="ham-badge ham-badge-adoption" title="waiting on @hanthor \(offline 26h, 2 nudges\) · Waiting on @hanthor's hive \(clanker · offline 26h\) — hive will adopt at 15:10 UTC \(in 38m\)"/);
assert.match(chip, /aria-label="Adoption — waiting on @hanthor \(offline 26h, 2 nudges\) · Waiting on @hanthor's hive \(clanker · offline 26h\)/);
assert.match(flat(chip), />waiting on <span class="ham-presence ham-presence-offline ham-presence-clanker"[^>]*><svg [^>]*><\/svg><i class="ham-presence-dot"><\/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), /^<span class="ham-badge ham-badge-waiting" [^>]*>waiting on <span class="ham-presence ham-presence-online"[^>]*><\/span>@Danathar<\/span>$/);
assert.match(flat(api.chip(online14989)), /^<span class="ham-badge ham-badge-waiting" [^>]*>waiting on <span class="ham-presence ham-presence-online ham-presence-clanker"[^>]*><svg [^>]*><\/svg><i class="ham-presence-dot"><\/i><\/span>@Danathar<\/span>$/);
// Text naming nobody gets the indicator in front.
assert.match(api.inPill(online14989, 'adopt?'), /^<span class="ham-presence ham-presence-online"[^>]*><\/span>adopt\?$/);
assert.match(flat(api.inPill(online14989, 'adopt?')), /^<span class="ham-presence ham-presence-online ham-presence-clanker"[^>]*><svg [^>]*><\/svg><i class="ham-presence-dot"><\/i><\/span>adopt\?$/);
});

test('rows without presence, or with a malformed one, render as before', () => {
Expand All @@ -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; \} \}/);
});
Loading
Loading