Watch
0
0
Fork
You've already forked hyperhive
0
hyperhive/frontend/packages/swarm-ui/test/pr-report.test.mjs
iris 71a4d1d255 swarm ui: the PR report's approvals column filters on whether the rule is met
The report had an approvals column (1/2) and a separate approved column.
They are one fact, so approvals now carries the filter, complete or missing,
and the approved column is gone.
2026-11-09 22:44:10 +01:00

96 lines
2.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// The PR report's URL and the words its columns show and filter on.
import assert from "node:assert/strict";
import { test } from "node:test";
import {
approvalsState,
approvalsText,
diffSize,
diffText,
hasAllApprovals,
prReportUrl,
yesNo,
} from "../src/pages/pr-report.ts";
test("no repo, or a filter that is not owner/name, reads as all repos", () => {
assert.equal(prReportUrl(""), "/api/pr-report");
assert.equal(prReportUrl("nothing"), "/api/pr-report");
});
test("a repo has its own URL, with each part encoded", () => {
assert.equal(
prReportUrl("hyperhive/hyperhive"),
"/api/repos/hyperhive/hyperhive/pr-report",
);
assert.equal(
prReportUrl("o/a?b#c%d"),
"/api/repos/o/a%3Fb%23c%25d/pr-report",
);
});
test("a flag filters on yes and no", () => {
assert.equal(yesNo(true), "yes");
assert.equal(yesNo(false), "no");
});
const row = (over) => ({
targets_protected_branch: true,
required_approvals: 2,
approvals: 1,
...over,
});
test("approvals read as have/required against a protected base", () => {
assert.equal(approvalsText(row({})), "1/2");
assert.equal(approvalsText(row({ approvals: 0 })), "0/2");
});
test("an unprotected base, or a rule asking for none, shows only what it has", () => {
assert.equal(
approvalsText(row({ targets_protected_branch: false, approvals: 0 })),
"—",
);
assert.equal(
approvalsText(row({ required_approvals: 0, approvals: 2 })),
"2",
);
});
test("the diff reads as lines added and removed, and sorts on both", () => {
assert.equal(diffText({ additions: 120, deletions: 8 }), "+120 −8");
assert.equal(diffText({ additions: 0, deletions: 3 }), "+0 −3");
assert.equal(diffText({ additions: 5, deletions: null }), "+5 −0");
assert.equal(diffText({ additions: null, deletions: null }), "—");
assert.equal(diffSize({ additions: 120, deletions: 8 }), 128);
assert.equal(diffSize({ additions: null, deletions: null }), 0);
});
test("a PR has all approvals when it meets the rule, and an unprotected base always does", () => {
assert.equal(hasAllApprovals(row({})), false);
assert.equal(hasAllApprovals(row({ approvals: 2 })), true);
assert.equal(hasAllApprovals(row({ approvals: 3 })), true);
assert.equal(
hasAllApprovals(
row({
targets_protected_branch: false,
required_approvals: 0,
approvals: 0,
}),
),
true,
);
});
test("the approvals column filters on whether the rule is met", () => {
assert.equal(approvalsState(row({})), "missing");
assert.equal(approvalsState(row({ approvals: 2 })), "complete");
assert.equal(
approvalsState(
row({
targets_protected_branch: false,
required_approvals: 0,
approvals: 0,
}),
),
"complete",
);
});