Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*/

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

/**
* Gets all quick action command menu items
Expand All @@ -14,21 +14,20 @@ import { sleep, waitForElements } from '../utils/generalUtils'
*/
export async function getQuickActionsCommands(webview: WebviewView): Promise<{ items: WebElement[]; texts: string[] }> {
await writeToChat('/', webview, false)
// need to give the overlay time to load
await sleep(2000)

const menuItems = await waitForElements(
webview,
By.css('.mynah-detailed-list-item.mynah-ui-clickable-item.target-command'),
10000
)

const menuTexts = []
for (let i = 0; i < menuItems.length; i++) {
const text = await menuItems[i].getText()
menuTexts.push(text)
const overlayWrapper = await waitForElement(webview, By.css('.mynah-chat-prompt-quick-picks-overlay-wrapper'))
const quickActionItems = await overlayWrapper.findElements(By.css('[data-testid="prompt-input-quick-pick-item"]'))
if (quickActionItems.length === 0) {
throw new Error('No quick action commands found')
}
const quickActionTexts = []
for (const item of quickActionItems) {
const text = await item.findElement(By.css('.mynah-detailed-list-item-name')).getText()
quickActionTexts.push(text)
}

return { items: menuItems, texts: menuTexts }
return { items: quickActionItems, texts: quickActionTexts }
}

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

if (indexToClick === -1) {
throw new Error(`Command "${commandName}" not found`)
for (const item of quickActionItems) {
const descriptionElement = await item.findElement(By.css('.mynah-detailed-list-item-name'))
const description = await descriptionElement.getText()
if (description.includes(commandName)) {
await item.click()
await sleep(3000)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be worth adding a comment of why this is needed.

return
}
}
await items[indexToClick].click()
await sleep(3000)

throw new Error(`Command "${commandName}" not found`)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
import '../utils/setup'
import { WebviewView } from 'vscode-extension-tester'
import { closeAllTabs, dismissOverlayIfPresent } from '../utils/cleanupUtils'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we should fix the dismissOverlayIfPresent or is it not needed anymore?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I think we should probably just delete the code for it until we find a better way to implement it, I'll make that change

import { closeAllTabs } from '../utils/cleanupUtils'
import { testContext } from '../utils/testContext'
import { clickQuickActionsCommand } from '../helpers/quickActionsHelper'
import { clearChatInput } from '../utils/generalUtils'
Expand All @@ -18,17 +18,19 @@ describe('Amazon Q Chat Quick Actions Functionality', function () {
webviewView = testContext.webviewView
})

after(async function () {
afterEach(async () => {
await closeAllTabs(webviewView)
})

afterEach(async () => {
// before closing the tabs, make sure that any overlays have been dismissed
await dismissOverlayIfPresent(webviewView)
it('/help Test', async () => {
await clickQuickActionsCommand(webviewView, '/help')
await clearChatInput(webviewView)
})

it('Quick Actions Test', async () => {
await clickQuickActionsCommand(webviewView, 'dev')
it('/clear Test', async () => {
await clickQuickActionsCommand(webviewView, '/clear')
})
it('/compact Test', async () => {
await clickQuickActionsCommand(webviewView, '/compact')
await clearChatInput(webviewView)
})
})
Loading