44 */
55
66import { 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 */
1515export 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 */
3938export 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}
0 commit comments