Elffuss BraidHub

kikocis/continue public

7dd3a742e7cd · 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 });
28
29 beforeEach(async function () {
30 this.timeout(DEFAULT_TIMEOUT.XL);
31
32 await GUIActions.toggleGui();
33
34 await editor.typeTextAt(1, 1, originalEditorText);
35 await editor.selectText(originalEditorText);
36
37 await EditActions.invokeEditShortcut(editor);
38
39 ({ view } = await GUIActions.switchToReactIframe());
40
41 await GUIActions.sendMessage({
42 view,
43 message: userMessage,
44 inputFieldIndex: 0,
45 });
46
47 await view.switchBack();
48
49 await TestUtils.waitForSuccess(async () => {
50 const editorText = await editor.getText();
51 return editorText.includes(llmResponse);
52 });
53 });
54
55 afterEach(async function () {
56 this.timeout(DEFAULT_TIMEOUT.XL);
57
58 await editor.clearText();
59
60 ({ view } = await GUIActions.switchToReactIframe());
61
62 const tipTapEditor = await GUISelectors.getMessageInputFieldAtIndex(
63 view,
64 0,
65 );
66 await tipTapEditor.clear();
67 });
68
69 async function getCodeLensWithRetry(editor: TextEditor, text: string) {
70 let codeLens: CodeLens | undefined;
71 await TestUtils.waitForSuccess(async () => {
72 codeLens = await editor.getCodeLens(text);
73 expect(codeLens).to.not.be.undefined;
74 }, DEFAULT_TIMEOUT.SM);
75 return codeLens;
76 }
77
78 it.only("Accepts an Edit in the GUI", async () => {
79 ({ view } = await GUIActions.switchToReactIframe());
80
81 await EditActions.acceptEditInGUI(view);
82
83 await view.switchBack();
84
85 await TestUtils.waitForSuccess(async () => {
86 const editorText = await editor.getText();
87
88 expect(
89 !editorText.includes(originalEditorText) &&
90 editorText.includes(llmResponse),
91 ).to.be.true;
92 }, DEFAULT_TIMEOUT.SM);
93 }).timeout(DEFAULT_TIMEOUT.XL);
94
95 it("Rejects an Edit in the GUI", async () => {
96 ({ view } = await GUIActions.switchToReactIframe());
97
98 await EditActions.rejectEditInGUI(view);
99
100 await view.switchBack();
101
102 await TestUtils.waitForSuccess(async () => {
103 const editorText = await editor.getText();
104
105 expect(
106 editorText.includes(originalEditorText) &&
107 !editorText.includes(llmResponse),
108 ).to.be.true;
109 }, DEFAULT_TIMEOUT.SM);
110 }).timeout(DEFAULT_TIMEOUT.XL);
111
112 it("Accepts an Edit using CodeLens buttons", async () => {
113 const acceptCodeLens = await editor.getCodeLens("Accept");
114 await acceptCodeLens?.click();
115
116 await TestUtils.waitForSuccess(async () => {
117 const editorText = await editor.getText();
118
119 expect(
120 !editorText.includes(originalEditorText) &&
121 editorText.includes(llmResponse),
122 ).to.be.true;
123 }, DEFAULT_TIMEOUT.SM);
124 }).timeout(DEFAULT_TIMEOUT.XL);
125
126 it("Rejects an Edit using CodeLens buttons", async () => {
127 const rejectCodeLens = await getCodeLensWithRetry(editor, "Reject");
128 await rejectCodeLens?.click();
129
130 await TestUtils.waitForSuccess(async () => {
131 const editorText = await editor.getText();
132
133 expect(
134 editorText.includes(originalEditorText) &&
135 !editorText.includes(llmResponse),
136 ).to.be.true;
137 }, DEFAULT_TIMEOUT.SM);
138 }).timeout(DEFAULT_TIMEOUT.XL);
139});