Skip to content

Commit 803511c

Browse files
committed
fix unit test
1 parent 49c3d21 commit 803511c

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

packages/amazonq/test/unit/amazonq/apps/inline/completion.test.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ import { AmazonQInlineCompletionItemProvider, InlineCompletionManager } from '..
2020
import { RecommendationService } from '../../../../../src/app/inline/recommendationService'
2121
import { SessionManager } from '../../../../../src/app/inline/sessionManager'
2222
import { createMockDocument, createMockTextEditor, getTestWindow, installFakeClock } from 'aws-core-vscode/test'
23-
import { noInlineSuggestionsMsg, ReferenceHoverProvider, ReferenceLogViewProvider } from 'aws-core-vscode/codewhisperer'
23+
import {
24+
noInlineSuggestionsMsg,
25+
ReferenceHoverProvider,
26+
ReferenceLogViewProvider,
27+
vsCodeState,
28+
} from 'aws-core-vscode/codewhisperer'
2429
import { InlineGeneratingMessage } from '../../../../../src/app/inline/inlineGeneratingMessage'
2530
import { LineTracker } from '../../../../../src/app/inline/stateTracker/lineTracker'
2631
import { InlineTutorialAnnotation } from '../../../../../src/app/inline/tutorials/inlineTutorialAnnotation'
@@ -41,7 +46,7 @@ describe('InlineCompletionManager', () => {
4146
let hoverReferenceStub: sinon.SinonStub
4247
const mockDocument = createMockDocument()
4348
const mockEditor = createMockTextEditor()
44-
const mockPosition = { line: 0, character: 0 } as Position
49+
const mockPosition = new Position(0, 0)
4550
const mockContext = { triggerKind: 1, selectedCompletionInfo: undefined }
4651
const mockToken = { isCancellationRequested: false } as CancellationToken
4752
const fakeReferences = [
@@ -61,6 +66,11 @@ describe('InlineCompletionManager', () => {
6166
insertText: 'test',
6267
references: fakeReferences,
6368
},
69+
{
70+
itemId: 'test-item2',
71+
insertText: 'import math\ndef two_sum(nums, target):\n',
72+
references: fakeReferences,
73+
},
6474
]
6575

6676
beforeEach(() => {
@@ -240,10 +250,11 @@ describe('InlineCompletionManager', () => {
240250
const activeStateController = new InlineGeneratingMessage(lineTracker)
241251
inlineTutorialAnnotation = new InlineTutorialAnnotation(lineTracker, mockSessionManager)
242252
recommendationService = new RecommendationService(mockSessionManager, activeStateController)
243-
253+
vsCodeState.isRecommendationsActive = false
244254
mockSessionManager = {
245255
getActiveSession: getActiveSessionStub,
246256
getActiveRecommendation: getActiveRecommendationStub,
257+
clear: () => {},
247258
} as unknown as SessionManager
248259

249260
getActiveSessionStub.returns({
@@ -257,7 +268,7 @@ describe('InlineCompletionManager', () => {
257268
getAllRecommendationsStub.resolves()
258269
sandbox.stub(window, 'activeTextEditor').value(createMockTextEditor())
259270
}),
260-
it('should call recommendation service to get new suggestions for new sessions', async () => {
271+
it('should call recommendation service to get new suggestions(matching typeahead) for new sessions', async () => {
261272
provider = new AmazonQInlineCompletionItemProvider(
262273
languageClient,
263274
recommendationService,
@@ -271,7 +282,7 @@ describe('InlineCompletionManager', () => {
271282
mockToken
272283
)
273284
assert(getAllRecommendationsStub.calledOnce)
274-
assert.deepStrictEqual(items, mockSuggestions)
285+
assert.deepStrictEqual(items, [mockSuggestions[1]])
275286
}),
276287
it('should handle reference if there is any', async () => {
277288
provider = new AmazonQInlineCompletionItemProvider(
@@ -319,10 +330,13 @@ describe('InlineCompletionManager', () => {
319330
mockSessionManager,
320331
inlineTutorialAnnotation
321332
)
322-
const expectedText = 'this is my text'
333+
const expectedText = `${mockSuggestions[1].insertText}this is my text`
323334
getActiveRecommendationStub.returns([
324335
{
325-
insertText: { kind: 'snippet', value: 'this is my text' } satisfies StringValue,
336+
insertText: {
337+
kind: 'snippet',
338+
value: `${mockSuggestions[1].insertText}this is my text`,
339+
} satisfies StringValue,
326340
itemId: 'itemId',
327341
},
328342
])
@@ -379,7 +393,7 @@ describe('InlineCompletionManager', () => {
379393
const p2 = provider.provideInlineCompletionItems(mockDocument, mockPosition, mockContext, mockToken)
380394
const p3 = provider.provideInlineCompletionItems(
381395
mockDocument,
382-
new Position(2, 2),
396+
new Position(1, 26),
383397
mockContext,
384398
mockToken
385399
)
@@ -394,7 +408,7 @@ describe('InlineCompletionManager', () => {
394408
const r3 = await p3
395409

396410
// calls the function with the latest provided args.
397-
assert.deepStrictEqual((r3 as InlineCompletionItem[])[0].range?.end, new Position(2, 2))
411+
assert.deepStrictEqual((r3 as InlineCompletionItem[])[0].range?.end, new Position(1, 26))
398412
})
399413
})
400414
})

0 commit comments

Comments
 (0)