[#336] added logout logic to user menu (#380)

Co-authored-by: Camille Moussu <cmoussu@linagora.com>
This commit is contained in:
Camille Moussu
2025-12-02 10:07:41 +01:00
committed by GitHub
parent c408e1818f
commit 8a68280023
2 changed files with 54 additions and 5 deletions
+47 -1
View File
@@ -1,7 +1,8 @@
import { fireEvent, screen, waitFor } from "@testing-library/react";
import { act, fireEvent, screen, waitFor } from "@testing-library/react";
import "@testing-library/jest-dom";
import { Menubar } from "../../src/components/Menubar/Menubar";
import { renderWithProviders } from "../utils/Renderwithproviders";
import * as oidcAuth from "../../src/features/User/oidcAuth";
describe("Calendar App Component Display Tests", () => {
const preloadedState = {
@@ -714,3 +715,48 @@ describe("Menubar interaction with expanded Dialog", () => {
expect(container.querySelector(".select-display")).toBeInTheDocument();
});
});
describe("Menubar logout flow", () => {
beforeEach(() => {
localStorage.clear();
sessionStorage.clear();
jest.clearAllMocks();
});
function renderMenubar(user = { name: "John", email: "test@example.com" }) {
const preloadedState = {
user: { userData: user },
settings: { view: "calendar" },
};
return renderWithProviders(
<Menubar
calendarRef={{ current: null }}
onRefresh={() => {}}
currentDate={new Date()}
currentView="dayGridMonth"
/>,
preloadedState
);
}
it("clears storage before redirecting", async () => {
sessionStorage.setItem("tokenSet", "dummy");
const logoutSpy = jest
.spyOn(oidcAuth, "Logout")
.mockResolvedValue(new URL("https://logout.url"));
await act(async () => {
renderMenubar();
});
await act(async () => {
fireEvent.click(screen.getByLabelText("menubar.userProfile"));
});
await act(async () => {
fireEvent.click(screen.getByText("menubar.logout"));
});
expect(logoutSpy).toHaveBeenCalled();
expect(sessionStorage.length).toBe(0);
});
});