import { describe, it, expect } from 'vitest';
import { render, screen } from '@testing-library/react';
import HomePage from '@/app/page';

describe('HomePage', () => {
  it('should render hero section', () => {
    render(<HomePage />);
    const heading = screen.getByRole('heading', { level: 1 });
    expect(heading.textContent).toMatch(/让/);
    expect(heading.textContent).toMatch(/每个人/);
    expect(heading.textContent).toMatch(/都能用好 AI/);
    expect(screen.getByText(/免费 AI 知识社区/)).toBeInTheDocument();
  });

  it('should render feature section title', () => {
    render(<HomePage />);
    expect(screen.getByText('为什么选择宇之然？')).toBeInTheDocument();
  });

  it('should render all four features', () => {
    render(<HomePage />);
    expect(screen.getByText('分领域指南')).toBeInTheDocument();
    expect(screen.getByText('AI 沙盒实战')).toBeInTheDocument();
    expect(screen.getByText('提示词库')).toBeInTheDocument();
    expect(screen.getByText('持续更新')).toBeInTheDocument();
  });

  it('should render stats section', () => {
    render(<HomePage />);
    expect(screen.getByText('50+')).toBeInTheDocument();
    expect(screen.getByText('200+')).toBeInTheDocument();
    expect(screen.getByText('30+')).toBeInTheDocument();
    expect(screen.getByText('10,000+')).toBeInTheDocument();
  });

  it('should render course preview section', () => {
    render(<HomePage />);
    expect(screen.getByText('热门专题')).toBeInTheDocument();
    expect(screen.getByText('AI 通识：零基础入门')).toBeInTheDocument();
    expect(screen.getByText('提示词工程从入门到精通')).toBeInTheDocument();
    expect(screen.getByText('用 AI 提升 10 倍办公效率')).toBeInTheDocument();
  });

  it('should render sandbox preview section', () => {
    render(<HomePage />);
    expect(screen.getByText('AI 沙盒实战')).toBeInTheDocument();
    expect(screen.getByText('内置 AI 对话沙盒，边学边练')).toBeInTheDocument();
  });

  it('should render CTA section', () => {
    render(<HomePage />);
    expect(screen.getByText('准备好开启 AI 之旅了吗？')).toBeInTheDocument();
    expect(screen.getByText('立即注册，免费探索所有内容')).toBeInTheDocument();
  });

  it('should have CTA buttons with correct links', () => {
    render(<HomePage />);
    const startLearning = screen.getByText('开始探索').closest('a');
    expect(startLearning).toHaveAttribute('href', '/courses');

    const registerBtn = screen.getAllByText('免费注册');
    expect(registerBtn.length).toBeGreaterThanOrEqual(1);
  });

  it('should render course descriptions', () => {
    render(<HomePage />);
    expect(screen.getAllByText('探索 AI 世界').length).toBe(3);
  });

  it('should render sandbox with mock chat interface', () => {
    render(<HomePage />);
    expect(screen.getByText('AI 沙盒实战')).toBeInTheDocument();
    expect(screen.getByText('内置 AI 对话沙盒，边学边练')).toBeInTheDocument();
  });
});
