/**
 * Login 组件单元测试
 */
import { render, screen, fireEvent, waitFor } from "@testing-library/react";
import { describe, it, expect } from "vitest";
import { BrowserRouter } from "react-router-dom";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import Login from "@/pages/auth/Login";

const renderLogin = () => {
  const queryClient = new QueryClient({
    defaultOptions: {
      queries: { retry: false },
      mutations: { retry: false },
    },
  });

  return render(
    <QueryClientProvider client={queryClient}>
      <BrowserRouter>
        <Login />
      </BrowserRouter>
    </QueryClientProvider>,
  );
};

describe.skip("Login Component", () => {
  it("should render login form", () => {
    renderLogin();

    expect(screen.getByPlaceholderText("邮箱")).toBeInTheDocument();
    expect(screen.getByPlaceholderText("密码")).toBeInTheDocument();
    expect(screen.getByRole("button", { name: "登录" })).toBeInTheDocument();
  });

  it("should show validation errors for empty fields", async () => {
    renderLogin();

    const submitButton = screen.getByRole("button", { name: "登录" });
    fireEvent.click(submitButton);

    await waitFor(() => {
      expect(screen.getByText("请输入邮箱")).toBeInTheDocument();
      expect(screen.getByText("请输入密码")).toBeInTheDocument();
    });
  });

  it("should navigate to register page", () => {
    renderLogin();

    const registerLink = screen.getByText("立即注册");
    expect(registerLink).toBeInTheDocument();
  });
});
