@@ -11,7 +11,15 @@ import * as crossFile from '../../../codewhisperer/util/supplementalContext/cros
11
11
import { createMockTextEditor } from '../testUtil'
12
12
import { CodeWhispererUserGroupSettings } from '../../../codewhisperer/util/userGroupUtil'
13
13
import { UserGroup } from '../../../codewhisperer/models/constants'
14
- import { assertTabCount , closeAllEditors , createTestWorkspaceFolder , openATextEditorWithText } from '../../testUtil'
14
+ import {
15
+ assertTabCount ,
16
+ closeAllEditors ,
17
+ createTestWorkspaceFolder ,
18
+ openATextEditorWithText ,
19
+ shuffleList ,
20
+ } from '../../testUtil'
21
+ import { areEqual , normalize } from '../../../shared/utilities/pathUtils'
22
+ import * as path from 'path'
15
23
import { getMinVscodeVersion } from '../../../shared/vscode/env'
16
24
17
25
const userGroupSettings = CodeWhispererUserGroupSettings . instance
@@ -49,6 +57,71 @@ describe('crossFileContextUtil', function () {
49
57
} )
50
58
} )
51
59
60
+ describe ( 'getCrossFileCandidate' , function ( ) {
61
+ before ( async function ( ) {
62
+ this . timeout ( 60000 )
63
+ } )
64
+
65
+ beforeEach ( async function ( ) {
66
+ tempFolder = ( await createTestWorkspaceFolder ( ) ) . uri . fsPath
67
+ } )
68
+
69
+ afterEach ( async function ( ) {
70
+ await closeAllEditors ( )
71
+ } )
72
+
73
+ it ( 'should return opened files, exclude test files and sorted ascendingly by file distance' , async function ( ) {
74
+ if ( ! shouldRunTheTest ( ) ) {
75
+ this . skip ( )
76
+ }
77
+
78
+ const targetFile = path . join ( 'src' , 'service' , 'microService' , 'CodeWhispererFileContextProvider.java' )
79
+ const fileWithDistance3 = path . join ( 'src' , 'service' , 'CodewhispererRecommendationService.java' )
80
+ const fileWithDistance5 = path . join ( 'src' , 'util' , 'CodeWhispererConstants.java' )
81
+ const fileWithDistance6 = path . join ( 'src' , 'ui' , 'popup' , 'CodeWhispererPopupManager.java' )
82
+ const fileWithDistance7 = path . join ( 'src' , 'ui' , 'popup' , 'components' , 'CodeWhispererPopup.java' )
83
+ const fileWithDistance8 = path . join (
84
+ 'src' ,
85
+ 'ui' ,
86
+ 'popup' ,
87
+ 'components' ,
88
+ 'actions' ,
89
+ 'AcceptRecommendationAction.java'
90
+ )
91
+ const testFile1 = path . join ( 'test' , 'service' , 'CodeWhispererFileContextProviderTest.java' )
92
+ const testFile2 = path . join ( 'test' , 'ui' , 'CodeWhispererPopupManagerTest.java' )
93
+
94
+ const expectedFilePaths = [
95
+ fileWithDistance3 ,
96
+ fileWithDistance5 ,
97
+ fileWithDistance6 ,
98
+ fileWithDistance7 ,
99
+ fileWithDistance8 ,
100
+ ]
101
+
102
+ const shuffledFilePaths = shuffleList ( expectedFilePaths )
103
+
104
+ for ( const filePath of shuffledFilePaths ) {
105
+ await openATextEditorWithText ( '' , filePath , tempFolder , { preview : false } )
106
+ }
107
+
108
+ await openATextEditorWithText ( '' , testFile1 , tempFolder , { preview : false } )
109
+ await openATextEditorWithText ( '' , testFile2 , tempFolder , { preview : false } )
110
+ const editor = await openATextEditorWithText ( '' , targetFile , tempFolder , { preview : false } )
111
+
112
+ await assertTabCount ( shuffledFilePaths . length + 3 )
113
+
114
+ const actual = await crossFile . getCrossFileCandidates ( editor )
115
+
116
+ assert . ok ( actual . length === 5 )
117
+ actual . forEach ( ( actualFile , index ) => {
118
+ const expectedFile = path . join ( tempFolder , expectedFilePaths [ index ] )
119
+ assert . strictEqual ( normalize ( expectedFile ) , normalize ( actualFile ) )
120
+ assert . ok ( areEqual ( tempFolder , actualFile , expectedFile ) )
121
+ } )
122
+ } )
123
+ } )
124
+
52
125
describe ( 'partial support - control group' , function ( ) {
53
126
before ( async function ( ) {
54
127
this . timeout ( 60000 )
0 commit comments