import { describe, expect, it } from 'vitest'; import { clampPopupY, screenMargin } from '../../src/ui/widgets/Popup'; describe('screenMargin', () => { it('is a tenth of the canvas, so it grows with the screen', () => { expect(screenMargin(800)).toBe(80); expect(screenMargin(1440)).toBe(144); }); }); describe('clampPopupY', () => { it('leaves a popup that already sits inside the band where it is', () => { expect(clampPopupY(300, 200, 1000)).toBe(300); }); it('keeps the same gap below as above when the anchor sits low', () => { // 1000 tall canvas, 100 margin: a 700 tall popup asked for y=500 ends at 200, not at 300. const y = clampPopupY(500, 700, 1000); expect(y).toBe(200); expect(1000 - (y + 700)).toBe(100); // the gap below matches the 100 above }); it('leaves a popup anchored high where it is, the gap above is no minimum', () => { // The + menu hangs off a button near the top; pushing it down to the margin would tear it away. expect(clampPopupY(10, 200, 1000)).toBe(10); expect(clampPopupY(0, 200, 1000)).toBe(0); }); it('still keeps the gap below when a tall popup has to be shifted up', () => { expect(clampPopupY(400, 900, 1000)).toBe(0); }); it('gives up rather than shifting a popup taller than the canvas off screen', () => { expect(clampPopupY(400, 1200, 1000)).toBe(0); }); });