diff --git a/apps/app/tests/unit/annotations.frameBox.test.ts b/apps/app/tests/unit/annotations.frameBox.test.ts index c7559e30..d55905dc 100644 --- a/apps/app/tests/unit/annotations.frameBox.test.ts +++ b/apps/app/tests/unit/annotations.frameBox.test.ts @@ -57,6 +57,17 @@ describe('frameBox', () => { }) }) + it('defaultBox lands inside the intersection when visible exceeds bounds', () => { + const visible = { x: 0, y: 0, w: 900, h: 675 } + const bounds = { x: 0, y: 0, w: 600, h: 500 } + expect(defaultBox({ x: 590, y: 490 }, visible, 4 / 3, bounds)).toEqual({ + x: 300, + y: 275, + w: 300, + h: 225, + }) + }) + it('drawnBox with a small drag returns the fallback', () => { const fallback = { x: 1, y: 2, w: 3, h: 4 } const box = drawnBox( @@ -133,6 +144,45 @@ describe('frameBox', () => { expect(box.w / box.h).toBe(2) }) + it('resizeBox keepRatio follows the height on a height-driven corner drag', () => { + expect( + resizeBox( + resize({ handle: 'se', delta: { x: 10, y: 100 }, keepRatio: true }), + ), + ).toEqual({ x: 100, y: 100, w: 400, h: 200 }) + }) + + it('resizeBox keepRatio grows to min keeping the ratio', () => { + expect( + resizeBox( + resize({ + handle: 'e', + delta: { x: -1000, y: 0 }, + min: 30, + keepRatio: true, + }), + ), + ).toEqual({ x: 100, y: 135, w: 60, h: 30 }) + }) + + it('resizeBox on nw stops at the bounds and at min', () => { + expect( + resizeBox(resize({ handle: 'nw', delta: { x: -1000, y: -1000 } })), + ).toEqual({ x: 0, y: 0, w: 300, h: 200 }) + expect( + resizeBox(resize({ handle: 'nw', delta: { x: 1000, y: 1000 } })), + ).toEqual({ x: 280, y: 180, w: 20, h: 20 }) + expect( + resizeBox( + resize({ + handle: 'nw', + delta: { x: -1000, y: -1000 }, + keepRatio: true, + }), + ), + ).toEqual({ x: 0, y: 50, w: 300, h: 150 }) + }) + it('moveBox clamps into the bounds and never resizes', () => { expect( moveBox({ x: 10, y: 10, w: 50, h: 40 }, { x: -100, y: 1000 }, BOUNDS), @@ -148,7 +198,7 @@ describe('frameBox', () => { expect(ratioLabel(980, 140, 'fr')).toBe('7:1') }) - it('ratioLabel falls back to a decimal for extreme ratios', () => { + it('ratioLabel finds extreme ratios in the integer search', () => { expect(ratioLabel(100, 1, 'fr')).toBe('100:1') expect(ratioLabel(1, 100, 'fr')).toBe('1:100') }) @@ -167,6 +217,24 @@ describe('frameBox', () => { expect(shownHandles(40, 200)).toEqual(['nw', 'ne', 'e', 'se', 'sw', 'w']) }) + it('toViewBox rounds the far edges down, not to nearest', () => { + expect(toViewBox({ x: 1, y: 2, w: 10.009, h: 5.006 })).toEqual({ + min_x: 1, + min_y: 2, + width: 10, + height: 5, + }) + }) + + it('toViewBox ignores float noise on the hundredth grid', () => { + expect(toViewBox({ x: 0.07, y: 0.1 + 0.2, w: 1, h: 1 })).toEqual({ + min_x: 0.07, + min_y: 0.3, + width: 1, + height: 1, + }) + }) + it('toViewBox rounds inward to 0.01', () => { expect(toViewBox({ x: 0.001, y: 0.004, w: 10, h: 5 })).toEqual({ min_x: 0.01,