// @vitest-environment jsdom import { afterEach, describe, expect, it, vi } from 'vitest'; import { emitMakelorePlaybackProgress, MAKELORE_PLAYBACK_PROGRESS_EVENT, } from '@/lib/makelore-runtime/progress-events'; afterEach(() => { delete window.__MAKELORE_OFFLINE_PLAYER__; vi.restoreAllMocks(); }); describe('offline player playback progress events', () => { it('publishes action-level and completion state only in the offline player', () => { const listener = vi.fn(); window.addEventListener(MAKELORE_PLAYBACK_PROGRESS_EVENT, listener); const detail = { sceneId: 'scene-2', sceneOrder: 2, actionIndex: 4, completed: true, }; emitMakelorePlaybackProgress(detail); expect(listener).not.toHaveBeenCalled(); window.__MAKELORE_OFFLINE_PLAYER__ = true; emitMakelorePlaybackProgress(detail); expect(listener).toHaveBeenCalledOnce(); expect((listener.mock.calls[0]![0] as CustomEvent).detail).toEqual(detail); window.removeEventListener(MAKELORE_PLAYBACK_PROGRESS_EVENT, listener); }); });