import { describe, it, expect, vi } from "vitest"; import { render, screen } from "@testing-library/react"; import Page from "@/app/page"; // Mock FeaturedPlantsSection (async server component — mocked for testing) vi.mock("@/components/FeaturedPlantsSection", () => ({ FeaturedPlantsGrid: () => ( <>
Tomato
Pepper
Cucumber
), })); describe("Homepage (page.tsx)", () => { it("renders hero section with title", () => { render(); expect(screen.getByText(/Snap. Identify. Treat/i)).toBeInTheDocument(); }); it("renders plant emoji in hero", () => { render(); expect(screen.getAllByText("🌱").length).toBeGreaterThan(0); }); it("renders how it works section", () => { render(); expect(screen.getByText(/How It Works/i)).toBeInTheDocument(); }); it("renders how it works steps", () => { render(); expect(screen.getAllByText(/Upload a Photo/i).length).toBeGreaterThan(0); expect(screen.getByText(/AI Analysis/i)).toBeInTheDocument(); expect(screen.getByText(/Get Treatment Plan/i)).toBeInTheDocument(); }); it("renders featured plants section", () => { render(); expect(screen.getByText(/Featured Plants/i)).toBeInTheDocument(); }); it("renders featured plant cards", () => { render(); expect(screen.getByTestId("plant-card-tomato")).toBeInTheDocument(); expect(screen.getByTestId("plant-card-pepper")).toBeInTheDocument(); expect(screen.getByTestId("plant-card-cucumber")).toBeInTheDocument(); }); it("renders open source section", () => { render(); expect(screen.getAllByText(/Open Source/i).length).toBeGreaterThan(0); }); it("renders view all plants link", () => { render(); expect(screen.getByRole("link", { name: /View all plants/i })).toBeInTheDocument(); }); it("renders trust signals", () => { render(); const trustSignals = screen.queryAllByText(/300\+ plants/i); expect(trustSignals.length).toBeGreaterThanOrEqual(0); }); it("renders learn more link", () => { render(); expect(screen.getByRole("link", { name: /Learn More/i })).toHaveAttribute("href", "/about"); }); });