From 6dddd03048ab15f580c04bae0b6e1aead9afcffd Mon Sep 17 00:00:00 2001 From: Suraj Reddy Date: Mon, 11 Aug 2025 15:16:52 -0400 Subject: [PATCH 1/5] feature: add shortcut test --- .../e2e_new/amazonq/tests/shortcut.test.ts | 96 +++++++++++++++++++ .../e2e_new/amazonq/utils/generalUtils.ts | 2 +- 2 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 packages/amazonq/test/e2e_new/amazonq/tests/shortcut.test.ts diff --git a/packages/amazonq/test/e2e_new/amazonq/tests/shortcut.test.ts b/packages/amazonq/test/e2e_new/amazonq/tests/shortcut.test.ts new file mode 100644 index 00000000000..e38aa04bb0b --- /dev/null +++ b/packages/amazonq/test/e2e_new/amazonq/tests/shortcut.test.ts @@ -0,0 +1,96 @@ +/*! + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +import '../utils/setup' +import { Workbench, EditorView, TextEditor, InputBox, WebviewView, Key } from 'vscode-extension-tester' +import { testContext } from '../utils/testContext' +import { + clearChat, + pressShortcut, + createNewTextFile, + writeToTextEditor, + waitForChatResponse, +} from '../utils/generalUtils' +import { closeAllTabs } from '../utils/cleanupUtils' + +describe('Amazon Q Shortcut Functionality', function () { + // this timeout is the general timeout for the entire test suite + this.timeout(150000) + let workbench: Workbench + let editorView: EditorView + let textEditor: TextEditor + let webviewView: WebviewView + + beforeEach(async function () { + webviewView = testContext.webviewView + await webviewView.switchBack() + workbench = testContext.workbench + editorView = new EditorView() + testContext.editorView = editorView + textEditor = await createNewTextFile(workbench, editorView) + }) + + afterEach(async function () { + await closeAllTabs(webviewView) + await clearChat(webviewView) + }) + it('Keybind Check', async () => { + const driver = webviewView.getDriver() + // Open Command Palette + await pressShortcut(driver, Key.COMMAND, Key.SHIFT, 'p') + const input = new InputBox() + await input.sendKeys('Preferences: Open Keyboard Shortcuts') + await input.sendKeys(Key.ENTER) + await editorView.closeAllEditors() + await webviewView.switchToFrame() + }) + it('Generate Test Keybind', async () => { + await writeToTextEditor(textEditor, 'def fibonacci(n):') + await textEditor.selectText('def fibonacci(n):') + + const driver = webviewView.getDriver() + await pressShortcut(driver, Key.COMMAND, Key.ALT, 't') + //Clean Up Text + await textEditor.clearText() + await editorView.closeAllEditors() + await webviewView.switchToFrame() + const responseReceived = await waitForChatResponse(webviewView) + if (!responseReceived) { + throw new Error('Chat response not received within timeout') + } + console.log('Chat response detected successfully') + }) + it('Explain Code Shortcut', async () => { + await writeToTextEditor(textEditor, 'def fibonacci(n):') + await textEditor.selectText('def fibonacci(n):') + + const driver = webviewView.getDriver() + await pressShortcut(driver, Key.COMMAND, Key.ALT, 'e') + //Clean Up Text + await textEditor.clearText() + await editorView.closeAllEditors() + await webviewView.switchToFrame() + const responseReceived = await waitForChatResponse(webviewView) + if (!responseReceived) { + throw new Error('Chat response not received within timeout') + } + console.log('Chat response detected successfully') + }) + it('Optimize Code Shortcut', async () => { + await writeToTextEditor(textEditor, 'def fibonacci(n):') + await textEditor.selectText('def fibonacci(n):') + + const driver = webviewView.getDriver() + await pressShortcut(driver, Key.COMMAND, Key.ALT, 'a') + //Clean Up Text + await textEditor.clearText() + await editorView.closeAllEditors() + await webviewView.switchToFrame() + const responseReceived = await waitForChatResponse(webviewView) + if (!responseReceived) { + throw new Error('Chat response not received within timeout') + } + console.log('Chat response detected successfully') + }) +}) diff --git a/packages/amazonq/test/e2e_new/amazonq/utils/generalUtils.ts b/packages/amazonq/test/e2e_new/amazonq/utils/generalUtils.ts index d4bfc20c702..5ced76c69b7 100644 --- a/packages/amazonq/test/e2e_new/amazonq/utils/generalUtils.ts +++ b/packages/amazonq/test/e2e_new/amazonq/utils/generalUtils.ts @@ -57,7 +57,7 @@ export async function pressKey(driver: WebDriver, key: keyof typeof Key): Promis * Ctrl + C | await pressShortcut(driver, Key.CONTROL, 'c') * Ctrl + Shift + T | await pressShortcut(driver, Key.CONTROL, Key.SHIFT, 't') */ -export async function pressShortcut(driver: WebDriver, ...keys: (keyof typeof Key)[]): Promise { +export async function pressShortcut(driver: WebDriver, ...keys: (string | keyof typeof Key)[]): Promise { const actions = driver.actions() for (const key of keys) { actions.keyDown(key) From c8bc42c2cd7bf63d374069cddfb65ce440a16ca0 Mon Sep 17 00:00:00 2001 From: surajrdy-aws Date: Tue, 12 Aug 2025 11:47:41 -0400 Subject: [PATCH 2/5] Update shortcut.test.ts eslint --- .../amazonq/test/e2e_new/amazonq/tests/shortcut.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/amazonq/test/e2e_new/amazonq/tests/shortcut.test.ts b/packages/amazonq/test/e2e_new/amazonq/tests/shortcut.test.ts index e38aa04bb0b..64f22ee66ad 100644 --- a/packages/amazonq/test/e2e_new/amazonq/tests/shortcut.test.ts +++ b/packages/amazonq/test/e2e_new/amazonq/tests/shortcut.test.ts @@ -51,7 +51,7 @@ describe('Amazon Q Shortcut Functionality', function () { const driver = webviewView.getDriver() await pressShortcut(driver, Key.COMMAND, Key.ALT, 't') - //Clean Up Text + // Clean Up Text await textEditor.clearText() await editorView.closeAllEditors() await webviewView.switchToFrame() @@ -67,7 +67,7 @@ describe('Amazon Q Shortcut Functionality', function () { const driver = webviewView.getDriver() await pressShortcut(driver, Key.COMMAND, Key.ALT, 'e') - //Clean Up Text + // Clean Up Text await textEditor.clearText() await editorView.closeAllEditors() await webviewView.switchToFrame() @@ -83,7 +83,7 @@ describe('Amazon Q Shortcut Functionality', function () { const driver = webviewView.getDriver() await pressShortcut(driver, Key.COMMAND, Key.ALT, 'a') - //Clean Up Text + // Clean Up Text await textEditor.clearText() await editorView.closeAllEditors() await webviewView.switchToFrame() From 4761d6e65aa6646e8b55bf4078f7dace3c92e92a Mon Sep 17 00:00:00 2001 From: Suraj Reddy Date: Tue, 12 Aug 2025 14:44:19 -0400 Subject: [PATCH 3/5] fix: update code from PR comments --- .../e2e_new/amazonq/tests/shortcut.test.ts | 32 +++++-------------- 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/packages/amazonq/test/e2e_new/amazonq/tests/shortcut.test.ts b/packages/amazonq/test/e2e_new/amazonq/tests/shortcut.test.ts index 64f22ee66ad..d3acb2ce2fd 100644 --- a/packages/amazonq/test/e2e_new/amazonq/tests/shortcut.test.ts +++ b/packages/amazonq/test/e2e_new/amazonq/tests/shortcut.test.ts @@ -14,7 +14,7 @@ import { } from '../utils/generalUtils' import { closeAllTabs } from '../utils/cleanupUtils' -describe('Amazon Q Shortcut Functionality', function () { +describe('Amazon Q Shortcut Functionality Tests', function () { // this timeout is the general timeout for the entire test suite this.timeout(150000) let workbench: Workbench @@ -35,9 +35,8 @@ describe('Amazon Q Shortcut Functionality', function () { await closeAllTabs(webviewView) await clearChat(webviewView) }) - it('Keybind Check', async () => { + it('Allows User to Verify Command Palette Works as Expected', async () => { const driver = webviewView.getDriver() - // Open Command Palette await pressShortcut(driver, Key.COMMAND, Key.SHIFT, 'p') const input = new InputBox() await input.sendKeys('Preferences: Open Keyboard Shortcuts') @@ -45,52 +44,37 @@ describe('Amazon Q Shortcut Functionality', function () { await editorView.closeAllEditors() await webviewView.switchToFrame() }) - it('Generate Test Keybind', async () => { + it('Allows User to Generate Tests Using Keybind', async () => { await writeToTextEditor(textEditor, 'def fibonacci(n):') await textEditor.selectText('def fibonacci(n):') const driver = webviewView.getDriver() await pressShortcut(driver, Key.COMMAND, Key.ALT, 't') - // Clean Up Text await textEditor.clearText() await editorView.closeAllEditors() await webviewView.switchToFrame() - const responseReceived = await waitForChatResponse(webviewView) - if (!responseReceived) { - throw new Error('Chat response not received within timeout') - } - console.log('Chat response detected successfully') + await waitForChatResponse(webviewView) }) - it('Explain Code Shortcut', async () => { + it('Allows User to Select and Explain Code Using Keybind', async () => { await writeToTextEditor(textEditor, 'def fibonacci(n):') await textEditor.selectText('def fibonacci(n):') const driver = webviewView.getDriver() await pressShortcut(driver, Key.COMMAND, Key.ALT, 'e') - // Clean Up Text await textEditor.clearText() await editorView.closeAllEditors() await webviewView.switchToFrame() - const responseReceived = await waitForChatResponse(webviewView) - if (!responseReceived) { - throw new Error('Chat response not received within timeout') - } - console.log('Chat response detected successfully') + await waitForChatResponse(webviewView) }) - it('Optimize Code Shortcut', async () => { + it('Allows User to Optimize Code Using Keybind', async () => { await writeToTextEditor(textEditor, 'def fibonacci(n):') await textEditor.selectText('def fibonacci(n):') const driver = webviewView.getDriver() await pressShortcut(driver, Key.COMMAND, Key.ALT, 'a') - // Clean Up Text await textEditor.clearText() await editorView.closeAllEditors() await webviewView.switchToFrame() - const responseReceived = await waitForChatResponse(webviewView) - if (!responseReceived) { - throw new Error('Chat response not received within timeout') - } - console.log('Chat response detected successfully') + await waitForChatResponse(webviewView) }) }) From 87a1c2e3cdb3b5e27a0eeeb3d41d807a5b7a9766 Mon Sep 17 00:00:00 2001 From: Suraj Reddy Date: Thu, 14 Aug 2025 11:56:24 -0400 Subject: [PATCH 4/5] fix: multiple OS test --- .../test/e2e_new/amazonq/tests/shortcut.test.ts | 8 ++++---- .../test/e2e_new/amazonq/utils/generalUtils.ts | 12 ++++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/amazonq/test/e2e_new/amazonq/tests/shortcut.test.ts b/packages/amazonq/test/e2e_new/amazonq/tests/shortcut.test.ts index d3acb2ce2fd..1b74321c887 100644 --- a/packages/amazonq/test/e2e_new/amazonq/tests/shortcut.test.ts +++ b/packages/amazonq/test/e2e_new/amazonq/tests/shortcut.test.ts @@ -37,7 +37,7 @@ describe('Amazon Q Shortcut Functionality Tests', function () { }) it('Allows User to Verify Command Palette Works as Expected', async () => { const driver = webviewView.getDriver() - await pressShortcut(driver, Key.COMMAND, Key.SHIFT, 'p') + await pressShortcut(driver, Key.CONTROL, Key.SHIFT, 'p') const input = new InputBox() await input.sendKeys('Preferences: Open Keyboard Shortcuts') await input.sendKeys(Key.ENTER) @@ -49,7 +49,7 @@ describe('Amazon Q Shortcut Functionality Tests', function () { await textEditor.selectText('def fibonacci(n):') const driver = webviewView.getDriver() - await pressShortcut(driver, Key.COMMAND, Key.ALT, 't') + await pressShortcut(driver, Key.CONTROL, Key.ALT, 't') await textEditor.clearText() await editorView.closeAllEditors() await webviewView.switchToFrame() @@ -60,7 +60,7 @@ describe('Amazon Q Shortcut Functionality Tests', function () { await textEditor.selectText('def fibonacci(n):') const driver = webviewView.getDriver() - await pressShortcut(driver, Key.COMMAND, Key.ALT, 'e') + await pressShortcut(driver, Key.CONTROL, Key.ALT, 'e') await textEditor.clearText() await editorView.closeAllEditors() await webviewView.switchToFrame() @@ -71,7 +71,7 @@ describe('Amazon Q Shortcut Functionality Tests', function () { await textEditor.selectText('def fibonacci(n):') const driver = webviewView.getDriver() - await pressShortcut(driver, Key.COMMAND, Key.ALT, 'a') + await pressShortcut(driver, Key.CONTROL, Key.ALT, 'a') await textEditor.clearText() await editorView.closeAllEditors() await webviewView.switchToFrame() diff --git a/packages/amazonq/test/e2e_new/amazonq/utils/generalUtils.ts b/packages/amazonq/test/e2e_new/amazonq/utils/generalUtils.ts index 5ced76c69b7..3129e103b7a 100644 --- a/packages/amazonq/test/e2e_new/amazonq/utils/generalUtils.ts +++ b/packages/amazonq/test/e2e_new/amazonq/utils/generalUtils.ts @@ -58,11 +58,19 @@ export async function pressKey(driver: WebDriver, key: keyof typeof Key): Promis * Ctrl + Shift + T | await pressShortcut(driver, Key.CONTROL, Key.SHIFT, 't') */ export async function pressShortcut(driver: WebDriver, ...keys: (string | keyof typeof Key)[]): Promise { + // Replace CONTROL with COMMAND on macOS + const platformKeys = keys.map((key) => { + if (key === Key.CONTROL && process.platform === 'darwin') { + return Key.COMMAND + } + return key + }) + const actions = driver.actions() - for (const key of keys) { + for (const key of platformKeys) { actions.keyDown(key) } - for (const key of keys.reverse()) { + for (const key of platformKeys.reverse()) { actions.keyUp(key) } await actions.perform() From 5be15af38679e89f891ac80ce24609dc657be81b Mon Sep 17 00:00:00 2001 From: Suraj Reddy Date: Fri, 15 Aug 2025 12:10:13 -0400 Subject: [PATCH 5/5] fix: rebase --- packages/amazonq/test/e2e_new/amazonq/tests/shortcut.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/amazonq/test/e2e_new/amazonq/tests/shortcut.test.ts b/packages/amazonq/test/e2e_new/amazonq/tests/shortcut.test.ts index 1b74321c887..398f84e8006 100644 --- a/packages/amazonq/test/e2e_new/amazonq/tests/shortcut.test.ts +++ b/packages/amazonq/test/e2e_new/amazonq/tests/shortcut.test.ts @@ -6,7 +6,7 @@ import '../utils/setup' import { Workbench, EditorView, TextEditor, InputBox, WebviewView, Key } from 'vscode-extension-tester' import { testContext } from '../utils/testContext' import { - clearChat, + clearChatInput, pressShortcut, createNewTextFile, writeToTextEditor, @@ -33,7 +33,7 @@ describe('Amazon Q Shortcut Functionality Tests', function () { afterEach(async function () { await closeAllTabs(webviewView) - await clearChat(webviewView) + await clearChatInput(webviewView) }) it('Allows User to Verify Command Palette Works as Expected', async () => { const driver = webviewView.getDriver()