import assert from 'node:assert/strict'; import test from 'node:test'; import { createWindowControls, type NativeWindow } from '../src/windowControls.ts'; test('window controls call the injected window and never throw', async () => { const calls: string[] = []; const failing = () => Promise.reject(new Error('no window')); const win: NativeWindow = { minimize: async () => { calls.push('minimize'); }, toggleMaximize: failing, close: async () => { calls.push('close'); }, startResizeDragging: async direction => { calls.push(`resize:${direction}`); }, isMaximized: async () => true, onResized: async () => () => {}, }; const invoked: unknown[] = []; const controls = createWindowControls(async (command, args) => { invoked.push([command, args]); }, () => win); await controls.minimize(); await controls.toggleMaximize(); await controls.close(); await controls.startResize('SouthEast'); await controls.systemMenu(10, 20); let maximized: boolean | null = null; await controls.onMaximizedChange(value => { maximized = value; }); await Promise.resolve(); assert.deepEqual(calls, ['minimize', 'close', 'resize:SouthEast']); assert.deepEqual(invoked, [['window_system_menu', { x: 10, y: 20 }]]); assert.equal(maximized, true); });