Elffuss BraidHub

kikocis/continue public

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