Watch
0
0
Fork
You've already forked hyperhive
0

frontend: root test and typecheck scripts, and tests for the review runs wording and the terminal drag

npm test and npm run typecheck now run in every workspace that has them (the repo root had only build and clean). New tests cover RunsTypes (labels and tones for every outcome, the classification count) and termDrag (what a drag carries and how the hover reads it). instructions.ts cannot be imported by a test under Node because of its .js specifier for unified-diff.ts, so it is not covered, and the conventions doc says so.
This commit is contained in:
iris 2026-11-19 19:01:47 +01:00 • committed by mara
commit e4cfac6926
2 changed files with 102 additions and 0 deletions

View file

@ -0,0 +1,47 @@
// How the review runs list words a run: outcome labels and tones, and the
// classification count. Run by `npm test`.
import assert from "node:assert/strict";
import { test } from "node:test";
import {
classificationCount,
OUTCOME_LABEL,
OUTCOME_TONE,
TRIGGER_LABEL,
} from "../src/pages/review-runs/RunsTypes.ts";
const OUTCOMES = [
"approved",
"changes-requested",
"no-verdict",
"queue-full",
"post-failed",
"done",
"failed",
];
test("every outcome has a label and a tone", () => {
for (const outcome of OUTCOMES) {
assert.ok(OUTCOME_LABEL[outcome], `label for ${outcome}`);
assert.ok(OUTCOME_TONE[outcome], `tone for ${outcome}`);
}
assert.deepEqual(Object.keys(OUTCOME_LABEL).sort(), [...OUTCOMES].sort());
});
test("a run that failed or could not post reads as negative", () => {
assert.equal(OUTCOME_TONE.failed, "negative");
assert.equal(OUTCOME_TONE["post-failed"], "negative");
assert.equal(OUTCOME_TONE.approved, "positive");
});
test("the triggers are named for the operator", () => {
assert.equal(TRIGGER_LABEL["try-out"], "try-out");
assert.equal(TRIGGER_LABEL.review, "requested review");
});
test("the classification count says one, many and none", () => {
const run = (rows) => ({ rows });
assert.equal(classificationCount(run(undefined)), "0 classifications");
assert.equal(classificationCount(run([])), "0 classifications");
assert.equal(classificationCount(run([{}])), "1 classification");
assert.equal(classificationCount(run([{}, {}, {}])), "3 classifications");
});

View file

@ -0,0 +1,46 @@
// What a drag of an agent's terminal carries, and how the hover reads it. Run by
// `npm test`.
import assert from "node:assert/strict";
import { test } from "node:test";
import {
AGENT_DRAG_TYPE,
draggedAgent,
endAgentDrag,
startAgentDrag,
} from "../src/agent/terminal/termDrag.ts";
function dragEvent() {
const data = {};
return {
data,
dataTransfer: {
effectAllowed: "",
setData: (type, value) => {
data[type] = value;
},
},
};
}
test("a drag carries the agent, as its own type and as text", () => {
const e = dragEvent();
startAgentDrag(e, "iris");
assert.equal(e.data[AGENT_DRAG_TYPE], "iris");
assert.equal(e.data["text/plain"], "iris");
assert.equal(e.dataTransfer.effectAllowed, "move");
endAgentDrag();
});
test("the hover reads the agent until the drag ends", () => {
assert.equal(draggedAgent(), null);
startAgentDrag(dragEvent(), "argus");
assert.equal(draggedAgent(), "argus");
endAgentDrag();
assert.equal(draggedAgent(), null);
});
test("a drag with no data transfer still records the agent", () => {
startAgentDrag({}, "atlas");
assert.equal(draggedAgent(), "atlas");
endAgentDrag();
});