A popover hung from its anchor and ran off the foot of the window when the anchor sat low. It now goes over the anchor when it fits neither way better below, and otherwise takes the roomier side with its height cut so it scrolls inside itself; the placement is a pure function with a test, and the box places itself again when its content changes size. The ssh popover showed three long paragraphs above its switch: the explainer and the host-key text now sit in a folded how it works section, and the warning and the switch stay visible. Its sections can no longer give the popover a sideways scroll.
49 lines
1.6 KiB
JavaScript
49 lines
1.6 KiB
JavaScript
// 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,
|
|
});
|
|
});
|