@@ -3,6 +3,7 @@ import { PalabraClient } from '../PalabraClient';
33import type { TargetLangCode } from '../utils/target' ;
44import type { SourceLangCode } from '../utils/source' ;
55import { EVENT_START_TRANSLATION , EVENT_STOP_TRANSLATION } from '../transport/PalabraWebRtcTransport.model' ;
6+ import { PipelineConfigManager } from '~/config' ;
67
78// Mock MediaStreamTrack for tests
89class MockMediaStreamTrack {
@@ -140,6 +141,88 @@ describe('PalabraClient', () => {
140141 client = new PalabraClient ( baseConstructorData ) ;
141142 } ) ;
142143
144+ describe ( 'ConfigManager' , ( ) => {
145+ it ( 'should set value and get value with extensions' , ( ) => {
146+ const manager = new PipelineConfigManager ( { initialExtension : { testProp : 12 } } ) ;
147+
148+ const cl = new PalabraClient ( { ...baseConstructorData , configManager : manager } ) ;
149+ expect ( ( cl . getConfigManager ( ) ) . getValue ( 'testProp' ) ) . toBe ( 12 ) ;
150+
151+ ( cl . getConfigManager ( ) ) . setValue ( 'testProp' , 13 ) ;
152+ expect ( ( cl . getConfigManager ( ) ) . getValue ( 'testProp' ) ) . toBe ( 13 ) ;
153+
154+ manager . setValue ( 'testProp' , 14 ) ;
155+ expect ( ( cl . getConfigManager ( ) ) . getValue ( 'testProp' ) ) . toBe ( 14 ) ;
156+ } ) ;
157+
158+ it ( 'should set value and get value without extensions' , ( ) => {
159+ const cl = new PalabraClient ( { ...baseConstructorData } ) ;
160+ expect ( ( cl . getConfigManager ( ) ) . getValue ( 'preprocessing.enable_vad' ) ) . toBe ( true ) ;
161+ } ) ;
162+ } ) ;
163+
164+ describe ( 'AudioContext' , ( ) => {
165+ it ( 'should not close AudioContext in stopTranslation' , async ( ) => {
166+ const closeAudioContextSpy = vi . spyOn ( client as unknown as { closeAudioContext : ( ) => void } , 'closeAudioContext' ) . mockImplementation ( ( ) => undefined ) ;
167+ await client . stopTranslation ( ) ;
168+ expect ( closeAudioContextSpy ) . not . toHaveBeenCalled ( ) ;
169+ } ) ;
170+
171+ it ( 'should not call close method on AudioContext in stopTranslation' , async ( ) => {
172+ const ctx = new AudioContext ( ) ;
173+ const closeAudioContextSpy = vi . spyOn ( ctx , 'close' ) . mockImplementation ( ( ) => undefined ) ;
174+ const localClient = new PalabraClient ( { ...baseConstructorData , audioContext : ctx } ) ;
175+ await localClient . stopTranslation ( ) ;
176+ expect ( closeAudioContextSpy ) . not . toHaveBeenCalled ( ) ;
177+ } ) ;
178+
179+ it ( 'should close AudioContext in cleanup' , async ( ) => {
180+ const closeAudioContextSpy = vi . spyOn ( client as unknown as { closeAudioContext : ( ) => void } , 'closeAudioContext' ) . mockImplementation ( ( ) => undefined ) ;
181+ await client . cleanup ( ) ;
182+ expect ( closeAudioContextSpy ) . toHaveBeenCalled ( ) ;
183+ } ) ;
184+
185+ it ( 'should ignore AudioContext creation when ignoreAudioContext is true and audioContext is provided' , async ( ) => {
186+ const ctx = new AudioContext ( ) ;
187+ const localClient = new PalabraClient ( { ...baseConstructorData , audioContext : ctx , ignoreAudioContext : true } ) ;
188+ // @ts -expect-error: audioContext is private
189+ expect ( localClient . audioContext ) . toBeUndefined ( ) ;
190+ } ) ;
191+
192+ it ( 'should create a new AudioContext when ignoreAudioContext is false and audioContext is not provided' , async ( ) => {
193+ const localClient = new PalabraClient ( { ...baseConstructorData , ignoreAudioContext : false } ) ;
194+ // @ts -expect-error: audioContext is private
195+ expect ( localClient . audioContext ) . toBeDefined ( ) ;
196+ } ) ;
197+
198+ it ( 'should use provided AudioContext' , async ( ) => {
199+ const ctx = new AudioContext ( ) ;
200+ // @ts -expect-error field for test
201+ ctx . field = 'test' ;
202+
203+ const localClient = new PalabraClient ( { ...baseConstructorData , audioContext : ctx , ignoreAudioContext : false } ) ;
204+ // @ts -expect-error: audioContext is private
205+ expect ( localClient . audioContext ) . toBeDefined ( ) ;
206+ // @ts -expect-error: field for test
207+ expect ( localClient . audioContext . field ) . toBe ( 'test' ) ;
208+ } ) ;
209+
210+ it ( 'should create a new AudioContext when audioContext is not provided' , async ( ) => {
211+ const localClient = new PalabraClient ( baseConstructorData ) ;
212+ await localClient . startTranslation ( ) ;
213+ // @ts -expect-error: audioContext is private
214+ expect ( localClient . audioContext ) . toBeDefined ( ) ;
215+ } ) ;
216+ } ) ;
217+
218+ it ( 'should get api client' , ( ) => {
219+ expect ( client . getApiClient ( ) ) . toBeDefined ( ) ;
220+ } ) ;
221+
222+ it ( 'should get config manager' , ( ) => {
223+ expect ( client . getConfigManager ( ) ) . toBeDefined ( ) ;
224+ } ) ;
225+
143226 it ( 'should create a new PalabraClient' , ( ) => {
144227 expect ( client ) . toBeDefined ( ) ;
145228 } ) ;
0 commit comments