mirror of
https://github.com/StanGirard/quivr.git
synced 2024-12-17 23:51:51 +03:00
6b39dd5641
* test(GoogleLogin): add unit tests * test: run tests concurrently * test(<LogoutPage/>): add unit tests * chore: refactor <SigupPage/> * test(<SignUpPage />): add unit tests
52 lines
1.3 KiB
TypeScript
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);
|
|
});
|
|
});
|