test: history

This commit is contained in:
tomasz-io 2024-12-09 14:35:14 -08:00
parent 28e8912584
commit 379e76fcdf
6 changed files with 68 additions and 42 deletions

View file

@ -1,3 +1,4 @@
import { expect } from "chai";
import { WebElement } from "vscode-extension-tester";
export class TestUtils {
@ -25,6 +26,30 @@ export class TestUtils {
throw new Error(`Element not found after ${timeout}ms timeout`);
}
public static async expectNoElement(
locatorFn: () => Promise<WebElement>,
timeout: number = 1000,
interval: number = 200,
): Promise<void> {
const startTime = Date.now();
let elementFound = false;
while (Date.now() - startTime < timeout) {
try {
const element = await locatorFn();
if (element) {
elementFound = true;
break;
}
} catch (e) {
// Continue if there's an error (element not found)
}
await new Promise((resolve) => setTimeout(resolve, interval));
}
expect(elementFound).to.be.false;
}
public static generateTestMessagePair(id: number): {
userMessage: string;
llmResponse: string;

View file

@ -7,7 +7,7 @@ export class GUISelectors {
}
public static getTipTapEditor(view: WebView) {
return view.findWebElement(By.className("tiptap"));
return view.findWebElements(By.className("tiptap"));
}
public static getAllIframes(driver: WebDriver) {
@ -26,6 +26,10 @@ export class GUISelectors {
return SelectorUtils.getElementByDataTestId(view, "model-select-button");
}
public static getNthHistoryTableRow(view: WebView, index: number) {
return SelectorUtils.getElementByDataTestId(view, `history-row-${index}`);
}
public static getModelDropdownOption(view: WebView, option: string) {
return view.findWebElement(
By.xpath(`//*[@role="listbox"]//*[contains(text(), "${option}")]`),

View file

@ -4,7 +4,6 @@ import {
WebDriver,
VSBrowser,
Key,
ActivityBar,
} from "vscode-extension-tester";
import { expect } from "chai";
import { GUIActions } from "../actions/GUI.actions";
@ -21,24 +20,6 @@ describe("GUI Test", () => {
before(async function () {
this.timeout(10000000);
// get all the view controls
const activityBar = new ActivityBar();
const controls = await activityBar.getViewControls();
expect(controls).not.empty;
// get titles from the controls
const titles = await Promise.all(
controls.map(async (control) => {
return control.getTitle();
}),
);
console.log("Titles:", titles);
// assert a view control named 'Explorer' is present
// the keyboard shortcut is part of the title, so we do a little transformation
expect(titles.some((title) => title.startsWith("Explorer"))).is.true;
await VSBrowser.instance.openResources(path.join("e2e/test-continue"));
await GUIActions.openGui();
@ -68,11 +49,11 @@ describe("GUI Test", () => {
});
describe("Chat Paths", () => {
it.only("chat → new chat → history → original chat", async () => {
it.only("chat → history → chat", async () => {
await GUIActions.selectModelFromDropdown(view, "Mock");
await GUIActions.selectModelFromDropdown(view, "TEST LLM");
const tiptap = await GUISelectors.getTipTapEditor(view);
const [tiptap] = await GUISelectors.getTipTapEditor(view);
const messagePair1 = TestUtils.generateTestMessagePair(1);
await tiptap.sendKeys(messagePair1.userMessage);
@ -91,27 +72,37 @@ describe("GUI Test", () => {
await view.switchBack();
await (await GUISelectors.getHistoryNavButton(view)).click();
await new Promise((res) => {
setTimeout(res, 2000);
});
await (await GUISelectors.getNewSessionNavButton(view)).click();
await new Promise((res) => {
setTimeout(res, 2000);
});
await (await GUISelectors.getHistoryNavButton(view)).click();
await Promise.all([
TestUtils.expectNoElement(() =>
GUISelectors.getThreadMessageByText(view, messagePair1.llmResponse),
),
TestUtils.expectNoElement(() =>
GUISelectors.getThreadMessageByText(view, messagePair2.llmResponse),
),
]);
await new Promise((res) => {
setTimeout(res, 100000000);
});
await GUIActions.switchToReactIframe(driver);
await (await GUISelectors.getNthHistoryTableRow(view, 0)).click();
await TestUtils.waitForElement(() =>
GUISelectors.getThreadMessageByText(view, messagePair1.llmResponse),
);
await TestUtils.waitForElement(() =>
GUISelectors.getThreadMessageByText(view, messagePair2.llmResponse),
);
// const messagePair3 = TestUtils.generateTestMessagePair(3);
// await tiptap.sendKeys(messagePair3.userMessage);
// await tiptap.sendKeys(Key.ENTER);
// await TestUtils.waitForElement(() =>
// GUISelectors.getThreadMessageByText(view, messagePair3.llmResponse),
// );
// ('aria-label="View History"');
const [, , tiptapNew] = await GUISelectors.getTipTapEditor(view);
const messagePair3 = TestUtils.generateTestMessagePair(3);
await tiptapNew.sendKeys(messagePair3.userMessage);
await tiptapNew.sendKeys(Key.ENTER);
await TestUtils.waitForElement(() =>
GUISelectors.getThreadMessageByText(view, messagePair1.llmResponse),
);
await TestUtils.waitForElement(() =>
GUISelectors.getThreadMessageByText(view, messagePair2.llmResponse),
);
await TestUtils.waitForElement(() =>
GUISelectors.getThreadMessageByText(view, messagePair3.llmResponse),
);
}).timeout(DEFAULT_TIMEOUT);
});
});

View file

@ -619,6 +619,7 @@
"build-debug:rust": "npm run build:rust --",
"build-release:rust": "npm run build:rust -- --release",
"e2e:compile": "tsc -p ./tsconfig.e2e.json",
"e2e:build": "npm --prefix ../../gui run build && npm run package",
"e2e:create-storage": "mkdir -p ./e2e/storage",
"e2e:get-chromedriver": "extest get-chromedriver --storage ./e2e/storage",
"e2e:get-vscode": "extest get-vscode --storage ./e2e/storage",
@ -627,7 +628,7 @@
"e2e:install-vsix": "extest install-vsix -f ./e2e/vsix/continue.vsix --extensions_dir ./e2e/.test-extensions --storage ./e2e/storage",
"e2e:test": "extest run-tests './e2e/_output/tests/*.test.js' --code_settings settings.json --extensions_dir ./e2e/.test-extensions --storage ./e2e/storage",
"e2e:clean": "rm -rf ./e2e/_output",
"e2e:all": "npm run package && npm run e2e:compile && npm run e2e:create-storage && npm run e2e:get-chromedriver && npm run e2e:get-vscode && npm run e2e:sign-vscode && npm run e2e:copy-vsix && npm run e2e:install-vsix && CONTINUE_GLOBAL_DIR=e2e/test-continue npm run e2e:test && npm run e2e:clean",
"e2e:all": "npm run e2e:build && npm run e2e:compile && npm run e2e:create-storage && npm run e2e:get-chromedriver && npm run e2e:get-vscode && npm run e2e:sign-vscode && npm run e2e:copy-vsix && npm run e2e:install-vsix && CONTINUE_GLOBAL_DIR=e2e/test-continue npm run e2e:test && npm run e2e:clean",
"e2e:quick": "npm run e2e:compile && CONTINUE_GLOBAL_DIR=e2e/test-continue npm run e2e:test && npm run e2e:clean",
"e2e:ci": "npm run e2e:compile && npm run e2e:create-storage && npm run e2e:get-chromedriver && npm run e2e:get-vscode && npm run e2e:copy-vsix && npm run e2e:install-vsix && CONTINUE_GLOBAL_DIR=e2e/test-continue npm run e2e:test"
},

View file

@ -18,11 +18,13 @@ export function HistoryTableRow({
date,
onDelete,
onEdit,
index,
}: {
sessionMetadata: SessionMetadata;
date: Date;
onDelete: (sessionId: string) => void;
onEdit: (session: SessionMetadata) => void;
index: number;
}) {
const dispatch = useDispatch();
const navigate = useNavigate();
@ -58,6 +60,7 @@ export function HistoryTableRow({
return (
<tr>
<td
data-testid={`history-row-${index}`}
className="p-1"
onMouseEnter={() => setHovered(true)}
onMouseLeave={() => setHovered(false)}
@ -75,6 +78,7 @@ export function HistoryTableRow({
}}
>
<div className="flex-1 cursor-pointer space-y-1">
{`history-row-${index}`}
{editing ? (
<div className="text-md">
<Input

View file

@ -168,6 +168,7 @@ export function History() {
)}
<HistoryTableRow
index={index}
sessionMetadata={session}
date={date}
onDelete={deleteSessionInUI}