import "@testing-library/jest-dom"; import React from "react"; import { ComparisonTable } from "./index"; import { render, screen } from "@testing-library/react"; jest.mock("@shared/components/text", () => ({ Text: ({ children, as, ...props }: any) => { const Tag = as || "span"; return {children}; }, })); describe("ComparisonTable", () => { const defaultProps = { title: "Compare Plans", disclaimer: * Terms and conditions apply, table: (
Feature Basic Pro
Speed 100 Mbps 500 Mbps
), }; it("renders the component container", () => { const { container } = render(); expect(container.querySelector(".component-container")).toBeInTheDocument(); }); it("renders the title as h2", () => { render(); const title = screen.getByText("Compare Plans"); expect(title.tagName).toBe("H2"); }); it("renders the table content", () => { render(); expect(screen.getByTestId("comparison-table-content")).toBeInTheDocument(); }); it("renders the disclaimer text", () => { render(); expect( screen.getByText("* Terms and conditions apply") ).toBeInTheDocument(); }); it("applies max-w-120 class when maxWidth is true (default)", () => { const { container } = render(); const inner = container.querySelector(".component-container > div"); expect(inner?.className).toContain("max-w-120"); expect(inner?.className).toContain("xl:mx-auto"); }); it("does not apply max-w-120 class when maxWidth is false", () => { const { container } = render( ); const inner = container.querySelector(".component-container > div"); expect(inner?.className).not.toContain("max-w-120"); expect(inner?.className).not.toContain("xl:mx-auto"); }); it("renders comparison-table-container", () => { const { container } = render(); expect( container.querySelector(".comparison-table-container") ).toBeInTheDocument(); }); it("renders without title", () => { const { container } = render( ); expect(container.querySelector(".component-container")).toBeInTheDocument(); expect(screen.queryByText("Compare Plans")).not.toBeInTheDocument(); }); it("renders without disclaimer", () => { const { container } = render( ); expect(container.querySelector(".component-container")).toBeInTheDocument(); }); it("renders table as a ReactNode", () => { const customTable =
Custom content
; render(); expect(screen.getByTestId("custom-table")).toBeInTheDocument(); }); it("renders with correct CSS structure", () => { const { container } = render(); const tableContainer = container.querySelector( ".comparison-table-container" ); expect(tableContainer?.className).toContain("mt-5"); expect(tableContainer?.className).toContain("p-5"); }); });