// 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); });