Skip to content

Commit 8c3a109

Browse files
committed
implementing a pin context test suite with all the abstractions in pinContextHelper
1 parent 3723e0d commit 8c3a109

File tree

2 files changed

+140
-0
lines changed

2 files changed

+140
-0
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
import { By, WebviewView } from 'vscode-extension-tester'
6+
import { waitForElement } from './generalHelper'
7+
import { WebElement } from 'vscode-extension-tester'
8+
9+
/**
10+
* Clicks the "Pin Context" button in the chat interface
11+
* @param webview The WebviewView instance
12+
* @returns Promise<boolean> True if button was found and clicked, false otherwise
13+
*/
14+
export async function clickPinContextButton(webview: WebviewView): Promise<boolean> {
15+
try {
16+
const topBar = await waitForElement(webview, By.css('.mynah-prompt-input-top-bar'))
17+
const buttons = await topBar.findElements(
18+
By.css('.mynah-button.mynah-button-secondary.fill-state-always.status-clear.mynah-ui-clickable-item')
19+
)
20+
// double check the label to make sure it says "Pin Context"
21+
for (const button of buttons) {
22+
const label = await button.findElement(By.css('.mynah-button-label'))
23+
const labelText = await label.getText()
24+
console.log('THE BUTTON TEXT LABEL IS:', labelText)
25+
if (labelText === '@Pin Context') {
26+
console.log('Found Pin Context button, clicking...')
27+
await button.click()
28+
return true
29+
}
30+
}
31+
console.log('Pin Context button not found')
32+
return false
33+
} catch (e) {
34+
console.error('Error clicking Pin Context button:', e)
35+
return false
36+
}
37+
}
38+
39+
/**
40+
* Lists all the possible Pin Context menu items in the console.
41+
* @param webview The WebviewView instance
42+
* @returns Promise<boolean> Returns the items as a WebElement List and the labels in a string array
43+
*/
44+
export async function getPinContextMenuItems(webview: WebviewView): Promise<{ items: WebElement[]; labels: string[] }> {
45+
try {
46+
const menuList = await waitForElement(webview, By.css('.mynah-detailed-list-items-block'))
47+
await new Promise((resolve) => setTimeout(resolve, 3000))
48+
const menuListItems = await menuList.findElements(By.css('.mynah-detailed-list-item.mynah-ui-clickable-item'))
49+
const labels: string[] = []
50+
51+
for (const item of menuListItems) {
52+
try {
53+
const textWrapper = await item.findElement(By.css('.mynah-detailed-list-item-text'))
54+
const nameElement = await textWrapper.findElement(By.css('.mynah-detailed-list-item-name'))
55+
const labelText = await nameElement.getText()
56+
labels.push(labelText)
57+
console.log('Menu item found:', labelText)
58+
} catch (e) {
59+
labels.push('')
60+
console.log('Could not get text for menu item')
61+
}
62+
}
63+
64+
return { items: menuListItems, labels }
65+
} catch (e) {
66+
console.error('Error getting Pin Context menu items:', e)
67+
return { items: [], labels: [] }
68+
}
69+
}
70+
71+
/**
72+
* Clicks a specific item in the Pin Context menu by its label text
73+
* @param webview The WebviewView instance
74+
* @param itemName The text label of the menu item to click
75+
* @returns Promise<boolean> True if the item was found and clicked, false otherwise
76+
*
77+
* NOTE: To find all possible text labels, you can call getPinContextMenuItems
78+
*/
79+
export async function clickPinContextMenuItem(webview: WebviewView, itemName: string): Promise<boolean> {
80+
try {
81+
// Find the menu list independently
82+
const menuList = await waitForElement(webview, By.css('.mynah-detailed-list-items-block'))
83+
await new Promise((resolve) => setTimeout(resolve, 3000))
84+
const menuListItems = await menuList.findElements(By.css('.mynah-detailed-list-item.mynah-ui-clickable-item'))
85+
// Iterate through items to find the one with matching text
86+
for (const item of menuListItems) {
87+
try {
88+
const textWrapper = await item.findElement(By.css('.mynah-detailed-list-item-text'))
89+
const nameElement = await textWrapper.findElement(By.css('.mynah-detailed-list-item-name'))
90+
const labelText = await nameElement.getText()
91+
92+
if (labelText === itemName) {
93+
console.log(`Clicking Pin Context menu item: ${itemName}`)
94+
await item.click()
95+
return true
96+
}
97+
} catch (e) {
98+
// Continue to next item if this one has issues
99+
continue
100+
}
101+
}
102+
103+
console.log(`Pin Context menu item not found: ${itemName}`)
104+
return false
105+
} catch (e) {
106+
console.error(`Error clicking Pin Context menu item ${itemName}:`, e)
107+
return false
108+
}
109+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 { WebviewView } from 'vscode-extension-tester'
7+
import { closeAllTabs, dismissOverlayIfPresent } from './framework/cleanupHelper'
8+
import { testContext } from './utils/testContext'
9+
import { clickPinContextButton, getPinContextMenuItems, clickPinContextMenuItem } from './framework/pinContextHelper'
10+
11+
describe('Amazon Q Pin Context Functionality', function () {
12+
// this timeout is the general timeout for the entire test suite
13+
this.timeout(150000)
14+
let webviewView: WebviewView
15+
16+
before(async function () {
17+
webviewView = testContext.webviewView!
18+
})
19+
after(async () => {
20+
await closeAllTabs(webviewView)
21+
})
22+
afterEach(async () => {
23+
await dismissOverlayIfPresent(webviewView)
24+
})
25+
26+
it('Pin Context Test', async () => {
27+
await clickPinContextButton(webviewView)
28+
await getPinContextMenuItems(webviewView)
29+
await clickPinContextMenuItem(webviewView, '@workspace')
30+
})
31+
})

0 commit comments

Comments
 (0)