Files
hermes-agent/apps/desktop/src/lib/renderer-loop-pause.test.ts
T
hermes-seaeye[bot] 01512ca000 fmt(js): npm run fix on merge (#86631)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-08-15 03:31:07 +00:00

32 lines
1.2 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from 'vitest'
import { installRendererAnimationPauseState, RENDERER_ANIMATIONS_PAUSED_ATTRIBUTE } from './renderer-loop-pause'
describe('installRendererAnimationPauseState', () => {
afterEach(() => {
document.documentElement.removeAttribute(RENDERER_ANIMATIONS_PAUSED_ATTRIBUTE)
vi.restoreAllMocks()
})
it('pauses on blur, resumes on focus, and cleans up its root state', () => {
let focused = true
vi.spyOn(document, 'hasFocus').mockImplementation(() => focused)
const dispose = installRendererAnimationPauseState()
expect(document.documentElement.hasAttribute(RENDERER_ANIMATIONS_PAUSED_ATTRIBUTE)).toBe(false)
focused = false
window.dispatchEvent(new Event('blur'))
expect(document.documentElement.hasAttribute(RENDERER_ANIMATIONS_PAUSED_ATTRIBUTE)).toBe(true)
focused = true
window.dispatchEvent(new Event('focus'))
expect(document.documentElement.hasAttribute(RENDERER_ANIMATIONS_PAUSED_ATTRIBUTE)).toBe(false)
focused = false
window.dispatchEvent(new Event('blur'))
dispose()
expect(document.documentElement.hasAttribute(RENDERER_ANIMATIONS_PAUSED_ATTRIBUTE)).toBe(false)
})
})