@@ -236,4 +236,66 @@ describe('CursorUpdateManager', () => {
236236 // Verify the provider was called again
237237 assert . strictEqual ( provideStub . callCount , 1 , 'Update should be sent when position has changed' )
238238 } )
239+
240+ describe ( 'autotrigger state handling' , ( ) => {
241+ let codeSuggestionsStateStub : sinon . SinonStubbedInstance < any >
242+ let onDidChangeStateStub : sinon . SinonStub
243+ let mockDisposable : { dispose : sinon . SinonStub }
244+
245+ beforeEach ( ( ) => {
246+ // Mock the disposable returned by onDidChangeState
247+ mockDisposable = { dispose : sinon . stub ( ) }
248+ onDidChangeStateStub = sinon . stub ( ) . returns ( mockDisposable )
249+
250+ codeSuggestionsStateStub = {
251+ isSuggestionsEnabled : sinon . stub ( ) . returns ( true ) ,
252+ onDidChangeState : onDidChangeStateStub ,
253+ }
254+
255+ // Mock the CodeSuggestionsState import
256+ const CodeSuggestionsState = require ( 'aws-core-vscode/codewhisperer' )
257+ sinon . stub ( CodeSuggestionsState , 'CodeSuggestionsState' ) . value ( {
258+ instance : codeSuggestionsStateStub ,
259+ } )
260+ } )
261+
262+ it ( 'should not start timer when autotrigger is disabled' , async ( ) => {
263+ // Test the new behavior: timer doesn't start when autotrigger is disabled
264+ codeSuggestionsStateStub . isSuggestionsEnabled . returns ( false )
265+ sendRequestStub . resolves ( { } )
266+
267+ await cursorUpdateManager . start ( )
268+
269+ // Manager should be active but timer should not be started
270+ assert . strictEqual ( ( cursorUpdateManager as any ) . isActive , true )
271+ assert . ok ( ! setIntervalStub . called , 'Timer should NOT be started when autotrigger is disabled' )
272+ } )
273+
274+ it ( 'should start/stop timer when autotrigger state changes' , async ( ) => {
275+ // Start with autotrigger enabled
276+ codeSuggestionsStateStub . isSuggestionsEnabled . returns ( true )
277+ sendRequestStub . resolves ( { } )
278+ await cursorUpdateManager . start ( )
279+
280+ // Get the state change callback
281+ const stateChangeCallback = onDidChangeStateStub . firstCall . args [ 0 ]
282+
283+ // Reset stubs to test state changes
284+ setIntervalStub . resetHistory ( )
285+ clearIntervalStub . resetHistory ( )
286+
287+ // Simulate autotrigger being disabled
288+ stateChangeCallback ( false )
289+ assert . ok ( clearIntervalStub . called , 'Timer should be stopped when autotrigger is disabled' )
290+
291+ // Simulate autotrigger being enabled again
292+ stateChangeCallback ( true )
293+ assert . ok ( setIntervalStub . called , 'Timer should be started when autotrigger is re-enabled' )
294+ } )
295+
296+ it ( 'should dispose autotrigger state listener on dispose' , ( ) => {
297+ cursorUpdateManager . dispose ( )
298+ assert . ok ( mockDisposable . dispose . called , 'Autotrigger state listener should be disposed' )
299+ } )
300+ } )
239301} )
0 commit comments