From 52b2ff7f8e7e55083f31879d5e60bd2c8b307023 Mon Sep 17 00:00:00 2001 From: Nate Date: Thu, 24 Apr 2025 08:58:15 -0700 Subject: [PATCH] MockIdeMessenger in redux store.ts --- gui/src/context/MockIdeMessenger.ts | 1 - gui/src/pages/history/history.test.tsx | 14 +++++++++----- gui/src/redux/store.ts | 8 +++++--- gui/src/util/test/render.tsx | 18 ++++++++++++++---- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/gui/src/context/MockIdeMessenger.ts b/gui/src/context/MockIdeMessenger.ts index 35633dc18..ac40a0a7f 100644 --- a/gui/src/context/MockIdeMessenger.ts +++ b/gui/src/context/MockIdeMessenger.ts @@ -95,7 +95,6 @@ export class MockIdeMessenger implements IIdeMessenger { messageType: T, data: FromWebviewProtocol[T][0], ): Promise> { - console.log("request: ", messageType); const content = await defaultMockHandleMessage(messageType, data); return { status: "success", diff --git a/gui/src/pages/history/history.test.tsx b/gui/src/pages/history/history.test.tsx index ae8ccff94..69227aa72 100644 --- a/gui/src/pages/history/history.test.tsx +++ b/gui/src/pages/history/history.test.tsx @@ -19,11 +19,15 @@ describe("history Page test", () => { expect(screen.getByTestId("history-sessions-note")).toBeInTheDocument(); }); - it.skip("History shows the first item in the list", async () => { - await act(async () => renderWithProviders()); - // renderWithProviders(); - await new Promise((resolve) => setTimeout(resolve, 3000)); - const sessionElement = await screen.findByText("Session 1"); + it("History shows the first item in the list", async () => { + renderWithProviders(); + const sessionElement = await screen.findByText( + "Session 1", + {}, + { + timeout: 5000, + }, + ); expect(sessionElement).toBeInTheDocument(); }); }); 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 91c626643..8963464cc 100644 --- a/gui/src/util/test/render.tsx +++ b/gui/src/util/test/render.tsx @@ -1,4 +1,4 @@ -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"; @@ -9,6 +9,7 @@ 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"; // As a basic setup, import your same slice reducers // This type interface extends the default options for render from RTL, as well @@ -22,9 +23,13 @@ export function renderWithProviders( ui: React.ReactElement, extendedRenderOptions: ExtendedRenderOptions = {}, ) { + const ideMessenger = new MockIdeMessenger(); + const { // Automatically create a store instance if no store was passed in - store = setupStore(), + store = setupStore({ + ideMessenger, + }), routerProps = {}, ...renderOptions } = extendedRenderOptions; @@ -33,7 +38,7 @@ export function renderWithProviders( const Wrapper = ({ children }: PropsWithChildren) => ( - + {children} @@ -44,10 +49,15 @@ export function renderWithProviders( ); + let rendered: RenderResult; + act(() => { + 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!, }; }