|
| 1 | +import { |
| 2 | + Workbench, |
| 3 | + EditorView, |
| 4 | + WebView, |
| 5 | + By, |
| 6 | + WebElement, |
| 7 | + WebDriver, |
| 8 | + Key, |
| 9 | +} from "vscode-extension-tester"; |
| 10 | +import { expect } from "chai"; |
| 11 | + |
| 12 | +const switchToReactIframe = async (driver: WebDriver) => { |
| 13 | + const iframes = await driver.findElements(By.css("iframe")); |
| 14 | + let continueIFrame: WebElement | undefined = undefined; |
| 15 | + for (let i = 0; i < iframes.length; i++) { |
| 16 | + const iframe = iframes[i]; |
| 17 | + const src = await iframe.getAttribute("src"); |
| 18 | + if (src.includes("extensionId=Continue.continue")) { |
| 19 | + continueIFrame = iframe; |
| 20 | + break; |
| 21 | + } |
| 22 | + } |
| 23 | + |
| 24 | + if (!continueIFrame) { |
| 25 | + throw new Error("Could not find continue iframe"); |
| 26 | + } |
| 27 | + |
| 28 | + await driver.switchTo().frame(continueIFrame); |
| 29 | + |
| 30 | + await new Promise((res) => { |
| 31 | + setTimeout(res, 500); |
| 32 | + }); |
| 33 | + |
| 34 | + const reactIFrame = await driver.findElement(By.css("iframe")); |
| 35 | + |
| 36 | + if (!reactIFrame) { |
| 37 | + throw new Error("Could not find React iframe"); |
| 38 | + } |
| 39 | + |
| 40 | + await driver.switchTo().frame(reactIFrame); |
| 41 | +}; |
| 42 | + |
| 43 | +describe("GUI Test", () => { |
| 44 | + let view: WebView; |
| 45 | + let driver: WebDriver; |
| 46 | + |
| 47 | + before(async function () { |
| 48 | + this.timeout(10000); |
| 49 | + |
| 50 | + await new Workbench().executeCommand("continue.focusContinueInput"); |
| 51 | + |
| 52 | + view = new WebView(); |
| 53 | + driver = view.getDriver(); |
| 54 | + |
| 55 | + await switchToReactIframe(driver); |
| 56 | + }); |
| 57 | + |
| 58 | + after(async () => { |
| 59 | + await view.switchBack(); |
| 60 | + await new EditorView().closeAllEditors(); |
| 61 | + }); |
| 62 | + |
| 63 | + it("should display correct panel description", async () => { |
| 64 | + const description = await view.findWebElement( |
| 65 | + By.xpath("//*[contains(text(), 'Quickly')]"), |
| 66 | + ); |
| 67 | + |
| 68 | + expect(await description.getText()).has.string( |
| 69 | + "Quickly get up and running using our API keys.", |
| 70 | + ); |
| 71 | + }); |
| 72 | + |
| 73 | + it("should allow typing text in the editor", async () => { |
| 74 | + const tiptap = await view.findWebElement(By.className("tiptap")); |
| 75 | + |
| 76 | + await tiptap.sendKeys("Hello world!"); |
| 77 | + |
| 78 | + expect(await tiptap.getText()).has.string("Hello world!"); |
| 79 | + |
| 80 | + // Just to show that we can |
| 81 | + await tiptap.sendKeys(Key.ENTER); |
| 82 | + await new Promise((res) => { |
| 83 | + setTimeout(res, 5000); |
| 84 | + }); |
| 85 | + }).timeout(6000); |
| 86 | +}); |
0 commit comments