-
Notifications
You must be signed in to change notification settings - Fork 682
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
base: feature/ui-e2e-tests
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
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') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
}) | ||
}) |
There was a problem hiding this comment.
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?