Merge pull request #5337 from continuedev/nate/gui-testing
Nate/gui testing
This commit is contained in:
commit
bf1ae81a5e
12 changed files with 265 additions and 34 deletions
2
.idea/scopes/Continue.xml
generated
2
.idea/scopes/Continue.xml
generated
|
|
@ -1,3 +1,3 @@
|
|||
<component name="DependencyValidationManager">
|
||||
<scope name="Continue" pattern="file[continue-intellij-extension]:*/&&!file[continue-intellij-extension]:binary/bin//*&&!file[continue-intellij-extension]:binary/build//*&&!file[continue-intellij-extension]:binary/out//*&&!file[continue-intellij-extension]:gui/dist//*&&!file[continue-intellij-extension]:extensions/intellij/build//*&&!file[continue-intellij-extension]:extensions/vscode/bin//*&&!file[continue-intellij-extension]:extensions/vscode/build//*&&!file[continue-intellij-extension]:extensions/vscode/out//*" />
|
||||
<scope name="Continue" pattern="file:*/&&!file:binary/bin//*&&!file:binary/build//*&&!file:binary/out//*&&!file:gui/dist//*&&!file:extensions/intellij/build//*&&!file:extensions/vscode/bin//*&&!file:extensions/vscode/build//*&&!file:extensions/vscode/out//*&&!file:**/*.coverage&&!file:**/*.coveragedata&&!file:**/coverage//*&&!file:**/.coverage//*&&!file:**/assets//**" />
|
||||
</component>
|
||||
6
gui/package-lock.json
generated
6
gui/package-lock.json
generated
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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 <></>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
||||
|
|
|
|||
|
|
@ -114,7 +114,10 @@ function ContinueInputBox(props: ContinueInputBoxProps) {
|
|||
: {};
|
||||
|
||||
return (
|
||||
<div className={`${props.hidden ? "hidden" : ""}`}>
|
||||
<div
|
||||
className={`${props.hidden ? "hidden" : ""}`}
|
||||
data-testid="continue-input-box"
|
||||
>
|
||||
<div className={`relative flex flex-col px-2`}>
|
||||
{props.isMainInput && <Lump />}
|
||||
<GradientBorder
|
||||
|
|
|
|||
|
|
@ -264,3 +264,14 @@ export class IdeMessenger implements IIdeMessenger {
|
|||
export const IdeMessengerContext = createContext<IIdeMessenger>(
|
||||
new IdeMessenger(),
|
||||
);
|
||||
|
||||
export const IdeMessengerProvider: React.FC<{
|
||||
children: React.ReactNode;
|
||||
messenger?: IIdeMessenger;
|
||||
}> = ({ children, messenger = new IdeMessenger() }) => {
|
||||
return (
|
||||
<IdeMessengerContext.Provider value={messenger}>
|
||||
{children}
|
||||
</IdeMessengerContext.Provider>
|
||||
);
|
||||
};
|
||||
122
gui/src/context/MockIdeMessenger.ts
Normal file
122
gui/src/context/MockIdeMessenger.ts
Normal file
|
|
@ -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<T extends keyof FromWebviewProtocol>(
|
||||
messageType: T,
|
||||
data: FromWebviewProtocol[T][0],
|
||||
): Promise<FromWebviewProtocol[T][1]> {
|
||||
function returnFor<K extends keyof FromWebviewProtocol>(
|
||||
_: 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<ChatMessage[], PromptLog | undefined> {
|
||||
yield [
|
||||
{
|
||||
role: "assistant",
|
||||
content: "This is a test",
|
||||
},
|
||||
];
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
post<T extends keyof FromWebviewProtocol>(
|
||||
messageType: T,
|
||||
data: FromWebviewProtocol[T][0],
|
||||
messageId?: string,
|
||||
attempt?: number,
|
||||
): void {}
|
||||
|
||||
async request<T extends keyof FromWebviewProtocol>(
|
||||
messageType: T,
|
||||
data: FromWebviewProtocol[T][0],
|
||||
): Promise<WebviewSingleProtocolMessage<T>> {
|
||||
const content = await defaultMockHandleMessage(messageType, data);
|
||||
return {
|
||||
status: "success",
|
||||
content,
|
||||
done: true,
|
||||
};
|
||||
}
|
||||
|
||||
respond<T extends keyof ToWebviewProtocol>(
|
||||
messageType: T,
|
||||
data: ToWebviewProtocol[T][1],
|
||||
messageId: string,
|
||||
): void {}
|
||||
|
||||
async *streamRequest<T extends keyof FromWebviewProtocol>(
|
||||
messageType: T,
|
||||
data: FromWebviewProtocol[T][0],
|
||||
cancelToken?: AbortSignal,
|
||||
): AsyncGenerator<
|
||||
GeneratorYieldType<FromWebviewProtocol[T][1]>[],
|
||||
GeneratorReturnType<FromWebviewProtocol[T][1]> | undefined
|
||||
> {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
62
gui/src/pages/gui/Chat.test.tsx
Normal file
62
gui/src/pages/gui/Chat.test.tsx
Normal file
|
|
@ -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(<Chat />);
|
||||
expect(await screen.findByTestId("continue-input-box")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("should be able to toggle modes", async () => {
|
||||
await renderWithProviders(<Chat />);
|
||||
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(<Chat />);
|
||||
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();
|
||||
});
|
||||
});
|
||||
|
|
@ -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(<HistoryPage />);
|
||||
it("History text is existed after render", async () => {
|
||||
await renderWithProviders(<HistoryPage />);
|
||||
expect(screen.getByTestId("history-sessions-note")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("History shows the first item in the list", async () => {
|
||||
await renderWithProviders(<HistoryPage />);
|
||||
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();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -109,7 +109,9 @@ const persistedReducer = persistReducer<ReturnType<typeof rootReducer>>(
|
|||
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<typeof rootReducer>;
|
||||
|
||||
|
|
|
|||
|
|
@ -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<RenderOptions, "queries"> & {
|
|||
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) => (
|
||||
<MemoryRouter {...routerProps}>
|
||||
<Provider store={store}>
|
||||
<AuthProvider>{children}</AuthProvider>
|
||||
</Provider>
|
||||
<IdeMessengerProvider messenger={ideMessenger}>
|
||||
<Provider store={store}>
|
||||
<AuthProvider>
|
||||
<MainEditorProvider>
|
||||
<LumpProvider>
|
||||
{children}
|
||||
<SetupListeners />
|
||||
</LumpProvider>
|
||||
</MainEditorProvider>
|
||||
</AuthProvider>
|
||||
</Provider>
|
||||
</IdeMessengerProvider>
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
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!,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue