Skip to content

Commit 116057a

Browse files
committed
add tests for fileClicked Actions
1 parent 8877704 commit 116057a

File tree

1 file changed

+84
-3
lines changed

1 file changed

+84
-3
lines changed

packages/core/src/test/amazonqFeatureDev/controllers/chat/controller.test.ts

Lines changed: 84 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import * as path from 'path'
99
import sinon from 'sinon'
1010
import { waitUntil } from '../../../../shared/utilities/timeoutUtils'
1111
import { ControllerSetup, createController, createSession } from '../../utils'
12-
import { FollowUpTypes, createUri } from '../../../../amazonqFeatureDev/types'
12+
import { CurrentWsFolders, FollowUpTypes, createUri } from '../../../../amazonqFeatureDev/types'
1313
import { Session } from '../../../../amazonqFeatureDev/session/session'
1414
import { Prompter } from '../../../../shared/ui/prompter'
1515
import { assertTelemetry, toFile } from '../../../testUtil'
1616
import { SelectedFolderNotInWorkspaceFolderError } from '../../../../amazonqFeatureDev/errors'
17-
import { PrepareRefinementState } from '../../../../amazonqFeatureDev/session/sessionState'
17+
import { CodeGenState, PrepareRefinementState } from '../../../../amazonqFeatureDev/session/sessionState'
1818
import { FeatureDevClient } from '../../../../amazonqFeatureDev/client/featureDev'
1919

20+
let mockGetCodeGeneration: sinon.SinonStub
2021
describe('Controller', () => {
2122
const tabID = '123'
2223
const conversationID = '456'
@@ -41,7 +42,7 @@ describe('Controller', () => {
4142
describe('openDiff', async () => {
4243
async function openDiff(filePath: string, deleted = false) {
4344
const executeDiff = sinon.stub(vscode.commands, 'executeCommand').returns(Promise.resolve(undefined))
44-
controllerSetup.emitters.openDiff.fire({ tabID, filePath, deleted })
45+
controllerSetup.emitters.openDiff.fire({ tabID, conversationID, filePath, deleted })
4546

4647
// Wait until the controller has time to process the event
4748
await waitUntil(() => {
@@ -242,4 +243,84 @@ describe('Controller', () => {
242243
assertTelemetry('amazonq_endChat', { amazonqConversationId: conversationID, result: 'Succeeded' })
243244
})
244245
})
246+
247+
describe('fileClicked', () => {
248+
const filePath = 'myfile.js'
249+
async function createCodeGenState() {
250+
mockGetCodeGeneration = sinon.stub().resolves({ codeGenerationStatus: { status: 'Complete' } })
251+
252+
const workspaceFolders = [controllerSetup.workspaceFolder] as CurrentWsFolders
253+
const testConfig = {
254+
conversationId: conversationID,
255+
proxyClient: {
256+
createConversation: () => sinon.stub(),
257+
createUploadUrl: () => sinon.stub(),
258+
generatePlan: () => sinon.stub(),
259+
startCodeGeneration: () => sinon.stub(),
260+
getCodeGeneration: () => mockGetCodeGeneration(),
261+
exportResultArchive: () => sinon.stub(),
262+
} as unknown as FeatureDevClient,
263+
sourceRoots: [''],
264+
uploadId: uploadID,
265+
workspaceFolders,
266+
}
267+
const testApproach = 'test-approach'
268+
269+
const codeGenState = new CodeGenState(
270+
testConfig,
271+
testApproach,
272+
[
273+
{
274+
zipFilePath: 'myfile.js',
275+
relativePath: 'myfile.js',
276+
fileContent: '',
277+
rejected: false,
278+
virtualMemoryUri: '' as unknown as vscode.Uri,
279+
workspaceFolder: controllerSetup.workspaceFolder,
280+
},
281+
],
282+
[],
283+
[],
284+
tabID,
285+
0
286+
)
287+
const newSession = await createSession({
288+
messenger: controllerSetup.messenger,
289+
sessionState: codeGenState,
290+
conversationID,
291+
tabID,
292+
uploadID,
293+
})
294+
return newSession
295+
}
296+
async function fileClicked(getSessionStub: sinon.SinonStub<[tabID: string], Promise<Session>>, action: string) {
297+
controllerSetup.emitters.fileClicked.fire({
298+
tabID,
299+
conversationID,
300+
filePath,
301+
action,
302+
})
303+
304+
// Wait until the controller has time to process the event
305+
await waitUntil(() => {
306+
return Promise.resolve(getSessionStub.callCount > 0)
307+
}, {})
308+
return getSessionStub.getCall(0).returnValue
309+
}
310+
it('This test case verifies that when a customer clicks on the "Reject File" button, the state of the file is updated correctly to "rejected: true".', async () => {
311+
const session = await createCodeGenState()
312+
const getSessionStub = sinon.stub(controllerSetup.sessionStorage, 'getSession').resolves(session)
313+
314+
const rejectFile = await fileClicked(getSessionStub, 'reject-change')
315+
assert.strictEqual(rejectFile.state.filePaths?.find(i => i.relativePath === filePath)?.rejected, true)
316+
})
317+
it('This test case verifies that when a customer clicks on the "Reject File" button and then clicks on the "Revert Reject File" button the state of the file is updated correctly to "rejected: false".', async () => {
318+
const session = await createCodeGenState()
319+
const getSessionStub = sinon.stub(controllerSetup.sessionStorage, 'getSession').resolves(session)
320+
321+
await fileClicked(getSessionStub, 'reject-change')
322+
const revertRejection = await fileClicked(getSessionStub, 'revert-rejection')
323+
assert.strictEqual(revertRejection.state.filePaths?.find(i => i.relativePath === filePath)?.rejected, false)
324+
})
325+
})
245326
})

0 commit comments

Comments
 (0)