// @ts-nocheck import { test } from 'node:test'; import assert from 'node:assert/strict'; import { WindowsCommands } from '../src/commands/windows'; import { makeChromeMock } from './chrome-mock'; function makeWindowsChromeMock(windows) { const chrome = makeChromeMock(); chrome.windows = { getAll: async () => windows, remove: async () => {}, create: async () => ({ id: 99 }), }; return chrome; } test('windows.list prunes aliases for closed windows', async () => { globalThis.chrome = makeWindowsChromeMock([ { id: 1, focused: true, state: 'normal', tabs: [{ id: 10 }] }, { id: 2, focused: false, state: 'minimized', tabs: [] }, ]); globalThis.chrome.storage.local._store.windowAliases = { 1: 'main', 2: 'side', 999: 'closed', }; const commands = new WindowsCommands({ jobs: {} }); const result = await commands.commands['windows.list']({}); assert.deepEqual(result.map(w => [w.id, w.alias]), [[1, 'main'], [2, 'side']]); assert.deepEqual(globalThis.chrome.storage.local._store.windowAliases, { 1: 'main', 2: 'side' }); }); test('windows.rename prunes stale aliases before saving the new name', async () => { globalThis.chrome = makeWindowsChromeMock([ { id: 1, focused: true, state: 'normal', tabs: [] }, { id: 2, focused: false, state: 'normal', tabs: [] }, ]); globalThis.chrome.storage.local._store.windowAliases = { 1: 'main', 999: 'closed', }; const commands = new WindowsCommands({ jobs: {} }); await commands.commands['windows.rename']({ windowId: 2, name: 'work' }); assert.deepEqual(globalThis.chrome.storage.local._store.windowAliases, { 1: 'main', 2: 'work' }); }); test('windows.close removes the closed window alias immediately', async () => { let removed = null; globalThis.chrome = makeWindowsChromeMock([ { id: 1, focused: true, state: 'normal', tabs: [] }, { id: 2, focused: false, state: 'normal', tabs: [] }, ]); globalThis.chrome.windows.remove = async id => { removed = id; }; globalThis.chrome.storage.local._store.windowAliases = { 1: 'main', 2: 'side', 999: 'closed', }; const commands = new WindowsCommands({ jobs: {} }); await commands.commands['windows.close']({ windowId: 2 }); assert.equal(removed, 2); assert.deepEqual(globalThis.chrome.storage.local._store.windowAliases, { 1: 'main' }); });