import React from "react"; import { ShapeBackgroundWrapper } from "./index"; import { render, screen } from "@testing-library/react"; describe("ShapeBackgroundWrapper", () => { describe("Rendering with show=true (default)", () => { it("renders children inside shape-bg-content wrapper", () => { render(

Child content

); expect(screen.getByText("Child content")).toBeInTheDocument(); expect( screen.getByText("Child content").closest(".shape-bg-content") ).toBeInTheDocument(); }); it("renders the outer container with shape-bg class", () => { const { container } = render( Test ); expect(container.querySelector(".shape-bg")).toBeInTheDocument(); }); it("renders content div with z-[1] for layering above SVG", () => { const { container } = render( Layered ); const content = container.querySelector(".shape-bg-content"); expect(content).toHaveClass("relative", "z-[1]"); }); }); describe("Rendering with show=false", () => { it("renders children without shape-bg wrapper", () => { const { container } = render(

Hidden shape

); expect(screen.getByText("Hidden shape")).toBeInTheDocument(); expect(container.querySelector(".shape-bg")).not.toBeInTheDocument(); }); it("does not render any SVG when show is false", () => { const { container } = render( No SVG ); expect(container.querySelector("svg")).not.toBeInTheDocument(); }); it("applies className when show is false", () => { const { container } = render( Styled ); expect(container.firstChild).toHaveClass("custom-class"); }); it("applies custom background style when show is false and background is non-theme", () => { const { container } = render( Gradient ); expect(container.firstChild).toHaveStyle({ background: "linear-gradient(red, blue)", }); }); }); describe("SVG path rendering", () => { it("renders path1 SVG when path='path1'", () => { const { container } = render( Path1 ); const svgs = container.querySelectorAll("svg"); expect(svgs).toHaveLength(1); expect(svgs[0]).toHaveAttribute("width", "2262"); expect(svgs[0]).toHaveAttribute("height", "4359"); }); it("renders path2 SVG by default", () => { const { container } = render( Default path ); const svgs = container.querySelectorAll("svg"); expect(svgs).toHaveLength(1); expect(svgs[0]).toHaveAttribute("width", "3739"); expect(svgs[0]).toHaveAttribute("height", "3666"); }); it("renders path3 SVG when path='path3'", () => { const { container } = render( Path3 ); const svgs = container.querySelectorAll("svg"); expect(svgs).toHaveLength(1); expect(svgs[0]).toHaveAttribute("width", "3044"); expect(svgs[0]).toHaveAttribute("height", "3248"); }); it("renders path4 SVG when path='path4'", () => { const { container } = render( Path4 ); const svgs = container.querySelectorAll("svg"); expect(svgs).toHaveLength(1); expect(svgs[0]).toHaveAttribute("width", "3739"); expect(svgs[0]).toHaveAttribute("height", "3666"); }); it("does not render SVG for unrecognized path value", () => { const { container } = render( Unknown ); expect(container.querySelector("svg")).not.toBeInTheDocument(); }); it("marks SVG with aria-hidden and focusable=false", () => { const { container } = render( Accessible ); const svg = container.querySelector("svg")!; expect(svg).toHaveAttribute("aria-hidden", "true"); expect(svg).toHaveAttribute("focusable", "false"); }); it("applies pointer-events-none to SVG", () => { const { container } = render( Non-interactive ); const svg = container.querySelector("svg")!; expect(svg).toHaveClass("pointer-events-none"); }); }); describe("Background themes", () => { it.each([ ["blue", "bg-[#07B2E2]"], ["green", "bg-[#26B170]"], ["yellow", "bg-[#F5FF1E]"], ["purple", "bg-[#931D69]"], ["white", "bg-white"], ["navy", "bg-[#00002D]"], ] as const)("applies %s background class", (bg, expectedClass) => { const { container } = render( BG Test ); const outer = container.querySelector(".shape-bg")!; expect(outer.className).toContain(expectedClass); }); it("applies inline style for custom (non-theme) background", () => { const { container } = render( Custom BG ); const outer = container.querySelector(".shape-bg") as HTMLElement; expect(outer.style.background).toBe("rgb(255, 87, 51)"); }); it("falls back to bg-white when no background provided", () => { const { container } = render( No BG ); const outer = container.querySelector(".shape-bg")!; expect(outer.className).toContain("bg-white"); }); }); describe("Fill color (SVG)", () => { it.each([ ["blue", "text-[#07B2E2]"], ["green", "text-[#26B170]"], ["yellow", "text-[#F5FF1E]"], ["purple", "text-[#931D69]"], ["white", "text-white"], ["navy", "text-[#00002D]"], ] as const)("applies %s fill color to SVG", (fill, expectedClass) => { const { container } = render( Fill ); const svg = container.querySelector("svg")!; expect(svg.className.baseVal).toContain(expectedClass); }); it("defaults to yellow fill when fill not specified", () => { const { container } = render( Default fill ); const svg = container.querySelector("svg")!; expect(svg.className.baseVal).toContain("text-[#F5FF1E]"); }); it("falls back to yellow for unrecognized fill value", () => { const { container } = render( Unknown fill ); const svg = container.querySelector("svg")!; expect(svg.className.baseVal).toContain("text-[#F5FF1E]"); }); }); describe("className prop", () => { it("applies custom className to shape-bg wrapper", () => { const { container } = render( Classy ); const outer = container.querySelector(".shape-bg")!; expect(outer).toHaveClass("extra-class"); }); it("handles undefined className without errors", () => { const { container } = render( No class ); expect(container.querySelector(".shape-bg")).toBeInTheDocument(); }); }); describe("maxFit prop", () => { it("applies max-content class when maxFit is true", () => { const { container } = render( Max fit ); const outer = container.querySelector(".shape-bg")!; expect(outer.className).toContain("max-content"); }); it("does not apply max-content when maxFit is false/undefined", () => { const { container } = render( No max fit ); const outer = container.querySelector(".shape-bg")!; expect(outer.className).not.toContain("max-content"); }); }); });