Skip to content

Commit a8c02b5

Browse files
committed
fix a test logic error
1 parent 878dfe8 commit a8c02b5

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

packages/amazonq/test/unit/lsp/chat/diffAnimation/diffAnimationController.test.ts

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ describe('DiffAnimationController', function () {
102102
totalDuration: 1000,
103103
})
104104

105-
sandbox.stub(VSCodeIntegration.prototype, 'showVSCodeDiff').resolves()
105+
// Mock VSCodeIntegration to call vscode.commands.executeCommand so tests can verify it
106+
sandbox.stub(VSCodeIntegration.prototype, 'showVSCodeDiff').callsFake(async () => {
107+
await (vscode.commands.executeCommand as sinon.SinonStub)('vscode.diff')
108+
})
106109
sandbox.stub(VSCodeIntegration.prototype, 'openFileInEditor').resolves()
107110
}
108111

@@ -152,12 +155,11 @@ describe('DiffAnimationController', function () {
152155
})
153156

154157
describe('animation data management', function () {
155-
it('should return undefined for non-existent file', function () {
156-
const result = controller.getAnimationData(testPaths.nonexistent)
157-
assert.strictEqual(result, undefined)
158-
})
158+
it('should handle animation data lifecycle', async function () {
159+
// Should return undefined for non-existent file
160+
assert.strictEqual(controller.getAnimationData(testPaths.nonexistent), undefined)
159161

160-
it('should return animation data after starting animation', async function () {
162+
// Should return animation data after starting animation
161163
setupFileOperationMocks('existing', testContent.original)
162164
await controller.startDiffAnimation(testPaths.existing, testContent.original, testContent.new)
163165

@@ -210,7 +212,13 @@ describe('DiffAnimationController', function () {
210212
it('should handle chat click parameter', async function () {
211213
setupFileOperationMocks('existing')
212214
await controller.startDiffAnimation(testPaths.existing, testContent.original, testContent.new, true)
213-
assert.ok(controller.getAnimationData(testPaths.existing))
215+
216+
// When isFromChatClick is true, it calls showVSCodeDiff and returns early
217+
// So no animation data should be stored
218+
assert.strictEqual(controller.getAnimationData(testPaths.existing), undefined)
219+
220+
// But vscode.commands.executeCommand should have been called
221+
assert.ok((vscode.commands.executeCommand as sinon.SinonStub).called)
214222
})
215223

216224
it('should handle file operation errors', async function () {
@@ -294,27 +302,18 @@ describe('DiffAnimationController', function () {
294302
})
295303

296304
describe('animation status queries', function () {
297-
it('should return false for non-existent file animation status', function () {
305+
it('should handle animation status queries', async function () {
306+
// Should return false for non-existent files
298307
assert.strictEqual(controller.isAnimating(testPaths.nonexistent), false)
299-
})
300-
301-
it('should return true for active animation', async function () {
302-
setupFileOperationMocks('existing', testContent.original)
303-
await controller.startDiffAnimation(testPaths.existing, testContent.original, testContent.new, false)
304-
305-
assert.strictEqual(controller.isAnimating(testPaths.existing), true)
306-
})
307-
308-
it('should return false for non-existent static diff status', function () {
309308
assert.strictEqual(controller.isShowingStaticDiff(testPaths.nonexistent), false)
310-
})
311309

312-
it('should return correct static diff status', async function () {
310+
// Should return correct status for active animation
313311
setupFileOperationMocks('existing', testContent.original)
314312
await controller.startDiffAnimation(testPaths.existing, testContent.original, testContent.new, false)
315313

316-
const result = controller.isShowingStaticDiff(testPaths.existing)
317-
assert.strictEqual(typeof result, 'boolean')
314+
assert.strictEqual(controller.isAnimating(testPaths.existing), true)
315+
const staticDiffResult = controller.isShowingStaticDiff(testPaths.existing)
316+
assert.strictEqual(typeof staticDiffResult, 'boolean')
318317
})
319318
})
320319

0 commit comments

Comments
 (0)