Skip to content

Commit 6dddd03

Browse files
committed
feature: add shortcut test
1 parent e24101c commit 6dddd03

File tree

2 files changed

+97
-1
lines changed

2 files changed

+97
-1
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
clearChat,
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', 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 clearChat(webviewView)
37+
})
38+
it('Keybind Check', async () => {
39+
const driver = webviewView.getDriver()
40+
// Open Command Palette
41+
await pressShortcut(driver, Key.COMMAND, Key.SHIFT, 'p')
42+
const input = new InputBox()
43+
await input.sendKeys('Preferences: Open Keyboard Shortcuts')
44+
await input.sendKeys(Key.ENTER)
45+
await editorView.closeAllEditors()
46+
await webviewView.switchToFrame()
47+
})
48+
it('Generate Test Keybind', async () => {
49+
await writeToTextEditor(textEditor, 'def fibonacci(n):')
50+
await textEditor.selectText('def fibonacci(n):')
51+
52+
const driver = webviewView.getDriver()
53+
await pressShortcut(driver, Key.COMMAND, Key.ALT, 't')
54+
//Clean Up Text
55+
await textEditor.clearText()
56+
await editorView.closeAllEditors()
57+
await webviewView.switchToFrame()
58+
const responseReceived = await waitForChatResponse(webviewView)
59+
if (!responseReceived) {
60+
throw new Error('Chat response not received within timeout')
61+
}
62+
console.log('Chat response detected successfully')
63+
})
64+
it('Explain Code Shortcut', async () => {
65+
await writeToTextEditor(textEditor, 'def fibonacci(n):')
66+
await textEditor.selectText('def fibonacci(n):')
67+
68+
const driver = webviewView.getDriver()
69+
await pressShortcut(driver, Key.COMMAND, Key.ALT, 'e')
70+
//Clean Up Text
71+
await textEditor.clearText()
72+
await editorView.closeAllEditors()
73+
await webviewView.switchToFrame()
74+
const responseReceived = await waitForChatResponse(webviewView)
75+
if (!responseReceived) {
76+
throw new Error('Chat response not received within timeout')
77+
}
78+
console.log('Chat response detected successfully')
79+
})
80+
it('Optimize Code Shortcut', async () => {
81+
await writeToTextEditor(textEditor, 'def fibonacci(n):')
82+
await textEditor.selectText('def fibonacci(n):')
83+
84+
const driver = webviewView.getDriver()
85+
await pressShortcut(driver, Key.COMMAND, Key.ALT, 'a')
86+
//Clean Up Text
87+
await textEditor.clearText()
88+
await editorView.closeAllEditors()
89+
await webviewView.switchToFrame()
90+
const responseReceived = await waitForChatResponse(webviewView)
91+
if (!responseReceived) {
92+
throw new Error('Chat response not received within timeout')
93+
}
94+
console.log('Chat response detected successfully')
95+
})
96+
})

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export async function pressKey(driver: WebDriver, key: keyof typeof Key): Promis
5757
* Ctrl + C | await pressShortcut(driver, Key.CONTROL, 'c')
5858
* Ctrl + Shift + T | await pressShortcut(driver, Key.CONTROL, Key.SHIFT, 't')
5959
*/
60-
export async function pressShortcut(driver: WebDriver, ...keys: (keyof typeof Key)[]): Promise<void> {
60+
export async function pressShortcut(driver: WebDriver, ...keys: (string | keyof typeof Key)[]): Promise<void> {
6161
const actions = driver.actions()
6262
for (const key of keys) {
6363
actions.keyDown(key)

0 commit comments

Comments
 (0)