diff --git a/package.json b/package.json index 3da9c013cbf..38d54b2fa0e 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "testE2E": "npm run testE2E -w packages/ --if-present", "test:ui:prepare": "./node_modules/.bin/extest get-vscode -s ~/.vscode-test-resources -n && extest get-chromedriver -s ~/.vscode-test-resources -n", "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'", - "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", + "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", "test:ui": "npm run test:ui:prepare && npm run test:ui:install && npm run test:ui:run", "testInteg": "npm run testInteg -w packages/ --if-present", "package": "npm run package -w packages/toolkit -w packages/amazonq", diff --git a/packages/amazonq/test/e2e_new/amazonq/tests/inline.test.ts b/packages/amazonq/test/e2e_new/amazonq/tests/inline.test.ts index 6c8d975206d..0433b67afc0 100644 --- a/packages/amazonq/test/e2e_new/amazonq/tests/inline.test.ts +++ b/packages/amazonq/test/e2e_new/amazonq/tests/inline.test.ts @@ -5,7 +5,7 @@ import '../utils/setup' import { Workbench, EditorView, InputBox, TextEditor, WebviewView, Key } from 'vscode-extension-tester' import { testContext } from '../utils/testContext' -import { pressKey, createNewTextFile, writeToTextEditor } from '../utils/generalUtils' +import { createNewTextFile, writeToTextEditor, sleep } from '../utils/generalUtils' import assert from 'assert' describe('Amazon Q Inline Completion / Chat Functionality', function () { @@ -20,25 +20,31 @@ describe('Amazon Q Inline Completion / Chat Functionality', function () { webviewView = testContext.webviewView await webviewView.switchBack() workbench = testContext.workbench - editorView = new EditorView() testContext.editorView = editorView - textEditor = await createNewTextFile(workbench, editorView) }) - - it('Inline Test', async () => { - await writeToTextEditor(textEditor, 'Select Me') + after(async function () { + // Switch back to Webview Iframe when dealing with external webviews from Amazon Q. + await editorView.closeAllEditors() + await webviewView.switchToFrame() + }) + it('Inline Test Shortcut', async () => { + await writeToTextEditor(textEditor, 'def factorial(n):') const text = await textEditor.getText() - assert.equal(text, 'Select Me') + assert.equal(text, 'def factorial(n): ') await textEditor.clearText() + const textBefore = await textEditor.getText() await workbench.executeCommand('Amazon Q: Inline Chat') const input = new InputBox() - await input.sendKeys('Write a simple sentece') + await input.sendKeys('Generate the fibonacci sequence through iteration') await input.sendKeys(Key.ENTER) - const driver = textEditor.getDriver() - await pressKey(driver, 'ENTER') - await pressKey(driver, 'TAB') + // Must wait for response to be generated. + await sleep(8000) + + const textAfter = await textEditor.getText() + assert(textAfter.length > textBefore.length, 'Amazon Q should have generated code') + await textEditor.clearText() }) }) diff --git a/packages/amazonq/test/e2e_new/amazonq/utils/generalUtils.ts b/packages/amazonq/test/e2e_new/amazonq/utils/generalUtils.ts index b85d2e98012..d4bfc20c702 100644 --- a/packages/amazonq/test/e2e_new/amazonq/utils/generalUtils.ts +++ b/packages/amazonq/test/e2e_new/amazonq/utils/generalUtils.ts @@ -157,9 +157,11 @@ export async function createNewTextFile(workbench: Workbench, editorView: Editor * @returns Promise */ export async function writeToTextEditor(textEditor: TextEditor, text: string): Promise { + // We require a "dummy" space to be written such that we can properly index the + // number of lines to register the textEditor. + await textEditor.typeTextAt(1, 1, ' ') const currentLines = await textEditor.getNumberOfLines() - const nextLine = currentLines + 1 - await textEditor.typeTextAt(nextLine, 1, text) + await textEditor.typeTextAt(currentLines, 1, text) } /**