import { render, screen, cleanup } from "@testing-library/react";
import { expect, test, vi, beforeEach, afterEach } from "vitest";
import SignupPage from "./page";

const mockPush = vi.fn();
vi.mock("next/navigation", () => ({
  useRouter: () => ({ push: mockPush }),
}));

vi.mock("../auth-context", () => ({
  useAuth: () => ({ register: vi.fn() }),
}));

beforeEach(() => vi.clearAllMocks());
afterEach(() => cleanup());

test("renders signup form with title", () => {
  render(<SignupPage />);
  expect(screen.getByRole("heading", { name: "Create account" })).toBeDefined();
});

test("renders email and password inputs", () => {
  render(<SignupPage />);
  expect(screen.getByLabelText("Email")).toBeDefined();
  expect(screen.getByLabelText("Password")).toBeDefined();
  expect(screen.getByLabelText("Confirm Password")).toBeDefined();
});

test("renders create account button", () => {
  render(<SignupPage />);
  expect(screen.getByRole("button", { name: "Create account" })).toBeDefined();
});

test("renders link to login", () => {
  render(<SignupPage />);
  expect(screen.getByText("Sign in")).toBeDefined();
});
