import React from "react"; import { TestimonialCard } from "./index"; import { render, screen } from "@testing-library/react"; jest.mock("@shared/components/material-icon", () => ({ MaterialIcon: ({ name, className }: any) => ( {name} ), })); jest.mock("@shared/components/text", () => ({ Text: ({ as: Tag = "span", children, className }: any) => ( {children} ), })); jest.mock("next/image", () => { const MockImage = ({ src, alt, className }: any) => ( {alt} ); return MockImage; }); jest.mock( "clsx", () => (...args: any[]) => args.flat().filter(Boolean).join(" ") ); describe("TestimonialCard", () => { const defaultProps = { title: "Great Service", quote: "This is an amazing product!", rating: 4, author: "John Doe", role: "CEO", }; describe("Rendering", () => { it("renders the figure element", () => { const { container } = render(); expect(container.querySelector("figure")).toBeInTheDocument(); }); it("renders title", () => { render(); expect(screen.getByText("Great Service")).toBeInTheDocument(); }); it("renders quote", () => { render(); expect( screen.getByText("This is an amazing product!") ).toBeInTheDocument(); }); it("renders author name", () => { render(); expect(screen.getByText("John Doe")).toBeInTheDocument(); }); it("renders author role", () => { render(); expect(screen.getByText("CEO")).toBeInTheDocument(); }); }); describe("Rating", () => { it("renders 5 star icons", () => { render(); const icons = screen.getAllByTestId("material-icon"); expect(icons).toHaveLength(5); }); it("applies filled class to rated stars", () => { render(); const icons = screen.getAllByTestId("material-icon"); const filledIcons = icons.filter(icon => icon.className.includes("text-text") ); expect(filledIcons.length).toBe(3); }); it("applies unfilled class to remaining stars", () => { render(); const icons = screen.getAllByTestId("material-icon"); const unfilledIcons = icons.filter(icon => icon.className.includes("text-gray-300") ); expect(unfilledIcons.length).toBe(2); }); it("does not render rating section when rating is undefined", () => { render(); expect(screen.queryByTestId("material-icon")).not.toBeInTheDocument(); }); it("renders rating aria-label", () => { const { container } = render( ); const ratingDiv = container.querySelector("[aria-label]"); expect(ratingDiv).toHaveAttribute("aria-label", "Rating: 4 out of 5"); }); }); describe("Avatar", () => { it("renders avatar image when avatarUrl is provided", () => { render(); expect(screen.getByTestId("avatar-image")).toBeInTheDocument(); expect(screen.getByTestId("avatar-image")).toHaveAttribute( "src", "/avatar.jpg" ); }); it("renders initials when avatarUrl is not provided", () => { render(); expect(screen.getByText("J")).toBeInTheDocument(); }); }); describe("Active state", () => { it("applies active styles when isActive is true", () => { const { container } = render( ); const figure = container.querySelector("figure"); expect(figure?.className).toContain("bg-bg-surface-secondary"); expect(figure?.className).toContain("shadow-drop"); }); it("applies inactive styles when isActive is false", () => { const { container } = render( ); const figure = container.querySelector("figure"); expect(figure?.className).toContain("opacity-40"); }); it("defaults to inactive", () => { const { container } = render(); const figure = container.querySelector("figure"); expect(figure?.className).toContain("opacity-40"); }); }); describe("Custom className", () => { it("applies custom className", () => { const { container } = render( ); const figure = container.querySelector("figure"); expect(figure?.className).toContain("custom-card"); }); }); describe("Author section", () => { it("does not render author section when author is not provided", () => { const { container } = render( ); expect(container.querySelector("figcaption")).not.toBeInTheDocument(); }); it("renders figcaption when author is provided", () => { const { container } = render(); expect(container.querySelector("figcaption")).toBeInTheDocument(); }); }); });