Select mode picks agents from the list: the select button in the filter card, a press on an agent's icon, or a long press on a card starts it. In it a card toggles a tick instead of opening its details, and the card's own controls stop answering. A bar at the foot of the list has select all shown, clear, broadcast and done; Escape leaves the mode. Broadcast opens a dialog with the picked agents and a message box, sending through the existing broadcast endpoint; the composer's send and result parts are now shared with the swarm page's broadcast card. A full send shows a toast and ends select mode; a partial one keeps the result with a retry for the agents that failed.
76 lines
2.5 KiB
JavaScript
76 lines
2.5 KiB
JavaScript
// The agents page's select mode: the picks and the long press. Run by `npm test`.
|
|
import assert from "node:assert/strict";
|
|
import { test } from "node:test";
|
|
import {
|
|
pickedAll,
|
|
startedOn,
|
|
stillThere,
|
|
toggled,
|
|
} from "../src/pages/agents/selection.ts";
|
|
import {
|
|
LONG_PRESS_SLOP,
|
|
createLongPressFlag,
|
|
strayed,
|
|
} from "../src/agent/roster/long-press.ts";
|
|
|
|
test("starting on an agent picks it and keeps the earlier picks", () => {
|
|
assert.deepEqual(startedOn([], "iris"), ["iris"]);
|
|
assert.deepEqual(startedOn(["argus"], "iris"), ["argus", "iris"]);
|
|
});
|
|
|
|
test("starting on an agent already picked changes nothing", () => {
|
|
const picked = ["iris"];
|
|
assert.equal(startedOn(picked, "iris"), picked);
|
|
});
|
|
|
|
test("starting with no agent (the select button) picks nothing", () => {
|
|
assert.deepEqual(startedOn([], null), []);
|
|
});
|
|
|
|
test("a click flips the agent's pick", () => {
|
|
assert.deepEqual(toggled(["a"], "b"), ["a", "b"]);
|
|
assert.deepEqual(toggled(["a", "b"], "a"), ["b"]);
|
|
});
|
|
|
|
test("select all adds every shown agent once, after the earlier picks", () => {
|
|
assert.deepEqual(pickedAll(["b"], ["a", "b", "c"]), ["b", "a", "c"]);
|
|
assert.deepEqual(pickedAll([], []), []);
|
|
});
|
|
|
|
test("a pick whose agent left the roster drops out", () => {
|
|
assert.deepEqual(stillThere(["a", "gone", "b"], ["a", "b", "c"]), ["a", "b"]);
|
|
});
|
|
|
|
test("a press that moves past the slop is not a long press", () => {
|
|
const from = { x: 10, y: 10 };
|
|
assert.equal(strayed(from, { x: 10, y: 10 }), false);
|
|
assert.equal(strayed(from, { x: 10 + LONG_PRESS_SLOP, y: 10 }), false);
|
|
assert.equal(strayed(from, { x: 10 + LONG_PRESS_SLOP + 1, y: 10 }), true);
|
|
assert.equal(strayed(from, { x: 16, y: 16 }), true);
|
|
});
|
|
|
|
test("the click that closes a long press is ignored once", () => {
|
|
const flag = createLongPressFlag();
|
|
flag.pressed();
|
|
flag.fire();
|
|
assert.equal(flag.blocksContextMenu(), true);
|
|
assert.equal(flag.consumeClick(), true);
|
|
assert.equal(flag.consumeClick(), false);
|
|
});
|
|
|
|
test("a long press that ends with no click does not swallow the next tap", () => {
|
|
const flag = createLongPressFlag();
|
|
flag.pressed();
|
|
flag.fire();
|
|
// No click follows (the context menu opened instead). The next tap starts
|
|
// with a press, which clears the flag.
|
|
flag.pressed();
|
|
assert.equal(flag.consumeClick(), false);
|
|
});
|
|
|
|
test("a plain press and click is not a long one", () => {
|
|
const flag = createLongPressFlag();
|
|
flag.pressed();
|
|
assert.equal(flag.blocksContextMenu(), false);
|
|
assert.equal(flag.consumeClick(), false);
|
|
});
|