Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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 {
clearChat,
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 clearChat(webviewView)
})
it('Allows User to Verify Command Palette Works as Expected', async () => {
const driver = webviewView.getDriver()
await pressShortcut(driver, Key.COMMAND, Key.SHIFT, 'p')
Copy link
Contributor

Choose a reason for hiding this comment

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

does VET not have native support for opening the command palette? Somewhat surprised by that.

Copy link
Author

Choose a reason for hiding this comment

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

They do, but for these tests, they specifically wanted to test Keybinds on the computer as short cuts. I wonder if just using the native VET support is any different in the testing sense?

Copy link
Contributor

Choose a reason for hiding this comment

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

interesting. Does VSC allow for users to overwrite key binds? If so would this test always fail on their machine?

Copy link
Author

Choose a reason for hiding this comment

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

Yes I believe they do allow for users to overwrite key binds. The tests would then fail on the machine. I think generally this test is not extremely robust, but not sure how else to tackle it since some of the test descriptions explicitly asked for keybinds to be used. What are your thoughts on it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea, I guess this is fine for now. Could be worth adding a comment, but don't see it as a blocker.

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.COMMAND, 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.COMMAND, 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.COMMAND, Key.ALT, 'a')
await textEditor.clearText()
await editorView.closeAllEditors()
await webviewView.switchToFrame()
await waitForChatResponse(webviewView)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
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

const actions = driver.actions()
for (const key of keys) {
actions.keyDown(key)
Expand Down
Loading