import { render, screen } from "@testing-library/react";
import { describe, it, expect } from "vitest";
import Home from "../components/HomeContent";
import { NextIntlClientProvider } from "next-intl";
import messages from "../messages/de.json";

const renderHome = () => {
  return render(
    <NextIntlClientProvider locale="de" messages={messages}>
      <Home />
    </NextIntlClientProvider>,
  );
};

describe("Home Page", () => {
  it("renders the hero section with correct title", () => {
    renderHome();
    expect(
      screen.getByRole("heading", { name: /Spezialisierter Partner/i }),
    ).toBeInTheDocument();
  });

  it("contains the CTA button", () => {
    renderHome();
    const ctaButton = screen.getByRole("link", { name: /Projekt anfragen/i });
    expect(ctaButton).toBeInTheDocument();
    expect(ctaButton).toHaveAttribute("href", "/kontakt");
  });

  it("renders the portfolio section", async () => {
    renderHome();
    expect(await screen.findByText(/Unsere Leistungen/i)).toBeInTheDocument();
    // Use getAllByText because it appears in both hero description and card title
    const elements = await screen.findAllByText(/Technische Beratung/i);
    expect(elements.length).toBeGreaterThan(0);
  });
});
