Skip to content

Commit a9a8b27

Browse files
authored
feat(amazonq): add shortcut test for UI E2E Tests (#7863)
## Problem We have not implemented the shortcut tests for our UI E2E Test suite with VSCode-Extension-Tester. Additionally, we face a small problem in our pressShortcut abstraction that throws a type error when trying to reference a Key command like `Key.COMMAND` since it is a IKey String. ## Solution We have implemented the shortcut tests: - Optimize Code Shortcut - Generate Test Shortcut - Keybind Check - Explain Code Shortcut We have also fixed the pressShortcut abstraction with a small edit in the logic of accepted parameters. NOTE: We have chosen to implement the Inline Shortcut within the Inline Tests even though it could be classified under Shorcuts. --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 40ce504 commit a9a8b27

File tree

2 files changed

+89
-2
lines changed

2 files changed

+89
-2
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
import '../utils/setup'
6+
import { Workbench, EditorView, TextEditor, InputBox, WebviewView, Key } from 'vscode-extension-tester'
7+
import { testContext } from '../utils/testContext'
8+
import {
9+
clearChatInput,
10+
pressShortcut,
11+
createNewTextFile,
12+
writeToTextEditor,
13+
waitForChatResponse,
14+
} from '../utils/generalUtils'
15+
import { closeAllTabs } from '../utils/cleanupUtils'
16+
17+
describe('Amazon Q Shortcut Functionality Tests', function () {
18+
// this timeout is the general timeout for the entire test suite
19+
this.timeout(150000)
20+
let workbench: Workbench
21+
let editorView: EditorView
22+
let textEditor: TextEditor
23+
let webviewView: WebviewView
24+
25+
beforeEach(async function () {
26+
webviewView = testContext.webviewView
27+
await webviewView.switchBack()
28+
workbench = testContext.workbench
29+
editorView = new EditorView()
30+
testContext.editorView = editorView
31+
textEditor = await createNewTextFile(workbench, editorView)
32+
})
33+
34+
afterEach(async function () {
35+
await closeAllTabs(webviewView)
36+
await clearChatInput(webviewView)
37+
})
38+
it('Allows User to Verify Command Palette Works as Expected', async () => {
39+
const driver = webviewView.getDriver()
40+
await pressShortcut(driver, Key.CONTROL, Key.SHIFT, 'p')
41+
const input = new InputBox()
42+
await input.sendKeys('Preferences: Open Keyboard Shortcuts')
43+
await input.sendKeys(Key.ENTER)
44+
await editorView.closeAllEditors()
45+
await webviewView.switchToFrame()
46+
})
47+
it('Allows User to Generate Tests Using Keybind', async () => {
48+
await writeToTextEditor(textEditor, 'def fibonacci(n):')
49+
await textEditor.selectText('def fibonacci(n):')
50+
51+
const driver = webviewView.getDriver()
52+
await pressShortcut(driver, Key.CONTROL, Key.ALT, 't')
53+
await textEditor.clearText()
54+
await editorView.closeAllEditors()
55+
await webviewView.switchToFrame()
56+
await waitForChatResponse(webviewView)
57+
})
58+
it('Allows User to Select and Explain Code Using Keybind', async () => {
59+
await writeToTextEditor(textEditor, 'def fibonacci(n):')
60+
await textEditor.selectText('def fibonacci(n):')
61+
62+
const driver = webviewView.getDriver()
63+
await pressShortcut(driver, Key.CONTROL, Key.ALT, 'e')
64+
await textEditor.clearText()
65+
await editorView.closeAllEditors()
66+
await webviewView.switchToFrame()
67+
await waitForChatResponse(webviewView)
68+
})
69+
it('Allows User to Optimize Code Using Keybind', async () => {
70+
await writeToTextEditor(textEditor, 'def fibonacci(n):')
71+
await textEditor.selectText('def fibonacci(n):')
72+
73+
const driver = webviewView.getDriver()
74+
await pressShortcut(driver, Key.CONTROL, Key.ALT, 'a')
75+
await textEditor.clearText()
76+
await editorView.closeAllEditors()
77+
await webviewView.switchToFrame()
78+
await waitForChatResponse(webviewView)
79+
})
80+
})

packages/amazonq/test/e2e_new/amazonq/utils/generalUtils.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,18 @@ export async function pressKey(driver: WebDriver, key: keyof typeof Key): Promis
110110
* Ctrl + Shift + T | await pressShortcut(driver, Key.CONTROL, Key.SHIFT, 't')
111111
*/
112112
export async function pressShortcut(driver: WebDriver, ...keys: (string | keyof typeof Key)[]): Promise<void> {
113+
// Replace CONTROL with COMMAND on macOS
114+
const platformKeys = keys.map((key) => {
115+
if (key === Key.CONTROL && process.platform === 'darwin') {
116+
return Key.COMMAND
117+
}
118+
return key
119+
})
113120
const actions = driver.actions()
114-
for (const key of keys) {
121+
for (const key of platformKeys) {
115122
actions.keyDown(key)
116123
}
117-
for (const key of keys.reverse()) {
124+
for (const key of platformKeys.reverse()) {
118125
actions.keyUp(key)
119126
}
120127
await actions.perform()

0 commit comments

Comments
 (0)