The pull requests card gets a diff column, the lines a PR adds and removes (`+120 −8`), sortable on the total. The controller takes the counts from the forge's pull request list, so no call is added. The column that said "has all approvals" is now headed "approved".
80 lines
2.4 KiB
JavaScript
80 lines
2.4 KiB
JavaScript
// 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 {
|
||
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,
|
||
);
|
||
});
|