MockIdeMessenger in redux store.ts
This commit is contained in:
parent
5e6eeac88d
commit
52b2ff7f8e
4 changed files with 28 additions and 13 deletions
|
|
@ -95,7 +95,6 @@ export class MockIdeMessenger implements IIdeMessenger {
|
|||
messageType: T,
|
||||
data: FromWebviewProtocol[T][0],
|
||||
): Promise<WebviewSingleProtocolMessage<T>> {
|
||||
console.log("request: ", messageType);
|
||||
const content = await defaultMockHandleMessage(messageType, data);
|
||||
return {
|
||||
status: "success",
|
||||
|
|
|
|||
|
|
@ -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(<HistoryPage />));
|
||||
// renderWithProviders(<HistoryPage />);
|
||||
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(<HistoryPage />);
|
||||
const sessionElement = await screen.findByText(
|
||||
"Session 1",
|
||||
{},
|
||||
{
|
||||
timeout: 5000,
|
||||
},
|
||||
);
|
||||
expect(sessionElement).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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,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) => (
|
||||
<MemoryRouter {...routerProps}>
|
||||
<IdeMessengerProvider messenger={new MockIdeMessenger()}>
|
||||
<IdeMessengerProvider messenger={ideMessenger}>
|
||||
<Provider store={store}>
|
||||
<AuthProvider>
|
||||
{children}
|
||||
|
|
@ -44,10 +49,15 @@ export function renderWithProviders(
|
|||
</MemoryRouter>
|
||||
);
|
||||
|
||||
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!,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue