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:
parent
96334845f0
commit
e4cfac6926
4 changed files with 102 additions and 0 deletions
|
|
@ -470,6 +470,13 @@ nix fmt # treefmt — authoritative, NOT bare cargo fmt
|
||||||
misses the non-rust files treefmt also covers, so always run `nix
|
misses the non-rust files treefmt also covers, so always run `nix
|
||||||
fmt` before pushing. It also formats and lints Python with ruff.
|
fmt` before pushing. It also formats and lints Python with ruff.
|
||||||
|
|
||||||
|
**Frontend checks** run from `frontend/`: `npm test` runs the unit tests of every
|
||||||
|
workspace that has any (today the swarm UI's, with Node's own runner), and
|
||||||
|
`npm run typecheck` runs `tsc` in each that has a typecheck. Build with
|
||||||
|
`npm run build`. Pure logic goes in a `.ts` module that a test imports directly. A test
|
||||||
|
under Node can't import a module that names a sibling with a `.js` specifier, as the
|
||||||
|
build resolves it.
|
||||||
|
|
||||||
**Clippy discipline — never add `#[allow(clippy::…)]`.** All lints are
|
**Clippy discipline — never add `#[allow(clippy::…)]`.** All lints are
|
||||||
CI-fatal at `-D warnings` (pedantic included); every warning that fires
|
CI-fatal at `-D warnings` (pedantic included); every warning that fires
|
||||||
must be *fixed*, not silenced. Common patterns:
|
must be *fixed*, not silenced. Common patterns:
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "npm run build --workspaces --if-present",
|
"build": "npm run build --workspaces --if-present",
|
||||||
|
"test": "npm run test --workspaces --if-present",
|
||||||
|
"typecheck": "npm run typecheck --workspaces --if-present",
|
||||||
"clean": "rm -rf packages/*/dist"
|
"clean": "rm -rf packages/*/dist"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
|
||||||
47
frontend/packages/swarm-ui/test/runs-types.test.mjs
Normal file
47
frontend/packages/swarm-ui/test/runs-types.test.mjs
Normal 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");
|
||||||
|
});
|
||||||
46
frontend/packages/swarm-ui/test/term-drag.test.mjs
Normal file
46
frontend/packages/swarm-ui/test/term-drag.test.mjs
Normal 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();
|
||||||
|
});
|
||||||
Loading…
Reference in a new issue