Elffuss BraidHub

kikocis/continue public

main · 3.9 KiBRawPermalink
1import { expect } from "chai";
2import {
3 CodeLens,
4 TextEditor,
5 VSBrowser,
6 WebView,
7} from "vscode-extension-tester";
8
9import { EditActions } from "../actions/Edit.actions";
10import { GlobalActions } from "../actions/Global.actions";
11import { GUIActions } from "../actions/GUI.actions";
12import { DEFAULT_TIMEOUT } from "../constants";
13import { GUISelectors } from "../selectors/GUI.selectors";
14import { TestUtils } from "../TestUtils";
15
16describe("Edit Test", () => {
17 let view: WebView;
18 let editor: TextEditor;
19 let originalEditorText = "Hello world!";
20 let { userMessage, llmResponse } = TestUtils.generateTestMessagePair();
21
22 before(async function () {
23 this.timeout(DEFAULT_TIMEOUT.XL);
24 await GUIActions.moveContinueToSidebar(VSBrowser.instance.driver);
25 await GlobalActions.openTestWorkspace();
26 ({ editor } = await GlobalActions.createAndOpenNewTextFile());
27 await GlobalActions.disableNextEdit();
28 });
29
30 beforeEach(async function () {
31 this.timeout(DEFAULT_TIMEOUT.XL);
32
33 await GUIActions.toggleGui();
34
35 await editor.typeTextAt(1, 1, originalEditorText);
36 await editor.selectText(originalEditorText);
37
38 await EditActions.invokeEditShortcut(editor);
39
40 ({ view } = await GUIActions.switchToReactIframe());
41
42 await GUIActions.sendMessage({
43 view,
44 message: userMessage,
45 inputFieldIndex: 0,
46 });
47
48 await view.switchBack();
49
50 await TestUtils.waitForSuccess(async () => {
51 const editorText = await editor.getText();
52 return editorText.includes(llmResponse);
53 });
54 });
55
56 afterEach(async function () {
57 this.timeout(DEFAULT_TIMEOUT.XL);
58
59 await editor.clearText();
60
61 ({ view } = await GUIActions.switchToReactIframe());
62
63 const tipTapEditor = await GUISelectors.getMessageInputFieldAtIndex(
64 view,
65 0,
66 );
67 await tipTapEditor.clear();
68 });
69
70 async function getCodeLensWithRetry(editor: TextEditor, text: string) {
71 let codeLens: CodeLens | undefined;
72 await TestUtils.waitForSuccess(async () => {
73 codeLens = await editor.getCodeLens(text);
74 expect(codeLens).to.not.be.undefined;
75 }, DEFAULT_TIMEOUT.SM);
76 return codeLens;
77 }
78
79 it.only("Accepts an Edit in the GUI", async () => {
80 ({ view } = await GUIActions.switchToReactIframe());
81
82 await EditActions.acceptEditInGUI(view);
83
84 await view.switchBack();
85
86 await TestUtils.waitForSuccess(async () => {
87 const editorText = await editor.getText();
88
89 expect(
90 !editorText.includes(originalEditorText) &&
91 editorText.includes(llmResponse),
92 ).to.be.true;
93 }, DEFAULT_TIMEOUT.SM);
94 }).timeout(DEFAULT_TIMEOUT.XL);
95
96 it("Rejects an Edit in the GUI", async () => {
97 ({ view } = await GUIActions.switchToReactIframe());
98
99 await EditActions.rejectEditInGUI(view);
100
101 await view.switchBack();
102
103 await TestUtils.waitForSuccess(async () => {
104 const editorText = await editor.getText();
105
106 expect(
107 editorText.includes(originalEditorText) &&
108 !editorText.includes(llmResponse),
109 ).to.be.true;
110 }, DEFAULT_TIMEOUT.SM);
111 }).timeout(DEFAULT_TIMEOUT.XL);
112
113 it("Accepts an Edit using CodeLens buttons", async () => {
114 const acceptCodeLens = await editor.getCodeLens("Accept");
115 await acceptCodeLens?.click();
116
117 await TestUtils.waitForSuccess(async () => {
118 const editorText = await editor.getText();
119
120 expect(
121 !editorText.includes(originalEditorText) &&
122 editorText.includes(llmResponse),
123 ).to.be.true;
124 }, DEFAULT_TIMEOUT.SM);
125 }).timeout(DEFAULT_TIMEOUT.XL);
126
127 it("Rejects an Edit using CodeLens buttons", async () => {
128 const rejectCodeLens = await getCodeLensWithRetry(editor, "Reject");
129 await rejectCodeLens?.click();
130
131 await TestUtils.waitForSuccess(async () => {
132 const editorText = await editor.getText();
133
134 expect(
135 editorText.includes(originalEditorText) &&
136 !editorText.includes(llmResponse),
137 ).to.be.true;
138 }, DEFAULT_TIMEOUT.SM);
139 }).timeout(DEFAULT_TIMEOUT.XL);
140});