Skip to content

Commit 0d506f1

Browse files
committed
fix: add inline test
1 parent 5d8706e commit 0d506f1

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"testE2E": "npm run testE2E -w packages/ --if-present",
3131
"test:ui:prepare": "./node_modules/.bin/extest get-vscode -s ~/.vscode-test-resources -n && extest get-chromedriver -s ~/.vscode-test-resources -n",
3232
"test:ui:install": "cd packages/amazonq && npm run package 2>&1 | grep -o 'VSIX Version: [^ ]*' | cut -d' ' -f3 | xargs -I{} bash -c 'cd ../../ && ./node_modules/.bin/extest install-vsix -f amazon-q-vscode-{}.vsix -e packages/amazonq/test/e2e_new/amazonq/resources -s ~/.vscode-test-resources'",
33-
"test:ui:run": "npm run testCompile && ./node_modules/.bin/extest run-tests -s ~/.vscode-test-resources -e packages/amazonq/test/e2e_new/amazonq/resources packages/amazonq/dist/test/e2e_new/amazonq/tests/*.js",
33+
"test:ui:run": "npm run testCompile && ./node_modules/.bin/extest run-tests -s ~/.vscode-test-resources -e packages/amazonq/test/e2e_new/amazonq/resources packages/amazonq/dist/test/e2e_new/amazonq/tests/*.test.js",
3434
"test:ui": "npm run test:ui:prepare && npm run test:ui:install && npm run test:ui:run",
3535
"testInteg": "npm run testInteg -w packages/ --if-present",
3636
"package": "npm run package -w packages/toolkit -w packages/amazonq",

packages/amazonq/test/e2e_new/amazonq/tests/inline.test.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import '../utils/setup'
66
import { Workbench, EditorView, InputBox, TextEditor, WebviewView, Key } from 'vscode-extension-tester'
77
import { testContext } from '../utils/testContext'
8-
import { pressKey, createNewTextFile, writeToTextEditor } from '../utils/generalUtils'
8+
import { createNewTextFile, writeToTextEditor, sleep } from '../utils/generalUtils'
99
import assert from 'assert'
1010

1111
describe('Amazon Q Inline Completion / Chat Functionality', function () {
@@ -20,25 +20,32 @@ describe('Amazon Q Inline Completion / Chat Functionality', function () {
2020
webviewView = testContext.webviewView
2121
await webviewView.switchBack()
2222
workbench = testContext.workbench
23-
2423
editorView = new EditorView()
2524
testContext.editorView = editorView
26-
2725
textEditor = await createNewTextFile(workbench, editorView)
2826
})
29-
30-
it('Inline Test', async () => {
31-
await writeToTextEditor(textEditor, 'Select Me')
27+
after(async function () {
28+
// Switch back to Webview Iframe when dealing with external webviews from Amazon Q.
29+
await editorView.closeAllEditors()
30+
await webviewView.switchToFrame()
31+
testContext.webviewView = webviewView
32+
})
33+
it('Inline Test Shortcut', async () => {
34+
await writeToTextEditor(textEditor, 'def factorial(n):')
3235
const text = await textEditor.getText()
33-
assert.equal(text, 'Select Me')
36+
assert.equal(text, 'def factorial(n): ')
3437
await textEditor.clearText()
3538

39+
const textBefore = await textEditor.getText()
3640
await workbench.executeCommand('Amazon Q: Inline Chat')
3741
const input = new InputBox()
38-
await input.sendKeys('Write a simple sentece')
42+
await input.sendKeys('Generate the fibonacci sequence through iteration')
3943
await input.sendKeys(Key.ENTER)
40-
const driver = textEditor.getDriver()
41-
await pressKey(driver, 'ENTER')
42-
await pressKey(driver, 'TAB')
44+
await sleep(8000)
45+
46+
const textAfter = await textEditor.getText()
47+
assert(textAfter.length > textBefore.length, 'Amazon Q should have generated code')
48+
assert(textAfter.includes('fibonacci'), 'Generated code should contain fibonacci logic')
49+
await textEditor.clearText()
4350
})
4451
})

packages/amazonq/test/e2e_new/amazonq/utils/generalUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ export async function createNewTextFile(workbench: Workbench, editorView: Editor
157157
* @returns Promise<void>
158158
*/
159159
export async function writeToTextEditor(textEditor: TextEditor, text: string): Promise<void> {
160+
await textEditor.typeTextAt(1, 1, ' ')
160161
const currentLines = await textEditor.getNumberOfLines()
161-
const nextLine = currentLines + 1
162-
await textEditor.typeTextAt(nextLine, 1, text)
162+
await textEditor.typeTextAt(currentLines, 1, text)
163163
}
164164

165165
/**

0 commit comments

Comments
 (0)