quivr/frontend/app/(auth)/logout/hooks/__tests__/useLogout.test.ts
Mamadou DICKO 7a2450eaf4
[ShareableBrain]: improve UX, fix minors bugs, refactor (#695)
* feat: add empty access list message

* feat: set default role to viewer

* feat: reset user invitation form after submit

* feat: add removing access indicator

* feat: add brain name on invitation page

* feat: display brain name on chat page

* feat: clear localStorage on logout
2023-07-18 18:28:44 +02:00

41 lines
934 B
TypeScript

import { act, renderHook } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { useLogout } from "../useLogout";
const mockSignOut = vi.fn(() => ({ error: null }));
const mockUseSupabase = () => ({
supabase: {
auth: {
signOut: mockSignOut,
},
},
});
vi.mock("next/navigation", () => ({
useRouter: () => ({ replace: vi.fn() }),
}));
vi.mock("@/lib/context/SupabaseProvider", () => ({
useSupabase: () => mockUseSupabase(),
}));
const clearLocalStorageMock = vi.fn();
Object.defineProperty(window, "localStorage", {
value: {
clear: clearLocalStorageMock,
},
});
describe("useLogout", () => {
it("should call signOut", async () => {
const { result } = renderHook(() => useLogout());
await act(() => result.current.handleLogout());
expect(mockSignOut).toHaveBeenCalledTimes(1);
expect(clearLocalStorageMock).toHaveBeenCalledTimes(1);
});
});