import { fireEvent, render, screen } from "@testing-library/react";
import { LoginWithGoogle } from "@ui/components/BrandButtons/LoginWithGoogle";
import { vi } from "vitest";
import { useLoginGoogle } from "../../hooks/auth";

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);
  });
});
