diff --git a/.idea/scopes/Continue.xml b/.idea/scopes/Continue.xml
index 3b28a76b1..d5943c932 100644
--- a/.idea/scopes/Continue.xml
+++ b/.idea/scopes/Continue.xml
@@ -1,3 +1,3 @@
-
+
\ No newline at end of file
diff --git a/gui/package-lock.json b/gui/package-lock.json
index 3f934ca59..183bdc0b1 100644
--- a/gui/package-lock.json
+++ b/gui/package-lock.json
@@ -4364,9 +4364,9 @@
}
},
"node_modules/caniuse-lite": {
- "version": "1.0.30001662",
- "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001662.tgz",
- "integrity": "sha512-sgMUVwLmGseH8ZIrm1d51UbrhqMCH3jvS7gF/M6byuHOnKyLOBL7W8yz5V02OHwgLGA36o/AFhWzzh4uc5aqTA==",
+ "version": "1.0.30001715",
+ "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001715.tgz",
+ "integrity": "sha512-7ptkFGMm2OAOgvZpwgA4yjQ5SQbrNVGdRjzH0pBdy1Fasvcr+KAeECmbCAECzTuDuoX0FCY8KzUxjf9+9kfZEw==",
"funding": [
{
"type": "opencollective",
diff --git a/gui/src/App.tsx b/gui/src/App.tsx
index 15082d35b..2f3a94dd8 100644
--- a/gui/src/App.tsx
+++ b/gui/src/App.tsx
@@ -45,7 +45,7 @@ const router = createMemoryRouter([
Prevents entire app from rerendering continuously with useSetup in App
TODO - look into a more redux-esque way to do this
*/
-function SetupListeners() {
+export function SetupListeners() {
useSetup();
return <>>;
}
diff --git a/gui/src/components/find/FindWidget.tsx b/gui/src/components/find/FindWidget.tsx
index 7f6874aeb..fd174f59c 100644
--- a/gui/src/components/find/FindWidget.tsx
+++ b/gui/src/components/find/FindWidget.tsx
@@ -11,9 +11,7 @@ import {
useRef,
useState,
} from "react";
-import { useSelector } from "react-redux";
import { HeaderButton, Input } from "..";
-import { RootState } from "../../redux/store";
import HeaderButtonWithToolTip from "../gui/HeaderButtonWithToolTip";
import { useAppSelector } from "../../redux/hooks";
diff --git a/gui/src/components/mainInput/ContinueInputBox.tsx b/gui/src/components/mainInput/ContinueInputBox.tsx
index 1bcbb3c8c..457aefd44 100644
--- a/gui/src/components/mainInput/ContinueInputBox.tsx
+++ b/gui/src/components/mainInput/ContinueInputBox.tsx
@@ -114,7 +114,10 @@ function ContinueInputBox(props: ContinueInputBoxProps) {
: {};
return (
-
+
{props.isMainInput &&
}
(
new IdeMessenger(),
);
+
+export const IdeMessengerProvider: React.FC<{
+ children: React.ReactNode;
+ messenger?: IIdeMessenger;
+}> = ({ children, messenger = new IdeMessenger() }) => {
+ return (
+
+ {children}
+
+ );
+};
diff --git a/gui/src/context/MockIdeMessenger.ts b/gui/src/context/MockIdeMessenger.ts
new file mode 100644
index 000000000..ac40a0a7f
--- /dev/null
+++ b/gui/src/context/MockIdeMessenger.ts
@@ -0,0 +1,122 @@
+import { IDE, PromptLog } from "core";
+import {
+ FromWebviewProtocol,
+ ToCoreProtocol,
+ ToWebviewProtocol,
+} from "core/protocol";
+import { MessageIde } from "core/protocol/messenger/messageIde";
+import {
+ GeneratorReturnType,
+ GeneratorYieldType,
+ WebviewSingleProtocolMessage,
+} from "core/protocol/util";
+import { ChatMessage } from "../redux/store";
+import { IIdeMessenger } from "./IdeMessenger";
+
+async function defaultMockHandleMessage(
+ messageType: T,
+ data: FromWebviewProtocol[T][0],
+): Promise {
+ function returnFor(
+ _: K,
+ value: FromWebviewProtocol[K][1],
+ ): FromWebviewProtocol[T][1] {
+ return value as unknown as FromWebviewProtocol[T][1];
+ }
+
+ switch (messageType) {
+ case "history/list":
+ return returnFor("history/list", [
+ {
+ title: "Session 1",
+ sessionId: "session-1",
+ dateCreated: new Date().toString(),
+ workspaceDirectory: "/tmp",
+ },
+ ]);
+ case "getControlPlaneSessionInfo":
+ return returnFor("getControlPlaneSessionInfo", {
+ accessToken: "",
+ account: {
+ label: "",
+ id: "",
+ },
+ });
+ case "config/getSerializedProfileInfo":
+ return returnFor("config/getSerializedProfileInfo", {
+ organizations: [],
+ profileId: "test-profile",
+ result: {
+ config: undefined,
+ errors: [],
+ configLoadInterrupted: false,
+ },
+ selectedOrgId: "local",
+ });
+ default:
+ throw new Error(`Unknown message type ${messageType}`);
+ }
+}
+
+export class MockIdeMessenger implements IIdeMessenger {
+ ide: IDE;
+
+ constructor() {
+ this.ide = new MessageIde(
+ (messageType, data) => {
+ throw new Error("Not implemented");
+ },
+ (messageType, callback) => {},
+ );
+ }
+
+ async *llmStreamChat(
+ msg: ToCoreProtocol["llm/streamChat"][0],
+ cancelToken: AbortSignal,
+ ): AsyncGenerator {
+ yield [
+ {
+ role: "assistant",
+ content: "This is a test",
+ },
+ ];
+
+ return undefined;
+ }
+
+ post(
+ messageType: T,
+ data: FromWebviewProtocol[T][0],
+ messageId?: string,
+ attempt?: number,
+ ): void {}
+
+ async request(
+ messageType: T,
+ data: FromWebviewProtocol[T][0],
+ ): Promise> {
+ const content = await defaultMockHandleMessage(messageType, data);
+ return {
+ status: "success",
+ content,
+ done: true,
+ };
+ }
+
+ respond(
+ messageType: T,
+ data: ToWebviewProtocol[T][1],
+ messageId: string,
+ ): void {}
+
+ async *streamRequest(
+ messageType: T,
+ data: FromWebviewProtocol[T][0],
+ cancelToken?: AbortSignal,
+ ): AsyncGenerator<
+ GeneratorYieldType[],
+ GeneratorReturnType | undefined
+ > {
+ return undefined;
+ }
+}
diff --git a/gui/src/pages/gui/Chat.test.tsx b/gui/src/pages/gui/Chat.test.tsx
new file mode 100644
index 000000000..5339f831b
--- /dev/null
+++ b/gui/src/pages/gui/Chat.test.tsx
@@ -0,0 +1,62 @@
+import { renderWithProviders } from "../../util/test/render";
+import { screen, waitFor } from "@testing-library/dom";
+import { act, fireEvent } from "@testing-library/react";
+import { Chat } from "./Chat";
+
+describe("Chat page test", () => {
+ it("should render input box", async () => {
+ await renderWithProviders();
+ expect(await screen.findByTestId("continue-input-box")).toBeInTheDocument();
+ });
+
+ it("should be able to toggle modes", async () => {
+ await renderWithProviders();
+ expect(screen.getByText("Chat")).toBeInTheDocument();
+
+ // Simulate cmd+. keyboard shortcut to toggle modes
+ act(() => {
+ document.dispatchEvent(
+ new KeyboardEvent("keydown", {
+ key: ".",
+ metaKey: true, // cmd key on Mac
+ }),
+ );
+ });
+
+ // Check that it switched to Edit mode
+ expect(await screen.findByText("Edit")).toBeInTheDocument();
+
+ act(() => {
+ document.dispatchEvent(
+ new KeyboardEvent("keydown", {
+ key: ".",
+ metaKey: true, // cmd key on Mac
+ }),
+ );
+ });
+
+ // Check that it switched to Agent mode
+ expect(await screen.findByText("Agent")).toBeInTheDocument();
+ });
+
+ it.skip("should send a message and receive a response", async () => {
+ const { user, container } = await renderWithProviders();
+ const inputBox = await waitFor(() =>
+ container.querySelector(".ProseMirror")!.querySelector("p"),
+ );
+ expect(inputBox).toBeDefined();
+
+ const sendButton = await screen.findByTestId("submit-input-button");
+
+ await act(async () => {
+ // Focus input box
+ inputBox!.focus();
+
+ // Type message
+ await user.type(inputBox!, "Hello, world!");
+
+ sendButton.click();
+ });
+ expect(await screen.findByText("Hello, world!")).toBeInTheDocument();
+ });
+});
diff --git a/gui/src/pages/history/history.test.tsx b/gui/src/pages/history/history.test.tsx
index 9a9d2772c..8ab4f2862 100644
--- a/gui/src/pages/history/history.test.tsx
+++ b/gui/src/pages/history/history.test.tsx
@@ -2,19 +2,21 @@ import { screen } from "@testing-library/dom";
import { renderWithProviders } from "../../util/test/render";
import HistoryPage from "./index";
-const navigateFn = vi.fn();
-
-vi.mock("react-router-dom", async () => {
- const original = await vi.importActual("react-router-dom");
- return {
- ...original,
- useNavigate: () => navigateFn,
- };
-});
-
describe("history Page test", () => {
- it("History text is existed after render", () => {
- renderWithProviders();
+ it("History text is existed after render", async () => {
+ await renderWithProviders();
expect(screen.getByTestId("history-sessions-note")).toBeInTheDocument();
});
+
+ it("History shows the first item in the list", async () => {
+ await renderWithProviders();
+ const sessionElement = await screen.findByText(
+ "Session 1",
+ {},
+ {
+ timeout: 3000, // There is a 2000ms timeout before the first call to refreshSessionMetadata is called
+ },
+ );
+ expect(sessionElement).toBeInTheDocument();
+ });
});
diff --git a/gui/src/redux/selectors/index.ts b/gui/src/redux/selectors/index.ts
index cca27e6e2..bbfea5364 100644
--- a/gui/src/redux/selectors/index.ts
+++ b/gui/src/redux/selectors/index.ts
@@ -47,7 +47,5 @@ export const selectUseActiveFile = createSelector(
(defaultContext) => defaultContext?.includes("activeFile" as any),
);
-export const selectUseHub = createSelector(
- [(state: RootState) => state.config.config.usePlatform],
- (usePlatform) => usePlatform,
-);
+export const selectUseHub = (state: RootState) =>
+ state.config.config.usePlatform;
diff --git a/gui/src/redux/store.ts b/gui/src/redux/store.ts
index 4a4d939c0..aa7c2bb5c 100644
--- a/gui/src/redux/store.ts
+++ b/gui/src/redux/store.ts
@@ -109,7 +109,9 @@ const persistedReducer = persistReducer>(
rootReducer,
);
-export function setupStore() {
+export function setupStore(options: { ideMessenger?: IIdeMessenger }) {
+ const ideMessenger = options.ideMessenger ?? new IdeMessenger();
+
const logger = createLogger({
// Customize logger options if needed
collapsed: true, // Collapse console groups by default
@@ -126,7 +128,7 @@ export function setupStore() {
serializableCheck: false,
thunk: {
extraArgument: {
- ideMessenger: new IdeMessenger(),
+ ideMessenger,
},
},
}),
@@ -148,7 +150,7 @@ export type AppThunkDispatch = ThunkDispatch<
UnknownAction
>;
-export const store = setupStore();
+export const store = setupStore({});
export type RootState = ReturnType;
diff --git a/gui/src/util/test/render.tsx b/gui/src/util/test/render.tsx
index 95f1cbd2d..2b9ae5b29 100644
--- a/gui/src/util/test/render.tsx
+++ b/gui/src/util/test/render.tsx
@@ -1,11 +1,17 @@
-import type { RenderOptions } from "@testing-library/react";
+import type { RenderOptions, RenderResult } from "@testing-library/react";
import { render } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { PropsWithChildren } from "react";
import { Provider } from "react-redux";
import { MemoryRouter, RouterProps } from "react-router-dom";
import { AuthProvider } from "../../context/Auth";
+import { IdeMessengerProvider } from "../../context/IdeMessenger";
+import { MockIdeMessenger } from "../../context/MockIdeMessenger";
import { setupStore } from "../../redux/store";
+import { SetupListeners } from "../../App";
+import { act } from "@testing-library/react";
+import { LumpProvider } from "../../components/mainInput/Lump/LumpContext";
+import { MainEditorProvider } from "../../components/mainInput/TipTapEditor";
// As a basic setup, import your same slice reducers
// This type interface extends the default options for render from RTL, as well
@@ -15,13 +21,26 @@ type ExtendedRenderOptions = Omit & {
routerProps?: RouterProps;
};
-export function renderWithProviders(
+function setupMocks() {
+ global.ResizeObserver = vi.fn().mockImplementation(() => ({
+ observe: vi.fn(),
+ unobserve: vi.fn(),
+ disconnect: vi.fn(),
+ }));
+}
+
+export async function renderWithProviders(
ui: React.ReactElement,
extendedRenderOptions: ExtendedRenderOptions = {},
) {
+ setupMocks();
+ const ideMessenger = new MockIdeMessenger();
+
const {
// Automatically create a store instance if no store was passed in
- store = setupStore(),
+ store = setupStore({
+ ideMessenger,
+ }),
routerProps = {},
...renderOptions
} = extendedRenderOptions;
@@ -30,16 +49,30 @@ export function renderWithProviders(
const Wrapper = ({ children }: PropsWithChildren) => (
-
- {children}
-
+
+
+
+
+
+ {children}
+
+
+
+
+
+
);
+ let rendered: RenderResult;
+ await act(async () => {
+ rendered = render(ui, { wrapper: Wrapper, ...renderOptions });
+ });
+
// Return an object with the store and all of RTL's query functions
return {
user,
store,
- ...render(ui, { wrapper: Wrapper, ...renderOptions }),
+ ...rendered!,
};
}