|
3 | 3 | * SPDX-License-Identifier: Apache-2.0
|
4 | 4 | */
|
5 | 5 | import { WebviewView, By } from 'vscode-extension-tester'
|
6 |
| -import { waitForElement } from '../utils/generalUtils' |
| 6 | +import { printElementHTML, sleep, waitForElement } from '../utils/generalUtils' |
7 | 7 |
|
8 | 8 | /**
|
9 | 9 | * Clicks the Rules button in the top bar
|
10 |
| - * @param webviewView The WebviewView instance |
| 10 | + * @param webview The WebviewView instance |
11 | 11 | */
|
12 |
| -export async function clickRulesButton(webviewView: WebviewView): Promise<void> { |
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() |
| 12 | +export async function clickRulesButton(webview: WebviewView): Promise<void> { |
| 13 | + const body = await webview.findWebElement(By.css('body')) |
| 14 | + await printElementHTML(body) |
| 15 | + |
| 16 | + const chatPromptWrapper = await waitForElement(webview, By.css('.mynah-chat-prompt-wrapper')) |
| 17 | + const topBar = await chatPromptWrapper.findElement(By.css('[data-testid="prompt-input-top-bar"]')) |
| 18 | + const buttons = await topBar.findElements(By.css('.mynah-button.mynah-button-secondary')) |
| 19 | + |
| 20 | + for (const button of buttons) { |
| 21 | + try { |
| 22 | + const labelElement = await button.findElement(By.css('.mynah-button-label')) |
| 23 | + const text = await labelElement.getText() |
| 24 | + if (text.trim() === 'Rules') { |
| 25 | + await button.click() |
| 26 | + return |
| 27 | + } |
| 28 | + } catch (e) { |
| 29 | + continue |
| 30 | + } |
| 31 | + } |
| 32 | + throw new Error('Rules button not found') |
| 33 | +} |
| 34 | + |
| 35 | +/** |
| 36 | + * Clicks on "Create a new rule" option from the rules menu |
| 37 | + * @param webview The WebviewView instance |
| 38 | + */ |
| 39 | +export async function clickCreateNewRuleOption(webview: WebviewView): Promise<void> { |
| 40 | + // needs a bit of time because the overlay has to load |
| 41 | + await sleep(1000) |
| 42 | + const overlayContainer = await waitForElement(webview, By.css('.mynah-overlay-container')) |
| 43 | + const quickPickItems = await overlayContainer.findElements(By.css('[data-testid="prompt-input-quick-pick-item"]')) |
| 44 | + |
| 45 | + if (quickPickItems.length === 0) { |
| 46 | + throw new Error('No quick pick items found') |
| 47 | + } |
| 48 | + const lastItem = quickPickItems[quickPickItems.length - 1] |
| 49 | + const bdiElement = await lastItem.findElement(By.css('.mynah-detailed-list-item-description.ltr bdi')) |
| 50 | + const text = await bdiElement.getText() |
| 51 | + |
| 52 | + if (text.trim() !== 'Create a new rule') { |
| 53 | + throw new Error(`Expected "Create a new rule" but found "${text}"`) |
| 54 | + } |
| 55 | + await lastItem.click() |
21 | 56 | }
|
22 | 57 |
|
23 | 58 | /**
|
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") |
| 59 | + * Enters a rule name in the rule creation form |
| 60 | + * @param webview The WebviewView instance |
| 61 | + * @param ruleName The name of the rule |
27 | 62 | */
|
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) |
| 63 | +export async function enterRuleName(webview: WebviewView, ruleName: string): Promise<void> { |
| 64 | + // needs a bit of time because the overlay has to load |
| 65 | + await sleep(1000) |
| 66 | + const sheetWrapper = await waitForElement(webview, By.css('[data-testid="sheet-wrapper"]')) |
| 67 | + const ruleNameInput = await sheetWrapper.findElement(By.css('[data-testid="chat-item-form-item-text-input"]')) |
| 68 | + |
| 69 | + await ruleNameInput.clear() |
| 70 | + await ruleNameInput.sendKeys(ruleName) |
| 71 | +} |
| 72 | + |
| 73 | +/** |
| 74 | + * Clicks the Create button in the rule creation form |
| 75 | + * @param webview The WebviewView instance |
| 76 | + */ |
| 77 | +export async function clickCreateButton(webview: WebviewView): Promise<void> { |
| 78 | + const sheetWrapper = await waitForElement(webview, By.css('[data-testid="sheet-wrapper"]')) |
| 79 | + const createButton = await sheetWrapper.findElement(By.xpath('.//button[@action-id="submit-create-rule"]')) |
| 80 | + |
| 81 | + await webview.getDriver().wait( |
| 82 | + async () => { |
| 83 | + const isDisabled = await createButton.getAttribute('disabled') |
| 84 | + return isDisabled === null |
| 85 | + }, |
| 86 | + 5000, |
| 87 | + 'Create button did not become enabled' |
| 88 | + ) |
| 89 | + |
| 90 | + await createButton.click() |
36 | 91 | }
|
37 | 92 |
|
38 | 93 | /**
|
39 |
| - * Clicks the Create button in the rule creation dialog |
40 |
| - * @param webviewView The WebviewView instance |
| 94 | + * Clicks the Cancel button in the rule creation form |
| 95 | + * @param webview The WebviewView instance |
41 | 96 | */
|
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() |
| 97 | +export async function clickCancelButton(webview: WebviewView): Promise<void> { |
| 98 | + const sheetWrapper = await waitForElement(webview, By.css('[data-testid="sheet-wrapper"]')) |
| 99 | + const cancelButton = await sheetWrapper.findElement(By.xpath('.//button[@action-id="cancel-create-rule"]')) |
| 100 | + await cancelButton.click() |
47 | 101 | }
|
48 | 102 |
|
49 | 103 | /**
|
50 |
| - * Clicks the Cancel button in the rule creation dialog |
51 |
| - * @param webviewView The WebviewView instance |
| 104 | + * Creates a new rule with the specified name (complete workflow) |
| 105 | + * @param webview The WebviewView instance |
| 106 | + * @param ruleName The name of the rule to create |
52 | 107 | */
|
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() |
| 108 | +export async function createNewRule(webview: WebviewView, ruleName: string): Promise<void> { |
| 109 | + await clickRulesButton(webview) |
| 110 | + await clickCreateNewRuleOption(webview) |
| 111 | + await enterRuleName(webview, ruleName) |
| 112 | + await clickCreateButton(webview) |
58 | 113 | }
|
0 commit comments