Skip to content

Commit ac7cdc6

Browse files
committed
some initial implementation, and a gitignore fix, as well as a testFileFolder
1 parent 0cb1eb3 commit ac7cdc6

File tree

4 files changed

+82
-34
lines changed

4 files changed

+82
-34
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,5 @@ packages/*/resources/css/icons.css
5757
.vscode-test-web
5858

5959
# Generated by E2E UI Tests
60-
packages/amazonq/test/e2e/amazonq/resources
60+
packages/amazonq/test/e2e/amazonq/resources
61+
packages/amazonq/test/e2e_new/amazonq/resources

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

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,56 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55
import { WebviewView, By } from 'vscode-extension-tester'
6+
import { waitForElement } from '../utils/generalUtils'
67

78
/**
8-
* Clicks the tools to get to the MCP server overlay
9+
* Clicks the Rules button in the top bar
910
* @param webviewView The WebviewView instance
10-
* @returns Promise<boolean> True if tools button was found and clicked, false otherwise
1111
*/
1212
export async function clickRulesButton(webviewView: WebviewView): Promise<void> {
13-
const buttons = await webviewView.findElements(
14-
By.css('.mynah-button.mynah-button-secondary.fill-state-always.status-clear.mynah-ui-clickable-item')
15-
)
16-
for (const button of buttons) {
17-
const span = await button.findElement(By.css('span'))
18-
const text = await span.getText()
19-
if (text === 'Rules') {
20-
await button.click()
21-
return
22-
}
23-
}
24-
throw new Error('Rules button not found')
13+
const wrapper = await webviewView.findElement(By.css('.mynah-chat-prompt-wrapper'))
14+
const topBar = await wrapper.findElement(By.css('.mynah-prompt-input-top-bar'))
15+
console.log('THIS WORKS 1')
16+
const buttons = await topBar.findElement(By.css('[data-testid="prompt-input-top-bar-button"]'))
17+
console.log('THIS WORKS 2')
18+
const button = await buttons.findElement(By.css('*'))
19+
console.log('THIS WORKS 3')
20+
await button.click()
21+
}
22+
23+
/**
24+
* Creates a new rule with the specified name
25+
* @param webviewView The WebviewView instance
26+
* @param ruleName The name of the rule to create (defaults to "testRule")
27+
*/
28+
export async function createRule(webviewView: WebviewView, ruleName: string = 'testRule'): Promise<void> {
29+
const overlay = await waitForElement(webviewView, By.css('[data-testid="prompt-input-top-bar-action-overlay"]'))
30+
const create = overlay.findElement(By.css('[data-testid="prompt-input-quick-pick-item"]'))
31+
await create.click()
32+
const anotheroverlay = await waitForElement(webviewView, By.css('[data-testid="sheet-wrapper"]'))
33+
const input = await anotheroverlay.findElement(By.css('[data-testid="chat-item-form-item-text-input"]'))
34+
await input.sendKeys(ruleName)
35+
await clickCreateRule(webviewView)
36+
}
37+
38+
/**
39+
* Clicks the Create button in the rule creation dialog
40+
* @param webviewView The WebviewView instance
41+
*/
42+
export async function clickCreateRule(webviewView: WebviewView): Promise<void> {
43+
const anotheroverlay = await waitForElement(webviewView, By.css('[data-testid="sheet-wrapper"]'))
44+
const buttonsContainer = await anotheroverlay.findElement(By.css('[data-testid="chat-item-buttons-wrapper"]'))
45+
const button = await buttonsContainer.findElements(By.css('[data-testid="chat-item-action-button"]'))
46+
await button[1].click()
47+
}
48+
49+
/**
50+
* Clicks the Cancel button in the rule creation dialog
51+
* @param webviewView The WebviewView instance
52+
*/
53+
export async function clickCancelRule(webviewView: WebviewView): Promise<void> {
54+
const anotheroverlay = await waitForElement(webviewView, By.css('[data-testid="sheet-wrapper"]'))
55+
const buttonsContainer = await anotheroverlay.findElement(By.css('[data-testid="chat-item-buttons-wrapper"]'))
56+
const button = await buttonsContainer.findElements(By.css('[data-testid="chat-item-action-button"]'))
57+
await button[0].click()
2558
}

packages/amazonq/test/e2e_new/amazonq/tests/rules.test.ts

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,55 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55
import '../utils/setup'
6-
import { WebviewView } from 'vscode-extension-tester'
6+
import {
7+
WebviewView,
8+
VSBrowser,
9+
DefaultTreeSection,
10+
ActivityBar,
11+
SideBarView,
12+
ViewContent,
13+
Workbench,
14+
} from 'vscode-extension-tester'
715
import { closeAllTabs } from '../utils/cleanupUtils'
816
import { testContext } from '../utils/testContext'
9-
import { clickRulesButton } from '../helpers/rulesHelper'
10-
import { sleep } from '../utils/generalUtils'
17+
import * as path from 'path'
18+
import { clickRulesButton, createRule } from '../helpers/rulesHelper'
1119

1220
describe('Amazon Q Rules Functionality', function () {
1321
// this timeout is the general timeout for the entire test suite
1422
this.timeout(150000)
1523
let webviewView: WebviewView
24+
let tree: DefaultTreeSection
25+
let content: ViewContent
26+
let workbench: Workbench
1627

1728
before(async function () {
29+
// switch out of the webview (we assume that the last test was a webview test)
1830
webviewView = testContext.webviewView
31+
await webviewView.switchBack()
32+
33+
// in order to access rules you must have at least 1 folder
34+
await VSBrowser.instance.openResources(path.join('..', 'utils', 'resources', 'testFolder'))
35+
;(await new ActivityBar().getViewControl('Explorer'))?.openView()
36+
const view = new SideBarView()
37+
content = view.getContent()
38+
tree = (await content.getSection('testFolder')) as DefaultTreeSection
39+
await tree.openItem('test-folder')
40+
41+
// once the folder is opened, we switch back to the amazonQ webview
42+
workbench = testContext.workbench
43+
await workbench.executeCommand('Amazon Q: Open Chat')
44+
webviewView = new WebviewView()
45+
await webviewView.switchToFrame()
46+
testContext.webviewView = webviewView
1947
})
2048

2149
after(async function () {
2250
await closeAllTabs(webviewView)
2351
})
2452

25-
afterEach(async () => {})
26-
27-
it('Rules Test', async () => {
28-
/**
29-
* TODO abstractions
30-
*
31-
* click the rules button DONE
32-
* list all the possible rules (disappearing overlay again UGH)
33-
* check and uncheck a rule
34-
* click create new rule
35-
* enter rule name
36-
* click create rule
37-
* click cancel rule
38-
*/
53+
it('Rules Option Test', async () => {
3954
await clickRulesButton(webviewView)
40-
41-
await sleep(5000)
55+
await createRule(webviewView)
4256
})
4357
})

packages/amazonq/test/e2e_new/amazonq/utils/resources/testFolder/testFile

Whitespace-only changes.

0 commit comments

Comments
 (0)