hermes-agent/apps/desktop/electron/main-window-lifecycle.test.ts
nousbot-eng 74fc222f17
fmt(js): npm run fix on merge (#65912)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-07-16 19:57:39 +00:00

72 lines
1.6 KiB
TypeScript

import assert from 'node:assert/strict'
import { test } from 'vitest'
import { ensureMainWindow } from './main-window-lifecycle'
test('recreates a destroyed primary window without focusing it', () => {
const destroyedWindow = {
isDestroyed: () => true
}
let createCalls = 0
let focusCalls = 0
ensureMainWindow(destroyedWindow, {
isReady: true,
createWindow: () => {
createCalls += 1
},
focusWindow: () => {
focusCalls += 1
}
})
assert.equal(createCalls, 1)
assert.equal(focusCalls, 0)
})
test('waits for app readiness before recreating a primary window', () => {
let createCalls = 0
ensureMainWindow(null, {
isReady: false,
createWindow: () => {
createCalls += 1
},
focusWindow: () => assert.fail('missing window must not be focused')
})
assert.equal(createCalls, 0)
})
test('focuses a live primary window for a normal second launch', () => {
const liveWindow = {
isDestroyed: () => false
}
let focusedWindow = null
ensureMainWindow(liveWindow, {
isReady: true,
createWindow: () => assert.fail('live window must not be replaced'),
focusWindow: window => {
focusedWindow = window
}
})
assert.equal(focusedWindow, liveWindow)
})
test('leaves live-window focus to deep-link delivery', () => {
const liveWindow = {
isDestroyed: () => false
}
ensureMainWindow(liveWindow, {
isReady: true,
createWindow: () => assert.fail('live window must not be replaced'),
focusWindow: () => assert.fail('deep-link delivery owns focus'),
focusExisting: false
})
})