| 1 | import { |
| 2 | InputBox, |
| 3 | Key, |
| 4 | WebDriver, |
| 5 | WebElement, |
| 6 | WebView, |
| 7 | Workbench, |
| 8 | } from "vscode-extension-tester"; |
| 9 | |
| 10 | import { DEFAULT_TIMEOUT } from "../constants"; |
| 11 | import { GUISelectors } from "../selectors/GUI.selectors"; |
| 12 | import { TestUtils } from "../TestUtils"; |
| 13 | |
| 14 | export class GUIActions { |
| 15 | public static moveContinueToSidebar = async (driver: WebDriver) => { |
| 16 | await GUIActions.toggleGui(); |
| 17 | await TestUtils.waitForSuccess(async () => { |
| 18 | await new Workbench().executeCommand("View: Move View"); |
| 19 | await ( |
| 20 | await InputBox.create(DEFAULT_TIMEOUT.MD) |
| 21 | ).selectQuickPick("Continue"); |
| 22 | await ( |
| 23 | await InputBox.create(DEFAULT_TIMEOUT.MD) |
| 24 | ).selectQuickPick("New Secondary Side Bar Entry"); |
| 25 | }); |
| 26 | |
| 27 | // first call focuses the input |
| 28 | await TestUtils.waitForTimeout(DEFAULT_TIMEOUT.XS); |
| 29 | await GUIActions.executeFocusContinueInputShortcut(driver); |
| 30 | |
| 31 | // second call closes the gui |
| 32 | await TestUtils.waitForTimeout(DEFAULT_TIMEOUT.XS); |
| 33 | await GUIActions.executeFocusContinueInputShortcut(driver); |
| 34 | }; |
| 35 | |
| 36 | public static switchToReactIframe = async () => { |
| 37 | const view = new WebView(); |
| 38 | const driver = view.getDriver(); |
| 39 | |
| 40 | const iframes = await GUISelectors.getAllIframes(driver); |
| 41 | let continueIFrame: WebElement | undefined = undefined; |
| 42 | for (let i = 0; i < iframes.length; i++) { |
| 43 | const iframe = iframes[i]; |
| 44 | const src = await iframe.getAttribute("src"); |
| 45 | if (src.includes("extensionId=Continue.continue")) { |
| 46 | continueIFrame = iframe; |
| 47 | break; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | if (!continueIFrame) { |
| 52 | throw new Error("Could not find Continue iframe"); |
| 53 | } |
| 54 | |
| 55 | await driver.switchTo().frame(continueIFrame); |
| 56 | |
| 57 | await new Promise((res) => { |
| 58 | setTimeout(res, 500); |
| 59 | }); |
| 60 | |
| 61 | const reactIFrame = await GUISelectors.getReactIframe(driver); |
| 62 | |
| 63 | if (!reactIFrame) { |
| 64 | throw new Error("Could not find React iframe"); |
| 65 | } |
| 66 | |
| 67 | await driver.switchTo().frame(reactIFrame); |
| 68 | return { |
| 69 | view, |
| 70 | driver, |
| 71 | }; |
| 72 | }; |
| 73 | |
| 74 | public static toggleGui = async () => { |
| 75 | return TestUtils.waitForSuccess(() => |
| 76 | new Workbench().executeCommand("continue.focusContinueInput"), |
| 77 | ); |
| 78 | }; |
| 79 | |
| 80 | public static selectModelFromDropdown = async ( |
| 81 | view: WebView, |
| 82 | option: string, |
| 83 | ) => { |
| 84 | const dropdownButton = await GUISelectors.getModelDropdownButton(view); |
| 85 | await dropdownButton.click(); |
| 86 | |
| 87 | const dropdownOption = await TestUtils.waitForSuccess(() => { |
| 88 | return GUISelectors.getModelDropdownOption(view, option); |
| 89 | }); |
| 90 | |
| 91 | await dropdownOption.click(); |
| 92 | }; |
| 93 | |
| 94 | public static selectModeFromDropdown = async ( |
| 95 | view: WebView, |
| 96 | option: string, |
| 97 | ) => { |
| 98 | const dropdownButton = await GUISelectors.getModeDropdownButton(view); |
| 99 | await dropdownButton.click(); |
| 100 | |
| 101 | const dropdownOption = await TestUtils.waitForSuccess(() => { |
| 102 | return GUISelectors.getModeDropdownOption(view, option); |
| 103 | }); |
| 104 | |
| 105 | await dropdownOption.click(); |
| 106 | }; |
| 107 | |
| 108 | public static async sendMessage({ |
| 109 | view, |
| 110 | message, |
| 111 | inputFieldIndex, |
| 112 | }: { |
| 113 | view: WebView; |
| 114 | message: string; |
| 115 | inputFieldIndex: number; |
| 116 | }) { |
| 117 | const editor = await GUISelectors.getMessageInputFieldAtIndex( |
| 118 | view, |
| 119 | inputFieldIndex, |
| 120 | ); |
| 121 | await editor.sendKeys(message); |
| 122 | await editor.sendKeys(Key.ENTER); |
| 123 | } |
| 124 | |
| 125 | public static async executeFocusContinueInputShortcut(driver: WebDriver) { |
| 126 | return driver |
| 127 | .actions() |
| 128 | .keyDown(TestUtils.osControlKey) |
| 129 | .sendKeys("l") |
| 130 | .keyUp(TestUtils.osControlKey) |
| 131 | .perform(); |
| 132 | } |
| 133 | |
| 134 | public static async toggleToolPolicy( |
| 135 | view: WebView, |
| 136 | toolName: string, |
| 137 | n: number, |
| 138 | ) { |
| 139 | const toolButton = await TestUtils.waitForSuccess(() => |
| 140 | GUISelectors.getToolButton(view), |
| 141 | ); |
| 142 | await toolButton.click(); |
| 143 | const toolPolicyButton = await TestUtils.waitForSuccess(() => |
| 144 | GUISelectors.getToolPolicyButton(view, toolName), |
| 145 | ); |
| 146 | await TestUtils.waitForTimeout(500); |
| 147 | |
| 148 | // Enabled -> Excluded -> Ask first |
| 149 | for (let i = 0; i < n; i++) { |
| 150 | await TestUtils.waitForSuccess(() => toolPolicyButton.click()); |
| 151 | } |
| 152 | } |
| 153 | } |