import { createRef } from "react";
import { render, screen } from "@testing-library/react";
import { describe, expect, it } from "vitest";
import { AppCard } from "@/components/ui/app-card";
import { Badge } from "@/components/ui/badge";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Separator } from "@/components/ui/separator";
import { Textarea } from "@/components/ui/textarea";
import { Container } from "@/components/layout/container";
import { HeroBadge } from "@/components/layout/hero-badge";
import { SectionHeading } from "@/components/home/section-heading";
describe("Badge", () => {
it("renders children and default variant classes", () => {
render(New);
const badge = screen.getByText("New");
expect(badge).toHaveClass("bg-primary");
});
it("applies a chosen variant and merges custom classNames", () => {
render(OK);
const badge = screen.getByText("OK");
expect(badge).toHaveClass("bg-status-success-soft");
expect(badge).toHaveClass("custom-class");
});
it("passes through arbitrary props", () => {
render(X);
expect(screen.getByTestId("b")).toHaveAttribute("title", "tip");
});
});
describe("Input", () => {
it("forwards the ref and renders attributes", () => {
const ref = createRef();
render();
const input = screen.getByPlaceholderText("you@example.com");
expect(ref.current).toBe(input);
expect(input).toHaveAttribute("type", "email");
expect(input).toBeDisabled();
});
it("merges custom classes", () => {
render();
expect(screen.getByLabelText("field")).toHaveClass("w-20");
});
});
describe("Textarea", () => {
it("forwards the ref and renders a default value", () => {
const ref = createRef();
render();
const textarea = screen.getByLabelText("msg");
expect(ref.current).toBe(textarea);
expect(textarea).toHaveValue("hello");
});
});
describe("Label", () => {
it("associates with a control via htmlFor", () => {
render();
expect(screen.getByText("Name")).toHaveAttribute("for", "name");
});
});
describe("Separator", () => {
it("defaults to a horizontal separator", () => {
const { container } = render();
expect(container.firstChild).toHaveClass("h-px", "w-full");
});
it("supports a vertical orientation", () => {
const { container } = render();
expect(container.firstChild).toHaveClass("h-full", "w-px");
});
});
describe("Card family", () => {
it("composes header, title, description and content", () => {
render(
Title
Desc
Body
,
);
expect(screen.getByRole("heading", { name: "Title" })).toBeInTheDocument();
expect(screen.getByText("Desc")).toBeInTheDocument();
expect(screen.getByText("Body")).toBeInTheDocument();
});
});
describe("AppCard", () => {
it("renders a single-layer card with its children", () => {
render(Single);
expect(screen.getByText("Single")).toBeInTheDocument();
});
it("renders a double-layer card (default) with its children", () => {
render(Double);
expect(screen.getByText("Double")).toBeInTheDocument();
});
});
describe("Container", () => {
it("applies the size variant classes", () => {
const { container } = render(Body);
expect(container.firstChild).toHaveClass("max-w-narrow");
});
it("renders as a child element when asChild is set", () => {
render(
,
);
expect(screen.getByTestId("as-child").tagName).toBe("SECTION");
});
});
describe("HeroBadge", () => {
it("renders children and optional trailing content", () => {
render(→}>Available);
expect(screen.getByText("Available")).toBeInTheDocument();
expect(screen.getByText("→")).toBeInTheDocument();
});
});
describe("SectionHeading", () => {
it("renders eyebrow, title and description", () => {
render();
expect(screen.getByText("Work")).toBeInTheDocument();
expect(screen.getByRole("heading", { name: "Projects" })).toBeInTheDocument();
expect(screen.getByText("What I build")).toBeInTheDocument();
});
it("centers content when align is center", () => {
const { container } = render(
,
);
expect(container.firstChild).toHaveClass("text-center");
});
});