From b3ac14332e8bd89237dfa41847701e3378487145 Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Mon, 23 Dec 2024 11:27:30 -0800 Subject: [PATCH] fix: cycling through chat messages --- extensions/vscode/e2e/tests/GUI.test.ts | 59 ++++++++++++++++++- gui/src/components/mainInput/TipTapEditor.tsx | 7 +-- gui/src/hooks/useInputHistory.ts | 4 +- 3 files changed, 63 insertions(+), 7 deletions(-) diff --git a/extensions/vscode/e2e/tests/GUI.test.ts b/extensions/vscode/e2e/tests/GUI.test.ts index c3c2cdf7e..d4c005eae 100644 --- a/extensions/vscode/e2e/tests/GUI.test.ts +++ b/extensions/vscode/e2e/tests/GUI.test.ts @@ -5,6 +5,7 @@ import { Key, WebElement, VSBrowser, + until, } from "vscode-extension-tester"; import { expect } from "chai"; import { GUIActions } from "../actions/GUI.actions"; @@ -192,7 +193,63 @@ describe("GUI Test", () => { }); describe("Chat Paths", () => { - it("Open chat and type → open history → cmd+l → chat opens, empty and in focus", async () => { + it("Open chat and send message → press arrow up and arrow down to cycle through messages → submit another message → press arrow up and arrow down to cycle through messages", async () => { + await GUIActions.sendMessage({ + view, + message: "MESSAGE 1", + inputFieldIndex: 0, + }); + + const input1 = await TestUtils.waitForSuccess(async () => { + return GUISelectors.getMessageInputFieldAtIndex(view, 1); + }); + expect(await input1.getText()).to.equal(""); + + await input1.sendKeys(Key.ARROW_UP); + await driver.wait( + until.elementTextIs(input1, "MESSAGE 1"), + DEFAULT_TIMEOUT.SM, + ); + + await input1.sendKeys(Key.ARROW_DOWN); // First press - bring caret to the end of the message + await input1.sendKeys(Key.ARROW_DOWN); // Second press - trigger message change + await driver.wait(until.elementTextIs(input1, ""), DEFAULT_TIMEOUT.SM); + + await GUIActions.sendMessage({ + view, + message: "MESSAGE 2", + inputFieldIndex: 1, + }); + + const input2 = await TestUtils.waitForSuccess(async () => { + return GUISelectors.getMessageInputFieldAtIndex(view, 2); + }); + expect(await input2.getText()).to.equal(""); + + await input2.sendKeys(Key.ARROW_UP); + await driver.wait( + until.elementTextIs(input2, "MESSAGE 2"), + DEFAULT_TIMEOUT.SM, + ); + + await input2.sendKeys(Key.ARROW_UP); + await driver.wait( + until.elementTextIs(input2, "MESSAGE 1"), + DEFAULT_TIMEOUT.SM, + ); + + await input2.sendKeys(Key.ARROW_DOWN); // First press - bring caret to the end of the message + await input2.sendKeys(Key.ARROW_DOWN); // Second press - trigger message change + await driver.wait( + until.elementTextIs(input2, "MESSAGE 2"), + DEFAULT_TIMEOUT.SM, + ); + + await input2.sendKeys(Key.ARROW_DOWN); + await driver.wait(until.elementTextIs(input2, ""), DEFAULT_TIMEOUT.SM); + }).timeout(DEFAULT_TIMEOUT.XL); + + it("Open chat and type → open history → press new session button → chat opens, empty and in focus", async () => { const originalTextInput = await GUISelectors.getMessageInputFieldAtIndex( view, 0, diff --git a/gui/src/components/mainInput/TipTapEditor.tsx b/gui/src/components/mainInput/TipTapEditor.tsx index 29c6b108a..24f874eb6 100644 --- a/gui/src/components/mainInput/TipTapEditor.tsx +++ b/gui/src/components/mainInput/TipTapEditor.tsx @@ -637,12 +637,11 @@ function TipTapEditor(props: TipTapEditorProps) { return; } - props.onEnter(json, modifiers, editor); - if (props.isMainInput) { - const content = editor.state.toJSON().doc; - addRef.current(content); + addRef.current(json); } + + props.onEnter(json, modifiers, editor); }, [props.onEnter, editor, props.isMainInput], ); diff --git a/gui/src/hooks/useInputHistory.ts b/gui/src/hooks/useInputHistory.ts index 8a664a9e4..3d63886fe 100644 --- a/gui/src/hooks/useInputHistory.ts +++ b/gui/src/hooks/useInputHistory.ts @@ -52,9 +52,9 @@ export function useInputHistory(historyKey: string) { ) { setCurrentIndex(inputHistory.length); return; - } else { - setCurrentIndex(inputHistory.length + 1); } + + setCurrentIndex(inputHistory.length + 1); setInputHistory((prev) => { return [...prev, inputValue].slice(-MAX_HISTORY_LENGTH); });