Skip to content

feat(amazonq): Add Pin Context Tests and Update to pinContextHelper #7829

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: feature/ui-e2e-tests
Choose a base branch
from
Open
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 @@ -104,3 +104,74 @@ export async function clickPinContextMenuItem(webview: WebviewView, itemName: st
return false
}
}
/**
* Lists all the possible Sub-menu items in the console.
* @param webview The WebviewView instance
* @returns Promise<boolean> Returns the items as a WebElement List and the labels in a string array
*/
export async function getSubMenuItems(webview: WebviewView): Promise<{ items: WebElement[]; labels: string[] }> {
try {
const menuList = await waitForElement(webview, By.css('.mynah-detailed-list-items-block'))
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.

Why is this additional sleep needed?

const menuListItems = await menuList.findElements(By.css('.mynah-detailed-list-item.mynah-ui-clickable-item'))
const labels: string[] = []

for (const item of menuListItems) {
try {
const textWrapper = await item.findElement(
By.css('.mynah-detailed-list-item-text.mynah-detailed-list-item-text-direction-row')
)
const nameElement = await textWrapper.findElement(By.css('.mynah-detailed-list-item-name'))
const labelText = await nameElement.getText()
labels.push(labelText)
console.log('Menu item found:', labelText)
} catch (e) {
labels.push('')
console.log('Could not get text for menu item')
Copy link
Contributor

Choose a reason for hiding this comment

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

should we fail here? If we can't find an item in the menu isn't that indicative of a bug?

}
}

return { items: menuListItems, labels }
} catch (e) {
console.error('Error getting Pin Context menu items:', e)
Copy link
Contributor

Choose a reason for hiding this comment

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

same question here.

return { items: [], labels: [] }
}
}
/**
* Clicks a specific item in the Sub-Menu by its label text
* @param webview The WebviewView instance
* @param itemName The text label of the menu item to click
* @returns Promise<boolean> True if the item was found and clicked, false otherwise
*
* NOTE: To find all possible text labels, you can call getPinContextMenuItems
*/
export async function clickSubMenuItem(webview: WebviewView, itemName: string): Promise<boolean> {
try {
const menuList = await waitForElement(webview, By.css('.mynah-detailed-list-items-block'))
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.

Why is this sleep needed? Shouldn't it be covered by waitForElement?

const menuListItems = await menuList.findElements(By.css('.mynah-detailed-list-item.mynah-ui-clickable-item'))
for (const item of menuListItems) {
try {
const textWrapper = await item.findElement(
By.css('.mynah-detailed-list-item-text.mynah-detailed-list-item-text-direction-row')
)
const nameElement = await textWrapper.findElement(By.css('.mynah-detailed-list-item-name'))
const labelText = await nameElement.getText()

if (labelText === itemName) {
console.log(`Clicking Pin Context menu item: ${itemName}`)
await item.click()
return true
}
} catch (e) {
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

same question as above about errors.

}
}

console.log(`Pin Context menu item not found: ${itemName}`)
return false
} catch (e) {
console.error(`Error clicking Pin Context menu item ${itemName}:`, e)
Copy link
Contributor

Choose a reason for hiding this comment

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

If this fails I think we should throw instead of returning a boolean.

return false
}
}
35 changes: 25 additions & 10 deletions packages/amazonq/test/e2e_new/amazonq/tests/pinContext.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* SPDX-License-Identifier: Apache-2.0
*/
import '../utils/setup'
import { WebviewView } from 'vscode-extension-tester'
import { WebviewView, By } from 'vscode-extension-tester'
import { closeAllTabs, dismissOverlayIfPresent } from '../utils/cleanupUtils'
import { testContext } from '../utils/testContext'
import { clickPinContextButton, getPinContextMenuItems, clickPinContextMenuItem } from '../helpers/pinContextHelper'
import { clearChat } from '../utils/generalUtils'
import { clickPinContextButton, clickPinContextMenuItem, clickSubMenuItem } from '../helpers/pinContextHelper'
import { waitForElement } from '../utils/generalUtils'

describe('Amazon Q Pin Context Functionality', function () {
// this timeout is the general timeout for the entire test suite
Expand All @@ -18,18 +18,33 @@ describe('Amazon Q Pin Context Functionality', function () {
webviewView = testContext.webviewView
})

after(async function () {
await closeAllTabs(webviewView)
})

afterEach(async () => {
await dismissOverlayIfPresent(webviewView)
await clearChat(webviewView)
await closeAllTabs(webviewView)
})
it('File Context Test', async () => {
await clickPinContextButton(webviewView)
await clickPinContextMenuItem(webviewView, 'Files')
await clickPinContextMenuItem(webviewView, 'Active file')
})

it('Pin Context Test', async () => {
await clickPinContextButton(webviewView)
await getPinContextMenuItems(webviewView)
await clickPinContextMenuItem(webviewView, '@workspace')
})
it('Prompts Context Test', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

same idea before on test labels.

await clickPinContextButton(webviewView)
await clickPinContextMenuItem(webviewView, 'Prompts')
const addPrompt = await waitForElement(webviewView, By.css('.mynah-ui-icon.mynah-ui-icon-list-add'))
await addPrompt.click()
const chatInput = await waitForElement(webviewView, By.css('[data-testid="chat-item-form-item-text-input"]'))
await chatInput.sendKeys('test')
const createPrompt = await waitForElement(
webviewView,
By.css('.mynah-button.fill-state-always.status-primary.mynah-ui-clickable-item')
)
await createPrompt.click()
await clickPinContextButton(webviewView)
await clickPinContextMenuItem(webviewView, 'Prompts')
await clickSubMenuItem(webviewView, 'test')
Copy link
Contributor

Choose a reason for hiding this comment

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

my understanding is that this returns a boolean false if it fails, but this won't cause the test to fail.

})
})
Loading