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