diff --git a/extensions/vscode/e2e/actions/Apply.actions.ts b/extensions/vscode/e2e/actions/Apply.actions.ts new file mode 100644 index 000000000..44aa87e85 --- /dev/null +++ b/extensions/vscode/e2e/actions/Apply.actions.ts @@ -0,0 +1,16 @@ +import { WebView } from "vscode-extension-tester"; + +import { ApplySelectors } from "../selectors/Apply.selectors"; +import { TestUtils } from "../TestUtils"; + +export class ApplyActions { + static async performAction( + view: WebView, + action: "apply" | "accept" | "reject" | "create", + ) { + let applyButton = await TestUtils.waitForSuccess( + async () => await ApplySelectors.getCodeblockToolbarAction(view, action), + ); + applyButton.click(); + } +} diff --git a/extensions/vscode/e2e/actions/Global.actions.ts b/extensions/vscode/e2e/actions/Global.actions.ts index aafd1040a..b3fca5cbd 100644 --- a/extensions/vscode/e2e/actions/Global.actions.ts +++ b/extensions/vscode/e2e/actions/Global.actions.ts @@ -7,10 +7,17 @@ import { } from "vscode-extension-tester"; import { DEFAULT_TIMEOUT } from "../constants"; +import { TestUtils } from "../TestUtils"; export class GlobalActions { + static defaultFolder = "e2e/test-continue"; + public static defaultNewFilename = "test.py"; + public static async openTestWorkspace() { - return VSBrowser.instance.openResources("e2e/test-continue"); + await VSBrowser.instance.openResources(GlobalActions.defaultFolder); + await new Workbench().executeCommand( + "Notifications: Clear All Notifications", + ); } public static async createAndOpenNewTextFile(): Promise<{ @@ -26,4 +33,47 @@ export class GlobalActions { return { editor }; } + + public static async createAndSaveNewFile( + filename = GlobalActions.defaultNewFilename, + ): Promise<{ + editor: TextEditor; + }> { + let { editor } = await GlobalActions.createAndOpenNewTextFile(); + + await new Workbench().executeCommand("File: Save As..."); + const inputBox = await InputBox.create(DEFAULT_TIMEOUT.MD); + + // Get current path and replace filename + const currentPath = await inputBox.getText(); + const pathParts = currentPath.split(/[\/\\]/); + pathParts[pathParts.length - 1] = filename; + const newPath = pathParts.join("/"); + + await inputBox.setText(newPath); + + await inputBox.confirm(); + await TestUtils.waitForTimeout(DEFAULT_TIMEOUT.XS); + + editor = (await new EditorView().openEditor(filename)) as TextEditor; + + return { editor }; + } + + public static async deleteFileFromFolder( + filename = GlobalActions.defaultNewFilename, + folder = GlobalActions.defaultFolder, + ): Promise { + const fs = require("fs"); + const path = require("path"); + + const folderPath = path.join(process.cwd(), folder); + const filePath = path.join(folderPath, filename); + + try { + await fs.promises.unlink(filePath); + } catch (error) { + console.warn(`Failed to delete file ${filePath}:`, error); + } + } } diff --git a/extensions/vscode/e2e/actions/KeyboardShortcuts.actions.ts b/extensions/vscode/e2e/actions/KeyboardShortcuts.actions.ts index 358d883bd..cac1097c7 100644 --- a/extensions/vscode/e2e/actions/KeyboardShortcuts.actions.ts +++ b/extensions/vscode/e2e/actions/KeyboardShortcuts.actions.ts @@ -1,4 +1,4 @@ -import { TextEditor } from "vscode-extension-tester"; +import { Key, TextEditor, WebElement } from "vscode-extension-tester"; export class KeyboardShortcutsActions { /** @@ -10,4 +10,27 @@ export class KeyboardShortcutsActions { await editor.selectText(text); await editor.typeText(text); } + + /** + * Types each string in the array with a newline (Shift+Enter) between them. + * Optionally adds a final Enter key press to submit. + */ + public static async typeWithNewlines({ + input, + lines, + submit, + }: { + input: TextEditor | WebElement; + lines: string[]; + submit?: boolean; + }) { + for (let i = 0; i < lines.length - 1; i++) { + await input.sendKeys(lines[i]); + await input.sendKeys(Key.chord(Key.SHIFT, Key.ENTER)); + } + await input.sendKeys(lines[lines.length - 1]); + if (submit) { + await input.sendKeys(Key.ENTER); + } + } } diff --git a/extensions/vscode/e2e/selectors/Apply.selectors.ts b/extensions/vscode/e2e/selectors/Apply.selectors.ts new file mode 100644 index 000000000..4d14f7ff5 --- /dev/null +++ b/extensions/vscode/e2e/selectors/Apply.selectors.ts @@ -0,0 +1,15 @@ +import { WebView } from "vscode-extension-tester"; + +import { SelectorUtils } from "./SelectorUtils"; + +export class ApplySelectors { + static getCodeblockToolbarAction( + view: WebView, + action: "apply" | "accept" | "reject" | "create", + ) { + return SelectorUtils.getElementByDataTestId( + view, + `codeblock-toolbar-${action}`, + ); + } +} diff --git a/extensions/vscode/e2e/tests/Apply.test.skip.ts b/extensions/vscode/e2e/tests/Apply.test.skip.ts new file mode 100644 index 000000000..80e005d01 --- /dev/null +++ b/extensions/vscode/e2e/tests/Apply.test.skip.ts @@ -0,0 +1,100 @@ +import { TextEditor, VSBrowser, WebView } from "vscode-extension-tester"; + +import { ApplyActions } from "../actions/Apply.actions"; +import { GlobalActions } from "../actions/Global.actions"; +import { GUIActions } from "../actions/GUI.actions"; +import { KeyboardShortcutsActions } from "../actions/KeyboardShortcuts.actions"; +import { DEFAULT_TIMEOUT } from "../constants"; +import { GUISelectors } from "../selectors/GUI.selectors"; +import { TestUtils } from "../TestUtils"; + +/** + * This file is currently `.skip`'d because the test is consistently failing in CI, + * bu consistenly passing locally. Screenshots from CI appear to indicate + * that our `GlobalActions.openTestWorkspace` fn isn't actually working, and therefore + * our apply button is instead rendering as "Create file" since the file doesn't exist + * in our workspace. + * + * The most recent failing screenshot is here: https://github.com/continuedev/continue/actions/runs/14481877233?pr=5167 + */ +describe("Apply Test", () => { + let view: WebView; + let editor: TextEditor; + let fileContent = "hello = 'world'"; + + before(async function () { + this.timeout(DEFAULT_TIMEOUT.XL); + + await GUIActions.moveContinueToSidebar(VSBrowser.instance.driver); + await GlobalActions.openTestWorkspace(); + + ({ editor } = await GlobalActions.createAndSaveNewFile()); + }); + + beforeEach(async function () { + this.timeout(DEFAULT_TIMEOUT.XL); + + await editor.typeTextAt(1, 1, fileContent); + await GUIActions.toggleGui(); + + ({ view } = await GUIActions.switchToReactIframe()); + await GUIActions.selectModelFromDropdown(view, "TEST LLM"); + }); + + afterEach(async function () { + this.timeout(DEFAULT_TIMEOUT.XL); + + await editor.clearText(); + + ({ view } = await GUIActions.switchToReactIframe()); + const tipTapEditor = await GUISelectors.getMessageInputFieldAtIndex( + view, + 0, + ); + await tipTapEditor.clear(); + }); + + after(async function () { + this.timeout(DEFAULT_TIMEOUT.XL); + await GlobalActions.deleteFileFromFolder(); + }); + + it("Can reject and apply changes from sidebar", async () => { + const newFileContent = fileContent + "!"; + + const [messageInput] = await GUISelectors.getMessageInputFields(view); + + await KeyboardShortcutsActions.typeWithNewlines({ + submit: true, + input: messageInput, + lines: [ + "```py " + GlobalActions.defaultNewFilename, + newFileContent, + "```", + "_", // To avoid extra lines getting included in the block + ], + }); + + await ApplyActions.performAction(view, "apply"); + await ApplyActions.performAction(view, "reject"); + await view.switchBack(); + + let editorText = await editor.getText(); + + await TestUtils.waitForSuccess(async () => editorText === fileContent); + + ({ view } = await GUIActions.switchToReactIframe()); + + await ApplyActions.performAction(view, "apply"); + await ApplyActions.performAction(view, "accept"); + await view.switchBack(); + + // Note that the editor after accpeting contains additional text + // from the default output of the test LLM, so instead of checking + // for an exact text match on the new content we just do a `.includes()` + editorText = await editor.getText(); + await TestUtils.waitForSuccess(async () => + editorText.includes(newFileContent), + ); + }).timeout(DEFAULT_TIMEOUT.XL); +}); diff --git a/extensions/vscode/e2e/tests/Autocomplete.test.ts b/extensions/vscode/e2e/tests/Autocomplete.test.ts index e6444c80c..836c2c60e 100644 --- a/extensions/vscode/e2e/tests/Autocomplete.test.ts +++ b/extensions/vscode/e2e/tests/Autocomplete.test.ts @@ -1,9 +1,4 @@ -import { - EditorView, - InputBox, - TextEditor, - Workbench, -} from "vscode-extension-tester"; +import { EditorView, TextEditor } from "vscode-extension-tester"; import { AutocompleteActions } from "../actions/Autocomplete.actions"; import { GlobalActions } from "../actions/Global.actions"; diff --git a/extensions/vscode/e2e/tests/Edit.test.ts b/extensions/vscode/e2e/tests/Edit.test.ts index 66b82aaf3..6d8812ff1 100644 --- a/extensions/vscode/e2e/tests/Edit.test.ts +++ b/extensions/vscode/e2e/tests/Edit.test.ts @@ -1,9 +1,9 @@ import { expect } from "chai"; import { - WebView, - VSBrowser, - TextEditor, CodeLens, + TextEditor, + VSBrowser, + WebView, } from "vscode-extension-tester"; import { EditActions } from "../actions/Edit.actions"; diff --git a/extensions/vscode/e2e/tests/KeyboardShortcuts.test.ts b/extensions/vscode/e2e/tests/KeyboardShortcuts.test.ts index 0191d1d63..e9b79472f 100644 --- a/extensions/vscode/e2e/tests/KeyboardShortcuts.test.ts +++ b/extensions/vscode/e2e/tests/KeyboardShortcuts.test.ts @@ -1,21 +1,22 @@ +import { expect } from "chai"; import { - WebDriver, - VSBrowser, EditorView, InputBox, - TextEditor, - Workbench, - WebView, - WebElement, - until, Key, + TextEditor, + VSBrowser, + WebDriver, + WebElement, + WebView, + Workbench, + until, } from "vscode-extension-tester"; + +import { GUIActions } from "../actions/GUI.actions"; +import { KeyboardShortcutsActions } from "../actions/KeyboardShortcuts.actions"; import { DEFAULT_TIMEOUT } from "../constants"; import { GUISelectors } from "../selectors/GUI.selectors"; -import { GUIActions } from "../actions/GUI.actions"; -import { expect } from "chai"; import { TestUtils } from "../TestUtils"; -import { KeyboardShortcutsActions } from "../actions/KeyboardShortcuts.actions"; describe("Keyboard Shortcuts", () => { let driver: WebDriver; diff --git a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/ApplyActions.tsx b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/ApplyActions.tsx index e645e68c9..7131e6ad9 100644 --- a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/ApplyActions.tsx +++ b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/ApplyActions.tsx @@ -36,6 +36,7 @@ export function ApplyActions(props: ApplyActionsProps) { const applyButton = (text: string) => (