feat: 新增MAC微信发送消息 文字转语音 功能

This commit is contained in:
Wxw-Gu
2026-08-17 18:16:14 +08:00
parent a52da455c3
commit 15811c820c
48 changed files with 7240 additions and 22 deletions
@@ -0,0 +1,69 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
const mocks = vi.hoisted(() => ({
keyGet: vi.fn(),
keySave: vi.fn(),
keyClear: vi.fn(),
loadSettings: vi.fn(),
updateSettings: vi.fn()
}))
vi.mock('../../src/main/ai-provider-key-store', () => ({
AIProviderKeyStore: class {
get = mocks.keyGet
save = mocks.keySave
clear = mocks.keyClear
}
}))
vi.mock('../../src/main/services/settings-store', () => ({
loadSettings: mocks.loadSettings,
updateSettings: mocks.updateSettings
}))
import { TextToSpeechSettingsService } from '../../src/main/services/text-to-speech-settings-service'
describe('TextToSpeechSettingsService', () => {
beforeEach(() => {
mocks.keyGet.mockReset().mockReturnValue({
success: true,
available: true,
key: undefined
})
mocks.keySave.mockReset().mockReturnValue({ success: true })
mocks.keyClear.mockReset().mockReturnValue({ success: true })
mocks.loadSettings.mockReset().mockReturnValue({ ttsSelectedVoiceId: 'demo-warm-female' })
mocks.updateSettings.mockReset()
})
it('returns an empty dynamic voice list without exposing a missing key', () => {
const result = new TextToSpeechSettingsService().get()
expect(result.success).toBe(true)
expect(result.settings.hasApiKey).toBe(false)
expect(result.settings.selectedVoiceId).toBe('')
expect(result.voices).toEqual([])
})
it('stores the key securely and persists the selected voice', () => {
mocks.keyGet.mockReturnValue({ success: true, available: true, key: 'stored' })
const result = new TextToSpeechSettingsService().save({
apiKey: ' fish-key ',
selectedVoiceId: 'demo-calm-male'
})
expect(mocks.keySave).toHaveBeenCalledWith('fish-audio-tts', 'fish-key')
expect(mocks.updateSettings).toHaveBeenCalledWith({
ttsSelectedVoiceId: 'demo-calm-male'
})
expect(result.settings.hasApiKey).toBe(true)
})
it('persists a remotely loaded voice id without local demo validation', () => {
const result = new TextToSpeechSettingsService().save({
selectedVoiceId: 'fish-model-id'
})
expect(result.success).toBe(true)
expect(mocks.updateSettings).toHaveBeenCalledWith({
ttsSelectedVoiceId: 'fish-model-id'
})
})
})