Elffuss BraidHub

kikocis/continue public

a5fcde5311cf · 6.7 KiBRawPermalink
1import { expect } from "chai";
2import {
3 EditorView,
4 InputBox,
5 Key,
6 TextEditor,
7 VSBrowser,
8 WebDriver,
9 WebElement,
10 WebView,
11 Workbench,
12 until,
13} from "vscode-extension-tester";
14
15import { GUIActions } from "../actions/GUI.actions";
16import { KeyboardShortcutsActions } from "../actions/KeyboardShortcuts.actions";
17import { DEFAULT_TIMEOUT } from "../constants";
18import { GUISelectors } from "../selectors/GUI.selectors";
19import { TestUtils } from "../TestUtils";
20
21describe("Keyboard Shortcuts", () => {
22 let driver: WebDriver;
23 let editor: TextEditor;
24 let view: WebView;
25
26 before(async function () {
27 this.timeout(DEFAULT_TIMEOUT.XL);
28 await GUIActions.moveContinueToSidebar(VSBrowser.instance.driver);
29 });
30
31 beforeEach(async function () {
32 this.timeout(DEFAULT_TIMEOUT.XL);
33
34 await TestUtils.waitForSuccess(async () => {
35 await new Workbench().executeCommand("Create: New File...");
36 await (
37 await InputBox.create(DEFAULT_TIMEOUT.MD)
38 ).selectQuickPick("Text File");
39 });
40
41 driver = VSBrowser.instance.driver;
42
43 editor = (await new EditorView().openEditor("Untitled-1")) as TextEditor;
44 });
45
46 afterEach(async function () {
47 this.timeout(DEFAULT_TIMEOUT.XL * 1000);
48 await view.switchBack();
49 await editor.clearText();
50 await new EditorView().closeAllEditors();
51 });
52
53 it("Should correctly undo and redo using keyboard shortcuts when writing a chat message", async () => {
54 await GUIActions.executeFocusContinueInputShortcut(driver);
55 ({ view } = await GUIActions.switchToReactIframe());
56 const chatInput = await TestUtils.waitForSuccess(async () => {
57 return GUISelectors.getMessageInputFieldAtIndex(view, 0);
58 });
59
60 await chatInput.sendKeys("HELLO ");
61 await TestUtils.waitForTimeout(DEFAULT_TIMEOUT.XS);
62
63 await chatInput.sendKeys("WORLD ");
64 await TestUtils.waitForTimeout(DEFAULT_TIMEOUT.XS);
65
66 await chatInput.sendKeys("HELLO ");
67 await TestUtils.waitForTimeout(DEFAULT_TIMEOUT.XS);
68
69 await chatInput.sendKeys("CONTINUE");
70 await TestUtils.waitForTimeout(DEFAULT_TIMEOUT.XS);
71
72 await chatInput.sendKeys(TestUtils.osControlKey + "z");
73 await driver.wait(
74 until.elementTextIs(chatInput, "HELLO WORLD"),
75 DEFAULT_TIMEOUT.SM,
76 );
77
78 await chatInput.sendKeys(TestUtils.osControlKey + "z");
79 await driver.wait(until.elementTextIs(chatInput, ""), DEFAULT_TIMEOUT.SM);
80
81 await chatInput.sendKeys(Key.SHIFT + TestUtils.osControlKey + "z");
82 await driver.wait(
83 until.elementTextIs(chatInput, "HELLO"),
84 DEFAULT_TIMEOUT.SM,
85 );
86
87 await chatInput.sendKeys(Key.SHIFT + TestUtils.osControlKey + "z");
88 await driver.wait(
89 until.elementTextIs(chatInput, "HELLO WORLD"),
90 DEFAULT_TIMEOUT.SM,
91 );
92
93 await chatInput.sendKeys(Key.SHIFT + TestUtils.osControlKey + "z");
94 await driver.wait(
95 until.elementTextIs(chatInput, "HELLO WORLD HELLO"),
96 DEFAULT_TIMEOUT.SM,
97 );
98
99 await chatInput.sendKeys(Key.SHIFT + TestUtils.osControlKey + "z");
100 await driver.wait(
101 until.elementTextIs(chatInput, "HELLO WORLD HELLO CONTINUE"),
102 DEFAULT_TIMEOUT.SM,
103 );
104 }).timeout(DEFAULT_TIMEOUT.XL);
105
106 it("Should not create a code block when Cmd+L is pressed without text highlighted", async () => {
107 const text = "Hello, world!";
108
109 await editor.setText(text);
110
111 await GUIActions.executeFocusContinueInputShortcut(driver);
112
113 ({ view } = await GUIActions.switchToReactIframe());
114
115 await TestUtils.expectNoElement(async () => {
116 return GUISelectors.getInputBoxCodeBlockAtIndex(view, 0);
117 }, DEFAULT_TIMEOUT.XS);
118 await GUIActions.executeFocusContinueInputShortcut(driver);
119 }).timeout(DEFAULT_TIMEOUT.XL);
120
121 it("Fresh VS Code window → sidebar closed → cmd+L with no code highlighted → opens sidebar and focuses input → cmd+L closes sidebar", async () => {
122 await GUIActions.executeFocusContinueInputShortcut(driver);
123 ({ view } = await GUIActions.switchToReactIframe());
124 const textInput = await TestUtils.waitForSuccess(() =>
125 GUISelectors.getMessageInputFieldAtIndex(view, 0),
126 );
127 const activeElement: WebElement = await driver.switchTo().activeElement();
128 const textInputHtml = await textInput.getAttribute("outerHTML");
129 const activeElementHtml = await activeElement.getAttribute("outerHTML");
130 expect(textInputHtml).to.equal(activeElementHtml);
131 expect(await textInput.isDisplayed()).to.equal(true);
132
133 await GUIActions.executeFocusContinueInputShortcut(driver);
134
135 await driver.wait(until.elementIsNotVisible(textInput), DEFAULT_TIMEOUT.XS);
136 expect(await textInput.isDisplayed()).to.equal(false);
137 }).timeout(DEFAULT_TIMEOUT.XL);
138
139 it("Send a message → focus code editor (not sidebar) → cmd+L → should focus sidebar and start a new session", async () => {
140 await GUIActions.executeFocusContinueInputShortcut(driver);
141 ({ view } = await GUIActions.switchToReactIframe());
142
143 const { userMessage: userMessage0 } = TestUtils.generateTestMessagePair(0);
144
145 await GUIActions.sendMessage({
146 view,
147 message: userMessage0,
148 inputFieldIndex: 0,
149 });
150
151 await view.switchBack();
152
153 KeyboardShortcutsActions.HACK__typeWithSelect(editor, "hello");
154
155 await TestUtils.waitForTimeout(DEFAULT_TIMEOUT.XS);
156
157 await GUIActions.executeFocusContinueInputShortcut(driver);
158
159 ({ view } = await GUIActions.switchToReactIframe());
160
161 await TestUtils.waitForTimeout(DEFAULT_TIMEOUT.XS);
162
163 const textInput = await TestUtils.waitForSuccess(() =>
164 GUISelectors.getMessageInputFieldAtIndex(view, 0),
165 );
166 const activeElement: WebElement = await driver.switchTo().activeElement();
167 const textInputHtml = await textInput.getAttribute("outerHTML");
168 const activeElementHtml = await activeElement.getAttribute("outerHTML");
169 expect(textInputHtml).to.equal(activeElementHtml);
170
171 await GUIActions.executeFocusContinueInputShortcut(driver);
172
173 await driver.wait(until.elementIsNotVisible(textInput), DEFAULT_TIMEOUT.XS);
174 expect(await textInput.isDisplayed()).to.equal(false);
175 }).timeout(DEFAULT_TIMEOUT.XL);
176
177 it("Should create a code block when Cmd+L is pressed with text highlighted", async () => {
178 const text = "Hello, world!";
179
180 await editor.setText(text);
181 await editor.selectText(text);
182
183 await GUIActions.executeFocusContinueInputShortcut(driver);
184
185 ({ view } = await GUIActions.switchToReactIframe());
186
187 const codeBlock = await TestUtils.waitForSuccess(() =>
188 GUISelectors.getInputBoxCodeBlockAtIndex(view, 0),
189 );
190 const codeblockContent = await codeBlock.getAttribute(
191 "data-codeblockcontent",
192 );
193
194 expect(codeblockContent).to.equal(text);
195
196 await GUIActions.executeFocusContinueInputShortcut(driver);
197 }).timeout(DEFAULT_TIMEOUT.XL);
198});