// Where a table's filter popover sits. Run by `npm test`, which Node runs // with its built-in test runner and type stripping, so the `.ts` module is // imported as it is. import assert from "node:assert/strict"; import { test } from "node:test"; import { clampLeft, placeVertically, } from "../src/ui/table/popover-position.ts"; test("a popover near the right edge is pulled back on screen", () => { // 300 wide in a 1000 wide window: the right edge may reach 992. assert.equal(clampLeft(900, 300, 1000), 692); assert.equal(clampLeft(100, 300, 1000), 100); }); test("a popover never goes past the left edge", () => { assert.equal(clampLeft(5, 300, 1000), 8); assert.equal(clampLeft(50, 2000, 1000), 8); }); // A 600 tall window, a badge from 300 to 330, a gap of 4 and an edge of 8: // 258 is free under it and 288 over it. test("a popover that fits under its anchor goes there", () => { assert.deepEqual(placeVertically(300, 330, 200, 600, 4), { top: 334, maxHeight: 258, }); }); test("one that does not fit under goes over when there is more room there", () => { assert.deepEqual(placeVertically(300, 330, 280, 600, 4), { top: 16, maxHeight: 288, }); }); test("one taller than either side is cut to the roomier side and scrolls", () => { // Over the anchor: 288 free, so it is 288 tall and ends 4 above it. assert.deepEqual(placeVertically(300, 330, 900, 600, 4), { top: 8, maxHeight: 288, }); // Near the top there is more room under it: it stays there, cut short. assert.deepEqual(placeVertically(20, 50, 900, 600, 4), { top: 54, maxHeight: 538, }); });