30 lines
1.7 KiB
JavaScript
30 lines
1.7 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {fitWindow,resizeWindow,windowResizeEdges} from '../packages/ui-react/dist/windowGeometry.js';
|
|
const bounds={width:1200,height:800}, r={left:200,top:100,width:600,height:400};
|
|
test('all resize edges preserve the opposite anchor and remain within the viewport',()=>{
|
|
for(const edge of windowResizeEdges) for(const dx of [-2000,-25,25,2000]) for(const dy of [-2000,-25,25,2000]){
|
|
const v=resizeWindow(r,edge,dx,dy,bounds);
|
|
assert.ok(v.width>=320&&v.height>=200);assert.ok(v.left>=8&&v.top>=8&&v.left+v.width<=1192&&v.top+v.height<=792);
|
|
if(edge.includes('w'))assert.equal(v.left+v.width,r.left+r.width);else assert.equal(v.left,r.left);
|
|
if(edge.includes('n'))assert.equal(v.top+v.height,r.top+r.height);else assert.equal(v.top,r.top);
|
|
}
|
|
});
|
|
test('viewport shrink retains reachable header and fits small screens',()=>{
|
|
const v=fitWindow({...r,left:1100,top:750},{width:280,height:180});
|
|
assert.deepEqual(v,{left:8,top:8,width:264,height:164});
|
|
assert.deepEqual(fitWindow(r,bounds),r);
|
|
});
|
|
|
|
test('custom tool minimum applies to restored geometry and every resize edge',()=>{
|
|
const minimum={width:380,height:280};
|
|
const restored=fitWindow({...r,width:320,height:200},bounds,minimum);
|
|
assert.equal(restored.width,380);assert.equal(restored.height,280);
|
|
for(const edge of windowResizeEdges)for(const delta of [-3000,3000]){
|
|
const resized=resizeWindow(r,edge,delta,delta,bounds,minimum);
|
|
assert.ok(resized.width>=380&&resized.height>=280);
|
|
}
|
|
assert.deepEqual(fitWindow(r,{width:280,height:180},minimum),{left:8,top:8,width:264,height:164});
|
|
const tiny=fitWindow(r,{width:10,height:10},minimum);assert.equal(tiny.width,1);assert.equal(tiny.height,1);
|
|
});
|