Skip to content

Commit 8987bf5

Browse files
fix(amazonq): Fix Quick Actions Test Suite (#7930)
## Problem There were some CSS changes to the quick actions menu which caused the old test suite to break. ## Solution This change fixes the CSS to match the new quick actions menu, and rewrites the tests to utilize the current Quick Actions commands --- - 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. Co-authored-by: Boyu <[email protected]>
1 parent 0e68c8b commit 8987bf5

File tree

2 files changed

+39
-29
lines changed

2 files changed

+39
-29
lines changed

packages/amazonq/test/e2e_new/amazonq/helpers/quickActionsHelper.ts

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*/
55

66
import { By, WebElement, WebviewView } from 'vscode-extension-tester'
7-
import { writeToChat } from '../utils/generalUtils'
8-
import { sleep, waitForElements } from '../utils/generalUtils'
7+
import { waitForElement, writeToChat } from '../utils/generalUtils'
8+
import { sleep } from '../utils/generalUtils'
99

1010
/**
1111
* Gets all quick action command menu items
@@ -14,21 +14,20 @@ import { sleep, waitForElements } from '../utils/generalUtils'
1414
*/
1515
export async function getQuickActionsCommands(webview: WebviewView): Promise<{ items: WebElement[]; texts: string[] }> {
1616
await writeToChat('/', webview, false)
17+
// need to give the overlay time to load
1718
await sleep(2000)
18-
19-
const menuItems = await waitForElements(
20-
webview,
21-
By.css('.mynah-detailed-list-item.mynah-ui-clickable-item.target-command'),
22-
10000
23-
)
24-
25-
const menuTexts = []
26-
for (let i = 0; i < menuItems.length; i++) {
27-
const text = await menuItems[i].getText()
28-
menuTexts.push(text)
19+
const overlayWrapper = await waitForElement(webview, By.css('.mynah-chat-prompt-quick-picks-overlay-wrapper'))
20+
const quickActionItems = await overlayWrapper.findElements(By.css('[data-testid="prompt-input-quick-pick-item"]'))
21+
if (quickActionItems.length === 0) {
22+
throw new Error('No quick action commands found')
23+
}
24+
const quickActionTexts = []
25+
for (const item of quickActionItems) {
26+
const text = await item.findElement(By.css('.mynah-detailed-list-item-name')).getText()
27+
quickActionTexts.push(text)
2928
}
3029

31-
return { items: menuItems, texts: menuTexts }
30+
return { items: quickActionItems, texts: quickActionTexts }
3231
}
3332

3433
/**
@@ -37,15 +36,24 @@ export async function getQuickActionsCommands(webview: WebviewView): Promise<{ i
3736
* @param commandName The name of the command to click
3837
*/
3938
export async function clickQuickActionsCommand(webview: WebviewView, commandName: string): Promise<void> {
40-
const { items, texts } = await getQuickActionsCommands(webview)
41-
if (items.length === 0) {
39+
await writeToChat('/', webview, false)
40+
// need to give the overlay time to load
41+
await sleep(2000)
42+
const overlayWrapper = await waitForElement(webview, By.css('.mynah-chat-prompt-quick-picks-overlay-wrapper'))
43+
const quickActionItems = await overlayWrapper.findElements(By.css('[data-testid="prompt-input-quick-pick-item"]'))
44+
if (quickActionItems.length === 0) {
4245
throw new Error('No quick action commands found')
4346
}
44-
const indexToClick = texts.findIndex((text) => text === commandName)
4547

46-
if (indexToClick === -1) {
47-
throw new Error(`Command "${commandName}" not found`)
48+
for (const item of quickActionItems) {
49+
const descriptionElement = await item.findElement(By.css('.mynah-detailed-list-item-name'))
50+
const description = await descriptionElement.getText()
51+
if (description.includes(commandName)) {
52+
await item.click()
53+
await sleep(3000)
54+
return
55+
}
4856
}
49-
await items[indexToClick].click()
50-
await sleep(3000)
57+
58+
throw new Error(`Command "${commandName}" not found`)
5159
}

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
import '../utils/setup'
66
import { WebviewView } from 'vscode-extension-tester'
7-
import { closeAllTabs, dismissOverlayIfPresent } from '../utils/cleanupUtils'
7+
import { closeAllTabs } from '../utils/cleanupUtils'
88
import { testContext } from '../utils/testContext'
99
import { clickQuickActionsCommand } from '../helpers/quickActionsHelper'
1010
import { clearChatInput } from '../utils/generalUtils'
@@ -18,17 +18,19 @@ describe('Amazon Q Chat Quick Actions Functionality', function () {
1818
webviewView = testContext.webviewView
1919
})
2020

21-
after(async function () {
21+
afterEach(async () => {
2222
await closeAllTabs(webviewView)
2323
})
2424

25-
afterEach(async () => {
26-
// before closing the tabs, make sure that any overlays have been dismissed
27-
await dismissOverlayIfPresent(webviewView)
25+
it('/help Test', async () => {
26+
await clickQuickActionsCommand(webviewView, '/help')
2827
await clearChatInput(webviewView)
2928
})
30-
31-
it('Quick Actions Test', async () => {
32-
await clickQuickActionsCommand(webviewView, 'dev')
29+
it('/clear Test', async () => {
30+
await clickQuickActionsCommand(webviewView, '/clear')
31+
})
32+
it('/compact Test', async () => {
33+
await clickQuickActionsCommand(webviewView, '/compact')
34+
await clearChatInput(webviewView)
3335
})
3436
})

0 commit comments

Comments
 (0)