Watch
0
0
Fork
You've already forked hyperhive
0
hyperhive/frontend/packages/swarm-ui/test/issue-report-repo.test.mjs
iris c5cc961028 swarm-ui: the report, review and classifier-key pages read through useResource
Part of the unification order in the UI sweep issue (step d, the rest).

The pull-request and issue reports (the repo list and the report), the review
try-out's repo list and classifier cap, and the classifier key move to the
shared read hook. A failed report still drops its rows, now by reading
'error ? null : loaded' instead of a handler that cleared them. The reads that
seed a draft, post, or are not a plain request stay as they were.
2026-11-26 01:21:15 +01:00

63 lines
1.8 KiB
JavaScript

import { test } from "node:test";
import assert from "node:assert/strict";
import {
ALL_REPOS,
reportRows,
reportUrl,
repoOptions,
} from "../src/pages/issue-report-repo.ts";
test("reportUrl: no repo means the combined report", () => {
assert.equal(reportUrl(ALL_REPOS), "/api/issue-report");
});
test("reportUrl: a filter without a slash is not a repo", () => {
assert.equal(reportUrl("nope"), "/api/issue-report");
});
test("reportUrl: org and name become two path segments", () => {
assert.equal(
reportUrl("hyperhive/hyperhive"),
"/api/repos/hyperhive/hyperhive/issue-report",
);
});
test("reportUrl: reserved characters in a name are encoded", () => {
assert.equal(
reportUrl("org/a?b#c%d"),
"/api/repos/org/a%3Fb%23c%25d/issue-report",
);
});
test("repoOptions: all repos comes first, then the list", () => {
assert.deepEqual(repoOptions(["a/x", "b/y"], ALL_REPOS), [
{ value: "", label: "all repos" },
{ value: "a/x", label: "a/x" },
{ value: "b/y", label: "b/y" },
]);
});
test("repoOptions: a listed selection adds nothing", () => {
assert.equal(repoOptions(["a/x"], "a/x").length, 2);
});
test("repoOptions: a remembered repo keeps an option before the list loads", () => {
assert.deepEqual(repoOptions(null, "a/x"), [
{ value: "", label: "all repos" },
{ value: "a/x", label: "a/x" },
]);
});
test("repoOptions: a remembered repo missing from the list says why", () => {
assert.deepEqual(repoOptions(["b/y"], "a/x").at(-1), {
value: "a/x",
label: "a/x (no open issues)",
});
});
test("reportRows: a failed report shows no rows, a good one shows them", () => {
const rows = [{ n: 1 }];
assert.equal(reportRows({ detail: "boom" }, rows), null);
assert.equal(reportRows(null, rows), rows);
assert.equal(reportRows(null, null), null);
});