mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
The mic opens a voice loop that listens, sends on end of speech, reads each completed reply and reopens the mic when the agent is idle. The phase reducer, pause options and voice-mode instruction move to the shared package. TTS gains per-message completion and pause/resume. The old tap-and-drag recorder, its strip and its CSS are removed.
97 lines
2.8 KiB
TypeScript
97 lines
2.8 KiB
TypeScript
import { describe, it, expect, beforeEach } from 'vitest'
|
|
import { renderHook, act } from '@testing-library/react'
|
|
import {
|
|
DEFAULT_VOICE_PAUSE_MS,
|
|
VOICE_PAUSE_STORAGE_KEY,
|
|
} from '@opencode-manager/shared/opencode'
|
|
import { useVoicePauseSetting } from './useVoicePauseSetting'
|
|
|
|
function readStoredPause(): string | null {
|
|
return window.localStorage.getItem(VOICE_PAUSE_STORAGE_KEY)
|
|
}
|
|
|
|
function dispatchStorageEvent(key: string): void {
|
|
window.dispatchEvent(new StorageEvent('storage', { key }))
|
|
}
|
|
|
|
describe('useVoicePauseSetting', () => {
|
|
beforeEach(() => {
|
|
window.localStorage.clear()
|
|
})
|
|
|
|
it('falls back to the default pause when storage holds nothing', () => {
|
|
const { result } = renderHook(() => useVoicePauseSetting())
|
|
|
|
expect(result.current.pauseMs).toBe(DEFAULT_VOICE_PAUSE_MS)
|
|
})
|
|
|
|
it('reads a valid stored pause', () => {
|
|
window.localStorage.setItem(VOICE_PAUSE_STORAGE_KEY, '2000')
|
|
|
|
const { result } = renderHook(() => useVoicePauseSetting())
|
|
|
|
expect(result.current.pauseMs).toBe(2000)
|
|
})
|
|
|
|
it('falls back to the default pause when the stored value is not an option', () => {
|
|
window.localStorage.setItem(VOICE_PAUSE_STORAGE_KEY, '1234')
|
|
|
|
const { result } = renderHook(() => useVoicePauseSetting())
|
|
|
|
expect(result.current.pauseMs).toBe(DEFAULT_VOICE_PAUSE_MS)
|
|
})
|
|
|
|
it('persists a selected pause and ignores values outside the options', () => {
|
|
const { result } = renderHook(() => useVoicePauseSetting())
|
|
|
|
act(() => {
|
|
result.current.setPauseMs(3000)
|
|
})
|
|
|
|
expect(result.current.pauseMs).toBe(3000)
|
|
expect(readStoredPause()).toBe('3000')
|
|
|
|
act(() => {
|
|
result.current.setPauseMs(1234)
|
|
})
|
|
|
|
expect(result.current.pauseMs).toBe(3000)
|
|
expect(readStoredPause()).toBe('3000')
|
|
})
|
|
|
|
it('propagates changes to every consumer mounted in the same tab', () => {
|
|
const first = renderHook(() => useVoicePauseSetting())
|
|
const second = renderHook(() => useVoicePauseSetting())
|
|
|
|
act(() => {
|
|
first.result.current.setPauseMs(1600)
|
|
})
|
|
|
|
expect(first.result.current.pauseMs).toBe(1600)
|
|
expect(second.result.current.pauseMs).toBe(1600)
|
|
})
|
|
|
|
it('follows changes written by another tab', () => {
|
|
const { result } = renderHook(() => useVoicePauseSetting())
|
|
|
|
act(() => {
|
|
window.localStorage.setItem(VOICE_PAUSE_STORAGE_KEY, '800')
|
|
dispatchStorageEvent(VOICE_PAUSE_STORAGE_KEY)
|
|
})
|
|
|
|
expect(result.current.pauseMs).toBe(800)
|
|
})
|
|
|
|
it('ignores storage events for unrelated keys', () => {
|
|
window.localStorage.setItem(VOICE_PAUSE_STORAGE_KEY, '800')
|
|
const { result } = renderHook(() => useVoicePauseSetting())
|
|
|
|
window.localStorage.setItem(VOICE_PAUSE_STORAGE_KEY, '3000')
|
|
act(() => {
|
|
dispatchStorageEvent('some-other-key')
|
|
})
|
|
|
|
expect(result.current.pauseMs).toBe(800)
|
|
})
|
|
})
|