3
3
* SPDX-License-Identifier: Apache-2.0
4
4
*/
5
5
import { WebviewView , By , WebElement } from 'vscode-extension-tester'
6
- import { waitForElement } from '../utils/generalUtils'
6
+ import { clickButton , waitForElement } from '../utils/generalUtils'
7
+ import { dismissOverlayIfPresent } from '../utils/cleanupUtils'
7
8
8
9
/**
9
10
* Clicks the tools to get to the MCP server overlay
10
11
* @param webviewView The WebviewView instance
11
12
* @returns Promise<boolean> True if tools button was found and clicked, false otherwise
12
13
*/
13
14
export async function clickToolsButton ( webviewView : WebviewView ) : Promise < void > {
14
- try {
15
- const navWrapper = await waitForElement ( webviewView , By . css ( '.mynah-nav-tabs-wrapper.mynah-ui-clickable-item' ) )
16
- const buttonsWrapper = await navWrapper . findElement ( By . css ( '.mynah-nav-tabs-bar-buttons-wrapper' ) )
17
- const buttons = await buttonsWrapper . findElements (
18
- By . css ( '.mynah-button.mynah-button-secondary.fill-state-always.mynah-ui-clickable-item' )
19
- )
20
- for ( const button of buttons ) {
21
- const icon = await button . findElement ( By . css ( 'i.mynah-ui-icon.mynah-ui-icon-tools' ) )
22
- if ( icon ) {
23
- await button . click ( )
24
- await webviewView . getDriver ( ) . actions ( ) . move ( { x : 0 , y : 0 } ) . perform ( )
25
- }
26
- }
27
- console . log ( 'Tools button not found' )
28
- } catch ( e ) {
29
- console . error ( 'Error clicking tools button:' , e )
30
- }
15
+ await clickButton (
16
+ webviewView ,
17
+ '[data-testid="tab-bar-buttons-wrapper"]' ,
18
+ '[data-testid="tab-bar-button"] .mynah-ui-icon-tools' ,
19
+ 'tools button'
20
+ )
31
21
}
32
22
33
23
/**
@@ -36,15 +26,7 @@ export async function clickToolsButton(webviewView: WebviewView): Promise<void>
36
26
* @returns Promise<boolean> True if add button was found and clicked, false otherwise
37
27
*/
38
28
export async function clickMCPAddButton ( webviewView : WebviewView ) : Promise < void > {
39
- try {
40
- const sheetWrapper = await waitForElement ( webviewView , By . id ( 'mynah-sheet-wrapper' ) )
41
- const header = await sheetWrapper . findElement ( By . css ( '.mynah-sheet-header' ) )
42
- const actionsContainer = await header . findElement ( By . css ( '.mynah-sheet-header-actions-container' ) )
43
- const addButton = await actionsContainer . findElement ( By . css ( 'button:has(i.mynah-ui-icon-plus)' ) )
44
- await addButton . click ( )
45
- } catch ( e ) {
46
- console . error ( 'Error clicking the MCP add button:' , e )
47
- }
29
+ await clickButton ( webviewView , '.mynah-sheet-header-actions-container' , 'i.mynah-ui-icon-plus' , 'MCP add button' )
48
30
}
49
31
50
32
/**
@@ -225,17 +207,12 @@ export async function configureMCPServer(webviewView: WebviewView, config: MCPSe
225
207
}
226
208
227
209
export async function saveMCPServerConfiguration ( webviewView : WebviewView ) : Promise < void > {
228
- try {
229
- const sheetWrapper = await waitForElement ( webviewView , By . id ( 'mynah-sheet-wrapper' ) )
230
- const body = await sheetWrapper . findElement ( By . css ( '.mynah-sheet-body' ) )
231
- const filterActions = await body . findElement ( By . css ( '.mynah-detailed-list-filter-actions-wrapper' ) )
232
- const saveButton = await filterActions . findElement (
233
- By . css ( '.mynah-button.fill-state-always.status-primary.mynah-ui-clickable-item' )
234
- )
235
- await saveButton . click ( )
236
- } catch ( e ) {
237
- console . error ( 'Error saving the MCP server configuration:' , e )
238
- }
210
+ await clickButton (
211
+ webviewView ,
212
+ '[data-testid="chat-item-action-button"][action-id="save-mcp"]' ,
213
+ 'span.mynah-button-label' ,
214
+ 'save button'
215
+ )
239
216
}
240
217
241
218
export async function cancelMCPServerConfiguration ( webviewView : WebviewView ) : Promise < void > {
@@ -259,13 +236,21 @@ export async function cancelMCPServerConfiguration(webviewView: WebviewView): Pr
259
236
*/
260
237
export async function clickMCPRefreshButton ( webviewView : WebviewView ) : Promise < void > {
261
238
try {
262
- const sheetWrapper = await waitForElement ( webviewView , By . id ( 'mynah-sheet-wrapper' ) )
263
- const header = await sheetWrapper . findElement ( By . css ( '.mynah-sheet-header' ) )
264
- const actionsContainer = await header . findElement ( By . css ( '.mynah-sheet-header-actions-container' ) )
265
- const refreshButton = await actionsContainer . findElement ( By . css ( 'button:has(i.mynah-ui-icon-refresh)' ) )
266
- await refreshButton . click ( )
239
+ // First dismiss any overlay that might be present
240
+ await dismissOverlayIfPresent ( webviewView )
241
+
242
+ await clickButton (
243
+ webviewView ,
244
+ '.mynah-sheet-header-actions-container' ,
245
+ 'i.mynah-ui-icon-refresh' ,
246
+ 'MCP refresh button'
247
+ )
248
+
249
+ // Dismiss any overlay that might appear after clicking
250
+ await dismissOverlayIfPresent ( webviewView )
267
251
} catch ( e ) {
268
252
console . error ( 'Error clicking the MCP refresh button:' , e )
253
+ throw e
269
254
}
270
255
}
271
256
@@ -276,11 +261,10 @@ export async function clickMCPRefreshButton(webviewView: WebviewView): Promise<v
276
261
*/
277
262
export async function clickMCPCloseButton ( webviewView : WebviewView ) : Promise < void > {
278
263
try {
279
- const sheetWrapper = await waitForElement ( webviewView , By . id ( 'mynah-sheet-wrapper' ) )
280
- const header = await sheetWrapper . findElement ( By . css ( '.mynah-sheet-header' ) )
281
- const cancelButton = await header . findElement ( By . css ( 'button:has(i.mynah-ui-icon-cancel)' ) )
282
- await webviewView . getDriver ( ) . executeScript ( 'arguments[0].click()' , cancelButton )
264
+ await dismissOverlayIfPresent ( webviewView )
265
+ await clickButton ( webviewView , '.mynah-sheet-header' , 'i.mynah-ui-icon-cancel' , 'MCP close button' )
283
266
} catch ( e ) {
284
267
console . error ( 'Error closing the MCP overlay:' , e )
268
+ throw e
285
269
}
286
270
}
0 commit comments