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 }),
  useSearchParams: () => ({ get: () => null }),
}));

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

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

test("renders signup form with title", () => {
  render(<SignupPage />);
  // Step 1 shows "Join with Invite" title (invite code entry)
  expect(screen.getByRole("heading", { name: "Join with Invite" })).toBeDefined();
});

test("renders invite code input", () => {
  render(<SignupPage />);
  expect(screen.getByLabelText("Invite Code")).toBeDefined();
});

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

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