40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { fireEvent, render, screen } from "@testing-library/react";
|
|
import { LoginWithGoogle } from "@ui/components/BrandButtons/LoginWithGoogle";
|
|
import { useLoginGoogle } from "@ui/hooks/auth";
|
|
import { vi } from "vitest";
|
|
|
|
vi.mock("../../hooks/auth", () => ({
|
|
useLoginGoogle: vi.fn(),
|
|
}));
|
|
|
|
describe("LoginWithGoogle", () => {
|
|
it("renders the Google login button", () => {
|
|
const mockLoginWithGoogle = vi.fn();
|
|
(useLoginGoogle as ReturnType<typeof vi.fn>).mockReturnValue({
|
|
loginWithGoogle: mockLoginWithGoogle,
|
|
});
|
|
|
|
render(<LoginWithGoogle />);
|
|
|
|
const button = screen.getByRole("button", {
|
|
name: /Continuer avec Google/i,
|
|
});
|
|
expect(button).toBeInTheDocument();
|
|
});
|
|
|
|
it("calls loginWithGoogle when clicked", () => {
|
|
const mockLoginWithGoogle = vi.fn();
|
|
(useLoginGoogle as ReturnType<typeof vi.fn>).mockReturnValue({
|
|
loginWithGoogle: mockLoginWithGoogle,
|
|
});
|
|
|
|
render(<LoginWithGoogle />);
|
|
|
|
const button = screen.getByRole("button", {
|
|
name: /Continuer avec Google/i,
|
|
});
|
|
fireEvent.click(button);
|
|
|
|
expect(mockLoginWithGoogle).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|