[#58] changed the error detection to prevent displaying error on first connection

This commit is contained in:
Camille Moussu
2025-08-22 10:26:51 +02:00
committed by Benoit TELLIER
parent a6c6f944a6
commit 4ba8be73b7
5 changed files with 45 additions and 35 deletions
+11 -10
View File
@@ -1,18 +1,21 @@
import { screen, waitFor } from "@testing-library/react";
import thunk from "redux-thunk";
import thunk, { ThunkDispatch } from "redux-thunk";
import HandleLogin from "../../../src/features/User/HandleLogin";
import * as oidcAuth from "../../../src/features/User/oidcAuth";
import { renderWithProviders } from "../../utils/Renderwithproviders";
import { clientConfig } from "../../../src/features/User/oidcAuth";
import * as apiUtils from "../../../src/utils/apiUtils";
clientConfig.url = "https://example.com";
import * as appHooks from "../../../src/app/hooks";
import { push } from "redux-first-history";
clientConfig.url = "https://example.com";
describe("HandleLogin", () => {
beforeEach(() => {
jest.spyOn(apiUtils, "redirectTo").mockImplementation(() => {});
jest.clearAllMocks();
jest.spyOn(apiUtils, "redirectTo").mockImplementation(() => {});
const dispatch = jest.fn() as ThunkDispatch<any, any, any>;
jest.spyOn(appHooks, "useAppDispatch").mockReturnValue(dispatch);
sessionStorage.clear();
});
@@ -37,8 +40,6 @@ describe("HandleLogin", () => {
);
expect(apiUtils.redirectTo).toHaveBeenCalledWith(loginUrlMock.redirectTo);
});
expect(screen.getByText(/error/i)).toBeInTheDocument();
});
test("shows Loading when userData exists and calendars pending is true", () => {
@@ -72,9 +73,9 @@ describe("HandleLogin", () => {
expect(screen.getByAltText("loading")).toBeInTheDocument();
});
test("shows Error when userData doesnt exists and calendars pending is false", () => {
renderWithProviders(<HandleLogin />);
expect(screen.getByText("Error")).toBeInTheDocument();
test("goes to error page when userData doesnt exists after loading and calendars pending is false", () => {
const dispatch = appHooks.useAppDispatch();
renderWithProviders(<HandleLogin />, { user: { loading: false } });
expect(dispatch).toHaveBeenCalledWith(push("/error"));
});
});