Skip to content

Commit ae6cdfc

Browse files
committed
test: update isCompletionActive tests for timestamp-based visibility check
- Update tests to use lastVisibleTime property in mock sessions - Replace try/catch test logic with timestamp-based assertions - Test both recent timestamp (returns true) and old timestamp (returns false) scenarios
1 parent a155f08 commit ae6cdfc

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ describe('AmazonQInlineCompletionItemProvider', function () {
153153
mockSessionManager.getActiveSession.returns({
154154
displayed: false,
155155
suggestions: [{ isInlineEdit: false }],
156+
lastVisibleTime: 0,
156157
})
157158

158159
const result = await provider.isCompletionActive()
@@ -165,6 +166,7 @@ describe('AmazonQInlineCompletionItemProvider', function () {
165166
mockSessionManager.getActiveSession.returns({
166167
displayed: true,
167168
suggestions: [{ isInlineEdit: true }],
169+
lastVisibleTime: performance.now(),
168170
})
169171

170172
const result = await provider.isCompletionActive()
@@ -174,9 +176,11 @@ describe('AmazonQInlineCompletionItemProvider', function () {
174176
})
175177

176178
it('should return true when VS Code command executes successfully', async function () {
179+
const currentTime = performance.now()
177180
mockSessionManager.getActiveSession.returns({
178181
displayed: true,
179182
suggestions: [{ isInlineEdit: false }],
183+
lastVisibleTime: currentTime, // Recent timestamp
180184
})
181185
mockVscodeCommands.resolves()
182186

@@ -188,11 +192,13 @@ describe('AmazonQInlineCompletionItemProvider', function () {
188192
})
189193

190194
it('should return false when VS Code command fails', async function () {
195+
const oldTime = performance.now() - 100 // Old timestamp (>50ms ago)
191196
mockSessionManager.getActiveSession.returns({
192197
displayed: true,
193198
suggestions: [{ isInlineEdit: false }],
199+
lastVisibleTime: oldTime,
194200
})
195-
mockVscodeCommands.rejects(new Error('Command failed'))
201+
mockVscodeCommands.resolves() // Command doesn't fail, but timestamp is old
196202

197203
const result = await provider.isCompletionActive()
198204

0 commit comments

Comments
 (0)