| 1 | import { expect } from "chai"; |
| 2 | import { TextEditor, VSBrowser, Workbench } from "vscode-extension-tester"; |
| 3 | |
| 4 | import { DEFAULT_TIMEOUT } from "../constants"; |
| 5 | import { NextEditSelectors } from "../selectors/NextEdit.selectors"; |
| 6 | import { TestUtils } from "../TestUtils"; |
| 7 | |
| 8 | export class NextEditActions { |
| 9 | /** |
| 10 | * Test accepting a Next Edit suggestion with Tab. |
| 11 | */ |
| 12 | public static async acceptNextEditSuggestion(editor: TextEditor) { |
| 13 | const hasDecoration = await NextEditActions.forceNextEdit(editor); |
| 14 | expect(hasDecoration).to.be.true; |
| 15 | |
| 16 | await new Workbench().executeCommand("Continue: Accept Next Edit Suggestion"); |
| 17 | |
| 18 | // Check if HELLO is written into the editor. |
| 19 | const editorText = await editor.getTextAtLine(1); |
| 20 | |
| 21 | return editorText === "HELLO"; |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Test rejecting a Next Edit suggestion with Esc. |
| 26 | */ |
| 27 | public static async rejectNextEditSuggestion(editor: TextEditor) { |
| 28 | const hasDecoration = await NextEditActions.forceNextEdit(editor); |
| 29 | expect(hasDecoration).to.be.true; |
| 30 | |
| 31 | await new Workbench().executeCommand("Continue: Hide Next Edit Suggestion"); |
| 32 | |
| 33 | // Check if the editor text didn't change. |
| 34 | const editorText = await editor.getText(); |
| 35 | |
| 36 | return editorText === "def main():\n "; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Force a Next Edit suggestion using command. |
| 41 | */ |
| 42 | public static async forceNextEdit(editor: TextEditor): Promise<boolean> { |
| 43 | await editor.setText("def main():\n "); |
| 44 | await editor.moveCursor(2, 4); |
| 45 | |
| 46 | await new Workbench().executeCommand("Continue: Force Next Edit"); |
| 47 | await TestUtils.waitForTimeout(DEFAULT_TIMEOUT.XL); |
| 48 | |
| 49 | const svgDecoration = await TestUtils.waitForSuccess( |
| 50 | () => NextEditSelectors.getSvgDecoration(VSBrowser.instance.driver), |
| 51 | DEFAULT_TIMEOUT.XL |
| 52 | ); |
| 53 | |
| 54 | return svgDecoration !== null; |
| 55 | } |
| 56 | |
| 57 | public static async reload(): Promise<void> { |
| 58 | await new Workbench().executeCommand('workbench.action.reloadWindow'); |
| 59 | } |
| 60 | } |