|
|
@@ -1,12 +1,9 @@
|
|
|
import { describe, test, expect, beforeEach, afterEach, vi } from 'vitest'
|
|
|
import { SttSdk } from '../../src/core/stt-sdk'
|
|
|
-import type { ISttManagerAdapter, IRtmManagerAdapter } from '../../src/types'
|
|
|
|
|
|
// 模拟现有应用的使用模式
|
|
|
describe('Integration Test - Existing Application Pattern', () => {
|
|
|
let sdk: SttSdk
|
|
|
- let sttManager: ISttManagerAdapter
|
|
|
- let rtmManager: IRtmManagerAdapter
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
// 模拟现有应用的初始化过程
|
|
|
@@ -16,20 +13,10 @@ describe('Integration Test - Existing Application Pattern', () => {
|
|
|
certificate: 'test-certificate',
|
|
|
logLevel: 'info',
|
|
|
})
|
|
|
-
|
|
|
- // 创建管理器实例(模拟现有应用的模式)
|
|
|
- sttManager = sdk.createSttManager()
|
|
|
- rtmManager = sdk.createRtmManager()
|
|
|
-
|
|
|
- // 模拟将管理器挂载到window对象(现有应用的做法)
|
|
|
- ;(globalThis as any).sttManager = sttManager
|
|
|
- ;(globalThis as any).rtmManager = rtmManager
|
|
|
})
|
|
|
|
|
|
afterEach(async () => {
|
|
|
await sdk.destroy()
|
|
|
- ;(globalThis as any).sttManager = undefined
|
|
|
- ;(globalThis as any).rtmManager = undefined
|
|
|
})
|
|
|
|
|
|
test('Should work with existing application initialization pattern', async () => {
|
|
|
@@ -38,6 +25,10 @@ describe('Integration Test - Existing Application Pattern', () => {
|
|
|
const channel = 'test-channel-456'
|
|
|
const userName = 'Test User'
|
|
|
|
|
|
+ // 创建管理器实例
|
|
|
+ const rtmManager = sdk.createRtmManager()
|
|
|
+ const sttManager = sdk.createSttManager(rtmManager)
|
|
|
+
|
|
|
// 初始化管理器(模拟现有应用的模式)
|
|
|
await sttManager.init({
|
|
|
userId,
|
|
|
@@ -45,12 +36,6 @@ describe('Integration Test - Existing Application Pattern', () => {
|
|
|
userName,
|
|
|
})
|
|
|
|
|
|
- await rtmManager.join({
|
|
|
- channel,
|
|
|
- userId,
|
|
|
- userName,
|
|
|
- })
|
|
|
-
|
|
|
// 验证管理器状态
|
|
|
expect(sttManager.isInitialized).toBe(true)
|
|
|
expect(sttManager.userId).toBe(userId)
|
|
|
@@ -63,18 +48,15 @@ describe('Integration Test - Existing Application Pattern', () => {
|
|
|
|
|
|
test('Should handle transcription lifecycle like existing application', async () => {
|
|
|
// 模拟现有应用的转录流程
|
|
|
+ const rtmManager = sdk.createRtmManager()
|
|
|
+ const sttManager = sdk.createSttManager(rtmManager)
|
|
|
+
|
|
|
await sttManager.init({
|
|
|
userId: 'test-user',
|
|
|
channel: 'test-channel',
|
|
|
userName: 'Test User',
|
|
|
})
|
|
|
|
|
|
- await rtmManager.join({
|
|
|
- channel: 'test-channel',
|
|
|
- userId: 'test-user',
|
|
|
- userName: 'Test User',
|
|
|
- })
|
|
|
-
|
|
|
// 开始转录(模拟现有应用的模式)
|
|
|
const languages = [
|
|
|
{ source: 'en', target: ['zh'] },
|
|
|
@@ -93,6 +75,9 @@ describe('Integration Test - Existing Application Pattern', () => {
|
|
|
})
|
|
|
|
|
|
test('Should handle RTM operations like existing application', async () => {
|
|
|
+ const rtmManager = sdk.createRtmManager()
|
|
|
+
|
|
|
+ // RTM管理器需要先加入频道
|
|
|
await rtmManager.join({
|
|
|
channel: 'test-channel',
|
|
|
userId: 'test-user',
|
|
|
@@ -122,6 +107,7 @@ describe('Integration Test - Existing Application Pattern', () => {
|
|
|
|
|
|
test('Should provide event system compatible with existing application', () => {
|
|
|
// 模拟现有应用的事件监听模式
|
|
|
+ const rtmManager = sdk.createRtmManager()
|
|
|
const sttDataChangedHandler = vi.fn()
|
|
|
const languagesChangedHandler = vi.fn()
|
|
|
const errorHandler = vi.fn()
|
|
|
@@ -149,18 +135,15 @@ describe('Integration Test - Existing Application Pattern', () => {
|
|
|
|
|
|
test('Should handle destruction like existing application', async () => {
|
|
|
// 模拟现有应用的销毁流程
|
|
|
+ const rtmManager = sdk.createRtmManager()
|
|
|
+ const sttManager = sdk.createSttManager(rtmManager)
|
|
|
+
|
|
|
await sttManager.init({
|
|
|
userId: 'test-user',
|
|
|
channel: 'test-channel',
|
|
|
userName: 'Test User',
|
|
|
})
|
|
|
|
|
|
- await rtmManager.join({
|
|
|
- channel: 'test-channel',
|
|
|
- userId: 'test-user',
|
|
|
- userName: 'Test User',
|
|
|
- })
|
|
|
-
|
|
|
// 销毁管理器(模拟现有应用的模式)
|
|
|
await sttManager.destroy()
|
|
|
await rtmManager.destroy()
|
|
|
@@ -172,6 +155,8 @@ describe('Integration Test - Existing Application Pattern', () => {
|
|
|
|
|
|
test('Should maintain property access patterns from existing application', () => {
|
|
|
// 模拟现有应用的属性访问模式
|
|
|
+ const rtmManager = sdk.createRtmManager()
|
|
|
+ const sttManager = sdk.createSttManager(rtmManager)
|
|
|
|
|
|
// 直接属性访问(如 window.sttManager.userId)
|
|
|
expect(typeof (sttManager as any).userId).toBe('string')
|
|
|
@@ -190,6 +175,8 @@ describe('Integration Test - Existing Application Pattern', () => {
|
|
|
|
|
|
test('Should handle error scenarios like existing application', async () => {
|
|
|
// 测试错误处理兼容性
|
|
|
+ const rtmManager = sdk.createRtmManager()
|
|
|
+ const sttManager = sdk.createSttManager(rtmManager)
|
|
|
|
|
|
// 未初始化时调用方法应该抛出错误
|
|
|
await expect(sttManager.startTranscription({ languages: [] })).rejects.toThrow()
|
|
|
@@ -203,12 +190,6 @@ describe('Integration Test - Existing Application Pattern', () => {
|
|
|
userName: 'Test User',
|
|
|
})
|
|
|
|
|
|
- await rtmManager.join({
|
|
|
- channel: 'test-channel',
|
|
|
- userId: 'test-user',
|
|
|
- userName: 'Test User',
|
|
|
- })
|
|
|
-
|
|
|
// 现在应该可以正常工作(需要提供有效的语言)
|
|
|
await expect(
|
|
|
sttManager.startTranscription({ languages: [{ source: 'en', target: ['zh'] }] })
|