2
2
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
3
* SPDX-License-Identifier: Apache-2.0
4
4
*/
5
-
6
5
import assert from 'assert'
7
6
import * as codewhispererClient from 'aws-core-vscode/codewhisperer'
8
7
import * as EditorContext from 'aws-core-vscode/codewhisperer'
9
- import { createMockTextEditor , createMockClientRequest , resetCodeWhispererGlobalVariables } from 'aws-core-vscode/test'
8
+ import {
9
+ createMockTextEditor ,
10
+ createMockClientRequest ,
11
+ resetCodeWhispererGlobalVariables ,
12
+ openATextEditorWithText ,
13
+ createTestWorkspaceFolder ,
14
+ closeAllEditors ,
15
+ } from 'aws-core-vscode/test'
10
16
import { globals } from 'aws-core-vscode/shared'
11
17
import { GenerateCompletionsRequest } from 'aws-core-vscode/codewhisperer'
12
18
13
19
describe ( 'editorContext' , function ( ) {
14
20
let telemetryEnabledDefault : boolean
21
+ let tempFolder : string
15
22
16
23
beforeEach ( async function ( ) {
17
24
await resetCodeWhispererGlobalVariables ( )
@@ -66,15 +73,19 @@ describe('editorContext', function () {
66
73
assert . strictEqual ( actual , expected )
67
74
} )
68
75
69
- it ( 'Should return expected filename for a long filename' , function ( ) {
76
+ it ( 'Should return expected filename for a long filename' , async function ( ) {
70
77
const editor = createMockTextEditor ( '' , 'a' . repeat ( 1500 ) , 'python' , 1 , 17 )
71
78
const actual = EditorContext . getFileName ( editor )
72
79
const expected = 'a' . repeat ( 1024 )
73
80
assert . strictEqual ( actual , expected )
74
81
} )
75
82
} )
76
83
77
- describe ( 'getfileNameForRequest' , function ( ) {
84
+ describe ( 'getFileRelativePath' , function ( ) {
85
+ this . beforeEach ( async function ( ) {
86
+ tempFolder = ( await createTestWorkspaceFolder ( ) ) . uri . fsPath
87
+ } )
88
+
78
89
it ( 'Should return a new filename with correct extension given a .ipynb file' , function ( ) {
79
90
const languageToExtension = new Map < string , string > ( [
80
91
[ 'python' , 'py' ] ,
@@ -86,11 +97,22 @@ describe('editorContext', function () {
86
97
87
98
languageToExtension . forEach ( ( extension , language ) => {
88
99
const editor = createMockTextEditor ( '' , 'test.ipynb' , language , 1 , 17 )
89
- const actual = EditorContext . getFileNameForRequest ( editor )
100
+ const actual = EditorContext . getFileRelativePath ( editor )
90
101
const expected = 'test.' + extension
91
102
assert . strictEqual ( actual , expected )
92
103
} )
93
104
} )
105
+
106
+ it ( 'Should return relative path' , async function ( ) {
107
+ const editor = await openATextEditorWithText ( 'tttt' , 'test.py' , tempFolder )
108
+ const actual = EditorContext . getFileRelativePath ( editor )
109
+ const expected = 'test.py'
110
+ assert . strictEqual ( actual , expected )
111
+ } )
112
+
113
+ afterEach ( async function ( ) {
114
+ await closeAllEditors ( )
115
+ } )
94
116
} )
95
117
96
118
describe ( 'validateRequest' , function ( ) {
0 commit comments