-
Notifications
You must be signed in to change notification settings - Fork 731
fix(amazonq): Addition of wait function for Amazon Q inline chat UI E2E Tests and Inline Keybind Shortcut Test #7840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
0d506f1
79b1b3a
92c3f61
c93536c
267d4af
2ecfebc
12b7763
6047137
79ed706
7544062
363703e
19d281e
702d852
6303d8e
4d1e04f
24a4514
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, waitForEditorStabilization } 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') | ||
| // Wait for Amazon Q to finish generating code | ||
| await waitForEditorStabilization(textEditor) | ||
|
|
||
| const textAfter = await textEditor.getText() | ||
| assert(textAfter.length > textBefore.length, 'Amazon Q generated code') | ||
| await textEditor.clearText() | ||
| }) | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -157,9 +157,42 @@ export async function createNewTextFile(workbench: Workbench, editorView: Editor | |
| * @returns Promise<void> | ||
| */ | ||
| export async function writeToTextEditor(textEditor: TextEditor, text: string): Promise<void> { | ||
| // 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) | ||
| } | ||
|
|
||
| /** | ||
| * Waits for editor content to stabilize by checking if line count stops changing | ||
| * @param editor The TextEditor instance | ||
| * @param timeout Maximum time to wait in milliseconds (default: 15000) | ||
| * @returns Promise<void> | ||
| * @throws Error if timeout is exceeded | ||
| */ | ||
| export async function waitForEditorStabilization(editor: TextEditor, timeout = 15000): Promise<void> { | ||
|
||
| const startTime = Date.now() | ||
| let previousLines = await editor.getNumberOfLines() | ||
| let stableCount = 0 | ||
|
|
||
| while (Date.now() - startTime < timeout) { | ||
| await sleep(1000) | ||
| const currentLines = await editor.getNumberOfLines() | ||
|
|
||
| if (currentLines === previousLines) { | ||
| stableCount++ | ||
| if (stableCount >= 2) { | ||
|
||
| return | ||
| } | ||
| } else { | ||
| stableCount = 0 | ||
| } | ||
|
|
||
| previousLines = currentLines | ||
| } | ||
|
|
||
| throw new Error(`Editor stabilization timed out after ${timeout}ms`) | ||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: should be corrected to iframe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha!