Watch
0
0
Fork
You've already forked hyperhive
0
hyperhive/frontend/packages/swarm-ui/test/soft-context.test.mjs
iris d4dc8b48b1 swarm ui: the context limit zones line up with their handles and legend
The zones were drawn by percentage of the full track, but a range input's thumb travels its own range less one thumb width, and the range starts at 5. So the colour edges sat off the handles. The zones now follow the thumb's travel (a tested helper in soft-context), and the Firefox thumb has the same size as the other. The legend bars had no colour either, as the item rule reset the border colour; their rule is now more specific.
2026-11-18 23:22:03 +01:00

41 lines
1.3 KiB
JavaScript

// The soft context limit field: what counts as empty, valid and refused. Run
// by `npm test`, which imports the `.ts` module as it is.
import assert from "node:assert/strict";
import { test } from "node:test";
import {
along,
MAX_SOFT_CONTEXT_PERCENT,
MIN_SOFT_CONTEXT_PERCENT,
softContextValue,
} from "../src/agent/detail/soft-context.ts";
test("an empty box leaves the agent on its own limit", () => {
assert.equal(softContextValue(""), undefined);
assert.equal(softContextValue(" "), undefined);
});
test("a whole percent from 5 to 100 is taken", () => {
assert.equal(softContextValue("20"), 20);
assert.equal(softContextValue(" 75 "), 75);
assert.equal(
softContextValue(String(MIN_SOFT_CONTEXT_PERCENT)),
MIN_SOFT_CONTEXT_PERCENT,
);
assert.equal(
softContextValue(String(MAX_SOFT_CONTEXT_PERCENT)),
MAX_SOFT_CONTEXT_PERCENT,
);
});
test("a percentage sits along the slider's range, not the full track", () => {
assert.equal(along(MIN_SOFT_CONTEXT_PERCENT), 0);
assert.equal(along(MAX_SOFT_CONTEXT_PERCENT), 100);
assert.equal(along(52.5), 50);
assert.ok(along(50) < 50);
});
test("anything else is refused", () => {
for (const text of ["0", "4", "101", "-20", "20.5", "abc", "1e1", "20%"]) {
assert.equal(softContextValue(text), null, text);
}
});