quivr/frontend/app/(auth)/logout/__tests__/page.test.tsx
Mamadou DICKO 6b39dd5641
Frontend/unit tests (#485)
* test(GoogleLogin): add unit tests

* test: run tests concurrently

* test(<LogoutPage/>): add unit tests

* chore: refactor <SigupPage/>

* test(<SignUpPage />): add unit tests
2023-07-03 14:59:24 +02:00

52 lines
1.3 KiB
TypeScript

import { render } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import Logout from "../page";
// mocking related hooks
const mockUseLogout = vi.fn(() => ({
handleLogout: vi.fn(),
isPending: false,
}));
vi.mock("../hooks/useLogout", () => ({
useLogout: () => mockUseLogout(),
}));
describe("Logout component", () => {
it("should render correctly", () => {
const { getByTestId } = render(<Logout />);
const logoutPage = getByTestId("logout-page");
expect(logoutPage).toBeDefined();
});
it("should call handleLogout 1 time when logout button is clicked", () => {
const mockHandleLogout = vi.fn();
mockUseLogout.mockReturnValue({
handleLogout: mockHandleLogout,
isPending: false,
});
const { getByTestId } = render(<Logout />);
const logoutButton = getByTestId("logout-button");
logoutButton.click();
expect(mockHandleLogout).toHaveBeenCalledTimes(1);
});
it("should not call handleLogout when isPending is true", () => {
const mockHandleLogout = vi.fn();
mockUseLogout.mockReturnValue({
handleLogout: mockHandleLogout,
isPending: true,
});
const { getByTestId } = render(<Logout />);
const logoutButton = getByTestId("logout-button");
logoutButton.click();
expect(mockHandleLogout).toHaveBeenCalledTimes(0);
});
});