@@ -62,13 +62,16 @@ class TestVitalLensController extends VitalLensControllerBase {
6262 methodHandler : MethodHandler ,
6363 bufferedResultsConsumer : BufferedResultsConsumer | null ,
6464 onPredict : ( result : VitalLensResult ) => Promise < void > ,
65- onNoFace : ( ) => Promise < void >
65+ onNoFace : ( ) => Promise < void > ,
66+ onFaceDetected ?: ( face : any ) => void
6667 ) : IStreamProcessor {
6768 return {
6869 init : jest . fn ( ) ,
6970 start : jest . fn ( ) ,
7071 isProcessing : jest . fn ( ) ,
7172 stop : jest . fn ( ) ,
73+ setInferenceEnabled : jest . fn ( ) ,
74+ reset : jest . fn ( ) ,
7275 } ;
7376 }
7477}
@@ -176,6 +179,10 @@ describe('VitalLensControllerBase', () => {
176179 mockStreamProcessor = {
177180 isProcessing : jest . fn ( ) . mockReturnValue ( false ) ,
178181 start : jest . fn ( ) ,
182+ setInferenceEnabled : jest . fn ( ) ,
183+ reset : jest . fn ( ) ,
184+ stop : jest . fn ( ) ,
185+ init : jest . fn ( ) ,
179186 } ;
180187 controller [ 'streamProcessor' ] = mockStreamProcessor as IStreamProcessor ;
181188
@@ -188,6 +195,10 @@ describe('VitalLensControllerBase', () => {
188195 mockStreamProcessor = {
189196 isProcessing : jest . fn ( ) . mockReturnValue ( true ) ,
190197 start : jest . fn ( ) ,
198+ setInferenceEnabled : jest . fn ( ) ,
199+ reset : jest . fn ( ) ,
200+ stop : jest . fn ( ) ,
201+ init : jest . fn ( ) ,
191202 } ;
192203 controller [ 'streamProcessor' ] = mockStreamProcessor as IStreamProcessor ;
193204
@@ -201,7 +212,11 @@ describe('VitalLensControllerBase', () => {
201212 // Create a mock stream processor that is processing
202213 mockStreamProcessor = {
203214 isProcessing : jest . fn ( ) . mockReturnValue ( true ) ,
215+ start : jest . fn ( ) ,
216+ setInferenceEnabled : jest . fn ( ) ,
217+ reset : jest . fn ( ) ,
204218 stop : jest . fn ( ) ,
219+ init : jest . fn ( ) ,
205220 } ;
206221 controller [ 'streamProcessor' ] = mockStreamProcessor as IStreamProcessor ;
207222 controller [ 'vitalsEstimateManager' ] . resetAll = jest . fn ( ) ;
@@ -215,7 +230,11 @@ describe('VitalLensControllerBase', () => {
215230 // Create a mock stream processor that is not processing
216231 mockStreamProcessor = {
217232 isProcessing : jest . fn ( ) . mockReturnValue ( false ) ,
233+ start : jest . fn ( ) ,
234+ setInferenceEnabled : jest . fn ( ) ,
235+ reset : jest . fn ( ) ,
218236 stop : jest . fn ( ) ,
237+ init : jest . fn ( ) ,
219238 } ;
220239 controller [ 'streamProcessor' ] = mockStreamProcessor as IStreamProcessor ;
221240 controller [ 'vitalsEstimateManager' ] . resetAll = jest . fn ( ) ;
@@ -232,7 +251,12 @@ describe('VitalLensControllerBase', () => {
232251 test ( 'should stop the streamProcessor (if exists) and reset vitalsEstimateManager' , ( ) => {
233252 // Create a mock stream processor that is processing
234253 mockStreamProcessor = {
254+ isProcessing : jest . fn ( ) . mockReturnValue ( true ) ,
235255 stop : jest . fn ( ) ,
256+ start : jest . fn ( ) ,
257+ setInferenceEnabled : jest . fn ( ) ,
258+ reset : jest . fn ( ) ,
259+ init : jest . fn ( ) ,
236260 } ;
237261 controller [ 'streamProcessor' ] = mockStreamProcessor as IStreamProcessor ;
238262 controller [ 'vitalsEstimateManager' ] . resetAll = jest . fn ( ) ;
@@ -448,4 +472,46 @@ describe('VitalLensControllerBase', () => {
448472 expect ( controller [ 'isProcessing' ] ( ) ) . toBe ( false ) ;
449473 } ) ;
450474 } ) ;
475+
476+ describe ( 'setInferenceEnabled' , ( ) => {
477+ test ( 'should call setInferenceEnabled on streamProcessor if it exists' , ( ) => {
478+ const mockProc = {
479+ isProcessing : jest . fn ( ) ,
480+ start : jest . fn ( ) ,
481+ stop : jest . fn ( ) ,
482+ init : jest . fn ( ) ,
483+ setInferenceEnabled : jest . fn ( ) ,
484+ reset : jest . fn ( ) ,
485+ } ;
486+ controller [ 'streamProcessor' ] = mockProc as unknown as IStreamProcessor ;
487+
488+ controller . setInferenceEnabled ( true ) ;
489+ expect ( mockProc . setInferenceEnabled ) . toHaveBeenCalledWith ( true ) ;
490+ } ) ;
491+ } ) ;
492+
493+ describe ( 'reset' , ( ) => {
494+ test ( 'should call reset on streamProcessor if it exists' , ( ) => {
495+ const mockProc = {
496+ isProcessing : jest . fn ( ) ,
497+ start : jest . fn ( ) ,
498+ stop : jest . fn ( ) ,
499+ init : jest . fn ( ) ,
500+ setInferenceEnabled : jest . fn ( ) ,
501+ reset : jest . fn ( ) ,
502+ } ;
503+ controller [ 'streamProcessor' ] = mockProc as unknown as IStreamProcessor ;
504+
505+ controller . reset ( ) ;
506+ expect ( mockProc . reset ) . toHaveBeenCalled ( ) ;
507+ } ) ;
508+
509+ test ( 'should cleanup bufferManager if streamProcessor does not exist' , ( ) => {
510+ controller [ 'streamProcessor' ] = null ;
511+ controller [ 'bufferManager' ] . cleanup = jest . fn ( ) ;
512+
513+ controller . reset ( ) ;
514+ expect ( controller [ 'bufferManager' ] . cleanup ) . toHaveBeenCalled ( ) ;
515+ } ) ;
516+ } ) ;
451517} ) ;
0 commit comments