import test from 'node:test' import assert from 'node:assert/strict' import { assistantFloatingRect, assistantMoveWindow } from '../../src/utils/assistant-window.js' test('a fallback rectangle is fully visible when no existing panel can be measured', () => { assert.deepEqual(assistantFloatingRect(null, { width: 1440, height: 900 }), { left: 270, top: 90, width: 900, height: 720 }) }) test('detaching retains the measured docked position and size instead of centering or enlarging', () => { const docked = { left: 744, top: 88, width: 680, height: 776 } assert.deepEqual(assistantFloatingRect(docked, { width: 1440, height: 900 }), docked) const short = { left: 584, top: 16, width: 680, height: 298 } assert.deepEqual(assistantFloatingRect(short, { width: 1280, height: 350 }), short) }) test('dragging clamps all window edges to the viewport', () => { const viewport = { width: 1440, height: 900 }, rect = assistantFloatingRect(null, viewport) assert.deepEqual(assistantMoveWindow(rect, { x: -9999, y: -9999 }, viewport), { ...rect, left: 16, top: 16 }) assert.deepEqual(assistantMoveWindow(rect, { x: 9999, y: 9999 }, viewport), { ...rect, left: 524, top: 164 }) }) test('viewport changes fit the restored floating window without losing its location unnecessarily', () => { const rect = { left: 450, top: 150, width: 900, height: 720 } assert.deepEqual(assistantFloatingRect(rect, { width: 1440, height: 900 }), rect) const fitted = assistantFloatingRect(rect, { width: 820, height: 600 }) assert.deepEqual(fitted, { left: 16, top: 16, width: 788, height: 568 }) const narrow = assistantFloatingRect(rect, { width: 320, height: 240 }) assert.ok(narrow.left + narrow.width <= 320 && narrow.top + narrow.height <= 240) }) test('geometry helpers do not change the original window when switching modes', () => { const rect = { left: 80, top: 100, width: 900, height: 600 }, before = { ...rect } assistantMoveWindow(rect, { x: 40, y: 10 }, { width: 1440, height: 900 }) assert.deepEqual(rect, before) })