// When a press or Escape closes a floating box: the rule `useDismiss` applies. // Run by `npm test`. import assert from "node:assert/strict"; import { test } from "node:test"; import { dialogsOverBox, escapeDismisses, pointerDismisses, } from "../../shared/src/use-dismiss.ts"; test("a press outside the box and every dialog closes it", () => { assert.equal(pointerDismisses(false, false), true); }); test("a press inside the box, or in a dialog over it, does not", () => { assert.equal(pointerDismisses(true, false), false); assert.equal(pointerDismisses(false, true), false); assert.equal(pointerDismisses(true, true), false); }); test("Escape closes the box unless a dialog it is not in is open", () => { assert.equal(escapeDismisses(false), true); assert.equal(escapeDismisses(true), false); }); test("a dialog the box is in is not over it", () => { const holding = { holdsBox: true }; const over = { holdsBox: false }; assert.deepEqual( dialogsOverBox([holding, over], (d) => d.holdsBox), [over], ); assert.deepEqual( dialogsOverBox([holding], (d) => d.holdsBox), [], ); }); test("a press in the dialog the box is in dismisses it", () => { const holding = { holdsBox: true }; const over = dialogsOverBox([holding], (d) => d.holdsBox); assert.equal(pointerDismisses(false, over.includes(holding)), true); });