@@ -33,9 +33,11 @@ describe('keyStrokeHandler', function () {
33
33
} )
34
34
describe ( 'processKeyStroke' , async function ( ) {
35
35
let invokeSpy : sinon . SinonStub
36
+ let startTimerSpy : sinon . SinonStub
36
37
let mockClient : codewhispererSdkClient . DefaultCodeWhispererClient
37
38
beforeEach ( function ( ) {
38
39
invokeSpy = sinon . stub ( KeyStrokeHandler . instance , 'invokeAutomatedTrigger' )
40
+ startTimerSpy = sinon . stub ( KeyStrokeHandler . instance , 'startIdleTimeTriggerTimer' )
39
41
sinon . spy ( RecommendationHandler . instance , 'getRecommendations' )
40
42
mockClient = new codewhispererSdkClient . DefaultCodeWhispererClient ( )
41
43
resetCodeWhispererGlobalVariables ( )
@@ -62,6 +64,7 @@ describe('keyStrokeHandler', function () {
62
64
const keyStrokeHandler = new KeyStrokeHandler ( )
63
65
await keyStrokeHandler . processKeyStroke ( mockEvent , mockEditor , mockClient , cfg )
64
66
assert . ok ( ! invokeSpy . called )
67
+ assert . ok ( ! startTimerSpy . called )
65
68
} )
66
69
67
70
it ( 'Should not call invokeAutomatedTrigger when changed text matches active recommendation prefix' , async function ( ) {
@@ -87,6 +90,7 @@ describe('keyStrokeHandler', function () {
87
90
)
88
91
await KeyStrokeHandler . instance . processKeyStroke ( mockEvent , mockEditor , mockClient , config )
89
92
assert . ok ( ! invokeSpy . called )
93
+ assert . ok ( ! startTimerSpy . called )
90
94
} )
91
95
92
96
it ( 'Should not call invokeAutomatedTrigger when doing delete or undo (empty changed text)' , async function ( ) {
@@ -98,23 +102,10 @@ describe('keyStrokeHandler', function () {
98
102
)
99
103
await KeyStrokeHandler . instance . processKeyStroke ( mockEvent , mockEditor , mockClient , config )
100
104
assert . ok ( ! invokeSpy . called )
101
- } )
102
-
103
- it ( 'Should not call invokeAutomatedTrigger if previous text input is within 2 seconds and it is not a specialcharacter trigger \n' , async function ( ) {
104
- KeyStrokeHandler . instance . keyStrokeCount = 14
105
- const mockEditor = createMockTextEditor ( )
106
- const mockEvent : vscode . TextDocumentChangeEvent = createTextDocumentChangeEvent (
107
- mockEditor . document ,
108
- new vscode . Range ( new vscode . Position ( 0 , 0 ) , new vscode . Position ( 0 , 1 ) ) ,
109
- 'a'
110
- )
111
- RecommendationHandler . instance . lastInvocationTime = performance . now ( ) - 1500
112
- await KeyStrokeHandler . instance . processKeyStroke ( mockEvent , mockEditor , mockClient , config )
113
- assert . ok ( ! invokeSpy . called )
105
+ assert . ok ( ! startTimerSpy . called )
114
106
} )
115
107
116
108
it ( 'Should call invokeAutomatedTrigger if previous text input is within 2 seconds but the new input is new line' , async function ( ) {
117
- KeyStrokeHandler . instance . keyStrokeCount = 14
118
109
const mockEditor = createMockTextEditor ( )
119
110
const mockEvent : vscode . TextDocumentChangeEvent = createTextDocumentChangeEvent (
120
111
mockEditor . document ,
@@ -127,7 +118,6 @@ describe('keyStrokeHandler', function () {
127
118
} )
128
119
129
120
it ( 'Should call invokeAutomatedTrigger if previous text input is within 2 seconds but the new input is a specialcharacter' , async function ( ) {
130
- KeyStrokeHandler . instance . keyStrokeCount = 14
131
121
const mockEditor = createMockTextEditor ( )
132
122
const mockEvent : vscode . TextDocumentChangeEvent = createTextDocumentChangeEvent (
133
123
mockEditor . document ,
@@ -200,31 +190,26 @@ describe('keyStrokeHandler', function () {
200
190
assert . ok ( ! invokeSpy . called )
201
191
} )
202
192
203
- it ( 'Should call invokeAutomatedTrigger with arg KeyStrokeCount when invocationContext.keyStrokeCount reaches threshold ' , async function ( ) {
193
+ it ( 'Should not start idle trigger timer when inputing special characters ' , async function ( ) {
204
194
const mockEditor = createMockTextEditor ( )
205
195
const mockEvent : vscode . TextDocumentChangeEvent = createTextDocumentChangeEvent (
206
196
mockEditor . document ,
207
197
new vscode . Range ( new vscode . Position ( 0 , 0 ) , new vscode . Position ( 0 , 1 ) ) ,
208
- 'a '
198
+ '( '
209
199
)
210
- KeyStrokeHandler . instance . keyStrokeCount = 15
211
200
await KeyStrokeHandler . instance . processKeyStroke ( mockEvent , mockEditor , mockClient , config )
212
- invokeSpy ( 'KeyStrokeCount' , mockEditor , mockClient )
213
- assert . ok ( invokeSpy . called )
201
+ assert . ok ( ! startTimerSpy . called )
214
202
} )
215
203
216
- it ( 'Should not call invokeAutomatedTrigger when user input is not special character and keyStrokeCount does not reach threshold, should increase invocationContext.keyStrokeCount by 1 ' , async function ( ) {
204
+ it ( 'Should start idle trigger timer when inputing non- special characters ' , async function ( ) {
217
205
const mockEditor = createMockTextEditor ( )
218
206
const mockEvent : vscode . TextDocumentChangeEvent = createTextDocumentChangeEvent (
219
207
mockEditor . document ,
220
208
new vscode . Range ( new vscode . Position ( 0 , 0 ) , new vscode . Position ( 0 , 1 ) ) ,
221
209
'a'
222
210
)
223
- RecommendationHandler . instance . lastInvocationTime = 0
224
- KeyStrokeHandler . instance . keyStrokeCount = 8
225
211
await KeyStrokeHandler . instance . processKeyStroke ( mockEvent , mockEditor , mockClient , config )
226
- assert . ok ( ! invokeSpy . called )
227
- assert . strictEqual ( KeyStrokeHandler . instance . keyStrokeCount , 9 )
212
+ assert . ok ( startTimerSpy . called )
228
213
} )
229
214
} )
230
215
@@ -250,15 +235,15 @@ describe('keyStrokeHandler', function () {
250
235
await keyStrokeHandler . invokeAutomatedTrigger ( 'Enter' , mockEditor , mockClient , config )
251
236
assert . ok ( getRecommendationsStub . calledOnce || oldGetRecommendationsStub . calledOnce )
252
237
} )
238
+ } )
253
239
254
- it ( 'should reset invocationContext.keyStrokeCount to 0' , async function ( ) {
255
- const mockEditor = createMockTextEditor ( )
256
- KeyStrokeHandler . instance . keyStrokeCount = 10
257
- sinon
258
- . stub ( RecommendationHandler . instance , 'getServerResponse' )
259
- . resolves ( [ { content : 'import math' } , { content : 'def two_sum(nums, target):' } ] )
260
- await KeyStrokeHandler . instance . invokeAutomatedTrigger ( 'Enter' , mockEditor , mockClient , config )
261
- assert . strictEqual ( KeyStrokeHandler . instance . keyStrokeCount , 0 )
240
+ describe ( 'shouldTriggerIdleTime' , function ( ) {
241
+ it ( 'should return false when inline is enabled and inline completion is in progress ' , function ( ) {
242
+ const keyStrokeHandler = new KeyStrokeHandler ( )
243
+ sinon . stub ( InlineCompletionService . instance , 'isPaginationRunning' ) . returns ( true )
244
+ sinon . stub ( InlineCompletion . instance , 'isPaginationRunning' ) . returns ( true )
245
+ const result = keyStrokeHandler . shouldTriggerIdleTime ( )
246
+ assert . strictEqual ( result , false )
262
247
} )
263
248
} )
264
249
0 commit comments