d21a8595 Andy McCall 23 days ago ↶
1
import { test } from "node:test";
2
import assert from "node:assert/strict";
3
import { look, pinDescription, pinLabel, pinTooltip, tone } from "../out/diffusionview.mjs";
4
5
const half = (tone, word) => ({ tone, word, title: `${word}.` });
6
const pin = (over = {}) => ({
7
upstream: "doomsdayone/rstar-api",
8
consumer: "doomsdayone/metalgear",
9
path: "rstar-api",
10
bookmark: "develop",
11
behind: 2,
12
follow: "green",
13
bump: 304,
14
run: 194,
15
run_status: "passed",
16
upstream_state: half("amber", "untested"),
17
consumer_state: half("green", "passes"),
18
...over,
19
});
20
21
test("a row shows the more urgent half", () => {
22
assert.equal(tone(pin()), "amber", "untested outranks passes");
23
assert.equal(tone(pin({ consumer_state: half("red", "fails") })), "red");
24
assert.equal(tone(pin({ upstream_state: half("green", "checked"), consumer_state: half("off", "not following") })), "green", "not following is not urgent");
25
assert.equal(tone(pin({ upstream_state: half("off", "x"), consumer_state: half("off", "y") })), "off");
26
assert.equal(look("red").icon, "error");
27
assert.equal(look("amber").color, "list.warningForeground");
28
assert.equal(look("whatever").icon, "circle-outline");
29
});
30
31
test("a row names the other end and reads like the pill", () => {
32
assert.equal(pinLabel(pin(), "takes"), "doomsdayone/rstar-api");
33
assert.equal(pinLabel(pin(), "gives"), "doomsdayone/metalgear");
34
assert.equal(pinDescription(pin()), "untested │ passes · 2 behind · bump #304");
35
assert.equal(pinDescription(pin({ behind: 0, bump: null, consumer_state: half("green", "up to date") })), "untested │ up to date");
36
assert.equal(pinDescription(pin({ behind: null, bump: null })), "untested │ passes");
37
const tip = pinTooltip(pin());
38
assert.match(tip, /\*\*doomsdayone\/rstar-api: untested\.\*\*/);
39
assert.match(tip, /Pinned at `rstar-api` on `develop`; doomsdayone\/metalgear follows when the upstream is green\. Open bump #304 · run #194 passed\./);
40
});