swarm ui: a command menu above an agent's message box
This commit is contained in:
parent
49719842b0
commit
fc650f6af3
1 changed files with 478 additions and 12 deletions
100
frontend/packages/swarm-ui/test/command-menu.test.mjs
Normal file
100
frontend/packages/swarm-ui/test/command-menu.test.mjs
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
// The command menu's matching, completion and keys. Run by `npm test`, which
|
||||
// imports the `.ts` module as it is.
|
||||
import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
import {
|
||||
completion,
|
||||
enterSends,
|
||||
matchCommands,
|
||||
menuQuery,
|
||||
moveSelection,
|
||||
splitName,
|
||||
} from "../src/agent/terminal/command-menu.ts";
|
||||
|
||||
const cmd = (name, kind = "command", description = "") => ({
|
||||
name,
|
||||
kind,
|
||||
description,
|
||||
});
|
||||
|
||||
test("the menu is wanted only while the text is one slash word", () => {
|
||||
assert.equal(menuQuery("/"), "");
|
||||
assert.equal(menuQuery("/comp"), "comp");
|
||||
assert.equal(menuQuery("/Base:PR"), "base:pr");
|
||||
assert.equal(menuQuery("hello /comp"), null);
|
||||
assert.equal(menuQuery("/compact now"), null);
|
||||
assert.equal(menuQuery("/compact "), null);
|
||||
assert.equal(menuQuery("//x"), null);
|
||||
assert.equal(menuQuery(""), null);
|
||||
});
|
||||
|
||||
test("prefix matches come first, then contains, then description", () => {
|
||||
const all = [
|
||||
cmd("recompact"),
|
||||
cmd("compact"),
|
||||
cmd("other", "command", "will compact the thing"),
|
||||
cmd("combine"),
|
||||
];
|
||||
assert.deepEqual(
|
||||
matchCommands(all, "com").map((c) => c.name),
|
||||
["combine", "compact", "recompact", "other"],
|
||||
);
|
||||
});
|
||||
|
||||
test("commands sort before skills within a rank, then by name", () => {
|
||||
const all = [
|
||||
cmd("zeta", "command"),
|
||||
cmd("alpha", "skill"),
|
||||
cmd("beta", "command"),
|
||||
];
|
||||
assert.deepEqual(
|
||||
matchCommands(all, "").map((c) => c.name),
|
||||
["beta", "zeta", "alpha"],
|
||||
);
|
||||
});
|
||||
|
||||
test("nothing matches a query nothing contains", () => {
|
||||
assert.deepEqual(matchCommands([cmd("compact")], "zzz"), []);
|
||||
});
|
||||
|
||||
test("taking a command leaves the command and a space", () => {
|
||||
assert.equal(completion(cmd("compact")), "/compact ");
|
||||
assert.equal(completion(cmd("base:pr-review", "skill")), "/base:pr-review ");
|
||||
});
|
||||
|
||||
test("the name splits around the matched part, case-insensitively", () => {
|
||||
assert.deepEqual(splitName("compact", "mpa"), {
|
||||
before: "co",
|
||||
hit: "mpa",
|
||||
after: "ct",
|
||||
});
|
||||
assert.deepEqual(splitName("Compact", "COM"), {
|
||||
before: "",
|
||||
hit: "Com",
|
||||
after: "pact",
|
||||
});
|
||||
assert.deepEqual(splitName("compact", ""), {
|
||||
before: "compact",
|
||||
hit: "",
|
||||
after: "",
|
||||
});
|
||||
assert.deepEqual(splitName("compact", "x"), {
|
||||
before: "compact",
|
||||
hit: "",
|
||||
after: "",
|
||||
});
|
||||
});
|
||||
|
||||
test("the arrow keys wrap around the list", () => {
|
||||
assert.equal(moveSelection(0, 3, "ArrowDown"), 1);
|
||||
assert.equal(moveSelection(2, 3, "ArrowDown"), 0);
|
||||
assert.equal(moveSelection(0, 3, "ArrowUp"), 2);
|
||||
assert.equal(moveSelection(1, 3, "ArrowUp"), 0);
|
||||
assert.equal(moveSelection(0, 0, "ArrowDown"), 0);
|
||||
});
|
||||
|
||||
test("Enter sends once the selected command is already typed in full", () => {
|
||||
assert.equal(enterSends("/compact", cmd("compact")), true);
|
||||
assert.equal(enterSends("/comp", cmd("compact")), false);
|
||||
assert.equal(enterSends("/", cmd("compact")), false);
|
||||
});
|
||||
Loading…
Reference in a new issue