72 lines
2.3 KiB
TypeScript
72 lines
2.3 KiB
TypeScript
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: () => (
|
|
<>
|
|
<div data-testid="plant-card-tomato">Tomato</div>
|
|
<div data-testid="plant-card-pepper">Pepper</div>
|
|
<div data-testid="plant-card-cucumber">Cucumber</div>
|
|
</>
|
|
),
|
|
}));
|
|
|
|
describe("Homepage (page.tsx)", () => {
|
|
it("renders hero section with title", () => {
|
|
render(<Page />);
|
|
expect(screen.getByText(/Snap. Identify. Treat/i)).toBeInTheDocument();
|
|
});
|
|
|
|
it("renders plant emoji in hero", () => {
|
|
render(<Page />);
|
|
expect(screen.getAllByText("🌱").length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it("renders how it works section", () => {
|
|
render(<Page />);
|
|
expect(screen.getByText(/How It Works/i)).toBeInTheDocument();
|
|
});
|
|
|
|
it("renders how it works steps", () => {
|
|
render(<Page />);
|
|
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(<Page />);
|
|
expect(screen.getByText(/Featured Plants/i)).toBeInTheDocument();
|
|
});
|
|
|
|
it("renders featured plant cards", () => {
|
|
render(<Page />);
|
|
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(<Page />);
|
|
expect(screen.getAllByText(/Open Source/i).length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it("renders view all plants link", () => {
|
|
render(<Page />);
|
|
expect(screen.getByRole("link", { name: /View all plants/i })).toBeInTheDocument();
|
|
});
|
|
|
|
it("renders trust signals", () => {
|
|
render(<Page />);
|
|
const trustSignals = screen.queryAllByText(/300\+ plants/i);
|
|
expect(trustSignals.length).toBeGreaterThanOrEqual(0);
|
|
});
|
|
|
|
it("renders learn more link", () => {
|
|
render(<Page />);
|
|
expect(screen.getByRole("link", { name: /Learn More/i })).toHaveAttribute("href", "/about");
|
|
});
|
|
});
|