Skip to content

Commit b66da8c

Browse files
committed
implemented the backslash abstraction, required implementing functions to handle mynah overlays
1 parent 74011d2 commit b66da8c

File tree

4 files changed

+105
-4
lines changed

4 files changed

+105
-4
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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 { By, WebviewView } from 'vscode-extension-tester'
7+
import { closeAllTabs, dismissOverlayIfPresent } from './framework/cleanupHelper'
8+
import { testContext } from './utils/testContext'
9+
import { writeToChat } from './framework/chatHelper'
10+
import { waitForElement } from './framework/generalHelper'
11+
12+
describe('Amazon Q Chat Backslash Functionality', function () {
13+
// this timeout is the general timeout for the entire test suite
14+
this.timeout(150000)
15+
let webviewView: WebviewView
16+
17+
before(async function () {
18+
webviewView = testContext.webviewView!
19+
})
20+
21+
after(async () => {
22+
await closeAllTabs(webviewView)
23+
})
24+
25+
afterEach(async () => {
26+
// before closing the tabs, make sure that any overlays have been dismissed
27+
await dismissOverlayIfPresent(webviewView)
28+
})
29+
30+
it('Backslash Test', async () => {
31+
// type "/" but don't send in order to trigger the overlay menu
32+
await writeToChat('/', webviewView, false)
33+
await new Promise((resolve) => setTimeout(resolve, 2000))
34+
35+
/* NOTE: do NOT look for the container first because the overlay will disappear on a click,
36+
instead, we should just look for the clickable overlay menu items directly and click them
37+
one by one for the test. */
38+
const menuItems = await waitForElement(
39+
webviewView,
40+
By.css('.mynah-detailed-list-item.mynah-ui-clickable-item.target-command'),
41+
true,
42+
10000
43+
)
44+
console.log(`Found ${menuItems.length} backslash command items`)
45+
46+
// get text of each menu item before clicking any of them
47+
const menuTexts = []
48+
for (let i = 0; i < menuItems.length; i++) {
49+
try {
50+
const text = await menuItems[i].getText()
51+
menuTexts.push(text)
52+
console.log(`Command ${i + 1}: ${text}`)
53+
} catch (e) {
54+
console.log(`Could not get text for command ${i + 1}`)
55+
}
56+
}
57+
58+
if (menuItems.length > 0) {
59+
console.log(`Clicking on command: ${menuTexts[0] || 'unknown'}`)
60+
await menuItems[0].click()
61+
62+
// wait for the command to process
63+
await new Promise((resolve) => setTimeout(resolve, 3000))
64+
console.log('Command clicked successfully')
65+
} else {
66+
console.log('No backslash commands found to click')
67+
}
68+
})
69+
})

packages/amazonq/test/e2e_new/amazonq/framework/chatHelper.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ Finds the chat input element using the .mynah-chat-prompt-input CSS selector,
1212
sends the provided prompt test, clicks the send button, and waits for a chat
1313
response. Returns true if successful, throws an error if the response times out */
1414

15-
export async function writeToChat(prompt: string, webview: WebviewView): Promise<boolean> {
15+
export async function writeToChat(prompt: string, webview: WebviewView, send = true): Promise<boolean> {
1616
const chatInput = await waitForElement(webview, By.css('.mynah-chat-prompt-input'))
1717
await chatInput.sendKeys(prompt)
18-
const sendButton = await waitForElement(webview, By.css('.mynah-chat-prompt-button'))
19-
await sendButton.click()
18+
if (send === true) {
19+
const sendButton = await waitForElement(webview, By.css('.mynah-chat-prompt-button'))
20+
await sendButton.click()
21+
}
2022
return true
2123
}
2224

packages/amazonq/test/e2e_new/amazonq/framework/cleanupHelper.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,33 @@ export async function closeAllTabs(webview: WebviewView) {
3232
console.log('Error closing tabs:', error)
3333
}
3434
}
35+
36+
/* Dismiss overlays if they are present.
37+
38+
Logic:
39+
If there are any mynah overlays that still exist, that will interfere with being able to click
40+
any other buttons such as closing chatTabs. Therefore, if you are testing some kind of overlay
41+
it is recommended to call this function in the "AfterEach" block to make sure the overlay doesn't
42+
interfere with any other parts of the test suite */
43+
44+
export async function dismissOverlayIfPresent(webview: WebviewView): Promise<boolean> {
45+
try {
46+
const overlays = await webview.findWebElements(By.css('.mynah-overlay.mynah-overlay-open'))
47+
if (overlays.length > 0) {
48+
console.log('Overlay detected, attempting to dismiss...')
49+
// Use JavaScript executor to click on the body element (outside the overlay)
50+
// This is more reliable than trying to find a specific element to click
51+
const driver = webview.getDriver()
52+
await driver.executeScript('document.body.click()')
53+
54+
// Wait briefly and check if overlay is gone
55+
await new Promise((resolve) => setTimeout(resolve, 1000))
56+
const overlaysAfter = await webview.findWebElements(By.css('.mynah-overlay.mynah-overlay-open'))
57+
return overlaysAfter.length === 0
58+
}
59+
return true // No overlay to dismiss
60+
} catch (e) {
61+
console.log('Error while trying to dismiss overlay:', e)
62+
return false
63+
}
64+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ export interface TestContext {
99
webviewView?: WebviewView
1010
}
1111

12-
// arr to store shared context
12+
// array to store shared context
1313
export const testContext: TestContext = {}

0 commit comments

Comments
 (0)