Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions packages/amazonq/test/e2e_new/amazonq/tests/shortcut.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*!
* 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 {
clearChatInput,
pressShortcut,
createNewTextFile,
writeToTextEditor,
waitForChatResponse,
} from '../utils/generalUtils'
import { closeAllTabs } from '../utils/cleanupUtils'

describe('Amazon Q Shortcut Functionality Tests', function () {
// this timeout is the general timeout for the entire test suite
this.timeout(150000)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we centralize this to one place?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: once all PRs are in, go into all files and create a constant.ts file to manage repeated code. @surajrdy-aws

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 clearChatInput(webviewView)
})
it('Allows User to Verify Command Palette Works as Expected', async () => {
const driver = webviewView.getDriver()
await pressShortcut(driver, Key.CONTROL, 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('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.CONTROL, Key.ALT, 't')
await textEditor.clearText()
await editorView.closeAllEditors()
await webviewView.switchToFrame()
await waitForChatResponse(webviewView)
})
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.CONTROL, Key.ALT, 'e')
await textEditor.clearText()
await editorView.closeAllEditors()
await webviewView.switchToFrame()
await waitForChatResponse(webviewView)
})
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.CONTROL, Key.ALT, 'a')
await textEditor.clearText()
await editorView.closeAllEditors()
await webviewView.switchToFrame()
await waitForChatResponse(webviewView)
})
})
11 changes: 9 additions & 2 deletions packages/amazonq/test/e2e_new/amazonq/utils/generalUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,18 @@ 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<void> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to describe the 'a' key as the specified type rather than the string? Or is this change necessary?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, so to my understanding, the problem isn't actually the 'a' string but also the IKey variables which are declared as strings. For example:

COMMAND: string; // Apple command key

// 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()
Expand Down
Loading