@@ -9,14 +9,15 @@ import * as path from 'path'
9
9
import sinon from 'sinon'
10
10
import { waitUntil } from '../../../../shared/utilities/timeoutUtils'
11
11
import { ControllerSetup , createController , createSession } from '../../utils'
12
- import { FollowUpTypes , createUri } from '../../../../amazonqFeatureDev/types'
12
+ import { CurrentWsFolders , FollowUpTypes , createUri } from '../../../../amazonqFeatureDev/types'
13
13
import { Session } from '../../../../amazonqFeatureDev/session/session'
14
14
import { Prompter } from '../../../../shared/ui/prompter'
15
15
import { assertTelemetry , toFile } from '../../../testUtil'
16
16
import { SelectedFolderNotInWorkspaceFolderError } from '../../../../amazonqFeatureDev/errors'
17
- import { PrepareRefinementState } from '../../../../amazonqFeatureDev/session/sessionState'
17
+ import { CodeGenState , PrepareRefinementState } from '../../../../amazonqFeatureDev/session/sessionState'
18
18
import { FeatureDevClient } from '../../../../amazonqFeatureDev/client/featureDev'
19
19
20
+ let mockGetCodeGeneration : sinon . SinonStub
20
21
describe ( 'Controller' , ( ) => {
21
22
const tabID = '123'
22
23
const conversationID = '456'
@@ -41,7 +42,7 @@ describe('Controller', () => {
41
42
describe ( 'openDiff' , async ( ) => {
42
43
async function openDiff ( filePath : string , deleted = false ) {
43
44
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 } )
45
46
46
47
// Wait until the controller has time to process the event
47
48
await waitUntil ( ( ) => {
@@ -242,4 +243,84 @@ describe('Controller', () => {
242
243
assertTelemetry ( 'amazonq_endChat' , { amazonqConversationId : conversationID , result : 'Succeeded' } )
243
244
} )
244
245
} )
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
+ } )
245
326
} )
0 commit comments