@@ -327,4 +327,78 @@ describe("DiffViewProvider", () => {
327327 ) . toBeUndefined ( )
328328 } )
329329 } )
330+
331+ describe ( "saveChanges method" , ( ) => {
332+ it ( "should apply configured delay before getting diagnostics" , async ( ) => {
333+ // Mock the configuration to return a specific delay
334+ const mockGetConfiguration = vi . fn ( ) . mockReturnValue ( {
335+ get : vi . fn ( ) . mockImplementation ( ( key : string , defaultValue : any ) => {
336+ if ( key === "diagnosticsDelayAfterSave" ) {
337+ return 1000 // 1 second delay
338+ }
339+ return defaultValue
340+ } )
341+ } )
342+
343+ // Save original implementation
344+ const originalGetConfiguration = vscode . workspace . getConfiguration
345+
346+ // Replace with our mock
347+ Object . defineProperty ( vscode . workspace , "getConfiguration" , {
348+ value : mockGetConfiguration ,
349+ configurable : true
350+ } )
351+
352+ // Mock setTimeout to track if it was called
353+ const originalSetTimeout = global . setTimeout
354+ const mockSetTimeout = vi . fn ( ) . mockImplementation ( ( callback , delay ) => {
355+ // Execute the callback immediately for testing
356+ callback ( )
357+ return 1 // Return a timeout ID
358+ } )
359+ global . setTimeout = mockSetTimeout as any
360+
361+ // Setup the diffViewProvider for testing
362+ ; ( diffViewProvider as any ) . relPath = "test.txt"
363+ ; ( diffViewProvider as any ) . newContent = "Test content"
364+ ; ( diffViewProvider as any ) . originalContent = "Original content"
365+ ; ( diffViewProvider as any ) . activeDiffEditor = {
366+ document : {
367+ uri : { fsPath : `${ mockCwd } /test.txt` } ,
368+ getText : vi . fn ( ) . mockReturnValue ( "Test content" ) ,
369+ lineCount : 1 ,
370+ } ,
371+ isDirty : false ,
372+ save : vi . fn ( ) . mockResolvedValue ( undefined ) ,
373+ }
374+
375+ // Mock getDiagnostics to track when it's called
376+ const mockGetDiagnostics = vi . fn ( ) . mockReturnValue ( [ ] )
377+ const originalGetDiagnostics = vscode . languages . getDiagnostics
378+ vscode . languages . getDiagnostics = mockGetDiagnostics
379+
380+ // Mock showTextDocument
381+ vi . mocked ( vscode . window . showTextDocument ) . mockResolvedValue ( { } as any )
382+
383+ // Execute saveChanges
384+ await diffViewProvider . saveChanges ( )
385+
386+ // Verify that getConfiguration was called with "roo-cline"
387+ expect ( mockGetConfiguration ) . toHaveBeenCalledWith ( "roo-cline" )
388+
389+ // Verify that setTimeout was called with the correct delay
390+ expect ( mockSetTimeout ) . toHaveBeenCalledWith ( expect . any ( Function ) , 1000 )
391+
392+ // Verify that getDiagnostics was called after the delay
393+ expect ( mockGetDiagnostics ) . toHaveBeenCalled ( )
394+
395+ // Restore original implementations
396+ Object . defineProperty ( vscode . workspace , "getConfiguration" , {
397+ value : originalGetConfiguration ,
398+ configurable : true
399+ } )
400+ global . setTimeout = originalSetTimeout
401+ vscode . languages . getDiagnostics = originalGetDiagnostics
402+ } )
403+ } )
330404} )
0 commit comments