import assert from "node:assert/strict"; import {test} from "node:test"; import {computeFloatingPosition,movingToMenu} from "../packages/ui-core/dist/index.js"; test("menus stay beyond the maximum magnified edge, including narrow windows",()=>{ for(const width of [320,640,1400])for(const size of [25,42,88]){ const anchor={left:width-12-size,right:width-12,top:200,bottom:225,width:size,height:25}; const p=computeFloatingPosition({anchor,surfaceWidth:220,surfaceHeight:400,placement:"left-start",flip:false,viewportWidth:width,viewportHeight:600}); assert.ok(p.left+Math.min(220,p.maxWidth)<=anchor.left-8+1e-9); assert.ok(p.left>=8);assert.ok(p.top+Math.min(400,p.maxHeight)<=592); const mirror={...anchor,left:12,right:12+size}; const q=computeFloatingPosition({anchor:mirror,surfaceWidth:220,surfaceHeight:400,placement:"right-start",flip:false,viewportWidth:width,viewportHeight:600}); assert.ok(q.left>=mirror.right+8);assert.ok(q.left+Math.min(220,q.maxWidth)<=width-8); } }); test("intent triangle protects diagonal entry but never blocks deliberate vertical or reverse motion",()=>{ const s={left:200,right:450,top:100,bottom:500,width:250,height:400},o={x:490,y:200}; assert.equal(movingToMenu(o,o,{x:480,y:210},s),true); assert.equal(movingToMenu(o,o,{x:490,y:240},s),false); assert.equal(movingToMenu(o,{x:480,y:210},{x:485,y:220},s),false); assert.equal(movingToMenu(o,o,{x:480,y:600},s),false); assert.equal(movingToMenu({x:150,y:200},{x:150,y:200},{x:160,y:210},s),true); assert.equal(movingToMenu({x:300,y:550},{x:300,y:550},{x:310,y:540},s),true); });