Merge pull request #5167 from continuedev/pe/e2e-apply-test
feat: apply e2e tests
This commit is contained in:
commit
0feee0e541
12 changed files with 229 additions and 22 deletions
16
extensions/vscode/e2e/actions/Apply.actions.ts
Normal file
16
extensions/vscode/e2e/actions/Apply.actions.ts
Normal file
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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<void> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
15
extensions/vscode/e2e/selectors/Apply.selectors.ts
Normal file
15
extensions/vscode/e2e/selectors/Apply.selectors.ts
Normal file
|
|
@ -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}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
100
extensions/vscode/e2e/tests/Apply.test.skip.ts
Normal file
100
extensions/vscode/e2e/tests/Apply.test.skip.ts
Normal file
|
|
@ -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);
|
||||
});
|
||||
|
|
@ -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";
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ export function ApplyActions(props: ApplyActionsProps) {
|
|||
|
||||
const applyButton = (text: string) => (
|
||||
<button
|
||||
data-testid="codeblock-toolbar-apply"
|
||||
className="text-lightgray text-[${vscForeground}] flex cursor-pointer items-center border-none bg-transparent pl-0 text-xs outline-none hover:brightness-125"
|
||||
onClick={props.onClickApply}
|
||||
>
|
||||
|
|
@ -65,6 +66,7 @@ export function ApplyActions(props: ApplyActionsProps) {
|
|||
|
||||
<div className="flex">
|
||||
<ToolbarButtonWithTooltip
|
||||
data-testid="codeblock-toolbar-reject"
|
||||
onClick={onClickReject}
|
||||
tooltipContent={`Reject all (${getMetaKeyLabel()}⇧⌫)`}
|
||||
>
|
||||
|
|
@ -72,6 +74,7 @@ export function ApplyActions(props: ApplyActionsProps) {
|
|||
</ToolbarButtonWithTooltip>
|
||||
|
||||
<ToolbarButtonWithTooltip
|
||||
data-testid="codeblock-toolbar-accept"
|
||||
onClick={props.onClickAccept}
|
||||
tooltipContent={`Accept all (${getMetaKeyLabel()}⇧⏎)`}
|
||||
>
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ export function CreateFileButton({ onClick }: CreateFileButtonProps) {
|
|||
return (
|
||||
<>
|
||||
<button
|
||||
data-testid="codeblock-toolbar-create"
|
||||
className={`text-lightgray flex items-center border-none bg-transparent pl-0 text-xs text-[${vscForeground}] cursor-pointer outline-none hover:brightness-125`}
|
||||
onClick={onClick}
|
||||
>
|
||||
|
|
|
|||
|
|
@ -24,12 +24,14 @@ interface ToolbarButtonWithTooltipProps {
|
|||
onClick: () => void;
|
||||
children: ReactNode;
|
||||
tooltipContent: string;
|
||||
"data-testid"?: string;
|
||||
}
|
||||
|
||||
export function ToolbarButtonWithTooltip({
|
||||
onClick,
|
||||
children,
|
||||
tooltipContent,
|
||||
"data-testid": testId,
|
||||
}: ToolbarButtonWithTooltipProps) {
|
||||
const tooltipId = useMemo(
|
||||
() => `tooltip-${Math.random().toString(36).slice(2, 11)}`,
|
||||
|
|
@ -42,6 +44,7 @@ export function ToolbarButtonWithTooltip({
|
|||
onClick={onClick}
|
||||
style={{ color: lightGray }}
|
||||
data-tooltip-id={tooltipId}
|
||||
data-testid={testId}
|
||||
className="px-0.5"
|
||||
>
|
||||
{children}
|
||||
|
|
|
|||
|
|
@ -227,7 +227,7 @@ export function StepContainerPreToolbar({
|
|||
return null;
|
||||
}
|
||||
|
||||
if (fileExists) {
|
||||
if (fileExists || !relativeFilepath) {
|
||||
return (
|
||||
<ApplyActions
|
||||
disableManualApply={disableManualApply}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue