168 lines
8.0 KiB
JavaScript
168 lines
8.0 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import {
|
|
targetAgent, agentKey, agentName, agentStatus, createGate, gatePasses, openGate, closeGate,
|
|
isPlainEnter, statusText, queueLabel, applySuggestion, insertedNewline,
|
|
} from "../mod/ovis-composer/view.js";
|
|
|
|
const agents = [{ address: "t1", app: "claude-code" }, { address: "a2" }];
|
|
|
|
test("targetAgent picks by focused.terminal, then focused.agent", () => {
|
|
assert.equal(targetAgent(agents, { terminal: "t1" }), agents[0]);
|
|
assert.equal(targetAgent(agents, { agent: "a2" }), agents[1]);
|
|
assert.equal(targetAgent(agents, { terminal: "zz" }), null);
|
|
assert.equal(targetAgent(agents, null), null);
|
|
});
|
|
|
|
test("agentKey/agentName/agentStatus", () => {
|
|
assert.equal(agentKey({ address: " x " }), "x");
|
|
assert.equal(agentName({ program: { key: "k" } }), "k");
|
|
assert.equal(agentName(null), "default");
|
|
assert.equal(agentStatus({}), "idle");
|
|
});
|
|
|
|
test("gate: opens after a seen turn, or outright", () => {
|
|
let g = createGate();
|
|
assert.equal(gatePasses(g, "idle"), false);
|
|
assert.equal(gatePasses({ sawWorking: true }, "done"), true);
|
|
g = openGate(g);
|
|
assert.equal(gatePasses(g, "working"), true);
|
|
g = closeGate(g);
|
|
assert.equal(gatePasses(g, "idle"), false);
|
|
});
|
|
|
|
test("isPlainEnter", () => {
|
|
assert.equal(isPlainEnter({}), true);
|
|
assert.equal(isPlainEnter({ shift: true }), false);
|
|
assert.equal(isPlainEnter({ secondary: true }), false);
|
|
assert.equal(isPlainEnter(null), false);
|
|
});
|
|
|
|
test("labels", () => {
|
|
assert.equal(statusText("working"), "pracuje");
|
|
assert.equal(statusText("x"), "gotowy");
|
|
assert.equal(queueLabel({ state: "queued" }), "Następna tura");
|
|
assert.equal(queueLabel({}), "");
|
|
});
|
|
|
|
test("applySuggestion replaces token and places caret", () => {
|
|
assert.deepEqual(applySuggestion("ala /re", 7, { start: 4 }, "/review "), { value: "ala /review ", caret: 12 });
|
|
});
|
|
|
|
test("insertedNewline finds the index", () => {
|
|
assert.deepEqual(insertedNewline("ab", "a\nb"), { index: 1 });
|
|
assert.equal(insertedNewline("ab", "abc"), null);
|
|
});
|
|
|
|
test("canAutoSend waits for the draft/identity check of the agent", async () => {
|
|
const { canAutoSend } = await import("../mod/ovis-composer/view.js");
|
|
assert.equal(canAutoSend(new Set(), "t2"), false);
|
|
assert.equal(canAutoSend(new Set(["t2"]), "t2"), true);
|
|
assert.equal(canAutoSend(new Set(["t3"]), "t2"), false);
|
|
assert.equal(canAutoSend(null, "t2"), false);
|
|
});
|
|
|
|
test("queueLabel for every state", () => {
|
|
assert.equal(queueLabel({ state: "queued" }), "Następna tura");
|
|
assert.equal(queueLabel({ state: "held" }), "Wstrzymana — wyślij ręcznie");
|
|
assert.equal(queueLabel({ state: "sending" }), "Wysyłanie…");
|
|
assert.equal(queueLabel({ state: "uncertain" }), "Nie potwierdzono");
|
|
assert.equal(queueLabel({ state: "countdown", left: 2 }), "Wysyłam za 2 s");
|
|
});
|
|
|
|
import { stillSameAgent } from "../mod/ovis-composer/view.js";
|
|
|
|
test("stillSameAgent: only when the field and the focus are on one agent", () => {
|
|
assert.equal(stillSameAgent({ before: "t2", after: "t2", target: "t2" }), true);
|
|
// the focus moved to t3 while the field still showed t2: the sync switched the field
|
|
assert.equal(stillSameAgent({ before: "t2", after: "t3", target: "t3" }), false);
|
|
// the focus is on something that is not an agent
|
|
assert.equal(stillSameAgent({ before: "t2", after: "", target: "" }), false);
|
|
assert.equal(stillSameAgent({ before: "", after: "", target: "" }), false);
|
|
assert.equal(stillSameAgent({ before: "", after: "t2", target: "t2" }), false);
|
|
});
|
|
|
|
import { directSendBlocked } from "../mod/ovis-composer/view.js";
|
|
|
|
test("directSendBlocked: who must wait behind the queue", () => {
|
|
const queue = [{ state: "queued" }];
|
|
// an answer to a blocked agent goes ahead of the queue
|
|
assert.equal(directSendBlocked({ draining: false, mode: "auto", status: "blocked", queue }), false);
|
|
// an idle agent with a queue: the new message waits at the end
|
|
assert.equal(directSendBlocked({ draining: false, mode: "auto", status: "idle", queue }), true);
|
|
assert.equal(directSendBlocked({ draining: false, mode: "auto", status: "done", queue }), true);
|
|
// Ctrl+Enter is the person's own order
|
|
assert.equal(directSendBlocked({ draining: false, mode: "now", status: "idle", queue }), false);
|
|
// a message on the wire always goes first
|
|
assert.equal(directSendBlocked({ draining: true, mode: "now", status: "blocked", queue: [] }), true);
|
|
assert.equal(directSendBlocked({ draining: true, mode: "auto", status: "idle", queue }), true);
|
|
// nothing waits
|
|
assert.equal(directSendBlocked({ draining: false, mode: "auto", status: "idle", queue: [] }), false);
|
|
assert.equal(directSendBlocked({ draining: false, mode: "auto", status: "idle", queue: [{ state: "held" }] }), false);
|
|
});
|
|
|
|
import { blockTargetPx, shouldResize, isManualResize } from "../mod/ovis-composer/view.js";
|
|
|
|
const fit = (over = {}) => ({ contentHeight: 100, padding: 16, zoom: 1.2, userMin: 0, min: 120, max: 520, ...over });
|
|
|
|
test("blockTargetPx: the content (plus padding) in layout px, clamped to the layout's range", () => {
|
|
// (100 + 16) / 1.2 = 96.7 -> 97, under the minimum of 120
|
|
assert.equal(blockTargetPx(fit()), 120);
|
|
// (300 + 16) / 1.2 = 263.3 -> 264
|
|
assert.equal(blockTargetPx(fit({ contentHeight: 300 })), 264);
|
|
assert.equal(blockTargetPx(fit({ contentHeight: 5000 })), 520);
|
|
assert.equal(blockTargetPx(fit({ contentHeight: 300, zoom: 1 })), 316);
|
|
});
|
|
|
|
test("blockTargetPx: the height the person dragged to is kept, and content that needs more wins", () => {
|
|
assert.equal(blockTargetPx(fit({ contentHeight: 100, userMin: 300 })), 300);
|
|
assert.equal(blockTargetPx(fit({ contentHeight: 500, userMin: 300 })), 430);
|
|
assert.equal(blockTargetPx(fit({ contentHeight: 100, userMin: 9999 })), 520);
|
|
assert.equal(blockTargetPx(fit({ contentHeight: 100, userMin: 0 })), 120);
|
|
});
|
|
|
|
test("blockTargetPx: a zoom that is not a number counts as 1", () => {
|
|
assert.equal(blockTargetPx(fit({ contentHeight: 300, zoom: 0 })), 316);
|
|
assert.equal(blockTargetPx(fit({ contentHeight: 300, zoom: NaN })), 316);
|
|
});
|
|
|
|
test("shouldResize: only for a difference over 4 px", () => {
|
|
assert.equal(shouldResize(150, 154), false);
|
|
assert.equal(shouldResize(150, 155), true);
|
|
assert.equal(shouldResize(150, 145), true);
|
|
assert.equal(shouldResize(150, 146), false);
|
|
assert.equal(shouldResize(null, 150), false);
|
|
assert.equal(shouldResize(150, undefined), false);
|
|
});
|
|
|
|
test("isManualResize: a height nobody ordered is the person's drag", () => {
|
|
assert.equal(isManualResize({ reportedPx: 200, orderedPx: 200 }), false);
|
|
assert.equal(isManualResize({ reportedPx: 202, orderedPx: 200 }), false);
|
|
assert.equal(isManualResize({ reportedPx: 260, orderedPx: 200 }), true);
|
|
assert.equal(isManualResize({ reportedPx: 100, orderedPx: 200 }), true);
|
|
// nothing was ordered yet: the first size is the layout's, not a drag
|
|
assert.equal(isManualResize({ reportedPx: 150, orderedPx: null }), false);
|
|
assert.equal(isManualResize({ reportedPx: NaN, orderedPx: 200 }), false);
|
|
});
|
|
|
|
import { luminance, fieldBackground } from "../mod/ovis-composer/view.js";
|
|
|
|
test("luminance: black is darker than grey is darker than white; alpha and rubbish are tolerated", () => {
|
|
assert.ok(luminance("#000000") < luminance("#808080"));
|
|
assert.ok(luminance("#808080") < luminance("#ffffff"));
|
|
assert.equal(luminance("#000000ff"), luminance("#000000"));
|
|
assert.equal(luminance("#fff"), luminance("#ffffff"));
|
|
assert.equal(luminance("red"), null);
|
|
assert.equal(luminance(undefined), null);
|
|
});
|
|
|
|
test("fieldBackground: the darkest color the theme has, darker than the panel", () => {
|
|
const theme = { popover: "#2a2c31", background: "#101114", canvas: "#16171a", raised: "#202226", chrome: "#1b1c20" };
|
|
assert.equal(fieldBackground(theme, theme.popover), "#101114");
|
|
// a theme where the background is lighter than another color: that one wins
|
|
assert.equal(fieldBackground({ ...theme, background: "#3a3c41", canvas: "#0c0d0f" }, theme.popover), "#0c0d0f");
|
|
// nothing valid: the panel's own color
|
|
assert.equal(fieldBackground({}, "#2a2c31"), "#2a2c31");
|
|
assert.equal(fieldBackground({ background: "nope" }, "#2a2c31"), "#2a2c31");
|
|
});
|