Skip to content

Commit 0d4a2b6

Browse files
committed
fixing PR comments
1 parent 60fc14c commit 0d4a2b6

File tree

1 file changed

+30
-53
lines changed

1 file changed

+30
-53
lines changed

packages/amazonq/test/e2e_new/amazonq/helpers/mcpHelper.ts

Lines changed: 30 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { waitForElement } from '../utils/generalUtils'
1010
* @param webviewView The WebviewView instance
1111
* @returns Promise<boolean> True if tools button was found and clicked, false otherwise
1212
*/
13-
export async function clickToolsButton(webviewView: WebviewView): Promise<boolean> {
13+
export async function clickToolsButton(webviewView: WebviewView): Promise<void> {
1414
try {
1515
const navWrapper = await waitForElement(webviewView, By.css('.mynah-nav-tabs-wrapper.mynah-ui-clickable-item'))
1616
const buttonsWrapper = await navWrapper.findElement(By.css('.mynah-nav-tabs-bar-buttons-wrapper'))
@@ -22,14 +22,11 @@ export async function clickToolsButton(webviewView: WebviewView): Promise<boolea
2222
if (icon) {
2323
await button.click()
2424
await webviewView.getDriver().actions().move({ x: 0, y: 0 }).perform()
25-
return true
2625
}
2726
}
2827
console.log('Tools button not found')
29-
return false
3028
} catch (e) {
3129
console.error('Error clicking tools button:', e)
32-
return false
3330
}
3431
}
3532

@@ -38,17 +35,15 @@ export async function clickToolsButton(webviewView: WebviewView): Promise<boolea
3835
* @param webviewView The WebviewView instance
3936
* @returns Promise<boolean> True if add button was found and clicked, false otherwise
4037
*/
41-
export async function clickMCPAddButton(webviewView: WebviewView): Promise<boolean> {
38+
export async function clickMCPAddButton(webviewView: WebviewView): Promise<void> {
4239
try {
4340
const sheetWrapper = await waitForElement(webviewView, By.id('mynah-sheet-wrapper'))
4441
const header = await sheetWrapper.findElement(By.css('.mynah-sheet-header'))
4542
const actionsContainer = await header.findElement(By.css('.mynah-sheet-header-actions-container'))
4643
const addButton = await actionsContainer.findElement(By.css('button:has(i.mynah-ui-icon-plus)'))
4744
await addButton.click()
48-
return true
4945
} catch (e) {
5046
console.error('Error clicking the MCP add button:', e)
51-
return false
5247
}
5348
}
5449

@@ -65,8 +60,7 @@ interface MCPServerConfig {
6560
transport?: number
6661
command?: string
6762
args?: string[]
68-
nameEnvironmentVariable?: string
69-
valueEnvironmentVariable?: string
63+
environmentVariable?: { name: string; value: string }
7064
timeout?: number
7165
}
7266

@@ -76,11 +70,10 @@ const defaultConfig: MCPServerConfig = {
7670
transport: 0,
7771
command: 'uvx',
7872
args: ['awslabs.aws-documentation-mcp-server@latest'],
79-
nameEnvironmentVariable: 'hi',
80-
valueEnvironmentVariable: 'hi',
8173
timeout: 0,
8274
}
8375

76+
// Each name maps to an index in the '.mynah-form-input-wrapper' array
8477
const formItemsMap = {
8578
SCOPE: 0,
8679
NAME: 1,
@@ -95,13 +88,15 @@ type McpFormItem = keyof typeof formItemsMap
9588

9689
async function selectScope(container: WebElement, scope: string) {
9790
try {
98-
const a = await container.findElements(By.css('.mynah-form-input-radio-label.mynah-ui-clickable-item'))
91+
const radioLabels = await container.findElements(
92+
By.css('.mynah-form-input-radio-label.mynah-ui-clickable-item')
93+
)
9994
if (scope === 'global') {
100-
const b = a[0]
101-
await b.click()
95+
const globalOption = radioLabels[0]
96+
await globalOption.click()
10297
} else {
103-
const b = a[1]
104-
await b.click()
98+
const workspaceOption = radioLabels[1]
99+
await workspaceOption.click()
105100
}
106101
} catch (e) {
107102
console.error('Error selecting the scope:', e)
@@ -111,7 +106,7 @@ async function selectScope(container: WebElement, scope: string) {
111106

112107
async function inputName(container: WebElement, name: string) {
113108
try {
114-
const input = container.findElement(By.css('.mynah-form-input'))
109+
const input = await container.findElement(By.css('.mynah-form-input'))
115110
await input.sendKeys(name)
116111
} catch (e) {
117112
console.error('Error inputing the name:', e)
@@ -133,7 +128,7 @@ async function selectTransport(container: WebElement, transport: number) {
133128

134129
async function inputCommand(container: WebElement, command: string) {
135130
try {
136-
const input = container.findElement(By.css('.mynah-form-input'))
131+
const input = await container.findElement(By.css('.mynah-form-input'))
137132
await input.sendKeys(command)
138133
} catch (e) {
139134
console.error('Error inputing the command:', e)
@@ -143,12 +138,8 @@ async function inputCommand(container: WebElement, command: string) {
143138

144139
async function inputArgs(container: WebElement, args: string[]) {
145140
try {
146-
const input = container.findElement(By.css('.mynah-form-input'))
147-
const addButton = container.findElement(
148-
By.css(
149-
'.mynah-button.mynah-button-secondary.fill-state-always.mynah-form-item-list-row-remove-button.mynah-ui-clickable-item'
150-
)
151-
)
141+
const input = await container.findElement(By.css('.mynah-form-input'))
142+
const addButton = await container.findElement(By.css('.mynah-form-item-list-add-button'))
152143
for (let i = 0; i < args.length; i++) {
153144
await input.sendKeys(args[i])
154145
await addButton.click()
@@ -159,16 +150,12 @@ async function inputArgs(container: WebElement, args: string[]) {
159150
}
160151
}
161152

162-
async function inputEnvironmentVariables(
163-
container: WebElement,
164-
nameEnvironmentVariable?: string,
165-
valueEnvironmentVariable?: string
166-
) {
153+
async function inputEnvironmentVariables(container: WebElement, environmentVariable?: { name: string; value: string }) {
167154
try {
168-
if (nameEnvironmentVariable && valueEnvironmentVariable) {
169-
const a = await container.findElements(By.css('.mynah-form-input'))
170-
await a[0].sendKeys(nameEnvironmentVariable)
171-
await a[1].sendKeys(valueEnvironmentVariable)
155+
if (environmentVariable) {
156+
const envInputs = await container.findElements(By.css('.mynah-form-input'))
157+
await envInputs[0].sendKeys(environmentVariable.name)
158+
await envInputs[1].sendKeys(environmentVariable.value)
172159
const addButton = await container.findElement(By.css('.mynah-form-item-list-add-button'))
173160
await addButton.click()
174161
} else {
@@ -182,16 +169,16 @@ async function inputEnvironmentVariables(
182169

183170
async function inputTimeout(container: WebElement, timeout: number) {
184171
try {
185-
const input = container.findElement(By.css('.mynah-form-input'))
172+
const input = await container.findElement(By.css('.mynah-form-input'))
186173
await input.clear()
187-
await input.sendKeys(timeout)
174+
await input.sendKeys(timeout.toString())
188175
} catch (e) {
189176
console.error('Error inputing the timeout:', e)
190177
throw e
191178
}
192179
}
193180

194-
async function processFormItems(mcpFormItem: McpFormItem, container: WebElement, config: MCPServerConfig) {
181+
async function processFormItem(mcpFormItem: McpFormItem, container: WebElement, config: MCPServerConfig) {
195182
switch (mcpFormItem) {
196183
case 'SCOPE':
197184
await selectScope(container, config.scope!)
@@ -209,15 +196,15 @@ async function processFormItems(mcpFormItem: McpFormItem, container: WebElement,
209196
await inputArgs(container, config.args!)
210197
break
211198
case 'ENV_VARS':
212-
await inputEnvironmentVariables(container, config.nameEnvironmentVariable, config.valueEnvironmentVariable)
199+
await inputEnvironmentVariables(container, config.environmentVariable)
213200
break
214201
case 'TIMEOUT':
215202
await inputTimeout(container, config.timeout!)
216203
break
217204
}
218205
}
219206

220-
export async function configureMCPServer(webviewView: WebviewView, config: MCPServerConfig = {}): Promise<boolean> {
207+
export async function configureMCPServer(webviewView: WebviewView, config: MCPServerConfig = {}): Promise<void> {
221208
const mergedConfig = { ...defaultConfig, ...config }
222209
try {
223210
const sheetWrapper = await waitForElement(webviewView, By.id('mynah-sheet-wrapper'))
@@ -228,17 +215,15 @@ export async function configureMCPServer(webviewView: WebviewView, config: MCPSe
228215

229216
for (const [formItem, index] of Object.entries(formItemsMap)) {
230217
if (index < items.length) {
231-
await processFormItems(formItem as McpFormItem, items[index], mergedConfig)
218+
await processFormItem(formItem as McpFormItem, items[index], mergedConfig)
232219
}
233220
}
234-
return true
235221
} catch (e) {
236222
console.log('Error configuring the MCP Server')
237-
return false
238223
}
239224
}
240225

241-
export async function saveMCPServerConfiguration(webviewView: WebviewView): Promise<boolean> {
226+
export async function saveMCPServerConfiguration(webviewView: WebviewView): Promise<void> {
242227
try {
243228
const sheetWrapper = await waitForElement(webviewView, By.id('mynah-sheet-wrapper'))
244229
const body = await sheetWrapper.findElement(By.css('.mynah-sheet-body'))
@@ -247,14 +232,12 @@ export async function saveMCPServerConfiguration(webviewView: WebviewView): Prom
247232
By.css('.mynah-button.fill-state-always.status-primary.mynah-ui-clickable-item')
248233
)
249234
await saveButton.click()
250-
return true
251235
} catch (e) {
252236
console.error('Error saving the MCP server configuration:', e)
253-
return false
254237
}
255238
}
256239

257-
export async function cancelMCPServerConfiguration(webviewView: WebviewView): Promise<boolean> {
240+
export async function cancelMCPServerConfiguration(webviewView: WebviewView): Promise<void> {
258241
try {
259242
const sheetWrapper = await waitForElement(webviewView, By.id('mynah-sheet-wrapper'))
260243
const body = await sheetWrapper.findElement(By.css('.mynah-sheet-body'))
@@ -263,10 +246,8 @@ export async function cancelMCPServerConfiguration(webviewView: WebviewView): Pr
263246
By.css('.mynah-button.mynah-button-secondary.mynah-button-border.fill-state-always.mynah-ui-clickable-item')
264247
)
265248
await saveButton.click()
266-
return true
267249
} catch (e) {
268250
console.error('Error saving the MCP server configuration:', e)
269-
return false
270251
}
271252
}
272253

@@ -275,17 +256,15 @@ export async function cancelMCPServerConfiguration(webviewView: WebviewView): Pr
275256
* @param webviewView The WebviewView instance
276257
* @returns Promise<boolean> True if refresh button was found and clicked, false otherwise
277258
*/
278-
export async function clickMCPRefreshButton(webviewView: WebviewView): Promise<boolean> {
259+
export async function clickMCPRefreshButton(webviewView: WebviewView): Promise<void> {
279260
try {
280261
const sheetWrapper = await waitForElement(webviewView, By.id('mynah-sheet-wrapper'))
281262
const header = await sheetWrapper.findElement(By.css('.mynah-sheet-header'))
282263
const actionsContainer = await header.findElement(By.css('.mynah-sheet-header-actions-container'))
283264
const refreshButton = await actionsContainer.findElement(By.css('button:has(i.mynah-ui-icon-refresh)'))
284265
await refreshButton.click()
285-
return true
286266
} catch (e) {
287267
console.error('Error clicking the MCP refresh button:', e)
288-
return false
289268
}
290269
}
291270

@@ -294,15 +273,13 @@ export async function clickMCPRefreshButton(webviewView: WebviewView): Promise<b
294273
* @param webviewView The WebviewView instance
295274
* @returns Promise<boolean> True if close button was found and clicked, false otherwise
296275
*/
297-
export async function clickMCPCloseButton(webviewView: WebviewView): Promise<boolean> {
276+
export async function clickMCPCloseButton(webviewView: WebviewView): Promise<void> {
298277
try {
299278
const sheetWrapper = await waitForElement(webviewView, By.id('mynah-sheet-wrapper'))
300279
const header = await sheetWrapper.findElement(By.css('.mynah-sheet-header'))
301280
const cancelButton = await header.findElement(By.css('button:has(i.mynah-ui-icon-cancel)'))
302281
await webviewView.getDriver().executeScript('arguments[0].click()', cancelButton)
303-
return true
304282
} catch (e) {
305283
console.error('Error closing the MCP overlay:', e)
306-
return false
307284
}
308285
}

0 commit comments

Comments
 (0)