| 1 | import { expect } from "chai"; |
| 2 | import { TextEditor, VSBrowser, Workbench } from "vscode-extension-tester"; |
| 3 | |
| 4 | import { DEFAULT_TIMEOUT } from "../constants"; |
| 5 | import { AutocompleteSelectors } from "../selectors/Autocomplete.selectors"; |
| 6 | import { TestUtils } from "../TestUtils"; |
| 7 | |
| 8 | export class AutocompleteActions { |
| 9 | public static async testCompletions(editor: TextEditor) { |
| 10 | const driver = editor.getDriver(); |
| 11 | |
| 12 | const messagePair0 = TestUtils.generateTestMessagePair(0); |
| 13 | await editor.typeTextAt(1, 1, messagePair0.userMessage); |
| 14 | await editor.typeTextAt(1, messagePair0.userMessage.length + 1, " "); |
| 15 | const ghostText0 = await TestUtils.waitForSuccess( |
| 16 | () => AutocompleteSelectors.getGhostTextContent(driver), |
| 17 | // The first completion takes longer because Continue needs to load |
| 18 | DEFAULT_TIMEOUT.XL, |
| 19 | ); |
| 20 | expect(ghostText0).to.equal(messagePair0.llmResponse); |
| 21 | |
| 22 | await editor.clearText(); |
| 23 | |
| 24 | const messagePair1 = TestUtils.generateTestMessagePair(1); |
| 25 | await editor.typeTextAt(1, 1, messagePair1.userMessage); |
| 26 | await editor.typeTextAt(1, messagePair1.userMessage.length + 1, " "); |
| 27 | const ghostText1 = await TestUtils.waitForSuccess(() => |
| 28 | AutocompleteSelectors.getGhostTextContent(driver), |
| 29 | ); |
| 30 | expect(ghostText1).to.equal(messagePair1.llmResponse); |
| 31 | } |
| 32 | |
| 33 | public static async forceCompletion(editor: TextEditor): Promise<string> { |
| 34 | await editor.setText("def main():\n "); |
| 35 | await editor.moveCursor(2, 5); |
| 36 | |
| 37 | await new Workbench().executeCommand("Continue: Force Autocomplete"); |
| 38 | |
| 39 | const ghostText = await TestUtils.waitForSuccess(() => |
| 40 | AutocompleteSelectors.getGhostTextContent(VSBrowser.instance.driver), |
| 41 | ); |
| 42 | |
| 43 | return ghostText; |
| 44 | } |
| 45 | } |