Skip to content

Commit 81b4e68

Browse files
committed
inline completion test done
1 parent 5fc411d commit 81b4e68

File tree

2 files changed

+34
-41
lines changed

2 files changed

+34
-41
lines changed

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

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +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 } from '../utils/generalUtils'
9-
10-
function pressShortcut(element: any, key: string, platform: 'mac' | 'windows', modifier: 'cmd' | 'alt' = 'cmd') {
11-
const modifierKey = modifier === 'cmd' ? (platform === 'mac' ? Key.META : Key.CONTROL) : Key.ALT
12-
return element.sendKeys(modifierKey, key)
13-
}
8+
import { sleep, expect, pressKey, createNewTextFile } from '../utils/generalUtils'
149

1510
describe('Amazon Q Inline Completion / Chat Functionality', function () {
1611
// this timeout is the general timeout for the entire test suite
@@ -25,48 +20,33 @@ describe('Amazon Q Inline Completion / Chat Functionality', function () {
2520
await webviewView.switchBack()
2621
workbench = testContext.workbench
2722

28-
await workbench.executeCommand('Create: New File...')
29-
await (await InputBox.create()).selectQuickPick('Text File')
30-
await sleep(1000)
3123
editorView = new EditorView()
3224
testContext.editorView = editorView
33-
textEditor = (await editorView.openEditor('Untitled-1')) as TextEditor
34-
// or if the file we want is currently opened we can simply do
35-
// editor = new TextEditor();
36-
})
3725

38-
after(async function () {
39-
// cleanup, delete the file contents and close the editor
40-
await textEditor.clearText()
41-
await editorView.closeAllEditors()
42-
43-
// after, in order to not affect the other tests, we must switch back to the webview
44-
await webviewView.switchToFrame()
26+
textEditor = await createNewTextFile(workbench, editorView)
4527
})
4628

47-
it('Inline Test', async () => {
48-
// the file is currently empty, lets write something in it
49-
// note the coordinates are (1, 1) for the beginning of the file
50-
await textEditor.typeTextAt(1, 1, 'hello')
29+
// after(async function () {
30+
// await editorView.closeAllEditors()
31+
// })
5132

52-
// now we can check if the text is correct
33+
it('Inline Test', async () => {
34+
await textEditor.typeTextAt(1, 1, 'Select Me')
5335
const text = await textEditor.getText()
54-
expect(text).equals('hello')
36+
expect(text).equals('Select Me')
37+
await textEditor.clearText()
5538

39+
await workbench.executeCommand('Amazon Q: Inline Chat')
40+
const input = new InputBox()
41+
await input.sendKeys('Write a simple sentece')
42+
await input.sendKeys(Key.ENTER)
43+
await sleep(5000)
44+
const driver = textEditor.getDriver()
45+
await pressKey(driver, 'Enter')
46+
await sleep(3000)
47+
await pressKey(driver, 'Tab')
5648
// we can also replace all the text with whatever we want
57-
await textEditor.setText(`line1\nline2\nline3`)
58-
// assert how many lines there are now
59-
expect(await textEditor.getNumberOfLines()).equals(3)
60-
61-
// get text at the line with given number
62-
const line = await textEditor.getTextAtLine(2)
63-
expect(line).include('line2')
64-
65-
// get the line number of a search string
66-
const lineNum = await textEditor.getLineOfText('3')
67-
expect(lineNum).equals(3)
68-
69-
// the editor should be dirty since we haven't saved yet
70-
expect(await textEditor.isDirty()).is.true
49+
await sleep(3000)
50+
// await textEditor.clear()
7151
})
7252
})

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
5-
import { By, WebviewView, WebElement } from 'vscode-extension-tester'
5+
import { By, WebviewView, WebElement, EditorView, InputBox, Workbench, TextEditor } from 'vscode-extension-tester'
66
import { until, WebDriver, Key } from 'selenium-webdriver'
77

88
/**
@@ -191,6 +191,19 @@ export async function clearChat(webview: WebviewView): Promise<boolean> {
191191
}
192192
}
193193

194+
/**
195+
* Creates a new text file and returns the editor
196+
* @param workbench The Workbench instance
197+
* @returns Promise<TextEditor> The text editor for the new file
198+
*/
199+
export async function createNewTextFile(workbench: Workbench, editorView: EditorView): Promise<TextEditor> {
200+
await workbench.executeCommand('Create: New File...')
201+
await (await InputBox.create()).selectQuickPick('Text File')
202+
await sleep(1000)
203+
const textEditor = (await editorView.openEditor('Untitled-1')) as TextEditor
204+
return textEditor
205+
}
206+
194207
/**
195208
* Finds an item based on the text
196209
* @param items WebElement array to search

0 commit comments

Comments
 (0)