Skip to content

Commit 7b1843a

Browse files
committed
changes based on the comments
1 parent 01b73d5 commit 7b1843a

File tree

2 files changed

+28
-52
lines changed

2 files changed

+28
-52
lines changed

packages/amazonq/test/e2e_new/amazonq/tests/inline.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import '../utils/setup'
66
import { Workbench, EditorView, InputBox, TextEditor, WebviewView, Key } from 'vscode-extension-tester'
77
import { testContext } from '../utils/testContext'
8-
import { sleep, expect, pressKey, createNewTextFile } from '../utils/generalUtils'
8+
import { sleep, expect, pressKey, createNewTextFile, writeToTextEditor } from '../utils/generalUtils'
99

1010
describe('Amazon Q Inline Completion / Chat Functionality', function () {
1111
// this timeout is the general timeout for the entire test suite
@@ -27,19 +27,17 @@ describe('Amazon Q Inline Completion / Chat Functionality', function () {
2727
})
2828

2929
it('Inline Test', async () => {
30-
await textEditor.typeTextAt(1, 1, 'Select Me')
30+
await writeToTextEditor(textEditor, 'Select Me')
3131
const text = await textEditor.getText()
3232
expect(text).equals('Select Me')
3333
await textEditor.clearText()
34+
3435
await workbench.executeCommand('Amazon Q: Inline Chat')
3536
const input = new InputBox()
3637
await input.sendKeys('Write a simple sentece')
3738
await input.sendKeys(Key.ENTER)
38-
await sleep(5000)
3939
const driver = textEditor.getDriver()
4040
await pressKey(driver, 'ENTER')
41-
await sleep(3000)
4241
await pressKey(driver, 'TAB')
43-
await sleep(3000)
4442
})
4543
})

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

Lines changed: 25 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -73,58 +73,24 @@ export async function pressKey(driver: WebDriver, key: keyof typeof Key): Promis
7373
await driver.actions().sendKeys(key).perform()
7474
}
7575

76-
type OSType = 'windows' | 'mac'
77-
type modifierKey = 'alt' | 'ctrl' | 'shift' | 'option' | 'command'
78-
79-
const MODIFIERKEYS: Record<OSType, Record<modifierKey, string>> = {
80-
windows: {
81-
alt: Key.ALT,
82-
ctrl: Key.CONTROL,
83-
shift: Key.SHIFT,
84-
option: Key.ALT,
85-
command: Key.COMMAND,
86-
},
87-
mac: {
88-
alt: Key.ALT,
89-
ctrl: Key.CONTROL,
90-
shift: Key.SHIFT,
91-
option: Key.ALT,
92-
command: Key.COMMAND,
93-
},
94-
}
95-
9676
/**
9777
* Presses a keyboard shortcut with modifier keys
9878
* @param driver The WebDriver instance
99-
* @param key The key to press
100-
* @param modifier The modifier key(s)
101-
* @param osType The operating system type
79+
* @param key The keys to press
80+
*
81+
* Examples:
82+
* Ctrl + C | await pressShortcut(driver, Key.CONTROL, 'c')
83+
* Ctrl + Shift + T | await pressShortcut(driver, Key.CONTROL, Key.SHIFT, 't')
10284
*/
103-
export async function pressShortcut(
104-
driver: WebDriver,
105-
key: string,
106-
modifier: modifierKey | modifierKey[],
107-
osType: OSType = 'windows'
108-
): Promise<void> {
109-
const actions = driver.actions({ bridge: true })
110-
111-
try {
112-
const modifiers = Array.isArray(modifier) ? modifier : modifier ? [modifier] : []
113-
for (const mod of modifiers) {
114-
if (!(mod in MODIFIERKEYS[osType])) {
115-
throw new Error(`Invalid modifier key '${mod}' for ${osType}`)
116-
}
117-
actions.keyDown(MODIFIERKEYS[osType][mod])
118-
}
119-
actions.sendKeys(key)
120-
for (const mod of modifiers.reverse()) {
121-
actions.keyUp(MODIFIERKEYS[osType][mod])
122-
}
123-
await actions.perform()
124-
} catch (error) {
125-
console.error(`Error performing keyboard shortcut: ${error}`)
126-
throw error
85+
export async function pressShortcut(driver: WebDriver, ...keys: (keyof typeof Key)[]): Promise<void> {
86+
const actions = driver.actions()
87+
for (const key of keys) {
88+
actions.keyDown(key)
12789
}
90+
for (const key of keys.reverse()) {
91+
actions.keyUp(key)
92+
}
93+
await actions.perform()
12894
}
12995

13096
/**
@@ -205,6 +171,18 @@ export async function createNewTextFile(workbench: Workbench, editorView: Editor
205171
return textEditor
206172
}
207173

174+
/**
175+
* Writes the given string in the textEditor in the next empty line
176+
* @param textEditor The TextEditor instance
177+
* @param text The text the user wants to type
178+
* @returns Promise<void>
179+
*/
180+
export async function writeToTextEditor(textEditor: TextEditor, text: string): Promise<void> {
181+
const currentLines = await textEditor.getNumberOfLines()
182+
const nextLine = currentLines + 1
183+
await textEditor.typeTextAt(nextLine, 1, text)
184+
}
185+
208186
/**
209187
* Finds an item based on the text
210188
* @param items WebElement array to search

0 commit comments

Comments
 (0)